﻿// JavaScript Document

// ------------------------- RESTYLING EXTERNAL LINKS ---------------
// Searched for all external links within only the Content Div (Excluding by this way: header, footer, left menu)
// and applies a different class over them. (where an icon is preceeding the link)
// also excluding any link whose href contains 'jabascript:' method call, coz this way, it will most probably have special style

// THIS IS DONE BY ----- Parsing The Querystring with Javascript
// Remember, URL has the form of <protocol>//<host>[:<port>]/<pathname>[<hash>][<search>]

function manageLinksStyle() {

    var contentDiv = document.getElementById('content-right');
    var contentLinks = contentDiv.getElementsByTagName('a');

    var link;
    var javascriptLink;

    for (var i = 0; i <= contentLinks.length; i++) {
        link = contentLinks[i];

        if (link != null && typeof link != "undefined" && link.id != "a_content") {
            //   continue;
            //alert("link href =" + link.href);
            javascriptLink = false;

            var linkHref_LowerCase = link.href.toLowerCase();
            if (linkHref_LowerCase.match("javascript") != null) {
                //alert("link href contains 'javascript:' call");
                javascriptLink = true;
            }

            // to get link.host & location.host without the port number if contains
            var linkHost_WithoutPort, locationHost_WithoutPort;
            if (!javascriptLink) {
                if (link.host.indexOf(':') != -1)
                    linkHost_WithoutPort = link.host.substr(0, link.host.indexOf(':'));
                else
                    linkHost_WithoutPort = link.host

                if (location.host.indexOf(':') != -1)
                    locationHost_WithoutPort = location.host.substr(0, location.host.indexOf(':'));
                else
                    locationHost_WithoutPort = location.host

                //alert ("link.host, location.host -- '" + link.host+"' , '"+location.host+ "'")
                //alert ("Modified -- link.host, location.host -- '" + linkHost_WithoutPort +"' , '"+locationHost_WithoutPort+"'")

                if (linkHost_WithoutPort != locationHost_WithoutPort) {
                    //alert("apply external link style");
                    link.className = 'ms-rteCustom-link_external';
                }
                else {
                    //alert("internal link");
                }
            }
            else {
                //alert("didn't check or apply external link style coz it probably has special style with the javascript call.");
            }
        }
    }
}



// ------------------------- EMBED LOGO -------------------------
// Embeds logo image included in the page if its [id = kibsilogo] 
// to be displayed in the header imgkibsilogo  
function embedLogo() {
    var myLayers = document.getElementsByTagName('img');
    var logo = document.getElementById('imgkibsilogo');

    if (myLayers.length > 0) {
        var myImages = new Array()
        for (i = 0; i < myLayers.length; i++) {
            if (myLayers[i].alt == 'kibsilogo') {
                myImages.push(myLayers[i].src)
                myLayers[i].style.display = "none";
            }
        }

        for (j = 0; j < myImages.length; j++) {
            logo.src = myImages[j];
        }
    }
}

// ------------------------- RESIZE WINDOW -------------------------
// Resizes window if it contains a hyper link <a> with id=kibsipopuppage 
// where desired width and height are uncluded in the link tooltip (title)
function resizeWindow() {
    var myLinks = document.getElementsByTagName('a');
    if (myLinks.length > 0) {
        var myLink = '';

        for (i = 0; i < myLinks.length; i++) {
            if (myLinks[i].id == 'kibsipopuppage') {
                myLink = myLinks[i].title;
                myLinks[i].style.display = "none";
                break;
            }
        }
        if (myLink.split(',').length > 0) {
            var width = myLink.split(',')[0];
            var height = myLink.split(',')[1];
            if ((width != null && width != '' && width != 0) && (height != null && height != '' && height != 0)) {
                window.resizeTo(width, height);
            }
        }
    }
}

// ------------------------- APPLY POPUP HEADER -------------------------
// Applies Popup Header to the page if it contains [div id = kibsipopupwindow]
function applyPopupHeader() {
    var myDiv = document.getElementById('kibsipopupwindow');
    if (myDiv != null && myDiv != 'undefined') {
        // Hide Footer - Begin 
        var divs = document.getElementsByTagName('div');

        for (var i = 0; i < divs.length; i++) {
            if (divs[i].id == "breadcrumb-container" || divs[i].id == "mainnav-container" || divs[i].id == "footer") {
                var breadcrumbContainerId = divs[i].id;
                document.getElementById(breadcrumbContainerId).style.display = "none";
            }

        }
        // Hide Footer - End 
        // Show Popup Header
        document.getElementById('popupnav').style.display = "block";
    }
}

//    var myDiv = document.getElementById('kibsipopupwindow');	
//    if (myDiv!=null && myDiv !='undefined') 
//    {
//        // Hide common header
//        document.getElementById('header_container').style.display = "none";
//        
//        // Hide Footer - Begin 
//        var divs = document.getElementsByTagName('div');
//                
//        for(var i=0; i<divs.length; i++)
//        {            
//            if(divs[i].className == "footercontainer")
//            {
//                var footerContainerId = divs[i].id;
//                document.getElementById(footerContainerId).style.display = "none";
//                break;
//            }
//        }
//        // Hide Footer - End 
//        
//        // Show Popup Header
//        document.getElementById('page_popup').style.display = "block";              	
//    }
//}

// ------------------------- SET WINDOW ATTRIBUTES -------------------------
// Sets window.open attributes(like menubar, address bar) of any link in 
// the page if its [tootltip=kibsipopoupcaller] and [target=_blank]
function setWindowAttributes() {
    var myLinks = document.getElementsByTagName('a');
    if (myLinks.length > 0) {
        for (i = 0; i < myLinks.length; i++) {
            if (myLinks[i].title == 'kibsipopupcaller' && myLinks[i].target == '_blank') {
                myLinks[i].onclick = function() {
                    try {
                        window.open(this.href, "Kapsch", "toolbar=no,status=yes, directories=no, menubar=no,resizable=yes,location=no,scrollbars=yes,copyhistory=no");
                    }
                    finally {
                        return false;
                    }
                };
                myLinks[i].target = "none";
            }
        }
    }
}

function HideContentPageImageForSlideshow() {
    var DivImage = document.getElementById('ContentTopImage');
    if (DivImage != null) {
        DivImage.style.display = "none";
    }
}



