onload = function(E,u,l) {  if (opener) { window.setTimeout("opener.blockEvents();",300); } }
onbeforeunload = function(E,u,l) { if (opener == null) {  checkSavedDocument(E);} }
onunload = function(E,u,l) { if (opener) {  window.setTimeout("opener.unblockEvents();",300); } }
var real_events = new Array("onclick", "onmouseover", "onmouseout", "ondblclick", "ondrag", "ondragend", "onkeydown", "onkeypress", "onkeyup", "onmousedown", "onmouseenter", "onmouseleave", "onmouseup", "onpropertychange");
var fake_events = new Array("_onclick", "_onmouseover", "_onmouseout", "_ondblclick", "_ondrag", "_ondragend", "_onkeydown", "_onkeypress", "_onkeyup", "_onmousedown", "_onmouseenter", "_onmouseleave", "_onmouseup", "_onpropertychange");




function TreeViewSelectNode(pid,id) {
	try{
		var hiddens = document.getElementsByTagName('INPUT');
		var selectedPID = document.getElementById('TreeViewControlSelectedPID');
		if (selectedPID == null) {
			for (var i = 0; i < hiddens.length; i++) {
				var tmpID = hiddens[i].getAttribute('id');
				if(tmpID != null){
					var pos = tmpID.indexOf('TreeViewControlSelectedPID');
					if (pos >= 0 && tmpID.substring(pos) == 'TreeViewControlSelectedPID') {
						selectedPID = hiddens[i];
						break;
					}
				}
			}
		}
		var selectedID = document.getElementById('TreeViewControlSelectedID');
		if (selectedID == null) {
			for (var i = 0; i < hiddens.length; i++) {
				var tmpID = hiddens[i].getAttribute('id');
				if(tmpID != null){
					var pos = tmpID.indexOf('TreeViewControlSelectedID');
					if (pos >= 0 && tmpID.substring(pos) == 'TreeViewControlSelectedID') {
						selectedID = hiddens[i];
						break;
					}
				}
			}
		}
		if (selectedPID != null && selectedID != null) {
			var spans = document.getElementsByTagName('SPAN');
			for (var i = 0; i < spans.length; i++) {
				var tmpID = spans[i].getAttribute('id');
				if(tmpID != null){
					var pos = tmpID.indexOf('treeNode_');
					if (pos == 0) {
						spans[i].className = 'cms_blue';
					}
				}
			}
			
			selectedPID.value = pid;
			selectedID.value = id;
		}
		obj = document.getElementById('treeNode_' + pid + '_' + id);
		obj.className = 'cms_black';
	}catch(e){}
	
	
}

function nodeSelect(node)
{ 
	var curNode = ctl00_TreeViewControltreeview.FindNodeById(node);
	ctl00_TreeViewControltreeview.SelectedNode = curNode;
	curNode.ExpandAncestors();
	ctl00_TreeViewControltreeview.Render();	
}
	

//*** WARNING: only to be used when running for the first time ***//
function TreeViewSelectNodeID(id) {
	try{
		var hiddens = document.getElementsByTagName('INPUT');
		var selectedID = document.getElementById('TreeViewControlSelectedID');
		if (selectedID == null) {
			for (var i = 0; i < hiddens.length; i++) {
				var tmpID = hiddens[i].getAttribute('id');
				var pos = tmpID.indexOf('TreeViewControlSelectedID');
				if (pos >= 0 && tmpID.substring(pos) == 'TreeViewControlSelectedID') {
					selectedID = hiddens[i];
					break;
				}
			}
		}
		if (selectedID != null) {
			var spans = document.getElementsByTagName('SPAN');
			for (var i = 0; i < spans.length; i++) {
				var tmpID = spans[i].getAttribute('id');
				var pos = tmpID.indexOf('treeNode_');
				var pos2 = tmpID.indexOf('_' + id);
				if (pos == 0 && tmpID.substring(pos2) == '_' + id) {
					spans[i].className = 'cms_black';
				}
			}
			selectedID.value = id;
		}
	}catch(e){}
}

function Dialog(URL, wdt, hgt, dName) {
	if (dName == null || dName == '') {
		dName = 'elementDialog';
	}
	if (dName == 'elementPreview') {
		window.open(URL, dName, "left=" + (screen.width - wdt) / 2 + ",top=" + (screen.height - hgt) / 2 + ",resizable=yes, scrollbars=yes, status=yes, scrollbars=yes, address=no, width=" + wdt + ",height=" + hgt);
	} else {
		openDialog(URL, wdt, hgt, dName);
	}
}

/**********************************************************************
  BEGIN MODAL DIALOG CODE (can also be loaded as external .js file)
***********************************************************************/
// Global for brower version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))

// One object tracks the current modal dialog opened from this window.
var dialogWin;

/// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    args -- [optional] any data you need to pass to the dialog
function openDialog(url, width, height, dName2, force) {
	top.dialogWin = new Object();
	if (top.dialogWin != null && (!top.dialogWin.win || (top.dialogWin.win && top.dialogWin.win.closed) || (force != null && force==true))) {
		// Initialize properties of the modal dialog object.
		//top.dialogWin.returnFunc = ""
		//top.dialogWin.returnedValue = ""
		//top.dialogWin.args = ""
		top.dialogWin.url = url
		top.dialogWin.width = width
		top.dialogWin.height = height
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		top.dialogWin.name = dName2;
		// Assemble window attributes and try to center the dialog.
		if (Nav4) {
			// Center on the main window.
			top.dialogWin.left = window.screenX +
			   ((window.outerWidth - top.dialogWin.width) / 2)
			top.dialogWin.top = window.screenY +
			   ((window.outerHeight - top.dialogWin.height) / 2)
			var attr = "screenX=" + top.dialogWin.left +
			   ",screenY=" + top.dialogWin.top + ",resizable=yes, menubar=no, status=yes, location=no, scrollbars=yes, address=no, modal=yes, width=" +
			   top.dialogWin.width + ",height=" + top.dialogWin.height
		} else {
			// The best we can do is center in screen.
			top.dialogWin.left = (screen.width - top.dialogWin.width) / 2
			top.dialogWin.top = (screen.height - top.dialogWin.height) / 2
			var attr = "left=" + top.dialogWin.left + ",top=" +
			   top.dialogWin.top + ",resizable=yes, scrollbars=yes, menubar=no, status=yes, location=no, scrollbars=yes, address=no, modal=yes, width=" + top.dialogWin.width +
			   ",height=" + top.dialogWin.height
		}

        //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");

		// Generate the dialog and make sure it has focus.
		top.dialogWin.win=window.open(top.dialogWin.url,dName2, attr);
	
	    if (top.dialogWin.win != null)
		{
		    top.dialogWin.win.focus();
		}
		else
		{
		    alert("Popup prevented - Check that popups are allowed for site and the google toolbar disabled if you are using IE 6");
		}
		    
	} else {
	    if (top.dialogWin.win != null)
		{
		    top.dialogWin.win.focus();
		}
		else
		{
		    alert("Popup prevented - Check that popups are allowed for site and the google toolbar disabled if you are using IE 6");
		}
	}

}


// Event handler to inhibit Navigator form element
// and IE link activity when dialog window is active.
function deadend() {
	if (top.dialogWin.win && !top.dialogWin.win.closed) {
		top.dialogWin.win.focus()
		return false
	}
}

// Since links in IE4 cannot be disabled, preserve
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks = "";

// Disable form elements and links in all frames for IE.
function disableForms() {
	IELinkClicks = new Array();
	

   

	for (var h = 0; h < frames.length; h++) {
   
		for (var i = 0; i < frames[h].document.forms.length; i++) {
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				
				//if (frames[h].document.forms[i].elements[j].getAttibute("persist") != null)
			//	{
				
				    frames[h].document.forms[i].elements[j].disabled = true;
			//	}
			}
		}
		IELinkClicks[h] = new Array();
		for (i = 0; i < frames[h].document.links.length; i++) {
			IELinkClicks[h][i] = frames[h].document.links[i].onclick;
			frames[h].document.links[i].onclick = deadend;
		}
	}
}

// Restore IE form elements and links to normal behavior.
function enableForms() {
	for (var h = 0; h < frames.length; h++) {
		for (var i = 0; i < frames[h].document.forms.length; i++) {
		    
		 
			for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
				frames[h].document.forms[i].elements[j].disabled = false
			}
		}
		for (i = 0; i < frames[h].document.links.length; i++) {
			frames[h].document.links[i].onclick = IELinkClicks[h][i]
		}
	}
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function blockEvents() {
	if (Nav4) {
	

		window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = deadend
	} else {
		disableForms()
	}

	  
	win = top;

	if (document.all != null)
	{
        // add checkModal handler to iframes (and any iframes contained within recursively)
        //checkModalForFrames(top)
        win.onfocus = checkModal;
        
        // use interative approach for now (recusive method locks IE)
        var ifrms = win.document.getElementsByTagName("iframe");

        for (i = 0; i < ifrms.length; i++)
        {    
              ifrms[i].onfocus = checkModal;

        }

    }
    else
    {

        var ifrms = win.document.getElementsByTagName("iframe");

         for (i = 0; i < ifrms.length; i++)
         {    
             var frmWin =  ifrms[i].contentWindow;
             frmWin.addEventListener("click", checkModalFF, false);      
              
         }

        win.onclick = checkModalFF
     
     }
}

function disableLinks(arrLinks)
{
   var oClick;
   
   for (i = 0; i < arrLinks.length; i ++)
   {
          oClick = arrLinks[i].onclick;
          
          if (top.opener == null)
          {
                arrLinks[i].onclick = function wrapLoad(e){  if (oClick != null) { oClick(e); }} 
          }
   }

}



function disableClick(e)
{

     if(top.dialogWin != null)
     { 
         if (top.dialogWin.win != null && !top.dialogWin.win.closed)
         { e.preventDefault(); }
     }
}



function winBlur()
{
    top.dialogWin.win.focus();
}





function checkModalForFrames(win)
{
   var frms = win.document.getElementsByTagName("iframe");


   for (i = 0; i < frms.length; i++)
   {
       frms[i].onfocus = checkModal;
        
       if (frms[i].contentWindow.checkModal != null)
       {
           checkModalForFrames(frms[i].contentWindow)     
       }
 
       
   }
   
   return;     

}

// As dialog closes, restore the main window's original
// event mechanisms.
function unblockEvents() {
	if (Nav4) {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
		window.onclick = null
		window.onfocus = null
	} else {
		enableForms()
	}
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModal() {

	if (top.dialogWin != null ){	
		if (top.dialogWin.win != null){
			if ((top.dialogWin.win && !top.dialogWin.win.closed)) {
			
				top.dialogWin.win.focus();
				
			}
		}
	}	
}


// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModalFF(e) {


	if (top.dialogWin != null ){	
		if (top.dialogWin.win != null){
			if ((top.dialogWin.win && !top.dialogWin.win.closed)) {
			
				top.dialogWin.win.focus();
				
			}
		}
	}	

}


/**************************
  END MODAL DIALOG CODE
**************************/

// Function to run upon closing the dialog with "OK".
function setPrefs() {
	// We're just displaying the returned value in a text box.
	document.returned.searchURL.value = top.dialogWin.returnedValue
}

// Called by "Apply Settings" button to reload the page with
// search string data appended to URL.
function applySettings() {
	if (document.returned.searchURL.value) {
		location.href = "main.html" + document.returned.searchURL.value
	}
}

/*****************************************
      BEGIN CUSTOM PAGE STYLE CODE
******************************************/
// Convert location.search into an array of values
// indexed by name.
function getSearchAsArray() {
	var results = new Array()
	var input = unescape(location.search.substr(1))
	if (input) {
		var srchArray = input.split("&")
		var tempArray = new Array()
		for (i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=")
			results[tempArray[0]] = tempArray[1]
		}
	}
	return results
}
var srchData = getSearchAsArray()

// Write style sheets with data passed in with location.search,
// or use default values if no data has been passed.
/*
document.write("<STYLE TYPE='text/css'>")
document.write("BODY {font-family:'Comic Sans MS',Helvetica,sans-serif; background-color:" +
   ((srchData["bgColor"]) ? srchData["bgColor"] : "#eeeeee") + "; color:" +
   ((srchData["textColor"]) ? srchData["textColor"] : "#000000") + "}")
document.write("H1 {text-align:right; font-size:" +
   ((srchData["h1Size"]) ? srchData["h1Size"] : "24") + "pt}")
document.write("</STYLE>")
*/
/*****************************************
      END CUSTOM PAGE STYLE CODE
******************************************/

/** this function is for the main page not the popup pages.
 * It creates the checker tags on each page that is being loaded.
 */
function createSavedDocumentTag() {
	var newElmnt = document.createElement('INPUT');
	var tagToBePlacesNextTo = document.getElementsByTagName('FORM');
	newElmnt.setAttribute('id', 'element_changes');
	newElmnt.setAttribute('name', 'element_change');
	newElmnt.setAttribute('value', 'false');
	newElmnt.setAttribute('type', 'text');
	document.body.insertBefore(newElmnt);
	//tagToBePlacesNextTo[0].insertAdjacentElement('afterBegin', newElmnt);
}

function makerunsavecheck(tmpdoc, thevalofbool){
	

	if (tmpdoc == 'document'){
		var dialogField  = document.getElementById("element_runsavecheck");
	}
	if (tmpdoc == 'opener'){
		
		if (opener != null)
		{
		    var dialogField  = opener.document.getElementById("element_runsavecheck");
	    }
	}	
	if (dialogField == null) {
	//	var tmpTag2 = "asd";
	//	document.replaceChild(dialogField, tmpTag2);
	//	return;
	}else{
		dialogField.setAttribute('value',thevalofbool,0);
		
	}	
}

/** this function is for the main page not the popup pages.
 * it checks to see if the page has been changed (anything)
 * if so it will alert a message that do you want move without saving the changes 
 * if yes, it will discard the confirm box and move to the new page.
 * if no, it will close the confirm box and won't change the page.
 */ 
function checkSavedDocument(e) {
	//if(this.opener == null && self.closed){
	
       	var e = e || window.event;

		var name2 = "element_runsavecheck";
		var dialogField  = document.getElementById(name2);
		if (dialogField == null) {
			//var tmpTag2 = "asd";
			//document.replaceChild(dialogField, tmpTag2);
			return false;
		}else{	
			var theAttr2 = dialogField.getAttribute('value');
			if (theAttr2 == null){
				//var tmpTag2 = "asd";
				//document.replaceChild(dialogField, tmpTag2);
				return false;
			}else{
				var checkedVal2 = theAttr2;
				
				if (checkedVal2 == 'true'){
					var name = "element_changes";
					var checkField  = document.getElementById(name);
					if (checkField == null) {
						return false;
					}else{
						var theAttr = checkField.getAttribute('value');
						if (theAttr == null){
							return false;
						}else{
							var checkedVal = theAttr;
							if (checkedVal == 'true'){
								e.returnValue = "This page has NOT been SAVED. You will LOSE the changes on the page if not saved.";
								
							}else{
								return false;		
							}
						}
					}
				}else{
				
				}
			}
		}
	//}				
}

function PopUpTheSecondLanguage(url) {
	var w = this.screen.width;
	var h = this.screen.height;
	window.moveTo(0, 0);
	window.resizeTo(this.screen.width, (this.screen.height/2)-5);
	var windowprops = "location=no,scrollbars=yes,top="+((h/2)-5)+",width="+w+",height="+(h/2)+",left=0,menubars=no,toolbars=no,resizable=yes";
	window.open(url,"secondLanguageWin",windowprops);
}


function createCommentLayer() {
	this.commentlayer.style.visibility = 'visible';
	return false;
}

function commentLayerOff() {
	this.commentlayer.style.visibility = 'hidden';
	return true;
}

function refreshParent()
{
    parent.top.location.href = parent.top.location.href; 
}

function refreshParentURL(url)
{
    parent.top.location.href = url;
 
}


var intervalID;

/// Check session state every two seconds - 
/// display warning box if session will timeout within
/// the warning interval 
function initSessionCheck()
{
   intervalID = window.setInterval("CheckSession()",2000);
}

