﻿// JScript File

function PageRedirect()
{
    var comboID = document.getElementById("comboIdValue").value;
    var combobox = document.getElementById(comboID);
    
    if (combobox != null)
    {
        if (combobox.selectedIndex > 0)
        {
            window.location = combobox.options[combobox.selectedIndex].value;
        }
        else
        {
            alert('Please first select an option.');
        }
    }
}

function Resize()
{
    var divCenter = document.getElementById("template_mainContentCenter"); // Main container (center)
    var divRight =  document.getElementById("template_mainContentRight");  // Right container
    var divRight1 = document.getElementById("RightContentBock1"); // Right-top container
    var divRight2 = document.getElementById("RightContentBock2"); // Right-bottom container
    var divRight1Shadow = document.getElementById('RinghtShadowContainer1');
    var divRight2Shadow = document.getElementById('RinghtShadowContainer2');
    
    if (divCenter != null && divRight != null)
    {
        if (divCenter.offsetHeight > divRight.offsetHeight  )
        {
            divRight.style.height = (divCenter.offsetHeight - 26 ) + "px";
            //alert("Entra al if");
            if(divRight2.offsetWidth === 0)
            {
                //divRight1.style.height = (divCenter.offsetHeight - 30 ) + "px";
                //divRight1Shadow.style.height = (divCenter.offsetHeight - 1) + "px";
                //divRight.style.height = (divCenter.offsetHeight - 1 ) + "px";
                divRight1Shadow.style.height = (divRight1.offsetHeight + 4) + "px";
                if (BrowserDetect.browser == "Explorer")
                { 
                  //  ResizeShadowDivSideBars(document.getElementById('RinghtShadowContainer1'));
                }
            }
            else
            {
                //divRight1.style.height = ((divCenter.offsetHeight - 44) - divRight2.offsetHeight) + "px"; 
                //divRight1Shadow.style.height = ((divCenter.offsetHeight - 15) - divRight2.offsetHeight) + "px";
                divRight1Shadow.style.height = (divRight1.offsetHeight + 4) + "px";
                divRight2Shadow.style.height = (divRight2.offsetHeight + 4) + "px"; 
                //divRight1Shadow.style.height = (divCenter.offsetHeight - 5) + "px";
                if (BrowserDetect.browser == "Explorer")
                { 
                   // ResizeShadowDivSideBars(document.getElementById('RinghtShadowContainer1'));
                   // ResizeShadowDivSideBars(document.getElementById('RinghtShadowContainer2'));
                }
            }
        }
        else
        {
        
            if (divCenter.offsetHeight < divRight.offsetHeight  )
            {
            //alert("Entra al else");
                if(divRight1.offsetHeight === divRight1Shadow.offsetHeight)
                {
                    divRight1Shadow.style.height = (divRight1Shadow.offsetHeight + 4) + "px";
                //ResizeShadowDivSideBars(document.getElementById('RinghtShadowContainer1'));
                }
                if(divRight2.offsetWidth != 0)
                {
                    if(divRight2.offsetHeight === divRight2Shadow.offsetHeight)
                    {
                        divRight2Shadow.style.height = (divRight2Shadow.offsetHeight + 4) + "px";
                    }
                    //ResizeShadowDivSideBars(document.getElementById('RinghtShadowContainer2'));
                }
            }
            if(divRight.offsetHeight >  divRight1Shadow.offsetHeight)
            {
                divRight1Shadow.style.height = (divRight.offsetHeight - 1) + "px";
                divRight1.style.height = (divRight1Shadow.offsetHeight - 29) + "px";
            }
        }
    }  
}


var ResizeShadowDiv = function(object)
{if (BrowserDetect.browser == "Explorer"){ 
    object.style.height = object.offsetHeight + 3 + "px";}
};

var ResizeShadowDivSideBars = function(object)
{if (BrowserDetect.browser == "Explorer"){ 
    object.style.height = object.offsetHeight + 4  + "px";
   }
};

var ResizeShadowDivForTemplateDMainContent = function(object)
{if (BrowserDetect.browser == "Explorer"){ 
    object.style.height = object.offsetHeight + 1 + "px";}
};

var ResizeMainContentCenterDiv = function(contentObject, mainObject)
{if (BrowserDetect.browser == "Explorer"){ 
    mainObject.style.height = contentObject.offsetHeight + 4 + "px";}
};

function ResizeSearch()
{
    var divMainLeft = document.getElementById("template_mainContentLeft");      // Main search container (left)
    var divCenter =  document.getElementById("template_mainContentCenter");     // Center container
    var divRight =  document.getElementById("template_mainContentRight");       // Right container
    var divSearchResults = document.getElementById("SearchResults");            // Search results div
    var divRightSection3 = document.getElementById("mainContentRightSection3"); // Right-bottom container
    var divResultsContents = document.getElementById("SearchResultsContainer"); // Search results container
    var bottomContainer = document.getElementById("bottomContainer");           // bottom Container
    //alert(divSearchResults.offsetHeight);
    if(divMainLeft != null && divCenter != null && divRight != null)
    {
        if(divMainLeft.offsetHeight > divCenter.offsetHeight)
        {
            divCenter.style.height = (divMainLeft.offsetHeight - 22) + "px";
            //alert("Main left bigger, increment divcenter " + divMainLeft.offsetHeight);
        }
        if(divMainLeft.offsetHeight > divRight.offsetHeight)
        {
            bottomContainer.style.height = (divMainLeft.offsetHeight - 640) + "px"; 
            divRightSection3.style.height = (divMainLeft.offsetHeight - 646) + "px";            
            divRight.style.height = (divMainLeft.offsetHeight) + "px";
           // divRightSection3.style.border = "1px solid #CCCCCC";
          //  alert("Main left bigger, increment divrightsection3 " + divMainLeft.offsetHeight);
        }
        if(divMainLeft.offsetHeight < divCenter.offsetHeight)
        {
            divSearchResults.style.height = (divCenter.offsetHeight - 135) + "px";
            divResultsContents.style.height = divSearchResults.offsetHeight + 4 + "px";
           // alert("DivCenter bigger, increment search results " + "center " +divCenter.offsetHeight + "left " +(divSearchResults.offsetHeight + 135));
        }
        if(divMainLeft.offsetHeight < divRight.offsetHeight)
        {
            divSearchResults.style.height = (divRight.offsetHeight - 135) + "px";
            divResultsContents.style.height = divSearchResults.offsetHeight + 4 + "px";
           // alert("DivRight bigger, increment search results " +divRight.offsetHeight);
        }
        if(divCenter.offsetHeight > divRight.offsetHeight)
        {
            bottomContainer.style.height = (divCenter.offsetHeight -650) + "px";
            divRightSection3.style.height = (divCenter.offsetHeight -656) + "px";
            divRight.style.height = (divCenter.offsetHeight) + "px";
            //alert("DivCenter bigger, increment right div " + divRightSection3.offsetHeight);            
        }
        if(divCenter.offsetHeight < divRight.offsetHeight)
        {
            divCenter.style.height = (divRight.offsetHeight - 26) + "px";
          //  alert("last one " + divRight.style.height);
        }        
    }
}

/* Deletes the (12) class from the LeftMenu images */
fixMenuImgs = function() {
    var imgs = document.getElementsByTagName('img');
    for(var i = 0; i < imgs.length; i++) {
        if(imgs[i].className === '12') {
            imgs[i].className = '';
            imgs[i].style.display = 'none';
        }
    }
};

/////////////////LEFT MENU////////////////
function fixMenuColor(node)
{
    var selectedNode = node;
    if(node.Nodes != null)
    {
        /*node.TreeView.NodeCssOver ="TreeNode";
        node.TreeView.NodeCssSelect ="TreeNode";
        node.Selected = false;
        node.UnHover;
        node.NodeCssSelect = "TreeNode";
        node.NodeCssOver = "TreeNode";*/
    }
    else
    {/*
        node.TreeView.NodeCssOver ="TreeNodeSelected";
        node.TreeView.NodeCssSelect ="TreeNodeSelected";
        node.NodeCssSelect = "TreeNodeSelected";
        node.NodeCssOver = "TreeNodeSelected";
       */ 
    }
}

//Expand on click

function ClickHandler(node)
{
    if (node.Nodes.length > 0)
    {
         node.Toggle();
       //  AfterClientToggle(node);
    }
    
}

//Preserve expanded nodes
toggleActions= new String(); 
var temp;
function AfterClientToggle(node) 
{
   temp = Get_Cookie('TreeToggleActions');
   
   if(temp != null)
     toggleActions= temp;
   
   if(toggleActions.indexOf(node.Value + '*') > -1)
   { 
     toggleActions = toggleActions.replace(node.Value+"*","");
     while(toggleActions.indexOf(node.Value + '*') > -1)
     {
       toggleActions = toggleActions.replace(node.Value+"*","");
     }
   }
   else     
       toggleActions += node.Value + '*'; 
       
   createCookie('TreeToggleActions',toggleActions,'');
}

function createCookie(name,value,days) 
{ 
    if (days) { 
        var date = new Date(); 
        date.setTime(date.getTime()+(days*24*60*60*1000)); 
        var expires = "; expires="+date.toGMTString(); 
    } 
    else var expires = ""; 
    document.cookie = name+"="+value+expires+";path=/"; 
} 

// Method to get a cookie 
// this function gets the cookie, if it exists
function Get_Cookie( name ) 
{
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
    {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
}
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) 
       document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-2070 00:00:01 GMT";
}

/* Browser detection DO NOT DELETE */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
/*                                 */

function resizeSearchResults()
{
    var divSearchResults = document.getElementById("SearchResults");  
    var divResultsContents = document.getElementById("SearchResultsContainer");
    var divBottomContainer = document.getElementById("bottomContainer");  
    var divMainContentRightSection3 = document.getElementById("mainContentRightSection3");

    if(divSearchResults != null && divResultsContents != null)
    {
        divResultsContents.style.height = (divSearchResults.offsetHeight + 2)+ "px"; 
    }
    if(divBottomContainer != null && divMainContentRightSection3 != null)
    {
        divBottomContainer.style.height = (divMainContentRightSection3.offsetHeight + 3)+ "px"; 
    }
}