// JavaScript Document


//validate the white space
function isWhiteWpace (s){
  var whitespace = " \t\n\r";
  var i;
  for (i = 0; i < s.length; i++){  
   var c = s.charAt(i);
   if (whitespace.indexOf(c) >= 0) {return true;}
 }
return false;
}

//validate the legal user name
// it should be number, alphabeta
function isSsnString (ssn){
var re=/^[0-9a-z][\w-.]*[0-9a-z]$/i;
if(re.test(ssn)){return true;}else{return false;}
}
//validate the lenth of the user name 
function checkUserName(ssn){
 if( ssn.length<3 || ssn.length>18 ) {
  alert("Please input the right length of the user name.(it should be 3-18)")
  document.form1.elements["username"].focus();
  return false;
 }
 if (isWhiteWpace(ssn)){
  alert("User name shouldn't have white space!");
  document.form1.elements["username"].focus();
  return false;
 }
 if (!isSsnString(ssn)){
  alert("your user name's format is wriong. it should consist of “a-z 0-9 ._-”(case insensitive)");
  document.form1.elements["username"].focus();
  return false;
 }
return true;
}
function checkssn(gotoURL) { 
 var ssn=document.form1.elements["username"].value.toLowerCase();  
 var pwd=document.form1.elements["password"].value.toLowerCase();
 var option1=document.form1.elements["usertype_0"].checked;
 var option2=document.form1.elements["usertype_1"].checked;

 if (checkfunction(option1,option2)&&checkUserName(ssn))//{    
 {
		 
	 location.href=gotoURL;
	 
 }
 else
 {
	return false; 
	 
 }
	
}
/**
*validate whether the pwd is between 3 and 18
*/

function validpwd(pwd)
{
	if(pwd.length<3||pwd.length>18)
	{
		alert("Please input the right length of password. (it should be 3-18)");
		document.form1.elements["password"].value="";
		document.form1.elements["password"].focus();
		return false;
		
		
	}
	/*if(isWhiteWpace(pwd))
	{
		alert("The password shouldn't have white space!")	
		document.form1.elements["password"].value="";
		document.form1.elements["password"].focus();
		return false;
		
	}
	if (!isSsnString(ssn))
	{
  		alert("your password's format is wriong. it should consist of “a-z 0-9 ._-”(case insensitive)");
		document.form1.elements["password"].value="";
  		document.form1.elements["password"].focus();
  		return false;
 	}*/
	
	return true;
	
	
	
	
}


function checkfunction(option1, option2)
{
	if(option1==true||option2==true)
		{
			return true;	
			
			
		}
	else
		{
			alert("You must choose at least one user type! (Dealers or Producers)");
			return false;
			
			
			
		}		
	
		
	
	
	
	
	
}


 