// JavaScript Document
function validate_text(field){
	with (field){
		if (value==null||value=="") {
  		   style.background="red";			
		   return false;
		}
		else {
			  style.background="white" ;				 
			  return true 
		}
	}
}

function validate_number(field){
	var ValidChars = "0123456789.";
	var Char;
	with (field){
		if (value==null||value=="") {
  		   style.background="red";			
		   return false;
		}
		else {
		   for (i = 0; i < value.length; i++) { 
      			Char = value.charAt(i); 
      			if (ValidChars.indexOf(Char) == -1) {
         			style.background="red";			
		   			return false;
         		}
      		}
		}
		style.background="white" ;				 
		return true 
		
	}
}


function validate_password (field) {
   var illegalChars=/[\W_]/; // allow only letters and numbers	 
   with (field){
	  if (value == "") {
         style.background="red";			
		 return false;
      }
    
      if ((value.length < 4) || (value.length > 15)) {
          style.background="red";			
		  return false;
      }
      else if (illegalChars.test(value)) {
         style.background="red";			
		 return false; 
      }
	  else {
		  style.background="white" ;				 
		  return true 
	  }
   }
}

function validate_email(field) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	with (field){
		if (!(emailFilter.test(value))) { 
    		style.background="red";			
			return false;
		}
		if (value.match(illegalChars)) {
           style.background="red";			
		   return false;
		}
		style.background="white" ;				 
	    return true;
	}
}
		
function validate_phone(field) {
	with (field){
		var stripped = value.replace(/[\(\)\.\-\ ]/g, '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		   style.background="red";			
		   return false;
		}
		if (!(stripped.length == 10)) {
       	   style.background="red";			
		   return false;
		}
  	    field.style.background="white" ;				 
	    return true;
	}
}
		
function validate_dropdown(field) {
	//with (field){
		if (field.value == 0) {
       		field.style.background="red";			
	   		return false;
   		}
		else {  
			field.style.background="white" ;				 
	    	return true;
		}
//	}
} 
		
function validate_creditcard(field,field1) {
   var cardno=field.value;
   var cardtype=field1.value;
   if (!checkCreditCard (cardno,cardtype)) {
		field.style.background="red";		
		field1.options[0].style.background="red";		 	
		return false;
	}
   else {
	    field.style.background="white";		
	    field1.options[0].style.background="white";		  
		return true;
  } 
}
