﻿// JScript File
function CheckTel(oTel){
        if (oTel.value.length==0){return}   //if empty exit function
        
        //if in vaild range check for numeric
        if ((oTel.value.length>=9) && (oTel.value.length<=10))  
        {
            if (!IsNumeric(oTel.value))
            {
                alert("נא הזן מספר בלבד.");
                oTel.value='';
            }
        }
        else    //alert for vaild range
        {
            alert("מספר התווים אינו תואם למספר טלפון");
            oTel.value='';
        }
    }
    
    //find if the string is vaild phone number
    function IsNumeric(strValue){
        var iCount
        var VaildChars='0123456789';    //vaild string
        var sValue;
        
        //loop on string
        for (iCount=0;iCount<strValue.length;iCount++){
            sValue=strValue.substring(iCount,iCount+1);
            if (VaildChars.indexOf(sValue)==-1)
            {
                return false
            }
        }
        return true
    }
    
    function CheckNumeric(strValue){
    
        if (!IsNumeric(strValue.value))
        {
            alert("שדה מסוג מספר");
            strValue.value='';
        }
    }
    
    function CheckBorenYear(oBorenDate)
    {
    
        if (!IsNumeric(oBorenDate.value))
        {
            alert("שדה מסוג מספר");
            oBorenDate.value='';
            return;
        }
        if (!(oBorenDate.value.length==4)){
            alert("שנת לידה בפורמט של 4 תווים");
            oBorenDate.value='';
            return;
        }
        
    }
    
   
    
    function CheckBorenDate(oBorenDate)
    {
        //if the field is empty then do not check
        if(oBorenDate.value==""){return}
        //check for the write chars
        if (!IsVaildDate(oBorenDate.value))
        {
            alert("תאריך אינו תקף");
            oBorenDate.value='';
            return;
        }
        
        
    }

 //find if the string is vaild phone number
    function IsVaildDate(strValue){
        var iCount
        var VaildChars='0123456789/-';    //vaild string
        var sValue;
       
        //loop on string
        for (iCount=0;iCount<strValue.length;iCount++){
            sValue=strValue.substring(iCount,iCount+1);
            if (VaildChars.indexOf(sValue)==-1)
            {
                return false
            }
        }
        return true
    }
//<Summery>
//this function check if the text box has vaild mail value
//</Summery>
function validateMail(oMail,lang){
    if (oMail.value.length==0){return}   //if empty exit function
   
    if ((oMail.value.indexOf('@')==-1) || (oMail.value.indexOf('.')==-1))
    {
        if(lang==0)
        {alert("כתובת דוא''ל אינה תקינה");}
        else{alert("Mial address isn't correct")}
        oMail.value='';
    }
}

function DeleteRec(RecIdName,RecIdValue){

    if (RecIdValue!=undefined){
        if (confirm("האם לבצע מחיקה") ==1){
            document.getElementById("task").innerText="1";
            document.getElementById(RecIdName).innerText=RecIdValue;
            document.getElementById("form1").submit();
        }
    }
    else{alert("לא ניתן לבצע מחיקה");}
}

function DeleteImage(RecIdName,RecIdValue){

    if (RecIdValue!=undefined){
        if (confirm("האם לבצע מחיקת תמונות") ==1){
            document.getElementById("task").innerText="4";
            document.getElementById(RecIdName).innerText=RecIdValue;
            document.getElementById("form1").submit();
        }
    }
    else{alert("לא ניתן לבצע מחיקה");}
}

function UpdateRec(RecIdName,RecIdValue)
{

    if (RecIdValue!=undefined)
    {
        document.getElementById("task").innerText="2";
        document.getElementById(RecIdName).innerText=RecIdValue;
        document.getElementById("form1").submit();
    }
    else{alert("לא ניתן לבצע עדכון");}
}
function AddRec()
{
   document.getElementById("task").innerText="3";
   if(document.getElementById("txtText")){
    document.getElementById("txtText").innerText = document.getElementById("kmText").innerHTML;
   }
   document.getElementById("form1").submit();
}
