var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var isMozilla = (document.getElementById && navigator.appName == "Netscape")? true:false;
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

function makevisible(cur,which){
strength=(which==0)? 1 : 0.7
if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}
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 GetNumbersAndLettersHeb(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch >= 1488 && ch <= 1513) || (ch >= 224 && ch <= 250) );
}

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

}


/*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;
// Minimum no of digits in an international mobile phone no.
var minDigitsInIMobileNumber = 10;

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);
}


function checkMobile(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIMobileNumber);
}

/*END ofPHONE CHECHING*/

//Show numbers in defined format
function format_number(pnumber,decimals) 
{
	if (isNaN(pnumber) || pnumber == '') //pnumber is null or not is number
		return '';
	else
	{
	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;
 }
}


//Calendar function
function DoCal(elTarget) {
  if (showModalDialog) {
    var sRtn;
    sRtn = showModalDialog("../../include/calendar.asp",elTarget.value,"center=yes; dialogWidth=110pt; dialogHeight=150pt; status=0; help=0;");
    if (sRtn!="")
      elTarget.value = sRtn;
  } else
    alert("Internet Explorer 4.0 or later is required.")
 return false;
 window.document.focus;   
}

function zoomOver(elem){
	try{
		elem.style.height=elem.offsetHeight+"px"; 
		elem.style.width=elem.offsetWidth+"px";
		var imgs=elem.getElementsByTagName("img");
		for(var i=0;i<imgs.length;i++) if(imgs[i].className.indexOf("zoom")>=0) addClass(imgs[i],"zoomOver");
	}catch(e){}
}
function zoomOut(elem){
	var imgs=elem.getElementsByTagName("img");
	for(var i=0;i<imgs.length;i++) if(imgs[i].className.indexOf("zoom")>=0) removeClass(imgs[i],"zoomOver"); 
}
function addClass(elem,className){elem.className=elem.className+" "+className;}
function removeClass(elem,className){var regx=new RegExp(className,"g");elem.className=elem.className.replace(regx,"");}



/***********************************************
* 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; 
  } 
  }
  } 
*/
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing

	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;

	return coordinates;
	}
	function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			//alert(y)
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}
	// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
	function frgPassword()
	{
		strpath = "password.aspx";
	h = 250;
	w = 300;
	l = parseInt((window.screen.availWidth - w) / 2);		
	window.open(strpath,"Password","width=" + w +",height="+ h +",toolbar=no,menubar=no,left=" + l +", top = 150,titlebar=no, scrollbars=no");
	return false;
	}

