﻿///////Common Functions /////////////
currentlang = 'ar'
function AddToFavorites() {
    var url = window.document.URL;
    var title = currentlang == 'ar' ? 'مجلس الضمان الصحي التعاوني - ' + window.document.title : 'Council Of Cooperative Health Insurance - ' + window.document.title;

    if (window.sidebar) {
        // Mozilla Firefox Bookmark         
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.opera && window.print) {// Opera 
        alert('لاضافة الصفحة إلى المفضلة (Ctrl +D) اضغط على');
    }
    else if (window.external) { // IE Favorite
        if (window.ActiveXObject) {
            //ie
            window.external.AddFavorite(url, title);
        } else {
            //chrome
            alert('لاضافة الصفحة إلى المفضلة (Ctrl +D) اضغط على');
        }
    }
    else { //safri
        alert('لاضافة الصفحة إلى المفضلة (Ctrl +D) اضغط على');
    }
}

///////////////// Set as home page ////////////////
//////// Works only with IE and Firefox only //////////
function setHomepage() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://cchi.sure.com.sa');

    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', 'http://www.cchi.gov.sa');
    }
    else {
        alert('لا يمكن اتمام هذه العملية في متصفحي جوجل كروم و سافاري');
    }
}

/////////// Send To Friend ///////////////////////
function SendToFriend() {
    var pageTitle = document.title;
    var pageURL = document.location.href;
    window.location = '/AboutUs/Pages/SendToFriend.aspx?title=' + pageTitle + '&link=' + pageURL;
}

// print page 
function PrintPage(pCopyrights) {
    if (document.getElementById != null) {
        var html = '';


        html = '<html dir="rtl"><head>';
        $('link[rel=stylesheet]').each(function () {
            html += '<link rel="stylesheet" href="' + $(this).attr('href') + '" />';
        });
        html += '<link href="/_layouts/CCHI/ar/css/print.css" rel="stylesheet" type="text/css" />';
        html += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
		+ '<meta http-equiv="X-UA-Compatible" content="IE=8" />';
        html += '</head><body>' +
    '<div class="main_div_int">' +
        '<div class="main2">' +
            '<div>' +
                '<img src="/_layouts/CCHI/ar/images/logo.png" border="0" usemap="#Map" />' +
                '<map name="Map" id="Map">' +
                    '<area shape="rect" coords="1,34,332,117" href="#" title="الصفحة الرئيسية" />' +
                '</map>' +
            '</div><div class="clr"></div>' +
            '<div>' +
                '<div class="main_int">' +
                    '<div class="int_body">';
        //Content Here
        var printReadyElem = document.getElementById("MSO_ContentTable");
        if (printReadyElem != null) {
            html += printReadyElem.innerHTML;
        }
        html += '<div class="clr">' +
                        '</div></div><div class="clr"></div></div></div>' +
            '<table width="100%" border="0" cellspacing="10" cellpadding="0" class="footer">' +
                '<tr><td align="center"><div dir="ltr">' + pCopyrights + '</div></td></tr></table><div class="clr"></div></div><div class="clr"></div></div></body>';

        ///End HTML for Print page*/

        html += '</html>';
        var printWin = window.open('', 'printxt');
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        printWin.print();
        // return false;
    }
}

function PrintPageWithCopyRight() {
    var Copyrights = $("#dvCopyrights").text();
    PrintPage(Copyrights);
}

// Chnage Language
function ChangeLanguage() {
    // check the english link for the same URL if exists
    var url = window.location.pathname; // get the url without domain
    var currentlang = 'ar';

    url = '/en' + url;

    // test if the url is there
    $.ajax({
        url: url,
        asyn: true,
        cache: false,
        success: function(data, textStatus, jqXHR) {
            $('#enLink').attr('href', url);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            $('#enLink').attr('href', '/en/');
        }
    });
}

$(document).ready(function () {
    // menu effects
    $(".right_menu li").hover(function () {
        $(this).css("background-color", "#e9e9e9");

    }, function () {
        $(this).css("background-color", "transparent");
    });

    $('.right_menu a').click(function () {
        if ($(this).next().is('ul')) {
            $(this).next().slideToggle("slow");
            return false;
        }
    });

    // For search icon
    $("#SRP_NextImg img").attr("src", "/_layouts/CCHI/ar/images/search_prev.png");

    // Change Language
    ChangeLanguage();
});

$('a.theme').click(function () {
    var newColor = $(this).attr('id');
    var oldColor = 'blue';
    $.ajax({
        url: '/_layouts/cchi/AjaxHelper.aspx?op=style&value=' + newColor,
        asyn: true,
        cache: false,
        dataType: 'text',
        success: function (txt) {
            $('link[rel=stylesheet][rev=cchi]').each(function () {
                var currCSS = $(this).attr('href');
                if (currCSS.indexOf('blue') != -1)
                    oldColor = 'blue';
                else if (currCSS.indexOf('gray') != -1)
                    oldColor = 'gray';
                else if (currCSS.indexOf('yellow') != -1)
                    oldColor = 'yellow';
                else if (currCSS.indexOf('green') != -1)
                    oldColor = 'green';
                else if (currCSS.indexOf('violet') != -1)
                    oldColor = 'violet';

                currCSS = currCSS.replace('/' + oldColor + '/', '/' + newColor + '/');
                $(this).attr('href', currCSS);

            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

    return false;
});
