﻿//########### FLASH FUNCTIONS
function writeFlash(theMovie, X, Y, theContainer, theFlashVars){
	if(document.getElementById(theContainer)){
		var theHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + X + '" height="' + Y + '" type="application/x-shockwave-flash">';
		theHTML += '<param name="movie" value="' + theMovie + '" />';
		theHTML += '<param name="quality" value="high" />';
		theHTML += '<param name="wmode" value="transparent" />';
		theHTML += '<param name="menu" value="false" />';
		theHTML += '<param name="FlashVars" value="' + theFlashVars + '">';
		theHTML += '<embed src="' + theMovie + '" quality="high" wmode="transparent" menu="false" FlashVars="' + theFlashVars + '" width="' + X + '" height="' + Y + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		theHTML += '</object>';
		document.getElementById(theContainer).innerHTML = theHTML;
	}
}

function writeFlashes(){
    writeFlash('img/intro2.swf',430,252,'flashContent','');
    writeFlash('img/button1.swf',154,72,'flashContent2','');
    writeFlash('img/button2.swf',154,72,'flashContent3','');
}

//########### MENU FUNCTIONS
function FindFirstChildsLinkAndGoThere(ChildCollection){
    var chs = ChildCollection;
    for (i=0;i<chs.length;i++)
        if (chs[i].tagName=='DIV')
            if(chs[i].id.indexOf('Container')>-1){
                var dvs = chs[i].childNodes;
                for (j=0;j<dvs.length;j++)
                    if(dvs[j].childNodes[0].id.indexOf('theLink')>-1){
                        var theUrl = dvs[j].childNodes[0].href;
                        if (theUrl.indexOf('javascript:')>-1){
                            eval(theUrl.replace('javascript:',''));
                            return;
                        }
                        else
                            document.location.href=theUrl;
                        return;
                    }
            }
}
function GoToFirstChildsLink(id){
    var chs = document.getElementById('submnu' + id + 'Children').childNodes;
    FindFirstChildsLinkAndGoThere(chs);
}

function GoToFirstChildsFirstChildsLink(id){
    var chs = document.getElementById('subsubmnu' + id + 'Children').childNodes;
    FindFirstChildsLinkAndGoThere(chs);
}

function expandChildren(id){
    //HIDE ALL CHILDREN MENUS FIRST
    var divs = document.getElementsByTagName('DIV')
    for (i=0;i<divs.length;i++)
        if (divs[i].id.indexOf('submnu')==0 && divs[i].id.indexOf('Children')>-1)
            divs[i].style.display = 'none';
    document.getElementById('submnu' + id + 'Children').style.display='';
}

function expandSubChildren(id){
    //HIDE ALL CHILDREN MENUS FIRST
    var divs = document.getElementsByTagName('DIV')
    for (i=0;i<divs.length;i++)
        if (divs[i].id.indexOf('subsubmnu')==0 && divs[i].id.indexOf('Children')>-1)
            divs[i].style.display = 'none';
    document.getElementById('subsubmnu' + id + 'Children').style.display='';
}

function SelectItem(lev,id){
    var cont = document.getElementById('mnuLev' + lev + '_' + id + 'Container')
    cont.className = 'Lev' + lev + 'ContainerSelected';
    if (lev==1){
        expandChildren(id);
        cont.childNodes[0].childNodes[0].src = 'img/mnuArrW.gif'
    }
    else{
        //IF lev>1, I NEED TO EXPAND THE PARENTS TOO...
        if (lev==2){
            var id = cont.parentNode.previousSibling.id.replace('mnuLev1','').replace('Container','').replace('_','');
            expandChildren(id);
            SelectItem(1,id);
        }
        if (lev==3){
            var id = cont.parentNode.previousSibling.id.replace('mnuLev2','').replace('Container','').replace('_','');
            expandSubChildren(id);
            SelectItem(2,id);
        }
    }
}

//############## CALENDAR FUNCTIONS
function HideAllDropDowns(){
	var dds = document.getElementsByTagName('SELECT');
	for (i=0;i<dds.length;i++)
		dds[i].style.visibility='hidden';
}
function ShowAllDropDowns(){
	var dds = document.getElementsByTagName('SELECT');
	for (i=0;i<dds.length;i++)
		dds[i].style.visibility='visible';
}
function HandleBodyClick(){
	if (window.event.srcElement.tagName == 'DIV' || window.event.srcElement.tagName == 'BODY')
	{
		HideAllCalendars();
		ShowAllDropDowns();
	}
}
function HideAllCalendars(){
	//Hides all Calendars And makes DropDowns visible again
	var divs = document.getElementsByTagName('DIV');
	for (i=0;i<divs.length;i++)
		if (divs[i].id.indexOf('DIV')>-1)
			divs[i].style.display='none';	
}
function ShowCalendar(theTextBox){
	HideAllCalendars(); //Hide All calendars to avoid having more than one visible
	theTextBox.text='';
	HideAllDropDowns();
	document.getElementById(theTextBox.id + 'DIV').style.display='';
	document.getElementById(theTextBox.id + 'DIV').innerHTML = '<iframe frameborder=0 width=190 height=160 src="cal.aspx?TheField=' + theTextBox.id + '"></iframe>'
}
  

//############## VARIOUS FUNCTIONS
function PosBottom(){
    var bt = document.getElementById('bottom');
    var mn = document.getElementById('Main');
    

    if(bt.offsetTop < (document.body.clientHeight - parseInt(bt.style.height)))
        document.getElementById('bottom').style.top = document.body.clientHeight - mn.offsetHeight - parseInt(bt.style.height);

    //THERE IS A SMALL CSS BUG IN MENU. FOR EACH SELECTED ITEM OF LEVEL1 AND 2, THERE ARE 2 DIVS FLOATED LEFT.
    //WELL, THE LEFT ONE CAN'T FOLLOW THE RIGHT ONE IN HEIGHT. THIS SHOULD FIX IT
    var divs = document.getElementsByTagName('DIV');
    for (i=0;i<divs.length;i++){
        if (divs[i].className=='Lev1ContainerSelected' || divs[i].className=='Lev2Container' || divs[i].className=='Lev2ContainerSelected' || divs[i].className=='Lev3ContainerSelected' || divs[i].className=='Lev3Container'){
            if (document.all){
                try{divs[i].childNodes[0].style.height=divs[i].childNodes[1].offsetHeight;}catch(e){}
            }
            else    //STUPID MOZILLA CORRECTION
                try{divs[i].childNodes[0].style.height=parseInt(divs[i].childNodes[1].offsetHeight)-7}catch(e){}
        }
    }
} 

function SwapImage(imgObj){
    if (imgObj.src.toLowerCase().indexOf('over.')>-1)
        imgObj.src = imgObj.src.toLowerCase().replace('over.','.');
    else
        imgObj.src = imgObj.src.toLowerCase().replace('.gif','over.gif').replace('.jpg','over.jpg');
}



//############## PRINT FUNCTIONS
function prepareForPrint(){
    document.getElementById('menu').style.display = 'none';
    document.getElementById('top').style.display = 'none';
}
function comeBackFromPrint(){
    document.getElementById('menu').style.display = '';
    document.getElementById('top').style.display = '';
}

//window.onbeforeprint = prepareForPrint;
//window.onafterprint = comeBackFromPrint;
