var ns = (navigator.appName.indexOf("Netscape") != -1);
function getTop(){
	return top.ns ? window.pageYOffset : document.body.scrollTop;
}
function getLeft(){
	return top.ns ? window.pageXOffset : document.body.scrollLeft;
}

function doSearch(){
	var searchString = document.getElementById("searchBox").value;
	if (searchString !=  null && searchString != ""){
		window.location.href = "searchProduct.php?cat=" + g_cat + "&q=" + searchString;
	}
}

function trimFloat(num, dp){
	var str = new String(num);
	var dIndx = str.indexOf(".");
	if (dIndx != -1){
		var locs = (str.substr(dIndx+1)).length;
		if (locs > dp){
			var len = dIndx + 1 + dp;
			var pwr = Math.pow(10, dp);
			str = Math.round(str*pwr)/pwr;
			if (str.length > len){
				str = str.substr(0,len);
			}
		}else{
			var z = dp-locs;
//			alert("locs = " + locs + "\ndp = " + dp + "\nz = " + z + "\nstr = " + str);
			for (var i = 0; i < z; i++){
				str += "0";
			}
		}
	}else{
		str += ".00";
	}
	
	return str;
//	return parseFloat(str);
}

var gParams = null;
function getCGIValue(name){
        var key, value = null;

        if (gParams == null){
        gParams = document.location.href.split("?");

        if (gParams.length > 0)
            gParams = new String(gParams[1]).split("&");
    }

        for (var i = 0; i < gParams.length; i++){
        var pEq = gParams[i].split("=");
                if (pEq.length > 1){
                        key = pEq[0];
                        value = unescape(pEq[1]);
                        if (name == key)
                                return value;
                }
        }
        return null;
}


function getRadioSelectedValue(list){
	for (var i = 0 ; i < list.length; i++){
		if (list[i].checked)
			return list[i].value;
	 }
	 
	 return null;
}

function changeSearchSelect(sel){
	document.location.href = "category.php?cat=" + sel.value;
}

function openRMP(){
	window.location.href = "/site/fmp.php";
}

function openCat(cat){
	window.location.href = "/site/category.php?cat=" + cat;
}

function changeAmountPrice(sel, priceId, origPrice){
	var disc = sel[sel.selectedIndex].getAttribute("disc");
	var pe = document.getElementById(priceId);
	if (disc == null){
		pe.innerHTML = origPrice;
	}else{
		pe.innerHTML = trimFloat(origPrice-(origPrice*disc / 100), 2);
	}
}

function gotoBasket(){
	window.location.href = "/site/basket.php?cat="+cat;
}

function matchEngine(id){
	var o = document.getElementById("engine_" + id);
	var val = o[o.selectedIndex].value;
	if (val == -1){
		alert("אנא בחר יצרן");
	}else{
		var lnk = new Array();
		lnk[lnk.length] = "engine.php?cat=";
		lnk[lnk.length] = 3;//writing media allways
		lnk[lnk.length] = "&enType=";
		lnk[lnk.length] = id;
		lnk[lnk.length] = "&enNid=";
		lnk[lnk.length] = val;
		
		window.location.href = lnk.join("");
	}
}

function showToolTip(e){
	var elem = document.getElementById("tooltip");
	elem.style.left = e.x;
	elem.style.top = e.y;
	elem.style.display = "inline";
}

function hideToolTip(){
	document.getElementById("tooltip").style.display = "none";
}

//------------------------------------------------------
Array.prototype.remove = function (val){
	for (var i = 0; i < this.length; i++){
		if (this[i] == val)
		 this.splice(i, 1);
	}
}
Array.prototype.contain = function (val){
	for (var i = 0; i < this.length; i++){
		if (this[i] == val)
			return true;
	}
	
	return false;
}