//.net stuff
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}


// search function
function SearchButtonClicked()
	
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["aspnetForm"];
	}
	else {
		theform = document.aspnetForm;
	}
	if (theform.ctl00_txtSearch != null)
	{
		var d=theform.ctl00_txtSearch.value; 
   		if (d.length < 1)
	    { 
		    alert('Please enter a search term'); 
		    return false;
	    }
	    else
	    {
		    location.href="../search/?q=" + escape(d);
		    return false;
	    }
	}
}

// homepage tabs fix for David to click on 
function swapLayers2(id,v) {  if (id == cur_lyr) window.location = v.getAttribute('href');  else if (cur_lyr) hideLayer(cur_lyr);  showLayer(id);  cur_lyr = id; }

// product page tabs function
var cur_lyr;	
function swapLayers(id) {
  if (!cur_lyr)
  {
    hideLayer('images');
    hideLayer('bvreviews');
  } 
  else if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}
function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
  var litab =   getElemRefs("tab" + id);
  if (litab && litab.className) litab.className = "selected";
}


function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
  
  var litab =   getElemRefs("tab" + id);
  if (litab && litab.className) litab.className = "normal";
}
function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// Cross Browser Bookmark / Favourite Add //
function bookmarksite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}


// stocklevel popup //
function stockcheck(v){
 URL = v.getAttribute('href');
 popup = window.open(URL,'stock','scrollbars=yes,width=225,height=160,left=0,top=0,resizable,left=400,top=350');
 popup.focus();
 return(false);
}



var swapTimer;
// delay before restoring original image onmouseout
var restore_delay = 800; // milliseconds
var image_list = new Array();

function preloadImages(brandid)
{
    // put images to preload in this array
    //var preload_list = new Array("heron.gif",	"wader.gif", "eagle.gif",	"smile.gif");
    var path_to_images = "../webcontent/product_images/large/" + brandid + "/";
    // preload (change path to images if necessary)
    if (document.images) {
	    
	    for (var preload_counter=0; preload_counter<preload_list.length; preload_counter++) 
	    {
  	        image_list[preload_counter] = new Image(); 
		        image_list[preload_counter].src = path_to_images + preload_list[preload_counter];	
         }
    }
}

function swapImage(num) {
	if (document.images) {
		document.prod_image.src = image_list[num].src;
	}
}

function checkNumeric(obj) 
{
    var re= /^\d*$/;
    okay=true

    if (obj.value=="") {obj.value="0"}


    if( !re.test(obj.value)) {
	    okay=false
	    alert ('Sorry, you have entered an invalid quantity, You must enter a number')
	    obj.value="1"
	    obj.focus()
    }
	return okay;
}

function ValidateBasketCustomerPrice(obj) 
{
    //debugger;
    var re= /^\d*\.?\d{0,2}$/;
    okay=true
    
    var sSKU;
    var sPriceSpandId;
    var sRetailPrice;
    var bRetValue=true;
    if (obj.name.lastIndexOf("_") != -1)
    {
        sSKU = obj.name.substring( obj.name.lastIndexOf("_")+1, obj.name.length)
        sPriceSpandId = "spnPrice_" + sSKU;
        sRetailPrice = document.getElementById(sPriceSpandId).innerText;
        sRetailPrice = sRetailPrice.substring(1, sRetailPrice.length); //removes £ symbol
        sRetailPrice = sRetailPrice.replace(',', ''); //removes comman
        sRetailPrice = parseFloat(sRetailPrice);
    }
      
    if (obj.value=="") {obj.value="0"}

    if( !re.test(obj.value)) 
    {
        bRetValue=false
        alert ('Sorry, you have entered an invalid value, You must enter a number')            
    }
    else if ((obj.value == "0") | (obj.value < sRetailPrice * 0.1))  // | (obj.value > sRetailPrice)
    {
        bRetValue=false
        alert ('Sorry, you have entered an invalid value, The Customer Price cannot be Zero, less than 10% or greater than retail price.')            
    }
    
    if (!bRetValue)
    {
        obj.value=sRetailPrice
        obj.focus()
    }
        
    return bRetValue;
}
