// form handlers

// set input field initial value
function settext(fld, def){
	if(fld.value == def){ 
		fld.value = ''; 
	} else if(fld.value == ''){
		fld.value = def; 
	}
}

// DROPDOWN HANDLER /////////////////////////////////////////////////////////////////////////////////////////////////////////
var timeout	= 100;
var closetimer	= 0;
var ddmenu	= 0;
var ddlink	= 0;
var curlink = '';
if ($.browser.msie) { var version = $.browser.version; }

function showmenu(id, a){	
	canceltimer();
	if(a.className == 'selected'){ curlink = a; } else { curlink.className = 'selected'; }

	if(ddmenu){ ddmenu.style.display = 'none'; }
	if(version != 6){ if(ddlink){ 
		if(ddlink.className != 'selected'){ ddlink.className = ''; }
	}}

	ddmenu = document.getElementById(id);
	ddlink = a;
	
	ddmenu.style.display = 'block';
	if(version != 6){ ddlink.className = 'hover'; }
	if($(ddlink).position().left == 2){
		ddmenu.style.left = $(ddlink).position().left + 'px';
	} else {
		ddmenu.style.left = ($(ddlink).position().left + 1) + 'px';
	}
}

function hidemenu(){
	if(ddmenu) ddmenu.style.display = 'none';
	if(version != 6){ if(ddlink){ 
		ddlink.className = '';
		if(curlink != ''){ curlink.className = 'selected'; }
	}}
}

function starttimer(){
	if(curlink != ''){ curlink.className = 'hover'; }
	closetimer = window.setTimeout(hidemenu, timeout);
}

function canceltimer(){
	if(curlink != ''){ curlink.className = 'hover'; }
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = hidemenu;

// JQUERY STUFF BELOW ////////////////////////////////////////////////////////////////////////////////////////////////////

// check for IE
function isIE(){  
    if(navigator.userAgent.match(/MSIE \d\.\d+/))  
        return true;  
    return false;  
} 

// move specified elements to top of pile
function zIndexWorkaround()  {  
    // If the browser is IE,  
    if(isIE())  
    {  
        /*  
        ** For each div with class menu (i.e.,  
        ** the thing we want to be on top),  
        */ 
        $("div.dropdown").parents().each(function() {  
            var p = $(this);  
            var pos = p.css("position");  
            // If it's positioned,  
            if(pos == "relative" ||  
               pos == "absolute" ||  
               pos == "fixed")  
            {  
                /*  
                ** Add the "on-top" class name when the  
                ** mouse is hovering over it, and remove  
                ** it when the mouse leaves.  
                */ 
                p.hover(function() {  
                        $(this).addClass("on-top");  
                    },  
                    function() {  
                        $(this).removeClass("on-top");  
                    });  
            }  
        });  
    }  
}