﻿function Text_OnFocus(obj, def) {
    if (obj.value == def) {
        obj.value = "";
    }
}

function Text_OnBlur(obj, def) {
    if (obj.value == "") {
        obj.value = def;
    }
}

var wait = false;
$("#btnContactSend").click(function () {
    if (wait) return;

    var toUserID = $("#MegaMenu1_cmbContactCategory").val();
    var fromEmail = $("#MegaMenu1_txtEMail").val();
    var subj = $("#MegaMenu1_txtSubject").val();
    var tel = $("#MegaMenu1_txtTel").val();
    if (tel.length > 0 && (tel.length != 11 || tel.substring(2, 0) != "09")) {
        alert('لطفا شماره موبایل معتبر وارد کنید.');
        return;
    }
    var body = $("#MegaMenu1_txtBody").val();
    var captcha = $("#MegaMenu1_txtCaptcha").val();
    $.ajax(
                {
                    type: "POST",
                    url: "admin/api.aspx/NewContact",
                    data: "{ToID:" + toUserID.toString() + ",Email:'" + fromEmail + "',Subj:'" + subj + "',Tel:'" + tel + "',Body:'" + body + "',captchaText:'" + captcha + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () {
                        wait = true;
                        $("#captchaImage").attr("src", "images/loading.gif");
                    },
                    success: function (msg) {
                        var a = msg.d.toString().split(';');
                        $("#captchaImage").attr("src", "images/temp/" + a[1]);
                        alert(a[0]);
                        wait = false;
                    },
                    complete: function () {

                    }
                });
});

SelectProv('تهران');

function SelectProv(key) {
    $.ajax(
                {
                    type: "POST",
                    url: "admin/api.aspx/SaleCenterCityList",
                    data: "{prov: '" + key + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () {
                        $("#mapLoading").show();
                        //do_load('on');
                    },
                    success: function (msg) {
                        $("#mapProvTitle").html("<div>استان : " + key + "</div>");
                        $("#mapCity").html(msg.d);

                    },
                    complete: function () {
                        $("#mapLoading").hide();
                        //do_load('off');
                    }
                });
}

$("#IranMap area").click(function () {
    var key = $(this).attr("key");

    SelectProv(key);
});

$("#refLink").click(function () {
    if (wait) return;

    var Email = $("#MegaMenu1_txtEmailRef").val();
    $.ajax(
                {
                    type: "POST",
                    url: "admin/api.aspx/CallTicket",
                    data: "{Email:'" + Email + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () {
                        wait = true;
                        $("#refLoading").show();
                    },
                    success: function (msg) {
                        $("#refLoading").hide();
                        if (msg.d != "")
                            alert(msg.d);
                        else
                            window.location = "ticket.htm";
                        wait = false;
                    },
                    complete: function () {

                    }
                });
});



$.ajax({
    type: "POST",
    url: "admin/api.aspx/ClearTemp",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
});

