//goes through nav list, gives the class 'over' to hovered items, to make the dropdowns work in IE
function startList() {
    if (document.all&&document.getElementById) {
	
	navRoot = document.getElementById("nav");
	
	for (i=0; i<navRoot.childNodes.length; i++) {
	    
	    node = navRoot.childNodes[i];
	    
	    if (node.nodeName=="LI") {
		
		node.onmouseover=function() {
		    this.className+=" over";
		}
    		
		node.onmouseout=function() {
		    this.className=this.className.replace(" over", "");
		}
	    }
	}
    }
}

//open links in new window without tons of crap
function externalLinks() {
    if (!document.getElementsByTagName) return;
    
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
	    anchor.target = "_blank";
	}
    }
}


function openWindow(url, width, height, left, top) {
    if(!left) {
        var left = parseInt((screen.availWidth/2) - (width/2));
    }

    if(!top) {
        var top = parseInt((screen.availHeight/2) - (height/2));
    }

    var windowFeatures = "scrollbars=yes,width=" + width + ",height=" + height +
    ",resizable=no,titlebar=no,status=no,menubar=no, left=" + left +
    ",top=" + top + ",screenX=" + left + ",screenY=" + top;

    var myWindow = window.open(url, "Grohe", windowFeatures);
}

function openPrintWindow(url, width, height) {
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));

    var windowFeatures = "width=" + width + ",height=" + height +
    ",resizable=no,titlebar=yes,status=no,menubar=no, scrollbars=yes, left=" + left +
    ",top=" + top + ",screenX=" + left + ",screenY=" + top;

    var myWindow = window.open(url, "Grohe", windowFeatures);
}


function fixFooter(elemHeight) 
{
	/*if(!elemHeight) elemHeight = 0;

	var newHeight = elemHeight + 50;
	var foot = document.getElementById('footer');
	
	foot.style.position = "absolute";

	var wrap = document.getElementById('wrapper');

	if(newHeight> 500) 
	{
	    wrap.style.height = newHeight + 50 + "px";
	}

	if(newHeight < 500) 
	{
	    foot.style.top = "auto";
	    foot.style.bottom = 0 + "px";
	} 
	else 
	{
	    foot.style.bottom = "auto";
	    foot.style.top = newHeight + "px";
	}*/
}

    function formatSearch() {
	document.getElementById('query').onchange = function() {
	    var new_num;
	    var new_num = this.value;

	    if ((new_num.length >= 2) && (new_num.length < 6) && (new_num.charAt(2) !== " ")) {  
		var first = new_num.substring(0,2);
		var last = new_num.substring(2, new_num.length);
		new_num = first + " " + last;
		this.value = '';
		this.value = new_num;
	    }
	}
	    
    }

    //1997-esq image preloading
    function preLoad() {
	var image1 = new Image();
	image1.src = '/g/removefromproject_over.gif';

	var image2 = new Image();
	image2.src = '/g/addtoproject_over.gif';

	var image3 = new Image();
	image3.src = '/g/download_over.gif';
	
	var image4 = new Image();
	image4.src = '/g/printer_over.gif';
	
	var image5 = new Image();
	image5.src = '/g/delete_over.gif';
    }


//adds the functions to the onload event
function addLoadEvent(func) {
    var oldonload = window.onload;

    if(typeof window.onload != 'function') {
	window.onload = func;
    } else {
	window.onload = function() {
	    oldonload();
	    func();
	}
    }
}

addLoadEvent(startList);
addLoadEvent(formatSearch);
addLoadEvent(externalLinks);
