//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('Enter a valid Email address.');
      thisForm.email.focus();
      return(false);
   } 
   else if(thisForm.promocode.value!=null && thisForm.promocode.value!="")
	{
       thisForm.promocode.value=checkAndReplace(thisForm.promocode.value);
	}
   else 
   {
	  thisForm.email.value=checkAndReplace(thisForm.email.value);
      return true;
   }


}



//For Feedback Form
function confirmFeedback(thisForm) 
{ 
   if(isBlank(thisForm.user_id.value)) 
   {  alert("Enter a valid Username.");
      thisForm.user_id.focus();
	  return false; 
   } 
   
   else if(!isValidEmailId(thisForm.email.value))
   {
      alert('Enter a valid Email address.');
      thisForm.email.focus();
      return(false);
   } 

   else if((thisForm.os.value=='Others') && (thisForm.os_others.value==''))
   {
     alert('Select the Operating System.');
     thisForm.os_others.focus();
     return (false);
   

   }

   else
   { return true ;
   }
}




// For Forgot Password 

function confirmForgotPwd(thisForm) 
{ 
   if( (thisForm.user_id.value=='') && (thisForm.email.value==''))
    {
      alert('Enter Username or email address.');
      return (false);
    }
    else if( (thisForm.user_id.value!='') && (invalidUserName(thisForm.user_id.value)) )
    {
      alert('Username cannot have special characters. The characters allowed are a-z, 0-9 and _.');
      thisForm.user_id.focus();
      return (false);
    }
    else if( (thisForm.email.value!='') && (!isValidEmailId(thisForm.email.value)) )
   {
     alert('Enter a valid Email address.');
      thisForm.email.focus();
      return(false);
   } 
   else
   { 
     
	  return (true);
   }
}



function confirmChangePwd(thisForm) 
{ 
   if(isBlank(thisForm.user_passwd.value))
   {
      alert('Enter the 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 < 4) || (thisForm.user_passwd.value.length > 16))
   {
       alert('Password must be between 4 to 16 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('Enter the 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('Enter the 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('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('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('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('Enter the 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('Enter the 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('Enter the Zip code.');
	  thisForm.zip.focus();
	  return (false);
   }

   

   else if(inValidZip(thisForm.zip.value))
   {    
          alert('Zip code 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(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('Enter a valid Email address.');
        thisForm.email.focus();
        return(false);
   }
     else if (thisForm.firstname.value =='')
     {
	 alert('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('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('Enter the 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 (isBlank(thisForm.city.value))
     {
        alert('Enter the 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('Enter the Zip code.');
	  thisForm.Zip.focus();
	  return (false);
     }
     else if(inValidZip(thisForm.Zip.value))
     {    
          alert('Zip code can contain only A-Z, a-z ,0-9 , - and blank space.');
	  thisForm.Zip.focus();
          return (false);
     }
    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);
 }


/* this is old method...

function checkAndReplace(str)
{
	var ch ='';
	var j;
	
	if(str=='')
	{
		return '';
	}
	else
	{
	
		for(var i=0;i<str.length;i++)
		{
			
			j = 0;
			if(str.charAt(i)=='\'')
			{
				j++;
			}

			if(str.charAt(i)=='<')
			{
				j++;
			}

			if(str.charAt(i)=='>')
			{
				j++;
				
			}

			if(str.charAt(i)=='\(')
			{
				j++;
				
			}

			if(str.charAt(i)=='\)')
			{
				j++;
				
			}

			if(j == 0)
			{
				ch = ch + str.charAt(i);
			}
			j = 0;
			
		}
	}

	return ch;
}*/



function checkAndReplace(str)
{
	var ch ='';
	var j;
	
	if(str=='')
	{
		return '';
	}
	else
	{
	
		for(var i=0;i<str.length;i++)
		{
			
			j = 0;
			if(str.charAt(i)=='\'')
			{
				j++;
			}

			if(str.charAt(i)=='<')
			{
				j++;
			}

			if(str.charAt(i)=='>')
			{
				j++;
				
			}

			if(str.charAt(i)=='(')
			{
				j++;
				
			}

			if(str.charAt(i)==')')
			{
				j++;
				
			}

			if(str.charAt(i)=='%')
			{
				j++;
				
			}
			if(str.charAt(i)=='+')
			{
				j++;
				
			}

			if(str.charAt(i)=='"')
			{
				j++;
				
			}

			if(str.charAt(i)=='&')
			{
				j++;
				
			}

			if(j == 0)
			{
				ch = ch + str.charAt(i);
			}
			j = 0;
			
		}
	}

	return ch;
}
