var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var isMozilla = (document.getElementById && navigator.appName == "Netscape")? true:false;

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) { //v3.0
  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); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}


function initUPpage() {
//this gives the total height of the document which may exceed the size of the window
//alert('scrollHeight='+document.body.scrollHeight +'; height='+window.screen.height);
   if (document.body.scrollHeight > 450 && window.screen.height == 600){
		if (document.layers) document.layers['UPpage'].visibility = "show"
		else if(ie4) document.all['UPpage'].style.visibility = "visible"

   } 
   else if (document.body.scrollHeight > 700 && window.screen.height > 690){
		if (document.layers) document.layers['UPpage'].visibility = "show"
		else if(ie4) document.all['UPpage'].style.visibility = "visible"
   }
}


function docjslib_getImageXfromLeft(imgID) {
  if (ns4) return eval(imgID).x
  else return docjslib_getRealLeft(imgID);
  
}

function docjslib_getImageYfromTop(imgID) {
  if (ns4) return eval(imgID).y
  else return docjslib_getRealTop(imgID);
}

function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}


//*************************************************************************************
// trim - this function deletes spaces around the string.
//*************************************************************************************
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//*************************************************************************************
// checkSearch - this function checked if  user fill in the search input field.
//*************************************************************************************
function checkSearch(){
  if(document.formSearch.keySearch.value.trim() == "")
 	alert ("Empty string")
  else 
 	document.formSearch.submit();
  return false; 
}

function GetNumbersAndLetters(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch >= 1488 && ch <= 1513) );
}


function getNumbers(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || ch ==46);
}

//Set image size to defined width and height
function setPictureSize(id,toHeight,toWidth)
{

	widthImg=document.images(id).width
	heightImg=document.images(id).height

	if (widthImg > toWidth)
	{
		newWidth = toWidth
		newHeight = toWidth * heightImg / widthImg
	}
	if (heightImg > toHeight)
	{
		newHeight = toHeight
		newWidth = toHeight * widthImg / heightImg
	}
	document.images(id).width = newWidth
	document.images(id).height = newHeight
}

function checkEmail(checkThisEmail){

//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


return myEMailIsValid

}

//Show numbers in defined format
function format_number(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}

/*CHECK PHONE NUMBER*/

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- /";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 9;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
/*END ofPHONE CHECHING*/

/*Check Card number*/
function checkCard(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}

  return bResult; // Return the results
}
/*End of card number checking*/


//Calendar function
function DoCal(elTarget) {
  if (showModalDialog) {
    var sRtn;
    sRtn = showModalDialog("../../include/calendar.asp",elTarget.value,"center=yes; dialogWidth=110pt; dialogHeight=134pt; status=0; help=0;");
    if (sRtn!="")
      elTarget.value = sRtn;
  } else
    alert("Internet Explorer 4.0 or later is required.")
 return false;
 window.document.focus;   
}

//Layer as Combo Box
function ShowHideSelBox(iddiv)
{
	if (ie4) {
		if(document.all(iddiv).style.visibility=="visible")
			HideSelBox(iddiv)
		else
			ShowSelBox(iddiv)
	}
	if (isMozilla) {
		if(document.getElementById(iddiv).style.visibility=="visible")
			HideSelBox(iddiv)
		else
			ShowSelBox(iddiv)
	}
}
function HideSelBox(iddiv)
{
	if (ie4) {
		document.all(iddiv).style.visibility="hidden"
		document.all("sel"+iddiv).title="Show products"
	}
	if (isMozilla) {
		document.getElementById(iddiv).style.visibility="hidden"
		document.getElementById("sel"+iddiv).title="Show products"
	}
}
function ShowSelBox(iddiv)
{//document.images("img"+iddiv).title='פתח רשימת מוצרים'
	//alert('ll'+document.images("img"+iddiv).alt)
	x=getAnchorPosition("img"+iddiv).x
	y=getAnchorPosition("img"+iddiv).y
	if (ie4) {
		document.all(iddiv).style.left=x
		document.all(iddiv).style.top=y+document.images("img"+iddiv).height+2
		document.all(iddiv).style.visibility="visible"
		document.all("sel"+iddiv).title="Hide products"
	}
	if (isMozilla) {
		document.getElementById(iddiv).style.left=x
		document.getElementById(iddiv).style.top=y+document.images["img"+iddiv].height+2
		document.getElementById(iddiv).style.visibility="visible"
		document.getElementById("sel"+iddiv).title="Hide products"
	}
}
function SetWidthSelBox(iddiv)
{
	if (ie4) {
		if (document.all("act"+iddiv) && document.all("sel"+iddiv))
		{
			var cssBorderWidth=new String
			document.all("act"+iddiv).style.width=document.all("imgwdt"+iddiv).width
			cssBorderWidth=document.all("sel"+iddiv).style.borderWidth
			borderwdt=eval(cssBorderWidth.substring(0,cssBorderWidth.length-2))
			document.all("sel"+iddiv).style.width=document.all("imgwdt"+iddiv).width+document.images("img"+iddiv).width+2*borderwdt
			cssBorderWidth=document.all(iddiv).style.borderRightWidth
			borderRwdt=eval(cssBorderWidth.substring(0,cssBorderWidth.length-2))
			cssBorderWidth=document.all(iddiv).style.borderLeftWidth
			borderLwdt=eval(cssBorderWidth.substring(0,cssBorderWidth.length-2))
			document.all(iddiv).style.width=document.all("imgwdt"+iddiv).width+document.images("img"+iddiv).width+borderLwdt+borderRwdt
		}
	}
	if (isMozilla) {
		if (document.getElementById("act"+iddiv) && document.getElementById("sel"+iddiv))
		{
			var cssBorderWidth=new String
			document.getElementById("act"+iddiv).style.width=document.getElementById("imgwdt"+iddiv).width
			cssBorderWidth=document.getElementById("sel"+iddiv).style.borderWidth
			borderwdt=eval(cssBorderWidth.substring(cssBorderWidth.length-3,cssBorderWidth.length-2))
			document.getElementById("sel"+iddiv).style.width=document.getElementById("imgwdt"+iddiv).width+document.images["img"+iddiv].width+2*borderwdt
			cssBorderWidth=document.getElementById(iddiv).style.borderRightWidth
			borderRwdt=eval(cssBorderWidth.substring(0,cssBorderWidth.length-2))
			cssBorderWidth=document.getElementById(iddiv).style.borderLeftWidth
			borderLwdt=eval(cssBorderWidth.substring(0,cssBorderWidth.length-2))
			document.getElementById(iddiv).style.width=document.getElementById("imgwdt"+iddiv).width+document.images["img"+iddiv].width+borderLwdt+borderRwdt
		}
	}
}


/***********************************************
* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
/*
var isNS = (navigator.appName == "Netscape") ? 1 : 0; 

//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")
var eventElement=new String

function disableselect(e){
if(isNS) 
	eventElement=e.target.tagName
else
	eventElement=e.srcElement.tagName
if (omitformtags.indexOf(eventElement.toLowerCase())==-1)
	return false
else
	return true
}

function reEnable(){
return true
}


//RIGHT CLICK
  var EnableRightClick = 0; 
  if(isNS) 
  document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP); 

function hideCopyRight()
{
	document.all("CopyRight").style.display="none"
}
function showCopyRight()
{
	document.all("CopyRight").style.pixelLeft= (window.screen.availWidth - 780 - 20) / 2 + 390 - 150
	document.all("CopyRight").style.pixelTop=window.event.y+document.body.scrollTop - 100
	document.all("CopyRight").style.display="block"
}

function mischandler(){ 
  if(EnableRightClick==1){ return true; } 
  else   {
 // alert('כל הזכויות שמורות לחברת יניב מערכות גרפיות בע"מ.\nעיצוב אתר חברת יניב, כל סממניו החיצוניים,\nודרך הצגת הנתונים באתר מוגנים בישראל מכוח חוק זכות יוצרים.\nאין להעתיק או להפיץ מלל כלשהו או תמונות מן האתר ללא הסכמה מפורשת בכתב מבעלי האתר. העובר על החוק יועמד לדין');
  showCopyRight()
  return false; 
  }
} 
  function mousehandler(e){ 
  if(EnableRightClick==1){ return true; } 
  var myevent = (isNS) ? e : event; 
  var eventbutton = (isNS) ? myevent.which : myevent.button; 
  if((eventbutton==2)||(eventbutton==3)) 
  {
 // alert('כל הזכויות שמורות לחברת יניב מערכות גרפיות בע"מ.\nעיצוב אתר חברת יניב, כל סממניו החיצוניים,\nודרך הצגת הנתונים באתר מוגנים בישראל מכוח חוק זכות יוצרים.\nאין להעתיק או להפיץ מלל כלשהו או תמונות מן האתר ללא הסכמה מפורשת בכתב מבעלי האתר. העובר על החוק יועמד לדין');
  showCopyRight()
  return false; 
  }
   } 
  
  function keyhandler(e) { 
  var myevent = (isNS) ? e : window.event; 
  if (myevent.keyCode==96) 
  {
	EnableRightClick = 1; //Cancel disabled right click
  }
  //alert(myevent.keyCode)
  if (myevent.keyCode==13) 
  {
  check_SearchForm()
  }
  return; 
  } 
  
  function mousehandlerDown(e)
  {
	mousehandler(e)
 disableselect(e)
  }
  function mousehandlerUp(e)
  {
	mousehandler(e)
	reEnable()
  }


if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
  document.onmousedown = mousehandlerDown; 
  document.onmouseup = mousehandlerUp; 
}
  
  document.oncontextmenu = mischandler; 
  document.onkeypress = keyhandler; 
  document.onkeydown = showDown; 
 
 
 
  function showDown() 
  { 
 if(ie4) 
  { 
  if (event.keyCode==82 || event.keyCode==114) 
  {
  //event.keyCode =0; 
  //return false; 
  } 
  }
  } 
*/