// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fill(combo, name, src)
{
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4)
		{
			if (xmlhttp.status != 200)
			{
				alert("שגיאה!");
				return;
			}
			var doc = new ActiveXObject("Microsoft.XMLDOM");
			doc.async = false;
			doc.loadXML(xmlhttp.responseText);
			var nodes = doc.selectNodes("xml/rs:data/z:row");
			combo.length = 1;
			for (i=0; i < nodes.length; i++)
			{
				var opt = document.createElement("OPTION");
				opt.value = nodes[i].getAttribute("ID");
				opt.text = nodes[i].getAttribute("Name");
				combo.add(opt);
			}
			xmlhttp = null;
			doc = null;
		}
	}
	xmlhttp.open("GET", "getxml.asp?" + name + "=" + src.value, true);
//	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send();
}

function GetComboData( ComboID, Name, Table, Src, SrcValue ){ 
 var combo = document.getElementById(ComboID);
 var retArr = new Array();
 var myAjax = new Ajax.Request(
   'getdata.asp?Name='+Name+'&Table='+Table+'&Src='+Src+'&SrcValue='+SrcValue,
   {
    method: 'get', 
    onComplete: function(response) { 
     retArr=response.responseText.split(';');
     combo.options.length=1;
     for(i=0; i< (retArr.length/2)-1; i++){
      combo.options[i+1] = new Option(retArr[2*i], retArr[2*i+1]);
     }
     combo.selectedIndex=0;
     
    }
    
   }                    );
}

function getDeliveryPrice(id)
{ 
 var totalPrice = document.getElementById('TotalPlusDelivery');
 var total = document.CartForm.Sum;
 var myAjax = new Ajax.Request(
   'getDeliveryPrice.asp?DeliveryID='+id,
   {
    method: 'get', 
    onComplete: function(response) 
	{ 
		price=response.responseText;
		totalPrice.innerHTML = parseFloat(total.value) + parseFloat(price);
		document.CartForm.Delivery.value = price;
    }
    
   }
);
}

function overData()
{
	var obj = window.event.srcElement;
	if (obj.tagName == "TD")
	{
		if (obj.parentElement.className.indexOf("click") < 0)
			obj.parentElement.className += " over";
	}
	else if (obj.tagName == "TH")
	{
		obj.className = "over";
	}
}

function outData()
{
	var obj = window.event.srcElement;
	if (obj.tagName == "TD")
	{
		if (obj.parentElement.className.indexOf("over") > 0)
			obj.parentElement.className = obj.parentElement.className.replace(" over", "");
	}
	else if (obj.tagName == "TH")
	{
		obj.className = "";
	}
}

/*function window.onscroll()
{
	obj = document.getElementById("sidebanner");
	if (!obj) return;
	obj.style.top = document.body.scrollTop;
	obj2 = document.getElementById("sidebanner2");
	if (!obj2) return;
	obj2.style.top = document.body.scrollTop;
}
*/
function showHide(id)
{
	oDiv = document.getElementById(id);
	if (oDiv)
	{
		if (oDiv.style.display == "none")
		{
			oDiv.style.display = "block";
		}
		else
		{
			oDiv.style.display = "none";
		}
	}
}

function sortData(strURL, strSort)
{
	var obj = window.event.srcElement;
	if (obj.tagName == "TH")
	{
		var ID = obj.id;
		if (ID)
		{
			strURL += "&Sort=" + ID;
			if (strSort == ID)
			{
				strURL += " DESC"
			}
			window.location.replace(strURL);
		}
	}
}

function menuclick(id)
{
	div = document.getElementById("div" + id);
	img = document.getElementById("p" + id);
	/*
	div.style.display = "block";
	if (lastmenuclickid > 0) {
		div = document.getElementById("div" + lastmenuclickid);
		div.style.display = "none";
	}
	lastmenuclickid = id;
	*/
	if (div.style.display != "none")
		div.style.display = "none";
		//alert(img);
		//img.style.display = "none";
	else
		div.style.display = "block";
		//img.style.display = "block";
	
}

function searchProduct()
{
	if (searchForm.Search.value != "")
		searchForm.submit();
	else
		alert("יש לרשום מלת חיפוש");
}

function openproduct(id)
{
	var args = "left=300, top=200, width=450, height=450, status=no, toolbar=no, menubar=no, scrollbars=yes, location=no";
	window.open("showproduct.asp?ProductID=" + id, "", args);
}
