// Scripts Used on the Contact Us Page //
// Version V1.0.0, 23/09/2007 WBM. //
// Copyright 2007. Property of Design Atom - wwww.designatom.com//

// Global Variables
arrWebsites = new Array();

// Clear the Comments Text Area when it gets Focus
function fctClearComments(thisControl) {
	thisControl.value = "";
}

// Website Design Requirements
function fctWebsite(thisControl){
	// Check if the user has selected or deselected Websites
	if (thisControl.checked) {
		// Ask the user if this site requires dynamic content
		var strMessage = "Will the Content on Your Site Change Regularly?<br/>e.g. Online Store, Catalogue, Ticketing, Price<br/>Comparison, Chatrooms and Blog Sites."
		var strReply = window.showModalDialog("../_dialogs/yesno.htm",strMessage,"dialogWidth:310px; dialogHeight:135px; center:yes; help:no; status:no; resizeable:no; scroll:no; unadorned:yes");
		
		if (strReply=="yes"){
			// The user needs a dynamic website
			arrWebsites.push("type:Dynamic");
		}
		else {
			// The user needs a static website
			arrWebsites.push("type:Static");
		}
	}
	else {
		// The User does not want a website so clear array
		arrWebsites.splice(1,arrWebsites.length);
	}
	
	// Add the Type of website to the form values
	var strWebsites = arrWebsites.join(";");
	quote.summary.value = strWebsites;
}


// Clear the Information on the Form
function fctClearForm(thisForm) {
   // Step through each of the Form Fields in turn
   for (var counter=0; counter < thisForm.length; counter++) {
      // Exclude the Reset and Submit Buttons
      if(thisForm[counter].value!="Reset" && thisForm[counter].value!="Submit") {
		 // Find the Comments Textbox
		if(thisForm[counter].name!="comments"){
			// Reset the Listbox
			thisForm[counter].value = "";
		 }
		 else {
			// Reset the Comments Textbox
			thisForm[counter].value = "Enter Your Comments Here.";
		 }
      }
      
      // Reset the focus to the First Listbox
      thisForm[0].focus()
   }
   return false;
}

// Validate the Information on the Form
function fctCheckForm(thisForm) {
   // Declare global variable
   var stringtosearch;
   
   // Replace all occurances of double quotes
   // Step through each of the Form Fields in turn
   for (var counter=0; counter < thisForm.length; counter++) {
      // Replace all double quotes for single quotes
      if(thisForm[counter].value!=null) {
      
         // Get the location of the first occurrence
         stringtosearch = thisForm[counter].value
         old_location = stringtosearch.indexOf("\"");
      
         // Loop until there are no more instances
         while (old_location!=-1) {
            stringtosearch = stringtosearch.replace("\"","'");
            old_location = stringtosearch.indexOf("\"");
         }
         
         // Rewrite string with no double quotes
         thisForm[counter].value = stringtosearch;
      }
   }
   
   
   // Check that a Contact Name has been entered
   if(!thisForm.contact.value) {
      alert("You have not entered a Contact Name.\nPlease Enter Your Name.");
      thisForm.contact.focus();
      return false;
   }

   // Check that a Company Name has been entered
   if(!thisForm.company.value) {
      alert("You have not entered a Company or Trading Name.\nPlease Enter Your Company Name.");
      thisForm.company.focus();
      return false;
   }

   // Check that an Email Address has been entered
   if(!thisForm.email.value && !thisForm.telephone.value) {
      alert("You have not entered Your Contact Details.\nDo You Require A Response?");
      thisForm.email.focus();
      return false;
   }
   
   // Check for a valid email address
   var emailError = false;
   emailAddress = thisForm.email.value;
   
   // Check if an email address has been entered
   if (emailAddress) {
      // Check the length
      if (emailAddress.length<7) emailError = true;

      // Verify email contains the correct seperators
      at_location = emailAddress.indexOf("@");
      dot_location = emailAddress.lastIndexOf(".");
      if (at_location == -1 || dot_location == -1 || at_location > dot_location) emailError = true;
     
      // Check there is a name field before the @
      if (at_location == 0) emailError = true;
   
      // Check that there is at least two characters in the url address
      if (dot_location - at_location <= 2) emailError = true;
   
      // Check that there are at least two characters in the country code
      if (emailAddress.length - dot_location <= 2) emailError = true;
   
      // If it is an invalid email address prompt the user
      if(emailError) {
         alert("You have entered an invalid email address.");
         thisForm.email.focus();
         return false;
      }
   }

   // Check that some information has been entered into the text box
   if(!thisForm.comments.value || thisForm.comments.value=="Enter Your Comments Here.") {
      alert("You have not entered any Comments.\nPlease Enter Your Comments.");
      thisForm.comments.focus();
      return false;
   }
}