// JScript source code
$(function () {



    $("#slider, #slider2").slider({
        range: "min",
        min: 100,
        max: 2500,
        step: 50,
        value: 500,
        slide: function (event, ui) {
            $("#amount, #amount2").val(ui.value);
            $("#slider, #slider2").slider("value", ui.value);
            if (ui.value == 2500)
                $("#amount, #amount2").val("+" + ui.value);

        }
    });
    $("#amount, #amount2").val($("#slider, #slider2").slider("value"));


    $(".next").button({
        icons: {
            primary: "ui-icon-carat-1-w"
        }
    });

    $(".prev").button({
        icons: {
            secondary: "ui-icon-carat-1-e"
        }
    });

    $("#radio, #radio_2").buttonset().live("click", function () { $("#lbl1 span, #lbl2 span, #lbl3 span, #lbl4 span, #lbl5 span").removeClass("validation"); });

    $(".goto_s2").click(function () {
        //alert(2);
        $("#slide_1, #slide_3").hide(1000);
        $("#slide_2").show("blind", 400);

    });

    $(".goto_s1").click(function () {
        //alert(1);
        $("#slide_1").show("blind", 400);
        $("#slide_2, #slide_3").hide(1000);


    });

    $(".goto_s3").click(function () {

        // Validate Mobile / Station / Both
        var elements1 = $("#lbl1 span, #lbl2 span, #lbl3 span");
        elements1.removeClass("validation");
        var selected1 = $("input[name='radio_2']:checked").val();

        if (selected1 == undefined) {
            elements1.effect("pulsate", { times: 3 }, 800).addClass("validation"); ;
            return;
        }

        $("#slide_1, #slide_2").hide(1000);
        $("#slide_3").show("blind", 400);

    });






});

$(document).ready(function () {

    //$(".example8").colorbox({ width: "650px", inline: true, href: "#get_advice" });
    $(".example8").click(function () {

        // Validate Mobile / Station / Both
        var elements2 = $("#lbl4 span, #lbl5 span");
        elements2.removeClass("validation");
        var selected2 = $("input[name='radio']:checked").val();

        if (selected2 == undefined) {
            elements2.effect("pulsate", { times: 3 }, 800).addClass("validation");
            return;
        }

        $(this).colorbox({ width: "650px", inline: true, href: "#get_advice" });
    });




});

function checkDialog() {

    var msg = "";
    var flag = 0;



    var fullName = document.getElementById("contact_full_name").value;

    if (fullName == "" || fullName == "שם מלא") {
        
        msg = msg + "הזן שם \n";
        flag = 1;
    }

    var email = document.getElementById("contact_email").value;
    if (email == "") {
        msg = msg + "הזן אימייל \n";
        flag = 1;
    } else {
        if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
            msg = msg + " הזן אימייל תקין \n";
            flag = 1;
        }
    }

    var phone = document.getElementById("contact_phone").value;
    if (phone == "" || phone == "טלפון") {
        msg = msg + "הזן טלפון \n";
        flag = 1;
    }

    if (flag == 1) {
        alert(msg);
        return false;
    } else {
        return true;
    }
}

$(function () {


    $("#sendContact").button({
        icons: {
            primary: "ui-icon-circle-triangle-w"
        }
    }).live("click", function () {
        var mesg = "<br />";

        if (!checkDialog())
            return false;

        var fullName = document.getElementById("contact_full_name").value;
        var email = document.getElementById("contact_email").value;
        var phone = document.getElementById("contact_phone").value;

        var needIsr = $("input[name='radio']:checked").val();
        var mobOrStand = $("input[name='radio_2']:checked").val();
        var amount = $("#amount").val();

        var contact_remarks = "<br/>" + "כמה דקות אתה מדבר בחודש? " + amount + "<br/>" + "האם אתה מדבר גם לנייחים וגם לניידים? " + mobOrStand + "<br/>" + "האם אתה צריך גם מספר מקומי או רק שיחות יוצאות? " + needIsr;

        //alert(contact_remarks);
        //return;

        $(".apply").html("<img alt='loading...' src='/Images/loading11.gif' />");

        $.ajax({
            cache: false,
            async: true,
            type: "POST",
            url: "/umbraco/plugins/lead.ashx",
            data: { full_name: fullName, phone: phone, email: email, contact_remarks: contact_remarks, c_type: 2 },
            complete: function (jqXHR, textStatus) {
                $(".apply").html(jqXHR.responseText);
                //alert(jqXHR.responseText);
            }
        });

    });


});
