﻿
//Since there is a bug in a textbox with a multiline mode
//We need to check the leng in js.
function CheckMultiLineMaxNumber(objTextBox,maxLen)
{
  if(objTextBox.value.length > (maxLen-1))
  {
    return false;
  }
}

function CheckDivMaxLength(objDiv,maxLen)
{
  if(objDiv.innerHTML.length > (maxLen-1))
  {
    return false;
  }
}

function IsNumeric()
{ 
  return ((event.keyCode >= 48) && (event.keyCode <= 57));  
}

//This function will check that the the sifrat bikoroet is current
// if not will fix it.it will also check TZ validity - 9 ditits etc
function CheckPersonalID(oTextBoxWithTZ)
{
	var arrFactor = new Array();
	var i,iSum,iResault,iTop,sDigit;
	var sNumber = new String();

	//return false and do nothing if the lenght is 0
	if(oTextBoxWithTZ.value.length == 0)
	{		
		return false;
	}//end if
	

	//if the value is <9 
	if(oTextBoxWithTZ.value.length < 9)
	{	
		return false;		
	}//end if

   // The tz was filled completly - check that the sifrat bikoret is correct
   //=======================================================================
	if(oTextBoxWithTZ.value.length == 9)
	{
	   //initialize an array [1,2,1,2,1,2,1,2]
		for(i=1;i<8;i=i+2)
		{
			arrFactor[i] = 1;
			arrFactor[i+1] = 2;
		}//end for	

		sNumber = Trim(oTextBoxWithTZ.value);	
		
		iSum = 0;	
		for(i=1;i<9;i++)
		{		
			iResault = sNumber.charAt(i-1)*arrFactor[i];			
			if(iResault>9)
				iResault = 1 + iResault - 10;
			iSum = iSum + iResault;
		}

		iTop = Math.floor((iSum+9)/10) * 10;		
		sDigit = iTop- iSum				
		
		if(sDigit != String(oTextBoxWithTZ.value).substring(8,9))
		{		
			return false;
		}
		
		else //all good
		{				
			return true;
		}				
		return false;
	}	
}//end function

function LTrim( value )
{	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

// Removes ending whitespaces
function RTrim( value ) 
{	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function Trim( value ) 
{	
	return LTrim(RTrim(value));	
}


function CheckIfToSerach()
{
  var key = window.event.keyCode;   
  var  oTxtForSearch = document.getElementById(GetSearchTextBoxID());
  var  oSearcherButtonID = document.getElementById(GetSearchButtonID());  

  if(oTxtForSearch.value != "")
  {  
    if (key == 13)
    {
      oSearcherButtonID.click();
    } 
  } 
}

function ChangeButtonOn(oButton)
{
 oButton.src="images/" + oButton.name + "On.jpg"
}

function ChangeButtonOff(oButton)
{
 oButton.src="images/" + oButton.name + "Off.jpg"
}