
function extLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "nofollow") 
     anchor.target = "_blank"; 
	 if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "blank") 
     anchor.target = "_blank";
if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "top") 
     anchor.target = "_top"; 
 } 
} 

function DisableSubmit() {
	document.agency.SEND.disabled=true;
	document.agency.terms[0].checked=false;
	document.agency.terms[1].checked=true;
}


function EnableSubmit() {
	document.agency.SEND.disabled=false;
}



function ChangeColour() {
	i = document.agency.color.selectedIndex;
	tabcolor = document.agency.color.options[i].value;
	document.getElementById("atable").style.background = tabcolor;
}

function ChangeName() {
	var agency = document.agency.AGENCYNAME2.value;
	var agency2 = document.getElementById("NAME1");
	agency2.firstChild.nodeValue=agency;
	document.agency.BUSNAME.value = agency;
}

function AddAddress1() {
	var address1 = document.agency.ADDRESS1.value;
	var agency3 = document.getElementById("AGENCYADDRESS1");
	agency3.firstChild.nodeValue=address1;
	document.agency.AGENCYADDRESS1.value = address1;
}

function AddAddress2() {
	var address2 =document.agency.ADDRESS2.value;
	var agency4 = document.getElementById("AGENCYADDRESS2");
	agency4.firstChild.nodeValue=address2;
	document.agency.AGENCYADDRESS2.value = address2;
}

function AddAddress3() {
	var address3 = document.agency.ADDRESS3.value;
	var agency5 = document.getElementById("AGENCYADDRESS3");
	agency5.firstChild.nodeValue=address3;
	document.agency.AGENCYADDRESS3.value = address3;
}

function AddAddress4() {
	var address4= document.agency.ADDRESS4.value;
	var agency7 = document.getElementById("AGENCYADDRESS4");
	agency7.firstChild.nodeValue=address4;
	document.agency.AGENCYADDRESS4.value = address4;
}

function AddPostcode() {
	var postcode= document.agency.POSTCODE.value;
	var agency6 = document.getElementById("AGENCYPOSTCODE");
	agency6.firstChild.nodeValue=postcode;
	document.agency.AGENCYPOSTCODE.value = postcode;
}



function ChangePhone() {
	var phone = document.agency.TELEPHONE2.value;
	var PhoneLength = document.agency.TELEPHONE2.value.length;
	if (PhoneLength != 0) {
	var PHONE1 = document.getElementById("PHONE1");
	PHONE1.firstChild.nodeValue=phone;
	document.agency.TELEPHONE.value = phone;}
	else { 
	var PHONE1 = document.getElementById("PHONE1").innerHTML="&nbsp;";
	}
}

function ChangeMobile() {
	var moby = document.agency.MOBILENUMBER2.value;
	var mobileLength = document.agency.MOBILENUMBER2.value.length;
	if (mobileLength != 0) {
	var MOBILE = document.getElementById("MOBILE");
	MOBILE.firstChild.nodeValue=moby;
	document.agency.MOBILENUMBER.value = moby;}
else { 
	var MOBILE = document.getElementById("MOBILE").innerHTML="&nbsp;";
	}
}

function ChangeEmail() {
	var email = document.agency.EMAIL2.value;
	var emailLength = document.agency.EMAIL2.value.length;
	if (emailLength != 0) {
	var email2 = document.getElementById("EMAIL");
	email2.firstChild.nodeValue=email;
	document.agency.EMAIL.value = email;}
else { 
	var email2 = document.getElementById("EMAIL").innerHTML="&nbsp;";
	}
}

function ConfirmEmail() {
	var FirstEmail= document.agency.EMAIL2.value;
	var FirstEmailLength= document.agency.EMAIL2.value.length;
	var SecondEmail= document.agency.EMAIL3.value;
	var SecondEmailLength= document.agency.EMAIL3.value.length;
	if (FirstEmailLength != 0  && SecondEmailLength !=0) {
		if (FirstEmail != SecondEmail) {
	alert("Confirm email  not the same as Email, Please check");
	document.agency.EMAIL.focus();
	return false;}
	}
}



function ChangeWebsite() {
	var web = document.agency.WEBSITE2.value;
	var webLength = document.agency.WEBSITE2.value.length;
	if (webLength != 0) {
	var WEBSITE = document.getElementById("WEBSITE");
	WEBSITE.firstChild.nodeValue=web;}
else { 
	var WEBSITE = document.getElementById("WEBSITE").innerHTML="&nbsp;";
	}
}


function ChangeSubjects() {
	Subs2 = document.agency.subjects.value;
	Subs2Length = document.agency.subjects.value.length;
	MaxSubs2 = 250;
	OverSubs2 = (Subs2Length - MaxSubs2) + 1;

	if (Subs2Length < MaxSubs2){
	var subjects2 = document.getElementById("SUBS1");
	subjects2.firstChild.nodeValue=Subs2;
	 }
else { alert("Total number of characters in the Subjects and levels box must be less than " + MaxSubs2 + "\nYou have entered " + Subs2Length +  " characters\nPlease delete " + OverSubs2 + " or more characters.");
	document.agency.subjects.focus();
	}}


function ChangeComments() {
	Coms2 = document.agency.Comments.value;
	Coms2Length = document.agency.Comments.value.length;
	MaxComs2 = 380;
	OverComs2 = (Coms2Length - MaxComs2) + 1;


	if (Coms2Length < MaxComs2){
	var comments2 = document.getElementById("ADDITIONAL");
	comments2.firstChild.nodeValue=Coms2;}
else { alert("Total number of characters in the additional information box  must be less than " + MaxComs2 + "\nYou have entered " + Coms2Length +  " characters\nPlease delete " + OverComs2 + " or more characters.");
	document.agency.Comments.focus();
	}}

function ChBoxCount(f){
var t=0;
var C12=35; 				// The cost of advertising for twelve months
var E = 10; 					//The cost per extra avert
var c=f['COUNTY[]'];
for(var i=0;i<c.length;i++){
c[i].checked?t++:null;
}
if (t > 0) {
	Z = C12-E;  					// Cost for twelve months  minus £extra advert
	if (t > 1) { 					// If more than one advert selected use pages otherwise use page
	p = " pages";}  
	else {
	p= " page"; }
			
x = (t*E + Z); // Total cost = no of counties selected multiplied by cost per extra advert ( currently £5) plus cost of one advert minus 5
y = 'As you have selected ' + t + p + ' the cost of your advertising will be  £'+ x +'.00.';  // Text to output on page
var cost = document.getElementById("output");
cost.firstChild.nodeValue = y;
var CosB = document.getElementById("CostButton");
CosB.firstChild.nodeValue = "Re-Calculate Cost";  // Updates text within button from calculate cost to RE-CALCULATE cost after first use 
} 
else 
{alert ('No Counties/Pages selected');}  // Alert box if no counties selected
}

	
	
function validate(){
	//Here are the variables for the validation function
	Subs = document.agency.subjects.value;
	SubsLength = document.agency.subjects.value.length;
	MaxSub = 250;
	OverSub = (SubsLength - MaxSub) + 1;

	Coms = document.agency.Comments.value;
	ComsLength = document.agency.Comments.value.length ;
	MaxComs = 380;
	OverComs = (ComsLength - MaxComs) + 1;
	

	if (document.agency.AGENCYNAME2.value.length < 1) {
	alert("Please check that you have \nentered a name for your agency");
	document.agency.AGENCYNAME2.focus();
	return false;}



if (document.agency.BUSNAME.value.length < 1) {
	alert("Please check that you have entered a name for your agency");
	document.agency.BUSNAME.focus();
	return false;}
	

	if (document.agency.AGENCYADDRESS1.value.length < 2) {
	alert("Have you have entered a valid address?");
	document.agency.AGENCYADDRESS1.focus();
	return false;}

	

	if (document.agency.AGENCYADDRESS3.value.length < 2) {
	alert("Please enter the Town/City...");
	document.agency.AGENCYADDRESS3.focus();
	return false;}

 	
	
	if (document.agency.AGENCYPOSTCODE.value.length < 6){
	alert("Have you have entered a valid postcode?");
	document.agency.AGENCYPOSTCODE.focus();
	return false;}

	title = document.agency.title.selectedIndex;
	val = document.agency.title.options[title].value;
	if (val=="_") {
	alert("please select the title of your contact name");
	document.agency.title.focus();
	return false;}

	if (document.agency.SURNAME.value.length < 2){
	alert("Please make sure that you have entered a contact name");
	document.agency.SURNAME.focus();
	return false;}



	if (document.agency.TELEPHONE.value.length < 11){
	alert("Please check that you have entered the full telephone number including area code.");
	document.agency.TELEPHONE.focus();
	return false;}
	
	if (document.agency.EMAIL.value.length < 6){
	alert("Please check that you have entered an E-Mail Address");
	document.agency.EMAIL.focus();
	return false;}
	
	if (document.agency.subjects.value.length < 2){
	alert("Please check that you have entered text in the subjects box");
	document.agency.subjects.focus();
	return false;}
	
	if (document.agency.Comments.value.length < 2){
	alert("Please check that you have entered text in the Additional information box");
	document.agency.Comments.focus();
	return false;}


	if (SubsLength > MaxSub){
	alert("Maximum number of characters in the Subjects and levels box  is " + MaxSub + "\nYou have entered " + SubsLength +  " characters\nPlease delete " + OverSub + " or more characters.");
	document.agency.subjects.focus();
	return false;}

	if (ComsLength > MaxComs){
	alert ("Maximum number of characters in the additional information box is " + MaxComs + "\nYou have entered " + ComsLength +  " characters\nPlease delete " + OverComs + " or more characters.");
	document.agency.Comments.focus();
	return false;}

	
	Conf=confirm ("You are about to submit your details to HomeTutorsDirectory.co.uk. Press OK to submit details OR Cancel to return to the form");
	if (Conf==true) {return true;}
	if (Conf==false) {return false;}
	


return true;
}
















