﻿jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
}; (function($) {
    function getViewportHeight() {
        var height = window.innerHeight;
        var mode = document.compatMode;
        if ((mode || !$.support.boxModel)) {
            height = (mode == "CSS1Compat") ? document.documentElement.clientHeight : document.body.clientHeight;
        }
        return height;
    }
    $(window).scroll(function() {
        var vpH = getViewportHeight(),
        scrolltop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop),
        elems = [];
        $.each($.cache, function() {
            if (this.events && this.events.inview) {
                elems.push(this.handle.elem);
            }
        });
        if (elems.length) {
            $(elems).each(function() {
                var $el = $(this),
                top = $el.offset().top,
                height = $el.height(),
                inview = $el.data("inview") || false;
                if (scrolltop > (top + height) || scrolltop + vpH < top) {
                    if (inview) {
                        $el.data("inview", false);
                        $el.trigger("inview", [false]);
                    }
                } else {
                    if (scrolltop < (top + height)) {
                        if (!inview) {
                            $el.data("inview", true);
                            $el.trigger("inview", [true]);
                        }
                    }
                }
            });
        }
    });
    $(function() {
        $(window).scroll();
    });
})(jQuery);

function jaxi(xurl, xparam, xtrgt, xeffect) {
    $.ajax({
        url: getBaseURL()+ xurl,
        type: "GET",
        data: {x: xparam},
        cache: false,        
        beforeSend: function() {
            if (xeffect == "slide") {
                $(xtrgt).hide();
            } else {
            $(xtrgt).hide().html('<center><img  src ="http://server/wajihati-educ/images/loader.gif" /></center>').fadeIn("slow");
            }
        },
        success: function(data) {
            if (xeffect == "slide") {
                $(xtrgt).html(data).slideDown("slow");
            } else {
                $(xtrgt).html(data).show(function() {
                    if ($.browser.msie) {  this.style.removeAttribute("filter");    }
                });
            }
        }
    });
}
$(function() {
    $("#gotop").click(function() {
        $("html, body").animate({
            scrollTop: 0
        }, 'slow');
    });

    $("#linux").bind("inview", function(event, visible) {
        if (visible) {
            $("#gotop").fadeOut("fast");
        } else {
            // if ($.browser.version != "6.0") {
            $("#gotop").fadeIn('slow');
            //   }
        }
    });
    $(window).scroll();
    $(".vmenu,.hmenu").live("click", function() {   
        var sc = this.id;
        var xtrgt = "#" + ($(this).attr("trgt") || "main_div");
        var xeffect = $(this).attr("effect") || "hide";        
        jaxi($(this).attr("fichier"), $(this).attr("param"), xtrgt, xeffect);        
        if ($(this).attr("without_submenu")!="true") {
            if (($(this).attr("parent") == "13") || ($(this).attr("parent") == "12")) {
               $("#SubMenu").show();             
               /*  if ($(this).hasClass("hmenu"))  alert("1111"); educ_menu{*/
               jaxi("home/SubMenu.aspx", $(this).attr("parent"), "#SubMenu", "show");
            }
            else
               $("#SubMenu").hide();
        }
        if ($(this).attr("large") == "1") {
            $("#right_menu").hide();
        } else {
            $("#right_menu").show();
        }
        return false;
    });

});
$(function() {

//    var cookie = $.cookie('font_size');
//    if (typeof cookie != 'object') {
//        $('body').css('font-size', parseInt(cookie, 10));
//    }
//    $(".larger").live('click', function() {
//        var x = parseInt($("body").css('font-size').substr(0, 2), 10);
//        $("body").css('font-size', x + 1);
//        $.cookie('font_size', x + 1);
//    });
//    $(".smaller").live('click', function() {
//        var x = parseInt($("body").css('font-size').substr(0, 2), 10);gray
//        $("body").css('font-size', x - 1);
//        $.cookie('font_size', x + 1);
//    });
   
    $('table#inbox_table td').live('mouseover', function() {
    $(this).closest('tr').css({ 'background-color': '#E7E7E7', 'cursor': 'pointer' });
    });
    $('table#inbox_table td').live('mouseout', function() {
        $(this).closest('tr').css({ 'background-color': '', 'cursor': '' });
    });
    $('#show_hints').live('click', function() {
    $('#hints').toggle(function() { $(this).css('visibility', 'hidden'); })
        return false;
    });

});
function getBaseURL() {
   // alert("111");
    //return "http://server/wajihati-educ/";
    var url = location.href;
    var baseURL = url.substring(0, url.indexOf('/', 15));
    return baseURL + "/";


//    var url = location.href;
//    var baseURL = url.substring(0, url.indexOf('/', 11));
//    if (baseURL.indexOf('http://server') != -1) 
//    baseURL= url.substr(0, url.indexOf("/", url.indexOf(location.pathname) + 1)) ;    
//    return baseURL + "/";
}
$(function() {
    //    var m_day = (new Date()).getDate();
    //    var str = '../images/images/slice_' + m_day + '.jpg'.toString();
    //    $('.m_day').css({ 'background-image': 'url("' + str + '")' });
    if (!$.browser.msie) {
        $("#m_footer li").css('display', 'inline-table');
    }
    $(".publicUrl").each(function() {
        $(this).attr("href", getBaseURL() + $(this).attr("href"));
    });
    $(".publicImg").each(function() {
    //alert("111");
        if ($.browser.msie) {
            var strt = $(this).attr("src");
            var i;
            if (strt.indexOf("upload") > -1) {
                i = strt.indexOf("upload");
            }
            if (strt.indexOf("Divers") > -1) {
                i = strt.indexOf("Divers");
            }
            if (strt.indexOf("home") > -1) {
                i = strt.indexOf("home");
            }
            strt = strt.substr(i);
            //alert(strt);
            $(this).attr("src", getBaseURL() + strt);
        }
        else {
            $(this).attr("src", getBaseURL() + $(this).attr("src"));
        }
    });

});
function tabdila(xclass, xrep) {
    $("." + xclass).each(function() {
        if ($.browser.msie) {
            var strt = $(this).attr("src");
            var i = strt.indexOf(xrep + "/");
            strt = strt.substr(i);
            $(this).attr("src", getBaseURL() + strt);
        }
        else 
            $(this).attr("src", getBaseURL() + $(this).attr("src"));
    });
}