var tmr;



window.onload = function() {

	//grab the anchor tags for the nav.

	modifyNewWindowLinks();

	var nav = document.getElementById('nav');

	

	var aTags = nav.getElementsByTagName('a');

	var liTags = nav.getElementsByTagName('li');

	

	for (var x = 0; x < aTags.length; x++) {

		aTags[x].onmouseover = showSubNav;

		aTags[x].onmouseout = hideSubNav;

		aTags[x].onfocus = showSubNav;

		aTags[x].onblur = hideSubNav;

	}

}



function showSubNav() {

	//get the parent element of the anchor with focus (or hover)	

	var pNode = this.parentNode;

	

	//Variable flag to determine whether or not the li element is in the top level of navigation.	

	var isTopLevel = true;

	

	//Check the parent element of the pNode. If the parent element's ID is 'nav' then the LI is in the top level of the navigation.

	if (pNode.parentNode.id != 'nav') {

		isTopLevel = false;

	}

	else {

		isTopLevel = true;

	}

	

	if (isTopLevel) {

		hideMenus(); //Hide other menus that might be visible

		clearTimeout(tmr); //Clear any timers that might be active

		if (String(pNode.className).indexOf('last') > -1) {

			pNode.className = 'over last';

		}

		else {

			pNode.className = 'over';

		}

	}

	else {

		clearTimeout(tmr); //Clear any timers that might be active

		pNode.className = 'over';

	}

}



function hideSubNav() {

	tmr = setTimeout("hideMenus()", 100);

}



function hideMenus() {

	//This function will hide any submenus that are currently visible.

	var nav = document.getElementById('nav');

	

	var liTags = nav.getElementsByTagName('li');

	

	for (var x = 0; x < liTags.length; x++) {

		if (String(liTags[x].className).indexOf('over') > -1) {

			if (String(liTags[x].className).indexOf('last') > -1) {

				liTags[x].className = 'last';

			}

			else {

				liTags[x].className = '';

			}

		}

	}

}

function modifyNewWindowLinks() {

	//This function looks for all the links with a class of "NewWindow"

	//and will cause them to open in a new window.



	var aTags = document.getElementsByTagName("a");

	for (var x = 0; x < aTags.length; x++) {

		var currTag = aTags[x];

		if (String(currTag.className).indexOf('NewWindow') > -1) {

			currTag.onclick = function(){ window.open(this.href); return false;}

		}

	}

}

function addNum()
{
	
	document.getElementById("num_pres").value++;
	
}

function addElement(name_el,title) {
	//Function add input field inside a div dinamically - keyler
	
  var ni = document.getElementById('delegates');
  num=document.getElementById("num_pres").value;

 var newdiv = document.createElement('div');
  newdiv.innerHTML='<label for="form-'+name_el+'">'+title+'</label>';
  ni.appendChild(newdiv);

  var newinput = document.createElement('input');
  newinput.type="text";
  newinput.id=name_el+num;
  newinput.name=name_el+num;

  newdiv.appendChild(newinput);
}
