﻿var prefix = "ctl00_ContentMain_";

function ClearForm() {
    SetControlValue(prefix + "txtName", "");
    SetControlValue(prefix + "txtPhone", "");
    SetControlValue(prefix + "txtMail", "");
    SetControlValue(prefix + "txtRemarks", "");
}

function SendForm() {
    var name = GetControlValue(prefix + "txtName");
    var phone = GetControlValue(prefix + "txtPhone");
    var mail = GetControlValue(prefix + "txtMail");
    var remarks = GetControlValue(prefix + "txtRemarks");
    
    var message = "";
    
    if(Trim(phone).length == 0 && Trim(mail).length == 0) {
        message = "נא למלא דוא''ל ו/או טלפון";
    }
    
    if(message.length == 0) {
        ContactAjax.SendContactMessage(name, phone, mail, remarks, SendForm_Callback);
    }
    else {
        alert(message);
    }
}

function SendForm_Callback(res) {
    if(res.value.toUpperCase() == "SUCCESS") {
        ClearForm();
        alert(",ההודעה נשלחה בהצלחה\r\nנציג החברה יצור עמכם קשר בהקדם");
    }
    else {
        alert("An errror has occured, mail was not sent, Administrator was notified.");
    }
}