function ShowElement(ElementID)
{
	document.getElementById(ElementID).style.display='';
}

function HideElement(ElementID)
{
	document.getElementById(ElementID).style.display='none';
}

function ShowOrHideElement(ElementID)
{
	if(document.getElementById(ElementID).style.display=='none')
		ShowElement(ElementID);
	else
		HideElement(ElementID);
}

function OpenWindow(FormName)
{
	var w=window.open('','CWindow','toolbars=no,addressbar=no,scrollbars=0,width=410,height=300,left=200,top=200,scrollbars=0');
	if(w)
	{
		document.forms[FormName].target="CWindow";
		document.forms[FormName].submit();
		w.focus();
		return true;
	}
	else
	{
		alert("כנראה שמופעל אצלך חוסם pop-up...");
		return false;
	}
}


String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.left = function(num)
{
	return this.substring(0,num);
}

String.prototype.right = function(num)
{
	return this.substring(this.length-num,this.length);
}

function replaceAll(oldStr,findStr,repStr) 
{
  var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                    // of oldStr are we searching.
  var newStr = "";  // newStr will hold the altered version of oldStr.
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
                    // As long as there are strings to replace, this loop
                    // will run. 
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
                    // Put it all the unaltered text from one findStr to
                    // the next findStr into newStr.
    newStr += repStr;
                    // Instead of putting the old string, put in the
                    // new string instead. 
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
                    // Now jump to the next chunk of text till the next findStr.           
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
                    // Put whatever's left into newStr.             
  return newStr;
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) 
    {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function isNumeric(sText)
{
	return isInteger(sText) || isDouble(sText);
}

function isDouble(sText)
{
	var NumRX = /^[+-]?[0-9]+\.[0-9]+$/;
	return NumRX.test(sText);
}

function isInteger(sText)
{
	var NumRX = /^[+-]?[0-9]+$/;
	return NumRX.test(sText);
}
function CheckZehut(m_id_num) //m_id_num must contain digits only
{
	var m_id_tmp;
	var a1, a2, a3, a4, a5, a6, a7, a8;
	var b2, b4, b6, b8;
	var m_sfx_num;
	var strMsg;
	var Response;
	    
	m_id_tmp = Left(Right(Zeros(9) + m_id_num, 9), 8)
	a1 = parseInt(Left(m_id_tmp, 1))
	a2 = parseInt(Left(Right(m_id_tmp, 7), 1)) * 2
	a3 = parseInt(Left(Right(m_id_tmp, 6), 1))
	a4 = parseInt(Left(Right(m_id_tmp, 5), 1)) * 2
	a5 = parseInt(Left(Right(m_id_tmp, 4), 1))
	a6 = parseInt(Left(Right(m_id_tmp, 3), 1)) * 2
	a7 = parseInt(Left(Right(m_id_tmp, 2), 1))
	a8 = parseInt(Right(m_id_tmp, 1)) * 2
	    
	b2 = (a2 % 10) + parseInt(a2 / 10)
	b4 = (a4 % 10) + parseInt(a4 / 10)
	b6 = (a6 % 10) + parseInt(a6 / 10)
	b8 = (a8 % 10) + parseInt(a8 / 10)
	    
	if (((a1 + b2 + a3 + b4 + a5 + b6 + a7 + b8) % 10) >= 1 && ((a1 + b2 + a3 + b4 + a5 + b6 + a7 + b8) % 10) <= 9)
		m_sfx_num = parseInt(10 - ((a1 + b2 + a3 + b4 + a5 + b6 + a7 + b8) % 10));
	else
		m_sfx_num = 0;
	    
	return (parseInt(Right((m_id_num), 1)) == m_sfx_num)
}
function CheckMail(mail)
{
	var RegExp = /^[A-Za-z\_\-0-9]+(\.[A-Za-z\_\-0-9]+)*@[A-Za-z\_\-0-9]+(\.[A-Za-z\_\-0-9]+)?(\.[A-Za-z]{2,3}){1,2}$/;
	return RegExp.test(mail);
}
function isPhone(sText)
{
	var RX = /^(0[2|3|4|8|9]|077)(\-)?[0-9]{7}$/;
	return (RX.test(sText));
}
function isPhoneNumber(sText)
{
	var RX = /^[0-9]{7}$/;
	return (RX.test(sText));
}
function isCellular(sText)
{
	var RX = /^05[0|2|4|7](\-)?[0-9]{7}$/;
	return RX.test(sText);
}
function Left(str,num)
{
	return str.substring(0,num);
}
function Right(str,num){
	return str.substring(str.length-num,str.length);
}
function Zeros(num)
{
	var str="";
	var i;
	for (i=1; i<=num; i++)
		str+="0";
	return str;
}
function SelectValue(obj)
{
	return obj[obj.selectedIndex].value;
}
function isDate(day,month,year)
{	
	if (!isNumeric(day) || !isNumeric(month) || !isNumeric(year)) return false;
	if (day.length !=2 || month.length!=2 || year.length!=4) return false;
	var Meuberet = ((year % 4)==0 && (year % 100)!=0) || ((year % 400)==0);
	if (month == 2 && day >28 && !Meuberet){
		return false;
	}
	if (month<1 || month>12)
		return false;
	if (month == 1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
	{
		if (day<1 || day>31)
		{
			return false;
		}
	}else{
		if (day<1 || day>30)
		{
			return false;
		}
	}
	return true;
}

function Get2DigitsNumber(number)
{
	return(Math.round(number*100)/100);
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function AddToCart(i)
{
	var frm = document.getElementById("addtocart"+i);
	var TasteSelect = document.getElementById("TasteSelect");
	if(frm.ProductTaste!=undefined&&TasteSelect!=undefined)
		frm.ProductTaste.value=TasteSelect.value;
	frm.submit();
	MPosition = findPos(document.getElementById("AddToCartTD"+i));
	document.getElementById("AddToCart_table"+i).style.left = (MPosition.x+20)+"px"; //((document.body.clientWidth-200)/2)+"px";
	document.getElementById("AddToCart_table"+i).style.top = (MPosition.y-80)+"px";
	document.getElementById("AddToCart_table"+i).style.display = "";
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {x:curleft,y:curtop};
}

function BodyOnLoad()
{
	document.getElementById('HomePageFlashTD').innerHTML = HomePageFlash;
	document.getElementById('LeftSideFlashTD').innerHTML = LeftSideFlash;
}

function ReplaceHttpsLinks()
{
	var links;
	links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++)
		links[i].href=links[i].href.replace("https://","http://");
	links = document.getElementsByTagName("area");
	for (var i=0; i<links.length; i++)
		links[i].href=links[i].href.replace("https://","http://");
}

