// JavaScript Document

function validate_contact(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfour=false; boxfive=false; boxsix=false;boxseven=false;boxeight=false;
 if(document.contactUsForm.company.value == ""){
 why+="Please enter the name of your Company\n";
 show = true;
 boxone=true;
 }

if(document.contactUsForm.name.value == ""){
 why+="Please enter your name\n";
 show = true;
 boxtwo=true;
}

if(isEmail(document.contactUsForm.email.value)==false){
 why+="Please enter a valid email address \n";
 show = true;
 boxthree=true;
}

if(document.contactUsForm.phone.value.length<1 || (CheckPhoneNumber(document.contactUsForm.phone.value)==false)){
 why+="Please enter a valid phone number\n";
 show = true;
 boxfour=true;
}

/*if(document.contactUsForm.website.value.length < 1 || !isValidSiteUrl(document.contactUsForm.website.value)){
 why+="Please enter a valid website\n";
 show = true;
 boxfive=true;
}
*/
if(document.contactUsForm.reason.value == ""){
 why+="Please enter reason\n";
 show = true;
 boxsix=true;
}

if(document.contactUsForm.how_find.value == ""){
 why+="Please enter how you found fluidesign \n";
 show = true;
 boxseven=true;
}

if(document.contactUsForm.comment.value == ""){
 why+="Please enter comment\n";
 show = true;
 boxeight=true;
}

 if(show){
   alert(why);
   if(boxeight){
   document.contactUsForm.comment.focus();}
   if(boxseven){
   document.contactUsForm.how_find.focus();}
   if(boxsix){
   document.contactUsForm.reason.focus();}
/*   if(boxfive){
   document.contactUsForm.website.focus();}
*/   if(boxfour){
   document.contactUsForm.phone.focus();}
   if(boxthree){
   document.contactUsForm.email.focus();}
   if(boxtwo){
   document.contactUsForm.name.focus();}
   if(boxone){
   document.contactUsForm.company.focus();}
  return false;
 }
 document.contactUsForm.submit();
}
function isEmail( strValue) {
 var objRegExp = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
 return objRegExp.test(strValue);
}
function CheckPhoneNumber(TheNumber) {
 var valid = 1
 var GoodChars = "0123456789()-+ "
 var i = 0
 if (TheNumber=="") {
 // Return false if number is empty
 valid = 0
 }
 for (i =0; i <= TheNumber.length -1; i++) {
 if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
 valid = 0
 } // End if statement
 } // End for loop
 return valid
}
function isValidSiteUrl(pmUrl){
	/*var urlPattern= /^(http:\/\/|https:\/\/|www.){1}([\w]+)(.[\w]+){1,2}$/;
	//var urlPattern=  '/^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+(=\w+)?)(&\w+(=\w+)?)*)?/';
	var vRegExp = new RegExp(urlPattern);
	return (vRegExp.test(pmUrl));*/
	if (pmUrl.indexOf(" ")!=-1) return false;
	var urlPat=/^(http:\/\/)|(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
	//var urlPat=/^(http:\/\/){1}(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
	if ( pmUrl.match(urlPat) == null ) return false;
	return true;
}

