
// JavaScript Document
var divVisible = 0;
var divTimeout = 0;
var divTimeoutDebex = 0;
var divTimeoutCerta = 0;
var divTimeoutVitaldent = 0;
var divSubTimeout = 0;
var lastmenu;
var lastmenuDebex;
var lastDropDown;
var lastSubMenu;
var lastDivMenuVisible = 0;
var firstOnFocus = 0;

function firstClick(div)
{
    if (firstOnFocus == 0)
    {
        document.getElementById(div).value = "";
    }
    else
    {
        firstOnFocus++;
    }
}

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 showDivVitaldent(div)
{
    if (document.getElementById && document.getElementById(div)!= null)
	{
		var style = document.getElementById(div).style;
		style.display = "block";
	}
}

function hideDivVitaldent(div)
{
    if (document.getElementById && document.getElementById(div)!= null)
	{
		var style = document.getElementById(div).style;
		style.display = "none";
	}
}

function natalDiv(div)
{
    if (document.getElementById && document.getElementById(div)!= null)
    {
        if (window.location.pathname != "/")
        {
		    var style = document.getElementById(div).style;
		    style.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+'")',100);
}

function cancelTimeout()
{
   clearTimeout(divTimeoutCerta);
}

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 hideDivVitaldent(div)
{
   divTimeoutVitaldent=setTimeout('hideDivVitaldentNow("'+div+'")',100);
}

function hideDivVitaldentNow(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style = document.getElementById(div).style;
		style.display = "none";
	}
}

function cancelTimeoutVitaldent()
{
   clearTimeout(divTimeoutVitaldent);
}

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[2] + leftMargin - document.getElementById(div).offsetWidth) + "px";
		    style2.top = (menuPos[1] + topMargin) + "px";
	    }
	}
}

function showMenuDebex(obj, div, offsetX, offsetY)
{   
    if (lastmenuDebex == div)
       clearTimeout(divTimeoutDebex); 
    else 
       hideDivNow(lastmenuDebex);
   
	if (!divVisible) // only if div is not visible
    {      
        divVisible = 1; // flags div as visible
        lastmenuDebex = 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";
		    style2.left = (obj.offsetLeft + leftMargin) + "px";
		    style2.top = (obj.offsetTop + topMargin) + "px";
	    }
	}
}

function showMenuAlmerindo(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 selectDropDownValue(dropdown, dropId)
{
    if (document.getElementById && document.getElementById(dropId) != null)
    {
        var dropElement = document.getElementById(dropId).value = dropdown;
        dropElement.selected = 'selected';
    }

}

function hideMenuDiv(div)
{
   divTimeout=setTimeout('hideDivNow("'+div+'")',300);
}

function hideMenuDivDebex(div)
{
   divTimeoutDebex=setTimeout('hideDivNow("'+div+'")',300);
}

function cancelHideMenuDiv(div)
{
   clearTimeout(divTimeout);
}

function findPos(obj) {
	var posleft = postop = posright = width = 0;
	if (obj.offsetParent)
	{
		posleft = obj.offsetLeft
		postop = obj.offsetTop
		width = obj.offsetWidth
		while (obj = obj.offsetParent)
		{
			posleft += obj.offsetLeft
			postop += obj.offsetTop 
		}
		posright = posleft + width
//		alert("left: " + posleft);
//		alert("top: " + postop);
//		alert("right: " + posright);
	}
	return [posleft,postop,posright];
}

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;
}
