﻿/*
this file contains the combine of script that r put in MasterPage.Master
<script src="lib/jquery.cookie.min.js" type="text/javascript"></script>
<script src="lib/polljs.js" type="text/javascript"></script>
removed due to chanes to otlob clip
<script src="lib/AjaxScript.js" type="text/javascript"></script>
<script src="lib/Sports.js" type="text/javascript"></script>
<script src="lib/slide.min.js" type="text/javascript"></script>
<script src="lib/jquery.json.min.js" type="text/javascript"></script>
<script src="lib/MasrawyHP.js" type="text/javascript"></script>
<script src="lib/MasrawyHP.services.js" type="text/javascript"></script>
<script src="lib/modal-window.js" type="text/javascript"></script>
<script src="lib/jquery.lazyload.mini.js" type="text/javascript"></script>
<script src="lib/time.js" type="text/javascript"></script>
<script src="lib/MHPFunc.js" type="text/javascript"></script>
*/
//--------------------jquery.cookie.min.js --------------------------------------
jQuery.cookie = function(name, value, options) { if (typeof value != "undefined") { 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() } 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 { 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]); if (cookie.substring(0, name.length + 1) == (name + "=")) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break } } } return cookieValue } };
//--------------------------------------------------------------------------------
//---------------------------polljs.js--------------------------------------------
//--------------------------------------------------------------------------------
function DrawCaptcha() {
    var a = Math.ceil(Math.random() * 9) + '';
    var b = Math.ceil(Math.random() * 9) + '';
    var c = Math.ceil(Math.random() * 9) + '';
    var d = Math.ceil(Math.random() * 9) + '';
    //    var e = Math.ceil(Math.random() * 10) + '';
    //    var f = Math.ceil(Math.random() * 10) + '';
    //    var g = Math.ceil(Math.random() * 10) + '';
    var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d; //+ ' ' + e + ' ' + f + ' ' + g;
    $('#spnCode').text(code);
}
function ValidCaptcha() {
    var str1 = removeSpaces(document.getElementById('spnCode').innerHTML);
    var str2 = removeSpaces(document.getElementById('txtCode').value);
    if (str1 == str2) return true;
    return false;
}
function removeSpaces(string) {
    return string.split(' ').join('');
}
$(document).ready(function() {
    var imgPoll = new Image();
    imgPoll.src = 'img/red-bar.png';
    //aaa    $('#btnSubmit').parent().before('<p class="pcaptchacont"><span class="spnpollcaptcha" id="spnCode"></span><input type="text" id="txtCode" size="6" /></p>');
    //aaa    DrawCaptcha();
    if ($("#divVoted").length > 0) //Already voted
    {
        animateResults();
    }
    else {
        //$("#rdoPoll0").attr("checked","checked"); //default select the first Choice
        // Add the page method call as an onclick handler for the Vote button.

        $("#btnSubmit").click(function() {
            var iz_checked = false;

            $("input[name='rdoPoll']").each(function() {

                if ($(this).is(':checked')) {

                    iz_checked = true;
                    return;
                }

            }); //End Each

            if (!iz_checked) {
                $("#ErrMsg").html("اختر اجابة من فضلك");
            }
            //aaa            else if (!ValidCaptcha()) {
            //aaa                $("#ErrMsg").html("من فضلك ادخل الكود");
            //aaa           }
            else {
                $("#divPoll").css("cursor", "wait"); //show wait cursor inside Poll div while processing
                $("#btnSubmit").attr("disabled", "true") //disable the Vote button while processing

                var pID = $("input[id$=hidPollID]").val(); //get Poll ID
                var cID = $("input[name='rdoPoll']:checked").val(); //get the checked Choice
                var SiteName = $("input[id$=hidSiteName]").val();
                var Lang = $("input[id$=hidLang]").val();
                var ZoneName = $("input[id$=hidZoneName]").val();
                var TotalVotesMsg = $("input[id$=hidTotalMsg]").val();
                var BarImg = $("input[id$=hidbarimg]").val();
                var AlreadyVoted = $("input[id$=hidAlreadyVoted]").val();
                var PerviousQues = $("input[id$=hidPervQues]").val();
                var PerviousQuesURL = $("input[id$=hidPervQuesURL]").val();

                var data = "{'pID':'" + pID + "', 'cID':'" + cID + "', 'SiteName':'" + SiteName + "', 'Lang':'" + Lang + "', 'ZoneName':'" + ZoneName + "', 'TotalVotesMsg':'" + TotalVotesMsg + "', 'BarImg':'" + BarImg + "', 'AlreadyVoted':'" + AlreadyVoted + "', 'PerviousQues':'" + PerviousQues + "', 'PerviousQuesURL':'" + PerviousQuesURL + "'}"; //create the JSON data to send to server

                $.ajax(
                {
                    type: "POST",
                    url: "AjaxMethods/bridge.aspx/UpdatePollCount",
                    data: data,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg)  //show the result
                    {
                        $("#divPoll").css("cursor", "default"); //remove the wait cursor
                        $("#btnSubmit").attr("disabled", "false") //enable the Vote button
                        if (msg.d == null) {
                            $("div[id$=divAnswers]").fadeOut("fast").html(msg).fadeIn("fast", function() { animateResults(); });
                        }
                        else {
                            $("div[id$=divAnswers]").fadeOut("fast").html(msg.d).fadeIn("fast", function() { animateResults(); });
                        }
                    }
                });
            } //ELSE
        });
    }
    function animateResults() {
        $("div[id$=divAnswers] img").each(function() {
            var percentage = $(this).attr("val");
            $(this).css({ width: "0%" }).animate({ width: percentage }, 'slow');
        });
    }
});
//------------------------------------------------------------------------------
//--------------------------AjaxScript.js-----------------------------------
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//--------------------------Sports.js----------------------------------------
//------------------------------------------------------------------------------
var lang = 1;
var tours, matches, gmt, tab, GMTText, TeamTitle, Matchestourid;
Matchestourid = 0;

function querySt(pname) {
    url = window.location.search.toLowerCase().substring(1);
    params = url.split("&");
    for (i = 0; i < params.length; i++) {
        pvalue = params[i].split("=");
        if (pvalue[0] == pname.toLowerCase()) {
            return pvalue[1];
        }
    }
}
function GetGMTText(gmt) {
    switch (gmt) {
        case "0":
            return "جرينتش";
            break;
        case "1":
            return "مصر";
            break;
        case "2":
            return "السعودية";
            break;
        case "3":
            return "الإمارات";
            break;
        case "6":
            return "المغرب";
            break;
        default: return "مصر";
    }
}
function GetGMTDiffText(gmt) {
    switch (gmt) {
        case "0":
            return "";
            break;
        case "1":
            return "GMT+2";
            break;
        case "2":
            return "GMT+3";
            break;
        case "3":
            return "GMT+4";
            break;
        case "6":
            return "GMT+0";
            break;
        default: return "GMT+2";
    }
}
function GetLangId() {
    return 1;
}
function SetActiveDiv(activetab, tab1, tab2) {
    $("#today").empty();
    $("#yesterday").empty();
    $("#tomorrow").empty();
    $(activetab).addClass("selected");
    $(tab1).removeClass("selected");
    $(tab2).removeClass("selected");
}
function RenderMatches(DivToRender, tab, gmt, lang) {
    $.ajax({
        type: "Post",
        url: "AjaxMethods/YallakoraProxy.asmx/GetMatchesList",
        data: "{'gmt': '" + gmt + "','lang':'" + lang + "','tab':'" + tab + "','tourid':" + $(MHP.R.DrpTourMatches).val() + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            if (tab == "0") {
                SetActiveDiv("#tab1a", "#tab2a", "#tab3a");
            }
            else if (tab == "1") {
                SetActiveDiv("#tab2a", "#tab1a", "#tab3a");
            }
            else {
                SetActiveDiv("#tab3a", "#tab1a", "#tab2a");
            }
            if (msg.d != "") {
                $.each(msg.d, function() {
                    //tours = '<div class="ChampName"><a title="" href="../ykchampions/default.aspx?region=&TourId=' + this['ID'] + '"><img onerror="SetNaMatcesImage(this)" src=' + this['TourLogo'] + '>' + this['Name'] + '</a></div>';
                    matches = "";
                    var Team1Title = "";
                    var Team2Title = "";
                    $.each(this['matchObj'], function() {
                        Team1Title = TeamTitle + this['Team1Name'];
                        Team2Title = TeamTitle + this['Team2Name'];
                        matches = matches + "<div class='match'><div class='prt1'>";
                        matches = matches + "<span class='team1'><a href='http://masrawy.yallakora.com/ykchampions/team.aspx?teamId=" + this['Team2'] + "&TourId=" + this['TourSeasonId'] + "'>" + this['Team2Name'] + "</a></span>";
                        matches = matches + "<span class='time2'>" + this['result'] + "</span>";
                        matches = matches + "<span class='team2'><a href='http://masrawy.yallakora.com/ykchampions/team.aspx?teamId=" + this['Team1'] + "&TourId=" + this['TourSeasonId'] + "'>" + this['Team1Name'] + "</a></span>";
                        matches = matches + "</div><div class='prt2'>";
                        if (tab == "0") {
                            if (!(this['MinbyMinIcon'] == "" && this['analysisIcon'] == "")) {
                                matches = matches + "<div class='MatcheInfo_icons'>";
                                matches = matches + this['MinbyMinIcon'];
                                matches = matches + this['analysisIcon'] + "</div>";
                            }
                        }
                        else if (tab == "1") {
                            if (!(this['MinbyMinIcon'] == "" && this['analysisIcon'] == "" && this['tvIcon'] == "" && this['PredictionIcon'] == "")) {
                                matches = matches + "<div class='MatcheInfo_icons'>";
                                matches = matches + this['tvIcon'];
                                matches = matches + this['MinbyMinIcon'];
                                matches = matches + this['analysisIcon'];
                                matches = matches + this['PredictionIcon'] + "</div>"
                            }
                        }
                        else {
                            if (!(this['MinbyMinIcon'] == "" && this['tvIcon'] == "" && this['PredictionIcon'] == "")) {
                                matches = matches + "<div class='MatcheInfo_icons'>";
                                matches = matches + this['tvIcon'];
                                matches = matches + this['PredictionIcon'] + "</div>";
                            }
                        }
                        matches = matches + this['status'];
                        matches = matches + "</div></div><div class='clear'></div>";
                    });
                    //$(DivToRender).append(tours);
                    $(DivToRender).append("<div class='allmatches'>" + matches + "</div>");
                });
            }
            else {
                $(DivToRender).append("<span class='noMatchlbl'>عفوا لا توجد مباريات في " + $(MHP.R.DrpTourMatches + " option:selected").text() + "</span>");
            }
        }

    });
}
function setCookie(cname, cvalue, chours) {
    if (chours) {
        var date = new Date();
        date.setTime(date.getTime() + (chours * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = cname + "=" + cvalue + expires + "; path=/";
}
function readCookie(cname) {
    var nameEQ = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
$(document).ready(function() {
    //matches clip
    $("#tab1a").attr({ 'title': ' نتائج المباريات السابقة ' });
    $("#tab2a").attr({ 'title': ' نتائج و مواعيد المباريات الحالية ' });
    $("#tab3a").attr({ 'title': ' مواعيد المباريات القادمة ' });
    //matches
    $('a.gmt').click(function() {
        $('#matchesloading').css('display', 'block');
        $('#matchesloading').height($('.matchList').height());
    });
    $("#tab2a").addClass("selected");

    if (readCookie("gmt") != "") {
        gmt = readCookie("gmt");
    }
    else {
        gmt = 1; //egypt is default
    }
    GMTText = "جميع المباريات وفقا لتوقيت";
    TeamTitle = "تغطية لجميع أخبار ومباريات";
    //
    tab = "1";
    $("#tab1a").click(function() {
        tab = "0";
        RenderMatches("#yesterday", 0, gmt, GetLangId());
        return false;
    });
    $("#tab2a").click(function() {
        tab = "1";
        RenderMatches("#today", 1, gmt, GetLangId());
        return false;
    });
    $("#tab3a").click(function() {
        tab = "2";
        RenderMatches("#tomorrow", 2, gmt, GetLangId());
        return false;
    });
    $("a.gmt").click(function() {
        gmt = $(this).attr("id");
        $("#dvGMT").html(GetGMTText(gmt));
        $('#yellow').html(GMTText + "&nbsp;" + GetGMTText(gmt) + "&nbsp;" + GetGMTDiffText(gmt));
        setCookie("gmt", "" + gmt + "", 8640000);
        if (tab == "0") {
            RenderMatches("#yesterday", 0, gmt, GetLangId());
        }
        else if (tab == "1") {
            RenderMatches("#today", 1, gmt, GetLangId());
        }
        else {
            RenderMatches("#tomorrow", 2, gmt, GetLangId());
        }
        return false;
    });
    $(MHP.R.DrpTourMatches).change(function() {
        if (tab == "0") {
            RenderMatches("#yesterday", 0, gmt, GetLangId());
        }
        else if (tab == "1") {
            RenderMatches("#today", 1, gmt, GetLangId());
        }
        else {
            RenderMatches("#tomorrow", 2, gmt, GetLangId());
        }
    });
})
//------------------------------------------------------------------------------
//--------------------------slide.min.js----------------------------------------
var csbustcachevar = 0; var csloadstatustext = "<img src='loading.gif' /> Requesting content..."; var csexternalfiles = []; var enablepersist = true; var slidernodes = new Object(); var csloadedobjects = ""; function Stop() { clearTimeout(window.slider1timer) } function Start() { window.slider1timer = setTimeout(function() { ContentSlider.autoturnpage("slider1", 7000) }, 7000) } function ContentSlider(sliderid, autorun, customPaginateText, customNextText) { var slider = document.getElementById(sliderid); if (typeof customPaginateText != "undefined" && customPaginateText != "") { slider.paginateText = customPaginateText } if (typeof customNextText != "undefined" && customNextText != "") { slider.nextText = customNextText } slidernodes[sliderid] = []; ContentSlider.loadobjects(csexternalfiles); var alldivs = slider.getElementsByTagName("div"); for (var i = 0; i < alldivs.length; i++) { if (alldivs[i].className == "contentdiv") { slidernodes[sliderid].push(alldivs[i]); if (typeof alldivs[i].getAttribute("rel") == "string") { ContentSlider.ajaxpage(alldivs[i].getAttribute("rel"), alldivs[i]) } } } ContentSlider.buildpagination(sliderid); var loadfirstcontent = true; if (enablepersist && __getCookie(sliderid) != "") { var cookieval = __getCookie(sliderid).split(":"); if (document.getElementById(cookieval[0]) != null && typeof slidernodes[sliderid][cookieval[1]] != "undefined") { ContentSlider.turnpage(cookieval[0], parseInt(cookieval[1])); loadfirstcontent = false } } if (loadfirstcontent == true) { ContentSlider.turnpage(sliderid, 0) } if (typeof autorun == "number" && autorun > 0) { window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorun) }, autorun) } } ContentSlider.buildpagination = function(sliderid) { var slider = document.getElementById(sliderid); var paginatediv = document.getElementById("paginate-" + sliderid); var pcontent = ""; pcontent += '<a href="#" style="float:left" onClick="ContentSlider.turnprepage(\'' + sliderid + "', parseInt(this.getAttribute('rel'))); return false\">< السابق</a>"; for (var i = 0; i < slidernodes[sliderid].length; i++) { pcontent += '<a href="#" style="display:none" onClick="ContentSlider.turnpage(\'' + sliderid + "', " + i + '); return false">' + (slider.paginateText ? slider.paginateText[i] : i + 1) + "</a> " } pcontent += '<a href="#" style="float:right" onClick="ContentSlider.turnpage(\'' + sliderid + "', parseInt(this.getAttribute('rel'))); return false\">التالي ></a>"; paginatediv.innerHTML = pcontent }; ContentSlider.turnpage = function(sliderid, thepage) { var paginatelinks = document.getElementById("paginate-" + sliderid).getElementsByTagName("a"); for (var i = 0; i < slidernodes[sliderid].length; i++) { paginatelinks[i].className = ""; slidernodes[sliderid][i].style.display = "none" } paginatelinks[thepage].className = "selected"; slidernodes[sliderid][thepage].style.display = "block"; paginatelinks[0].setAttribute("rel", thenextpage = (thepage > 0) ? thepage - 1 : paginatelinks.length - 3); paginatelinks[paginatelinks.length - 1].setAttribute("rel", thenextpage = (thepage < paginatelinks.length - 3) ? thepage + 1 : 0); if (enablepersist) { __setCookie(sliderid, sliderid + ":" + thepage) } }; ContentSlider.turnprepage = function(sliderid, thepage) { var paginatelinks = document.getElementById("paginate-" + sliderid).getElementsByTagName("a"); for (var i = 0; i < slidernodes[sliderid].length; i++) { paginatelinks[i].className = ""; slidernodes[sliderid][i].style.display = "none" } paginatelinks[thepage].className = "selected"; slidernodes[sliderid][thepage].style.display = "block"; paginatelinks[0].setAttribute("rel", thenextpage = (thepage > 0) ? thepage - 1 : paginatelinks.length - 3); paginatelinks[paginatelinks.length - 1].setAttribute("rel", thenextpage = (thepage < paginatelinks.length - 3) ? thepage + 1 : 0); if (enablepersist) { __setCookie(sliderid, sliderid + ":" + thepage) } }; ContentSlider.autoturnpage = function(sliderid, autorunperiod) { var paginatelinks = document.getElementById("paginate-" + sliderid).getElementsByTagName("a"); var nextpagenumber = parseInt(paginatelinks[paginatelinks.length - 1].getAttribute("rel")); ContentSlider.turnpage(sliderid, nextpagenumber); window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorunperiod) }, autorunperiod) }; ContentSlider.Stop = function() { clearTimeout(window[sliderid + "timer"]); alert("in ContentSlider.stop ") }; ContentSlider.start = function() { window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorunperiod) }, autorunperiod) }; function __getCookie(Name) { var re = new RegExp(Name + "=[^;]+", "i"); if (document.cookie.match(re)) { return document.cookie.match(re)[0].split("=")[1] } return "" } function __setCookie(name, value) { document.cookie = name + "=" + value } ContentSlider.ajaxpage = function(url, thediv) { var page_request = false; var bustcacheparameter = ""; if (window.XMLHttpRequest) { page_request = new XMLHttpRequest() } else { if (window.ActiveXObject) { try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { try { page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { } } } else { return false } } thediv.innerHTML = csloadstatustext; page_request.onreadystatechange = function() { ContentSlider.loadpage(page_request, thediv) }; if (csbustcachevar) { bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime() } page_request.open("GET", url + bustcacheparameter, true); page_request.send(null) }; ContentSlider.loadpage = function(page_request, thediv) { if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) { thediv.innerHTML = page_request.responseText } }; ContentSlider.loadobjects = function(externalfiles) { for (var i = 0; i < externalfiles.length; i++) { var file = externalfiles[i]; var fileref = ""; if (csloadedobjects.indexOf(file) == -1) { if (file.indexOf(".js") != -1) { fileref = document.createElement("script"); fileref.setAttribute("type", "text/javascript"); fileref.setAttribute("src", file) } else { if (file.indexOf(".css") != -1) { fileref = document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file) } } } if (fileref != "") { document.getElementsByTagName("head").item(0).appendChild(fileref); csloadedobjects += file + " " } } };
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//--------------------------jquery.json.min.js----------------------------------
//------------------------------------------------------------------------------
/*
* jQuery JSON Plugin
* version: 1.0 (2008-04-17)
*
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php
*
* Brantley Harris technically wrote this plugin, but it is based somewhat
* on the JSON.org website's http://www.json.org/json2.js, which proclaims:
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
* I uphold.  I really just cleaned it up.
*
* It is also based heavily on MochiKit's serializeJSON, which is 
* copywrited 2005 by Bob Ippolito.
*/
(function($) {
    function toIntegersAtLease(n) { return n < 10 ? "0" + n : n } Date.prototype.toJSON = function(date) { return date.getUTCFullYear() + "-" + toIntegersAtLease(date.getUTCMonth() + 1) + "-" + toIntegersAtLease(date.getUTCDate()) }; var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
    var meta = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }; $.quoteString = function(string) { if (escapeable.test(string)) { return '"' + string.replace(escapeable, function(a) { var c = meta[a]; if (typeof c === "string") { return c } c = a.charCodeAt(); return "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16) }) + '"' } return '"' + string + '"' }; $.toJSON = function(o) { var type = typeof (o); if (type == "undefined") { return "undefined" } else { if (type == "number" || type == "boolean") { return o + "" } else { if (o === null) { return "null" } } } if (type == "string") { return $.quoteString(o) } if (type == "object" && typeof o.toJSON == "function") { return o.toJSON() } if (type != "function" && typeof (o.length) == "number") { var ret = []; for (var i = 0; i < o.length; i++) { ret.push($.toJSON(o[i])) } return "[" + ret.join(", ") + "]" } if (type == "function") { throw new TypeError("Unable to convert object of type 'function' to json.") } ret = []; for (var k in o) { var name; var type = typeof (k); if (type == "number") { name = '"' + k + '"' } else { if (type == "string") { name = $.quoteString(k) } else { continue } } val = $.toJSON(o[k]); if (typeof (val) != "string") { continue } ret.push(name + ": " + val) } return "{" + ret.join(", ") + "}" }; $.evalJSON = function(src) { return eval("(" + src + ")") }; $.secureEvalJSON = function(src) { var filtered = src; filtered = filtered.replace(/\\["\\\/bfnrtu]/g, "@"); filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]"); filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, ""); if (/^[\],:{}\s]*$/.test(filtered)) { return eval("(" + src + ")") } else { throw new SyntaxError("Error parsing JSON, source is not valid.") } }
})(jQuery);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//--------------------------MasrawyHP.js----------------------------------------
/// <reference path="Common.js" />
(function() {
    var MasrawyHP = window.MasrawyHP = function() {
        return new MasrawyHP.prototype.init();
    };

    if (!window.MasrawyHP) {
        window.MasrawyHP = MasrawyHP;
    }

    MasrawyHP.proto = MasrawyHP.prototype = {
        init: function() {
            return new MasrawyHP();
        }
    }
    MasrawyHP.getQSValue = function(q) {
        if (!qsObj) { loadCurrentQS(); }
        return qsObj[q];
    }
    MasrawyHP.setCookie = function(name, value, expires, path, domain, secure) {
        var today = new Date();
        today.setTime(today.getTime());

        if (expires) {
            expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date(today.getTime() + (expires));

        document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
    }
    MasrawyHP.getCookie = function(name) {
        var dc = document.cookie;
        if (dc.indexOf(name) != -1 && dc.substr(dc.indexOf(name) + name.length, 1) == '=') {
            if (dc.indexOf(";", dc.indexOf(name)) != -1) {
                var EndOfCookie = dc.indexOf(";", dc.indexOf(name));
                var CookieName = dc.indexOf(name) + name.length + 1;
                var CookieValue = EndOfCookie - CookieName;
                return dc.substr(dc.indexOf(name) + name.length + 1, CookieValue)
            }
            else {
                return dc.substr(dc.indexOf(name) + name.length + 1, dc.length)
            }
        }
        return "";
    }
    MasrawyHP.deleteCookie = function(name, path, domain) {
        if (MasrawyHP.getCookie(name)) document.cookie = name + "=" +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    MasrawyHP.startLoader = function(divName) {
        var loader = $("#loader" + divName)[0];
        var div = $("#" + divName);
        if (!loader) {
            loader = document.createElement("div");
            loader.id = "loader" + divName;
            loader.className = "loader";
            loader.innerHTML = "<img src='img/loader.gif' class='imgloader' />";
            div.before(loader);
        }
        if (div.length > 0) {
            loader.style.width = div[0].offsetWidth + "px";
            loader.style.height = parseInt(div[0].offsetHeight) + "px";
            $(loader).show();
        }
    }
    MasrawyHP.inputOut = function(fld, value) {
        if (fld.value == '') {
            fld.value = value;
        }
    }
    MasrawyHP.inputIn = function(fld, value) {
        if (fld.value == value) {
            fld.value = '';
        }
    }
    MasrawyHP.showPrompt = function(title, divname, pname, width, height, opacityValue, data) {
        if (data != null) {
            $("#" + pname).html(data);
        }
        $("#" + divname).dialog({
            height: height,
            width: width,
            modal: true,
            draggable: false,
            resizable: false,
            title: title,
            overlay: { opacity: opacityValue, background: "#dfdfdf" }
        });
    }
    var qsObj;
    function loadCurrentQS() {
        qsObj = new Object()
        var url = location.href;
        if (url.indexOf("?") > -1) {
            var strParams = url.split("?")[1].split("&");
            for (var i = 0; i < strParams.length; i++) {
                var qsParam = strParams[i].split("=");
                qsObj[qsParam[0]] = qsParam[1];
            }
        }
    }
    MasrawyHP.validation = {
        isEmpty: function(txt) {
            if (txt.value.replace(/ /g, '') == '') {
                txt.style.borderColor = 'red';
                return true;
            }
            else {
                txt.style.borderColor = 'green';
                return false;
            }
        },
        isEmpty2: function(txt) {
            if (txt.value.replace(/ /g, '') == '') {
                txt.className = 'ce-usernameboxError';
                return true;
            }
            else {
                txt.className = 'ce-usernamebox';
                return false;
            }
        },
        isValueEmpty: function(Value) {
            if (Value.replace(/\s/g, '') == '') {
                return true;
            }
            else {
                return false;
            }
        },
        istxtSearchEmpty: function(txt, defaultvalue) {
            // alert(defaultvalue);
            var txtSearchval = $('#' + txt).val().replace(defaultvalue, '').replace(/ /g, '');
            //alert(txtSearchval);
            if (txtSearchval == '') {
                document.getElementById(txt).style.borderColor = 'red';
                return true;
            }
            else {
                document.getElementById(txt).style.borderColor = 'green';
                return false;
            }
        },
        isSelected: function(sel) {
            if (sel.selectedIndex > 0) {
                sel.style.borderColor = 'green';
                return true;
            }
            else {
                sel.style.borderColor = 'red';
                return false;
            }
        },
        isNumeric: function(txt) {
            var num = txt.value;
            num = num * 1;
            if (num == num) {
                txt.style.borderColor = 'green';
                return true;
            }
            else {
                txt.style.borderColor = 'red';
                return false;
            };
        },
        IsCharDigitsOnly: function(txt) {
            var filter = /[^أ-يa-zA-Z0-9 آء]+/g;
            if (txt.value.search(filter) == -1) {
                txt.style.borderColor = 'green';
                return true;
            }
            else {
                txt.style.borderColor = 'red';
                return false;
            }
        },
        isCharLessThan: function(txt, num) {
            if (txt.value.replace(/ /g, '').length > 0 && txt.value.replace(/ /g, '').length < num) {
                txt.style.borderColor = 'red';
                return true;
            }
            else {
                txt.style.borderColor = 'green';
                return false;
            }
        }
    }
    String.prototype.format = function() {
        var str = this;
        for (var i = 0; i < arguments.length; i++) {
            var re = new RegExp('\\{' + (i) + '\\}', 'gm');
            str = str.replace(re, arguments[i]);
        }
        return str;
    }
})();
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//---------------------MasrawyHP.services.js------------------------
(function(MasrawyHP) {
    MasrawyHP.ajax = {
        doCallbackHtml: function(id, param, callback) {
            $.ajaxSetup({
                contentType: "application/x-www-form-urlencoded"
            });
            var postData = "__CALLBACKID=" + escape(id) +
			"&__CALLBACKPARAM=" + escape(param) + "&__VIEWSTATE=&";
            $.post(document.URL, postData, function(data, status) {
                if (data.charAt(0) == "s") {
                    status = "success";
                    data = data.substring(1);
                } else if (data.charAt(0) == "e") {
                    status = "error";
                    data = data.substring(1);
                } else {
                    var separatorIndex = data.indexOf("|");
                    if (separatorIndex != -1) {
                        var valLength = parseInt(data.substring(0, separatorIndex));
                        if (!isNaN(valLength)) {
                            data = data.substring(separatorIndex + valLength + 1);
                        }
                    }
                }
                if (callback != null)
                    callback(data, status);
            }, "html");
        },
        doCallbackJson: function(url, method, params, callback) {
            $.ajaxSetup({
                contentType: "application/json"
            });

            $.post(url + method, $.toJSON(params), function(data, status) {
                var res = eval(data);
                callback(res[method + "Result"], status);
            }, "json");
        },
        doCallbackJsona: function(url, params, callback) {
            if (params = '') {
                $.getJSON(url, callback);
            }
            else
                $.getJSON(url, params, callback);

        }
		,
        doCallback: function(url, method, params) {
            $.ajaxSetup({
                contentType: "application/json"
            });
            $.post(url + method, $.toJSON(params), null, "json");
        }
    }
    MasrawyHP.services = {
        hostUrl: "AjaxMethods/AjaxMethodsV2.asmx/#FunctionName#",
        pagesUrl: "ctrlt/#pageName#",
        AjaxMethods: {
            AjaxMethodsCaller: function(param, functionName, callback, callbackError) {
                $.ajaxSetup({
                    contentType: "application/json; charset=utf-8"
                });
                $.ajax({
                    type: "POST",
                    url: MasrawyHP.services.hostUrl.replace('#FunctionName#', functionName),
                    data: param,
                    success: function(msg, Status) {
                        var res = eval(msg.replace('"', '').replace('"', ''));
                        callback(res, Status);
                    },
                    complete: function(msg, result) {
                        //                        if (msg.status == 200 && msg.statusText == 'OK') {
                        //                            //var res = eval(msg.responseText.replace('"', '').replace('"', ''));
                        //                            callback(msg, status);
                        //                        }
                        //                        else {
                        //                            callbackError(msg, status);
                        //                        }
                    },
                    error: function(XMLHttpRequest1, textStatus, errorThrown) {
                        callbackError(textStatus, "Error");
                    },
                    dataType: "application/json"
                });
            },
            AjaxPagesCaller: function(pageName, callback, callbackError) {
                //                $.ajaxSetup({
                //                    contentType: "application/json; charset=utf-8"
                //                });
                $.ajax({
                    type: "GET",
                    url: MasrawyHP.services.pagesUrl.replace('#pageName#', pageName),
                    //data: param,
                    success: function(msg, Status) {
                        // var res = eval(msg.replace('"', '').replace('"', ''));
                        callback(msg, Status);
                    },
                    complete: function(msg, result) {
                        //                        if (msg.status == 200 && msg.statusText == 'OK') {
                        //                            //var res = eval(msg.responseText.replace('"', '').replace('"', ''));
                        //                            callback(msg, status);
                        //                        }
                        //                        else {
                        //                            callbackError(msg, status);
                        //                        }
                    },
                    error: function(XMLHttpRequest1, textStatus, errorThrown) {
                        callbackError(textStatus, "Error");
                    },
                    dataType: "xml"
                });
            }
        }
    }
})(MasrawyHP);
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//----------------------modal - window.js---------------------------------
var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    type: null,
    divName: null,
    close: function(modalObj) {
        if (modalObj.type == 1)
            $(modalObj.divName).appendTo($(document.body)).hide();
        $(".modal-window").remove();
        $(".modal-overlay").remove();

    },
    open: function() {
        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        if (this.type == 0) {
            modal += this.content;
            modal += "</div>";
            $(this.parent).append(modal);
        }
        else {
            modal += "</div>";
            $(this.parent).append(modal);
            $(this.divName).appendTo($('#' + this.windowId)).show();
        }
        var modalObj = this;
        $(".modal-window").append("<a class=\"close-window\"></a>");
        $(".close-window").click(function() { modalWindow.close(modalObj); });
        $(".modal-overlay").click(function() { modalWindow.close(modalObj); });
    }
};


var openMyModal = function(source, type, Width, Height) {
    modalWindow.type = type;
    modalWindow.windowId = "myModal";
    modalWindow.width = Width; //Width//480;
    modalWindow.height = Height; //Height//370;
    if (type == 0) {
        modalWindow.content = "<iframe width='480' height='390' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'>&lt/iframe>";
    }
    else {
        modalWindow.divName = source;
    }
    modalWindow.open();
};
//-------------------------------------------------------------------------------
//----------------------jquery.lazyload.mini.js----------------------------------
(function($) {
    $.fn.lazyload = function(options) {
        var settings = { threshold: 0, failurelimit: 0, event: "scroll", effect: "show", container: window }; if (options) { $.extend(settings, options); }
        var elements = this; if ("scroll" == settings.event) { $(settings.container).bind("scroll", function(event) { var counter = 0; elements.each(function() { if ($.abovethetop(this, settings) || $.leftofbegin(this, settings)) { } else if (!$.belowthefold(this, settings) && !$.rightoffold(this, settings)) { $(this).trigger("appear"); } else { if (counter++ > settings.failurelimit) { return false; } } }); var temp = $.grep(elements, function(element) { return !element.loaded; }); elements = $(temp); }); }
        this.each(function() {
            var self = this; if (undefined == $(self).attr("original")) { $(self).attr("original", $(self).attr("src")); }
            if ("scroll" != settings.event || undefined == $(self).attr("src") || settings.placeholder == $(self).attr("src") || ($.abovethetop(self, settings) || $.leftofbegin(self, settings) || $.belowthefold(self, settings) || $.rightoffold(self, settings))) {
                if (settings.placeholder) { $(self).attr("src", settings.placeholder); } else { $(self).removeAttr("src"); }
                self.loaded = false;
            } else { self.loaded = true; }
            $(self).one("appear", function() {
                if (!this.loaded) {
                    $("<img />").bind("load", function() {
                        $(self).hide().attr("src", $(self).attr("original"))
[settings.effect](settings.effectspeed); self.loaded = true;
                    }).attr("src", $(self).attr("original"));
                };
            }); if ("scroll" != settings.event) { $(self).bind(settings.event, function(event) { if (!self.loaded) { $(self).trigger("appear"); } }); }
        }); $(settings.container).trigger(settings.event); return this;
    }; $.belowthefold = function(element, settings) {
        if (settings.container === undefined || settings.container === window) { var fold = $(window).height() + $(window).scrollTop(); } else { var fold = $(settings.container).offset().top + $(settings.container).height(); }
        return fold <= $(element).offset().top - settings.threshold;
    }; $.rightoffold = function(element, settings) {
        if (settings.container === undefined || settings.container === window) { var fold = $(window).width() + $(window).scrollLeft(); } else { var fold = $(settings.container).offset().left + $(settings.container).width(); }
        return fold <= $(element).offset().left - settings.threshold;
    }; $.abovethetop = function(element, settings) {
        if (settings.container === undefined || settings.container === window) { var fold = $(window).scrollTop(); } else { var fold = $(settings.container).offset().top; }
        return fold >= $(element).offset().top + settings.threshold + $(element).height();
    }; $.leftofbegin = function(element, settings) {
        if (settings.container === undefined || settings.container === window) { var fold = $(window).scrollLeft(); } else { var fold = $(settings.container).offset().left; }
        return fold >= $(element).offset().left + settings.threshold + $(element).width();
    }; $.extend($.expr[':'], { "below-the-fold": "$.belowthefold(a, {threshold : 0, container: window})", "above-the-fold": "!$.belowthefold(a, {threshold : 0, container: window})", "right-of-fold": "$.rightoffold(a, {threshold : 0, container: window})", "left-of-fold": "!$.rightoffold(a, {threshold : 0, container: window})" });
})(jQuery);
//-------------------------------------------------------------------------------
//-------------------------------time.js--------------------------------------
function getStrDate(date) {
    var strDate = "";
    var currDate = date;
    // alert(date.getDate());
    var newDate = new Date();
    var diff = newDate - currDate;
    var sec = diff / 1000;
    var min = sec / 60;
    var hours = min / 60;
    var days = hours / 24;
    var strLessMin = ' أقل من دقيقة ';
    var strHalfMin = ' نصف دقيقة ';
    var strAbut = ' حوالي ';
    var strDay = ' يوم ';
    var strDays = ' أيام '
    var strAgo = ' منذ ';
    var strHours = ' ساعات ';
    var strHour = ' ساعة ';
    var strMin = ' دقيقة ';
    var strMins = ' دقائق ';
    if (days >= 7) {
        strDate = currDate.getHours() + ":" + currDate.getMinutes() + ":" + currDate.getSeconds() + " " + currDate.getMonth() + " " + currDate.getDate();
        strDate = strDate + " " + currDate.getFullYear()
    }
    else {
        if (Math.round(days) == 1) {
            strDate = strAgo + strAbut + Math.round(days) + strDay
        } else {
            if (Math.round(days) > 1) {
                strDate = strAgo + strAbut + Math.round(days) + strDays
            } else {
                if (Math.round(hours) > 1)
                { strDate = strAgo + strAbut + Math.round(hours) + strHours }
                else {
                    if (Math.round(hours) == 1 && Math.round(min) > 45) {
                        strDate = strAgo + strAbut + "1" + strHour
                    } else {
                        if (Math.round(min) == 1)
                        { strDate = strAgo + "1" + strMin }
                        else {
                            if (Math.round(min) > 1) {
                                strDate = strAgo + Math.round(min) + strMins
                            }
                            else {
                                if (sec <= 30) {
                                    strDate = strHalfMin;
                                }
                                else {
                                    if (sec > 30) {
                                        strDate = strLessMin;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } return strDate
}
//-------------------------------------------------------------------------------
//----------------------MHPFunc.js----------------------------------
/// <reference path="Common.js" />
(function() {
    var MHPFunc = window.MHPFunc = function() {
        return new MHPFunc.prototype.init();
    };
    if (!window.MHPFunc) {
        window.MHPFunc = MHPFunc;
    }
    MHPFunc.proto = MHPFunc.prototype = {
        init: function() {
            return new MHPFunc();
        }
    }
    MHPFunc.PageUniqueID = null;
    MHPFunc.AdAttributes = new Array();
    MHPFunc.ErrorTitle = null;
    MHPFunc.ErrorMsgGeneral = null;
    MHPFunc.UserID = null;
    MHPFunc.Load = function() {
        //MHPFunc.HandleTabs();
        MHPFunc.AttachEvents();
        // MHPFunc.checkFeaturesNewsStyles();
        MHPFunc.GetCommentsCount();
        MHPFunc.LoadWeatherCounries();
        MHPFunc.GetUserNews();
        MHPFunc.GetUserArticles();
        MHPFunc.HandleHPLink();
        MHPFunc.getTridionClipData('FunnyXML.aspx', '#tab-29', MHPFunc.JokesRes, MHPFunc.JokesResError)
        //Adjust the clips height to be same height
        MHPFunc.AdjustClipHeight('HawadthJokes');
        MHPFunc.GetOnTvProgramVideo();
        //mmm MHPFunc.AdjustClipHeight('maindivs');

        ///mm MHPFunc.getTridionClipData('VideosXML.aspx', '#videos', MHPFunc.videosRes, MHPFunc.videosResError);

        // MHPFunc.checkFeaturesNewsStyles();
    }
    MHPFunc.AttachEvents = function() {
        //Nav
        $('.clr1').click(function() { $("body").attr('id', 'colr1'); MasrawyHP.setCookie("MasrawyHPTheme", "colr1", 5, "", "", ""); })
        $('.clr2').click(function() { $("body").attr('id', 'colr2'); MasrawyHP.setCookie("MasrawyHPTheme", "colr2", 5, "", "", ""); })
        $('.clr3').click(function() { $("body").attr('id', 'colr3'); MasrawyHP.setCookie("MasrawyHPTheme", "colr3", 5, "", "", ""); })
        $('.clr4').click(function() { $("body").attr('id', 'colr4'); MasrawyHP.setCookie("MasrawyHPTheme", "colr4", 5, "", "", ""); })
        $('.clr5').click(function() { $("body").attr('id', 'colr5'); MasrawyHP.setCookie("MasrawyHPTheme", "colr5", 5, "", "", ""); })
        $('.clr6').click(function() { $("body").attr('id', 'colr6'); MasrawyHP.setCookie("MasrawyHPTheme", "colr6", 5, "", "", ""); })
        $('.clr7').click(function() { $("body").attr('id', 'colr7'); MasrawyHP.setCookie("MasrawyHPTheme", "colr7", 5, "", "", ""); })
        $('.clr8').click(function() { $("body").attr('id', 'colr8'); MasrawyHP.setCookie("MasrawyHPTheme", "colr8", 5, "", "", ""); })
        $('.clr9').click(function() { $("body").attr('id', 'colr9'); MasrawyHP.setCookie("MasrawyHPTheme", "colr9", 5, "", "", ""); })
        //MasrawyHPFeaturedStyle: moved to control:FeaturedNews.ascx
        ///fff $(".display1").click(MHPFunc.MasrawyHPFeaturedStyle1Click);
        ///fff $(".display2").click(MHPFunc.MasrawyHPFeaturedStyle2Click);
        ///fff $(".display3").click(MHPFunc.MasrawyHPFeaturedStyle3Click);

        //Sliders
        MHPFunc.AttachSlideDivs();
        //slider for control: SmallFeature.ascx
        ContentSlider("slider1", 7000);

        //Weather
        $(MHP.R.DropCountriesWeather).change(function() {
            MHPFunc.DropCountriesWeatherChange();
        });
        $(MHP.R.DropCitiesWeather).change(function() {
            MHPFunc.DropCitiesWeatherChange(this);
        });
        $(MHP.R.LnkShowWeatherDiv).mouseover(function() {
            $(MHP.R.WeatherDropDiv).css('display', 'block');
        });
        $(MHP.R.LnkShowWeatherDiv).click(function() {
            MHPFunc.LnkShowWeatherClick(this);
        });
        $(MHP.R.BtnCloseWeatherDiv).click(function() {
            $(MHP.R.WeatherDropDiv).css('display', 'none');
        });
        //End Weather
        //TabsCounter
        $(MHP.R.PageTabClass).click(MHPFunc.PageTabClick);
        //$(MHP.R.lnkUserNews).click(MHPFunc.GetUserNews);

        $(MHP.R.drpNews).change(function() {
            MHPFunc.DropKPTchanges(2);
        });
        $(MHP.R.drpPosts).change(function() {
            MHPFunc.DropKPTchanges(1);
        });
        //EndTabsCounter
        //MHPFunc.IniTializeDatePicker();
    }

    /*fff   MHPFunc.checkFeaturesNewsStyles1 = function() {
    var MasrawyHPFeaturedStyle = MasrawyHP.getCookie("MasrawyHPFeaturedStyle2");
    if (MasrawyHPFeaturedStyle != "") {
    switch (MasrawyHPFeaturedStyle) {
    case "display1":
    //alert("calling click 1");
    MHPFunc.MasrawyHPFeaturedStyle1Click();
    break;
    case "display2":
    //alert("calling click 2");
    MHPFunc.MasrawyHPFeaturedStyle2Click();
    break;
    case "display3":
    //alert("calling click 3");
    MHPFunc.MasrawyHPFeaturedStyle3Click();
    break;
    default: MHPFunc.MasrawyHPFeaturedStyle1Click();
    }
    }
    }*/
    MHPFunc.AttachSlideDivs = function() {
        $('.drp li').hover(
		function() {
		    //show its submenu
		    $('ul', this).show(); //.slideDown(100);
		},
		function() {
		    //hide its submenu
		    $('ul', this).hide(); //.slideUp(100);
		}
     );
    }
    /*fff  MHPFunc.MasrawyHPFeaturedStyle1Click = function() {
    $('.newstheme a span').removeClass('nactive');
    $('a.display1 span').addClass('nactive');
    $('#news').removeClass().addClass('tabs display1');
    $('.ful').width(listwidth); //
    MasrawyHP.setCookie("MasrawyHPFeaturedStyle2", "display1", 5, "", "", "");
    }
    MHPFunc.MasrawyHPFeaturedStyle2Click = function() {
    $('.newstheme a span').removeClass('nactive');
    $('a.display2 span').addClass('nactive');
    $('#news').removeClass().addClass('tabs display2');
    $('.ful').width(604);
    MasrawyHP.setCookie("MasrawyHPFeaturedStyle2", "display2", 5, "", "", "");
    }
    MHPFunc.MasrawyHPFeaturedStyle3Click = function() {
    $('.newstheme a span').removeClass('nactive');
    $('a.display3 span').addClass('nactive');
    $('#news').removeClass().addClass('tabs display3');
    $('.ful').width(604);
    MasrawyHP.setCookie("MasrawyHPFeaturedStyle2", "display3", 5, "", "", "");
    }
    */
    MHPFunc.HandleTabs = function() {
        //Tabs
        var tabContainers = $('div.tabs > div');
        var clicks = $('div.tabs > ul');
        tabContainers.hide().filter(':first').show();
        $('div.tabs ul.tb a').click(function() {
            var tabContainers = $(this).parents('.tabs').find(' > div');
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $(tabContainers).parents('.tabs').find('.tb a').removeClass('active');
            $(this).addClass('active');
            return false;
        })
        $(clicks).each(function() {
            if ($(this).hasClass(MHP.R.RandonTabsClass)) {
                var count = $(this).find('a').length;
                var randomnumber = Math.floor(Math.random() * count);
                //alert(randomnumber);
                $(this).find('a').filter(function(index) {
                    return index == randomnumber;
                }).click();
            }
            else {
                $(this).find('a').filter(':first').click();
            }
            //$(this).parent().find('a').filter(':first').click();
        })
        // hasClass( class )
        //  })
        //Sub Tabs
        var tabContainers = $('div.subtabs > div');
        tabContainers.hide().filter(':first').show();
        $('div.subtabs ul.subtb a').click(function() {
            var tabContainers = $(this).parents('.subtabs').find(' > div');
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $(tabContainers).parents('.subtabs').find('.subtb a').removeClass('active');
            $(this).addClass('active');
            return false;
        })
        $(tabContainers).each(function() {
            //$(this).parent().find('a').filter(':first').click();
        })
    }
    MHPFunc.LoadWeatherCounries = function() {
        // var param = $.toJSON('');
        var param = $.toJSON({ LangID: 1 });
        MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(param, 'GetWeatherCountries', MHPFunc.LoadWeatherCounriesRes, MHPFunc.LoadWeatherCounriesResError)
    }
    MHPFunc.LoadWeatherCounriesRes = function(data, status) {
        // alert(data.toString());
        $.each(data, function() {
            //alert('alert');
            $(MHP.R.DropCountriesWeather).append("<option value=\"" + this['ID'] + "\">" + this['ArabicName'] + "</option>");
        });
    }
    MHPFunc.LoadWeatherCounriesResError = function(data, status) {
        //mmm alert(data);
        //CommentsEngineV3.showPrompt(CommentsListControl.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CommentsListControl.ErrorMsgGeneral);
    }
    MHPFunc.DropCountriesWeatherChange = function() {
        if ($(MHP.R.DropCountriesWeather).val() != 0) {
            var param = $.toJSON({ CountryID: $(MHP.R.DropCountriesWeather).val() });
            MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(param, 'GetWeatherCitiesByCountryID', MHPFunc.DropCountriesWeatherChangeRes, MHPFunc.DropCountriesWeatherChangeResError)
        }
    }
    MHPFunc.DropCountriesWeatherChangeRes = function(data, status) {
        $(MHP.R.DropCitiesWeather).empty();
        $(MHP.R.DropCitiesWeather).append($("<option></option>").val("0").html("اختر المدينة"));
        $.each(data, function() {
            $(MHP.R.DropCitiesWeather).append("<option value=\"" + this['ID'] + "\">" + this['ArabicName'] + "</option>");
        });
    }
    MHPFunc.DropCountriesWeatherChangeResError = function(data, status) {
        //mmm alert(data);
        //CommentsEngineV3.showPrompt(CommentsListControl.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CommentsListControl.ErrorMsgGeneral);
    }

    MHPFunc.DropCitiesWeatherChange = function(ctrl) {
        if ($(MHP.R.DropCitiesWeather).val() != 0) {
            var Version = $(ctrl).attr("version");
            var param = $.toJSON({ CityID: $(MHP.R.DropCitiesWeather).val(), version: Version });
            MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(param, 'GetCityWeather', MHPFunc.DropCitiesWeatherChangeRes, MHPFunc.DropCitiesWeatherChangeResError)
        }
    }
    MHPFunc.DropCitiesWeatherChangeRes = function(data, status) {

        $.each(data, function() {

            $(MHP.R.SpnWeatherCityName).html($(MHP.R.DropCitiesWeather + " :selected").text());
            $(MHP.R.SpnWeatherData).html(this['D0_High'] + " - " + this['D0_Low']);
            $(MHP.R.ImgWeather).attr("src", this['D0_Icon']);
            $(MHP.R.ImgWeather).attr("alt", this['D0_Condition']);
            $(MHP.R.ImgWeather).attr("title", this['D0_Condition']);
        });
        MasrawyHP.setCookie("MasrawyHPWeatherCityID", $(MHP.R.DropCitiesWeather).val(), 20, "", "", "");
    }
    MHPFunc.DropCitiesWeatherChangeResError = function(data, status) {
        //mmm alert(data);
        //CommentsEngineV3.showPrompt(CommentsListControl.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CommentsListControl.ErrorMsgGeneral);
    }
    MHPFunc.LnkShowWeatherClick = function(ctrl) {

        if (readCookie("MasrawyHPWeatherCityID") != "") {
            var CityID = readCookie("MasrawyHPWeatherCityID");
            var ad = window.open("" + MHP.R.WeatherChannelWeatherCityURL.replace('#cityid#', CityID));
            //alert(CityID);

        }
    }
    //End Weather functions

    ///////////////////PrayTimes Functions////////////////////////////////
    MHPFunc.ChangeDropCountries = function() {
        var CountryID = $(MHP.R.DropCountries).val();
        //$("#yourdropdownid option:selected").text();
        MasrawyHP.ajax.doCallbackHtml(MHP.R.PrayTimesUniqueID, "ChangeCountry~" + CountryID, MHPFunc.GetCountryCitiesRes);
        MasrawyHP.startLoader(MHP.R.DivPrayTimesContainer);
    }
    MHPFunc.GetCountryCitiesRes = function(data, status) {
        if (data.indexOf('ChangeCountry') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivPrayTimesAll).html(ResItems[1]);
                $('#loader' + MHP.R.DivPrayTimesContainer).hide();
            }
            else {
                $('#loader' + MHP.R.DivPrayTimesContainer).hide();
                //clear pray times div only
                $(MHP.R.DivPrayTimes).html('');
            }
        }
        else {
            $('#loader' + MHP.R.DivPrayTimesContainer).hide();
            $(MHP.R.DivPrayTimes).html('');
            // CommentsEngineProfileV3.showPrompt(CPV3.R.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CPV3.R.ErrorMsgGeneral);
        }
    }
    MHPFunc.ChangeDropCities = function(tid) {
        var CityId = $(MHP.R.DropCities).val();
        var CountryID = $(MHP.R.DropCountries).val();
        var CityName = $(MHP.R.DropCities + ' option:selected').text();
        MasrawyHP.startLoader(MHP.R.DivPrayTimesContainer);
        //        if (document.getElementById('<%=MoreLink.ClientID%>'))
        //            document.getElementById('<%=MoreLink.ClientID%>').href = "Emsakiya.aspx?CountryID=" + CountryId + "&CityID=" + CityId;
        MasrawyHP.ajax.doCallbackHtml(MHP.R.PrayTimesUniqueID, "ChangeCity~" + CountryID + "~" + CityId + "~" + CityName, MHPFunc.ChangeDropCitiesRes);
    }
    MHPFunc.ChangeDropCitiesRes = function(data, status) {
        if (data.indexOf('ChangeCity') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivPrayTimes).html(ResItems[1]);
                $('#loader' + MHP.R.DivPrayTimesContainer).hide();
            }
            else {
                $('#loader' + MHP.R.DivPrayTimesContainer).hide();
                $(MHP.R.DivPrayTimes).html('');
            }
        }
        else {
            $('#loader' + MHP.R.DivPrayTimesContainer).hide();
            $(MHP.R.DivPrayTimes).html('');
            //CommentsEngineProfileV3.showPrompt(CPV3.R.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CPV3.R.ErrorMsgGeneral);
        }
    }
    //////////////////////End PrayTimes Functions/////////////////////////
    /////////////////////Comments Count Functions ///////////////////////
    MHPFunc.ItemCommentsCount = function(AdAttributes, spanID, count) {
        obj = new Object();
        obj.SpanID = spanID;
        obj.Count = count;
        AdAttributes.push(obj);
    }
    MHPFunc.GetCommentsCount = function() {
        $(MHP.R.CommentsCountClass).each(function() {
            var SpanID = $(this).attr("id");
            var ItemID = $(this).attr("ItemID");
            var Category = $(this).attr("Category");
            var Portal = $(this).attr("Portal");
            //MHPFunc.GetItemCommentsCount(SpanID, ItemID, Category, Portal);
            if (SpanID != "" && SpanID) {
                var params = $.toJSON({ ControlID: SpanID, ItemID: ItemID, Category: Category, Portal: Portal });
                //MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCount', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
                if (Portal.toLowerCase() != "yallakora") {//if yallakora call old comments engine

                    //one exception here is that 3 categories needed to be checked to use old comments engine under masrawy
                    //islameyat,women, recipes
                    if (Category.toLowerCase() == "islameyat" || Category.toLowerCase() == "women" || Category.toLowerCase() == "recipes") {
                        MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCount', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
                    }
                    else {//all other masrawy categories
                        MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCountV3', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
                    }
                }
                else {

                    MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCount', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
                }
            }
        });
    }
    MHPFunc.GetItemCommentsCount = function(SpanID, ItemID, Category, Portal) {
        var isInArray = false;
        var ItemCount;
        if (MHPFunc.AdAttributes) {
            $(MHPFunc.AdAttributes).each(function(i, selected) {
                if ($(this)[0].SpanID == SpanID) {
                    isInArray = true;
                    ItemCount = $(this)[0].Count;
                }
            });

            if (isInArray) {
                MHPFunc.GetCommentsCountRes("GetCommentsCount~" + SpanID + "~" + ItemCount);
            } else {
                if (SpanID != "" && SpanID) {
                    var params = $.toJSON({ ControlID: SpanID, ItemID: ItemID, Category: Category, Portal: Portal });
                    MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCount', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
                }
            }
        }
        else {
            if (SpanID != "" && SpanID) {
                var params = $.toJSON({ ControlID: SpanID, ItemID: ItemID, Category: Category, Portal: Portal });
                MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'GetCommentsCount', MHPFunc.GetCommentsCountRes, MHPFunc.GetCommentsCountResError);
            }
        }
    }
    MHPFunc.GetCommentsCountRes = function(data, status) {
        if (data) {
            if (data.indexOf('GetCommentsCount') != -1) {
                //data:GetCommentsCount~spanid~commentcount
                var ResItems = data.split('~');
                if (ResItems.length > 2) {
                    //$('#' + ResItems[1]).html(ResItems[2]);
                    $("span[ItemID='" + ResItems[1] + "']").html(ResItems[2]);
                    //MHPFunc.ItemCommentsCount(MHPFunc.AdAttributes, ResItems[1], ResItems[2]);
                }
            }
        }
    }
    MHPFunc.GetCommentsCountResError = function(data, status) {
        //mmm alert(data);
    }
    /////////////////////End comments Count Functions ///////////////////////
    ///////////////////YKstandings Functions////////////////////////////////
    MHPFunc.ChangeDropTours = function(tid) {
        var TourId = $(MHP.R.DropTours).val();
        MasrawyHP.startLoader(MHP.R.DivStandings.replace('#', ''));
        MasrawyHP.ajax.doCallbackHtml(MHP.R.StandingsUniqueID, "ChangeTour~" + TourId, MHPFunc.ChangeDropToursRes);
    }
    MHPFunc.ChangeDropToursRes = function(data, status) {
        if (data.indexOf('ChangeTour') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivStandings).html(ResItems[1]);
                $.each($(".linkTeam"), function() {
                    this.href = this.href + $(MHP.R.DropTours).val();
                });
                $('#loader' + MHP.R.DivStandings.replace('#', '')).hide();
            }
            else {
                $('#loader' + MHP.R.DivStandings.replace('#', '')).hide();
                $(MHP.R.DivStandings).html('');
            }
        }
        else {
            $('#loader' + MHP.R.DivStandings.replace('#', '')).hide();
            $(MHP.R.DivStandings).html('');
        }
    }
    //////////////////////YKstandings Functions/////////////////////////
    ///////////////////YKTours Functions////////////////////////////////
    MHPFunc.LoadTours = function(tid) {
        MasrawyHP.startLoader(MHP.R.DivTours.replace('#', ''));
        MasrawyHP.ajax.doCallbackHtml(MHP.R.StandingsUniqueID, "LoadTours", MHPFunc.LoadToursRes);
    }
    MHPFunc.LoadToursRes = function(data, status) {
        if (data.indexOf('LoadTours') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivTours).html(ResItems[1]);
                $('#loader' + MHP.R.DivTours.replace('#', '')).hide();
                MHPFunc.ChangeDropTours();
            }
            else {
                $('#loader' + MHP.R.DivTours.replace('#', '')).hide();
                $(MHP.R.DivTours).html('');
            }
        }
        else {
            $('#loader' + MHP.R.DivTours.replace('#', '')).hide();
            $(MHP.R.DivTours).html('');
        }
    }
    //////////////////////YKTours Functions/////////////////////////
    ///////////////////YKMatchesTours Functions////////////////////////////////
    MHPFunc.LoadMatchesTours = function(tid) {
        MasrawyHP.startLoader(MHP.R.DivTourMatches.replace('#', ''));
        MasrawyHP.ajax.doCallbackHtml(MHP.R.MatchesUniqueID, "LoadMatchesTours", MHPFunc.LoadMatchesToursRes);
    }
    MHPFunc.LoadMatchesToursRes = function(data, status) {
        if (data.indexOf('LoadMatchesTours') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivTourMatches).html(ResItems[1]);
                $('#loader' + MHP.R.DivTourMatches.replace('#', '')).hide();
                RenderMatches("#today", 1, gmt, GetLangId());
            }
            else {
                $('#loader' + MHP.R.DivTourMatches.replace('#', '')).hide();
                $(MHP.R.DivTourMatches).html('');
            }
        }
        else {
            $('#loader' + MHP.R.DivTourMatches.replace('#', '')).hide();
            $(MHP.R.DivTourMatches).html('');
        }
    }
    //////////////////////YKMatchesTours Functions/////////////////////////

    MHPFunc.GetAlbums = function() {
        if ($('#divAlbums').children().children().length < 5) {
            MasrawyHP.startLoader('music');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.MusicUniqueID, "GetAlbums", MHPFunc.SetMusicData);
        }
    }
    MHPFunc.GetMovies = function() {
        if ($('#divMovies').children().length < 5) {
            MasrawyHP.startLoader('music');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.MusicUniqueID, "GetMovies", MHPFunc.SetMusicData);
        }
    }
    MHPFunc.GetSongs = function() {
        if ($('#divSongs').children().length < 5) {
            MasrawyHP.startLoader('music');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.MusicUniqueID, "GetSongs", MHPFunc.SetMusicData);
        }
    }
    MHPFunc.SetMusicData = function(result, status) {

        if (result.indexOf('SetAlbums') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#divAlbums').html(ResItems[1]);
                $('#loadermusic').hide();
            }
            else {
                $('#loadermusic').hide();
                $('#divAlbums').html('');
            }
        }
        else
            if (result.indexOf('SetMovies') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#divMovies').html(ResItems[1]);
                $('#loadermusic').hide();
            }
            else {
                $('#loadermusic').hide();
                $('#divMovies').html('');
            }
        }
        else
            if (result.indexOf('SetSongs') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#divSongs').html(ResItems[1]);
                $('#loadermusic').hide();
            }
            else {
                $('#loadermusic').hide();
                $('#divSongs').html('');
            }
        }
    }
    //////////////////////TabsUpdateViews Functions/////////////////////////
    MHPFunc.PageTabClick = function() {
        var TabID = $(this).attr('tabid');
        if (TabID) {
            MHPFunc.TabsUpdateViews(TabID);
        }
    }
    MHPFunc.TabsUpdateViews = function(TabID) {
        var params = $.toJSON({ TabID: TabID });
        MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(params, 'TabsUpdateViews', MHPFunc.TabsUpdateViewsRes, MHPFunc.TabsUpdateViewsResError);
    }
    MHPFunc.TabsUpdateViewsRes = function(data, status) {
        if (data) {
            if (data.indexOf('TabsUpdateViews') != -1) {
                //data:TabsUpdateViews~resint
                var ResItems = data.split('~');
            }
        }
    }
    MHPFunc.TabsUpdateViewsResError = function(data, status) {
        //mmm alert(data);
    }
    //////////////////////End TabsUpdateViews Functions/////////////////////////
    ////////////////// KPT Functions //////////////////////////////////
    MHPFunc.GetUserNews = function() {
        if ($(MHP.R.DivUserNews).children().children().length < 5) {
            //MasrawyHP.startLoader('kpt');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.KPTUniqueID, "GetUserNews", MHPFunc.GetUserNewsRes);
        }
    }
    MHPFunc.GetUserNewsRes = function(result, status) {
        if (result.indexOf('GetUserNews') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivUserNews).html(ResItems[1]);
                MHPFunc.HandleUNTime();
                //$('#loaderkpt').hide();
                ///////
                //                $(function() {
                //                    var maxHeight = 0;
                //                    $('.tt').each(function() {
                //                        if (maxHeight < $(this).height())
                //                        { maxHeight = $(this).height() }
                //                    });
                //                    $('.tt').each(function() {
                //                        if ($(this).height() > 60) {
                //                            $(this).height(maxHeight);
                //                        }
                //                    });
                //                });
                /////////////
            }
            else {
                //$('#loaderkpt').hide();
                $(MHP.R.DivUserNews).html('');
            }
        }
        $(MHP.R.drpNews).change(function() {
            MHPFunc.DropKPTchanges(2);
        });
    }
    MHPFunc.GetUserArticles = function() {
        if ($(MHP.R.DivUserArticles).children().children().length < 5) {
            //MasrawyHP.startLoader('kpt');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.KPTUniqueID, "GetUserArticles", MHPFunc.GetUserArticlesRes);
        }
    }
    MHPFunc.GetUserArticlesRes = function(result, status) {
        if (result.indexOf('GetUserArticles') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $(MHP.R.DivUserArticles).html(ResItems[1]);
                MHPFunc.HandleUATime();
                //$('#loaderkpt').hide();
                ///////
                //                $(function() {
                //                    var maxHeight = 0;
                //                    $('.tt').each(function() {
                //                        if (maxHeight < $(this).height())
                //                        { maxHeight = $(this).height() }
                //                    });
                //                    $('.tt').each(function() {
                //                        if ($(this).height() > 60) {
                //                            $(this).height(maxHeight);
                //                        }
                //                    });
                //                });
                /////////////
            }
            else {
                //$('#loaderkpt').hide();
                $(MHP.R.DivUserArticles).html('');
            }
        }
        $(MHP.R.drpPosts).change(function() {
            MHPFunc.DropKPTchanges(1);
        });
    }
    MHPFunc.DropKPTchanges = function(type) {
        if (type == 1) {
            if ($(MHP.R.drpPosts).val() != 0) {
                window.location = 'http://www.masrawy.com/ketabat/Category.aspx?catid=' + $(MHP.R.drpPosts).val();
            }
        }
        else {
            if ($(MHP.R.drpNews).val() != 0) {
                window.location = 'http://www.masrawy.com/moraselon/Category.aspx?catid=' + $(MHP.R.drpNews).val();
            }
        }
    }
    MHPFunc.HandleUATime = function() {
        $('.sinceUA').each(function() {
            var vTime = $(this).html();
            vTime = vTime.replace('ص', 'AM').replace('م', 'PM');
            vTime = new Date(vTime.replace(new RegExp('-', 'g'), '/'));
            $(this).html(getStrDate(vTime));
        });
    }
    MHPFunc.HandleUNTime = function() {
        $('.sinceUN').each(function() {
            var vTime = $(this).html();
            vTime = vTime.replace('ص', 'AM').replace('م', 'PM');
            vTime = new Date(vTime.replace(new RegExp('-', 'g'), '/'));
            $(this).html(getStrDate(vTime));
        });
    }
    ////////////////////End KPT Functions //////////////////////////////
    ////////////////////////SSO LogIn PopUp /////////////////////////
    MHPFunc.ShowLogInDiv = function() {
        $('#DivMsg').addClass("hide");
        $('#TxtUserName').val('');
        $('#TxtPassword').val('');
        $("#SSOLogIn").dialog({
            modal: true,
            draggable: false,
            resizable: false,
            title: "تسجيل الدخول",
            overlay: { opacity: "0.5", background: "#dfdfdf" }
        });
    }
    MHPFunc.SendLogInRequest = function() {

        if (MHPFunc.ValidateSSOLogIn()) {
            MasrawyHP.ajax.doCallbackHtml(MHP.R.MasterUniqueID, $('#TxtUserName').val() + "~" + $('#TxtPassword').val(), MHPFunc.SendLogInRes);
        }
    }
    MHPFunc.SendLogInRes = function(result, status) {
        if (result == "1")//Success
        {
            location.reload(true);
        }
        else { //log in failed
            $('#DivMsg').removeClass('hide');
        }
    }
    MHPFunc.ValidateSSOLogIn = function() {
        if (!MasrawyHP.validation.isEmpty($('#TxtUserName')[0]) && !MasrawyHP.validation.isEmpty($('#TxtPassword')[0])) {
            return true;
        }
        else { return false; }
    }
    MHPFunc.WriteDomain = function() {
        var uname = $('#TxtUserName').val();
        var domain = '@masrawy.com';
        if (uname != '' && uname.indexOf('@') == -1) {
            $('#TxtUserName').val(uname + domain);
            $('#TxtUserName').focus();
        }
    }
    //////////////////////////////////////End SSO LogIn PopUp/////////////////////////
    //////////////////////////////////////Tridion Clips Ajax/////////////////////////
    MHPFunc.AttachTridionCicksEvents = function() {
        //Women
        $('#tab1').click(function() { MHPFunc.getTridionClipData('WomenXML.aspx', '#tab-13', MHPFunc.womenNewsRes, MHPFunc.womenNewsResError) });
        $('#tab2').click(function() { MHPFunc.getTridionClipData('RecipesXML.aspx', '#tab-14', MHPFunc.recipesRes, MHPFunc.recipesResError) });
        $('#tab3').click(function() { MHPFunc.getTridionClipData('HealthXML.aspx', '#tab-15', MHPFunc.healthRes, MHPFunc.healthResError) });
        //Media
        //$('#tab4').click(function() { MHPFunc.getTridionClipData('NewsVideosXML.aspx', '#NewsVideos', MHPFunc.newsVideosRes, MHPFunc.newsVideosResError) });
        //$('#tab6').click(function() { MHPFunc.getTridionClipData('CaricatureXML.aspx', '#tab-6', MHPFunc.CaricatureRes, MHPFunc.CaricatureResError) });
        //Funny
        //        $('#tab28').click(function() { MHPFunc.getTridionClipData('VideosXML.aspx', '#videos', MHPFunc.videosRes, MHPFunc.videosResError) });
        //        $('#tab29').click(function() { MHPFunc.getTridionClipData('FunnyXML.aspx', '#tab-29', MHPFunc.JokesRes, MHPFunc.JokesResError) });
        //
        //Islamic
        $('#tab10').click(function() { MHPFunc.getTridionClipData('IslamicXML.aspx', '#tab-10', MHPFunc.IslamicNewsRes, MHPFunc.IslamicNewsResError) });
        $('#tab12').click(function() { MHPFunc.getTridionClipData('FatawaXML.aspx', '#tab-12', MHPFunc.FatawaRes, MHPFunc.FatawaResError) });
        //SportsNews
        ///sportsyk $('#tab41').click(function() { MHPFunc.getTridionClipData('SportsNewsXML.aspx', '#tab-41', MHPFunc.SportsNewsRes, MHPFunc.SportsNewsResError) });
        //$('#tab41').click(function() { MHPFunc.GetSportsWCNews(); });
        $('#tab41').click(function() { MHPFunc.GetSportsNewsYKFeed(); });

    }
    MHPFunc.getTridionClipData = function(pageName, divName, callbackFunction, callbackErrorFunction) {
        //divName: is the name of the div to check if it contains data or not.
        //alert(divName=" "+ $(divName).length);
        if ($(divName).length == 0) {
            MasrawyHP.services.AjaxMethods.AjaxPagesCaller(pageName, callbackFunction, callbackErrorFunction);
        }
    }
    ////////////////////////////YK Sports News ////////////////////////////////////////////
    MHPFunc.GetSportsNewsYKFeed = function() {
        //$(divName).length
        if ($("#tab-41").children().children().length < 5) {
            MasrawyHP.ajax.doCallbackHtml(MHP.R.SportNewsYKFeedUniqueID, "GetSportNewsYKFeed", MHPFunc.GetSportsNewsYKFeedRes);
        }
    }
    MHPFunc.GetSportsNewsYKFeedRes = function(result, status) {
        if (result.indexOf('GetSportNewsYKFeed') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#tab-41').html(ResItems[1]);

            }
            else {
                $('#tab-41').html('لا يوجد محتوى للعرض الأن');
            }
        }
    }
    //////////////////////////// End WC News ////////////////////////////////////////////
    //////////////////////////// WC News ////////////////////////////////////////////
    MHPFunc.GetSportsWCNews = function() {
        //$(divName).length
        if ($("#tab-41").children().children().length < 5) {
            //MasrawyHP.startLoader('kpt');
            MasrawyHP.ajax.doCallbackHtml(MHP.R.WCSportNewsUniqueID, "GetSportNewsWC", MHPFunc.GetSportsWCNewsRes);
        }
    }
    MHPFunc.GetSportsWCNewsRes = function(result, status) {
        if (result.indexOf('GetSportNewsWC') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#tab-41').html(ResItems[1]);

            }
            else {
                $('#tab-41').html('لا يوجد محتوى للعرض الأن');
            }
        }
    }
    //////////////////////////// End WC News ////////////////////////////////////////////
    //////////////////////////// OnTvRamadan program and video //////////////////////////
    MHPFunc.GetOnTvProgramVideo = function() {
        MasrawyHP.ajax.doCallbackHtml(MHP.R.OnTvRamadanUniqueID, "GetOnTvProgramVideo", MHPFunc.GetOnTvProgramVideoRss);
    }

    MHPFunc.GetOnTvProgramVideoRss = function(result, status) {
        if (result.indexOf('GetOnTvProgramVideo') != -1) {
            var ResItems = result.split('~');
            if (ResItems.length > 1) {
                $('#OnTvProgramVideo').html(ResItems[1]);
            }
            else {
                $('#OnTvProgramVideo').html('لا يوجد محتوى للعرض الأن');

            }
        }
    }


    //////////////////////////// End OnTvRamadan program and video //////////////////////

    ///////Women Clip//////////////////////////
    /////women News
    MHPFunc.womenNewsRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div>" + "<span class='coom'> <span class='commentcount' id='Span1' ItemID='" + $(this).find('ArticleID').text() + "' Category='" + $(this).find('ArticleCategory').text() + "' Portal='" + $(this).find('ArticlePortal').text() + "'></span></span><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += '<li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-13'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a class='morbtn' href='http://www.masrawy.com/women/default.aspx?ref=NewHPClip'>المزيد من أخبار المرأه</a></li><li class='lef'></li></ul></div>";
            //tempHtmlFinal = '<div id="tab-10" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/women/default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من أخبار المرأه</a></div>';
            $('#women').removeAttr("style");
            $('#women').append(tempHtmlFinal);
            MHPFunc.AdjustClipHeight('womenislamic');
            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }
        }
    }
    MHPFunc.womenNewsResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-13'>لا يوجد محتوى للعرض الأن</div>";
        $('#women').append(tempHtml);
    }
    //end women News
    //recipes
    MHPFunc.recipesRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div>" + "<span class='coom'><span class='commentcount' id='Span1' ItemID='" + $(this).find('ArticleID').text() + "' Category='" + $(this).find('ArticleCategory').text() + "' Portal='" + $(this).find('ArticlePortal').text() + "'></span></span><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += ' <li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-14'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a class='morbtn' href='http://www.masrawy.com/recipes/default.aspx?ref=NewHPClip'>المزيد من  الوصفات</a></li><li class='lef'></li></ul></div>";
            //tempHtmlFinal = '<div id="tab-11" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/recipes/default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من  الوصفات</a></div>';
            $('#women').removeAttr("style");
            $('#women').append(tempHtmlFinal);
            MHPFunc.AdjustClipHeight('womenislamic');
            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }
        }
    }
    MHPFunc.recipesResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-14'>لا يوجد محتوى للعرض الأن</div>";
        $('#women').append(tempHtml);
    }
    //End recipes
    //health
    MHPFunc.healthRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div><span class='coom'> <span class='commentcount' id='Span1' ItemID='" + $(this).find('ArticleID').text() + "' Category='" + $(this).find('ArticleCategory').text() + "' Portal='" + $(this).find('ArticlePortal').text() + "'></span></span><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += '<li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-15'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a class='morbtn' href='http://www.masrawy.com/women/Health/Default.aspx?ref=NewHPClip'>المزيد من أخبار الصحة</a></li><li class='lef'></li></ul></div>";
            //tempHtmlFinal = '<div id="tabHealth" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/women/Health/Default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من أخبار الصحة</a></div>';
            $('#women').removeAttr("style");
            $('#women').append(tempHtmlFinal);
            MHPFunc.AdjustClipHeight('womenislamic');
            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }
        }
    }
    MHPFunc.healthResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-15'>لا يوجد محتوى للعرض الأن</div>";
        $('#women').append(tempHtml);
    }
    //End health
    ///////End Women Clip//////////////////////////
    ///////Media Clip//////////////////////////
    /////newsVideos
    MHPFunc.newsVideosRes = function(data, status) {
        if (data) {
            var tempHtml = "";
            $(data).find("item").each(function(index) {
                tempHtml += '<a class="ply" href="' + $(this).find("link").text() + '"><img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("title").text() + '" title="' + $(this).find("Caption").text() + '" width="280" hight="180"> <img class="plyico" src="images/plyico.png"><span>' + $(this).find("Caption").text() + '</span></a>'
                index = index + 1;
            });
            tempHtml = '<div id="NewsVideos">' + tempHtml + '</div>';
            $('#tab-4').prepend(tempHtml);
        }
    }
    MHPFunc.newsVideosResError = function(data, status) {
    }
    /////End newsVideos
    /////Caricature
    MHPFunc.CaricatureRes = function(data, status) {
        if (data) {
            var tempHtml = "";
            var tempHtmlSec = "";

            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtml += '<a href="' + $(this).find("link").text() + '" title="' + $(this).find("Caption").text() + '"><img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("title").text() + '" title="' + $(this).find("Caption").text() + '"></a><div class="clr"></div>'
                }
                else {
                    tempHtmlSec += '<a href=' + $(this).find("link").text() + ' class="ply b"><img height="80" width="110" src=' + $(this).find("Thumb").text() + ' alt=' + $(this).find("Caption").text() + 'class="vidimg"></a>';
                }
                index = index + 1;
            });
            //alert("CaricatureRes" + index);
            tempHtmlSec = '<div class="g2">' + tempHtmlSec + '<div class="clr"></div><a href="http://www.masrawy.com/Jokes/Caricature/caricature_archive.aspx" class="morbtn">المزيد من الكاريكاتير</a> <a href="http://www.masrawy.com/Jokes/Caricature/caricature_send2us.aspx" class="morbtn">أضف كاريكاتير</a></div>';
            tempHtml = tempHtml + tempHtmlSec;
            tempHtml = '<div id="tab-6" class="clipcn">' + tempHtml + '</div>';
            $('#media').append(tempHtml);
        }
    }
    MHPFunc.CaricatureResError = function(data, status) {
        var tempHtml = "";
        tempHtml = '<div id="tab-6" class="clipcn height2">لا يوجد محتوى للعرض الأن</div>';
        $('#media').append(tempHtml);
    }
    /////End Caricature
    ///////End Media Clip//////////////////////////
    ///////Funny Clip//////////////////////////
    /////Videos
    MHPFunc.videosRes = function(data, status) {
        if (data) {
            var tempHtml = '';
            //alert("video res");
            $(data).find("item").each(function(index) {

                tempHtml += '<a class="ply" href="' + $(this).find("link").text() + '"><img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("title").text() + '" title="' + $(this).find("Caption").text() + '" width="280" hight="180"> <img class="plyico" src="images/plyico.png"><span>' + $(this).find("Caption").text() + '</span></a>';
                index = index + 1;
            });
            tempHtml = '<a href="http://videohat.masrawy.com/upload.php?ref=HpClip" class="morbtn"><span>حمل فيديوهاتك </span><span class="addb"> </span></a><div class="clr"></div><div id="videos">' + tempHtml + '</div>';
            $('#tab-28').prepend(tempHtml);
        }
    }
    MHPFunc.videosResError = function(data, status) {
    }
    /////End Videos
    /////Jokes
    MHPFunc.JokesRes = function(data, status) {
        if (data) {
            var tempHtml = "";
            $(data).find("item").each(function(index) {
                tempHtml += '<h3><a href="http://www.masrawy.com/jokes/" title="تعليقات ساخرة">نكتة اليوم</a></h3><p>' + $(this).find("description").text() + '</p><ul class="ulbtn"><li class="rig"></li><li class="mid"><a class="morbtn" href="http://www.masrawy.com/jokes/Home_Send_Us.aspx?ref=NewHP">إرسل نكتة</a></li><li class="lef"></li></ul><ul class="ulbtn"><li class="rig"></li><li class="mid"><a href="http://www.masrawy.com/jokes/default.aspx?ref=HPClipMore" class="morbtn">المزيد</a></li><li class="lef"></li></ul><br /><br /><ul class="lin"><li class="csp"></li><li><a href="http://www.masrawy.com/jokes/nokat/default.aspx?ref=NewHP">نكت على زوقك</a></li><li class="csp"></li><li><a href="http://www.masrawy.com/Jokes/Micha/micha.aspx?ref=NewHP">ميكانيكى مصراوي</a></li><li class="csp"></li><li><a href="http://www.masrawy.com/jokes/What/default.aspx?ref=NewHP">فزورة فى صورة</a></li><li class="csp"></li><li><a href="http://www.masrawy.com/jokes/Best_Comment/default.aspx?ref=NewHP">أطرف تعليق</a></li><li class="csp"></li></ul>';
                index = index + 1;
            });
            tempHtml = '<div id="tab-29" class="clipcn">' + tempHtml + '</div>';
            $('#funny').append(tempHtml);
        }
    }
    MHPFunc.JokesResError = function(data, status) {
        var tempHtml = "";
        tempHtml = '<div id="tab-29" class="clipcn height2">لا يوجد محتوى للعرض الأن</div>';
        $('#funny').append(tempHtml);
    }
    /////End Caricature
    ///////End Funny Clip//////////////////////////
    ///////Islamic Clip//////////////////////////
    /////Islamic News
    MHPFunc.IslamicNewsRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            var divheightbefore = $('#islamic').height() + "  - " + $('#women').height();
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div><span class='coom'><span class='commentcount' id='Span1' ItemID='" + $(this).find('ArticleID').text() + "' Category='" + $(this).find('ArticleCategory').text() + "' Portal='" + $(this).find('ArticlePortal').text() + "'></span></span><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += '<li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-10'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a class='morbtn' href='http://www.masrawy.com/islameyat/?ref=NewHP'>المزيد من مقالات أسلامية</a></li><li class='lef'></li></ul></div>";
            //tempHtmlFinal = '<div id="tab-10" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/women/default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من أخبار المرأه</a></div>';

            //mmm $('#islamic').removeAttr("style");
            $('#islamic').removeAttr("style");
            $('#islamic').append(tempHtmlFinal);
            //mmm alert("islamic: " + $('#islamic').height());
            //alert("all before : " + divheightbefore + " ,after: " + $('#islamic').height() + " - " + $('#women').height());
            MHPFunc.AdjustClipHeight('womenislamic');
            //alert("all before : " + divheightbefore + " ,after: " + $('#islamic').height() + " - " + $('#women').height());
            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }
        }
    }
    MHPFunc.IslamicNewsResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-10'>لا يوجد محتوى للعرض الأن</div>";
        $('#islamic').append(tempHtml);
    }
    //end Islamic News
    //Fatawa
    MHPFunc.FatawaRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            var divheightbefore = $('#islamic').height() + "  - " + $('#women').height();
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += '<li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-12'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a class='morbtn' href='http://www.masrawy.com/islameyat/listing.aspx?id=fatawamo3amlat&ref=NewHP'>المزيد من الفتاوى</a></li><li class='lef'></li></ul></div>";
            //tempHtmlFinal = '<div id="tab-10" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/women/default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من أخبار المرأه</a></div>';
            $('#islamic').removeAttr("style");
            $('#islamic').append(tempHtmlFinal);
            //alert("all before : " + divheightbefore + " ,after: " + $('#islamic').height() + " - " + $('#women').height());
            MHPFunc.AdjustClipHeight('womenislamic');
            //alert("all before : " + divheightbefore + " ,after: " + $('#islamic').height() + " - " + $('#women').height());

            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }

        }
    }
    MHPFunc.FatawaResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-12'>لا يوجد محتوى للعرض الأن</div>";
        $('#islamic').append(tempHtml);
    }
    //End Fatawa
    ///////End Islamic Clip//////////////////////////
    MHPFunc.SportsNewsRes = function(data, status) {
        if (data) {
            var tempHtmlHead = "";
            var tempHtml = "";
            var tempHtmlFinal = "";
            var ItemID = "";
            var Category = "";
            var Portal = "";
            $(data).find("item").each(function(index) {
                if (index == 0) {
                    tempHtmlHead += "<div class='linkfx2'><a class='ctitle' href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></div><span class='coom'><span class='commentcount' id='Span1' ItemID='" + $(this).find('ArticleID').text() + "' Category='" + $(this).find('ArticleCategory').text() + "' Portal='" + $(this).find('ArticlePortal').text() + "'></span></span><div class='clear'></div><div class='newsSummary'><a href='" + $(this).find("link").text() + "'><img height=67 width=100 src='" + $(this).find("Thumb").text() + "' alt='" + $(this).find("title").text() + "'></a>" + $(this).find("mainstatus").text() + "<p>" + $(this).find("description").text() + " <a href='" + $(this).find("link").text() + "'>المزيد »</a></p></div><div class='clear'></div>";
                    //tempHtmlHead += '<img src="' + $(this).find("Thumb").text() + '" alt="' + $(this).find("Caption").text() + '" title="مكياج صيفي" class="mainimg" width="112" hight="170"> <div class="main"><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a> <span class="coom"> <span class="commentcount" id="Span1" ItemID="' + $(this).find("ArticleID").text() + '" Category="' + $(this).find("ArticleCategory").text() + '" Portal="' + $(this).find("ArticlePortal").text() + '"></span> <span>تعليق</span></span>' + $(this).find("mainstatus").text() + '<p>' + $(this).find("description").text() + '<a href="' + $(this).find("link").text() + '">المزيد</a></p></div><div class="sp"></div>';
                    ItemID = $(this).find("ArticleID").text(); Category = $(this).find("ArticleCategory").text(); Portal = $(this).find("ArticlePortal").text();
                } else {
                    tempHtml += "<li><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a>" + $(this).find("mainstatus").text() + "</li>"
                    //tempHtml += '<li><a href="' + $(this).find("link").text() + '">' + $(this).find("title").text() + '</a>' + $(this).find("mainstatus").text() + '</li><li class="csp"></li>';
                }
                if (index == 4) return false;
            });
            tempHtmlFinal = "<div id='tab-41'>" + tempHtmlHead + "<ul class='mornews'>" + tempHtml + "</ul><ul class='ulbtn'><li class='rig'></li><li class='mid'><a href='http://masrawy.yallakora.com/arabic/default.aspx?region=&ref=NewHPClip' class='morbtn'>المزيد من أخبار الرياضة</a></li><li class='lef'></li></ul><div class='clear'></div></div>";
            //tempHtmlFinal = '<div id="tab-10" class="clipcn height2">' + tempHtmlHead + ' <ul class="lin">' + tempHtml + '</ul><a href="http://www.masrawy.com/women/default.aspx?ref=NewHPClip" class="linkmor">&#8249;&#8249; المزيد من أخبار المرأه</a></div>';
            $('#sports').append(tempHtmlFinal);
            //get comments count for headline clip
            if (ItemID && Category && Portal) {
                MHPFunc.GetItemCommentsCount(ItemID, ItemID, Category, Portal);
            }
        }
    }
    MHPFunc.SportsNewsResError = function(data, status) {
        var tempHtml = "";
        tempHtml = "<div id='tab-41'>لا يوجد محتوى للعرض الأن</div>";
        $('#sports').append(tempHtml);
    }

    //////////////////////////////////////End Tridion Clips Ajax/////////////////////////
    //////////////////////////////////Poll social sharing //////////////////////////////
    MHPFunc.HandlePollSocailLinks = function() {
        $(MHP.R.lnkFbPollshare).attr('href', MHPFunc.getSocailURL(1));
        $(MHP.R.lnkTwPollshare).attr('href', MHPFunc.getSocailURL(2));
    }
    MHPFunc.getSharingURL = function(type) {
        if (type == 1)//facebook
        {
            return $('#lnkPreviousPolls').attr('href') + escape('&popupurl=') + escape(MHP.R.pollDetailsPageUrl.replace("?", "---").replace("#pollid#", $(MHP.R.hidPollID).val()).replace("#portalname#", $(MHP.R.hidSiteName).val()).replace("#langname#", $(MHP.R.hidLang).val()) + "&title=" + escape(jQuery.trim($(MHP.R.pollQuestion).html())));
        }
        else {
            return $('#lnkPreviousPolls').attr('href') + escape('&popupurl=') + escape(MHP.R.pollDetailsPageUrl.replace("?", "---").replace("#pollid#", $(MHP.R.hidPollID).val()).replace("#portalname#", $(MHP.R.hidSiteName).val()).replace("#langname#", $(MHP.R.hidLang).val())); //+ "&title=" + escape(jQuery.trim($(MHP.R.pollQuestion).html())));
        }
    }
    MHPFunc.getSocailURL = function(type) {
        if (type == 1)//facebook
            return 'http://www.facebook.com/share.php?u=' + MHPFunc.getSharingURL(type) + '&t=' + jQuery.trim($(MHP.R.pollQuestion).html());
        else if (type == 2) {//twitter
            return 'http://twitter.com/share?url=' + MHPFunc.getSharingURL(type) + '&text=' + jQuery.trim($(MHP.R.pollQuestion).html()) + '&via=Masrawy';
        }
    }
    //////////////////////////End Poll social sharing///////////////////////
    /////////////////////////Top Date //////////////////////////////////////
    MHPFunc.getTopData = function() {
        //MasrawyHP.startLoader('article');
        MasrawyHP.ajax.doCallbackHtml(MHP.R.TopViewedUniqueID, "getTopData", MHPFunc.getTopDataRes);
    }
    MHPFunc.getTopDataRes = function(data, status) {
        if (data.indexOf('getTopData') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $('#TopViewed').html(ResItems[1]);
                //$('#loaderarticle').hide();
                //mmm MHPFunc.AdjustClipHeight('mostdata');

            }
            else {
                //$('#loaderarticle').hide();
                $('#TopViewed').html('');
            }
        }
        else {
            // $('#loaderarticle').hide();
            $('#TopViewed').html('');
        }
    }
    /////////////////////////End Top Data //////////////////////////////////
    /////////////////////////Top Commented //////////////////////////////////////
    MHPFunc.getCommentedData = function() {
        //MasrawyHP.startLoader('article');
        MasrawyHP.ajax.doCallbackHtml(MHP.R.TopCommentedUniqueID, "getCommentedData", MHPFunc.getCommentedDataRes);
    }
    MHPFunc.getCommentedDataRes = function(data, status) {
        if (data.indexOf('getCommentedData') != -1) {
            var ResItems = data.split('~');
            if (ResItems.length > 1) {
                $('#TopCommented').html(ResItems[1]);
                //$('#loaderarticle').hide();
                //mmm MHPFunc.AdjustClipHeight('mostdata');

            }
            else {
                //$('#loaderarticle').hide();
                $('#TopCommented').html('');
            }
        }
        else {
            // $('#loaderarticle').hide();
            $('#TopCommented').html('');
        }
    }
    /////////////////////////End Top Commented//////////////////////////////////
    MHPFunc.AdjustClipHeight = function(calssName) {
        var maxHeight = 0;
        //alert(calssName);
        $('.' + calssName).each(function() {
            if (maxHeight < $(this).height()) {
                // alert(maxHeight + "  " + $(this).height());
                maxHeight = $(this).height();
            }
        });
        $('.' + calssName).each(function() {
            $(this).height(maxHeight);
        });
    }
    MHPFunc.GetInternetCount = function() {
        $.ajaxSetup({
            contentType: "application/json; charset=utf-8"
        });
        $.ajax({
            type: "Post",
            url: "AjaxMethods/AjaxMethodsV2.asmx/GetInterCount",
            // contentType: "application/json; charset=utf-8",
            complete: function(msg) {
                //alert(msg.responseText.substr(msg.responseText.indexOf('/">') + 3, msg.responseText.indexOf('</string>') - (msg.responseText.indexOf('/">') + 3)));
                $('#spncompaincount').html(msg.responseText.substr(msg.responseText.indexOf('/">') + 3, msg.responseText.indexOf('</string>') - (msg.responseText.indexOf('/">') + 3)))
            }, dataType: "application/json"
        });
    }
    MHPFunc.GetInternetCount2 = function() {
        var param = $.toJSON({ id: 1 });
        MasrawyHP.services.AjaxMethods.AjaxMethodsCaller(param, 'GetInterCount', MHPFunc.GetInternetCount2Res, MHPFunc.GetInternetCount2ResError)

    }
    MHPFunc.GetInternetCount2Res = function(data, status) {
        $('#spncompaincount').html(data);
        //alert(data);

    }
    MHPFunc.GetInternetCount2ResError = function(data, status) {
        //mmm alert(data);
        //CommentsEngineV3.showPrompt(CommentsListControl.ErrorTitle, 'PromptOk', 'Pprompt', null, null, 0.5, CommentsListControl.ErrorMsgGeneral);
    }
    MHPFunc.HandleHPLink = function() {
        if (window.location.toString().toLowerCase().indexOf('aspx') == -1) {
            //no aspx so mean on root
            $($(".hselect").find("a")).removeAttr("href");
        }
        else {//contains
            if (window.location.toString().toLowerCase().indexOf('default.aspx') > -1) {
                $($(".hselect").find("a")).removeAttr("href");
            }
        }
    }
})();
