
// PopUp in centre of browser 
function PopUpWindow(page,name, w, h, attributes){
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;	
	
	winprops = "height=" + h + ",width=" + w + ",top=" + wint + ",left=" + winl + "," + attributes;
	var OpenWin = window.open(page, name, winprops);
}

// keep application pop-up the same
function PopUpApplications(iApplicationID){
	PopUpWindow('application_info.php?app='+iApplicationID,'Application', 620, 520, 'resizable=1,scrollbars=1');
}

//box selection of application - do logic
function ViewApplications(oSelect){
	var sSelectValue = oSelect.value;
	if(sSelectValue.length){
		if(isNaN(parseInt(sSelectValue))){// show a list of applications - no id
			document.location = "index.php?page=application";
		}
		else{// pop-up specific application, we have an id
			PopUpApplications(sSelectValue);
		}
	}
}

// delete link
function DeleteLink(sDeleteObj,sURL){
	if(confirm("Are you sure you want to delete this " + sDeleteObj + "?"))
		document.location = sURL;
}
// write options
function WriteOptions(oSelect,Text,Value,bSelected){
	var OptionsLength = oSelect.length;	//get length of options
	oSelect.length += 1;//increment option count
	oSelect.options[OptionsLength].value = Value;//write value into option
	oSelect.options[OptionsLength].text= Text;	//write text into option
	if(bSelected) oSelect.options[OptionsLength].selected = true;//select added option
}

function CalendarWrite(iCalID, dValue, sInputName, oContainer){
	var oInput = document.createElement("input");
	oInput.setAttribute("size", "10");
	oInput.setAttribute("id", "calinput_"+iCalID);
	oInput.setAttribute("value", dValue);
	oInput.setAttribute("name", sInputName);

	var oA = document.createElement("a");
	oA.setAttribute("name", "calposition_"+iCalID);
	oA.setAttribute("id", "calposition_"+iCalID);

	var oA2 = document.createElement("a");
	oA2.setAttribute("onclick", new Function("cal_"+iCalID+".showCalendar('anchor_"+iCalID+"'); current_calendar='calinput_"+iCalID+"';return false;"));
	oA2.setAttribute("name", "anchor_"+iCalID);
	oA2.setAttribute("id", "anchor_"+iCalID);
	oA2.setAttribute("href", "#");
	
	var oIMG = document.createElement("img");
	oIMG.setAttribute("align", "absmiddle");
	oIMG.setAttribute("src", "calendar/calendar.gif");
	oIMG.setAttribute("alt", "Calendar");
	oIMG.setAttribute("border", "0");
	oIMG.setAttribute("hspace", "1");
	oIMG.setAttribute("vspace", "1");
	
	var oDiv = document.createElement("div");
	oDiv.setAttribute("id", "caldiv_"+iCalID);
	oDiv.setAttribute("className", "cpCalPop");
	//oDiv.setAttribute("");
	
	oA2.appendChild(oIMG);
	oContainer.appendChild(oInput);
	oContainer.appendChild(oA);
	oContainer.appendChild(oA2);
	oContainer.appendChild(oDiv);
	
	eval("cal_"+iCalID+" = CalendarInit("+iCalID+")");
}

// ---- IE 6+7 Menu functions ---
sfHover = function() {
	var oAboutEls = document.getElementById("menu_about").getElementsByTagName("LI");
	doMenuStyle(oAboutEls);
	
	var oProductsEls = document.getElementById("menu_products").getElementsByTagName("LI");
	doMenuStyle(oProductsEls);
	
	var oApplicationEls = document.getElementById("menu_applications").getElementsByTagName("LI");
	doMenuStyle(oApplicationEls);
}

/*
function doMenuStyle(sfEls){
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);*/
// --- ---

// submenu functions
function submenuOpen(sId){
	var sMenuId = '';
	var sMenuPrefix = 'menu_';
	
	oParent = $("menu_parent");
	oAllUl = oParent.getElementsByTagName("UL");
	
	for( var iNav=0; iNav<oAllUl.length; iNav++ ){
		// menu id's just have to start: menu_
		if( !oAllUl[iNav].id.length ||  oAllUl[iNav].id.substring(0,5) != sMenuPrefix ) continue;
		// get the child nodes
		var arrSubNav = oAllUl[iNav].getElementsByTagName("UL");
		// dont go'ne hide our opening menu or tryn hide already hidden menus
		if( !$(arrSubNav[0].id) || arrSubNav[0].id == sId || arrSubNav[0].style.display == 'none' ) continue;
		// other subnav hide
		Effect.BlindUp(arrSubNav[0].id, { duration: 2.0 });
	}
	Effect.BlindDown(sId, { duration: 1.0 });
}
