﻿//This function validate the search box
function chkForm() {
	if (document.frmSearch.query.value=='')
	{
		alert('חובה להקליד לפחות מילת חיפוש אחת');
		return false;
	}
	document.frmSearch.submit();
	return true;
}

//-----------------------------------------------------------------------------------
// This function add item into the shopping cart using AJAX
function fAdd2Cart(prodid,count,changebtn){
	var getCount;
	if (changebtn) { //replace the add2cart image
		document.getElementById('i'+ prodid).style.background = "#BBDCED url(images/cart.gif) 99% 10% no-repeat";
	}
getCount=GetXmlResponse("prodid="+prodid+"&count="+count, "add2cart.asp",true)
if (getCount==0){
	document.getElementById("oTermDiv").innerHTML = '<a href="cart.asp">סל הקניות שלך ריק</a>'
}
else{
	document.getElementById("oTermDiv").innerHTML ='<a href="cart.asp">' + getCount + ' מוצרים בסל</a>'
	}
}

//-----------------------------------------------------------------------------------
// This function is an impementation of AJAX
 function GetXmlResponse(DataToSend, URL, bText)
{
    var xmlhttp
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE new version
	    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
  	} else if (window.ActiveXObject) { // IE old version
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
    xmlhttp.open("POST",URL ,false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1255");
    xmlhttp.send(DataToSend);
    return(bText?xmlhttp.responseText:xmlhttp.responseXML);
}