//Stuff to hide <selects> from the actionspanel
if(browserIsIE())
{
	window.attachEvent('onload', recalcActionsPanel);
	window.attachEvent('onresize', recalcActionsPanel);
	window.attachEvent('onscroll', recalcActionsPanel);
}
function hideAllSelects()
{
	var selects = document.getElementsByTagName("select");
	for(i=0; i<selects.length; i++)
	{
		selects[i].style.visibility="hidden";
	}
}
function hideSelectsFromActions()
{
	var selects = document.getElementsByTagName("select");
	for(i=0; i<selects.length; i++)
	{
		checkAndHide(selects[i]);
	}
}
function checkAndHide(daSelect)
{
	var daActionsObj = document.getElementById("actionsContainer");
	daSelect.style.visibility = (findPosY(daSelect)>(findPosY(daActionsObj))-20)?"hidden":"visible";
}
function findPosY(obj)
{
	if(obj==null) return;
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
// END Stuff to hide <selects> from the actionspanel

//Function to recalculation the position and width/height for the iframe
//that provides <select>-hiding on IE.
//INACTIVATED as it does not seem to work as intended on Win2K
function recalcActionsPanel()
{
	horizontalScroll = false;
	if(document.body.clientWidth<document.body.scrollWidth)
	{
		horizontalScroll = true;
	}
		
	if(document.getElementById("actionsContainer")==null){ return; }
	daIFrameStyleObj = document.getElementById("actionsIFrame").style;
	daActionsStyleObj = document.getElementById("actionsContainer").style;
	
	daTopValue = document.body.scrollTop + document.body.offsetHeight - getActionsHeight() - 5;
	if(horizontalScroll)
	{
		daTopValue = daTopValue - 20;
	}
	
	daIFrameStyleObj.top = daTopValue;
	daIFrameStyleObj.height = getActionsHeight() + 1;
	daIFrameStyleObj.width = document.body.offsetWidth - 50;
	daActionsStyleObj.top = daTopValue;
	
	//Illogical and stupid hack to make IE not mess upp all <select>s on the page when scrolling.
	var selects = document.getElementsByTagName("select");
	if(selects.length!=0) selects[0].style.fontFamily=selects[0].style.fontFamily;
}

//Function to check for Internet Explorer
function browserIsIE()
{
	ie = document.all?true:false;
	return ie;
}

//This function is called from the function recalcActionsPanel (MSIE only)
//IMPORTANT: Whenever the height of the actions panel is 
//changed dynamically on the client, daActionsHeight should 
//be reset to null. The value will then be recalculated automatically.
var daActionsHeight = null;
function getActionsHeight()
{
	if(daActionsHeight==null)
	{
		daActionsObj = document.getElementById("actionsContainer");
		daActionsHeight = daActionsObj.clientHeight;
		return daActionsHeight;
	}
	else
	{
		return daActionsHeight;
	}
}

//Called from Recordlist.ascx
//"check all checkboxes"-behaviour
function InitCheckAll()
{
	x=0;
	listIsEmpty = true;
	inputArr = document.getElementsByTagName("input");
	for(i=0;i<inputArr.length;i++)
	{
		if (inputArr[i].type=="checkbox" && inputArr[i].name.indexOf(SearchCbId) != -1)
		{
			listIsEmpty = false;
			if(!inputArr[i].checked)
			{
				x++;
			}
		}
	}
	if (x==0 && !listIsEmpty)
	{
		try{document.getElementById(CheckAllId).checked = true;}catch(ex){}
	}
}

//Function to disable/enable actions on the basis of what is selected in the recordlist
function UpdateActions(selectionType)
{
	daActionsObj = document.getElementById("actionsContainer");
	if(daActionsObj==null) return;
	
	daHiddens = daActionsObj.getElementsByTagName("input");
	for(i=0;i<daHiddens.length;i++)
	{
		hdn = daHiddens[i];
		if(hdn.type=="hidden" && hdn.id.indexOf("hdnselectionTypeAllowed") != -1)
		{
			typeAllowed=hdn.value;
			if(typeAllowed!="")
			{
				daActionsObj = hdn.parentNode.getElementsByTagName("a")[0];
				if(selectionType=="0")
				{					
					disableAction(daActionsObj);
				}
				else if(typeAllowed=="1" && selectionType=="2")
				{
					disableAction(daActionsObj);
				}			
				else
				{
					enableAction(daActionsObj);
				}	
			}
		}
	}
}
//Helper function to UpdateActions
function disableAction(daObj)
{
	if(!daObj) return;
	if(daObj.className.indexOf("disabled") == -1)
	{
		daObj.className += " disabled";
	}
	daObj.disabled=true;
}
//Helper function to UpdateActions
function enableAction(daObj)
{
    if(daObj != null)
    {
        daObj.className = daObj.className.replace("disabled","");
        daObj.disabled=false;
    }
}

//Default function to confirm delete operations
//Can be overridden in individual pages
function ConfirmDelete(daObj)
{
	if(ActionIsDisabled(daObj)) return false;
	return confirm(strConfirm);
}

//Confirms if a number of translations should be approved
function ConfirmApprove(daObj)
{
	if(ActionIsDisabled(daObj)) return false;
	return confirm(strConfirmApprove);
}

//Confirms if a number of translations should be disapproved
function ConfirmDisapprove(daObj)
{
	if(ActionIsDisabled(daObj)) return false;
	return confirm(strConfirmDisapprove);
}

//Default function to confirm "Common properties" operations.
//Might be used elsewhere too.
function ConfirmUpdate()
{
	return confirm(strConfirm);
}

//Function to check for selected items
function CheckSelection(daObj)
{
	daObj.blur();
	if(ActionIsDisabled(daObj)) return false;
}

//Function to check for selected items, perform confirmation and showing the processing message
//Called from the wizardpanel
function CheckWizardSelection(daObj, doShowProcessingMessage, doConfirm)
{
	daObj.blur();
	
	returnValue = false;
	if(!ActionIsDisabled(daObj))
	{
		returnValue = true;
	}
	if(doConfirm)
	{
		returnValue = ConfirmDelete(daObj);
	}
	if(returnValue)
	{
		if(doShowProcessingMessage)
		{
			ShowProcessingMessage();
		}
		return true
	}
	else
	{
		return false;
	}
}

//Function to check for selected items. If selection is correct, disable page links and show processing message
function CheckSelectionAndStartOperation(daObj)
{
	if(!ActionIsDisabled(daObj))
	{
		StartOperation();
		return true;
	}
	else
	{
		return false;
	}
}

//Disables page links and shows processing message
function StartOperation()
{
	disableAdminPage(); 
	ShowProcessingMessage();
	return true;
}

//Receives oncheck event from the TreeView and updates the nrOfCheckedTreeNodes variable accordingly
function onClientCheck(node)
{
	switch(node.isChecked())
	{
		case true: 
			nrOfCheckedTreeNodes++;
			break;
		case false:
			nrOfCheckedTreeNodes--;
			break;
	}
	UpdateActionsForTree()
}

function onClientCheckNoAction(node)
{
	switch(node.isChecked())
	{
		case true: 
			nrOfCheckedTreeNodes++;
			break;
		case false:
			nrOfCheckedTreeNodes--;
			break;
	}
}

//Updates actions based on what is selected in the tree
function UpdateActionsForTree()
{
	if(nrOfCheckedTreeNodes <= 0)
	{
		UpdateActions("0");
	}
	else if(nrOfCheckedTreeNodes == 1)
	{
		UpdateActions("1");
	}
	else if(nrOfCheckedTreeNodes > 1)
	{
		UpdateActions("2");
	}
}

//Initializes the tree to handle updating of actions based on what is selected in the tree
function InitNrOfCheckedTreeNodes()
{
	nrOfCheckedTreeNodes = 0;
	TreeView1.uncheckAll();
	UpdateActionsForTree();
}

//Function to check if an action is disabled
function ActionIsDisabled(daObj)
{
	if(daObj.className!=null)
	{
		return(daObj.className.indexOf("disabled") != -1);
	}
	else
	{
		return true;
	}
}

//Used to simulate radiobutton-group functionality
//Called from roles
function SelectSingleRb(rbToSelect,rbString)
{
	inputArr = document.getElementsByTagName("input");
	for(i=0;i<inputArr.length;i++)
	{
		if (inputArr[i].type=="radio" && inputArr[i].name.indexOf(rbString) != -1)
			inputArr[i].checked = false;
	}
	rbToSelect.checked = true;
	window.status = rbToSelect.value;
}

//Functions to check what is selected in the recordlist
function StatusCheckedInRecordList()
{
	if(typeof(getRememberSelection) != "undefined" && getRememberSelection())
	{
		try{counterValue = parseInt(document.getElementById(CounterId).innerHTML);}
		catch(e){return "0";}
		if(counterValue==1)
		{
			return "1";
		}
		else if(counterValue>1)
		{
			return "2";
		}
	}
	else
	{
		x=0;
		inputArr = document.getElementsByTagName("input");
		
		//loop through all checkboxes to count the objects selected
		for(i=0;i<inputArr.length;i++)
		{
			//if (inputArr[i].type=="checkbox" && inputArr[i].name.indexOf(SearchCbId) != -1)
			if (inputArr[i].type=="checkbox" && inputArr[i].name.indexOf("chkRecordListCheckBox") != -1)
			{
				if(inputArr[i].checked)
				{
					x++;
				}
			}
		}
		
		if(x==1)
		{
			return "1";
		}
		else if(x>1)
		{
			return "2";
		}
		else
		{
			return "0";
		}
	}
}
//END Functions to check if anything is selected in the recordlist

//Updates the counter for selected objects.
//Called in Recordlist.ascx
function CounterChange(daStatus,updateActions)
{
	daObj = document.getElementById(CounterId);
	currentNr = parseInt(daObj.innerHTML);
	if(daStatus)
		currentNr++;
	else 
		if(currentNr > 0)
			currentNr--;
	daObj.innerHTML = currentNr;
	
	if(!updateActions) return;
	
	if(currentNr==0)
	{
		UpdateActions("0");
	}
	else if(currentNr==1)
	{
		UpdateActions("1");
	}
	else if(currentNr>1)
	{
		UpdateActions("2");
	}
}

//Used in recordlist.ascx to perform a client side callback. Updates the value in the "selected items"-counter
function InitSelectedCount(counterXmlUrl,pageId)
{
	if(!xmlhttp || xmlhttp==null)
		return;
	if(callInProgress(xmlhttp))
		return;
	
	myRandom=parseInt(Math.random()*99999999);
	myUrl = counterXmlUrl + "?random=" + myRandom + "&id=" + pageId;
	
	xmlhttp.open("GET", myUrl, true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			if(xmlhttp.status!=200)
			{
				return;
			}
			else
			{
				if(xmlhttp.responseText.indexOf("<html>") == -1 && xmlhttp.responseText.indexOf("<html>") == -1)
				{
					document.getElementById(CounterId).innerHTML = xmlhttp.responseText;
					document.getElementById(CounterId).style.visibility="visible";
					
					if(xmlhttp.responseText == "0")
					{
						CheckAll(false);
						UpdateActions("0");
					}
					else if(xmlhttp.responseText == "1")
					{
						UpdateActions("1");
					}
					else if(Number(xmlhttp.responseText) > 1)
					{
						UpdateActions("2");
					}
				}
			}
		}
	}
	xmlhttp.send(null);
}

//Checkbox behaviour. Called in Recordlist.ascx
//Selects/deselects all checkboxes and updates the counter
function CheckAll(valueToSet)
{
	inputArr = document.getElementsByTagName("input");
	for(i=0;i<inputArr.length;i++)
	{
		if (inputArr[i].type=="checkbox" && inputArr[i].name.indexOf(SearchCbId) != -1)
		{
		    //This used to not check for if the checkbox was already checked, thus making it counted more than once in total, fixed for 2.5 Nisse
			if(inputArr[i].checked != valueToSet){
			    inputArr[i].checked = valueToSet;
			    CounterChange(valueToSet);
			}
		}
	}
	daObj = document.getElementById(CounterId);
	currentNr = Number(daObj.innerHTML);
	if(currentNr==0)
	{
		UpdateActions("0");
	}
	else if(currentNr==1)
	{
		UpdateActions("1");
	}
	else if(currentNr>1)
	{
		UpdateActions("2");
	}
}

//Checkbox behaviour. Called in Recordlist.ascx
//Updates the counter for selected objects
function CheckMe(me,reverse)
{
	if (me.checked)
	{		
		if (reverse)
		{
			CounterChange(false,true);
		}
		else
		{	
			CounterChange(true,true);
		}
	}
	else
	{
		if (reverse)
		{
			try{document.getElementById(CheckAllId).checked = false;}catch(ex){}
			CounterChange(true,true);
		}
		else
		{
			try{document.getElementById(CheckAllId).checked = false;}catch(ex){}
			CounterChange(false,true);
		}
	}
}

//Used in course catalogue and news
function CheckMeNoCounter(me, masterCb)
{
	if (!me.checked)
	{
		document.getElementById(masterCb).checked = false;
	}
}

//Used in course catalogue and news
function CheckAll2(masterCb,cbString)
{
	inputArr = document.getElementsByTagName("input");
	for(i=0;i<inputArr.length;i++)
	{
		if (inputArr[i].type=="checkbox" && inputArr[i].name.indexOf(cbString) != -1)
			inputArr[i].checked = masterCb.checked;
	}
}

//Used for course catalogue and news
function CheckAnythingChecked(ctrl, msgNothingChecked, msgConfirm) {
	var chkArray = document.getElementsByTagName("input");
	
	for(i=0; i<chkArray.length; i++)
	{
		if((chkArray[i].id.indexOf(ctrl) != '-1'))
		{
			if(chkArray[i].checked)
			{
				return confirm(msgConfirm);
			}
		}
	}
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedAndProcess(ctrl, msgNothingChecked)
{
	var chkArray = document.getElementsByTagName("input");
	
	for(i=0; i<chkArray.length; i++)
	{
		if((chkArray[i].id.indexOf(ctrl) != '-1'))
		{
			if(chkArray[i].checked)
			{
				return ShowProcessingMessage();
			}
		}
	}
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedNoProcess(ctrl, msgNothingChecked)
{
	var chkArray = document.getElementsByTagName("input");
	
	for(i=0; i<chkArray.length; i++)
	{
		if((chkArray[i].id.indexOf(ctrl) != '-1'))
		{
			if(chkArray[i].checked)
			{
				return true;
			}
		}
	}
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedInTreeAndProcess(ctrl, msgNothingChecked)
{
	if(nrOfCheckedTreeNodes > 0)
	{
		return ShowProcessingMessage();
	}
	
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedInTree(ctrl, msgNothingChecked)
{
	if(nrOfCheckedTreeNodes > 0)
	{
	    return true;
	}
	
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedInTreeAndConfirm(ctrl, msgNothingChecked, msgconfirm)
{
	if(nrOfCheckedTreeNodes > 0)
	{
	    return confirm(msgconfirm);
	}
	
	alert(msgNothingChecked);
	return false;
}

function CheckAnythingCheckedInTreeOnlyOneAllowed(ctrl, msgNothingChecked, msgSelectOneOnly)
{
	if(nrOfCheckedTreeNodes > 0)
	{
		if(nrOfCheckedTreeNodes > 1)
		{
		    alert(msgSelectOneOnly);
		    return false;
		}
		return true;
	}
	
	alert(msgNothingChecked);
	return false;
}

//Used to check if any checkbox is checked in a specific object.
function CheckAnyChecked(msgNothingChecked, msgConfirm, objId)
{	
	var rootObj = document;
	if(objId!=null)
	{
		rootObj = document.getElementById(objId);
		if(rootObj==null)
			return false;
	}
	var chkArray = rootObj.getElementsByTagName("input");
	
	for(i=0; i<chkArray.length; i++)
	{
		if(chkArray[i].type=="checkbox")
		{
			if(chkArray[i].checked)
			{
				if(msgConfirm != "")
					return confirm(msgConfirm);
				else
					return true;
			}
		}
	}
	alert(msgNothingChecked);
	return false;
}

//This returns the nr of checked checkboxes in a specific object
function CheckNrOfChecked(objId)
{
	var rootObj = document;
	var nrOfCheckedInObj = 0;
	if(objId!=null)
	{
		rootObj = document.getElementById(objId);
		if(rootObj==null)
			return false;
	}
	var chkArray = rootObj.getElementsByTagName("input");
	
	for(i=0; i<chkArray.length; i++)
	{
		if(chkArray[i].type=="checkbox")
		{
			if(chkArray[i].checked)
			{
				nrOfCheckedInObj++;
			}
		}
	}
	return nrOfCheckedInObj;
}

//Gets the id of the first checked checkbox in the recordlist
function getSingleRecordListCheckboxId()
{
	objArr = document.getElementsByTagName("input");
	for(i=0;i<objArr.length;i++)
	{
		if(objArr[i].type=="hidden" && objArr[i].name.indexOf("hdnID")>=1 && objArr[i].value!="")
		{
			currentCB = objArr[i].parentNode.getElementsByTagName("input")[0];
			if(currentCB.checked)
			{
				return objArr[i].value;
			}
		}
	}
	return null;
}

//This opens the help window
//Called from various places
function OpenHelpWin(url)
{
	window.open(url,"","width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes");
}

//This opens the report window
//Called from various places in the report generator
function OpenReportWin(url)
{
	window.open(url,"","width=980,height=750,toolbar=no,scrollbars=yes,resizable=yes");
}

//This opens a window for listing dependencies
//Called from various pages
function OpenDependenciesWin(url)
{
	window.open(url,"","width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes,status=yes");
	return false;
}

//This opens a window for listing selected entities
//Called from Recordlist
function EntititiesWin(url)
{
	return window.open(url,"","width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes,status=yes");
}

//Opens a new window
function OpenWin(url,width,height)
{
	return window.open(url,"","width=" + width + ",height=" + height +",toolbar=no,scrollbars=yes,resizable=yes,status=no");
}

//This activates the "processing"-message for long operations
function ShowProcessingMessage(){	
	disableAllLinks();
	if(browserIsIE())
	{
		hideAllSelects();
	}
	myBody = document.getElementsByTagName("body")[0];
	myBody.style.cursor = "wait";
	
	if(document.getElementById("div-processing")==null)
	{
		processingDiv=document.createElement("div");
		processingDiv.className = "processing";
		myBody.appendChild(processingDiv);
		processingText = "Processing";
	}
	else
	{
		processingDiv = document.getElementById("div-processing");
		processingDiv.style.display="block";
		processingText = processingDiv.innerHTML;
		processingDiv.innerHTML = "";
	}
	
	newDiv2=document.createElement("div");
	newDiv2.className = "processing-bg";
	myBody.appendChild(newDiv2);
	
	newP=document.createElement("p");
	newP.id = "waitingText";
	newP.className = "text";
	newP.innerHTML = processingText;
	processingDiv.appendChild(newP);
	
	newP=document.createElement("p");
	newP.id = "waitingDots";
	newP.innerHTML = ".";
	newP.className = "dots";	
	processingDiv.appendChild(newP);
	
	setTimeout("fixWaitingDots()",500);
	
	return true;
}

//This animates the dots in the "processing"-message
function fixWaitingDots()
{
	daObj = document.getElementById("waitingDots");
	if(daObj.innerHTML=="")
	{
		daObj.innerHTML=".";
		
	}
	else if(daObj.innerHTML==".")
	{
		daObj.innerHTML="..";
	}
	else if(daObj.innerHTML=="..")
	{
		daObj.innerHTML="...";
	}
	else if(daObj.innerHTML=="...")
	{
		daObj.innerHTML="....";
	}
	else if(daObj.innerHTML=="....")
	{
		daObj.innerHTML=".....";
	}
	else if(daObj.innerHTML==".....")
	{
		daObj.innerHTML=".";
	}
	setTimeout("fixWaitingDots()",500);
}

//The usual "close window"-function
function closeWindow()
{
	window.close();
	return false;
}

//function to reveal advanced actions
function showHideAdvancedActions(daSender)
{
	daActionsHeight = null;
	
	divArr = document.getElementsByTagName("div");
	for(i=0;i<divArr.length;i++)
	{
		if (divArr[i].id.indexOf("divAdvancedActions") != -1)
		{
			daObj = divArr[i];
		}
	}
	
	if(daObj.style.display=="none")
	{
		daObj.style.display="block";
		daSender.className=daSender.className.replace(" closed", " open");
	}
	else
	{
		daObj.style.display="none";
		daSender.className=daSender.className.replace(" open", " closed");
	}
	if(browserIsIE()) {recalcActionsPanel();}
	
	daSender.blur();
	document.getElementById(advancedActionsId).value = (daObj.style.display=="block");
	return false;
}

//Disables all page links in LUVIT Admin
function disableAdminPage()
{
	objArr = new Array();
	try	
	{ 	
	    if(document.getElementById("topbarContainer") == null)
	        return;
	        
	    objArr = document.getElementById("topbarContainer").getElementsByTagName("a"); 
	}
	catch(e){}	
	for(i=0;i<objArr.length;i++)
	{
		disableOneLink(objArr[i]);
	}
	
	objArr2 = new Array();
	try	
	{ 
	        if(document.getElementById("menuContainer") == null)	    
	            return;
	            
	        objArr2 = document.getElementById("menuContainer").getElementsByTagName("td"); 
	}
	catch(e){}
	for(i=0;i<objArr2.length;i++)
	{
		objArr2[i].style.color = "#999999";
		//objArr2[i].onmouseover = function(){return false;}
	}
	objMenuContainer = document.getElementById("menuContainer");
	objMenuDisabler = document.getElementById("fastMenuDisabler");
	objMenuDisabler.style.width = objMenuContainer.clientWidth + "px";
	objMenuDisabler.style.height = objMenuContainer.clientHeight + "px";
	objMenuDisabler.style.display = "block";
}

//Function to disable all links on a page
function disableAllLinks()
{
	daObjArr = document.getElementsByTagName("a");
	for(i=0;i<daObjArr.length;i++)
	{
		daObjArr[i].className += " disabled";
		daObjArr[i].disabled = true;
		daObjArr[i].onclick = function(){return false};
	}
}

//Function to disable a specific link on a page
function disableOneLink(daObj)
{
	daObj.className += " disabled";
	daObj.disabled = true;
	daObj.onclick = function(){return false};
}

function openWinInCenter(url,width,height,usemenu)
{
	if(width==null) width = 800;
	if(height==null) height = 600;
	winAttributes = ',status=1,toolbar=0,scrollbars=1,resizable=1';
	if(usemenu != null && usemenu==true) winAttributes += ",menubar=1";
	
	//This opens the window centered
	var n = window.open(url,'','width=' + width + ',height=' + height + ',left=' + (screen.width-width) / 2 + ',top=' + (screen.height-height) / 3 + winAttributes);
	
	//This does not position the new window
	//var n = window.open(url,'','width=' + width + ',height=' + height + winAttributes);
	
	n.focus();
}

function OpenPortalWin(url)
{
	objWin = window.open(url, "_luvitPortalWin");
	objWin.focus();
	return false;
}

//Function to check the length of the contents in a textfield and return false if it exceeds a given length
function checkLength(e,maxlen)
{
	if (e.value.length > maxlen)
    {
		if (e.value.length > maxlen)
			e.value = e.value.substr(0,maxlen)
		return false;
    }
}

//Function to dynamically add onload-events to document body
function addLoadEvent(func) 
{
  addEvent(window,"load",func);
  
  /*
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else
  {
    window.onload = function() 
    {
      oldonload();
      func();
    }
  }
  */
}

//Scott Andrew's cross browser event handling code
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be attached");
  }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be removed");
  }
}
//END Scott Andrew's cross browser event handling code


var xmlhttp=getXmlHttpRequestObj();
function getXmlHttpRequestObj()
{
	//CODE TO CREATE XMLHTTPREQUEST OBJECT
	var daObj = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try 
	{
		daObj = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			daObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E)
		{
			daObj = false;
		}
	}
	@end @*/
	if (!daObj && typeof XMLHttpRequest!='undefined')
	{
		daObj = new XMLHttpRequest();
	}
	if(!daObj && browserIsIE())
		alert("Could not create the xml object. To use this page you must adjust the security settings in your browser to \"medium\"");
	
	return daObj;
	//END CODE TO CREATE XMLHTTPREQUEST OBJECT
}

function doXmlHttpCallBack(sendMethod,url,returnFunction)
{
	newXmlObj = getXmlHttpRequestObj();
	newXmlObj.open(sendMethod, url, true);
	newXmlObj.onreadystatechange=function()
	{
		if (newXmlObj.readyState==4)
		{
			if(newXmlObj.status!=200)
			{
				return;
			}
			else
			{
				if(returnFunction != null)
				{
					eval(returnFunction + "('" + newXmlObj.responseText + "');");
				}
			}
		}
	}
	newXmlObj.send(null);
}

//This hooks up a fixed version of WebForm_FireDefaultButton ;
try { addEvent(window, "load", SetNewDefaultButtonScript); } catch(ex){}
var __defaultFired = false; //Fix after.NET patch 2006-10

function SetNewDefaultButtonScriptBase()
{
    __defaultFired = false;
	WebForm_FireDefaultButton = WebForm_FireDefaultButton_LUVIT;
}

function SetNewDefaultButtonScript()
{
	WebForm_FireDefaultButton = WebForm_FireDefaultButton_LUVIT;
}

function WebForm_FireDefaultButton_LUVIT(event, target) {
	if (!__defaultFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
		var defaultButton;
		if (__nonMSDOMBrowser) {
			defaultButton = document.getElementById(target);
		}
		else {
			defaultButton = document.all[target];
		}
		if (defaultButton && typeof(defaultButton.click) != "undefined") {
			__defaultFired = true;
			defaultButton.click();
			event.cancelBubble = true;
			if (event.stopPropagation) event.stopPropagation();
			return false;
		}
		else if(defaultButton && defaultButton.tagName.toLowerCase() == "a") {
			//We're dealing with a linkbutton and must activate the href, rather than triggering the click event
			eval(defaultButton.href);
			//top.location = defaultButton.href;
			event.cancelBubble = true;
			if (event.stopPropagation) event.stopPropagation();
			return false;
		}
	}
}
