
// JavaScript Document
var divVisible = 0;
var divTimeout = 0;
var divTimeoutCerta = 0;
var divSubTimeout = 0;
var lastmenu;
var lastDropDown;
var lastSubMenu;
var lastDivMenuVisible = 0; 

function openMenu(div, menuId)
{
    if (document.getElementById && document.getElementById('subMenu_parent_' + menuId)!= null)
    {
        showHideDiv(div);
    }
    else 
        window.location = "index.aspx?p=MenuPage&MenuId="+menuId;
}

function setDiv(divWhite, divRed)
{
    if (document.getElementById && document.getElementById(divWhite)!= null)
	{
		var style1 = document.getElementById(divWhite).style;
		var style2 = document.getElementById(divRed).style;
		style2.display = "block";
		style1.display = "none";
	}
}


function showMenuCerta(divWhite, divRed, div, menuId, obj, offsetX, offsetY)
{
    if (document.getElementById && document.getElementById('subMenu_parent_' + menuId)!= null)
    {
        showMenu(obj, div, offsetX, offsetY);
        showDivCerta(divWhite, divRed);
    }
    else 
        window.location = "index.aspx?p=MenuPage&MenuId="+menuId;

}

function showMenuCertaRed(div, menuId, obj, offsetX, offsetY)
{
    if (document.getElementById && document.getElementById('subMenu_parent_' + menuId)!= null)
    {
        showMenu(obj, div, offsetX, offsetY);
    }
    else 
        window.location = "index.aspx?p=MenuPage&MenuId="+menuId;

}

function hideMenuDivCerta(divWhite, divRed, div)
{
    hideMenuDiv(div);
    hideDivCerta(divWhite, divRed);
}

function showDivCerta(divWhite, divRed)
{
	if (document.getElementById && document.getElementById(divWhite)!= null)
	{
		var style1 = document.getElementById(divWhite).style;
		var style2 = document.getElementById(divRed).style;
		style1.display = "none";
		style2.display = "block";
	}
}

function hideDivCerta(divWhite, divRed)
{
   divTimeoutCerta=setTimeout('hideDivCertaNow("'+divWhite+'","'+divRed+'")',500);
}

function hideDivCertaNow(divWhite, divRed)
{
	if (document.getElementById && document.getElementById(divWhite)!= null)
	{
		var style1 = document.getElementById(divWhite).style;
		var style2 = document.getElementById(divRed).style;
		style2.display = "none";
		style1.display = "block";
	}
}

function showMenu(obj, div, offsetX, offsetY)
{   
    obj = obj.offsetParent;
    if (lastmenu == div)
       clearTimeout(divTimeout); 
    else 
       hideDivNow(lastmenu);
   
	if (!divVisible) // only if div is not visible
    {      
        divVisible = 1; // flags div as visible
        lastmenu = div; // stores last menu visited (this one)
        
	    if (document.getElementById)
	    {
		    var leftMargin = offsetX;
		    var topMargin = offsetY;
		    var style2 = document.getElementById(div).style;
		    style2.display = style2.display ? "" : "block";
		    menuPos =  findPos (obj); // (mouseX(event) - leftMargin);
		    style2.left = (menuPos[0] + leftMargin) + "px";
		    style2.top = (menuPos[1] + topMargin) + "px";
	    }
	}
}

function showHideDiv(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		if (style2.display == "none" || style2.display == "")
		{
			style2.display = "block";
		}
		else
		{
			style2.display = "none";
		}
	}
}

function showHideDropDownOption(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
	    if (lastDropDown == null)
	    {
	        lastDropDown = div;
	    }
		var style2 = document.getElementById(div).style;
		var styleOld = document.getElementById(lastDropDown).style;
		if (style2.display == "none" || style2.display == "")
		{
			styleOld.display = "none";
			style2.display = "block";
			lastDropDown = div;	
		}
		else
		{
			style2.display = "none";
		}
	}
}

function hideDivNow(div) 
{    
	if (document.getElementById && document.getElementById(div)!= null)
	{
	    divVisible = 0;
		var style2 = document.getElementById(div).style;
		style2.display = "none";	
	}
}

function hideMenuDiv(div)
{
   divTimeout=setTimeout('hideDivNow("'+div+'")',500);
}

function findPos(obj) {
	var posleft = postop = 0;
	if (obj.offsetParent)
	{
		posleft = obj.offsetLeft
		postop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			posleft += obj.offsetLeft
			postop += obj.offsetTop
		}
	}
	return [posleft,postop];
}

function redirectPDF(targ, url) {

    
    url = targ+".pdf";
    url = stripSpecialChars(url);
    //alert(url);
    window.open("PDFFiles/"+url);
}

function stripSpecialChars(string) {
	marks = "/:?'<>|\\";
	str = string;

	for (i = 0; i < marks.length; i++) {

		mark = marks.charAt(i);

		while (str.indexOf(mark) != -1) {
			point = str.indexOf(mark);
			first_part = str.substring(0, point);
			second_part = str.substring(point + 1, str.length);
			str = first_part + second_part;
		}
	}
	return str;
}