//if (location.href.indexOf("telepath.co.il")==-1) location.href="http://www.telepath.co.il";
//else if ((location.href.indexOf("www.")==-1) && (location.href.indexOf("http://")!=-1)) location.href=location.href.replace("http://","http://www.");
var About_On = new Image(); About_On.src = "images/B_About_On.gif";
var Contact_On = new Image(); Contact_On.src = "images/B_Contact_On.gif";
var Search_On = new Image(); Search_On.src = "images/B_Search_On.gif";
var English_On = new Image(); English_On.src = "images/B_English_On.gif";
function ChangePic(Btn) {
  if (Btn.src.indexOf("_Off")>-1) Btn.src=Btn.src.replace("_Off","_On");
  else Btn.src=Btn.src.replace("_On","_Off");
}

function Go2Link(TheLink) {
  location.href=TheLink;
}

function SHL(layerName) {
  if (document.getElementById(layerName).style.visibility=="visible") {
    document.getElementById(layerName).style.visibility="hidden";
    document.getElementById(layerName).style.display="none";
  } else {
    document.getElementById(layerName).style.visibility="visible";
    document.getElementById(layerName).style.display="inline";
  }
}

function ChangeAdvOptLinkText(tagID) {
  if (document.getElementById(tagID).innerText.indexOf("הצג")==-1) document.getElementById(tagID).innerText="הצג אפשרויות חיפוש מתקדם";
  else document.getElementById(tagID).innerText="הסתר אפשרויות חיפוש מתקדם";
}

function OpenWindow(Address,WinWidth,WinHeight) {
  window.open(Address,"NewWin","width="+WinWidth+",height="+WinHeight+",resizeable='yes'");
}

function ShowCart(CartItems) {
  CartItems=CartItems.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  if (CartItems=="") {
    document.write("<td colspan='5' align='center'>העגלה ריקה</td>");
  } else {
    var Sum=0;
    for (i in CartItems) {
      SpecItem=CartItems[i].split("|");
      document.write("<tr>");
      document.write("<td title='סמן על מנת למחוק מוצר זה' align='center'><input type='checkbox' name='Del"+i+"' id='Del"+i+"'></td>");
      document.write("<td><a href='Products_Options.asp?Action=View&ItemID="+SpecItem[0]+"'>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'><input type='text' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"' style='width:25px;'></td>");
      document.write("<td align='center'><input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'>"+SpecItem[3]+" ₪</td>");
      document.write("<td align='center'>"+parseFloat(SpecItem[3])*parseInt(SpecItem[2])+" ₪</td>");
      document.write("</tr>");
      Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
    }
    document.write("<tr bgcolor='#E2E2E2'><td colspan='4' align='left'><b><font color='red'>סה\"כ</font></b>&nbsp;<input type='hidden' name='NumberOfItems' id='NumberOfItems' value='"+i+"'></td><td align='center'><font color='red'><b>"+Sum+" ₪</b></font></td></tr>");
  }
}

function ShowCartE(CartItems) {
  CartItems=CartItems.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  if (CartItems=="") {
    document.write("<td colspan='5' align='center'>The cart is empty</td>");
  } else {
    var Sum=0;
    for (i in CartItems) {
      SpecItem=CartItems[i].split("|");
      document.write("<tr>");
      document.write("<td title='check to delete' align='center'><input type='checkbox' name='Del"+i+"' id='Del"+i+"'></td>");
      document.write("<td><a href='Products_Options.asp?Action=View&ItemID="+SpecItem[0]+"&Lang=E'>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'><input type='text' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"' style='width:25px;'></td>");
      document.write("<td align='center'><input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'>"+SpecItem[3]+" ₪</td>");
      document.write("<td align='center'>"+parseFloat(SpecItem[3])*parseInt(SpecItem[2])+" ₪</td>");
      document.write("</tr>");
      Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
    }
    document.write("<tr bgcolor='#E2E2E2'><td colspan='4' align='left'><b><font color='red'>סה\"כ</font></b>&nbsp;<input type='hidden' name='NumberOfItems' id='NumberOfItems' value='"+i+"'></td><td align='center'><font color='red'><b>"+Sum+" ₪</b></font></td></tr>");
  }
}

function ShowCartList(CartItems) {
  CartItems=CartItems.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  if (CartItems=="") {
    document.write("אין מוצרים בעגלה.");
  } else {
    var Sum=0;
    for (i in CartItems) {
      SpecItem=CartItems[i].split("|");
      Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
      document.write(SpecItem[2]+" <font color='green' size='-2'><b>X</b></font> "+SpecItem[1]+"<hr>");
    }
    document.write("<b><font color='red'>סה\"כ: "+Sum+" ₪</font></b>");
    document.write("<br><br><a href='Cart_Options.asp?Action=Clear'>רוקן עגלה</a>")
    document.write("<br><b><font size='2'><a href='Cart_Options.asp'>לעגלה/קופה</a></form></b>")
  }
}

function ShowItems(Items) {
//Writes the same as "ShowCart" function, but without the option to change an amount and delete.
  Items=Items.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  var Sum=0;
  for (i in Items) {
    SpecItem=Items[i].split("|");
    if (SpecItem[0].indexOf("C")!=-1) {
      if (SpecItem[0].indexOf("P")!=-1) CuponSign="%";
      else CuponSign="₪";
      document.write("<tr>");
      document.write("<td><a>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'>"+SpecItem[2]+"<input type='hidden' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"'></td>");
      document.write("<td align='center'>-"+SpecItem[3]+" "+CuponSign+"<input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'></td>");
      document.write("<td align='center'>-"+SpecItem[3]+" "+CuponSign+" </td>");
      document.write("</tr>");
      if (SpecItem[0].indexOf("P")!=-1) Sum=Sum-parseFloat(Sum*SpecItem[3]/100);
      else Sum=Sum-SpecItem[3];
    } else {
      document.write("<tr>");
      document.write("<td><a href='Products_Options.asp?Action=View&ItemID="+SpecItem[0]+"'>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'>"+SpecItem[2]+"<input type='hidden' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"'></td>");
      document.write("<td align='center'>"+SpecItem[3]+" ₪<input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'></td>");
      document.write("<td align='center'>"+parseFloat(SpecItem[3])*parseInt(SpecItem[2])+" ₪</td>");
      document.write("</tr>");
      Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
    }
  }
  document.write("<tr bgcolor='#E2E2E2'><td colspan='3' align='left'><b><font color='red'>סה\"כ</font></b>&nbsp;<input type='hidden' name='NumberOfItems' id='NumberOfItems' value='"+i+"'></td><td align='center'><font color='red'><b>"+Sum+" ₪</b></font></td></tr>");
}

function ShowItemsE(Items) {
//Writes the same as "ShowCart" function, but without the option to change an amount and delete.
  Items=Items.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  var Sum=0;
  for (i in Items) {
    SpecItem=Items[i].split("|");
    if (SpecItem[0].indexOf("C")!=-1) {
      if (SpecItem[0].indexOf("P")!=-1) CuponSign="%";
      else CuponSign="₪";
      document.write("<tr>");
      document.write("<td><a>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'>"+SpecItem[2]+"<input type='hidden' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"'></td>");
      document.write("<td align='center'>-"+SpecItem[3]+" "+CuponSign+"<input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'></td>");
      document.write("<td align='center'>-"+SpecItem[3]+" "+CuponSign+" </td>");
      document.write("</tr>");
      if (SpecItem[0].indexOf("P")!=-1) Sum=Sum-parseFloat(Sum*SpecItem[3]/100);
      else Sum=Sum-SpecItem[3];
    } else {
      document.write("<tr>");
      document.write("<td><a href='Products_Options.asp?Action=View&ItemID="+SpecItem[0]+"'>"+SpecItem[1]+"</a><input type='hidden' name='Name"+i+"' id='Name"+i+"' value='"+SpecItem[0]+"|"+SpecItem[1]+"'></td>");
      document.write("<td align='center'>"+SpecItem[2]+"<input type='hidden' name='Amount"+i+"' id='Amount"+i+"' value='"+SpecItem[2]+"'></td>");
      document.write("<td align='center'>"+SpecItem[3]+" ₪<input type='hidden' name='Price"+i+"' id='Price"+i+"' value='"+SpecItem[3]+"'></td>");
      document.write("<td align='center'>"+parseFloat(SpecItem[3])*parseInt(SpecItem[2])+" ₪</td>");
      document.write("</tr>");
      Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
    }
  }
  document.write("<tr bgcolor='#E2E2E2'><td colspan='3' align='right'><b><font color='red'>Sum</font></b>&nbsp;<input type='hidden' name='NumberOfItems' id='NumberOfItems' value='"+i+"'></td><td align='center'><font color='red'><b>"+Sum+" ₪</b></font></td></tr>");
}

function WriteSum(CartItems) {
  CartItems=CartItems.split("|^^|");
//Item Line: ProductID | Name/Weight/Taste | Amount | Price
  var Sum=0;
  for (i in CartItems) {
    SpecItem=CartItems[i].split("|");
    if (SpecItem[0].indexOf("CP")!=-1) Sum=Sum-parseFloat(Sum*SpecItem[3]/100);
    else if (SpecItem[0].indexOf("CM")!=-1) Sum=Sum-SpecItem[3];
    else Sum=Sum+(parseFloat(SpecItem[3])*parseInt(SpecItem[2]));
  }
  document.write(Sum+" ₪");
}

var otherLayer="SignUp";
function RegType(layer) {
  document.getElementById(otherLayer).style.visibility="hidden";
  document.getElementById(otherLayer).style.display="none";
  document.getElementById(layer).style.visibility="visible";
  document.getElementById(layer).style.display="inline";
  otherLayer=layer;
}

var FirstTImeSetSubCat=true;
function SetProductsOptions() {
  for (i=0;i<document.all.ProductID.options.length;i++) document.all.ProductID.options[i]=null;
  if (document.all.ProductID.options.length>0) for (i=0;i<document.all.ProductID.options.length;i++) document.all.ProductID.options[i]=null;
  if (FirstTImeSetSubCat) {
    ProductsOptions=ProductsOptions.split("|^|");
    FirstTImeSetSubCat=false;
  }
  for (i in ProductsOptions) {
    if (parseInt(ProductsOptions[i].split("|")[1])==parseInt(document.all.CatID.options[document.all.CatID.options.selectedIndex].value)) {
      document.all.ProductID.options[document.all.ProductID.length]=new Option(ProductsOptions[i].split("|")[2],ProductsOptions[i].split("|")[0]);
    }
  }
  if (document.all.ProductID.length==0) document.all.ProductID.options[document.all.ProductID.length]=new Option('אין','0');
}

function SwapImg(TheImage) {
   if (TheImage.src.indexOf("_On") != -1) TheImage.src = TheImage.src.replace("_On","_Off");
   else TheImage.src = TheImage.src.replace("_Off","_On");
}
function PNGswap(TheImage)
{
   if (TheImage.filters(0).src.indexOf("_On") != -1) TheImage.filters(0).src = TheImage.filters(0).src.replace("_On","_Off");
   else TheImage.filters(0).src = TheImage.filters(0).src.replace("_Off","_On");
}

nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta) {
  if (!document.all) return;
  if (object != "[object]") {  
    setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
    return;
  }
  clearTimeout(nereidFadeTimers[object.sourceIndex]);
  diff = destOp-object.filters.alpha.opacity;
  direction = 1;
  if (object.filters.alpha.opacity > destOp) direction = -1;
  delta=Math.min(direction*diff,delta);
  object.filters.alpha.opacity+=direction*delta;
  if (object.filters.alpha.opacity != destOp) {
    nereidFadeObjects[object.sourceIndex]=object;
    nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
  }
}

function CreateFlashObject(source,width,height,trans) {
  document.writeln("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' align='middle'>");
  document.writeln("  <param name='allowScriptAccess' value='sameDomain' />");
  if (trans) document.writeln("  <param NAME='wmode' VALUE='transparent' />");
  document.writeln("  <param name='movie' value='"+source+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' />");
  document.writeln("  <embed src='"+source+"' quality='high' bgcolor='#ffffff' width='"+width+"' height='"+height+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
  document.writeln("</object>");
}

function FAQSwap(obj,FAQID) {
  if ((FAQID==0) && (obj.src.indexOf("_Down")==-1)) SwapImg(obj);
  else if ((FAQID!=0) && (obj.src.indexOf("_Down")==-1)) {
    obj.src=obj.src.replace("_On","_Down");
    SHL("Q"+FAQID);
//    document.getElementById("Q"+FAQID).style.display="block";
//    document.getElementById("Q"+FAQID).style.visibility="visible";
  } else if ((FAQID!=0) && (obj.src.indexOf("_Down")!=-1)) {
    obj.src=obj.src.replace("_Down","_On");
    SHL("Q"+FAQID);
//    document.getElementById("Q"+FAQID).style.display="none";
//    document.getElementById("Q"+FAQID).style.visibility="hidden";
  }
}

function LoadPNG(img) {
  var arVersion = navigator.appVersion.split("MSIE");
  var version = parseFloat(arVersion[1]);
  if ((version >= 5.5) && (document.body.filters)) 
  {
    var imgID = (img.id) ? "id='" + img.id + "' " : "";
    var imgClass = (img.className) ? "class='" + img.className + "' " : "";
    var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
    var imgStyle = "display:inline-block;" + img.style.cssText;
    if (img.align == "left") imgStyle = "float:left;" + imgStyle;
    if (img.align == "right") imgStyle = "float:right;" + imgStyle;
    if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
    var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"";
    if (img.attributes.onmouseover.value != "") strNewHTML += " onmouseover=\""+img.attributes.onmouseover.value+"\"";
    if (img.attributes.onmouseout.value != "") strNewHTML += " onmouseout=\""+img.attributes.onmouseout.value+"\"";
    if (img.attributes.onclick.value != "") strNewHTML += " onclick=\""+img.attributes.onclick.value+"\"";
    strNewHTML += "></span>";
    img.outerHTML = strNewHTML;
  }
}

function SubmitOnEnter(theForm,theEvent) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if (keycode == 13) {
    document.getElementById("SubmitButton").click();
  } else return true;
}