function CheckNum(myfield,e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function CheckLogin()
	{
	if (document.Login.Id.value == "")
		{
		alert("שדה תעודת זהות ריק");
		document.Login.Id.focus();
		return false;
		}
	if (document.Login.Pwd.value == "")
		{
		alert("לא הוקלדה סיסמה");
		document.Login.Pwd.focus();
		return false;
		}
	return true;
}


function CheckNum(myfield,e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("0123456789.-").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function CheckHeb(myfield,e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("\"אבגדהוזחטיכלמנסעפצקרשתןםףךץ-\/. ',").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function CheckEng(myfield,e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("abcdefghijklmnopqrstuvwxyz\"ABCDEFGHIJKLMNOPQRSTUVWXYZ/\-. ,'").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function CheckLetters(myfield,e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\-.אבגדהוזחטיכלמנסעפצקרשתןםףךץ\"0123456789~() ',").indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}


function Check_Fields()
	{
	document.Register.act.value = 0;
	if (document.Register.FName.value == "")
		{
		alert("השדה שם פרטי ריק");
		document.Register.FName.focus();
		return false;
		}
	if (document.Register.SName.value == "")
		{
		alert("השדה שם משפחה ריק");
		document.Register.SName.focus();
		return false;
		}
       if (document.Register.PersonalId.value == "")
		{
		alert("השדה תעודת זהות ריק");
		document.Register.PersonalId.focus();
		return false;
		}
	if (document.Register.UserName.value == "")
		{
		alert("שדה שם משתמש ריק");
		document.Register.UserName.focus();
		return false;
		}

	if (document.Register.Phone1.value == "")
		{
		alert("שדה טלפון ריק");
		document.Register.Phone1.focus();
		return false;
		}
	document.Register.act.value = 1;
	return true;
}

function AddBus_Check_Fields()
	{
	document.AddBus.act.value = 0;
	if (document.AddBus.PersonalId.value == "0")
		{
		alert("עליך לבחור משתמש שהוא בעל העסק");
		document.AddBus.PersonalId.focus();
		return false;
		}
	if (document.AddBus.BName.value == "")
		{
		alert("השדה שם עסק ריק");
		document.AddBus.BName.focus();
		return false;
		}
	if (document.AddBus.BID.value == "")
		{
		alert("השדה עוסק מורשה ריק");
		document.AddBus.BID.focus();
		return false;
		}
	if (document.AddBus.ActiveRange.value == "0")
		{
		alert("יש לבחור איזור פעילות");
		document.AddBus.ActiveRange.focus();
		return false;
		}
	if (document.AddBus.Phone1.value == "")
		{
		alert("השדה טלפון ראשי ריק");
		document.AddBus.Phone1.focus();
		return false;
		}

	document.AddBus.act.value = 1;
	return true;
}

function showtime()
{
	var now     = new Date()
	var minutes = now.getMinutes() 
	var seconds = now.getSeconds() 
	var GMT     = now.getHours()

	var NowDate	= now.getDate()
	var Month 	= now.getMonth()+1
	var Year	= now.getFullYear()

	var hoursGMT      = (GMT + 00)
	
	var 
		timeValueGMT  = "" + ( (hoursGMT >  24) ? hoursGMT - 24 : hoursGMT )
		timeValueGMT +=      ( (minutes <  10) ? ":0" : ":" ) + minutes 
		timeValueGMT +=      ( (seconds <  10) ? ":0" : ":" ) + seconds 
		timeValueGMT += "  "
		timeValueGMT +=      ( (NowDate <  10) ? "0" : "" ) + NowDate
		timeValueGMT +=      ( (Month <  10) ? "/0" : "/" ) + Month
		timeValueGMT +=      ( (Year <  10) ? "/0" : "/" ) + Year

	document.all.faceGMT.value = timeValueGMT
	
	timerID = setTimeout("showtime()",1000) 
}
function PaintRow(oRow,color){
		
	for(var i=0;i<oRow.children.length;i++){
		if(oRow.children(i).name=='td_ShortName'){
			if(color==''){
				oRow.children(i).style.color='';
			}else{
				oRow.children(i).style.color='darkblue';
				oRow.children(i).style.backgroundColor='red';
			}
		}
		oRow.children(i).style.backgroundColor=color;
	}
}

function AddToFavorites() {
    window.external.AddFavorite(location.href,document.title);
}

function ValidateEnglish(fld) {
    if (fld.value.match(/[^A-Za-z\. ]/)) fld.value=fld.value.replace(/[^A-Za-z\. ]/g,'');
}

function autoTab(input) {
    ValidateIntlNumber(input);
    if(input.value.length >= input.getAttribute ('maxlength')) {
        input.value = input.value.slice(0, input.getAttribute ('maxlength'));
        input.form[(getNextFld(input)+1) % input.form.length].focus();
    }

    function getNextFld(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.elements.length && index == -1) {
            if (input.form.elements[i] == input ) index = i;
            else i++;
        }
        return index;
    }
    return true;
}

function ValidateIntlNumber(fld) {
    if (fld.value.match(/[^0-9]/)) fld.value=fld.value.replace(/[^0-9]/g,'');
}

function checkemail(emailstr){
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(emailstr)) {
        return true;
    }else{
        return false;
    }
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
//		alert("יש למלא את התאריך בפורמט הבא: dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
//		alert("נא למלא חודש תקין");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("נא למלא יום תקין");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("נא למלא שנה בין "+minYear+" ו-"+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//		alert("נא למלא תאריך לידה תקין");
		return false;
	}
    return true
}

function Left(str, n){
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}