function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,'');
}

function validm()
{
	  if(trim(document.searchfrm.search.value)=='' || document.searchfrm.search.value=='Type keyword (name, city, interest, company, school, title,..)')
	  {
	  	alert("Enter search string");
	  	document.searchfrm.search.value='';
	  	document.searchfrm.search.focus();
	  	return false;
	  }
	  else
	  {
	  	document.searchfrm.submit();
	  }
}

function form_validate()
{
	if(document.login.email.value=="")
	  {
	  		alert("Please enter your e-mail id");
	  		document.login.email.focus();
	  		return false;
	  }
	else
      {
    	if(document.login.email.value!="")
 		 {
 	 		str=document.login.email.value;
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
			if (!filter.test(str))
			{
				alert("Please input a valid email address!")
 				document.login.email.focus();
 				return false;
			}
		 }
	  }

	if(trim(document.login.password.value)=="")
	  {
	  		alert("Please enter your password");
			document.login.password.value='';
	  		document.login.password.focus();
	  		return false;
	  }
  	else
	  {
		 var params = "e="+document.login.email.value+"&p="+document.login.password.value+"&cvalue="+document.login.checkbox.checked;
         xmlHttp1=GetXmlHttpObject();
		 url="/newhome/log.php";

		 xmlHttp1.open("POST",url,true);

		 xmlHttp1.onreadystatechange=stateChanged1;

		 xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		 xmlHttp1.setRequestHeader("Content-length", params.length);
		 xmlHttp1.setRequestHeader("Connection", "close");

		 xmlHttp1.send(params);
		 return false;
  	  }
}

function stateChanged1()
{
    if (xmlHttp1.readyState==4 && xmlHttp1.status == 200)
     {
        var info = xmlHttp1.responseText;
		if(info=='RES|1')
		{
			document.getElementById("abhijit1").innerHTML='Your emailid or password not matched, please try again';
			document.login.password.value='';
			document.login.password.focus();
		}
		else
        	window.location = info;
        return false;
     }
}

function showlogin(what,frm)
{
	if(what==1)
	{
		what='open';
	}
	var v1 = document.getElementById("newmahi");
	var v2 = document.getElementById("newmahi2");
	if(what=='open')
	{
		v1.style.display = "block";
		v2.style.display = "block";
	}
	else if(what=='close')
	{
		v1.style.display = "none";
		v2.style.display = "none";
	}
}

/*	validation code for sign in box.*/
function loginvalidation()
{
	if(document.logintop.email.value=="")
		  {
	  		alert("Please enter your e-mail id");
	  		document.logintop.email.focus();
	  		return false;
		  }
		else
  	      {
		    	if(document.logintop.email.value!="")
		 		 {
		 	 		str=document.logintop.email.value;
					var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
					if (!filter.test(str))
		 				{
							alert("Please input a valid email address!")
			 				document.logintop.email.focus();
			 				return false;
						}
				 }

		  }

		if(trim(document.logintop.password.value)=="")
		  {
		  		alert("Please enter your password");
		  		document.logintop.password.focus();
		  		return false;
		  }
		  else
		  {
			 var params = "e="+document.logintop.email.value+"&p="+document.logintop.password.value+"&cvalue="+document.logintop.checkbox.checked;
             xmlHttp=GetXmlHttpObject();
			 url="/newhome/log.php";

			 xmlHttp.open("POST",url,true);

			 xmlHttp.onreadystatechange=stateChanged;

			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			 xmlHttp.setRequestHeader("Content-length", params.length);
			 xmlHttp.setRequestHeader("Connection", "close");

			 xmlHttp.send(params);
			 return false;
  	  	  }
}

function stateChanged()
{
    if (xmlHttp.readyState==4 && xmlHttp.status == 200)
     {
        var info = xmlHttp.responseText;
		if(info=='RES|1')
		{
			document.getElementById("abhijit").innerHTML='Your emailid or password not matched, please try again';
			document.logintop.password.value='';
			document.logintop.password.focus();
		}
		else
        	window.location = info;
        return false;
     }
}
/*	END	*/

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
      {
		  // Firefox, Opera 8.0+, Safari

		  xmlHttp=new XMLHttpRequest();
      }

    catch (e)
      {

	      // Internet Explorer

	      try

	        {
	        	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	        }

	      catch (e)

	        {

	        	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

	        }

      }
    return xmlHttp;
}


function load_ads()
{
	var el1 = document.getElementById('adver1');//for footer ad
	document.getElementById("advertise1").innerHTML = el1.innerHTML;
	var el2 = document.getElementById('adver2');//for rightside ad
	document.getElementById("sidead").innerHTML = el2.innerHTML;
}
