function brakeFrame(){
    	if(top.location != self.location){
        	top.location.href = document.location.href;
	}
}

function contactValidate(){
	//flag for error message
    	var flagError = 0;

    	//for error message
    	var errorText = "ERROR\nPlease enter\n";

	//for blank email
    	var flagEmailBlankError = 0;

 	//for email error
    	var flagEmailError = 0;

	//error message for email
	var emailError = "";

	//for blank enquiryComment
	var flagEnquiryCommentBlankError = 0;

	//error message for enquiryComment
	var enquiryCommentError = "";

	//for blank form
	var formBlankError = "";
	
	//flag for blank form
	var flagBlankFormError = 0;

    	//error message for blanks in address block
    	var addressBlankError = "";

    	//for blanks in address block
    	var flagAddressBlankError = 0;

    	//for blank phone
    	var flagPhoneBlankError = 0;

    	//error message for phone
    	var phoneError = "";

	//to make sure a name is entered in input field
	if (window.document.getElementById("contactForm").name.value == ""){ 
		errorText += "Name\n";
		flagError++;
		}
	
	//To validate for valid email address
	var x=window.document.getElementById("contactForm") ;
	var Temp=x.email.value ;
	var EmailOk  = true ;
	var AtSym    = Temp.indexOf('@') ;
	var Period   = Temp.lastIndexOf('.');
	var Space    = Temp.indexOf(' ') ;
	var Length   = Temp.length - 1;
	if (((AtSym < 1) ||                // '@' cannot be in first position
		(Period <= AtSym+1) ||         // Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||         // Must be atleast one valid char after '.'
		(Space  != -1)) &&             // No empty spaces permitted
		!(window.document.getElementById("contactForm").email.value == ""))
		{
		//window.document.getElementById("contactForm").email.value = "";
		flagEmailError++;
		flagError++;
		emailError = "Valid Email\n";
		}

	//To see if textarea has text in it
	if(
	(window.document.getElementById("contactForm").message.value == ""))
	{
		flagEnquiryCommentBlankError++;
		flagError++;
		enquiryCommentError = "Message\n";
	}

	//To see if anything has been entered on the form
	if((window.document.getElementById("contactForm").name.value == "") &&
	(window.document.getElementById("contactForm").telephone.value == "") &&
	(window.document.getElementById("contactForm").email.value == "") &&
	(window.document.getElementById("contactForm").message.value == ""))
	{
		//errorText = "ERROR\nNothing entered on form";
		flagBlankFormError++;
		flagError++;
		formBlankError = "ERROR\nNothing entered on form";
	}	 

	//To see if telephone or email plus message entered on the form
	if((window.document.getElementById("contactForm").name.value != "") &&
	(window.document.getElementById("contactForm").telephone.value == "") &&
	(window.document.getElementById("contactForm").email.value == "") &&
	(window.document.getElementById("contactForm").message.value == ""))
	{
		//errorText = "ERROR\nNothing entered on form";
		//flagBlankFormError++;
		flagError++;
		errorText += "Telephone OR Email\n";
		
	}	 


	//To see if telephone or email is on the form
	if((window.document.getElementById("contactForm").name.value != "") &&
	(window.document.getElementById("contactForm").telephone.value == "") &&
	(window.document.getElementById("contactForm").email.value == "") &&
	(window.document.getElementById("contactForm").message.value != "") &&
	(flagEmailError < 1))
	{
		flagError++;
		errorText += "Telephone OR Email\n";
	}	 

	//**********Output block****************
	if(flagBlankFormError > 0){
		errorText = formBlankError;
	}

	if((flagEnquiryCommentBlankError > 0) && (flagBlankFormError < 1)){
		errorText += enquiryCommentError;
		flagError++;
	}

	if((flagEmailError > 0) && (flagBlankFormError < 1)){
        	errorText += emailError;
        	flagError++;
   }

   //Test to see if error message is shown
   if(flagError > 0){
        window.alert(errorText);
   }

    //Return statements
   if(flagError < 1)
         return true;
    return false;
}


function resultsMarketingValidate(){
	//flag for error message
	var flagError = 0;
		
	//for error message
	var errorText = "ERROR\nPlease enter\n";
		
	//for blank email
	var flagEmailBlankError = 0;
		
	//for email error
	var flagEmailError = 0;
		
	//error message for email
	var emailError = "";
		
	//for blank form
	var formBlankError = "";
		
	//flag for blank form
	var flagBlankFormError = 0;

	var contactBy = "";

	//Get value of radio button. If selected initialise $contactBy
	//if ( $_POST['resultsMarketingContact'] == "telephone1") {  $contactBy = 'telephone'; }
	//if ( $_POST['resultsMarketingContact'] == "email1") { $contactBy = 'email'; }
		
	//**********Testing for blanks in Name block****************
	//to make sure a name is entered in input field
	if (window.document.getElementById("resultsMarketingForm").name.value == ""){ 
		errorText += "Name\n";
		flagError++;
	}
	
			
	//To validate for valid email address
	var x=window.document.getElementById("resultsMarketingForm") ;
	var Temp=x.email.value ;
	var EmailOk  = true ;
	var AtSym    = Temp.indexOf('@') ;
	var Period   = Temp.lastIndexOf('.');
	var Space    = Temp.indexOf(' ') ;
	var Length   = Temp.length - 1;
	if (((AtSym < 1) ||                // '@' cannot be in first position
		(Period <= AtSym+1) ||         // Must be atleast one valid char btwn '@' and '.'
		(Period == Length ) ||         // Must be atleast one valid char after '.'
		(Space  != -1)) &&             // No empty spaces permitted
		!(window.document.getElementById("resultsMarketingForm").email.value == ""))
		{
		//window.document.getElementById("resultsMarketingForm").email.value = "";
		flagEmailError++;
		flagError++;
		emailError = "Valid Email\n";
		}
		

	//To see if anything has been entered on the form
	if((window.document.getElementById("resultsMarketingForm").name.value == "") &&
		(window.document.getElementById("resultsMarketingForm").business.value == "") &&
		(window.document.getElementById("resultsMarketingForm").telephone.value == "") &&
		(window.document.getElementById("resultsMarketingForm").email.value == ""))
		{
		flagBlankFormError++;
		flagError++;
		formBlankError = "ERROR\nNothing entered on form";
		}	 

	//To see if anything has been entered on the form
	if((window.document.getElementById("resultsMarketingForm").name.value == "") &&
		(window.document.getElementById("resultsMarketingForm").business.value != "") &&
		(window.document.getElementById("resultsMarketingForm").telephone.value == "") &&
		(window.document.getElementById("resultsMarketingForm").email.value == ""))
		{
		flagError++;
		errorText += "telephone or email\n";
		}	 

	//To see if telephone or email plus message entered on the form
	if((window.document.getElementById("resultsMarketingForm").name.value != "") &&
		(window.document.getElementById("resultsMarketingForm").telephone.value == "") &&
		(window.document.getElementById("resultsMarketingForm").email.value == ""))
		{
		flagError++;
		errorText += "Email or Telephone\n";
		}	 

	//**********Output block****************
	if(flagBlankFormError > 0){
		errorText = formBlankError;
	}

	if((flagEmailError > 0) && (flagBlankFormError < 1)){
        	errorText += emailError;
        	flagError++;
   }
	
	//Test to see if error message is shown
   	if(flagError > 0){
       		 window.alert(errorText);
   	}

    	//Return statements
   	if(flagError < 1)
         	return true;
    	return false;
}