function validate()
{

	myDate = new Date();

	if(trim(document.getElementById('user').value)=="")
	{
		alert("Please specify Email Address.");
		document.getElementById('user').focus();
		return false;
		
	}
	
	
	var contactEmail = trim(document.getElementById('user').value);
	if(contactEmail !="")
	{
		if(!checkEmail(contactEmail,null,"Please enter a valid Email Address."))
		{
			document.getElementById('user').focus();
			return false;
		}
	}	
	
	if(document.getElementById('user').value.length < 6)
	{
		alert("User name should be minimum 6 characters");
		document.getElementById('user').focus();
		return false;
		
	}
	if(trim(document.getElementById('password').value) =="")
	{
		alert("Please specify Password.");
		document.getElementById('password').focus();
		return false;
		
	}
	if(document.getElementById('password').value.length < 6 )
	{
		alert("Password should not be less then 6 characters");
		document.getElementById('password').focus();
		return false;
		
	}
	if(trim(document.getElementById('cPassword').value )=="")
	{
		alert("Please confirm your Password.");
		document.getElementById('cPassword').focus();
		return false;
		
	}
	if(trim(document.getElementById('cPassword').value ) != trim(document.getElementById('password').value))
	{
		alert("Password doesn't matches.");
		document.getElementById('cPassword').focus();
		return false;
	}
	
	
	if(trim(document.getElementById('firstname').value )=="")
	{
		alert("Please specify First Name.");
		document.getElementById('firstname').focus();
		return false;
		
	}
	if(trim(document.getElementById('lastname').value )=="")
	{
		alert("Please specify Last Name.");
		document.getElementById('lastname').focus();
		return false;
		
	}
	
	
	/*
	if(trim(document.getElementById('email').value )=="")
	{
		alert("Please specify email address.");
		document.getElementById('email').focus();
		return false;
		
	}
	
	
	var contactEmail = trim(document.getElementById('email').value);
	if(contactEmail !="")
	{
		if(!checkEmail(contactEmail,null,"Please enter valid email address."))
		{
			document.getElementById('email').focus();
			return false;
		}
	}	
	
	*/
	
	if(document.getElementById('phone').value=="")
	{
		alert("Please specify Phone.");
		document.getElementById('phone').focus();
		return false;
		
	}

	if(!isValidPhone(trim(document.getElementById('phone').value))){
			alert("Please specify valid Phone.");
			document.getElementById('phone').focus();
			return false;
	}
	
	if(document.getElementById('companyAdd').value =="")
	{
		alert("Please specify Address1.");
		document.getElementById('companyAdd').focus();
		return false;
		
	}
	if(document.getElementById('companyCity').value =="")
	{
		alert("Please specify City.");
		document.getElementById('companyCity').focus();
		return false;
		
	}

	
	
	if(document.getElementById('companyState').value =="")
	{
		alert("Please specify State / Province.");
		document.getElementById('companyState').focus();
		return false;
		
		
	}
	if(document.getElementById('companyZip').value =="")
	{
		alert("Please specify Zip / Postal Code .");
		document.getElementById('companyZip').focus();
		return false;
		
		
	}
	
	
	if(document.getElementById('country').value =="")
	{
		alert("Please specify Country.");
		document.getElementById('country').focus();
		return false;
		
	}
	
	/*
	if(!isValidNumber(trim(document.getElementById('companyZip').value))){
			alert("Please specify valid Zip No.");
			document.getElementById('companyZip').focus();
			return false;
	}
	*/
	
	
		if(trim(document.getElementById('ccNumber').value )=="")
	{
		alert("Please specify Credit Card Number.");
		document.getElementById('ccNumber').focus();
		return false;
		
	}
	
	
	if(!isValidCc(trim(document.getElementById('ccNumber').value))){
			alert("Please specify valid Credit Card Number.");
			document.getElementById('ccNumber').focus();
			return false;
	}
	
	if(document.getElementById('ccNumber').value.length < 16)
	{
		alert("Enter Card Number with 16 digits.");
		document.getElementById('ccNumber').focus();
		return false;
		
	}
	
	
	/*
	if(document.getElementById('ccVarifyCode').value.length != 4)
	{
		alert("Please enter valid Varify Code Number.");
		document.getElementById('ccVarifyCode').focus();
		return false;
		
	}
	*/
	
	
	
	
	if(trim(document.getElementById('ccName').value )=="")
	{
		alert("Please specify Name of card.");
		document.getElementById('ccName').focus();
		return false;
		
	}
/*	if(trim(document.getElementById('ccName').value )=="Visa")
	{
				if(document.getElementById('ccVarifyCode').value.length != 4)
				{
				alert("Please enter valid Varify Code Number for Visa card.");
				document.getElementById('ccVarifyCode').focus();
				return false;
				
				}
		
//		return false;
		
	}
	if(trim(document.getElementById('ccName').value )=="Mastercard")
	{
				if(document.getElementById('ccVarifyCode').value.length != 4)
				{
				alert("Please enter valid Varify Code Number for Mastercard card.");
				document.getElementById('ccVarifyCode').focus();
				return false;
				
				}
		//return false;
		
	}
	if(trim(document.getElementById('ccName').value )=="Amex")
	{
				if(document.getElementById('ccVarifyCode').value.length != 3)
				{
				alert("Please enter valid Varify Code Number for Ameican express card.");
				document.getElementById('ccVarifyCode').focus();
				return false;
				
				}
				
		//return false;
		
	}
	
	
	if(trim(document.getElementById('ccVarifyCode').value )=="")
	{
		alert("Please specify Varify Code Number.");
		document.getElementById('ccVarifyCode').focus();
		return false;
		
	}
	*/
	//alert(document.getElementById('ccName').value);

	if(trim(document.getElementById('ccVarifyCode').value )=="")
	{
		alert("Please specify Card Verification Code.");
		document.getElementById('ccVarifyCode').focus();
		return false;
		
	}
	if(!isValidCc(trim(document.getElementById('ccVarifyCode').value))){
			alert("Please specify a valid Card Verification Code.");
			document.getElementById('ccVarifyCode').focus();
			return false;
	}
	if(document.getElementById('ccName').value!=""){
	if((document.getElementById('ccName').value == 'Visa' || document.getElementById('ccName').value == 'Mastercard') && document.getElementById('ccVarifyCode').value.length != 3)
	{
		alert("Please enter a valid Card Verification Code.");
		document.getElementById('ccVarifyCode').focus();
		return false;
	}
	if(document.getElementById('ccName').value == 'Amex' && document.getElementById('ccVarifyCode').value.length != 4 )
	{
		alert("Please enter a valid Card Verification Code.");
		document.getElementById('ccVarifyCode').focus();
		return false;
		
	}
	}
	
	if(trim(document.getElementById('edMM').value )=="")
	{
		alert("Please specify Expiry Month.");
		document.getElementById('edMM').focus();
		return false;
		
	}
	if(trim(document.getElementById('edYY').value )=="")
	{
		alert("Please specify Expiry Year.");
		document.getElementById('edYY').focus();
		return false;
		
	}




	if( (trim(document.getElementById('edMM').value ) <= (myDate.getMonth()+1))  && (trim(document.getElementById('edYY').value ) <= myDate.getFullYear())  )
	{
		alert("Expiry date should be future date.");
		document.getElementById('edMM').focus();
		return false;
		
	}
	else if( (trim(document.getElementById('edMM').value ) > (myDate.getMonth()+1))  && (trim(document.getElementById('edYY').value ) < myDate.getFullYear())  )
	{
		alert("Expiry date should be future date.");
		document.getElementById('edMM').focus();
		return false;
		
	}


	return true;
}


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}



function checkEmail(field,excval,errstmt){
var emailregex=/^[\w]+\+?\w*@[\w]+\.[\w.]+\w$/;
var match=field.match(emailregex);
     if (!match) {
          if (errstmt) alert(errstmt);
          if (excval) eval(excval);
          return false;
     }else return true;
}

function isValidNumber(strVal, strMsg){
	var sValidChars = "0123456789";
	var strCompareVal = new String(strVal);
	var blnReturn = true
	var i = new Number(0);
	while ((blnReturn) && (i < strCompareVal.length))
    {
		blnReturn = (sValidChars.indexOf(strCompareVal.charAt(i)) >= 0)
		i++
    }
	return (blnReturn)
}//end of validCrdeit cardCharacter function	


function isValidZip(strVal, strMsg){
	var sValidChars = "0123456789";
	var strCompareVal = new String(strVal);
	var blnReturn = true
	var i = new Number(0);
	while ((blnReturn) && (i < strCompareVal.length))
    {
		blnReturn = (sValidChars.indexOf(strCompareVal.charAt(i)) >= 0)
		i++
    }
	return (blnReturn)
}//end of validNameCharacter function	




function validateLogin(){
	var userName = document.getElementById('user');
	var password = document.getElementById('password');
	if(validLength ( trim(userName.value),"Please specify your user name." ) == false ){
		userName.focus();
		return false;
	}else if(validLength ( trim(password.value),"Please specify your password." ) == false ){
		password.focus();
		return false;
	}
	return true;
}//end of validateAdmin function
function validLength ( strVal, strMsg ) {
  if ( strVal.length < 1) {
		alert( strMsg );
		return false;
  }  //End of IF
  
} //End of FUNC validLength


function isValidPhone(strVal, strMsg){
	var sValidChars = "0123456789- xXeEtT";
	var strCompareVal = new String(strVal);
	var blnReturn = true
	var i = new Number(0);
	while ((blnReturn) && (i < strCompareVal.length))
    {
		blnReturn = (sValidChars.indexOf(strCompareVal.charAt(i)) >= 0)
		i++
    }
	return (blnReturn)
}//end of validPhoneCharacter function	

function isValidCc(strVal, strMsg){
	var sValidChars = "0123456789";
	var strCompareVal = new String(strVal);
	var blnReturn = true
	var i = new Number(0);
	while ((blnReturn) && (i < strCompareVal.length))
    {
		blnReturn = (sValidChars.indexOf(strCompareVal.charAt(i)) >= 0)
		i++
    }
	return (blnReturn)
}//end of validCrdeit cardCharacter function	

