
function formcheck(signinform)

{



var alertMsg = "Please complete the following fields:\n";



var l_Msg = alertMsg.length;



	if (signinform.username.value == "")

	{	alertMsg += " - " + " User Name " + "\n";

	}



	if(signinform.password.value == ""){

		alertMsg += " - " + " Password " + "\n";}



	

	if (alertMsg.length == l_Msg){

		usrpass=signinform.username.value + "|" + signinform.password.value;

		SetCookie("usrpass", usrpass , null, "/");

		SetCookie("navtype", 'first' , null, "/");


		return true;

	}else{

		alert(alertMsg);

		return false;

	}



alert(alertMsg);





}

function SetCookie (name,value,expires,path,domain,secure) {

   document.cookie = name + "=" + escape (value) +

                     ((expires) ? "; expires=" + expires.toGMTString() : "") +

                     ((path) ? "; path=" + path : "") +

                     ((domain) ? "; domain=" + domain : "") +

                     ((secure) ? "; secure" : "");

}

function checkuserid(username)
{
	if(username != '')
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			alert("Your browser does not support XMLHTTP!");
		}

		params = "username="+username+"&function=CHKUSRID";
		xmlhttp.open("POST","validatenewuser.php",false);
		//Send the proper header information along with the request  
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
		xmlhttp.setRequestHeader("Content-length", params.length);  
		xmlhttp.setRequestHeader("Connection", "close"); 

		xmlhttp.onreadystatechange=function()
		{
  			if(xmlhttp.readyState==4)
  			{
  				if(xmlhttp.responseText == 'DUPLICATE USERID')
				{
					alert("Username You have entered is already in use!! \n\n\n Please Choose different username");
					document.loginform.username.value = "";
					document.loginform.username.focus();
					return false;
				}
  			}
		}

		xmlhttp.send(params);
	}
}

function checkuser(fname,mname,lname,spname)
{
	if(fname != '' && mname != '' && lname != '')
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			alert("Your browser does not support XMLHTTP!");
		}

		params = "first="+fname+"&middle="+mname+"&last="+lname+"&spname="+spname+"&function=CHKUSR";
		xmlhttp.open("POST","validatenewuser.php",false);
		//Send the proper header information along with the request  
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
		xmlhttp.setRequestHeader("Content-length", params.length);  
		xmlhttp.setRequestHeader("Connection", "close"); 

		xmlhttp.onreadystatechange=function()
		{
  			if(xmlhttp.readyState==4)
  			{
  				if(xmlhttp.responseText == 'DUPLICATE USER')
				{
					alert("User alredy exist! \n\n\n Please Click on OK button to redirect on forgot password page to get yout login details!");
					window.navigate("forgotpass.php","_self");
					return false;
				}
  			}
		}

		xmlhttp.send(params);
	}
}




function validation(loginform)

{

if (loginform.first.value == "")
{ alert (" Please Enter First Name.");
loginform.first.focus();
return(false);

}
if (loginform.middle.value == "")
{ alert (" Please Enter Middle Initial.");
loginform.middle.focus();
return(false);

}
if (loginform.last.value == "")
{ alert (" Please Enter Your Last Name.");
loginform.last.focus();
return(false);

}

if (loginform.username.value == "")
{ alert (" Please Enter a User Name.");
loginform.username.focus();
return(false);

}
if (loginform.password.value == "")
{ alert (" Please Enter Your Password.");
loginform.password.focus();
return(false);

}


if (loginform.rpass.value == "")
{ alert (" Please Repeat your password.");
loginform.rpass.focus();
return(false);

}

if (loginform.password.value != loginform.rpass.value)
{
alert ("Your Password Fields do not match. Recheck!.");
loginform.rpass.focus();
return (false);
}

if (loginform.address1.value == "")
{ alert (" Please your address.");
loginform.address1.focus();
return(false);

}
if (loginform.city.value == "")
{ alert (" Please enter your city name.");
loginform.city.focus();
return(false);

}
if (loginform.state.value == "")
{ alert (" Please select your state.");
loginform.state.focus();
return(false);

}
if (loginform.zipcode.value == "")
{ alert (" Please Enter your Zip code.");
loginform.zipcode.focus();
return(false);

}

if (loginform.email.value == "")
{ 
	result = confirm("You have not entered E-Mail ID! \n\n\n Are you sure you want to proceed without E-Mail ID?");
	if(!result)
	{
		loginform.email.focus();
		return(false);
	}
}

if (loginform.email.value != "")
{
	var checkemail = "@.";
	var checkstr  = loginform.email.value;
	var emailvalid = false;
	var emailat = false;
	var emailperiod = false;
	for (i=0; i < checkstr.length; i++)
	{
		ch = checkstr.charAt(i);
		
		for (j=0;  j < checkemail.length; j++)
		{
		if (ch == checkemail.charAt(j) && ch == "@")
		emailat = true;
		if (ch == checkemail.charAt(j) && ch == ".")
		emailperiod = true;		  
		  if (emailat && emailperiod)
			  break;
		  if (j == checkemail.length)
				break;				 
		}
		if (emailat && emailperiod)
		{
			emailvalid = true
			break;
		}
	}
	if (!emailvalid)
	{
	alert("Your Email ID is invalid.Please Enter a Valid Email ID.");
	loginform.email.focus();
	return (false);
	}
}

}





