﻿// JavaScript Document

// ------------------------- RESTYLING EXTERNAL LINKS ---------------
// Searched for all external links within only the Content Div (Excluding this way header, footer, left menu)
// and applies a different class over them. (where an icon is preceeding the link)
function manageLinksStyle()
{    
    var contentDiv = document.getElementById('content');
    var contentLinks = contentDiv.getElementsByTagName('a');
        
    var link;
    for ( var i=0;i<=contentLinks.length;i++) 
    {
        link = contentLinks[i]; 
        if(link.id=="a_content")
            continue;
        var linkHost_WithoutPort;
        if(link.host.indexOf(':') != -1)
            linkHost_WithoutPort = link.host.substr(0,link.host.indexOf(':'));
        else
            linkHost_WithoutPort = link.host
            
        var locationHost_WithoutPort;
        if(location.host.indexOf(':') != -1)
            locationHost_WithoutPort = location.host.substr(0,location.host.indexOf(':'));
        else
            locationHost_WithoutPort = location.host
            
        //alert ("link.host: " + link.host+" - location.host: "+location.host)
        //alert ("Modified -- link.host: " + linkHost_WithoutPort +" - location.host: "+locationHost_WithoutPort)
        
        if (linkHost_WithoutPort != locationHost_WithoutPort)
        {            
            link.className= 'ms-rteCustom-link_external';
        }
    }
}

// ------------------------- 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 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";
            }
 		}
  	}
}