scrollStep=1

timerLeft=""
timerRight=""
// -------------------------------------------------------------
function toLeft(id){
  document.getElementById(id).scrollLeft=0
}
// -------------------------------------------------------------
function scrollDivLeft(id){
  clearTimeout(timerRight) 
  changeImg('pic_scroll_right','scroll_right_on.gif');
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}
// -------------------------------------------------------------
function scrollDivRight(id){
  clearTimeout(timerLeft)
  changeImg('pic_scroll_left','scroll_left_on.gif');
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}
// -------------------------------------------------------------
function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}
// -------------------------------------------------------------
function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
  changeImg('pic_scroll_left', 'scroll_left_off.gif');
  changeImg('pic_scroll_right','scroll_right_off.gif');
}

// -------------------------------------------------------------
function changeImg(imgName,toImg){
	var i = document.getElementById(imgName);
	imgpth = rootFolder + "images/" +toImg;
	i.src = imgpth;
}

function changeImg_store(imgName,toImg){
	var i = document.getElementById(imgName);
	i.src = toImg;
}

// -------------------------------------------------------------
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;
}
// -------------------------------------------------------------

function sort_list(mode,url){
	location.href = url + "?sort=" + mode;
}

// -------------------------------------------------------------
function showHide(divID, mode) {
	document.getElementById(divID).style.display = mode;
}
// -------------------------------------------------------------

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 +"\n ";
		alert(errmsg);
	}
}
// -------------------------------------------------------------
function product_form_submit(){
	var frm = document.form_product_enquiry;
  	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._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 +"\n ";
		alert(errmsg);
	}
}

// -------------------------------------------------------------

function securityinfo(){
	alert("What's this?\n\nThis is a 5-digit security code that helps us to ensure we get real enquiries from real people.\n\nIf you cannot read the code easily, use the speaker icon to download an audio file that will read the code to you.\nAlternatively, you can click the 'Refresh Image' icon which will load a new code for you. This can be done as many times as you wish.\n\nWe apologise for any inconvenience this may cause but due to other, inconsiderate marketers, we have to protect ourselves again spam and other malicious emails.\n\n")
}
// -------------------------------------------------------------

function setElementOn(thisItem){
	thisItem.style.background = "#CFC";	
}
function setElementOff(thisItem){
	thisItem.style.background = "#FFF";	
}
// -------------------------------------------------------------

function checkSearchBox(){
	var val = trim(document.form_quick_search.form_quick_search_text.value)
	if(val == "" || val =="Click here to search..."){
		alert("Please enter a search word or phrase")
		return false
	}else{
		document.form_quick_search.submit()
	}
}


// -------------------------------------------------------------
function sampleWin(thisURL){
	winRef = window.open(thisURL,'infowindow','width=600,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 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 trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
// -------------------------------------------------------------


/* ==========================================================
BUDGET SEARCH
============================================================*/

function checkBudget(){
	var t_or_f = true;
	var err = "";
	frm = document.frm_budgetizer;
	
	if(frm.budget.value =="" || isNaN(frm.budget.value) || frm.budget.value=="0"){
		err = err + " - Please enter a budget value using only numbers\n";
	}
	if(frm.quantity.value == "" || isNaN(frm.quantity.value) || frm.quantity.value=="0"){
		err = err+ " - Please enter a quantity value using only numbers\n";
	}
	
	if(frm.minval.value == "" || isNaN(frm.minval.value)){
		err = err+ " - Please enter a minimum product value using only numbers. If no minimum value is required please enter 0 (zero)\n";
	}
	
	
	if(frm.minval.value * frm.quantity.value > frm.budget.value){
		err = err + " - Your budget is insufficient for the number of products at the minimim price\n"
		t_or_f = false;
	}
	if(err==""){
		frm.btn_submit.value="Searching";
		frm.btn_submit.disabled = true;
		frm.submit()
	}else{
		alert("Sorry but there are errors...\n"+err+" ")
		return false;
	}
	
}

function boxTick(thisBox){
	if(thisBox.checked){
		boxticked ++
	}else{
		boxticked --
	}
}

function setMaxPrice(){
	var val = 0;
	var frm = document.frm_budgetizer;
	if(frm.budget.value != "" && (frm.quantity.value!="" && frm.quantity.value != "0")){
		if(isNaN(frm.budget.value) == false && isNaN(frm.quantity.value) == false){
			val=parseFloat(frm.budget.value)/parseFloat(frm.quantity.value);
			document.getElementById("span_maxprice").innerHTML = val.toFixed(2);
		}
	}
}

//-----------------------------------------------------------------------------------

function findPositionX(tar){
    var left = 0;
 	obj = document.getElementById(tar);
   if(obj.offsetParent)
    {
        while(1) 
        {
          left += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    }
    else if(obj.x)
    {
        left += obj.x;
    }
    return left;
}
function findPosY(tar){
    var top = 0;
 	obj = document.getElementById(tar);
    if(obj.offsetParent)
    {
        while(1)
        {
          top += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    }
    else if(obj.y)
    {
        top += obj.y;
    }
    return top;
 }
 
//-----------------------------------------------------------------------------------

function placeDiv(target,thisDiv){
	x = findPositionX(thisDiv);
	y = findPosY(thisDiv)
	move = document.getElementById(target);
	move.style.top = y+"px";
	move.style.left = x+"px";
	showHide(target,"block");
}

//-----------------------------------------------------------------------------------

function addToBasket(p){
	location.href = "../enquiry_basket.php?mode=add&item="+p;
}

function confirmRemoveItem(iid,f, prod){
	if(confirm("Are you sure you want to remove " + prod + " from this list?")){
		eval("document." +f + ".submit()");	
	}
}

//----------------------------------------------------------------------------------

function checkQuickAdd(v){
	if(v.length <6){
		document.frm_quickadd.btn_quickadd.disabled = true
	}else{
		document.frm_quickadd.btn_quickadd.disabled = false
	}
}

function confirmAddAllLists(){
	v= document.frm_listadd.l_id.options[document.frm_listadd.l_id.selectedIndex].value;
	if(v == "*") {
			return confirm("Are you sure you want to add this product to ALL lists?");	
	}else{
		return true;	
	}
}
//-----------------------------------------------------------------------------------

// AJAX page caller - calls page set in 'url' and then sets return output in div id 'updateDiv'
function call_aj_page(url, updateDiv, include_content, runthis) { 
	if(!include_content) include_content = 0;
	if(!runthis) runthis = "";
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
			new_content = xmlhttp.responseText;
			if(include_content == 1) new_content = document.getElementById(updateDiv).innerHTML + new_content;
            document.getElementById(updateDiv).innerHTML= new_content;
			
			if(runthis !="") eval(runthis);
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}


function post_aj_page(url, updateDiv, include_content, runthis) { 
	if(!include_content) include_content = 0;
	if(!runthis) runthis = "";
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
	xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
			new_content = xmlhttp.responseText;
			if(include_content == 1) new_content = document.getElementById(updateDiv).innerHTML + new_content;
			if(new_content.indexOf("rx=1")>0){
				showHide("quickadd_result","none");
				window.location.href = new_content;	
			}
	            document.getElementById(updateDiv).innerHTML= new_content;
			
			if(runthis !="") eval(runthis);
        }
    }

	var n; var ic; var p; var m; var li_id; var l_id; var sr; var prodcode;

	if(document.getElementById("list_item_notes")) n=encodeURIComponent(document.getElementById("list_item_notes").value);
	if(document.getElementById("ic")) ic = encodeURIComponent(document.getElementById("ic").value);
	if(document.getElementById("p")) p = encodeURIComponent(document.getElementById("p").value);
	if( document.getElementById("mode")) m = encodeURIComponent(document.getElementById("mode").value);
	if(document.getElementById("li_id")) li_id = encodeURIComponent(document.getElementById("li_id").value);
	
	if(document.getElementById("l_id")) l_id = encodeURIComponent(document.getElementById("l_id").value);
	if(document.getElementById("sr")) sr = encodeURIComponent(document.getElementById("sr").value);
	if(document.getElementById("prodcode")) prodcode = encodeURIComponent(document.getElementById("prodcode").value);
	
	var parameters="list_item_notes="+n+"&ic="+ic+"&p="+p+"&mode="+m+"&li_id="+li_id+"&l_id="+l_id+"&sr="+sr+"&prodcode="+prodcode;
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    xmlhttp.send(parameters);
	
}

function GetXmlHttpObject() {
    var xmlhttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlhttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlhttp;
}

//-----------------------------------------------------------------------------------

