//large image lightbox
function large_image(img,w,h)
{
	var height=h+20;
	 TINY.box.show('large-image.php?img='+img+'&w='+w+'&h='+h,1,w,height,1);
}

//////////////////////////////////////////
///////////PNG-Fix//////////////////
////////////////////////////////////////

function correctPNG()
   {
   for(var i=0; i<document.images.length; i++)
      {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='image');\"><"+"/span>"
         img.outerHTML = strNewHTML
         i = i-1
         }
      }
   }
   
 function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function redirect_wsh(chat_keyword)
{
var redirect;
var keyword_param = gup('keyword');
var filename=getfilename();
if(filename=="wsh_search1.php")
   redirect="wwsh_search1.php";
else if(filename=="wsh_search.php")
   redirect="wwsh_search.php";
else if(filename=="wsh_search2.php")
   redirect="wwsh_search2.php";
else if(filename=="art.php")
   redirect="art_chat.php";   
else if(filename=="human.php")
   redirect="human_chat.php";  
else if(filename=="search_engine.php")
   redirect="ssearch_engine.php";   
else
   redirect="homepage.php";   
 window.location=redirect+"?keyword="+keyword_param+"&chat_keyword="+chat_keyword;
}	

function redirect_wsh_art(chat_keyword,id)
{
var keyword_param = gup('keyword');
window.location="art_chat.php?keyword="+keyword_param+"&chat_keyword="+chat_keyword+"&id="+id;
}

function redirect_wsh_news(chat_keyword,$news_key,$page)
{
window.location="art_chat.php?news_key="+news_key+"&chat_keyword="+chat_keyword+"&page="+page;
}
   
function redirect_wsh2_chat(chat_keyword,keyword)
{
window.location="/wwsh_search2/"+chat_keyword+"/"+keyword;
}
  
function getfilename()
{
var url = window.location.pathname;
var lastSlash = url.lastIndexOf("/");
var firstQuestionMark = url.indexOf("?");
if(firstQuestionMark == -1)
{
firstQuestionMark = url.length;
}
var fileName = url.substring(lastSlash + 1, firstQuestionMark);
return fileName;
}   
      
function make_blank()
{
document.chat_form.chat_keyword.value ="";
}   
   
 function str_rot13() {
 var str=document.search_form.keyword.value;
    return (str+'').replace(/[a-z]/gi, function(s){
       return  String.fromCharCode(s.charCodeAt(0)+(s.toLowerCase()<'n'?13:-13));
    });
}

function convert()
{
document.search_form.keyword.value=str_rot13();
} 

    // Get the HTTP Object
      function getHTTPObject(){
      if (window.ActiveXObject) 
      return new ActiveXObject("Microsoft.XMLHTTP");
      else if (window.XMLHttpRequest) 
      return new XMLHttpRequest();
      else {
      alert("Your browser does not support AJAX.");
      return null;
      }
      } 
	  
  
      function p_attributes(keyword,page){
	     httpObject = getHTTPObject();
         if (httpObject != null) {
         httpObject.open("GET", "product_attributes.php?keyword="
         +keyword+"&page="+page, true);
         httpObject.send(null);
		 httpObject.onreadystatechange = setOutput;
         }
        }	  
		
		function setOutput(){
		if(httpObject.readyState == 4){
		document.getElementById('products').innerHTML = httpObject.responseText;
		}
		}

		function redirect_wsh2(key)
		{
		  document.wsh2_form.action="/wsh_search2/"+document.wsh2_form.keyword.value+"/";
		  document.submit();
		}
		
		function redirect_chat2()
		{
		  document.chat_form.action="/wwsh_search2/"+document.chat_form.chat_keyword.value+"/"+document.chat_form.keyword.value;
		  document.submit();
		}
		
		function more_attr(id,keyword)
		{
		 TINY.box.show('more.php?id='+id+'&keyword='+keyword,1,600,700,1);
		}
	
		
function validateForm()
{
var x=document.email_form.email_address.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Not a valid e-mail address");
  return false;
  }
  return true;
}	

function validate_news()
{
if(document.news_form.news_key.value=="")
		 {
		   alert("Please enter word for news search");
		   document.news_form.news_key.select();
		   document.news_form.news_key.focus();
		   return false;
		 }
		return true;
}


function post_captcha(){

if(document.comment_form.comment.value=="" || document.comment_form.comment.value=="Add your comment")
		 {
		   alert("Please enter your comment");
		   document.comment_form.comment.select();
		   document.comment_form.comment.focus();
		   return false;
		 }
		else if(document.comment_form.captcha.value=="")
		{
		  alert("Please enter the 3 black symbols");
		  document.comment_form.captcha.select();
		  document.comment_form.captcha.focus();
		   return false;
		}	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			document.getElementById('u_captcha').value="";
			document.getElementById('u_comment').value="";
			img = document.getElementById('captcha_img');
	        img.src = 'captcha.php?' + Math.random();
			}
	}
	var comment = document.getElementById('u_comment').value;
	var captcha = document.getElementById('u_captcha').value;
	var comment_id = document.getElementById('u_comment_id').value;
	var queryString = "comment=" + comment + "&captcha=" + captcha + "&comment_id=" + comment_id;
	ajaxRequest.open("POST", "post_captcha.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", queryString.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(queryString); 
}

function post_emailalerts(){
		if(document.email_form.email_name.value=="")
		 {
		   alert("Please enter your name");
		   document.email_form.email_name.select();
		   document.email_form.email_name.focus();
		   return false;
		 }
		else if(document.email_form.email_address.value=="")
		{
		  alert("Please enter your email address");
		  document.email_form.email_address.select();
		  document.email_form.email_address.focus();
		   return false;
		}	
	  if(validateForm()==false)
		  return false;
		 
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		if(ajaxRequest.responseText=="success")
		   window.location="email_success.php";
		   else
		   {
			var ajaxDisplay = document.getElementById('alertDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		   }
		}
	}
	var email_name = document.getElementById('email_name1').value;
	var email_address = document.getElementById('email_address1').value;
	var queryString = "email_name=" + email_name + "&email_address=" + email_address ;
	ajaxRequest.open("POST", "post_emailalerts.php", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", queryString.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(queryString); 
}
