﻿// <summary>
//     Product:        Enewspaper
//     Classname:      Java Script
//     Version:        02.02 
//     Programmer:     Elham Esmaieli[elhamesmaieli@gmail.com] 
//     Purpose: 
//         All required JS to make HTML page dynamic.
// 
//     Copyright 2009 by Digital Secure Co. All Rights Reserved. 
// </summary>
// <IsMultiEdition>False</IsMultiEdition>
// <classVersion>002</classVersion>
// <EditingHistory>
//     Name:       Elham
//     Date:       01 September, 2009
//     Reason of change :
//         - Creating  document.
// </EditingHistory>
// <EditingHistory>
//     Name:       Anisa
//     Date:       06 September, 2009
//     Reason of change :
//         - 'geting' function is added.
//         - 'showNewsLink' is updated (getBewsId function is called)
// </EditingHistory>
// <EditingHistory>
//     Name:       Elham
//     Date:       07 September, 2009
//     Reason of change :
//         - Add "goUrlInNewWindow" function.
// </EditingHistory>

var panState = '';//Keeps div id of opened sub title pan
var LastNewsContent = '0'; //A global variable to always keeps last news content id
var fs = true;
/* -------Global Functions------------  */
//This function changes the background image of next and previous buttons
function buttonBgOverOut(imgId, imgSrc){
    document.getElementById(imgId).src='url(' + imgSrc + ')';
}

//This function make highlight btn during mouse over
function buttonImgOverOut(imgId, imgSrc){
    document.getElementById(imgId).src = imgSrc;
}

//This function change class name
function changeClass(objId, objClass){
    document.getElementById(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';
}

/* -------Next & previou button------------  */
//This function changes the backgroung image of next and previous buttons
function buttonOverOut(imgId, imgSrc){
    document.getElementById(imgId).style.backgroundImage='url(' + imgSrc + ')';
}


//This function creat next pagging button in both conditions, disabled or enabled
function putNextPagging(nextParam, src){
    if (nextPageURL == ''){
        document.getElementById('next').innerHTML +=   '<img src="' + src + 'images/pagging/tehranEmrooz_nextDis.jpg" width="4" height="8" border="0" alt="صفحه بعدی" title="صفحه بعدی"/>' +
                                                       '<span class="lightGray">' +
                                                       '  صفحه بعدی'+
                                                       '</span>';
        document.getElementById('next2').innerHTML +=  '<img src="' + src + 'images/pagging/tehranEmrooz_nextDis.jpg" width="4" height="8" border="0" alt="صفحه بعدی" title="صفحه بعدی"/>' +
                                                       '<span class="lightGray">' +
                                                       '  صفحه بعدی' + 
                                                       '</span>';                               
    }
    else{    
        document.getElementById('next').innerHTML +=    '<img src="' + src + 'images/pagging/tehranEmrooz_next.jpg" width="4" height="8" border="0" alt="صفحه بعدی" title="صفحه بعدی" class="pointer" onclick="goUrl(\'' + nextParam + '\');" />' +
                                                        '<span onclick="goUrl(\'' + nextParam + '\');" class="pointer black">' +
                                                        '  صفحه بعدی' + 
                                                        '</span>';
        document.getElementById('next2').innerHTML +=   '<img src="' + src + 'images/pagging/tehranEmrooz_next.jpg" width="4" height="8" border="0" alt="صفحه بعدی" title="صفحه بعدی" class="pointer" onclick="goUrl(\'' + nextParam + '\');" />' +
                                                        '<span onclick="goUrl(\'' + nextParam + '\');" class="pointer black">' +
                                                        '  صفحه بعدی' + 
                                                        '</span>';                               
    }      
}

//This function creat previous pagging button in both conditions, disabled or enabled
function putPrevPagging(prevParam, resource) {
    if (prevParam == ''){
        document.getElementById('prev').innerHTML +=    '<span class="lightGray">' +
                                                        'صفحه قبلی  ' + 
                                                        '</span>' +
                                                        '<img src="' + resource + 'images/pagging/tehranEmrooz_prevDis.jpg" width="4" height="8" border="0" alt="صفحه قبلی" title="صفحه قبلی"/>';
        document.getElementById('prev2').innerHTML +=   '<span class="lightGray">' +
                                                        'صفحه قبلی  ' + 
                                                        '</span>' +
                                                        '<img src="' + resource + 'images/pagging/tehranEmrooz_prevDis.jpg" width="4" height="8" border="0" alt="صفحه قبلی" title="صفحه قبلی"/>';                                
    }
    else{ 
        document.getElementById('prev').innerHTML  +=   '<span onclick="goUrl(\'' + prevParam + '\');" class="pointer black">' +
                                                        'صفحه قبلی  ' + 
                                                        '</span>' + 
                                                        '<img src="' + resource + 'images/pagging/tehranEmrooz_prev.jpg" width="4" height="8" border="0" alt="صفحه قبلی" title="صفحه قبلی" class="pointer" onclick="goUrl(\'' + prevParam + '\');" />';
        document.getElementById('prev2').innerHTML  +=  '<span onclick="goUrl(\'' + prevParam + '\');"  class="pointer black">' +
                                                        'صفحه قبلی  ' +
                                                        '</span>' + 
                                                        '<img src="' + resource + 'images/pagging/tehranEmrooz_prev.jpg" width="4" height="8" border="0" alt="صفحه قبلی" title="صفحه قبلی" class="pointer" onclick="goUrl(\'' + prevParam + '\');" />';                                
    }       
}

/* -------Show and hide right pan tree------------  */
// -------Main title------
//This function expand and colaps the main papaer title side pan menu
function showHideNewsTitle(divId, HTMLResourcePath){
    sts = document.getElementById(divId).style.display;
    if(sts == 'none'){
        document.getElementById(divId).style.display = 'block';
        document.getElementById('spn_'+divId).className = 'panLink_active';        
        document.getElementById('tree_'+divId).src = HTMLResourcePath + 'images/sideBar/tehranEmrooz_serviceTreeOpen.jpg';
        return;
        }
    else if(sts == 'block'){
        document.getElementById(divId).style.display = 'none';
        document.getElementById('spn_'+divId).className = 'panLink';
        document.getElementById('tree_'+divId).src = HTMLResourcePath + 'images/sideBar/tehranEmrooz_serviceTree.jpg';
        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)){
        document.getElementById(panState).style.display = 'none';
        document.getElementById('spn_'+panState).className = 'panLink';
        document.getElementById('tree_'+panState).src = HTMLResourcePath + 'images/sideBar/tehranEmrooz_serviceTree.jpg';
    } 
    //sts holds the status of div pan display 
    sts = document.getElementById(divId).style.display;
    //show and hide status of div pan 
    if(sts == 'none'){
        document.getElementById(divId).style.display = 'block';
        document.getElementById('spn_'+divId).className = 'panLink_active';
        document.getElementById('tree_'+divId).src = HTMLResourcePath + 'images/sideBar/tehranEmrooz_serviceTreeOpen.jpg';
        panState = divId;
        return;
        }
    else if(sts == 'block'){
        document.getElementById(divId).style.display = 'none';
        document.getElementById('spn_'+divId).className = 'panLink';
        document.getElementById('tree_'+divId).src = HTMLResourcePath + 'images/sideBar/tehranEmrooz_serviceTree.jpg';
        return;
        }        
}

/* -------Make content div visible------------  */
//This function first hide the news headlines and shows the current news content and then highlight the related map area highlight
//It works on clicking aech headlines
function showContent(divId) {
    // hold current active news id.
    SetCurrentNewsID(divId);
    document.getElementById('newsFeature').style.display = 'block';
    document.getElementById('newsHeadlines').style.display = 'none';
    document.getElementById('newsContent').style.display = 'block';    
    document.getElementById('newsContent_' + divId).style.display = 'block';
    LastNewsContent = 'newsContent_' + divId; 
    showHighlightImageMap('map_' + divId); //Highlight related map area
}

function lightContent(divId){
    showHighlightImageMap('map_' + divId); //Highlight related map area
}

function hideLightContent(divId){
    hideHighlightImageMap('map_' + divId); //Hide Highlight related map area
}

//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) {
    // hold current active news id.
    SetCurrentNewsID(divId);
    //hide last map area highlight
    hideLastHighlight(); 
    
    document.getElementById('newsHeadlines').style.display = 'none';
    document.getElementById('newsFeature').style.display = 'block';
    document.getElementById('newsContent').style.display = 'block';
    
    if(LastNewsContent != '0'){
        document.getElementById(LastNewsContent).style.display = 'none';    
    }
    document.getElementById('newsContent_' + divId).style.display = 'block';
    LastNewsContent = 'newsContent_' + divId;

    //document.getElementById('newsFeature').style.display = 'block';
}

//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){
    //hideLastHighlight(); //hide last map area highlight
    //document.getElementById('newsHeadLines').style.display = 'none';
//    if(LastNewsContent != '0'){
//        document.getElementById(LastNewsContent).style.display = 'none';    
//    }
    //document.getElementById('newsContent_' + divId).style.display = 'block';
    goUrlInNewWindow(URLAddress);
    //LastNewsContent = 'newsContent_' + divId;
}

/* -------Make headline div visible------------  */
//This function first hides last news map highlight and then  shows all newspaper headlines
//It works on clicking news Headlines
function showHeadlines() {
    //document.getElementById('newsFeature').style.display = 'none';
    hideLastHighlight(); //Hides last map area highlight
    var c = document.getElementById(LastNewsContent);    
    if((c != null) && (c != ''))
        c.style.display = 'none';
    document.getElementById('newsContent').style.display = 'none';
    document.getElementById('newsFeature').style.display = 'none';    
    LastNewsContent = '0';// set lastNewsContent to zero(empty)
    var n = document.getElementById('newsHeadlines');    
    if((n != null) && (n != ''))        
        n.style.display = 'block';
}


/* -------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 a url aand open it in parent window  
function goUrlInParent(URLAddress){
    if (URLAddress != "") {
      window.parent.document.location.href = 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;
        document.getElementById(lni).style.border='none';
    }
}

/* ------- Confirm News Direct Link ------------ */  
var newsLinkSts = false;
var str = new String();
//This function visible the archive date drop down list by clicking on 'بایگانی'
function showNewsLink(objId) {
        
    str = window.location + '?NewsID=' + getNewsId(LastNewsContent);
    document.getElementById(objId).value = str;
    x = window.confirm(str + '\n\n  کپی شود؟ clipboard آیا در');
    if (x)
        geting(objId);
    else
        return; 
}


//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){    
    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]);
    xy[0] = parseInt(xy[0]) - 4;
    xy[1] = parseInt(xy[1]) - 4;
    document.getElementById('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 +'\')">&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]); 
    xy[0] = parseInt(xy[0]) - 4;
    xy[1] = parseInt(xy[1]) - 4;
    document.getElementById('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){
        document.getElementById(divId).style.border = 'none';
        document.getElementById(divId).style.cursor = 'default';
        }
}

//This function highlights div by gives it a background color 
function showHighlightImageMap(divId){
    document.getElementById(divId).style.border = 'solid 4px #ffcc00'; 
    document.getElementById(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){
        document.getElementById('archiveSearch').style.display = 'block';
        archiveSts = true;
        return;
    }
    else{
        document.getElementById('archiveSearch').style.display = 'none';
        archiveSts = false;
        return;
    }
}

//This function visible the archive date drop down list by clicking on search button
function hideArchiveDiv(){
    document.getElementById('archiveSearch').style.display = 'none';
}

//This function make highlight search btn during mouse over
function archiveBtnOverOut(imgId, imgSrc){
    document.getElementById(imgId).src = imgSrc;
}



function changeFontSize(){
    if(fs){
        changeClass('newsContent', 'fontSizeXLarg lineHeightLarg');
        fs = false;
        return;
    }
    else{
        changeClass('newsContent', 'fontSizeLarg lineHeightMedium');
        fs = true;
        return;
    }        
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}


function setPageElementHeight(imgH){
    if (imgH > 565){
        var c = parseInt(imgH) - 565;                
        document.getElementById('sidebarHolder').style.height = (800 + c) + 'px';
        document.getElementById('bodyHolder').style.height = (800 + c) + 'px';
        document.getElementById('mainBody').style.height = (686 + c) + 'px';
        document.getElementById('paperBox').style.height = (686 + c) + 'px';
        document.getElementById('paperBoxInner').style.height = (678 + c) + 'px';
        document.getElementById('paperHolder').style.height = (686 + c) + 'px';
        document.getElementById('mapNewsPaperHolder').style.height = (565 + c) + 'px';
        document.getElementById('mapDivHolder').style.height = (565 + c) + 'px';
        document.getElementById('paperShadow').style.height = (686 + c) + 'px';
        document.getElementById('headLinesBox').style.height = (678 + c) + 'px';
        document.getElementById('pageContentBox').style.height = (652 + c) + 'px';
        document.getElementById('newsHeadlines').style.height = (652 + c) + 'px';
        document.getElementById('newsContent').style.height = (652 + c) + 'px';
    }
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = parseInt(window.innerWidth) - 17;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    document.getElementById('allHolder').style.width = myWidth +  'px';            
    var w = parseInt(myWidth) - 678;      
    if(w > 344){
        document.getElementById('bodyHolder').style.width = (470 + w) + 'px';
        document.getElementById('headLinesBox').style.width = w + 'px';    
    }
}

function setInternalPageHeight(imgH){
    if (imgH > 352){
        var c = parseInt(imgH) - 352;                
        document.getElementById('sidebarHolder').style.height = (587 + c) + 'px';
        document.getElementById('bodyHolder').style.height = (587 + c) + 'px';
        document.getElementById('mainBody').style.height = (473 + c) + 'px';
        document.getElementById('paperBox').style.height = (473 + c) + 'px';
        document.getElementById('paperBoxInner').style.height = (465 + c) + 'px';
        document.getElementById('paperHolder').style.height = (465 + c) + 'px';
        document.getElementById('paperShadow').style.height = (473 + c) + 'px';
    }
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = parseInt(window.innerWidth) - 17;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    document.getElementById('allHolder').style.width = myWidth +  'px';            
    var w = parseInt(myWidth) - 678;      
    if(w > 344){
        document.getElementById('bodyHolder').style.width = (470 + w) + 'px';
        document.getElementById('paperBox').style.width = (parseInt(myWidth)-200) + 'px';
        document.getElementById('paperBoxInner').style.width = (parseInt(myWidth)-200) + 'px';
        document.getElementById('paperHolder').style.width = (parseInt(myWidth)-220) + 'px';
        document.getElementById('paperShadowBottom').style.width = (parseInt(myWidth)-213) + 'px';             
    }
}

//This function make move icon hidden if the browser would be Net scape
function hidePdfIcn(prm){    
    if (prm != '')
        document.getElementById('pdfIcn').style.display = 'block';
    else        
        return;
}
//This function get the object data and copy in clipboard
function geting(objId) {
    var v = document.getElementById(objId).value;
    document.getElementById(objId).select();
    clipboardData.setData('Text', v);
}

window.fCopyToClipboard =
function(rSource) {
    rSource.select();
    if (window.clipboardData) {
        var r = clipboardData.setData('Text', rSource.value); return 1;
    }
    else return 0
}

//This function Use to show or hide an object
function ShowHideRSS(){    
    var c = document.getElementById('rssHolder').style.display;            
    if(c == 'none'){
        document.getElementById('rssHolder').style.display = 'block';
        return;
    }        
    else{
        document.getElementById('rssHolder').style.display = 'none';
        return;
    }
}