function checkFields(){		
	var flag=0;
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	for(var x=0; x<field.length; x++){	
		if(type[x]=='opt')var nn = document.thisForm[field[x]].options[document.thisForm[field[x]].selectedIndex].value;
		else if(type[x]=='radio'){flag=1
			for(i=0;i<document.thisForm[field[x]].length;i++){
				if(document.thisForm[field[x]][i].checked)flag=0}
		}
		else var nn=document.thisForm[field[x]].value			
		if((type[x]!='radio')&&(nn==""||nn=="null"||nn==null||nn==0))flag=1
		if(type[x]=='email'&& !re.test(nn))flag=1
		if((type[x]=='num')&&!checknumber(nn))flag=1			
		if(type[x]=='credit' && !checkCC(nn))flag=2
		if(flag>=1){
			if(flag==1)alert("A proper entry is required for the following:  "+name[x])+"  "
			if(type[x]!='radio')document.thisForm[field[x]].focus()
			return false;
		}		
	} 
	return true;
}
function checknumber(object_value){    
    if (object_value.length == 0) return true;
	var start_format = " .+-()0123456789";
	var number_format = " .-()0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	check_char = start_format.indexOf(object_value.charAt(0))
	if (check_char == 1) decimal = true;
	else if (check_char < 1) return false;
	for (var i = 1; i < object_value.length; i++){
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0) return false;
		else if (check_char == 1){
			if (decimal) return false;
			else decimal = true;
		}
		else if (check_char == 0){
			if (decimal || digits) trailing_blank = true;
		}
		else if (trailing_blank) return false;
		else digits = true;
	}	
    return true
}
function checkCC(object_value) {	
    CCNumber = object_value;
	NumberLength = object_value.length;	
    ShouldLength = "";
	NumberLeft = CCNumber.substr(0, 4);
	Accept=0
	PayMethod=document.thisForm.pay_option.options[document.thisForm.pay_option.selectedIndex].value;
	
	if ((NumberLeft >= 3400 && NumberLeft <= 3499) || (NumberLeft >= 3700 && NumberLeft <= 3799)) {     	
        if (PayMethod=="AMEX"){
			CardName = "American Express";
			ShouldLength = 15; 
			Accept=1;
		}
		else Accept=-1
	}	
    if (NumberLeft >= 4000 && NumberLeft <= 4999) {   		
		if (PayMethod=="VISA"){
			CardName = "VISA";		
			if (NumberLength > 14)  ShouldLength = 16; Accept=1;
			if (NumberLength < 14)  ShouldLength = 13; Accept=1;
			if (NumberLength == 14){
				msg_cc = "Number "+CCNumber+" is 14 digits long. ";
				msg_cc = msg_cc + "\n\nVisa cards usually have 16 digits, though some have 13. ";
				msg_cc = msg_cc + "\n\nPlease check the number and try again.";
				alert (msg_cc)
				return false;
			}  
		} 
		else Accept=-1   	
	}		
   	if (NumberLeft >= 5100 && NumberLeft <= 5599) {
     	if (PayMethod=="MAST"){
			CardName = "MasterCard";
			ShouldLength = 16;
        	Accept=1;
		}
		else Accept=-1
	}	
	if (NumberLeft == 6011) {
		if (PayMethod=="DISC"){
	     	CardName = "Discover/Novus";
			ShouldLength = 16;
	        Accept=1;
		}
		else Accept=-1
	}	
	
	if (Accept == -1){
		msg_cc="The payment method you selected does not correspond to the card number you entered."
		msg_cc=msg_cc+"\nPlease check the payment method and credit card number for accuracy."
		alert(msg_cc)
		return false;
	}	
	if (Accept != 1){
		if (NumberLeft.length == 1) dgt = "digit "+NumberLeft+" does" 
		else dgt = "digits "+NumberLeft+" do"
	    msg_cc = "The beginning "+dgt+" not match any credit card types we accept. ";
	    msg_cc = msg_cc  + "\n               Please check the credit card number for accuracy. ";
		alert(msg_cc)
	   	return false; 
	}  	
	if (NumberLength != ShouldLength) {
        Missing = (NumberLength - ShouldLength);
        if (Missing < 0) {
			dgt = "digits";
			if (Math.abs(Missing) ==  1) dgt = "digit";
            msg_cc = "The card number "+CCNumber+" appears to be a "+CardName+" number,\n but is missing ";
			msg_cc = msg_cc + Math.abs(Missing) + " "+dgt
			msg_cc = msg_cc + ". Please check the credit card number for accuracy. ";

        } else {
			dgt = "digits";
			if (Missing == 1) dgt = "digit" 
            msg_cc = "The card number "+CCNumber+" appears to be a "+CardName+" number,\nbut has "+Missing;
			msg_cc = msg_cc + " extra "+dgt+". Please check the credit card number for accuracy. ";
        }
		alert(msg_cc)
        return false;
    }	
	var doubledigit = NumberLength % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;
	for (var i = 0; i < NumberLength; i++){
		tempdigit = eval(CCNumber.charAt(i))
		if (doubledigit){
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);
			if ((tempdigit / 10) >= 1.0) checkdigit++;
			doubledigit = false;
		}
		else {
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	if ((checkdigit % 10) != 0){
		msg_cc =  "The card number "+CCNumber+" appears to be a "+CardName+" number, but the ";
   		msg_cc = msg_cc + "\nnumber is not valid. Please check the credit card number for accuracy. ";
		alert(msg_cc)
  		return false;	
    } 
	return true;
}
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Please, check the E-mail address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please, check the E-mail address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please, check the E-mail address")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please, check the E-mail address")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please, check the E-mail address")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please, check the E-mail address")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Please, check the E-mail address")
		return false
	 }

	 return true					
}

function validateContactForm(){
	if( ! echeck( document.frm_contacts.email.value ) ){
		return false;
	}else if( document.frm_contacts.fullName.value == "" ){
		alert("Please, check the Full Name field.");
		return false;
	}else if( document.frm_contacts.fullName.value.length < 3 ){
		alert("Please, check the Full Name field.");
		return false;
	}else if( document.frm_contacts.comments.value == "" ){
		alert( "Please, check the Comments field.");
		return false;
	}else if( document.frm_contacts.comments.value.length < 10 ){
		alert( "Please, check the Comments field.");
		return false;
	}else{
		return true;
	}
}