﻿/* Author: dcoder405

*/

if (typeof ERB === undefined) {
    ERB = {};
}

function positionChat() {
    if ($(window).width() < 1024) {
        $("#chat_section").css({
            right: 0
        });
    } else {
        $("#chat_section").css({
            right: "-230px"
        });
    }
}

function emailTest(value) {
    // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
    return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
}

$(document).ready(function () {

    $('#btn_google_search').click(function () {
        var keyword = $('#search_keyword').val();
        if (keyword != '') {
            window.location = "/GoogleResults.aspx?q=" + keyword;
        }
    });



    $('.corner').corner();
    $('.corner_small').corner('5px');

    //Chat window position control
    positionChat();
    $(window).resize(positionChat);

    //Home page slideshow using jQuerytools tabs
    $("#slides_nav").tabs("#slides > li", {

        effect: 'default',
        fadeOutSpeed: "slow",
        rotate: true

    }).slideshow({ autoplay: true });

    $("#sidebar_nav >ul>li").hoverIntent(function () {
        $(this).find('ul').show();
    }, function () {
        $(this).find('ul').hide();
    });

    //Cufon Font replacement
    //Calibri
    Cufon.replace('#header #main_nav ul li,#join', {
        hover: true, textDecoration: 'underline', fontSize: '12px'
    });

    //treatment page slideshow
    $(".slidetabs").tabs("#treatment_slides > li", {

        effect: 'default',
        fadeOutSpeed: "slow",
        rotate: true

    }).slideshow({ autoplay: true });

    //selectbox
    $(".select").selectbox();

    $("#notifyEmailSubmit").click(function () {


        var notifyEmail = $.trim($("#notifyEmail").val());

        if (notifyEmail == '') {
            alert("Please enter your email address");
            return false;
        } else if (!emailTest(notifyEmail)) {
            alert("Not a valid email address");
            return false;
        }

        $.ajax({
            type: "POST",
            url: "handler/AjaxMethod.aspx/AddPromotionNotification",
            data: "{'email':'" + notifyEmail.toString() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
                if (data.status == 'success') {

                    $('#messageReport').html('Email has been sent successfully.');
                    return false;
                }
                else {
                    $('#messageReport').html('Email has not been sent successfully.');
                    return false;
                }

            }
        });

    });


    //make enquiry

    $("#enquirySubmit").click(function () {


        var q_email = $.trim($("#q_email").val());

        if (q_email == '') {
            alert("Please enter your email address");
            return false;
        } else if (!emailTest(q_email)) {
            alert("Not a valid email address");
            return false;
        }

        $.ajax({
            type: "POST",
            url: "handler/AjaxMethod.aspx/AddEnquiry",
            data: "{'name':'" + q_name.toString() + "','email':'" + q_email.toString() + "','phone':'" + q_phone.toString() + "','details':'" + q_details.toString() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
                if (data.status == 'success') {

                    $('#messageReport').html('Email has been sent successfully.');
                    return false;
                }
                else {
                    $('#messageReport').html('Email has not been sent successfully.');
                    return false;
                }

            }
        });
    });



    //reward section
    $('#my_reward').click(function () {

        var email = $.trim($("#reward_email").val());

        if (email == '') {
            alert("Please enter your email address");
            return false;
        } else if (!emailTest(email)) {
            alert("Not a valid email address");
            return false;
        }

        $.ajax({
            type: "POST",
            /*url: "handler/PopulateAjaxData.aspx/validateEmail",*/
            url: "ajax.html",
            data: "{'loginEmail':'" + email + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {

                //alert("msg== " + data.d[0].Value);
                if (data.status == 'success') {
                    //Open the overlay & show the password input field
                    var api1 = $("#reward_step1_true").data("overlay");
                    api1.load();
                }
                else {
                    //Open the overlay & Your email doesn'e exist.
                    //please click here to register.  <a href="register">Register</a>
                    var api2 = $("#reward_step1_error").data("overlay");
                    api2.load();
                }
            }
        });

        return false;
    });

    var overlaySettings = {
        top: 260,
        mask: {
            color: '#fff',
            loadSpeed: 200,
            opacity: 0.5
        },
        oneInstance: false,
        closeOnClick: false,
        load: false
    };

    $("#reward_step1_true").overlay(overlaySettings);
    $("#reward_step1_error").overlay(overlaySettings);

    $('#password_submit').click(function () {

        var loginEmail = $.trim($("#reward_email").val());
        var loginPassword = $.trim($("#user_pass").val());
        if (loginPassword == '') {
            alert("Please enter your password");
            return false;
        }

        $.ajax({
            type: "POST",
            /*url: "handler/PopulateAjaxData.aspx/validatePassword",*/
            url: "ajax.html",
            data: "{'loginEmail':'" + loginEmail.toString() + "','loginPassword':'" + loginPassword.toString() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
                //alert("msg== " + data.d[0].Value);
                if (data.status == 'success') {
                    /*
                    $.cookie("userId", "0", { expires: -1, path: "/" });
                    $.cookie("userId", data.d[0].Value, { expires: 2, path: "/" });*/

                    var api3 = $("#reward_step1_true").data("overlay");

                    // Here You have to replace the text box with the text (i,e, Welcome Maruf, your total points 500)

                    //var txt = "Welcome" + data.d[0].Value + " your total points " + data.d[0].DisplayData;
                    var txt = "Welcome James, your total points 500";

                    $('#reward_form').html($("<div class='div'></div>").text(txt));

                    api3.close();
                }
                else {
                    $('#message').remove();
                    var t = $('<div id="message" class="error"></div>').html('Please enter correct credentials.').prependTo("#reward_step1_true .contentWrap");
                    console.log(t);
                    return false;
                }
            }
        });

        return false;
    });

    //treatment page radio button functionalities
    $(".t_row.first :radio").change(function () {
        var $this = $(this),
                $trt_btn = $(".trt_btn"),
                $booknowDivs = $(".booknow");

        if ($this.attr("id") == "booknow") {
            $booknowDivs.toggle();
            $trt_btn.toggle();
        } else if ($this.attr("id") == "addcart") {
            $booknowDivs.toggle();
            $trt_btn.toggle();
        }
    });

    //terms and services overlay
    $("a.mterms").overlay({

        mask: {
            color: '#fff',
            loadSpeed: 200,
            opacity: .5
        },
        effect: 'apple',
        top: '15%',

        onBeforeLoad: function () {

            // grab wrapper element inside content
            var wrap = this.getOverlay().find(".contentWrap");

            // load the page specified in the trigger
            wrap.load(this.getTrigger().attr("href"));
        }

    });

    //virtual tour overlay
    $("#tour a").overlay({

        mask: {
            color: '#fff',
            loadSpeed: 200,
            opacity: .5
        },
        effect: 'apple',
        top: '6%'

    });

    //Enquiry form open in overlay
    $(".do_query").overlay({

        mask: {
            color: '#fff',
            loadSpeed: 200,
            opacity: .5
        },
        effect: 'apple',
        top: '-4%',

        onBeforeLoad: function () {

            $("#query_form .required").each(function () {
                $(this).val("");
            });
        },
        onLoad: function () {
            $("#q_name").focus();
        }

    });

    //enquiry form validation
    //$("#q_form").validate();

    $("#book_btn").click(function () {

        return false;
    });
});

    
	



