/*  700 - Quick Product Search Front End
Ajax routine to automatically populate list of product when typing keywords
*/
function getproductdesc(str,divname)
{
   document.getElementById(divname + "resultlist").style.visibility="visible";
   if (str.length==0)
   {
      document.getElementById(divname + "resultlist").style.visibility="hidden";
   }

   var checkingurl="shopajaxsearchlookup.asp"
   var pars = 'keyword=' + str;
   var target = divname + 'resultlist';
   var myAjax = new Ajax.Updater(target, checkingurl, {method: 'post',parameters: pars});
}

// VPASP CUSTOMISATION - 2011.04.13 - Bobby
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }
}

function getproductoutofstock(str,divname)
{

  // VPASP CUSTOMISATION - 2011.04.13 - Bobby
  var baseurl = getBaseURL();
  var e1 = document.getElementById("NPoSProductSizes");
  var size = e1.options[e1.selectedIndex].text;

  if (divname == "outofstockmsg1")
  {
// this is the code for the size pulldown
	var rl=queryvalue("rl");
	if (rl != "")
	{
		
	}
	else
	{
		var e = document.getElementById("NPoSProductColour");
		rl = e.options[e.selectedIndex].text;
	}
	window.location.href = baseurl + "shopexd.asp?id="+str+"&rl=" +rl+"&size="+size;
//	alert( baseurl + "shopexd.asp?id="+str+"&rl=" +rl+"&size="+size);

   }
  else
  {

// this is the code for the colour pulldown
	var e2 = document.getElementById("NPoSProductSizes");
	var size1 = e2.options[e2.selectedIndex].value;
// 	alert(size1);	
	window.location.href = baseurl + "shopexd.asp?id="+size1+"&rl="+str+"&size="+size;	


	//location.reload(true)
	//document.location.hash = baseurl + "shopexd.asp?id="+size1+"&rl="+str+"&size="+size;
	
  }
   // document.getElementById(divname).style.visibility="visible";
}
function getproductoutofstock1(str,divname)
{

  // VPASP CUSTOMISATION - 2011.04.13 - Bobby
  var baseurl = getBaseURL();
  window.location.href = baseurl + "shopdisplayproducts.asp?id="+str+"&cat="+queryvalue("cat");

   // document.getElementById(divname).style.visibility="visible";
   // if (str.length==0)
   // {
      // document.getElementById(divname).style.visibility="hidden";
   // }
   // document.getElementById(divname).innerHTML="<img src='../images/ajaxshippingload.gif' border='0'> checking stock...";
   // var checkingurl="shopajaxoutofstocklookup.asp"
   // var pars = 'keyword=' + str;
   // var target = divname;
   // var myAjax = new Ajax.Updater(target, checkingurl, {method: 'post',parameters: pars});
}
function queryvalue( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
