// JavaScript Document



function validate() {
		
 if(!document.getElementById) return;
  var fullname = document.getElementById("GRCategory2a").value;
 var email = document.getElementById("GRCategory3a").value;
  var dayphone = document.getElementById("GrCustom0a").value;
 var address = document.getElementById("GrCustom1a").value;
   var city = document.getElementById("GrCustom2a").value;  
 var province = document.getElementById("GrCustom3a").value;  
  var postal = document.getElementById("GrCustom4a").value;    
  var comment = document.getElementById("GrCustom5a").value;   
  var comment2 = document.getElementById("GrCustom6a").value;  
  
  
  var incorrect = new Array();
  var no = 0;
  var regExp = /[A-Za-z]{1,}/;
  
  if(regExp.test(fullname)) {
   	fullname = fullname;
  } else {
   	incorrect[no] = "1";
  	no++;
  }
  
  regExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  
  if(regExp.test(email)) {
   	email = email;
  } else {
   	incorrect[no] = "2";
  	 no++;
  }
	
	regExp = /^([0-9\-])+$/;
  if(regExp.test(dayphone)) {
  	  	dayphone = dayphone;
    }else{
		incorrect[no] = "3";
  	 	no++;
	}
	
   if(address.length > 0) {
  	  	address = address;
    }else{
		incorrect[no] = "4";
  	 	no++;
	}
  
 if(city.length > 0) {
  	  	city = city;
    }else{
		incorrect[no] = "5";
  	 	no++;
	}

  if(province.length > 0) {
  	  	province = province;
    }else{
		incorrect[no] = "6";
  	 	no++;
	}
   
  postal = postal.toUpperCase();
  regExp = /[ABCEGHJKLMNPRSTVXY]\d[A-Z]\s?\d[A-Z]\d/;
  if(regExp.test(postal)) {
   	if(postal.indexOf(" ") < 0) {
    		postal = postal.substring(0,postal.length-3) + " " + postal.substring(postal.length-3,postal.length);
   	}
  } else {
    incorrect[no] = "7";
    no++;
    postal = "";
  }	
  if(comment.length > 0) {
  	  	comment = comment;
    }else{
		incorrect[no] = "8";
  	 	no++;
	}	
  if(comment2.length > 0) {
  	  	comment2 = comment2 ;
    }else{
		incorrect[no] = "9";
  	 	no++;
	}
	
  
   for(i=1;i<10;i++) {
  		document.getElementById(i).style.color="#000000";
  }

  for(j=0;j<no;j++) {
  		document.getElementById(incorrect[j]).style.color="#FF0000";
  }

  document.getElementById("GRCategory2a").value = fullname;
 document.getElementById("GRCategory3a").value = email;
   document.getElementById("GrCustom0a").value = dayphone;
  document.getElementById("GrCustom1a").value = address;
 document.getElementById("GrCustom2a").value = city;
  document.getElementById("GrCustom3a").value = province;  
  document.getElementById("GrCustom4a").value = postal;  

  
  if(no > 0) {
   document.getElementById("errors").innerHTML = "<span class=\"error\">There was an error with your form submission. Please fill in the neccessary fields.</span><br />";
	return false;
  }else{
	  return true;
	  }

}


