﻿var global;
var myWidth;
var myHeight;
var MouseX;
var MouseY;
var Tips;

    function updateTips(t) {
   
        tips
				.text(t)
				.addClass('ui-state-error');
        setTimeout(function() {
            tips.removeClass('ui-state-error', 1500);
        }, 500);
    }
    function checkLength(o, n, min, max) {

        if (o.val().length > max || o.val().length < min) {
            o.addClass('ui-state-error');
            updateTips("طول " + n + " باید بین " + min + " و " + max + " باشد.");
            return false;
        } else {
            return true;
        }

    }

    function checkRegexp(o, regexp, n) {

        if (!(regexp.test(o.val()))) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }
        
    
function alertSize() {
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

};
jQuery(document).ready(function(){

   $(document).mousemove(function(e){
   MouseX=e.pageX ;
   MouseY=e.pageY;

   }); 
})
//تابع برای نمایش هشدارها
function messagebox(t, m) {
alertSize();
 var temp;
 if (m == 's') {
     temp = $('#success')//موفقیت
 } else if (m == 'i') {
     temp = $('#info')//پیغام
 }
 else if (m == 'w') {
     temp = $('#warning')//هشدار
 }
 else if (m == 'e') {
     temp = $('#error')//خطا
 }
 else
 { temp = $('#loa') }
    temp.show();
    temp.css({'left':MouseX,'top':MouseY,'width':0});
        temp.animate({
        'left': ($(window).width() - 600) / 2 + $(window).scrollLeft() + "px",
        'top': ($(window).height() - 200) / 2 + $(window).scrollTop() + "px",
        'width':600,
        'opacity':1    
        },500);
         temp.children('div').html(t);
         setTimeout(function () {
             temp.fadeOut();
         }, 5000);
};
function changepage(data) {
 //   $('#mainpage').fadeOut('slow', function() {
    $('#mainpage').html(data);
  //  });
//    $('#mainpage').fadeIn('slow');
};
$(document).ready(function() {
    
    alertSize();
    $('#success').css({ left: myWidth / 2 - 300, top: 5 });
    $('#info').css({ left: myWidth / 2 - 300, top: 5 });
    $('#warning').css({ left: myWidth / 2 - 300, top: 5 });
    $('#error').css({ left: myWidth / 2 - 300, top: 5 });
    $.ajaxSetup({
        beforeSend: function() {
            $('#load').center();
            $('#load').show();
        }
                ,
        complete: function() {
            $('#load').center();
            $('#load').hide();
        }
    });
});

jQuery.fn.center = function() {
this.css("position", "absolute");
    
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

jQuery.jPrintArea = function(el) {
    var iframe = document.createElement('IFRAME');
    var doc = null;
    $(iframe).attr('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
    document.body.appendChild(iframe);
    doc = iframe.contentWindow.document;
    var links = window.document.getElementsByTagName('link');
    for (var i = 0; i < links.length; i++)
        if (links[i].rel.toLowerCase() == 'stylesheet')
        doc.write('<link type="text/css" rel="stylesheet" href="' + links[i].href + '"></link>');
    doc.write('<div class="' + $(el).attr("class") + '">' + $(el).html() + '</div>');
    doc.close();
    iframe.contentWindow.focus();
    iframe.contentWindow.print();
    alert('Printing...');
    document.body.removeChild(iframe);
}


