sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("ul");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].parentNode.onmouseover= function() {
			this.lastChild.className+=" sfhover";
			this.lastChild.style.left = "auto";
		}
		sfEls[i].parentNode.onmouseout=function() {
			this.lastChild.className=this.lastChild.className.replace(new RegExp(" sfhover\\b"), "");
			this.lastChild.style.left = "-999em";
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

//add and subtract form elements
function addElement(div,set,url) {
	var ni = document.getElementById(div);
	var counterID = set+'theValue';
	var numi = document.getElementById(counterID);
	var num = parseFloat(document.getElementById(counterID).value) + 1;
	if(num < "5") {
		numi.value = num;
		var divIdName = div+num;
		var newtr = document.createElement('tr');
		newtr.setAttribute("id",divIdName);
		newtr.className = "auto";
		var newlabeltd = document.createElement('td');
		var newinputtd = document.createElement('td');
		newinputtd.colSpan = "3";
	

		if(set=="atts"){
			if(num < "4") {
				plusButton = "<img align=\"bottom\" src=\""+url+"/images/plus.gif\" width=\"16\" height=\"16\" alt=\"Add Another Attachment\" class=\"plusminus\" /></a>";
			}else {
				plusButton = "";
			}
			
			newlabeltd.innerHTML = "<label for=\"att"+num+"\">File "+(num+1)+"</label>";
			newinputtd.innerHTML = "<input type=\"file\" id=\"att"+num+"\" name=\"att"+num+"\" size=\"40\" /> &nbsp; <a href=\"javascript:;\" onclick=\"addElement('"+div+"','"+set+"','"+url+"')\">"+plusButton+"<a href=\"javascript:;\" onclick=\"removeElement('"+div+"','"+divIdName+"','"+set+"');\"><img align=\"bottom\" src=\""+url+"/images/minus.gif\" width=\"16\" height=\"16\" alt=\"Remove This Attachment\" class=\"plusminus\" />";
		}

		ni.appendChild(newtr);
		newtr.appendChild(newlabeltd);
		newtr.appendChild(newinputtd);
		changeOpac(0, divIdName);
		shiftOpacity(divIdName, 375);
	}
}


function removeElement(div,item,set) {
	var counterID = set+'theValue';
	var numi = document.getElementById(counterID);
	var d = document.getElementById(div);
	var olddiv = document.getElementById(item);
	d.removeChild(olddiv);
	var num = parseFloat(document.getElementById(counterID).value) - 1;
	numi.value = num;
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}


function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        moveOpacity(id, 0, 100, millisec); 
    } else { 
        moveOpacity(id, 100, 0, millisec); 
    } 
}

function moveOpacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
}

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			if(confirm(alerttxt)) {
				return true;
			}else {
				return false;
			}
		} else {
			messageP = document.getElementById("messageP");
			messageP.innerHTML = 'Your files are currently uploading.<br />Please do not close this page until you see the confirmation message.';
			addClass(messageP, "messageP");
			
			submitBtn = document.getElementById("submitBtn");
			submitBtn.disabled=true;
						
			return true;
		}
	}
}

function validate_form(thisform) {
	with (thisform) {
		if (validate_required(att0,"Are you sure you want to submit without uploading a file?")==false) {
			return false;
		}
	}
}

function addClass(element, value) {
	if(!element.className) {
		element.className = value;
	} else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}