/*
********************************************************************************
Brochures.js
JS Functions used on the brochure request, Email Sign Up Pages

********************************************************************************
*/
/* Below are functions for the brochure request page */
var BrochureOK = "";
BrochureOK = "NO"
// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification.  It will be invoked
// from the onSubmit() event handler.  The handler should return whatever
// value this function returns. This routine will not work across all browsers for select boxes, checkboxes and option buttons.
function verify(f)
{
	var f = document.BrochureRequestForm;
    var msg;
    var empty_fields = "";
    var errors = "";

    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined.  Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.

    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
			
        if (((e.type == "text") || (e.type == "textarea") || (e.type == "select-one")) && !e.optional) 
		{
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value) || (e.value == "Make a selection...")) {
                empty_fields += "\n          " + e.name;
                continue;
         }
            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) { 
                var v = parseFloat(e.value);
                if (isNaN(v) || 
                    ((e.min != null) && (v < e.min)) || 
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null) 
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null) 
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }
    }
	
	
	//check the Source Code - need to validate this outside the main routine as early versions of Nav
	//will not work.
	 if (f.where[0].selected == true )
    	{
		alert("You have not told us where you heard about us. Please select an option from the list and resubmit the form."); 
		return false;
		}

	// force the user to answer data protection questions
	var CompanyMail = "";
	var mailerror = "no";
	var mailerrorstring = "";
		/*if (f.companyinfomail[0].checked)
			CompanyMail =="No";
		else if(f.companyinfomail[1].checked)
			CompanyMail =="No";
		else {
			mailerror=="Yes";
			mailerrorstring +=  "Future contact by post" + "\n";
		}
		if (f.companyinfoemail[0].checked)
			CompanyMail +="No";
		else if(f.companyinfoemail[1].checked)
			CompanyMail =="No";
		else {
			mailerror=="Yes";
			mailerrorstring +=  "Future contact by email" + "\n";
		}
		if (f.companyinfotele[0].checked)
			CompanyMail =="No";
		else if(f.companyinfotele[1].checked)
			CompanyMail =="No";
		else {
			mailerror=="Yes";
			mailerrorstring +=  "Future contact by telephone" + "\n";
		}*/
		
	if (!mailerrorstring) ;
		else
			{msg = "The form was not submitted because the following compulsory questions were not answered. \n";
			msg +="Please answer these questions and re-submit.\n";
			msg+= mailerrorstring + "\n";
			alert (msg);
			return false;}
	
    // Now, if there were any errors, then display the messages, and
    // return false to prevent the form from being submitted.  Otherwise
    // return true

    if (!empty_fields && !errors)
		document.BrochureRequestForm.submit();
		else
    		{
				msg  = "______________________________________________________\n\n"
    			msg += "The form was not submitted because of the following error(s).\n";
    			msg += "Please correct these error(s) and re-submit.\n";
   			     msg += "______________________________________________________\n\n"

	
    			if (empty_fields) {
        			msg += "- The following required field(s) are empty:" 
                	+ empty_fields + "\n";
        			if (errors) msg += "\n";
    					{
    						msg += errors;
    						alert(msg);
						}
				}
    				return false;
			}
}
     
function SetBox(strFieldName,intno)
  {
   /*
  // alert(document.forms.BrochureRequestForm.chkBrochureCouples.value)
   if (strFieldName=="chkBrochureCouples"){
      if (document.forms.BrochureRequestForm.chkBrochureCouples.checked = true)
 	      document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
		  document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false,
		  document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false  
	  else {
  	      document.forms.BrochureRequestForm.chkBrochureFamilies.checked = true,
		  document.forms.BrochureRequestForm.chkBrochureCouples.checked = false,
		  document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false,
		  document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false
    }	 
  }	  
  
   if (strFieldName=="chkBrochureFamilies"){
     if (document.forms.BrochureRequestForm.chkBrochureFamilies.checked = true)
        //document.forms.BrochureRequestForm.chkBrochureCouples.checked = false,
	    document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false,
		document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false  
     else{	 
 	     //document.forms.BrochureRequestForm.chkBrochureCouples.checked = true,
		 //document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
		 document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false,
		 document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false
    }	 
  }
  */
  // Re-instate this for next Season - Paul Ferguson 13/9/2004
  if (strFieldName=="chkBrochureCouples8"){
      if (document.forms.BrochureRequestForm.chkBrochureCouples8.checked = true)
 	      document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false
 		  //document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
 		  //document.forms.BrochureRequestForm.chkBrochureCouples.checked = false
     else {
  	      document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = true,
		  document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false
 		  //document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
		  //document.forms.BrochureRequestForm.chkBrochureCouples.checked = false
    }	 
  }	  
  
   if (strFieldName=="chkBrochureFamilies8"){
     if (document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = true)
        document.forms.BrochureRequestForm.chkBrochureCouples8.checked = false
		  //document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
		  //document.forms.BrochureRequestForm.chkBrochureCouples.checked = false  
     else{	 
 	     document.forms.BrochureRequestForm.chkBrochureCouples8.checked = true,
		 document.forms.BrochureRequestForm.chkBrochureFamilies8.checked = false
		 //document.forms.BrochureRequestForm.chkBrochureFamilies.checked = false,
		 //document.forms.BrochureRequestForm.chkBrochureCouples.checked = false
    }	 
  }	   
  
// end of functions for brochure request page 
}

// Below are functions for email sign up 

function SetBox2(strFieldName,intno)
{
   
  // alert(document.forms.BrochureRequestForm.chkBrochureCouples.value)
   
  if (strFieldName=="chkBrochureCouples")
  {
      if (document.EmailSignUp.chkBrochureCouples.checked = true)
 	      document.EmailSignUp.chkBrochureFamilies.checked = false,
		  document.EmailSignUp.chkBrochureFamilies7.checked = false,
		  document.EmailSignUp.chkBrochureCouples7.checked = false  
	  else {
  	      document.EmailSignUp.chkBrochureFamilies.checked = true,
		  document.EmailSignUp.chkBrochureCouples.checked = false,
		  document.EmailSignUp.chkBrochureFamilies7.checked = false,
		  document.EmailSignUp.chkBrochureCouples7.checked = false
    	   }	 
  }	  
  
   if (strFieldName=="chkBrochureFamilies"){
     if (document.EmailSignUp.chkBrochureFamilies.checked = true)
        document.EmailSignUp.chkBrochureCouples.checked = false,
	    document.EmailSignUp.chkBrochureFamilies7.checked = false,
		document.EmailSignUp.chkBrochureCouples7.checked = false  
     else{	 
 	     document.EmailSignUp.chkBrochureCouples.checked = true,
		 document.EmailSignUp.chkBrochureFamilies.checked = false ,
		 document.EmailSignUp.chkBrochureFamilies7.checked = false,
		 document.EmailSignUp.chkBrochureCouples7.checked = false
    }	 
  }	  
  // Re-instate this for next Season - Paul Ferguson 13/9/2004
  if (strFieldName=="chkBrochureCouples7"){
      if (document.EmailSignUp.chkBrochureCouples7.checked = true)
 	      document.EmailSignUp.chkBrochureFamilies7.checked = false,
 		  document.EmailSignUp.chkBrochureFamilies.checked = false,
 		  document.EmailSignUp.chkBrochureCouples.checked = false
     else {
  	      document.EmailSignUp.chkBrochureFamilies7.checked = true,
		  document.EmailSignUp.chkBrochureCouples7.checked = false,
 		  document.EmailSignUp.chkBrochureFamilies.checked = false,
		  document.EmailSignUp.chkBrochureCouples.checked = false
    }	 
  }	  
  
   if (strFieldName=="chkBrochureFamilies7"){
     if (document.EmailSignUp.chkBrochureFamilies7.checked = true)
        document.EmailSignUp.chkBrochureCouples7.checked = false,
		  document.EmailSignUp.chkBrochureFamilies.checked = false,
		  document.EmailSignUp.chkBrochureCouples.checked = false  
     else{	 
 	     document.EmailSignUp.chkBrochureCouples7.checked = true,
		 document.EmailSignUp.chkBrochureFamilies7.checked = false,
		 document.EmailSignUp.chkBrochureFamilies.checked = false,
		 document.EmailSignUp.chkBrochureCouples.checked = false
    }	 
  }	  
 
// }	  
   
}


	function validateFormEC() 
	
   {
    <!--- Ensure a valid looking email address --->
    if ((document.EmailSignUp.email.value == "") || 
        (document.EmailSignUp.email.value == null) ||
        (-1 == document.EmailSignUp.email.value.indexOf("@")) ||
        (-1 == document.EmailSignUp.email.value.indexOf(".")) ||
        (-1 != document.EmailSignUp.email.value.indexOf(",")) ||
        (-1 != document.EmailSignUp.email.value.indexOf("#")) ||
        (-1 != document.EmailSignUp.email.value.indexOf("!")) ||
        (-1 != document.EmailSignUp.email.value.indexOf(" ")) ||
        (document.EmailSignUp.email.value.length < 5)) {
          alert("Please enter your e-mail address");
          document.EmailSignUp.email.focus();
          return false;
    } 
	if ((document.EmailSignUp.title.value == "") || (document.EmailSignUp.title.value == null)) {
      alert("Please select your title.");
      document.EmailSignUp.title.focus();
      return false;
    }
    if ((document.EmailSignUp.initial.value == "") || (document.EmailSignUp.initial.value == null)) {
      alert("Please enter your Initial.");
      document.EmailSignUp.initial.focus();
      return false;
    }

    if ((document.EmailSignUp.surname.value == "") || (document.EmailSignUp.surname.value == null)) {
      alert("Please enter your Surname.");
      document.EmailSignUp.surname.focus();
      return false;
    }   
    if ((document.EmailSignUp.address1.value == "") || (document.EmailSignUp.address1.value == null)) {
      alert("Please enter the first Line of your Address.");
      document.EmailSignUp.address1.focus();
      return false;
    }   
    if ((document.EmailSignUp.address2.value == "") || (document.EmailSignUp.address2.value == null)) {
      alert("Please enter the second Line of your Address.");
      document.EmailSignUp.address2.focus();
      return false;
    } 
	if ((document.EmailSignUp.postcode.value == "") || (document.EmailSignUp.postcode.value == null)) {
      alert("Please enter your Post Code.");
      document.EmailSignUp.postcode.focus();
      return false;
    } 
	if ((document.EmailSignUp.country.value == "") || (document.EmailSignUp.country.value == null)) {
      alert("Please select a country.");
      document.EmailSignUp.country.focus();
      return false;
	  }
   /* if ((document.EmailSignUp.companyinfomail[0].checked == false))
	    if ((document.EmailSignUp.companyinfomail[1].checked == false))
	    {alert ("Please select either Yes or No for future contact by post.");	
		document.EmailSignUp.companyinfomail[1].focus();
		return false;
        }  */
	document.EmailSignUp.submit();
	  }  

/* end of functions for email signup */
function popurl(url, w, h)
{
	if (w==0)
	{
	  w = 800; //default width
	}
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width='+ w + ',height=' + h +'');
	self.name = "mainWin";
	sealWin.focus()
}

