// JavaScript Document

if (location.host=='localhost') 
{
	currentPath = document.location.href.split('/');
	var HttpPath = 'http://'+location.host+'/'+currentPath[3]+'/';
}
else 
{
	var HttpPath = 'http://'+location.host+'/';
}

	function getRand() {
		return randomnumber=Math.floor(Math.random()*10000001);
	}
	function dispBasketTotals() {
	   $("#basketbox").load(HttpPath+'WebShop/JsDisplayBasket.cfm?uid='+getRand())
	}
	function getBasket() {
	   $("#popupbox").load(HttpPath+'WebShop/JsGetBasket.cfm?uid='+getRand())
	   resizewin('popupbox',750,0);
	   openPopup('popupbox');
	}
	function removeBasketItem(oLine) {
	   $("#result").load(HttpPath+'WebShop/JsRemoveBasketItem.cfm?oLine='+escape(oLine)+'&uid='+getRand());
}
	function getPreview() {
    	$("#previewbox").load(HttpPath+'webshop/ProductPreview.cfm?uid='+getRand()).hide().fadeIn('slow')
		setTimeout("getPreview()", 15000)
	}
	function viewProductDetails(prodcode) {
	   $("#popupbox").load(HttpPath+'WebShop/JsViewProductDetails.cfm?ProdCode='+escape(prodcode)+'&uid='+getRand())
	   resizewin('popupbox',750,0);
		openPopup('popupbox');
	}
	function viewLinkedProductDetails(prodcode,linkedproduct) {
	   $("#popupbox").load(HttpPath+'WebShop/JsViewProductDetails.cfm?ProdCode='+escape(prodcode)+'&linkedproduct=1&uid='+getRand())
	   resizewin('popupbox',750,0);
	openPopup('popupbox');
	}
	function viewProductDetailsFromOrder(prodcode) {
	   $("#popupbox").load(HttpPath+'webshop/JsViewProductDetails.cfm?ProdCode='+escape(prodcode)+'&uid='+getRand())
	   resizewin('popupbox',750,0);
		openPopup('popupbox');
	}

	function blogComment(blogId) {
	   $("#popupbox").load(HttpPath+'blog/Comment.cfm?BlogId='+escape(blogId)+'&uid='+getRand())
	   resizewin('popupbox',650,0);
		openPopup('popupbox');
	}
	function blogSendLink(blogId) {
	   $("#popupbox").load(HttpPath+'blog/SendLink.cfm?BlogId='+escape(blogId)+'&uid='+getRand())
	   resizewin('popupbox',650,0);
	openPopup('popupbox');
	}
	function showDiv(divid) {
		$('#pgp'+divid).slideDown("fast");
		document.getElementById('crbshow'+divid).style.display = 'none';
		document.getElementById('crbhide'+divid).style.display = 'block';
	}	
	function hideDiv(divid) {
		$('#pgp'+divid).slideUp("slow");
		document.getElementById('crbshow'+divid).style.display = 'block';
		document.getElementById('crbhide'+divid).style.display = 'none';
	}


	function PaginateSearch(startrow,pg,totalrecords,sortord,srchterm) {
		$("#searchresult").load('../FileManager/SearchResults.cfm?StartRow='+escape(startrow)+'&pg='+escape(pg)+'&TotalRecords='+escape(totalrecords)+'&SortOrd='+escape(sortord)+'&SrchTerm='+escape(srchterm))
	}
	function updSearchSortOrd(sortord,srchterm) {
	   $("#searchresult").load('../FileManager/SearchResults.cfm?SortOrd='+escape(sortord)+'&srchterm='+escape(srchterm))
	}

	function viewFaq(faqid) {
	   $("#faqbox").load(HttpPath+'info/FaqAnswers.cfm?FaqId='+escape(faqid)+'&uid='+getRand())
	   	document.getElementById('faqboxholder').style.display = 'block';
	}
	function closeFaq() {
	   	document.getElementById('faqboxholder').style.display = 'none';
	}
	function loadWindow(thediv,pagetoload) {
		$('#'+thediv).load(pagetoload)
	}

function calcOptPrice() {
var thedivs = document.getElementsByTagName('select');
var optTot = 0;
for (x=0;x<thedivs.length;x++){
   if(thedivs[x].id.substr(0,9)=='ProdComps'){
   		newVal = thedivs[x].value;
		newVal = newVal.split("|");
       optTot = optTot + Number(newVal[2]);
   }
}
	optTot = optTot + Number(document.getElementById('unitVal').value);
	optTot = optTot * Number(document.getElementById('qtyOrdered').value);

	document.getElementById('optprice').innerHTML = '&pound;' + optTot.toFixed(2) + '*';
}

