﻿
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function ShowElement(ElementID) {
    document.getElementById(ElementID).style.display = '';
}

function HideElement(ElementID) {
    document.getElementById(ElementID).style.display = 'none';
}

function OpenWindow(FormName) {
    window.open('', 'newWindow', 'toolbars=no,addressbar=no,scrollbars=0,width=410,height=300,left=200,top=200,scrollbars=0');
    document.forms[FormName].target = "newWindow";
    document.forms[FormName].submit();
}

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 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 GetShortNumber(Number, DigitsAfterDot) {
    var temp = 1;
    for (i = 0; i < DigitsAfterDot; i++)
        temp *= 10;

    return (Math.round(number * temp) / temp);
}

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 submitregform(TheForm) {
    if (TheForm.Userlname.value.trim() == "") {
        alert("עליך להזין שם פרטי");
        TheForm.Userlname.focus();
        return false;
    }

    if (TheForm.UserFname.value.trim() == "") {
        alert("עליך להזין שם משפחה");
        TheForm.UserFname.focus();
        return false;
    }

    if (TheForm.UserCity.value.trim() == "") {
        alert("עליך להזין עיר");
        TheForm.UserCity.focus();
        return false;
    }

    if (TheForm.UserAddress.value.trim() == "") {
        alert("עליך להזין כתובת");
        TheForm.UserAddress.focus();
        return false;
    }

    if (TheForm.UserPhone.value.trim() == "") {
        alert("עליך להזין טלפון");
        TheForm.UserPhone.focus();
        return false;
    }

    if (TheForm.UserPhone2.value.trim() == "") {
        alert("עליך להזין טלפון נייד");
        TheForm.UserPhone2.focus();
        return false;
    }

    if (TheForm.UserEmail.value.trim() == "") {
        alert("עליך להזין כתובת אימייל");
        TheForm.UserEmail.focus();
        return false;
    }

    if (TheForm.UserPass.value.trim() == "") {
        alert("עליך להזין סיסמה");
        TheForm.UserPass.focus();
        return false;
    }

    if (TheForm.UserPass2.value.trim() == "") {
        alert("אנא ודא את הסיסמה");
        TheForm.UserPass2.focus();
        return false;
    }

    if ((TheForm.UserPass.value.trim() !== TheForm.UserPass2.value.trim())) {
        alert("הסיסמאות לא תואמות");
        TheForm.UserPass2.focus();
        return false;
    }



    return true;
}

function CheckContactForm(TheForm) {
    if (TheForm.ContactFirstName.value.trim() == "") {
        alert("עליך להזין שם פרטי");
        TheForm.ContactFirstName.focus();
        return false;
    }

    if (TheForm.ContactLastName.value.trim() == "") {
        alert("עליך להזין שם משפחה");
        TheForm.ContactLastName.focus();
        return false;
    }

    if (TheForm.email.value.trim() == "") {
        alert("עליך להזין כתובת דואר");
        TheForm.email.focus();
        return false;
    }

    if (!isPhone(TheForm.ContactPhone.value) && !isCellular(TheForm.ContactPhone.value)) {
        alert("נא להזין מספר טלפון תקין");
        TheForm.ContactPhone.focus();
        return false;
    }

    return true;
}

function frmSend() {
    if (theform.firstname.value.trim() == "") {
        alert("עליך להזין שם פרטי");
        theform.firstname.focus();
        return ;
    }

    if (theform.lastname.value.trim() == "") {
        alert("עליך להזין שם משפחה");
        theform.lastname.focus();
        return ;
    }


    if (!CheckMail(theform.email.value)) {
        alert("נא להזין אימייל תקין");
        theform.email.focus();
        return;
    }
    if (!isPhone(theform.phone.value)) {
        alert("נא להזין מספר טלפון תקין");
        theform.phone.focus();
        return ;
    }
    //alert("aaaaaaaaaaaa");

    document.theform.submit();
}
//////////////////////////////////////////////////////////////////////////////
function frmLofin() {
    if (document.getElementById("userName").value == "") {
        alert("עליך להזין שם משתשמש");
        document.getElementById("userName").focus();
        return;
    }
    if (document.getElementById("password").value == "") {
        alert("עליך להזין סיסמא");
        document.getElementById("password").focus();
        return;
    }

    document.getElementById("frmLofin").submit();
    

}
//////////////////////////////////////////////////////////////////////////////

function frmSearch() {
    var textfield = document.getElementById("textfield").value;
    if (textfield == "") {
        alert("יש למלא ערך חיפוש");
    }
    else {
        document.getElementById("frmSearch").submit();
    }
}

//////////////////////////////////////////////////////////////////////////////
function changeTab(prm1, prm2, prm3,prm4, prm5, prm6) {

    document.getElementById("tab" + prm2).className = "tab";
    document.getElementById("container" + prm2).style.display = 'none';
    document.getElementById("tab" + prm3).className = "tab";
    document.getElementById("container" + prm3).style.display = 'none';
    document.getElementById("tab" + prm4).className = "tab";
    document.getElementById("container" + prm4).style.display = 'none';
    document.getElementById("tab" + prm5).className = "tab";
    document.getElementById("container" + prm5).style.display = 'none';
    document.getElementById("tab" + prm6).className = "tab";
    document.getElementById("container" + prm6).style.display = 'none';
    document.getElementById("tab" + prm1).className = "tab-on";
    document.getElementById("container" + prm1).style.display = 'block';


}

function changeGalID(prm) {
    location.href = "gallery.asp?galID=" + prm;
}


function changeBullID(prm) {
    location.href = "billboard.asp?bullID=" + prm;
}


function sendMailToUser(prm) {

    window.open('inc/sendMailForm.asp?userID=' + prm, 'sendMailForm', 'width=400,height=200,scrollbars=no,toolbar=no')
}


function openDiv(obj) {
    //alert(obj)

    var el = document.getElementById(obj);
    if (el.style.display != 'none') {
        el.style.display = 'none';
    }
    else {
        el.style.display = '';
    }
}




