//history.forward();

function setState(thisForm)
{
	if(thisForm.country.value != 'United States of America')
	{
		  thisForm.state.value = "Others";
		  thisForm.state.disabled = true;
	}
	else
	{
		  //thisForm.state.value = "Choose a state";
		  thisForm.state.disabled = false;
	}
}


function setupdateprofileState(thisForm)
{   
    if(thisForm.country.value != 'United States of America')
	{
		  thisForm.state.value = "Others";
		  thisForm.state.disabled = true;
	}
	else
	{
		  //thisForm.state.value = "Choose a state";
		  thisForm.state.disabled = false;
	}

}



//For SignUp page

function signUpSubmit(thisForm)
{


   if(thisForm.email.value=='')
   {

     alert('Email address cannot be blank');
     thisForm.email.focus();
     return(false);

   }

   else if(!isValidEmailId(thisForm.email.value))
   {
      alert('Please enter a valid Email address');
      thisForm.email.focus();
      return(false);
   } 

   else 
   {
      return true;
   }


}



//For Feedback Form
function confirmFeedback(thisForm) 
{ 
   if(isBlank(thisForm.user_id.value)) 
   {  alert("Please enter Username");
      thisForm.user_id.focus();
	  return false; 
   } 
   
   else if(!isValidEmailId(thisForm.email.value))
   {
      alert('Please enter a valid Email address');
      thisForm.email.focus();
      return(false);
   } 

   else if((thisForm.os.value=='Others') && (thisForm.os_others.value==''))
   {
     alert('Please specify the OS');
     thisForm.os_others.focus();
     return (false);
   

   }

   else
   { return true ;
   }
}




// For Forgot Password 

function confirmForgotPwd(thisForm) 
{ 
   if( (thisForm.user_id.value=='') && (thisForm.email.value=='') )
    {
      alert('Please enter either Username or Email address');
      return (false);
    }
    else if( (thisForm.user_id.value!='') && (invalidUserName(thisForm.user_id.value)) )
    {
      alert('Username cannot have special characters, allowed characters are a-z, 0-9 and _ (underscore).');
      thisForm.user_id.focus();
      return (false);
    }
    else if( (thisForm.email.value!='') && (!isValidEmailId(thisForm.email.value)) )
   {
     alert('Please enter a valid Email address');
      thisForm.email.focus();
      return(false);
   } 
   else
   { 
      return (true);
   }
}



function confirmChangePwd(thisForm) 
{ 
   if(isBlank(thisForm.user_passwd.value))
   {
      alert('Please enter Password');
	  thisForm.user_passwd.focus();
      return (false);
   }
   else if (inValidString(thisForm.user_passwd.value))
   {
       alert('Password can contain only A-Z, a-z, and 0-9 as characters')
       thisForm.user_passwd.focus();
       return (false);
   }
   else if( (thisForm.user_passwd.value.length < 8) || (thisForm.user_passwd.value.length > 20))
   {
       alert('Password must be between 8 to 20 characters');
       thisForm.user_passwd.focus();
       return(false);
   }
   else if (!containsNumeric(thisForm.user_passwd.value))
   {
       alert('Password should have at least one numeric character')
       thisForm.user_passwd.focus();
       return (false);
   }
   else if(thisForm.user_passwd2.value != thisForm.user_passwd.value)
   {  alert('Confirm Password must be same as Password');
      thisForm.user_passwd2.focus();
      return (false);
   }
   else
   { 
      return (true);
   }
}

 
//For Registration process
function confirmSubmit(thisForm)
{

   

   if(isBlank(thisForm.user_id.value))
   {  alert('Please enter Username');
      thisForm.user_id.focus();
	  return (false);
   }
   else if(invalidUserName(thisForm.user_id.value))
   {  alert('Username can contain only a-z, 0-9 and _ (Underscore)');
      thisForm.user_id.focus();
	  return (false);
   }
   else if(isBlank(thisForm.user_passwd.value))
   {  alert('Please enter Password');
      thisForm.user_passwd.focus();
	  return (false);
   }
   else if (inValidString(thisForm.user_passwd.value))
   {
       alert('Password can contain only A-Z, a-z, and 0-9 as characters')
       thisForm.user_passwd.focus();
       return (false);
   }
   else if( (thisForm.user_passwd.value.length < 8) || (thisForm.user_passwd.value.length > 20))
   {
        alert('Password must be between 8 to 20 characters');
        thisForm.user_passwd.focus();
        return(false);
   }
   else if (!containsNumeric(thisForm.user_passwd.value))
   {
       alert('Password should have at least one numeric character')
       thisForm.user_passwd.focus();
       return (false);
   }
   else if(thisForm.user_id.value == thisForm.user_passwd.value)
   {
      alert('Password cannot be same as Username');
      thisForm.user_passwd.focus();
      return (false);
   }
   else if(isBlank(thisForm.user_passwd2.value))
   {  alert('Please confirm your Password');
      thisForm.user_passwd2.focus();
	  return (false);
   }
   else if(thisForm.user_passwd2.value != thisForm.user_passwd.value)
   {  alert('Confirm Password must be same as Password');
      thisForm.user_passwd2.focus();
     return (false);
   }
   else if (thisForm.first_name.value =='')
   {
	  alert('Please enter the First name');
	  thisForm.first_name.focus();
	  return (false);
   }
   else if (invalidName(thisForm.first_name.value))
   {
	  alert('First name can contain only characters A-Z, a-z and blank space');
      thisForm.first_name.focus();
	  return (false);
   }
   else if (thisForm.last_name.value == '')
   {
	  alert('Please enter the Last name');
	  thisForm.last_name.focus();
	  return (false);
   }
   else if (invalidName(thisForm.last_name.value))
   {
	  alert('Last name can contain only characters A-Z, a-z and blank space');
	  thisForm.last_name.focus();
	  return (false);
   }
   else if (isBlank(thisForm.address1.value))
   {
	  alert('Please enter Address1');
	  thisForm.address1.focus();
	  return (false);
   }


   else if (inValidAddress(thisForm.address1.value) )
   {
	  alert('Address1 can contain only A-Z, a-z, 0-9, _, # / ( ) - and blank space');
 	  thisForm.address1.focus();
	  return (false);
   }
   
   else if (!isBlank(thisForm.address2.value) && inValidAddress(thisForm.address2.value) )
   {

      alert('Address2 can contain only A-Z, a-z, 0-9, _, # / ( ) - and blank space');
 	  thisForm.address2.focus();
	  return (false);
   }
/* 
   else if (inValidAddress(thisForm.address2.value) )
   {
	  alert('Address2 can contain only A-Z, a-z, 0-9, _, # / ( ) - and blank space');
 	  thisForm.address2.focus();
	  return (false);
   } 
*/
   else if (isBlank(thisForm.city.value))
   {
	  alert('Please enter City');
	  thisForm.city.focus();
	  return (false);
   }


     else if(inValidCity(thisForm.city.value))
   {
	  alert('City can contain only A-Z, a-z and blank space');
	  thisForm.city.focus();
	  return (false);
   }



   else if (isBlank(thisForm.zip.value))
   {
	  alert('Please enter Zip');
	  thisForm.zip.focus();
	  return (false);
   }

   

   else if(inValidZip(thisForm.zip.value))
   {    
          alert('Zip can contain only A-Z, a-z, 0-9 _ and blank space');
	  thisForm.zip.focus();
          return (false);
   }


/*
   else if(thisForm.country.value == 'United States of America')
   {
	   if(thisForm.state.value == '' || thisForm.state.value == 'Others' || thisForm.state.value == 'Choose a state')
	   {
		    alert('Please select a State');
		    return(false);
	   }
                  
   }    
   else if(thisForm.country.value != 'United States of America')
   {
	    thisForm.state.value == 'Others' ;
	    thisForm.state.disabled = false;
	
   }   */ 
   else
   {
     return true;
   }


}










//For Edit profile process
function editprofileSubmit(thisForm)
{
     
   if(!isBlank(thisForm.password.value))
   {
		 if (inValidString(thisForm.password.value))
		 {
			 alert('Password can contain only A-Z, a-z, and 0-9 as characters')
			 thisForm.password.focus();
			 return (false);
		 }
		 else if( (thisForm.password.value.length < 8) || (thisForm.password.value.length > 20))
		 {
			  alert('Password must be between 8 to 20 characters');
		  
			  thisForm.password.focus();
			  return(false);
		 }
		 else if (!containsNumeric(thisForm.password.value))
		 {
			 alert('Password should have atleast one numeric character (0-9)')
		  
			 thisForm.password.focus();
			 return (false);
		 }
		 else if(thisForm.password1.value != thisForm.password.value)
		 {  alert('Confirm Password must be same as Password');
			thisForm.password1.focus();
			return (false);
		 }
   }      
   else if(!isValidEmailId(thisForm.email.value))
   {
        alert('Please enter a valid Email address');
        thisForm.email.focus();
        return(false);
   }
     else if (thisForm.firstname.value =='')
     {
	 alert('Please enter the First name');
	 thisForm.firstname.focus();
	 return (false);
     }
     else if (invalidName(thisForm.firstname.value))
     {
	alert('First name can contain only characters A-Z, a-z and blank space');
        thisForm.firstname.focus();
	return (false);
     }
     else if (thisForm.lastname.value == '')
     {
	alert('Please enter the Last name');
	thisForm.lastname.focus();
	return (false);
     }
     else if (invalidName(thisForm.lastname.value))
     {
	alert('Last name can contain only characters A-Z, a-z and blank space');
	thisForm.lastname.focus();
	return (false);
     }

     else if (isBlank(thisForm.address1.value))
     {
        alert('Please enter Address1');
	thisForm.address1.focus();
	return (false);
     }


     else if (inValidAddress(thisForm.address1.value) )
     {
	alert('Address1 can contain only A-Z, a-z, 0-9, _, # / ( ) - and blank space');
 	thisForm.address1.focus();
	return (false);
     }
   /*
     else if (isBlank(thisForm.address2.value))
     {
        alert('Please enter address2');
	thisForm.address2.focus();
        return (false);
     }
  
     else if (inValidAddress(thisForm.address2.value) )
     {
	alert('Allowed characters for Address2:A-Z a-z 0-9 - # , / (  ) and space');
 	thisForm.address2.focus();
	return (false);
     } 
*/




else if (!isBlank(thisForm.address2.value) && inValidAddress(thisForm.address2.value) )
   {

      alert('Address2 can contain only A-Z, a-z, 0-9, _, # / ( ) - and blank space');
 	  thisForm.address2.focus();
	  return (false);
   }


     else if (isBlank(thisForm.city.value))
     {
        alert('Please enter City');
	thisForm.city.focus();
	return (false);
     }

     else if(inValidCity(thisForm.city.value))
     {
	  alert('City can contain only A-Z, a-z and blank space');
	  thisForm.city.focus();
	  return (false);
     }

     else if (isBlank(thisForm.zipcode.value))
     {
          alert('Please enter Zip');
	  thisForm.zipcode.focus();
	  return (false);
     }

   

     else if(inValidZip(thisForm.zipcode.value))
     {    
          alert('Zip can contain only A-Z, a-z ,0-9 , - and blank space');
	  thisForm.zipcode.focus();
          return (false);
     }
/*
     else if(thisForm.country.value == 'United States of America')
     {
	  if(thisForm.state.value == '' || thisForm.state.value == 'Others' || thisForm.state.value == 'Choose a state' )
	   {
	     alert('Please select the state');
	     return(false);
	   }
     }
   else if(thisForm.country.value != 'United States of America')
	{
	    thisForm.state.disabled = false;
	    thisForm.state.value == 'Others' ;
            return(true);
	}  */
    else
    {
       return true;
    }
}




 


function isBlank(Str)
 {
   while(''+Str.charAt(0)==' ')
   Str=Str.substring(1,Str.length);
   while(''+Str.charAt(Str.length-1)==' ')
   Str=Str.substring(0,Str.length-1);
   if (Str == '')
   { return(true);
   }
   else
   { return(false);
   };
 }



function invalidName(Str)
 {
     var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";

     for(var count = 0; count < Str.length; count++)
     {
        if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
        {
            return(true);
        }
     };

 }



function containsNumeric(Str)
 {
	 var alloweduser = "0123456789";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) != -1)
		{
		  totcount++;
		}
	 };

	 if(totcount!=0)
	 {
	   return(true);
	 }
     return(false);
 }







function isValidEmailId(email)
 {
	if (email == null)
	{
		return(false);
	}
	else if(email == '')
	{
		return(false) ;
	}
	else if ( (trim(email).indexOf('@') == -1) ||
			  (trim(email).indexOf('@') == 0) ||
			  (trim(email).indexOf('@') == (trim(email).length-1) ||  trim(email).indexOf('@',(trim(email).indexOf('@')+1))!=-1))
	{
		return(false);
	}
	else if (hasSpecChar(email))
	{
		return(false) ;
	}
	else
	{
		return(true) ;
	};
 }





function trim(Str)
 {
   if (!(isBlank(Str)))
   {
	  while(''+Str.charAt(0)==' ')
	  Str=Str.substring(1,Str.length);
	  while(''+Str.charAt(Str.length-1)==' ')
	  Str=Str.substring(0,Str.length-1);
	  return(Str);
   }
   else
   { return ('');
   };
 }



 function hasSpecChar(Str)
 {
	var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@.- ";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  return(true);
		}

	 };
	 return(false);
 }




 function inValidString(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  return(true);
		}

	 };
	 return(false);
 }



 function invalidNumber(Str)
 {
	 var alloweduser = "0123456789";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}
	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
   return(false);
 }


 function invalidPhoneNumber(Str)
 {
	 var alloweduser = "0123456789()- xX+";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}
	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
   return(false);
 }




















 function invalidUserName(Str)
 {
	 var alloweduser = "abcdefghijklmnopqrstuvwxyz0123456789_";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
			return(true);
		}
	 };

 }

function inValidZip(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- ";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}

	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
	 return(false);
 }



function inValidAddress(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- #,/()";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}

	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
	 return(false);
 }



function inValidCity(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}

	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
	 return(false);
 }







