// JavaScript Document
function GetPassword(displaydiv,hidediv){
document.getElementById(hidediv).style.display="none";	
document.getElementById(displaydiv).style.display="block";	
}
function checkloginform()
{

 var username = document.getElementById('userName').value;
 
 username=username.replace(/^\s+|\s+/,"");  
 var passwords = document.getElementById('userPassword').value;
 passwords=passwords.replace(/^\s+|\s+/,"");
 
	if(username=="")
      {
	   alert("Please enter user name.");
	   document.getElementById('userName').focus();
	   return false;
	 }
	 
	 if(username!=""){
		if (username.indexOf ('@',0) == -1 || username.indexOf ('.',0) == -1) {
		  alert("The Email field requires a \"@\" and a \".\" to be used.\n Please re-enter your E-mail Id.");
		  document.getElementById('userName').value="";
		  document.getElementById('userName').focus();
		  return false;
		} 	
	}
	
	
  	if(passwords=="")
      {
	   alert("Please enter passwords.");
	   document.getElementById('userPassword').focus();
	   return false;
	 }
	/*if(username !="" && passwords !="")
	   validateUser('validateUser.php?userName='+username+'&passwd='+passwords,'loginForm');*/
	  
	  return true;
}









function register()
    {  
		
		
		fname   = trimSpace('fname');
		lname   = trimSpace('lname');
		
		email   = trimSpace('email');
		passwd  = trimSpace('passwd');
		passwd2 = trimSpace('passwd2');
		

		if(fname=="")
		  {
		alert("Please enter first name.");
	    document.getElementById('fname').focus();
	    return false;  
		  }
		if(lname=="")
		  {
		alert("Please enter surname.");
	    document.getElementById('lname').focus();
	    return false;  
		  }  
		
		if(email=="")
		  {
		alert("Please enter email.");
	    document.getElementById('email').focus();
	    return false;  
		  }
		if(email!="")
		  {
				
				if(isValidEmail1(email,'0','1') !="")
				{
					alert("Invalid email id");
					document.getElementById('email').focus();
					return false;
				}

		}  
		  
		
		if(passwd=="")
		  {
		alert("Please enter password.");
	    document.getElementById('passwd').focus();
	    return false;  
		  }
		 
		 if(passwd2=="")
		  {
		alert("Please re-enter password.");
	    document.getElementById('passwd2').focus();
	    return false;  
		  }
		  
		  
		if(passwd != passwd2)
		{
	     alert("Password mismatch.");
	    document.getElementById('passwd2').focus();
	    return false;  
		}
	

		
		
		}
function trimSpace(string)
     {
		var str = document.getElementById(string).value;
		  
		 st  = str.replace(/^\s+|\s+/,""); 
		
		    return st;
		}
function showHide(id)
    {
		
		myid=document.getElementById(id);
		if(myid.style.display=="none") 
		   myid.style.display="";
		   else
		   myid.style.display="none";
		   
		
		
		}
var xmlhttp = createXmlHttpRequestObject(); 
// holds the remote server address 

// creates an XMLHttpRequest instance 
function createXmlHttpRequestObject() 
 { 
 // will store the reference to the XMLHttpRequest object 
 var xmlhttp; 
 // this should work for all browsers except IE6 and older 
 try 
   { 
   // try to create XMLHttpRequest object 
   xmlhttp = new XMLHttpRequest();
   } 
   catch(e) 
   { 
   // assume IE6 or older 
   var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"); 
   // try every id until one works 
   for (var i=0; i<XmlHttpVersions.length && !xmlhttp; i++) 
     { 
	 try 
	  { 
	  // try to create XMLHttpRequest object 
	  xmlhttp = new ActiveXObject(XmlHttpVersions[i]); 
	  } 
	  catch (e) 
	  {} 
	  // ignore potential error 
	  } 
	  } 
	  // return the created object or display an error message 
	  if (!xmlhttp) 
	    {}//displayError("Error creating the XMLHttpRequest object."); 
	  else return xmlhttp;
	  } 

//var please_wait = "Please wait...";
var please_wait="<div style='width=100%;height:300px;padding:100px 0px 0px 0px;' align='center'><img src='../images/loader.gif'></div>";

function validateUser(url,targetId) {
	

	
  if(!xmlhttp)return false;
    var e=document.getElementById(targetId);
	
	
	
	

	xmlhttp.open("GET", url, true);
	  
	
	
	xmlhttp.onreadystatechange = function()
	{ 
	response(url, targetId);
	}
    try{	
	 
      xmlhttp.send(null);
		
   }
   catch(l)
     {
    while(e.firstChild)e.removeChild(e.firstChild);
    e.appendChild(document.createTextNode("request failed"));
     }
}

function response(url, e)
   {
     if(xmlhttp.readyState != 4)
	    return;
     
	 //var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText;
  
  if(xmlhttp.readyState == 4)
   {
	  // alert(e);
  document.getElementById(e).innerHTML=xmlhttp.responseText;
   }
  //alert(xmlhttp.responseText);
     
  //  var d=document.createElement("div");
    //var d=document.getElementById(e);
	//alert(e);
	
	 
//	e.innerHTML=tmp;
   
   
}

function showTime(url,targetId) {
	
  if(!xmlhttp)return false;
    var e=document.getElementById(targetId);
	
	
	
	

	xmlhttp.open("GET", url, true);
	  
	
	
	xmlhttp.onreadystatechange = function()
	{ 
	response(url, targetId);
	}
    try{	
	 
      xmlhttp.send(null);
		
   }
   catch(l)
     {
    while(e.firstChild)e.removeChild(e.firstChild);
    e.appendChild(document.createTextNode("request failed"));
     }
setTimeout("showTime('showTime.php','timeId')", 10000);

}

function isValidEmail1(strEmail) {
var msg;
var i;
var len=strEmail.length;
if(strEmail=="") {
msg="Invalid Email Address.";
} else {
if((strEmail.charAt(0)=="@") || (strEmail.charAt(0)==".")) {
msg="";
} else {
// checking the number of the @ and dots in the email add
var countAt=0;
var countDot=0;
for (i=0; i<len; i++) {
if(strEmail.charAt(i)=="@") {
countAt=countAt+1;
}
if(strEmail.charAt(i)==".") {
countDot=countDot+1;
}
} //end of for (i=0; i<strEmail.length; i++) {...
if((countAt!=1) || (countDot<1)) {
msg="Invalid Email Address.";
} else {
// checking the position of the @ with respect to the dot
var posDot=0;
var posAt=0;
posDot=strEmail.lastIndexOf(".");
posAt=strEmail.indexOf("@");
//alert(posDot);
if((posAt>posDot) || (posDot==(posAt+1))) {
msg=posDot;
} else {
// checking the dot position and the @ postion at the end
if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {
msg="Invalid Email Address.";
} else {
/* checking for the invalid characters
if(ereg('[^A-Za-z0-9_]', strEmail)) {
msg="Only letters, numbers and underscores(_)."; */
msg = "";
} //end of if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {...
} //end of if((posAt>posDot) || (posDot==(posDot+1))) {...
} //end of if((countAt!=1) ||(countDot<1)) {...
} //end if((strEmail.charAt(i)=="@") || (strEmail.charAt(i)==".")) {...
} //end of if(strEmail=="") {...
return msg;
}//end function
