function trim(str) {
     str = str.replace(/^\s+/, ""); // beginning spaces are convert to an empty string

     str = str.replace(/\s+$/, ""); // ending spaces are convert to an empty string

     return(str);
}

// Validation for reg form step1
function regfrm()
 { 

    var errorMsg = "";	
	
	if ( trim(document.first_step.name.value) == "")
	{
		alert("Enter your First Name");
		document.first_step.name.focus();
		return false;
	}
	if ( document.first_step.name.value.charAt(0) == " ")
	{
		alert("First Name Should Not Contain Blank Spaces at the begininig");
		document.first_step.name.focus();
		return false;
	}
	
	validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.name.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("First Name Accepts only Characters");
		document.first_step.name.focus();
		return false
	}
	
    if ( trim(document.first_step.surname.value) == "")
	{
		alert("Enter Surname");
		document.first_step.surname.focus();
		return false;
	}
	if (document.first_step.surname.value.charAt(0) == " ")
	{
		alert("Surname Should Not Contain Blank Spaces at the begininig");
		document.first_step.surname.focus();
		return false;
	}

	validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.surname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Surname.");
		document.first_step.surname.focus();
		return false
	}
	
	if (document.first_step.day.value == "") 
	{
	    alert("Select A Day");
		document.first_step.day.focus();
        return false;		
	}
	if (document.first_step.month.value== "") 
	{
	    alert("Select the Month");
		document.first_step.month.focus();
        return false;		
	}
	if (document.first_step.year.value == "") 
	{
	    alert("Select the Year");
		document.first_step.year.focus();
        return false;		
	}
	
	if(document.first_step.day.value != "" && document.first_step.month.value != "" && document.first_step.year.value != "")
	{
		day = document.first_step.day.value;
		month = document.first_step.month.value;
		year = document.first_step.year.value;
		chkdate=month+'/'+day+'/'+year;
		
		if(isDate(chkdate) == false)
		{
			document.first_step.day.focus();
			return false;
		}
	}
	
	if (document.first_step.email.value=="")
		{
						alert("Enter your Email Id");
						document.first_step.email.focus();
					  return false;
			
		}
		if (document.first_step.email.value!="")
		{
		validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
  		strEmail = document.first_step.email.value;
		if (strEmail.search(validRegExp) == -1) 
 		{
						alert("Invalid email");
						document.first_step.email.focus();
						return false
					
 		}		

 }
	
					
/*if (document.first_step.telephone.value.length == "") 
	{
	    alert("Enter telephone number");
		document.first_step.telephone.focus();
        return false;		
	}

	validRegExp = /^[0]+$/i;
	strName = trim(document.first_step.telephone.value);
	if( strName.search(validRegExp) == "0"){
		alert("Invalid telephone number");
		document.first_step.telephone.focus();
		return false;
	}
	if (document.first_step.telephone.value.length<5) 
	{
	   alert("Telephone number must be greater than 5 digits");
		document.first_step.telephone.focus();
        return false;		
	}
	if (document.first_step.telephone.value.length>2) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.telephone.value;
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			alert("Invalid telephone number");
			document.first_step.telephone.focus();
            return false;			
		}
	}

if (document.first_step.mobile.value == "") 
	{
	   alert("Enter mobile number");
	   document.first_step.mobile.focus();
	   return false;
	}
if (document.first_step.mobile.value.length<8) 
	{
	   alert("Mobile number must be greater than 8 digits");
	   document.first_step.mobile.focus();
	   return false;
	}
if (document.first_step.mobile.value.length>8) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.mobile.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid mobile Number");
				document.first_step.mobile.focus()
             return false;
		}

}
	
	if (document.first_step.country.value == "") 
	{
	    alert("Select country");
		document.first_step.country.focus();
        return false;		
	}
	/*validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.country.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid country.");
		document.first_step.country.focus();
		return false
	}
*/
	
/*
if (document.first_step.fax.value.length<2) 
	{
	   alert("Enter fax number");
		document.first_step.fax.focus();
        return false;		
	}

if (document.first_step.fax.value.length>2) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.fax.value;
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			alert("Invalid fax number");
			document.first_step.fax.focus();
            return false;			
		}
	}
*/	

if (document.first_step.address1.value == "")
	{
		alert("Please enter your Address");
		document.first_step.address1.focus()
		return false;
	}
if (document.first_step.town.value == "")
	{
		alert("Please enter your Town");
		document.first_step.town.focus()
		return false;
	}
 if (document.first_step.username.value == "")
	{
		alert("Please enter your Username");
		document.first_step.username.focus()
		return false;
	}
if (document.first_step.username.value.length<6 ||  document.first_step.username.value.length>16 )
{
	alert("Username  must be between 6 and 15 characters");  
	document.first_step.username.focus();
	return false;
}
 if (document.first_step.password.value == "")
	{
		alert("Please enter your Password");
		document.first_step.password.focus()
		return false;
	}
if (document.first_step.password.value.length<6 || document.first_step.password.value.length>9 )
{
	alert("Password must be between 6 and 8 characters");  
	document.first_step.password.focus();
	return false;
}

 if (document.first_step.conpassword.value == "")
	{
		alert("Enter Confirm Password");
		document.first_step.conpassword.focus()
  		return false;
	}

if (document.first_step.conpassword.value.length<5 ||  document.first_step.password.value.length<5 )
{
	alert("Length must be between 6 and 8 characters");  
	document.first_step.conpassword.focus();
	return false;
}

 if (document.first_step.conpassword.value != "" && document.first_step.password.value != "")
	{
	  if (document.first_step.password.value!==document.first_step.conpassword.value)
		{
			alert("Check confirm password");
			document.first_step.conpassword.focus();
            return false;
		}		
	}

if (document.first_step.accept.checked == false)
	{
		alert("Accept the terms and Conditions and privacy policy");
		document.first_step.accept.checked = true;
  		return false;
	}

if (errorMsg != "")
 {	
	return false;
 }	
 
return true;
/*
if (document.first_step.zip.value=="") 
	{
	   alert("Enter Zip code");
       document.first_step.zip.focus();
	   return false; 		
    }
if (document.first_step.zip.value.length<4) 
	{
	   alert("Enter valid Zip code");
       document.first_step.zip.focus();
	   return false; 		
    }

if (document.first_step.zip.value.length>2) 
{
	var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrsruvwxyz ";
	var checkStr = document.first_step.zip.value;
	
	var allValid = true;
	for (i=0;i<checkStr.length;i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;j < checkOK.length;j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	}
	if (!allValid)
	{
		alert("Invalid zip code");
		document.first_step.zip.focus();
		return false;		
	}
}
*/

/*if (document.first_step.security_question.value == "")
	{
		alert("Enter Confirm Password");
		document.first_step.security_question.focus()
  		return false;
	}
if (document.first_step.security_answer.value == "")
	{
		alert("Enter Security answer ");
		document.first_step.security_answer.focus()
  		return false;
	}




	 if(document.getElementById( "display1" ).style.display=="")
			{
					if(document.first_step.card_name.value == "")
					{
					alert("Select A Card");
					document.first_step.card_name.focus();
					return false;
					}
					if(document.first_step.card_number.value == "")
					{
					alert("Enter the Card Number");
					document.first_step.card_number.focus();
					return false;
					}
					
					
						var checkOK = "0123456789";
						var checkStr = document.first_step.card_number.value;
						
						var allValid = true;
						
						for (i=0;i<checkStr.length;i++)
						{
							ch = checkStr.charAt(i);
							for (j = 0;j < checkOK.length;j++)
								if (ch == checkOK.charAt(j))
								break;
								if (j == checkOK.length)
								{
									allValid = false;
									break;
								}
						}
						
						if (!allValid)
						{
							 alert("Enter only the numbers");
								document.first_step.card_number.focus()
							 return false;
						}
					
					if(checkStr.length<15 || checkStr.length>16){
							alert("Card Number should be maximum 15 or 16");
							document.first_step.card_number.focus()
							return false;						  
						}
					if(document.first_step.exp_month.value == "")
					{
					alert("Select Expire Month");
					document.first_step.exp_month.focus();
					return false;
					}
								
					if(document.first_step.exp_year.value == "")
					{
					alert("Select Expire Year");
					document.first_step.exp_year.focus();
					return false;
					}
					
					if(document.first_step.exp_month.value != "" )
					{
						var d = new Date();
						var currentmonth = d.getMonth();
						var curyear=d.getFullYear();
							if(document.first_step.exp_month.value.charAt(0)==0){
							expmonth=document.first_step.exp_month.value.charAt(1);
							}
							else{expmonth=document.first_step.exp_month.value;
							}
					 
						if(document.first_step.exp_year.value < curyear){
						alert("Selected Expire Year should be greater than the current Year");
						document.first_step.exp_month.focus();
						return false;
						}
						
						if(document.first_step.exp_year.value == curyear){
						
							if(expmonth<(currentmonth+2)){
							alert("Selected Expire Month should be greater than the current month");
							document.first_step.exp_month.focus();
							return false;
							}
						}
							
					}
					
					if(document.first_step.card_holder_name.value == "")
					{
					alert("Enter the Card Holder Name");
					document.first_step.card_holder_name.focus();
					return false;
					}
					validRegExp = /^[a-z ]+$/i;
					strName = trim(document.first_step.card_holder_name.value);
					if ( strName.search(validRegExp) == -1)
					{
						alert("Please enter valid Card Holder Name");
						document.first_step.card_holder_name.focus();
						return false
					}
					
					if(document.first_step.security_number.value == "")
					{
					alert("Enter the Security Number");
					document.first_step.security_number.focus();
					return false;
					}
						var checkOK = "0123456789";
						var checkStr = document.first_step.security_number.value;
						
						var allValid = true;
						for (i=0;i<checkStr.length;i++)
						{
							ch = checkStr.charAt(i);
							for (j = 0;j < checkOK.length;j++)
								if (ch == checkOK.charAt(j))
								break;
								if (j == checkOK.length)
								{
									allValid = false;
									break;
								}
						}
						if (!allValid)
						{
							 alert("Enter only numbers in Security Code");
								document.first_step.security_number.focus()
							 return false;
						}
						if(checkStr.length !=3){
							alert("Security Number should be 3 numbers");
							document.first_step.security_number.focus()
							return false;						  
						}
				
	}

*/


}
// validation form step2

// Add fund form validation starts here
function addfundfrmcheck()
{
	
	if(document.addfundfrm1.payment_method.value == "")
	{
	alert("Select A Payment Method");
	document.addfundfrm1.payment_method.focus();
	return false;
	}
	
	if(document.addfundfrm1.amount.value == "")
	{
	alert("Enter the amount");
	document.addfundfrm1.amount.focus();
	return false;
	}
	
		var checkOK = "0123456789";
		var checkStr = document.addfundfrm1.amount.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid Amount");
			 	
				document.addfundfrm1.amount.select();
             return false;
		}
		
		if(document.addfundfrm1.amount.value != ""){
		
		if(parseInt(document.addfundfrm1.amount.value) <=0){
		alert("Enter the amount greater than Zero");
		document.addfundfrm1.amount.select();
		return false;
		}
		}
		
	
			if(document.addfundfrm1.checkpassword.value == "")
			{
			alert("Enter the Password");
			document.addfundfrm1.checkpassword.focus();
			return false;
			}
		
			
			
	
	
				
				
		return true;
}

// Add fund form validation ENDS here

// WITHDRAW FUND VALIDATION STARTS HERE

function withdrawfundfrmcheck()
{
	
	
	if(document.withdrawfundfrm1.amount.value == "")
	{
	alert("Enter the amount");
	document.withdrawfundfrm1.amount.focus();
	return false;
	}
	
	
		var checkOK = "0123456789.";
		var checkStr = document.withdrawfundfrm1.amount.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid Amount");
			 	
				document.withdrawfundfrm1.amount.select();
             return false;
		}
		
			if(document.withdrawfundfrm1.checkpassword.value == "")
			{
			alert("Enter the Password");
			document.withdrawfundfrm1.checkpassword.focus();
			return false;
			}
		
		if(document.withdrawfundfrm1.amount.value != ""){
		
		if(parseInt(document.withdrawfundfrm1.amount.value) <=0){
		alert("Enter the amount greater than Zero");
		document.withdrawfundfrm1.amount.select();
		return false;
		}
		
		if(parseInt(document.withdrawfundfrm1.amount.value) > parseInt(document.withdrawfundfrm1.available_withdrawal.value)){
		alert("Withdrawal amount should not be greater than the total available for withdrawal");
		document.withdrawfundfrm1.amount.select();
		return false;
		}
		
		if(document.withdrawfundfrm1.amount.value > document.withdrawfundfrm1.winnings_held.value){
		
		var amt = document.withdrawfundfrm1.amount.value;
		var amt_won = document.withdrawfundfrm1.winnings_held.value;
		var amt_stake = document.withdrawfundfrm1.stake_money.value;
		
		admin_percentage = (amt-amt_won)/5;
		amt_can_withdraw = (amt-admin_percentage);
		
		return confirm("Please be aware that withdrawal of Stake monies\nwill incur a 20% admin charge;\nwinnings do not encounter this charge.\n\n You will be getting only "+amt_can_withdraw+"\n\nAre you sure to withdraw the amount?");
		
		}
		
		}
		
	
			
				
				
		return true;
}
 
 //WITHDRAW FUNDVALIDATION ENDS HERE

//TRANSFER VALIDATION STARTS HERE

function teansferfundfrmcheck()
{
	
	
	if(document.transferfundfrm1.amount.value == "")
	{
	alert("Enter the amount");
	document.transferfundfrm1.amount.focus();
	return false;
	}
	
			
	
		var checkOK = "0123456789.";
		var checkStr = document.transferfundfrm1.amount.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid Amount");
			 	
				document.transferfundfrm1.amount.select();
             return false;
		}
		if(document.transferfundfrm1.checkpassword.value == "")
			{
			alert("Enter the Password");
			document.transferfundfrm1.checkpassword.focus();
			return false;
			}
			
		
		if(document.transferfundfrm1.amount.value != ""){
		if(parseFloat(document.transferfundfrm1.amount.value) <=0){
		alert("Enter the amount greater than Zero");
		document.transferfundfrm1.amount.select();
		return false;
		}
		
		if(parseFloat(document.transferfundfrm1.amount.value) > parseFloat(document.transferfundfrm1.winnings_held.value)){
		alert("Transfer amount should not be greater than the Winning amount");
		document.transferfundfrm1.amount.select();
		return false;
		}
		
				
		}
		
	
			
				
				
		return true;
}
 

//TRANSFER VALIDATION ENDS HERE


// Money add form(Credit card form check)
function moneyfrmcheck()
{
	if(document.addmoneyfrm1.amount.value == "")
	{
	alert("Enter the amount");
	document.addmoneyfrm1.amount.focus();
	return false;
	}
	
		var checkOK = "0123456789";
		var checkStr = document.addmoneyfrm1.amount.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid Amount");
				document.addmoneyfrm1.amount.focus()
             return false;
		}
		
		
	if(document.addmoneyfrm1.card_name.value == "")
			{
			alert("Select A Card");
			document.addmoneyfrm1.card_name.focus();
			return false;
			}
			if(document.addmoneyfrm1.card_number.value == "")
			{
			alert("Enter the Card Number");
			document.addmoneyfrm1.card_number.focus();
			return false;
			}
			
			
				var checkOK = "0123456789";
				var checkStr = document.addmoneyfrm1.card_number.value;
				
				var allValid = true;
				
				for (i=0;i<checkStr.length;i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;j < checkOK.length;j++)
						if (ch == checkOK.charAt(j))
						break;
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
				}
				
				if (!allValid)
				{
					 alert("Enter only the numbers");
						document.addmoneyfrm1.card_number.focus()
					 return false;
				}
			
			if(checkStr.length<15 || checkStr.length<16){
					alert("Card Number should be maximum 15 or 16");
					document.addmoneyfrm1.card_number.focus()
					return false;						  
				}
			if(document.addmoneyfrm1.exp_month.value == "")
			{
			alert("Select Expire Month");
			document.addmoneyfrm1.exp_month.focus();
			return false;
			}
			if(document.addmoneyfrm1.exp_year.value == "")
			{
			alert("Select Expire Year");
			document.addmoneyfrm1.exp_year.focus();
			return false;
			}
			if(document.addmoneyfrm1.card_holder_name.value == "")
			{
			alert("Enter the Card Holder Name");
			document.addmoneyfrm1.card_holder_name.focus();
			return false;
			}
			validRegExp = /^[a-z ]+$/i;
			strName = trim(document.addmoneyfrm1.card_holder_name.value);
			if ( strName.search(validRegExp) == -1)
			{
				alert("Please enter valid Card Holder Name");
				document.addmoneyfrm1.card_holder_name.focus();
				return false
			}
			
			if(document.addmoneyfrm1.security_number.value == "")
			{
			alert("Enter the Security Number");
			document.addmoneyfrm1.security_number.focus();
			return false;
			}
				var checkOK = "0123456789";
				var checkStr = document.addmoneyfrm1.security_number.value;
				
				var allValid = true;
				for (i=0;i<checkStr.length;i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;j < checkOK.length;j++)
						if (ch == checkOK.charAt(j))
						break;
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
				}
				if (!allValid)
				{
					 alert("Enter only numbers in Security Code");
						document.addmoneyfrm1.security_number.focus()
					 return false;
				}
				if(checkStr.length !=3){
					alert("Security Number should be 3 numbers");
					document.addmoneyfrm1.security_number.focus()
					return false;						  
				}
				
		return true;
}
// END OF CREDIT CARD FORM


//SCRIPT FOR FORGOT LOGIN DETAILS
function forgotfrm()
 { 

    var errorMsg = "";	

	if ( trim(document.first_step.name.value) == "")
	{
		alert("Enter your Name");
		document.first_step.name.focus();
		return false;
	}
	
	validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.name.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Name");
		document.first_step.name.focus();
		return false
	}
	
    if ( trim(document.first_step.surname.value) == "")
	{
		alert("Enter Surname");
		document.first_step.surname.focus();
		return false;
	}

	validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.surname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Surname.");
		document.first_step.surname.focus();
		return false
	}
	
	if (document.first_step.day.value == "") 
	{
	    alert("Select A Day");
		document.first_step.day.focus();
        return false;		
	}
	if (document.first_step.month.value== "") 
	{
	    alert("Select the Month");
		document.first_step.month.focus();
        return false;		
	}
	if (document.first_step.year.value == "") 
	{
	    alert("Select the Year");
		document.first_step.year.focus();
        return false;		
	}
	
	if(document.first_step.day.value != "" && document.first_step.month.value != "" && document.first_step.year.value != "")
	{
		day = document.first_step.day.value;
		month = document.first_step.month.value;
		year = document.first_step.year.value;
		chkdate=month+'/'+day+'/'+year;
		
		if(isDate(chkdate) == false)
		{
			document.first_step.day.focus();
			return false;
		}
	}
	
	if (document.first_step.email.value=="")
		{
						alert("Enter your Email Id");
						document.first_step.email.focus();
					  return false;
			
		}
		if (document.first_step.email.value!="")
		{
		validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
  		strEmail = document.first_step.email.value;
		if (strEmail.search(validRegExp) == -1) 
 		{
						alert("Invalid email");
						document.first_step.email.focus();
						return false
					
 		}		

 }
	
 }
 
 //END OF SCRIPT FOR LOGIN DETAILS
 
function editfrm()
 { 

    var errorMsg = "";	

	if ( trim(document.first_step.name.value) == "")
	{
		alert("Enter your First Name");
		document.first_step.name.focus();
		return false;
	}
	
	validRegExp = /^[a-z ]+$/i;
	strName = trim(document.first_step.name.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid First Name");
		document.first_step.name.focus();
		return false
	}
	
    if ( trim(document.first_step.surname.value) == "")
	{
		alert("Enter Last Name");
		document.first_step.surname.focus();
		return false;
	}

	validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.surname.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Last Name.");
		document.first_step.surname.focus();
		return false
	}
	
	if (document.first_step.day.value.length == "") 
	{
	    alert("Select A Day");
		document.first_step.day.focus();
        return false;		
	}
	if (document.first_step.month.value.length == "") 
	{
	    alert("Select the Month");
		document.first_step.month.focus();
        return false;		
	}
	if (document.first_step.year.value.length == "") 
	{
	    alert("Select the Year");
		document.first_step.year.focus();
        return false;		
	}
	
	
	if(document.first_step.day.value != "" && document.first_step.month.value != "" && document.first_step.year.value != "")
	{
		day = document.first_step.day.value;
		month = document.first_step.month.value;
		year = document.first_step.year.value;
		chkdate=month+'/'+day+'/'+year;
		
		if(isDate(chkdate) == false)
		{
			document.first_step.day.focus();
			return false;
		}
	}
	
	
	
	
	if (document.first_step.email.value=="")
		{
						alert("Enter your Email Id");
						document.first_step.email.focus();
					  return false;
			
		}
		if (document.first_step.email.value!="")
		{
		validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
  		strEmail = document.first_step.email.value;
		if (strEmail.search(validRegExp) == -1) 
 		{
						alert("Invalid email");
						document.first_step.email.focus();
						return false
					
 		}		
		
		
		

 }
	
	
/*if (document.first_step.telephone.value.length == "") 
	{
	    alert("Enter telephone number");
		document.first_step.telephone.focus();
        return false;		
	}

	validRegExp = /^[0]+$/i;
	strName = trim(document.first_step.telephone.value);
	if( strName.search(validRegExp) == "0"){
		alert("Invalid telephone number");
		document.first_step.telephone.focus();
		return false;
	}
	if (document.first_step.telephone.value.length<5) 
	{
	   alert("Telephone number must be greater than 5 digits");
		document.first_step.telephone.focus();
        return false;		
	}
	if (document.first_step.telephone.value.length>2) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.telephone.value;
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			alert("Invalid telephone number");
			document.first_step.telephone.focus();
            return false;			
		}
	}

if (document.first_step.mobile.value == "") 
	{
	   alert("Enter mobile number");
	   document.first_step.mobile.focus();
	   return false;
	}
if (document.first_step.mobile.value.length<8) 
	{
	   alert("Mobile number must be greater than 8 digits");
	   document.first_step.mobile.focus();
	   return false;
	}
if (document.first_step.mobile.value.length>8) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.mobile.value;
		
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid mobile Number");
				document.first_step.mobile.focus()
             return false;
		}

}
	
	if (document.first_step.country.value.length == "") 
	{
	    alert("Select country");
		document.first_step.country.focus();
        return false;		
	}
	/*validRegExp = /^[a-z]+$/i;
	strName = trim(document.first_step.country.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid country.");
		document.first_step.country.focus();
		return false
	}
*/
	
/*
if (document.first_step.fax.value.length<2) 
	{
	   alert("Enter fax number");
		document.first_step.fax.focus();
        return false;		
	}

if (document.first_step.fax.value.length>2) 
	{
		var checkOK = "0123456789";
		var checkStr = document.first_step.fax.value;
		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			alert("Invalid fax number");
			document.first_step.fax.focus();
            return false;			
		}
	}
*/	

if (document.first_step.address1.value == "")
	{
		alert("Please enter your Address");
		document.first_step.address1.focus()
		return false;
	}
if (document.first_step.town.value == "")
	{
		alert("Please enter your Town");
		document.first_step.town.focus()
		return false;
	}
/*
if (document.first_step.zip.value=="") 
	{
	   alert("Enter Zip code");
       document.first_step.zip.focus();
	   return false; 		
    }
if (document.first_step.zip.value.length<4) 
	{
	   alert("Enter valid Zip code");
       document.first_step.zip.focus();
	   return false; 		
    }

if (document.first_step.zip.value.length>2) 
{
	var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrsruvwxyz ";
	var checkStr = document.first_step.zip.value;
	
	var allValid = true;
	for (i=0;i<checkStr.length;i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;j < checkOK.length;j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	}
	if (!allValid)
	{
		alert("Invalid zip code");
		document.first_step.zip.focus();
		return false;		
	}
}
*/

 if (document.first_step.username.value == "")
	{
		alert("Please enter your Username");
		document.first_step.username.focus()
		return false;
	}
if (document.first_step.username.value.length<6 ||  document.first_step.username.value.length>16 )
{
	alert("Length must be between 6 and 15 characters");  
	document.first_step.username.focus();
	return false;
}
 if (document.first_step.password.value == "")
	{
		alert("Please enter your Password");
		document.first_step.password.focus()
		return false;
	}
if (document.first_step.password.value.length<5 && document.first_step.password.value.length>9 )
{
	alert("Length must be between 6 and 8 characters");  
	document.first_step.password.focus();
	return false;
}

 if (document.first_step.conpassword.value == "")
	{
		alert("Enter Confirm Password");
		document.first_step.conpassword.focus()
  		return false;
	}

if (document.first_step.conpassword.value.length<5 ||  document.first_step.password.value.length<5 )
{
	alert("Length must be between 6 and 8 characters");  
	document.first_step.conpassword.focus();
	return false;
}

 if (document.first_step.conpassword.value != "" && document.first_step.password.value != "")
	{
	  if (document.first_step.password.value!==document.first_step.conpassword.value)
		{
			alert("Check confirm password");
			document.first_step.conpassword.focus();
            return false;
		}		
	}
/*if (document.first_step.security_question.value == "")
	{
		alert("Enter Confirm Password");
		document.first_step.security_question.focus()
  		return false;
	}
if (document.first_step.security_answer.value == "")
	{
		alert("Enter Security answer ");
		document.first_step.security_answer.focus()
  		return false;
	}*/
/*if (document.first_step.accept.checked == false)
	{
		alert("Accept the terms and Conditions and privacy policy");
		document.first_step.accept.checked = true;
  		return false;
	}*/
	
	
	 if(document.getElementById( "display1" ).style.display=="")
	{
			if(document.first_step.card_name.value == "")
			{
			alert("Select A Card");
			document.first_step.card_name.focus();
			return false;
			}
			if(document.first_step.card_number.value == "")
			{
			alert("Enter the Card Number");
			document.first_step.card_number.focus();
			return false;
			}
			
			
				var checkOK = "0123456789";
				var checkStr = document.first_step.card_number.value;
				
				var allValid = true;
				
				for (i=0;i<checkStr.length;i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;j < checkOK.length;j++)
						if (ch == checkOK.charAt(j))
						break;
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
				}
				
				if (!allValid)
				{
					 alert("Enter only the numbers");
						document.first_step.card_number.focus()
					 return false;
				}
			
			if(checkStr.length<15 || checkStr.length>16){
					alert("Card Number should be maximum 15 or 16");
					document.first_step.card_number.focus()
					return false;						  
				}
			if(document.first_step.exp_month.value == "")
			{
			alert("Select Expire Month");
			document.first_step.exp_month.focus();
			return false;
			}
						
			if(document.first_step.exp_year.value == "")
			{
			alert("Select Expire Year");
			document.first_step.exp_year.focus();
			return false;
			}
			
			if(document.first_step.exp_month.value != "" )
			{
				var d = new Date();
				var currentmonth = d.getMonth();
				var curyear=d.getFullYear();
					if(document.first_step.exp_month.value.charAt(0)==0){
					expmonth=document.first_step.exp_month.value.charAt(1);
					}
					else{expmonth=document.first_step.exp_month.value;
					}
			 
				if(document.first_step.exp_year.value < curyear){
				alert("Selected Expire Year should be greater than the current Year");
				document.first_step.exp_month.focus();
				return false;
				}
				
				if(document.first_step.exp_year.value == curyear){
				
					if(expmonth<(currentmonth+2)){
					alert("Selected Expire Month should be greater than the current month");
					document.first_step.exp_month.focus();
					return false;
					}
				}
					
			}
			
			if(document.first_step.card_holder_name.value == "")
			{
			alert("Enter the Card Holder Name");
			document.first_step.card_holder_name.focus();
			return false;
			}
			validRegExp = /^[a-z ]+$/i;
			strName = trim(document.first_step.card_holder_name.value);
			if ( strName.search(validRegExp) == -1)
			{
				alert("Please enter valid Card Holder Name");
				document.first_step.card_holder_name.focus();
				return false
			}
			
			if(document.first_step.security_number.value == "")
			{
			alert("Enter the Security Number");
			document.first_step.security_number.focus();
			return false;
			}
				var checkOK = "0123456789";
				var checkStr = document.first_step.security_number.value;
				
				var allValid = true;
				for (i=0;i<checkStr.length;i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;j < checkOK.length;j++)
						if (ch == checkOK.charAt(j))
						break;
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
				}
				if (!allValid)
				{
					 alert("Enter only numbers in Security Code");
						document.first_step.security_number.focus()
					 return false;
				}
				if(checkStr.length !=3){
					alert("Security Number should be 3 numbers");
					document.first_step.security_number.focus()
					return false;						  
				}
				
	}
	
	 

	if (errorMsg != "")
     {	
		return false;
	 }	
	return true;
}
// validation form step2
// Dynamic form validation 
function removeMessage() 
{
  if (document.all) 
  {
    var msg = document.all.msg;
    if (msg)
    msg.outerHTML = '';
  }
    else if (document.getElementById) {
    var msg = document.getElementById('msg');
    if (msg)
    msg.parentNode.removeChild(msg);
  }
}

function insertMessage (element, message) 
 {
  removeMessage();
  if (document.all) 
   {
    var html = '';
    html += '<SPAN ID="msg" CLASS="msg">' + message + '<\/SPAN>';
    element.insertAdjacentHTML('afterEnd', html);
   }
   else if (document.getElementById) 
   {
    var parent = element.parentNode;
    var span = document.createElement('SPAN');
    span.id = 'msg';
    span.className = 'msg';
    span.appendChild(document.createTextNode(message));
    parent.insertBefore(span, element.nextSibling);
   }
 }
function validateForm (form) {
 
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];
    if ((el.type.toLowerCase() == 'text'
        || el.type.toLowerCase() == 'textarea'
        || el.type.toLowerCase() == 'password')
        && el.value == '') {
      insertMessage(el, '<font face=verdana size=1 color=red><b>*</b></font>');
      el.focus();
      return false;
    }
    else if (el.type.toLowerCase().indexOf('select') != -1
             && el.selectedIndex == -1) {
      insertMessage(el, '*');
      el.focus();
      return false;
    }
  }
  return true;
}  
//End of dynamic form validation

// add new product step 2 validation form
function add_prod_step2()
 { 
    var errorMsg = "";	
	if ( trim(document.prod_add_step2.add_title.value) == "")
	{
		alert("Please enter the Title");
		document.prod_add_step2.add_title.focus();
        return false;
	}

	validRegExp = /^[a-z ]+$/i;
	strName = trim(document.prod_add_step2.add_title.value);
	if ( strName.search(validRegExp) == -1)
	{
		alert("Please enter valid Title.");
		document.prod_add_step2.add_title.focus();
		return false
	}


	if (document.prod_add_step2.currency.value == "")
	{
		alert("Please select Currency type");
		document.prod_add_step2.currency.focus()
        return false;		
	}
	validRegExp = /^[0]+$/i;
	strName = trim(document.prod_add_step2.price.value);
	if( strName.search(validRegExp) == "0"){
	   alert("Enter the valid Price");
	   document.prod_add_step2.price.focus();
       return false;
	}


if ( document.prod_add_step2.price.value.length <1 )
	{
	   alert("Enter the Price");
	   document.prod_add_step2.price.focus();
       return false;
	}

if (isNaN( trim(document.prod_add_step2.price.value) )) 
	{
		alert("Price should be numeric");
		document.prod_add_step2.price.focus();
		return false;			
	}


if (document.prod_add_step2.qty.value == "")
	{
		alert("Please enter Quantity");
		document.prod_add_step2.qty.focus();
        return false;
	}
 		
if (document.prod_add_step2.qty.value.length<1) 
	{
	    alert("Please enter Quantity");
        document.prod_add_step2.qty.focus();
	    return false; 
	}

if (document.prod_add_step2.qty.value.length !="" ) 
	{
		var checkOK = "0123456789";
		var checkStr = document.prod_add_step2.qty.value;

		var allValid = true;
		for (i=0;i<checkStr.length;i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;j < checkOK.length;j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
		}
		if (!allValid)
		{
			 alert("Invalid quantity");
			 document.prod_add_step2.qty.focus();
			 return false			
		}
}
	if (errorMsg != "")
    {		
		return false;
	}	
	return true;
}
// end of add new product setp2 validation 


// add new product step 3 validation form
function add_prod_step3(frm)
 { 
    var errorMsg = "";	
	if (document.prod_add_step3.start_date.value == "")
	{
		alert("Please pick start date");
         document.prod_add_step3.start_date.focus();
		 return false
	}
   if (document.prod_add_step3.end_date.value == "")
	{
		alert("Please pick end date");
        document.prod_add_step3.end_date.focus();
         return false 
	}
	// make sure start date is before the end date
	/*if (Date.parse(frm.start_date.value) > Date.parse(frm.end_date.value)) {
		alert("Invalid Date Range!\nStart Date cannot be after End Date!")
		return false;
	}*/
	date1 = new Array();
	date2 = new Array();
	date1 = frm.start_date.value.split("-");
	date2 = frm.end_date.value.split("-");

	if( date1[2] == date2[2]){
		if( date1[1] == date2[1]){
			if( date1[0] > date2[0]){
				alert("Invalid Date Range!\nStart Date cannot be after End Date!")
				return false
			}
		}else if( date1[1] > date2[1]){
			alert("Invalid Date Range!\nStart Date cannot be after End Date!")
			return false
		}
	}else if( date1[2] > date2[2]){
		alert("Invalid Date Range!\nStart Date cannot be after End Date!")
		return false
	}

	if (document.prod_add_step3.cont_email.checked==false )
	{
		if( frm.cont_email_txt.value == ""){
			alert("Please enter email");
			document.prod_add_step3.cont_email_txt.focus();
			document.prod_add_step3.cont_email.checked=true;
			return false;
		}else{
			document.prod_add_step3.cont_email.checked = true
		}
   }
  if (document.prod_add_step3.cont_email.checked==true )
	{
		validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
		strEmail = document.prod_add_step3.cont_email_txt.value;
        if (document.prod_add_step3.cont_email_txt .value == ""	)
		{ 
          alert("Please enter email address");
		  document.prod_add_step3.cont_email_txt.focus();
		  return false
        }
	   if (document.prod_add_step3.cont_email_txt.value != ""	)
		{ 
		  if (strEmail.search(validRegExp) == -1) 
			{
				alert("Check email address");
				document.prod_add_step3.cont_email_txt.focus();
				return false;				
			}		
	   }
    }

 if ( document.prod_add_step3.cont_state.checked==false)
	{
		if( frm.ShippingOriginCountry.value != ""){
			frm.cont_state.checked=true;
		}else{
			alert("Please select Country");
			document.prod_add_step3.ShippingOriginCountry.focus();
			document.prod_add_step3.cont_state.checked=true;
			return false;
		}
   }

 if ( document.prod_add_step3.cont_state.checked==true   )
	{
        if (document.prod_add_step3.ShippingOriginCountry.value=="")
		{
		  alert("Please select country");
          document.prod_add_step3.ShippingOriginCountry.focus();
          return false;
 		} 	
   }

 if ( document.prod_add_step3.cont_state.checked==true   )
	{
        if (document.prod_add_step3.ShippingOriginState.value=="0")
		{
		  alert("Please select State");
          document.prod_add_step3.ShippingOriginState.focus();
          return false;
 		} 
   }
   
  
   	return true;
}
// end of add new product setp3 validation 

// add new product step 3 validation form
function val_login()
 { 
    var errorMsg = "";	
	if (document.login.user_name.value == "")
	{
		alert("Enter your Username");
		document.login.user_name.focus();
        return false;
	} 		
   if (document.login.pwd.value == "")
	{
		alert("Enter your Password");
		document.login.pwd.focus();
        return false;
	}
	if (errorMsg != "")
    {
		return false;
    }	
	return true;
}
// end of add new product setp3 validation 

//for search form
function search_validate()
{	
	if(document.frm_search.txtSearch.value=="")
	{
		alert("Enter the text to describe your search");
		document.frm_search.txtSearch.focus();
		return false;
	}
}


// Validation for affiliate signup
function affiliatesignup1()
 { 

	if (document.affiliatesignup.fname.value == "")
	{
		alert("Enter your first name");
		document.affiliatesignup.fname.focus();
		return false;
	}

   if (document.affiliatesignup.acctype.value == "")
	{
		alert("Select accout type");
  		 document.affiliatesignup.acctype.focus();
		return false;
	}
   if (document.affiliatesignup.city.value == "")
	{
		alert("Enter city/town");
  		document.affiliatesignup.city.focus();
		return false;
	}
   if (document.affiliatesignup.state.value == "")
	{
		alert("Enter state");
  		document.affiliatesignup.state.focus();
		return false;
	}

	if (document.affiliatesignup.zipcode.value.length < 2) 
	{
	   alert("Enter Zipcode");
       document.affiliatesignup.zipcode.focus();
	   return false; 		
    }

	if (document.affiliatesignup.zipcode.value.length>2) 
	{
			var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrsruvwxyz ";
			var checkStr = document.affiliatesignup.zipcode.value;	
			var allValid = true;
			for (i=0;i<checkStr.length;i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;j < checkOK.length;j++)
					if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
			}
			if (!allValid)
			{
				 alert("Invalid zip code");
				document.affiliatesignup.zipcode.focus();
				 return false;		
			}
	}

	if (document.affiliatesignup.country.value == "")
	{
		alert("Select country");
		document.affiliatesignup.country.focus();
		return false;
	}

	if (document.affiliatesignup.telephone.value.length<2) 
	{
		   alert("Enter telephone number");
			document.affiliatesignup.telephone.focus();
			return false;		
	}

	if (document.affiliatesignup.telephone.value.length>2) 
	{
			var checkOK = "0123456789";
			var checkStr = document.affiliatesignup.telephone.value;
			var allValid = true;
			for (i=0;i<checkStr.length;i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;j < checkOK.length;j++)
					if (ch == checkOK.charAt(j))
					break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
			}
			if (!allValid)
			{
				alert("Invalid telephone number");
				document.affiliatesignup.telephone.focus();
				return false;			
			}
	}


	if (document.affiliatesignup.email.value=="")
	{
		alert(" Enter your email");
		document.affiliatesignup.email.focus();
		return false;		
	}

	if (document.affiliatesignup.email.value!="")
	{
	validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
	strEmail = document.affiliatesignup.email.value;
	if (strEmail.search(validRegExp) == -1) 
	{
		alert("Invalid email");
		document.affiliatesignup.email.focus();
		return false					
	}
  }	
	if (document.affiliatesignup.agree.checked == false)
	{
		alert("Please accept the agreement");
		return false;
	}
	return true;
}



var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }


