


//**** Validates form ****
function validateForm(){

    var status = 0; 
    
   //Validates surname
   if (trim(document.getElementById("subject").value) == "" ){
	  document.getElementById("subjectErrorMsg").style.display=""; 
	  status = 1;
   }else{
      document.getElementById("subjectErrorMsg").style.visibility='hidden';
   }
   
    //Validates name(kana)
   if (trim(document.getElementById("company").value) == "" ){
	  document.getElementById("companyErrorMsg").style.display=""; 
	  status = 1;
   }else{
      document.getElementById("companyErrorMsg").style.visibility='hidden';
   }
   
   //Validates email address if empty
   if (trim(document.getElementById("email").value) == "" ){
	  document.getElementById("emailErrorMsg").style.display=""; 
	  status = 1;
   }else{
	  document.getElementById("emailErrorMsg").style.visibility='hidden';
	  //Validates email address
	  if (validateEmail(document.getElementById("email").value) == false ){
		  document.getElementById("invalidEmailMsg").style.display=""; 
		  status = 1;
	  }else{
		  document.getElementById("invalidEmailMsg").style.visibility='hidden';
	  } 
   }
   
   //Validates mail content
   if (trim(document.getElementById("message").value) == "" ){
	  document.getElementById("messageErrorMsg").style.display=""; 
	  status = 1;
   }else{
      document.getElementById("messageErrorMsg").style.visibility='hidden';
   }
   
   //Check if status 
   if (status == 0){
      return true; //No error .... return true
   }
   
   return false;
   
}//*** End of ValidateForm Function ******


//*** Validate required fields (Trim space) *****
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//** Validate email address **** 
function validateEmail(str) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
	    return true;
	}else{
		//alert("Please input a valid email address!")
		return false;
   }
}

// This code validates a credit card number
function validateCC(fieldToValidate) {
	// Validate for numbers only
    var ccRE=/\W/gi;
    var CCnumber=fieldToValidate.value.replace(ccRE, "");

    if (isNaN(CCnumber)) {
	    fieldToValidate.focus();
        return false;
    }
	
	/*

    // Validate for the number of digits in the credit card number
    if ((CCnumber.length!=16) && (CCnumber.length!=18)) {
		alert("Incorrect number of digits in credit card number.");
        fieldToValidate.focus();
        return false;
    }

    // More advanced validation using a mathematical formula that applies to all credit card numbers
    var cardMath=0;
    for (i=CCnumber.length; i>0; i--) {
		if (i % 2 == 1) {
			var doubled = "" + (parseInt(CCnumber.substring(i - 1, i)) * 2);
			if (doubled.length==2) {
				doubled = parseInt(doubled.substring(0,1)) + parseInt(doubled.substring(1,2))
			}
           cardMath += parseInt(doubled);
       } else {
		   cardMath += parseInt(CCnumber.substring(i - 1, i))
	   }
    }

    if (cardMath % 10 != 0) {
		alert("Credit card number is invalid.");
        fieldToValidate.focus();
        return false;
    }*/
}
