﻿var isLang = 0;
document.observe("dom:loaded", loadContact);
var isYourSelf = 0;
function loadContact() {
    try {
        isLang = parseInt(window.location.href.split("=")[1]) == 1 ? 1 : 0;
    } catch (e) { isLang = 0; }
    changeLangContact();
    if (utils.IE_Firefox() == "-1") {
        $('divTitle').style.marginLeft = "0px";
    }
}
function changeLangContact() {
    try {
        var oContact = lang4Contact()[isLang];
        $('spnTitle').update(oContact[19]);
        $('Span1').update(oContact[21]); //Quang 26/05
        $('compName').update(oContact[22]);

        //address
        //$('spnTitleAddress').update(oContact[5]);
        var arrAddress = $('divContentAddress').select('.h5_Address_Title');
        arrAddress[0].update(oContact[7]);
        arrAddress[1].update(oContact[20]); //Quang 26/05
        //arrAddress[5].update(oContact[8]);
        //from to here
        //        var oLink = Link4Language();
        //        $('aFrom').update(oLink.from);
        //        $('spnOr').update(oLink.or);
        //        $('aHere').update(oLink.to);
        //contact
        //$('spnTitleContact').update(oContact[9]);
        var arrContact = $('divContentContact').select('.h5_CT_RecipientEmail');
        arrContact[0].update(oContact[10]);
        arrContact[1].update(oContact[11]);
        arrContact[2].update(oContact[12]);
        arrContact[3].update(oContact[13]);
        arrContact[4].update(oContact[14]);
        $('spnDescription').update(oContact[15]);
        $('aSendContact').down('p').update(oContact[16]);
        $('aClearContact').down('p').update(oContact[17]);
        $('divContrainst').down('h5').update(oContact[18]);
        setError([$('spanFullNameContact'), $('spanEmailContact'), $('spnResult')]);
    } catch (ex) { };
}
function oClickChangeContact(e) {
    isLang = (e.id == "div_LangUSA") ? 1 : 0;
    changeLangContact();
}
function oClickYourSelf(e) {
    if ($('chkYourSelf').checked == true) {
        isYourSelf = 1;
    } else {
        isYourSelf = 0;
    }

}
function clearFormContact(e) {
    $('txt_CT_RecipientEmail').value = "info@diadiem.com";
    $('txt_CT_FullName').value = "";
    $('txt_CT_SenderEmail').value = "";
    $('chkYourSelf').checked = false;
    $('txt_CT_Content').value = "";
    $('spanFullNameContact').update('');
    $('spanEmailContact').update('');
    $('spnResult').update('');
}
function setError(arrcontainer) {
    try {
        var arrMessage = lang4Contact()[isLang == 1 ? 0 : 1];
        for (var j = 0; j < arrcontainer.length; j++) {
            var strerror = arrcontainer[j].innerHTML;
            for (var i = 0; i < arrMessage.length; i++) {
                if (arrMessage[i] == strerror) {
                    arrcontainer[j].update(lang4Contact()[isLang][i]);
                    break;
                }
            }
        }
    } catch (ex) { };
}
function Link4Language() {
    var langCate = lang4Category()[isLang];
    return { "from": langCate[2], "or": langCate[8], "to": langCate[3], "detail": langCate[4], "des": langCate[9] };
}
function sendMail() {
    var oErrContact = lang4Contact()[isLang];
    if ($('txt_CT_FullName').value == "") {
        $('spanFullNameContact').update(oErrContact[1]); return;
    } else {
        $('spanFullNameContact').update('');
    }
    if (!utils.checkMail($('txt_CT_SenderEmail').value)) {
        $('spanEmailContact').update(oErrContact[0]); return;
    }
    else {
        utils.call("contact.aspx", { "stpe": 1, "f": $('txt_CT_SenderEmail').value, "t": $('txt_CT_RecipientEmail').value, "c": $('txt_CT_Content').value, "n": $('txt_CT_FullName').value, "s": isYourSelf }, "POST", "resultSendMail", "resultSendMail");
    }
}
function resultSendMail(str) {
    var oErrContact = lang4Contact()[isLang];
    clearFormContact();
    $('spnResult').update(str == "1" ? oErrContact[2] : oErrContact[3]);
}
