// TARGETS BLANK IN XHTML STRICT

function relTags() {

	if (document.getElementsByTagName) {
	
		var anchors = document.getElementsByTagName( "a" );
		
		for (var loop = 0; loop < anchors.length; loop++) {
			
			var anchor = anchors[loop];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
		}
	}
}


// Email.js version 5
var tld_ 	= new Array()
tld_[0]  	= "com";
tld_[1] 	= "org";
tld_[2]  	= "net";
tld_[3]  	= "info";
tld_[4] 	= "co.uk";
tld_[5] 	= "fr";
tld_[6] 	= "org.uk";
tld_[7] 	= "gov.uk";
tld_[8] 	= "uk.com";
tld_[9] 	= "gb.com";
var topDom_ = 13;
var m_ 		= "mailto:";
var a_ 		= "@";
var d_ 		= ".";

function mail(name, dom, tl, accesskey, display) {
	var s = e(name,dom,tl);
	
	if (display != "") { document.write('<a href="'+m_+e(name,dom,tl)+'" accesskey="'+accesskey+'">'+display+'</a>'); }
	else { document.write('<a href="'+m_+s+'" accesskey="'+accesskey+'">'+s+'</a>'); }
		
}

function e(name, dom, tl) {
	var s = name+a_;
	if (tl!=-2) {
		s+= dom;
		if (tl>=0)
			s+= d_+tld_[tl];
	}
	else
		s+= swapper(dom);
	return s;
}

function swapper(d) {
	var s = "";
	for (var i=0; i<d.length; i+=2)
		if (i+1==d.length)
			s+= d.charAt(i)
		else
			s+= d.charAt(i+1)+d.charAt(i);
	return s.replace(/\?/g,'.');
}

function CheckFreeSampleForm() {
	var errorMsg = "";    

	// Check name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Full Name";	
	}
	
	// Check Company name
	if (document.Form.company.value == ""){
		errorMsg += "\n\tCompany \t- Enter your Full Company name";	
	}
	
	// Check address
	if (document.Form.address.value == ""){
		errorMsg += "\n\tAddress \t- Enter your Address";	
	}
	
	// Check postcode
	if (document.Form.postcode.value == ""){
		errorMsg += "\n\tPostcode \t- Enter your postcode";	
	}
	
	// Check phone
	if (document.Form.phone.value == ""){
		errorMsg += "\n\tPhone \t- Enter your Phone number";	
	}
		
	//Check for an e-mail address and that it is valid
	if ((document.Form.email.value == "") || (document.Form.email.value.length > 0 && (document.Form.email.value.indexOf("@",0) == - 1 || document.Form.email.value.		    indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail Address \t- Enter a valid e-mail address";
	}
	
	// Check Dropdown Selection
	if (document.Form.comMB.value == ""){
		errorMsg += "\n\tDrop-down Selection \t- How did you hear about us?";	
	}
	
	// Check Dropdown Selection
	if (document.Form.comMBtwo.value == ""){
		errorMsg += "\n\tDrop-down Selection \t- Select your role";	
	}

	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: \n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}


// Highlight CELL TAB
function changeTdBackgroundColor (id,colorOff,colorOn) {
	var selector = document.getElementById(id);
	
	var anchors = selector.getElementsByTagName("td");
	for (var i = 0; i < anchors.length; i++) {
		anchors[i].onmouseover = function() {
			this.style.backgroundColor = colorOn;
		}
		anchors[i].onmouseout = function() {
			this.style.backgroundColor  = colorOff;
		}
	}
	
}


function changeTdByClass (id,classOn) {
	
	var selector = document.getElementById(id);
	
	var tag = selector.getElementsByTagName("tr");
	
	for (var i = 1; i < tag.length; i++) {
		
		tag[i].onmouseout = function() {
			alert(oldClass[i] +' '+ i);
			this.className  = oldClass[i];
		}
		
		tag[i].onmouseover = function() {
			this.className = classOn;
		}
	
	}
	
}


