/*browser sniffer*/
var bVer = parseFloat(navigator.appVersion);
if (document.layers) {n=1;ie=0}
if (document.all) {n=0;ie=1}
if (n) {var k = "document.layers.";}
if (ie) {var k = "document.all.";}

/*Print the basket for a quote*/
function fnPrintTheBasket() {
	var page = "/public/orders/print_basket.asp";
	windowprops = "height=300,width=750,location=no,"
	+ "scrollbars=yes,menubars=no,toolbars=no,resizable=no";
	window.open(page, "Popup", windowprops);
}

/*radio buttons*/
var searchIndex = 0;
 
function fnsearch_select(radIndex){

	var returnValue = true;
	searchIndex = radIndex;
	return returnValue;
}

/*populate billing details same as delivery details*/
function fnPopulate() {
	document.regsitration.badd1.value = document.regsitration.add1.value;
	document.regsitration.badd2.value = document.regsitration.add2.value;
	document.regsitration.barea.value = document.regsitration.area.value;
	document.regsitration.bpcode.value = document.regsitration.pcode.value;
}

/*search function*/
function fnSearchSubmit(){
	
	var strStxt = "";
	var strSearch = "";
	var strRStxt = "";
	var varType = "";
	var nStartPos = 1;
	var nCompanyId = document.searchform.Cid.value;
		
	strStxt = document.all.stxt.value;
	varType = document.all.searchradio[searchIndex].value
	varEndPos = (strStxt.length) - 1
	strLastChar = strStxt.slice(varEndPos)

	if (strLastChar == "s") {
		strSearchFor = strStxt.slice(0,varEndPos)
	}
	else {
		strSearchFor = strStxt.slice(0,varEndPos + 1);
	}

	if (varType == "pcode") { strSearch = "Keyword=&Code=" + strSearchFor; }
	if (varType == "keyw") { strSearch = "Keyword=" + strSearchFor + "&Code="; }
	
	f("../../objects/Search_IPAF_1000.dll?" + strSearch + "&Startpos=" + nStartPos + "&CompanyId=" + nCompanyId);
}

function f(strURL) {
	document.location.href = strURL;
}


/*login function*/
function fnLogin() {
	var varEmail = document.logindetails.email.value;
	var varPass = document.logindetails.password.value;
	var strEmail = "";
	var strPass = "";

	if (varEmail != "" && varPass != "")  {
		var strPath = document.location.href;
		var strCPath = "";
		strCPath = strPath.replace(/[$&]/g,"*");
		document.location.href = "../../objects/validate.asp?strE=" + varEmail + "&strP=" + varPass + "&strPath=" + strCPath ;
	}
}

/*status display in the window*/
function fnDisplay(str) {
  window.status = str;
  return true;
}

/*logged on highlighting*/
function changeto(highlightcolor){
source=event.srcElement
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TR")
source=source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function changeback(originalcolor){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
return
if (event.toElement!=source)
source.style.backgroundColor=originalcolor
}

/*partsearch function*/
function fnPartSearch(ref){
	var strURL = "";
	if (ref == "GC") {strURL = document.partsearch.pdfGC.value;}
	if (ref == "LC") {strURL = document.partsearch.pdfLC.value;}
	if (ref == "MS") {strURL = document.partsearch.pdfMS.value;}
	if (ref == "OTHER") {strURL = document.partsearch.pdfOTHER.value;}
	if (strURL != "none") {
		document.location.href = "../../public/part_search/part_display.asp?strURL=" + strURL;
	}
}

/*Disable the commit order button*/
function fnRecal() {
	document.all.reg.innerHTML = "<input type='submit' class='button' name='submit' disabled value='Commit Order'>";
}