﻿//////////////////////////////////////////
// Contact Errs:
var ContactNameErr = 'יש להזין שם';
var ContactMailErr = 'יש להזין כתובת אימייל';
var ContactPhoneErr = 'יש להזין מספר טלפון';
var ContactMsgErr = 'יש לרשום את נושא הפניה';

if (lang == 'en') 
{
    var ContactNameErr = 'Please enter name';
    var ContactMailErr = 'Please enter email';
    var ContactPhoneErr = 'Please enter phone number';
    var ContactMsgErr = 'Please write message';
}

function Trim(strText) 
{
    while (strText.substring(0, 1) == ' ')
        strText = strText.substring(1, strText.length);

    while (strText.substring(strText.length - 1, strText.length) == ' ')
        strText = strText.substring(0, strText.length - 1);
    return strText;
}


function ValidateMail(email) 
{
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email;
    return reg.test(address);

}

function WriteStr(InputStr) 
{

    document.write(InputStr);

}


function SubmitContact(ActionPage) 
{
    if (!ActionPage) 
    {
        ActionPage = '/SendContact.aspx'
    }

    document.getElementById("ContactForm").action = ActionPage;

    var _ContactName = document.getElementById("ContactName").value;
    var _ContactPhone = document.getElementById("ContactPhone").value;
    var _ContactEmail = document.getElementById("ContactEmail").value;
    var _ContactMsg = document.getElementById("ContactMsg").value;


    var hasErrors = 0;

    if (Trim(_ContactName) == '' || Trim(_ContactName) == ContactNameErr) 
    {
        document.getElementById("ContactName").value = ContactNameErr;
        hasErrors = 1;
    }



    if (Trim(_ContactEmail) == '' || !ValidateMail(_ContactEmail)) {
        document.getElementById("ContactEmail").value = ContactMailErr;
        hasErrors = 1;
    }


    if (Trim(_ContactPhone) == '' || Trim(_ContactPhone) == ContactPhoneErr) 
    {
        document.getElementById("ContactPhone").value = ContactPhoneErr;
        hasErrors = 1;
    }


    if (Trim(_ContactMsg) == '' || Trim(_ContactMsg) == ContactMsgErr) 
    {
        document.getElementById("ContactMsg").value = ContactMsgErr;
        hasErrors = 1;
    }


    if (hasErrors) 
    {
        return false;
    }
    else 
    {
        document.getElementById("ContactHidden").value = "15465419681796817";
    }
}


function ClickOnContactText(Obj) 
{
    var Str = Trim(Obj.value);
    if (Str == ContactNameErr) 
    {
        Obj.value = '';
    }
    else if (Str == ContactMailErr) 
    {
        Obj.value = '';
    }
    else if (Str == ContactPhoneErr) 
    {
        Obj.value = '';
    }
    else if (Str == ContactMsgErr) 
    {
        Obj.value = '';
    }
}
