// JavaScript Document
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
}
else if( document.documentElement && ( document.documentElement.scrollWidth) ) {
	//IE 7+ in 'standards compliant mode'
	myWidth = document.documentElement.scrollWidth;
	myHeight= document.documentElement.scrollHeight;
}
function trim(fieldValue){
	var s = new String(fieldValue);
	var str = ""
	var strSpace = " ";
	var i,j,intCount;	
	//to replace the enter pressed with space
	for(intCount=0;intCount<s.length;intCount++){
		if (!((s.charCodeAt(intCount)!=13) && (s.charCodeAt(intCount)!=10)))
			s=s.replace(s.charAt(intCount)," ");
	}
	
	for (i=0;i<s.length && s.charAt(i) == strSpace;i++);
	for (j=s.length; j>=0 && s.charAt(j - 1) == strSpace; j--);

	for (;i<j;i++)
		str = str + s.charAt(i);
	return (str)		
}
function sharePage(val,title){	
	if(val.indexOf("?")!=-1){
		temps=val.split("?");
		val=temps[0];
	}
	url="sharePage.php?share_pg="+escape(val)+"&title="+escape(title);
	html="<br><br><br><br><img src='images/loading.gif'><br>Loading......<br><br><br>";		
	var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	obj=document.getElementById("divWindow");
	if(h<=230)
		obj.style.top=230+'px';
	else
		obj.style.top=h+(myHeight/2-200)+'px';
	obj.style.left=(myWidth/2-250)+'px';
	obj.style.display="block";
	obj=document.getElementById("divEmail");	
	obj.innerHTML=html;
	obj=document.getElementById("divNTitle");	
	obj.innerHTML="<strong>Share this page</strong>";
	xmlHttp=GetXmlHttpObject_new(stateChanged3)
	xmlHttp.open("GET", url , true)	
	xmlHttp.setRequestHeader("If-Modified-Since","Thu, 1 Jan 1970 00:00:00 GMT")	
	xmlHttp.setRequestHeader("Cache-Control", "no-cache")
	xmlHttp.setRequestHeader("Content-Type","text/html")
	xmlHttp.send(null)
	return false;			
}		
function hideDiv(){
	obj=document.getElementById("divWindow");
	obj.style.display="none";
	obj=document.getElementById("divEmail");
	obj.innerHTML=""
	return false;
}	
function GetXmlHttpObject_new(handler)
{ 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	else
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 
function stateChanged3() 
{ 	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 	
		//alert(xmlHttp.responseText);	
		obj=document.getElementById("divEmail");		
		str=xmlHttp.responseText;
		temps=str.split("#$#$#");
		str1=temps[0];
		str2=temps[1];
		obj.innerHTML=str1;							
		if(trim(str2)!="")
			alert(str2);
	} 

}
function checkmailForm(){
	MM_validateForm('Your_Name','','R','Your_Email','','RisEmail','Email1','','NisEmail','Email2','','NisEmail','Email3','','NisEmail');
	if(!document.MM_returnValue){
		return false;
	}
	if(document.mailform.Email1.value=="" && document.mailform.Email2.value=="" && document.mailform.Email3.value==""){
		alert("Enter your friend's email address");
		return false;
	}
	if(trim(document.mailform.verify.value)==""){
		alert("Enter verify code");
		return false;
	}
	url="mailMe.php?email_pg="+escape(document.mailform.email_pg.value)+"&Your_Name="+escape(document.mailform.Your_Name.value)+"&Your_Email="+escape(document.mailform.Your_Email.value)+"&Email1="+escape(document.mailform.Email1.value)+"&Email2="+escape(document.mailform.Email2.value)+"&Email3="+escape(document.mailform.Email3.value)+"&Message="+escape(document.mailform.Message.value)+"&verify="+escape(document.mailform.verify.value)+"&title="+escape(document.title);
	html="<br><br><br><br><img src='images/loading.gif'><br>Loading......<br><br><br>";
	obj=document.getElementById("divEmail");	
	obj.innerHTML=html;
	
	xmlHttp=GetXmlHttpObject_new(stateChanged3)
	xmlHttp.open("GET", url , true)	
	xmlHttp.setRequestHeader("If-Modified-Since","Thu, 1 Jan 1970 00:00:00 GMT")	
	xmlHttp.setRequestHeader("Cache-Control", "no-cache")
	xmlHttp.setRequestHeader("Content-Type","text/html")
	xmlHttp.send(null)
	return false;			
}
function reloadImg(){
	obj=document.getElementById("captchaDiv");
    //location.href=location.href;
	obj.innerHTML='<img border="0" src="captcha.php">';
	return false;
}
function mailMe(val,bgcolor){
	if(val.indexOf("?")!=-1){
		temps=val.split("?");
		val=temps[0];
	}
	url="mailMe.php?email_pg="+escape(val);
	html="<br><br><br><br><img src='images/loading.gif'><br>Loading......<br><br><br>";		
	var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	obj=document.getElementById("divWindow");
	if(h<=230)
		obj.style.top=230+'px';
	else
		obj.style.top=h+(myHeight/2-200)+'px';
	obj.style.left=(myWidth/2-250)+'px';
	obj.style.display="block";
	obj=document.getElementById("divEmail");	
	obj.innerHTML=html;
	obj=document.getElementById("divNTitle");	
	obj.innerHTML="<strong>Email this page to friend</strong>";
	
	xmlHttp=GetXmlHttpObject_new(stateChanged3)
	xmlHttp.open("GET", url , true)	
	xmlHttp.setRequestHeader("If-Modified-Since","Thu, 1 Jan 1970 00:00:00 GMT")	
	xmlHttp.setRequestHeader("Cache-Control", "no-cache")
	xmlHttp.setRequestHeader("Content-Type","text/html")
	xmlHttp.send(null)
	return false;			
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
