var prodCatLast = ""
var idTM

function trim1(iSt){
	var rSt = iSt
	
	if (typeof(rSt) == "undefined") return "-"
	
	var isSpace = true
	for(i=iSt.length-1; i > 0; i--) {
		if ((iSt.charAt(i) == ' ') && (isSpace)) {
			rSt = iSt.substring(0, i)
		} else {
			isSpace = false
		}
	}

	iSt = rSt
	var isSpace = true
	for(i=0; i < iSt.length; i++) {
		if ((iSt.charAt(i) == ' ') && (isSpace)) {
			j = i + 1
			rSt = iSt.substring(j, iSt.length)
		} else {
			isSpace = false
		}
	}

	return rSt;
}

function trim(s){
	if (typeof(s) == "undefined") return "-"
	var rSt="";
	for(i=0; i < s.length; i++) if(s.charAt(i) != ' ') rSt += s.charAt(i);
	return rSt;
}

function checkValue(vtc) {

	allowString = "abcdefghijklmnopqrstuvwxyz0123456789_."

	if (typeof(vtc) != "string") return false;	

	vtc = vtc.toString()
	vtc = vtc.toLowerCase()

	for (q=0; q<vtc.length; q++) {
		if (allowString.indexOf(vtc.charAt(q))<0) {
			alert("wrong name")
			return false;
			break;
		}
	}

	return true;

}

function regType_change() {

	if (document.forma.regType.value == "P") {
		document.forma.regType.value = "C"
		document.getElementById("regComp").style.display = ""
		document.forma.cmpStreet.value = document.forma.cstStreet.value
		document.forma.cmpCity.value = document.forma.cstCity.value
		document.forma.cmpZip.value = document.forma.cstZip.value
	} else {
		document.forma.regType.value = "P"
		document.getElementById("regComp").style.display = "none"
	}

}

function konfPriceSet() {

	if (document.konfForm.opts.value > 0) {

		price = 0
		priceFull = 0
	
		for (idO = 0; idO < document.konfForm.opts.value; idO ++ ) {

			for (id = 0; id < optItem.length; id++) {
	
				if (optItem[id] == document.konfForm["opt" + idO].value) {
	
					if (optType[idO] == "s") {
						price += optPrice[id]
						priceFull += optPriceFull[id]
					}
	
					if (optType[idO] == "c") {
						if (document.konfForm["opt" + idO].checked == 1) {
							price += optPrice[id]
							priceFull += optPriceFull[id]
						}
					}
	
					break;
				}
			
			}
		}
	
		price = Math.round(price)
		priceFull = Math.round(priceFull)

		pricevat = Math.round((price*document.konfForm.vat.value)/10000)
		priceFullVat = Math.round((priceFull*document.konfForm.vat.value)/10000)

		//price = Math.round(price/100)
	
		document.getElementById("idprice").innerHTML = numberStyle(Math.round(price/100), 0)
		document.getElementById("idpricevat").innerHTML = numberStyle(pricevat, 0)
	
		if (parseInt(isPriceDisc) == 1) {
			disc = Math.round((((priceFull-price))/priceFull)*1000)
			document.getElementById("idpricedisc").innerHTML = numberStyle(disc, 1)
		}

	}
	
	
}

function numberStyle(strNumber, decp){

	var i = 0;
	var j = 0;
	var txt_new = "";
	var txt_end = "";

	var fltNumber =  Math.round(parseFloat(strNumber));
	strNumber = fltNumber.toString();

	var intLenght = strNumber.length;
	if (fltNumber == 0)	return "0,00 "

	var txt = strNumber.substring(0, intLenght-decp);
	if (decp != 0) var txt_end = "," + strNumber.substring(intLenght-decp);

	for (i = (txt.length - 1); i >= 0; i--){
		j++;
		txt_new = txt.substring(i, i+1) + txt_new;
		if (j > 2) {
			txt_new = " " + txt_new;
			j = 0;
		}
	}

	if (txt_new.substring(0, 1) != " ") txt_new = " " + txt_new

	return txt_new + txt_end
}

function basketAct(act) {

	if (act == "orderDlvrC") {
		if (document.formBask.vchCode.value == "") {
			act = ""
			if (document.getElementById("vchLabel")) {document.getElementById("vchLabel").style.color = "red"}
		} else {
			act = "orderDlvr"
		}
	}

	if (act != "") {
		document.formBask.redir.value = act
		document.formBask.submit()
	}
}

function paySave() {

	document.formPay.act.value = "save"
	document.formPay.submit()

}

function payGoBack() {
	document.location.href = "/basket.asp"
}

function paySetVal() {
	document.formPay.act.value = ""
	document.formPay.submit()
}

function prodSearch() {

	if (document.getElementById("formProdSrch").value != "") {
		document.location.href = "/productSearch.asp?pn=" + document.getElementById("formProdSrch").value
	}
}

function basketOrder() {
	document.location.href = "/basket.asp"
}

function konfShowSpecif() {

	document.getElementById("idKonfCmptb").style.display = "none"
	document.getElementById("idKonfSpecif").style.display = ""

}

function konfShowCmptb() {

	document.getElementById("idKonfSpecif").style.display = "none"
	document.getElementById("idKonfCmptb").style.display = ""

}

function sortProductType() {

	document.formSort.pg.value = 0
	document.formSort.submit()

}

function sortProductDir(typDir) {

	document.formSort.pg.value = 0
	document.formSort.sd.value = typDir
	document.formSort.submit()

}

function npMenu(npId) {

	if ((document.getElementById("np_" + npId)) && (document.getElementById("npi_" + npId))) {
		if (document.getElementById("np_" + npId).style.display == "none") {
			document.getElementById("np_" + npId).style.display = ""
			document.getElementById("npi_" + npId).src = "/shpImg/ups1.gif"
		} else {
			document.getElementById("np_" + npId).style.display = "none"
			document.getElementById("npi_" + npId).src = "/shpImg/dns1.gif"
		}
	}

}

function prodDescrHelpOpen(obj, msgD) {

	var objX = 0;
	var objY = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			objX += obj.offsetLeft
			objY += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if ((obj.x) && (obj.y)) {
		objX += obj.x;
		objY += obj.y;
	}

	if (objX == 0) objX = 100;
	if (objY == 0) objY = 100;

	//alert(objX + " - " + objY);

	if (document.getElementById("idProdDescrH")) {
		document.getElementById("idProdDescrHT").innerHTML = msgD;  
		document.getElementById("idProdDescrH").style.left = objX +20 +'px';
		document.getElementById("idProdDescrH").style.top = objY + 20 + 'px';  
		document.getElementById("idProdDescrH").style.width = "200"
		document.getElementById("idProdDescrHT").style.width = "190"
		document.getElementById("idProdDescrH").style.display = 'block';  
	}


}

function prodDescrHelpHide() {
	document.getElementById("idProdDescrHT").innerHTML = ""
	document.getElementById("idProdDescrH").style.display = "none"
}

function prodCatShow(catId) {

	if (document.getElementById("prodCat_" + prodCatLast)) {document.getElementById("prodCat_" + prodCatLast).style.display="none"}
	if (document.getElementById("prodCat_" + catId)) {document.getElementById("prodCat_" + catId).style.display=""}
	prodCatLast = catId

	window.clearTimeout(idTM)
	
}

function prodCatHide() {
	if (document.getElementById("prodCat_" + prodCatLast)) {
		if (document.getElementById("prodCat_" + prodCatLast).style.display=="") {idTM = window.setTimeout("prodCatHideR()", 1000)}
	}
	
}

function prodCatHideR() {

	if (document.getElementById("prodCat_" + prodCatLast)) {document.getElementById("prodCat_" + prodCatLast).style.display="none"}

}

function custLogFrmShow(catId) {

	if (document.getElementById("idCustLogFrm")) {
		document.getElementById("idCustLogFrm").style.display=""
		document.custLogFrm.cstEmail.focus()
	}
	window.clearTimeout(idTM)
	
}

function custLogFrmHide() {
	if (document.getElementById("idCustLogFrm")) {
		if (document.getElementById("idCustLogFrm").style.display=="") {idTM = window.setTimeout("custLogFrmHideR()", 1500)}
	}
	
}

function custLogFrmHideR() {

	if (document.getElementById("idCustLogFrm")) {document.getElementById("idCustLogFrm").style.display="none"}

}


