﻿/// <summary>
///     Product:        Enewspaper
///     Classname:    	Java Script
///     Version:        02.02 
///     Programmer:     Elham Esmaieli 
///     Purpose: 
///         All required JS to make HTML page dynamic.
/// 
///     Copyright 2009 by Digital Secure Co. All Rights Reserved. 
/// </summary>
/// <IsMultiEdition>True</IsMultiEdition>
/// <classVersion>002</classVersion>
/// <EditingHistory>
///     Name:       Elham
///     Date:       13 September, 2009
///     Reason of change :
///         Craeting file.
/// </EditingHistory>


var panState = ''; //Keeps div id of opened sub title pan
var LastNewsContent = '0'; //A global variable to always keeps last news content id

/* -------Global Functions------------  */
//This function returns an object by id
function getObj(id) {
    return document.getElementById(id);
}

//This function changes the background image of next and previous buttons
function buttonBgOverOut(imgId, imgSrc) {
    getObj(imgId).src = 'url(' + imgSrc + ')';
}

//This function make highlight btn during mouse over
function buttonImgOverOut(imgId, imgSrc) {
    getObj(imgId).src = imgSrc;
}

//This function change class name
function changeClass(objId, objClass) {
    getObj(objId).className = objClass;
}

//This function make Dispaly block
function displayBlock(objId) {
    document.getElementById(objId).style.display = 'block';
}

//This function make Dispaly none
function displayNone(objId) {
    document.getElementById(objId).style.display = 'none';
}

//This function gets object id and makes an array of all tagName which choosed
function getRootObj(item, tagName) {
    if (typeof (item) == "string") {
        if (getObj(item) != null)
            return getObj(item).getElementsByTagName(tagName);
        else
            return null;
    }
    else {
        if (item.getElementsByTagName != null) {
            return item.getElementsByTagName(tagName);
        }
        else {
            return null;
        }
    }
}

//This function hides all news content Div
function hideAllContentDiv() {
    var items = getRootObj("allContent", "div");
    for (var i = 0; i < items.length; i++) {
        getObj(items[i].id).style.display = 'none';
    }
}

//This function make highlight pagging number by clicking
function changePageNumber() {
    var len = getObj('pageNumberHolder').childNodes.length;
    for (var i = 0; i < len; i++) {
        if (getObj('pageNumberHolder').childNodes.item(i).className == 'paggNumberingHolderSelected white') {
            getObj('pageNumberHolder').childNodes.item(i).className = 'paggNumberingHolder black';
            break;
        }
    }
}

//This function creat next pagging button in both conditions, disabled or enabled
function putNextPagging(nextParam, src) {
    if (nextPageURL == '') {
        getObj('next').innerHTML += '<img src="' + src + 'images/pagging/asia_nextDis.gif" width="26" height="95" class="pointer" alt="صفحه بعدي" title="صفحه بعدي" />';
    }
    else {
        getObj('next').innerHTML += '<img src="' + src + 'images/pagging/asia_next.gif" width="26" height="95" class="pointer" alt="صفحه بعدي" title="صفحه بعدي" onclick="goUrl(\'' + nextParam + '\');" />';
    }
}

//This function creat previous pagging button in both conditions, disabled or enabled
function putPrevPagging(prevParam, resource) {
    if (prevParam == '') {
        getObj('prev').innerHTML += '<img src="' + resource + 'images/pagging/asia_prevDis.gif" width="26" height="95" class="pointer" alt="صفحه قبلي" title="صفحه قبلي" />';


    }
    else {
        getObj('prev').innerHTML += '<img src="' + resource + 'images/pagging/asia_prev.gif" width="26" height="95" class="pointer" alt="صفحه قبلي" title="صفحه قبلي" onclick="goUrl(\'' + prevParam + '\');" />';
    }
}

//This function set the height of all effected element height by newspaper image height
function setAllHeightyImageSize(imgH) {
    if (imgH > 780) {
        var d = (parseInt(imgH)) - 780;
        
        getObj('mapDivHolder').style.height = (imgH) + 'px';
        getObj('mapNewsPaperHolder').style.height = (imgH) + 'px';
        getObj('mainBodyPageBodyL').style.height = (1030 + d) + 'px';
        getObj('mainBodyPageBody').style.height = (1061 + d) + 'px';
        getObj('mainBodyInner').style.height = (1204 + d) + 'px';
        getObj('mainBodyBgR').style.height = (1240 + d) + 'px';
        getObj('mainBodyBgBotR').style.height = (1240 + d) + 'px';
        getObj('mainBodyHolder').style.height = (1240 + d) + 'px';
        //getObj('sidebarHolder').style.height = (1200 + d) + 'px';
        //getObj('bodyHolder').style.height = (1172 + d) + 'px';
    }
}

//This function set the height of all effected element height by newspaper image height
function setInternalHeightSize(imgH) {
    if (imgH >= 500) {
        var d = (parseInt(imgH)) - 500;
        getObj('mapNewsPaperHolder').style.height = (imgH + 283) + 'px';
        getObj('mainBodyPageBodyL').style.height = (1030 + d) + 'px';
        getObj('mainBodyPageBody').style.height = (1061 + d) + 'px';
        getObj('mainBodyInner').style.height = (1204 + d) + 'px';
        getObj('mainBodyBgR').style.height = (1240 + d) + 'px';
        getObj('mainBodyBgBotR').style.height = (1240 + d) + 'px';
        getObj('mainBodyHolder').style.height = (1240 + d) + 'px';
    }
}

function setAdvSearchHeightSize(imgH) {
    if (imgH >= 500) {
        var d = (parseInt(imgH)) - 763;
        getObj('mapNewsPaperHolder').style.height = (imgH) + 'px';
        getObj('mainBodyPageBodyL').style.height = (1030 + d) + 'px';
        getObj('mainBodyPageBody').style.height = (1061 + d) + 'px';
        getObj('mainBodyInner').style.height = (1204 + d) + 'px';
        getObj('mainBodyBgR').style.height = (1240 + d) + 'px';
        getObj('mainBodyBgBotR').style.height = (1240 + d) + 'px';
        getObj('mainBodyHolder').style.height = (1240 + d) + 'px';
    }
}

/* -------Show and hide right pan tree------------  */
//--------Main title------This function expand and collaps the main papaer title side pan menu
function showHideNewsTitle(divId, HTMLResourcePath) {
    stsN = getObj(divId).style.display;
    if (stsN == 'none') {
        getObj(divId).style.display = 'block';
        getObj('tree_' + divId).src = HTMLResourcePath + 'images/sideBar/serviceTreeOpen.jpg';
        getObj('tree_' + divId).className = 'menuIconOpen';
        return;
    }
    else if (stsN == 'block') {
        getObj(divId).style.display = 'none';
        getObj('tree_' + divId).src = HTMLResourcePath + 'images/sideBar/serviceTreeClose.jpg';
        getObj('tree_' + divId).className = 'menuIconClose';
        return;
    }
}

//-------Sub title------This function expand and colaps sub title of side pan
function showHidePageIndex(divId, HTMLResourcePath) {
    //panState holds the open pan div id but it shouldn't be equal to current div id to close it 
    if ((panState != '') && (panState != divId)) {
        getObj(panState).style.display = 'none';
        getObj('tree_' + panState).src = HTMLResourcePath + 'images/sideBar/serviceTreeClose.jpg';
        getObj('tree_' + panState).className = 'menuIconClose';
    }

    //sts holds the status of div pan display 
    sts = getObj(divId).style.display;
    //show and hide status of div pan 
    if (sts == 'none') {
        getObj(divId).style.display = 'block';
        getObj('tree_' + divId).src = HTMLResourcePath + 'images/sideBar/serviceTreeOpen.jpg';
        getObj('tree_' + divId).className = 'menuIconOpen';
        panState = divId;
        return;
    }
    else if (sts == 'block') {
        getObj(divId).style.display = 'none';
        getObj('tree_' + divId).src = HTMLResourcePath + 'images/sideBar/serviceTreeClose.jpg';
        getObj('tree_' + divId).className = 'menuIconClose';
        return;
    }

}



/* -------News Content Related Functions----  */
//This function visible the Content Div
function showNewsContentDiv() {
    newsTitleSts = getObj('newsContentHolder').style.display;
    hideLastHighlight();
    getObj('newsContentHolder').style.display = 'block';
}

function hideNewsContentDiv() {
    hideLastHighlight();
    getObj('newsContentHolder').style.display = 'none';
    LastNewsContent = '0'; // set lastNewsContent to zero(empty)
}

//This function show highlight map area border by getting an ID
function lightContent(divId) {
    showHighlightImageMap('map_' + divId);
}

//This function hide highlight map area border by getting an ID
function hideLightContent(divId) {
    hideHighlightImageMap('map_' + divId);
}

//This function first hides last news map highlight, newspaper headlines and all newsContent except the current news content
//It works on clicking each map area highlight
function showContentForArea(divId,WebPath){
    // hold current active news id.
    SetCurrentNewsID(divId,WebPath);
    hideLastHighlight(); //hide last map area highlight
    LastNewsContent = 'newsContent_' + divId;
    hideAllContentDiv();
    showNewsContentDiv();
    document.getElementById('content_' + divId).style.display = 'block';
    showHighlightImageMap('map_' + divId);    
}

//This function first hides last news map highlight, newspaper headlines and all newsContent except the current news content
//It works on clicking each map area highlight
function showImageForArea(divId, URLAddress) {
    goUrlInNewWindow(URLAddress);
}



/* -------Redirect to specific URL address ------------ */
//This function gets a url and changes pages url by that
function goUrl(URLAddress) {
    if (URLAddress != "") {
        document.location.href = URLAddress;
    }
}

//This function gets a url aand open it in new window
function goUrlInNewWindow(URLAddress) {
    if (URLAddress != "") {
        window.open(URLAddress);
    }
}

//This function gets the global variable value to hide previous map area highlight
function hideLastHighlight() {
    if (LastNewsContent != 0) {
        i = getNewsId(LastNewsContent);
        lni = 'map_' + i;
        getObj(lni).style.border = 'none';
    }
}

//This function gets coords of map shape and creates a div element for each one and by newsId parameters gives them a unice id
//in onmouseover event calls "showHighlightImageMap(divId)" to highlight the div
//in onmouseout event calls "hideHighlightImageMap(divId)" to hide div
//in onclick event calls "showContentForArea(newsId)" to show related news content
function createImageMap(xyStr, newsId, WebPath) {
    var xy = new Array();
    for (var i = 0; i < 3; i++) {
        f = xyStr.indexOf(',');
        xy[i] = xyStr.substring(0, f);
        xyStr = xyStr.substring(f + 1);
    }
    xy[3] = xyStr;
    w = parseInt(xy[2]) - parseInt(xy[0]);
    h = parseInt(xy[3]) - parseInt(xy[1]);
    getObj('mapDivHolder').innerHTML += '<div id="map_' + newsId + '" style="position:absolute; left:' + xy[0] + 'px; top:' + xy[1] + 'px; width:' + w + 'px; height:' + h + 'px; " onmouseover="showHighlightImageMap(\'map_' + newsId + '\');"  onmouseout="hideHighlightImageMap(\'map_' + newsId + '\');" onclick="showContentForArea(\'' + newsId + '\' , \'' + WebPath + '\'); goUrl(\'#top\');">&nbsp;</div>';
}

//This function gets coords of map shape and creates a div element for each one and by newsId parameters gives them a unice id
//in onmouseover event calls "showHighlightImageMap(divId)" to highlight the div
//in onmouseout event calls "hideHighlightImageMap(divId)" to hide div
//in onclick event calls "showImageForArea(newsId)" to show related news content
function createImageMap4ImageNews(xyStr, newsId, URLAddress) {
    var xy = new Array();
    for (var i = 0; i < 3; i++) {
        f = xyStr.indexOf(',');
        xy[i] = xyStr.substring(0, f);
        xyStr = xyStr.substring(f + 1);
    }
    xy[3] = xyStr;
    w = parseInt(xy[2]) - parseInt(xy[0]);
    h = parseInt(xy[3]) - parseInt(xy[1]);
    getObj('mapDivHolder').innerHTML += '<div id="map_' + newsId + '" style="position:absolute; left:' + xy[0] + 'px; top:' + xy[1] + 'px; width:' + w + 'px; height:' + h + 'px; " onmouseover="showHighlightImageMap(\'map_' + newsId + '\');"  onmouseout="hideHighlightImageMap(\'map_' + newsId + '\');" onclick="showImageForArea(\'' + newsId + '\' , \'' + URLAddress + '\')">&nbsp;</div>';
}

//This function checks div and if it is not the current highlight div for current news content makes it hidden
function hideHighlightImageMap(divId) {
    i = getNewsId(LastNewsContent);
    lni = 'map_' + i;
    if (lni != divId) {
        getObj(divId).style.border = 'none';
        getObj(divId).style.cursor = 'default';
    }
}

//This function highlights div by gives it a background color 
function showHighlightImageMap(divId) {
    getObj(divId).style.border = 'solid 4px #ffcc00';
    getObj(divId).style.cursor = 'pointer';
}

//This function gets "LastNewsContent" global variable value to finds the last news Id
function getNewsId(newsContentId) {
    u = newsContentId.indexOf('_');
    n = newsContentId.substring(u + 1);
    return n;
}

//Pass the query string parametre to this function to get the value
function querySt(str) {
    hu = window.location.search.substring(1);
    if (hu == '') {
        return '';
    }
    gy = hu.split("?");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == str) {
            return ft[1];
        }
    }
    return '';
}

// This function get URL Base and make print version link
// note : if news ID avalable
function goPrintVersion(URLBase) {
    if (LastNewsContent != '0') {
        goUrlInNewWindow(URLBase + LastNewsContent);
    }
    else {
        alert('لطفاً يک خبر را انتخاب کنيد');
    }
}



/* ------- display Archive Div ------------ */
var archiveSts = false;
//This function visible the archive date drop down list by clicking on 'بايگاني'
function showArchiveDiv() {
    if (!archiveSts) {
        getObj('archiveHolder').style.display = 'block';
        archiveSts = true;
        return;
    }
    else {
        getObj('archiveHolder').style.display = 'none';
        archiveSts = false;
        return;
    }
}

//This function visible the archive date drop down list by clicking on search button
function hideArchiveDiv() {
    var year = getObj('ddlYear').options[getObj('ddlYear').selectedIndex].value;
    var month = getObj('ddlMonth').options[getObj('ddlMonth').selectedIndex].value;
    var day = getObj('ddlDay').options[getObj('ddlDay').selectedIndex].value;

    if (year == '' || month == '' || day == '')
        return;
    else {
        getObj('archiveHolder').style.display = 'none';
        archiveSts = false;
    }
}


//This function make move icon hidden if the browser would be Net scape
function hideMoveIcn() {
    var browserVer = navigator.appName;
    if (browserVer == 'Netscape') {
        getObj('movmentIcn').style.display = 'none';
        getObj('movmentTxt').style.display = 'none';
    }
    else
        return;
}

//This function make move icon hidden if the browser would be Net scape
function hidePdfIcn(prm) {
    if (prm != '')
        getObj('pdfIcn').style.display = 'block';
    else
        return;
}

//This function help page number to be sorted correctly by numeric value. 
function sortNumber(a, b) {
    return a - b;
}



//This function genareted sorted page numbering html code
var pageNumbers = new Array();
var pageLink;
var i = 0;
var selectPage;

function creatPaggingNumber() {
    var end = pageNumbers.length;
    pageNumbers.sort(sortNumber);
    for (var i = 0; i < end; i++) {
        var tdTag = document.createElement("td");
        tdTag.align = "center";
        if (pageNumbers[i] == selectPage) {
            tdTag.innerHTML = "<div class='paggNumberingHolderSelected white'><div style='padding-top:17px;'>" + pageNumbers[i] + "</div></div>";
            if (pageNumbers[i] > 16) {
                getObj('paggingNumber').style.direction = 'ltr';
                getObj('paggingNumber').style.textAlign = 'left';
            }
        }
        else {
            var c = pageLink.indexOf('Page/');
            c = parseInt(c) + 5;
            var link = pageLink.substring(0, c);
            link = link + pageNumbers[i] + '/Index.htm';
            tdTag.innerHTML = "<div onclick='goUrl(\"" + link + "\");' class='paggNumberingHolder black' onmouseover='this.className=\"paggNumberingHolderOver white\"' onmouseout='this.className=\"paggNumberingHolder black\"'><div style='padding-top:17px;'>" + pageNumbers[i] + "</div></div>";
        }

        getObj('pageNumberHolder').appendChild(tdTag);
    }
}

//This function creat combobox
var combSTS = true;
function openCloseCombo() {
    if (combSTS) {
        displayBlock('comboBox');
        combSTS = false;
        return;
    }
    else {
        displayNone('comboBox');
        combSTS = true;
        return;
    }
}

//This function create combobox
var treeSTS = true;
function showCurrentSheet(objId, t) {
    var s = document.getElementById(objId).style.display;
    if (s != 'block') {
        displayNone('ServiceTree');
        displayNone('Thumnail');
        displayNone('NewsHeadlines');
        displayBlock(objId);
    }

    document.getElementById('tab1').className = 'tabSheetServiceTree pointer';
    document.getElementById('tab2').className = 'tabSheetThumnail pointer';
    document.getElementById('tab3').className = 'tabSheetNewsHeadlines pointer';
    document.getElementById(t.id).className = 'tabSheet' + objId + 'Select pointer';


    /*
    if (treeSTS){
    displayBlock('serviceTreeBox');
    displayNone('newsHeadLinesBox');
    headlineSTS = true;
    treeSTS = false;
    return;        
    }
    else{    
    displayNone('serviceTreeBox');
    treeSTS = true;
    return;
    }
    */
}




