﻿/*               Risa Developer(c)-Downloadcenter Project-Class Comments
* author : Mahdi Farhani
* create Date: 1389/2/6
* description:JS
* [Hisory]
* Edited by: Mahdi Farhani Loading Function , Edit for Downloadcenter Project
* Edited by: Mahdi Farhani, Add Jquery Effect
* [/History]
*/

if (typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/, '');
    }
}
function Loading() {
    var loadingPanel = document.getElementById("Loading");
    var mainPanel = document.getElementById("main");
    
    if (loadingPanel) {
        loadingPanel.style.display = "block";
        mainPanel.style.opacity = 0.4;
        mainPanel.style.filter = "alpha(opacity=40)";
    }
    
}
function Loaded()
{
    var loadingPanel = document.getElementById("Loading");
    var mainPanel = document.getElementById("main");

    if (loadingPanel) {
        loadingPanel.style.display = "none";
        mainPanel.style.opacity = 1;
        mainPanel.style.filter = "";
    }
}
function HighlightControl(name,message) {
    var e = document.getElementById(name);
    
    if (e) {
        e.style.backgroundColor = "yellow";
        alert(message);
        e.value= message;
        e.focus();
    }
}
/************************ Jquery Effect ****************************/
function ShowModal() {
    var id = "#modalBox";

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    $('#mask').fadeIn(1000);
    $('#mask').fadeTo("slow", 0.8);

    var winH = $(window).height();
    var winW = $(window).width();

    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

    $(id).fadeIn(2000);
}
function CheckPhone() {
    var value = $(".phoneNumber").attr("value");
    if (value.trim() == "") {
        alert('لطفاً شماره تلفن همراه را وارد کنید');
        return;
    }
    $.ajax({
        url: "DefaultModule/forgetcode.aspx",
        type: "POST",
        data: "phoneNumber=" + value,
        success: function(content) {
            $('#mask').hide();
            $('.window').hide();

            var pos = content.indexOf("Not Found", 0);
            
            if (pos < 0) {
                showDialog('یادآوری کدرهگیری', 'کد رهگیری برای شما ارسال شد', 'success');
            }
            else {
                showDialog('یادآوری کدرهگیری', 'چنین شماره ای در سیستم ثبت نشده است', 'error');
            }
        }
    });
}
function ShowForgetcodePage() {
    var title = $("#forgetCode").attr("title");

    $.ajax({
        url: "DefaultModule/ForgetCode.aspx",
        async: false,
        success: function(content) {
           
            $("#ModalTitle").html(title);
            $("#modalBox .ModalContent").html(content);
            ShowModal();
        }
    });
    $('.window .close').click(function(e) {
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    })
}
$(document).ready(function() {
    $("#Loading").ajaxStart(function() {
        $(this).show();
    });
    $("#Loading").ajaxStop(function() {
        $(this).hide();
    });

    /*/\/\/\/\/\/\/\/\ Search Wahter Mark /\/\/\/\/\/\/\/\/\/\*/
    var options = {
        cssClass: "watermark"
    };
    $("#txtSearch").watermark("جــسـتـجـو", options);
    $('#txtSearch').keypress(function(e) {

        var code = null;

        code = (e.keyCode ? e.keyCode : e.which);
        
        if (code == 13) {
            $(".searchButton").click();
            return false;
        }
        else {
            return true;
        }

    });
    /******************* Search Content ****************************/
    $(".searchButton").click(function() {
        var value = $("#txtSearch").attr("value");
        var title = $(this).attr("alt");

        if (value.trim() == "" || value == "جــسـتـجـو")
            return;

        $.ajax({
            url: "DefaultModule/search.aspx",
            type: "POST",
            data: "searchValue=" + value,
            success: function(content) {
                $("#ModalTitle").html(title);
                $("#modalBox .ModalContent").html(content);
                ShowModal();
            }
        });
    });
    /******************* Search Content ****************************/
    /*******************   Forget Code  ****************************/

    /*******************   Forget Code  ****************************/
    /*******************    Modal Box   ****************************/
    $('.modalBoxClick').click(function() {

        var pageAddress = $(this).attr("alt");
        var title = $(this).attr("title");

        $.ajax({
            url: pageAddress,
            async: false,
            success: function(content) {
                $("#ModalTitle").html(title);
                $("#modalBox .ModalContent").html(content);

            }
        });

        ShowModal();
    });

    $('.window .close').click(function(e) {
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    })
});

