/*
Version 1.85
*/

var to_swap = 0;
var isIndex = false;
lt='<';
gt='>';
// ==============================================================================================
function i_swap(iname){
	// only run on index page
	clearTimeout(to_swap);
	if(isIndex){
		if (iname == "") {
			to_swap=setTimeout("MM_swapImage('index_img','','" + defaultImg + "')",2500);
		}else{
			iname= rootFolder + 'images/i_'+iname+'.jpg';
			MM_swapImage('index_img','',iname);
		}
	}
}
// -------------------------------------------------------------
function costsWin(){
	mywindow = window.open ("setup.php","costs","location=0,status=0,scrollbars=0,width=570,height=358");
	
}
// -------------------------------------------------------------
function sampleWin(thisURL){
	winRef = window.open(thisURL,'infowindow','width=600,height=600,left=50,top=50,screenX=50,screenY=50,resizable=1')
	
}
// -------------------------------------------------------------
function brochureWin(){
	winRef = window.open('view_brochure.php','infowindow','width=1000,height=600,left=50,top=50,screenX=50,screenY=50,resizable=1')
	
}
// -------------------------------------------------------------

function noEnterKey() {
	//alert(window.event.keyCode)
	if (window.event.keyCode == 13){
		alert("Enter key has been disabled.")
		window.event.keyCode =0;
	}
} 

// -------------------------------------------------------------
function requestQuote(mode) {
	//showHideDiv("prod_request");
	if(mode == "hide"){
		showHide("product_request","none");
		showHide("product_specs","block");
	}else{
		showHide("product_specs","none");
		showHide("product_request","block");
	}
}
// -------------------------------------------------------------

function showHide(divID, mode) {
	document.getElementById(divID).style.display = mode;
}
// -------------------------------------------------------------
function moveToTop(){
	document.getElementById("container").scrollTop = 0; //It scrolls to top;
}
// -------------------------------------------------------------
function writeEmail(emName,emHost,emSubject, emClass, emText){
	/*  outputs email link : emClass and emText are optional
		emClass is the name of the class for the <a> tag
		emText is the text shown - defaults to email address
	*/
	var emClass = (emClass == null) ? "" : 'class="'+ emClass +'"';
	var emText = (emText == null) ? emName + "@" +emHost : emText;
	document.write ('<a href="mailto:' + emName + '@' + emHost + emSubject +'"' + emClass + ' onclick="doTracking()">');
	document.write (emText + '</a>');
}
// -------------------------------------------------------------

function findPos(obj) {
	this.X = obj.offsetLeft;
	this.Y = obj.offsetTop;
	while(obj.offsetParent){
		this.X=this.X+obj.offsetParent.offsetLeft;
		this.Y=this.Y+obj.offsetParent.offsetTop;
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{obj=obj.offsetParent;}
	}
	return this
}
// -------------------------------------------------------------

function browserType() {
    t = "Other";
    if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4)) 
		t = "NS";
    if ((navigator.appName == "Microsoft Internet Explorer") &&	(parseInt(navigator.appVersion) >= 4)) 
		t = "IE";
    return t;
}
var thisBrowser = browserType();
// -------------------------------------------------------------
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// -------------------------------------------------------------

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact
// -------------------------------------------------------------

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}
// -------------------------------------------------------------
function doSearchForm(){
	var frm  =document.frm_search;
	var t_or_f = true;
	if(frm.search_phrase.value == ""){
		t_or_f = false;
		alert("Please enter a word or phrase to search for.");
	}
	if(t_or_f){
		showHide("div_search_fields","none");
		showHide("div_searching","block");
		frm.submit();	
	}
}

// -------------------------------------------------------------
function info_popup(page, height){
	winRef = window.open(rootFolder +page,'infowindow','width=450,height='+height+',left=50,top=50,screenX=50,screenY=50')
}
function doTracking(){
	info_popup('mailer.php', 1);
}

//-------------------------------------------------------------------
function checkFormRequest(){
	var frm = document.form_enquiry_basket;
  	var myTelNo = frm.phone.value;
	var errmsg = "";
	if(frm.name.value == "") errmsg = errmsg + " - Your name\n";
  	if (!checkUKTelephone (myTelNo))  errmsg = errmsg + " - Telephone number (" + telNumberErrors[telNumberErrorNo] + ")\n";
	if(frm.email.value == "") errmsg = errmsg + " - Email address\n";
	
	if(frm.virtual_sample.checked == true){
		if(frm._userfile1.value == "" && frm._userfile1.value == "" && frm._userfile1.value == "") errmsg = errmsg + " - Image : you have requested a Virtual Sample but not attached an image\n";
	}
	
	
	if(frm._security_code.value == "") errmsg = errmsg + " - Security code\n";
	if(errmsg == "") {
		frm._mode.value = "submit";
		frm.submit();
	}else{
		errmsg = "Sorry but the form is incomplete. \n\nPlease check the following fields...\n" + errmsg;
		alert(errmsg);
	}
}

function setElementOn(thisItem){
	thisItem.style.background = "#CFC";	
}
function setElementOff(thisItem){
	thisItem.style.background = "#FFF";	
}

function confirmBasketAdd(t_or_f){
	if(t_or_f){
		return confirm("This product is already in your enquiry basket.\n\nAre you sure you want to add it again?");
	}else{
		return true
	}

}

function confirmQuote(t_or_f){
	if(t_or_f){
		return confirm("This product is already in your Enquiry Basket.\n\nAre you sure you want to get a separate quote for this product?");
	}else{
		return true
	}
}
