// 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";
			}
		}
	}
}


// INCREASE AND DECREASE THE FONT

var min=8;
var max=18;

function increaseFontSize() {
  
   
   var tag = new Array('content','menu','linksCopyright','submenu');
   
   for(j=0;j<tag.length;j++) {
	   
	   var p = document.getElementById(tag[j]);
		  if(p.style.fontSize) {
			 var s = parseInt(p.style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
		  if(s!=max) {
			 s += 1;
		  }
		  p.style.fontSize = s+"px"
	   
   }
   
}

function decreaseFontSize() {
	
   var tag = new Array('content','menu','linksCopyright','submenu');
   
   for(j=0;j<tag.length;j++) {

	   var p = document.getElementById(tag[j]);
		  if(p.style.fontSize) {
			 var s = parseInt(p.style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
		  if(s!=min) {
			 s -= 1;
		  }
		  p.style.fontSize = s+"px"
	   
   }
   
}


// 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 CheckFeedbackForm() {
	var errorMsg = "";

	// Check name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Full Name";	
	}
	

	// Check company 
	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";
	}	
	

	//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;
}



function CheckFreeSampleForm() {
	var errorMsg = "";

	// Check name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Full Name";	
	}
	

	// Check company 
	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- Please select one option from the list";	
	}	

	//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;
		}
	
	}
	
}


// POP UP NOTES

function hideObject(id) {

   document.getElementById(id).style.display = "none";

}


function showObject(id) {

     document.getElementById(id).style.display = "block";

}

// ON LOAD

window.onload = function() {
	relTags();
}


// Evolution login validation
function chk(){

	if(document.login.userName.value==""){

		alert("Please enter your Username");
		document.login.userName.focus();
		return false;

	}	

	if(document.login.password.value==""){

		alert("Please enter your Password");

		document.login.password.focus();

		return false;
	}
	
	        document.login.password.value = document.login.password.value;
            document.login.userName.value = document.login.userName.value;
            document.login.action = "http://www.barbour-abi.com/onlineservices/Login.do";

}




