// 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-1;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-1;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"
	   
   }
   
}

function increaseContentSize() {
  
   var tag = new Array('content','linksCopyright');
   for(j=0;j<tag.length-1;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 decreaseContentSize() {
	
   var tag = new Array('content','linksCopyright');
   
   for(j=0;j<tag.length-1;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 CheckContactForm() {
	var errorMsg = "";

	// Check name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Full Name";	
	}
	
	// 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 name
	if (document.Form.title.value == ""){
		errorMsg += "\n\tTitle \t- Please select an option.";
	}

	// Check name
	if (document.Form.comment.value == ""){
		errorMsg += "\n\tComments \t- Enter your enquiry.";
	}
	

	//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 CheckForm() {
	var errorMsg = "";

	// Check name
	if (document.Form.compare.value == ""){
		errorMsg += "\n\tCompare \t- Please select a compare method";	
	}
	

	// Check Company name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tCompany \t- Enter your Full Company name";	
	}
	
	// Check phone
	if (document.Form.phone.value == ""){
		errorMsg += "\n\tPhone \t- Enter your Phone number";	
	}

	// Check phone
	if (document.Form.address.value == ""){
		errorMsg += "\n\tAddress \t- Enter your Address";	
	}

	// Check phone
	if (document.Form.postcode.value == ""){
		errorMsg += "\n\tPostcode \t- Enter your postcode";	
	}
	

	//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;
}

// 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();
}

// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
	closeHandler(cal);
	cal.sel.focus();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		//calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		//cal.setDateFormat("d/m/y");
		calendar.create();		// create a popup calendar
		//calendar.parseDate(el.value);
	}
	calendar.parseDate(el.value);
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

