
//document.write("<div id=\"HintBubble\" class=\"hint\"></div>");
var LastnodeLoaded
function hintpopupDisplay(caption,xpos,ypos){
	DelaySeconds = 2;
	HintBubble.style.pixelLeft = 30;//xpos - 15;
	HintBubble.style.pixelTop = ypos + 18;
	HintBubble.innerHTML = "<table cellspacing=0 class=\"hint\"><tr><td>"+caption+"<td></tr></table>";
	HintBubble.hintTimer = setTimeout("HintBubble.innerHTML = '';",DelaySeconds*1000);
	return;
}
function hintpopupTrigger(item){
	if (HintBubble.preHintTimer != null) {
		window.clearTimeout(HintBubble.preHintTimer);
	}
	if (HintBubble.hintTimer != null) {
		HintBubble.innerHTML = "";
		window.clearTimeout(HintBubble.hintTimer);
	}
	x = window.event.clientX;
	y = window.event.clientY;
	alt = item.alt;
	HintBubble.preHintTimer = setTimeout("hintpopupDisplay(alt,x,y);",1000);
	return;
}
function hint(item){
	window.status = item.alt;
	//hintpopupTrigger(item);
	return true;
}
function closealltreenodes(){
	for (key in document.all) {
		if (document.all[key].className == "folder-Open") {
			//alert(window.event.srcElement.name +" : "+document.all[key].name)
			document.all[key].className = "folder-Closed"
		}
	}
	return;
}

function getXMLHTTPobj (){
	    var xmlhttp
    var resulttext
    var xmlversion;  
    // Find an xml object 
    // IF IE then use the most upto date class ID
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		 try {
		  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
		 } catch (e) {
		  try {
		  xmlhttp=new ActiveXObject("Msxml.XMLHTTP")
		 } catch (e) {
		  try {
		    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		  } catch (E) {
		   xmlhttp=false
		  }
		 }
		}
		@else
		 xmlhttp=false
		@end @*/
	// IF not IE then try using Netscape
		if (!xmlhttp) {
		 try {
		  xmlhttp = new XMLHttpRequest();
		 } catch (e) {
		  xmlhttp=false
		 }
		}
	return xmlhttp;
}
function LoadXML (URL) {
    var xmlhttp
    var resulttext
    var xmlversion;  
	xmlhttp = getXMLHTTPobj ()
	// if we have created an object send the request
	if (xmlhttp) {
		xmlhttp.Open("Get",URL+"&UniqueRequestID="+document.uniqueID+"&xmlversion="+xmlversion , false);
		try {
			xmlhttp.setRequestHeader ("content-type", "text/xml");
			xmlhttp.Send();
		} catch (e) {
			alert ("MS xml component has hung!\n Please check you have all the latest MS upgrades / patches\n"+URL);
		}
		resulttext = xmlhttp.responseText; 
		xmlhttp = null;
		return resulttext;;
	// else alert the user that they are using an unsupport browser
	} else {
		alert("Your browser dosen't support XMLHTTP request");
		return;
	}	
}
function FailedRequest(objectname){
	document.all[objectname+'status'].XMLref.abort(); 
	if (confirm('Unable to connect to server.\nDo you want to retry? ')){
		 document.all[objectname.replace("Menu","")].click();
		 document.all[objectname.replace("Menu","")].click(); 
		 //document.all[objectname+'status'].loadtimeout = setTimeout("FailedRequest('"+objectname+"');",1000);
	}
	return;
}

function doHttpReadyStateChange(xmlhttp,objectname){
	//if (xmlhttp.readyState == 0) {
	  //nothing has been called
	//}
	if (xmlhttp.readyState == 1) {
	  //XMLHTTP open method called but no send called
	  if (!document.all[objectname+'status']) {
		//need to tyde up this
		document.all[objectname].innerHTML = "<li class=item id=\""+objectname+"status\"></li>" +document.all[objectname].innerHTML; 
		window.clearTimeout(document.all[objectname+'status'].statustimeout);
		document.all[objectname+'status'].statustimeout = setTimeout("document.all['"+objectname+"status'].innerHTML = \"Connecting...\";",3000);
		document.all[objectname+'status'].XMLref = xmlhttp;
		document.all[objectname+'status'].loadtimeout = setTimeout("FailedRequest('"+objectname+"');",10000);
	  } else {
		//if (document.all[objectname+'status']) window.clearTimeout(document.all[objectname+'status'].statustimeout);
		//document.all[objectname+'status'].statustimeout = setTimeout("document.all['"+objectname+"status'].innerHTML = \"Connecting...\";",3000);
	  }
	}
	if (xmlhttp.readyState == 2) {
	  //header received but no content 
	  if (document.all[objectname+'status']) window.clearTimeout(document.all[objectname+'status'].statustimeout);
	  document.all[objectname+'status'].statustimeout = setTimeout("document.all['"+objectname+"status'].innerHTML = \"Loading...\";",3000);
	}
	if (xmlhttp.readyState == 3) {
	  // some of the document content is downloaded but not all  
	  if (document.all[objectname+'status']) window.clearTimeout(document.all[objectname+'status'].statustimeout);
	  document.all[objectname+'status'].statustimeout = setTimeout("document.all['"+objectname+"status'].innerHTML = document.all['"+objectname+"status'].innerHTML + \".\";",3000);
	}
	if (xmlhttp.readyState == 4) {
		// All document content has been downloaded
		if (document.all[objectname]) {
			window.clearTimeout(document.all[objectname+'status'].statustimeout);
			window.clearTimeout(document.all[objectname+'status'].loadtimeout);
			document.all[objectname].innerHTML = xmlhttp.responseText;
		}// else {
			//User has navigated else where so lets ignore for now!	
		//}
	}
	return;
}
function LoadXMLasync (URL,nodeid){	
	var xmlhttp;
 	xmlhttp = getXMLHTTPobj ();
	if (xmlhttp) {
		xmlhttp.onreadystatechange = function () { doHttpReadyStateChange (xmlhttp,nodeid+'Menu');};
		xmlhttp.Open("Get",URL+"&UniqueRequestID="+document.uniqueID , true);
 		xmlhttp.setRequestHeader ("content-type", "text/xml");
		xmlhttp.Send();
	} else {
		alert("Your browser dosen't support XMLHTTP request");
	}
	return ;
}
function Loaddata(nodeid) {    
   LoadXMLasync ("menu.asp?nodeid="+nodeid,nodeid);
   return;  //LoadXML ("menu.asp?nodeid="+nodeid);
    
}
function getmenuitems(nodeid){
	if (nodeid + "" != ""){
		LastnodeLoaded = nodeid
		document.body.lastopened = LastnodeLoaded
		if (document.all[nodeid+'Menu'].className == "folder-Open"){
			//document.all[nodeid+'Menu'].innerHTML = Loaddata(nodeid);
			Loaddata(nodeid);
		}else {
			//alert("close");
		}
	}
	return;
}	

function LoadFilteredPageddata (nodeid,PageNo,Filter) {    
   LoadXMLasync ("menu.asp?nodeid="+nodeid+"&listPage="+PageNo+"&filter="+Filter,nodeid);
   return;  //LoadXML ("menu.asp?nodeid="+nodeid);
    
}

function getFilteredPagedmenuitems(nodeid,PageNo,Filter){
	if (nodeid + "" != ""){
		LastnodeLoaded = nodeid
		document.body.lastopened = LastnodeLoaded
		if (document.all[nodeid+'Menu'].className == "folder-Open"){
			//document.all[nodeid+'Menu'].innerHTML = Loaddata(nodeid);
			LoadFilteredPageddata(nodeid,PageNo,Filter);
		}else {
			//alert("close");
		}
	}
	return;
}	

function showMenu(menu){
	var ClassNameSplit;
	if (window.event) {
		if (window.event.srcElement.name == menu.name) {
			//alert(window.event.srcElement.name)
			ClassNameSplit = menu.className.split("-");
			if (ClassNameSplit[1] == "Open"){
				menu.className = ClassNameSplit[0] + "-Closed";
				document.all[menu.name+"Menu"].className = "folder-Closed";
			} else {
				menu.className = ClassNameSplit[0] + "-Open";
				document.all[menu.name+"Menu"].className = "folder-Open";
				getmenuitems(menu.id);
			}
		}else{
			if ((menu.name)&&(menu.name != window.event.srcElement.name+"Menu")){
				ClassNameSplit = menu.parentElement.className.split("-");
				if (ClassNameSplit[1] == "Closed"){
					menu.className = ClassNameSplit[0] + "-Open";
					document.all[menu.name+"Menu"].className = "folder-Open";
					getmenuitems(menu.id);
				}
			}
		}
	}else {
		
		alert('no event');
		/*
		todo : figure out code to map Netscape events to IE event
		document.captureEvents(Event.CLICK);
		alert (e.target);
		window.event = event;
		window.event.fromElement = event.target;
		window.event.toElement = event.target;
		window.event.srcElement = event.target;
		window.event.x = event.x;
		window.event.y = event.y;
		window.event.srcElement.handleEvent(event);
		showMenu(menu);*/
	}
}
function adminopenpage(link){
     parent.top.mainframe.location = link;
     return;
}
function togleMenu () {
	if (getCookie ("simpleMenu") == 'true'){
		  nodynamicmenu (false);
	} else {
		  nodynamicmenu (true);
	}
	return;
}
function nodynamicmenu (trueFalse) {
	document.cookie = "simpleMenu=" + escape(trueFalse) + ";";
	document.frames.menuiframe.document.location = "/admin/menu.asp";
	//document.location = "/admin/menu.asp";
	return;
}
function getCookie (sCookieName)
{
    var sName=sCookieName+"=", ichSt, ichEnd;
    var sCookie=document.cookie;

    if ( sCookie.length && ( -1 != (ichSt = sCookie.indexOf(sName)) ) )
    {
        if (-1 == ( ichEnd = sCookie.indexOf(";",ichSt+sName.length) ) )
            ichEnd = sCookie.length;
        return unescape(sCookie.substring(ichSt+sName.length,ichEnd));
    }
    
    return null;
}

function linkshowMenu(menu){
	var ClassNameSplit;
	if (window.event) {
		if (window.event.srcElement.name == menu.name) {
			ClassNameSplit = menu.parentElement.className.split("-");
			if (ClassNameSplit[1] != "Open"){
				menu.parentElement.className = ClassNameSplit[0] + "-Open";
				document.all[menu.parentElement.name+"Menu"].className = "folder-Open";
				getmenuitems(menu.id);
			} 
		}else{
			if ((menu.name)&&(menu.name != window.event.srcElement.name+"Menu")){
				ClassNameSplit = menu.className.split("-")
				if (ClassNameSplit[1] == "Closed"){
					menu.className = ClassNameSplit[0] + "-Open"; 
					document.all[menu.name+"Menu"].className = "folder-Open";
					getmenuitems(menu.id);
				}
			}
			//alert(window.event.srcElement.name)
		}
	}else {
		alert('no event')
	}
	return
}

function openWindow (newwidth,newheight,link,scrollresize){ 
  if (scrollresize){
	scrolltext=",scrollbars=yes";
	resizetext=",resizable=yes";
  }else{
	scrolltext="";
	resizetext="";
  }
  link = link.replace(/ /,"+");
  if (navigator.userAgent.indexOf("MSIE") >= 0){
		if ((screen.availWidth >= newwidth) && (screen.availHeight >= newheight)){
			popupWin = window.open(link,"remote","left="+((screen.availWidth - newwidth)/2)+",top="+((screen.availHeight - newheight)/2)+",height="+newheight+",width="+newwidth+",titlebar=no,title=no"+resizetext+scrolltext);
		}else {
			popupWin = window.open(link,"remote","left=0,top=0,height="+(screen.availHeight-35)+",width="+(screen.availWidth-10)+",titlebar=yes,scrollbars=yes"+scrolltext);
		}
  }else{
		popupWin = window.open(link,"remote","height=" + newheight + ",width=" + newwidth + ",resizable=yes,titlebar=yes"+resizetext);
  }
  popupWin.focus();
  return;
}
function viewimage (id,width,height){ 
  openWindow (width+20,height+30,"/servercode/showpic.asp?id="+id+"&width="+width+"&height="+height,false);
  return;
}


function selectCategory(theform,strSrcFieldName,strDestFieldName){
	theform.elements[strDestFieldName].value=theform.elements[strSrcFieldName].value;
	theform.submit();
	return;
}

function preview(theform,targeturl){	
	try {
		saveaction = theform.action;
		savetarget = theform.target;
		theform.action = targeturl;
		theform.target="_blank";
		if (theform.onsubmit){
			theform.onsubmit();
		}
		theform.submit();
		theform.action = saveaction;
		theform.target = savetarget;
	} catch (exCaughtException) {
		alert ("Error previewing form because "+exCaughtException.description+" Source:"+exCaughtException.Source );
	}
	return;
}
function AddSelectOption(selectbox,optionvalue,optionname){
	var oOption = document.createElement("OPTION");
	document.all(selectbox).options.add(oOption);
	oOption.innerText = optionname;
	oOption.value = optionvalue;
	oOption.selected = true;
	document.all(selectbox).onchange();
	//return;
}
function AddImageSelectOption(selectbox,optionvalue,optionname,width,height){
	var oOption = document.createElement("OPTION");
	document.all(selectbox).options.add(oOption);
	oOption.innerText = optionname;
	oOption.value = optionvalue;
	oOption.PictureWidth = width;
	oOption.PictureHeight = height;
	oOption.selected = true;
	document.all(selectbox).onchange();
	//return;
}
function uploadimage (inputboxname,pictureID,pictureName){
	var args = pictureID+','+pictureName;
	var id_namearray;
	var id;
	var name;
	var width;
	var height;
	dialogoptions = 'dialogHeight: 175px; dialogWidth: 400px; edge: Raised; center: Yes; help: No; resizable: No; status: No;';
	id_name = window.showModalDialog('/admin/images/uploaddialogue.asp',args,dialogoptions);
	if ((id_name != undefined) && (id_name + "" != "")){
		if ((inputboxname != undefined) && (inputboxname + "" != "")){
			id_namearray = id_name.split(",");
			id = id_namearray[0];
			name = id_namearray[1];
			width = id_namearray[2];
			height = id_namearray[3];
			AddImageSelectOption(inputboxname,id,name,width,height);
		}
	}else {
	}
}
function uploaddocument (inputboxname,documentID,documentName){
	var args = documentID+','+documentName;
	var id_namearray;
	var id;
	var name;
	dialogoptions = 'dialogHeight: 150px; dialogWidth: 400px; edge: Raised; center: Yes; help: No; resizable: No; status: No;';
	id_name = window.showModalDialog('/admin/documents/uploaddialogue.asp',args,dialogoptions);
	if ((id_name != undefined) && (id_name + "" != "")){
		if ((inputboxname != undefined) && (inputboxname + "" != "")){
			id_namearray = id_name.split(",");
			id = id_namearray[0];
			name = id_namearray[1];
			AddSelectOption(inputboxname,id,name);
		}
		return true;
	}else {
		return false;
	}
}

function trim(theString){
	var result;
	// Performs a leading and trailing whitespace trim (inc. space, tab, formfeed etc).
	// .exec returns an array with element [0] being the whole match and [1] to [n] being the submatches.
	// Fortunately for us, the first submatch is the string we require.
	try { 
		result = /^\s*(.*\S|.*)\s*$/.exec(theString)[1];
	}catch(myerror){ //if the patten returns no match (nothing to trim then we return the origanal)
		result = theString
	}
	return result
}
function htmlsafe(theString){
	// replace " charactors with &quot;
	var re;
	re = /\"/g;  //g indicates Global search
	return theString.replace(re,"&quot;");
}
function reportscripterror (errorObject){
	LoadXML ("/servercode/customerrors/scripterror.asp?number="+(errorObject.number& 0xFFFF)+"&name="+errorObject.name+"&message="+errorObject.message+"&description="+errorObject.description);
	return;
}
function openlogon (){
	var selection
	var Link
	dialogoptions = 'dialogHeight: 298px; dialogWidth: 595px; edge: Raised; center: Yes; help: No; resizable: No; status: No;';
	Link = window.showModalDialog('/admin/logon/logondialogue.asp'+"?UniqueRequestID="+document.uniqueID,selection,dialogoptions);	
	document.location.reload(true);
}


