function SwapImg(obj) {
  if (obj.src.indexOf("_On") != -1) obj.src = obj.src.replace("_On","_Off");
  else obj.src = obj.src.replace("_Off","_On");
}

function SHL(layerID) {
  if (layerID=="") return;
  if (document.getElementById(layerID).style.display=="block") {
    document.getElementById(layerID).style.display = "none";
    document.getElementById(layerID).style.visibility = "hidden";
  } else {
    document.getElementById(layerID).style.display = "block";
    document.getElementById(layerID).style.visibility = "visible";
  }
}
function HL(layerID) {
  if (layerID=="") return;
  document.getElementById(layerID).style.display = "none";
  document.getElementById(layerID).style.visibility = "hidden";
}
function CheckMainForm(Lang) {
  var errorMessage = "";
  if (Lang==1) errorMessage = "שגיאה: לא הוזן פרמטר חיפוש.";
  else errorMessage = "Error: No search parameter was assigned.";
  if (document.getElementById("MainSearchForm").MainSearch.value == "" || document.getElementById("MainSearchForm").MainSearch.value == "חיפוש חופשי"  || document.getElementById("MainSearchForm").MainSearch.value == "Free Search") alert(errorMessage);
  else document.getElementById("MainSearchForm").submit();
}

function GoToCat(id) {
  location.href = "Products.asp?SearchType=Cat&Cat="+id;
}

function GoToCatEng(id) {
  location.href = "ProductsEng.asp?SearchType=Cat&Cat="+id;
}
function ShowLayer(layerID) {
  SHL("Details"+layerID);
  SHL("HideHref"+layerID);
  SHL("ShowHref"+layerID);
}

function HideLayer(layerID) {
  SHL("Details"+layerID);
  SHL("HideHref"+layerID);
  SHL("ShowHref"+layerID);
}

function CreateFlashObject(source,width,height) {
  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' /><param NAME='wmode' VALUE='transparent' />");
//  document.writeln("  <param name='allowScriptAccess' value='sameDomain' />");
  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 Trim(str) { if(str) return( str.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); else return ""; }
function RetFalse(obj,msg) { alert(msg);obj.focus();/*obj.select();*/return false; }

function CheckContactUs(TheForm) {
  TheForm.FullName.value=Trim(TheForm.FullName.value);
  if (TheForm.FullName.value == "") return RetFalse(TheForm.FullName, "שגיאה: אתה חייב להכניס שם מלא.");
  if (!(/^[A-Za-zא-ת\'\-\'_ ]+$/.test(TheForm.FullName.value))) return RetFalse(TheForm.FullName, "שגיאה: שם מלא אינו תקין.");
  TheForm.EMail.value=Trim(TheForm.EMail.value);
  if (TheForm.EMail.value == "") return RetFalse(TheForm.EMail, "שגיאה: אתה חייב להכניס דואל.");
  if (TheForm.EMail.value.indexOf("@") == -1) return RetFalse(TheForm.EMail, "שגיאה: דואל אינו תקין.");
  return true;
}
function ChangeImg(baseName) {
  var imgNum = Math.floor((6-0)*Math.random()) + 1
  document.getElementById("TopImg").src = "images/TopImages/"+baseName+"_pic"+imgNum+".jpg";
}

function grayOut(vis, options) {
// Pass true to gray out screen, false to ungray
// options are optional. This is a JSON object with the following (optional) properties
// opacity:0-100 // Lower number = less grayout higher = more of a blackout 
// zindex: # // HTML elements with a higher zindex appear on top of the gray out
// bgcolor: (#xxxxxx) // Standard RGB Hex color code
// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
// in any order. Pass only the properties you need to set.
var options = options || {}; 
var zindex = options.zindex || 50;
var opacity = options.opacity || 70;
var opaque = (opacity / 100);
var bgcolor = options.bgcolor || '#ffffff';
var dark=document.getElementById('darkenScreenObject');
if (!dark) {
// The dark layer doesn't exist, it's never been created. So we'll
// create it here and apply some basic styles.
// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
var tbody = document.getElementsByTagName("body")[0];
var tnode = document.createElement('div'); // Create the layer.
tnode.style.position='absolute'; // Position absolutely
tnode.style.top='0px'; // In the top
tnode.style.left='0px'; // Left corner of the page
tnode.style.overflow='hidden'; // Try to avoid making scroll bars 
tnode.style.display='none'; // Start out Hidden
tnode.id='darkenScreenObject'; // Name it so we can find it later
tbody.appendChild(tnode); // Add it to the web page
dark=document.getElementById('darkenScreenObject'); // Get the object.
}
if (vis) {
// Calculate the page width and height 
if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
var pageWidth = document.body.scrollWidth+'px';
var pageHeight = document.body.scrollHeight+'px';
} else if( document.body.offsetWidth ) {
var pageWidth = document.body.offsetWidth+'px';
var pageHeight = document.body.offsetHeight+'px';
} else {
var pageWidth='100%';
var pageHeight='100%';
} 
//set the shader to cover the entire page and make it visible.
dark.style.opacity=opaque; 
dark.style.MozOpacity=opaque; 
dark.style.filter='alpha(opacity='+opacity+')'; 
dark.style.zIndex=zindex; 
dark.style.backgroundColor=bgcolor; 
dark.style.width= pageWidth;
dark.style.height= pageHeight;
dark.style.display='block'; 
} else {
dark.style.display='none';
}
}

function GrayIt() {
  grayOut(true);
  document.getElementById("disclaimer").style.display="block";
}
function GrayOK() {
  grayOut(false);
  document.getElementById("disclaimer").style.display="block";
  document.getElementById("disclaimer").style.display="none";
  document.getElementById("BgContainer").style.display="block";
  document.getElementById("Footer_BgContainer").style.display="block";
  document.getElementById("Designers").style.display="block";
}

var isNeedShowCats=false;
var checkShowCatsVar=null
function CheckNeedClose() {
  if (!isNeedShowCats) {
    document.getElementById("SearchCats").style.display = "none";
    document.getElementById("SearchCats").style.visibility = "hidden";
    clearInterval(checkShowCatsVar);
    checkShowCatsVar=null;
  } else checkShowCatsVar=setInterval("CheckNeedClose()",2000);
}

function MainSearchSubmit() {
  //if (Trim(document.getElementById('MainSearch').value) == "") return RetFalse(document.getElementById('MainSearch'), "שגיאה: לא הוזן ביטוי חיפוש.");
  //if (!(/^[A-Za-zא-ת\-_ ]+$/.test(document.getElementById('MainSearch').value))) return RetFalse(document.getElementById('MainSearch'), "שגיאה: הוזנן ביטוי שגוי.");
  document.getElementById('MainSearchForm').submit();
}
function ProductSearchSubmit() {
  //if (Trim(document.getElementById('ProductSearch').value) == "") return RetFalse(document.getElementById('ProductSearch'), "שגיאה: לא הוזן ביטוי חיפוש.");
  //if (!(/^[A-Za-zא-ת\-_ ]+$/.test(document.getElementById('ProductSearch').value))) return RetFalse(document.getElementById('ProductSearch'), "שגיאה: הוזנן ביטוי שגוי.");
  document.getElementById('SearchProduct').submit();
}
function ProductSearchSubmitE() {
  //if (Trim(document.getElementById('ProductSearch').value) == "") return RetFalse(document.getElementById('ProductSearch'), "Error: search query is invalid.");
  //if (!(/^[A-Za-zא-ת\-_ ]+$/.test(document.getElementById('ProductSearch').value))) return RetFalse(document.getElementById('ProductSearch'), "Error: search query is invalid.");
  document.getElementById('SearchProduct').submit();
}
