var TreeViewNodeSelectedId = "";

function getElement(win, id) {

	if (document.all) {
		return win.document.all(id);
	}
	else {
		return win.document.getElementById(id);
	}
}


function toggleDivDisplay(divid) {
	var div = getElement(window, divid);

	if (div.style.display == "block") {
		div.style.display = "none";
	}
	else if (div.style.display == "none") {
		div.style.display = "block";
	}
	else {
		div.style.display = "block";
	}
}


function setDivContent(win, divid, url) {

	var xmlhttp;
	var div = getElement(win, divid);

	if (window.attachEvent) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET", url, false);
		xmlhttp.send();
	}
	else {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", url, false);
		xmlhttp.send("");
	}
	
	div.innerHTML = xmlhttp.responseText;
				
} // function setDivContent(win, divid, url)


function setFormFocus(ctrlid) {
	var ctl = getElement(window, ctrlid);
	if (ctl) { ctl.focus(); }
}


function setFormScrollTo(ctrlid) {
	//alert(ctrlid);
	var ctl = getElement(window, ctrlid);
	if (ctl) { ctl.scrollIntoView(true); }
}


function doCPIPostBack() {
	__doPostBack("", "");
}


function doPopup(winname,btype,width,height,loadfile) {
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2 - 50);
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	
	if (btype == "Full")
	{
	    //alert("full window");
	    var fullwin = window.open(loadfile, winname, winParms + ",resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes");
    	fullwin.focus();
	}
	else
	{
	    var clipwin = window.open(loadfile, winname, winParms + ",resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no");
    	clipwin.focus();
	}
} // function doPopup(winname,width,height,loadfile)


function sendloc(template) {
	var win = window.open(template, "Other_Site");
	win.focus();
} // function sendloc(template)

function PageQuery(q) {
	if (q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	
	this.keyValuePairs = new Array();
	if (q) {
		for (var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	
	this.getValue = function(s) {
		for (var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}

	this.getParameters = function() {
		var a = new Array(this.getLength());
		for (var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function displayItem(key){
	var val = queryString(key);
	if (val == "false") {
		document.write("you didn't enter a ?name=value querystring item.");
	}
	else {
		document.write(val);
	}
}

function SetDivScrollPosition(element)
{
    var data = "scroll-y-pos:" + element.id + ":!~" + element.scrollTop + "~!";
    document.cookie = data;
}

function GetDivScrollPosition()
{
    var cookie = document.cookie;
    var strCut1 = cookie.indexOf("scroll-y-pos:");
    if (strCut1 >= 0)
    {
        strCut1 = strCut1 + 13;
        var strCut2 = cookie.indexOf(":!~");
        var strCut3 = strCut2 + 3;
        var strCut4 = cookie.indexOf("~!");
        var elementId = cookie.substring(strCut1, strCut2);
        var elementScrollTop = cookie.substring(strCut3, strCut4);
        document.getElementById(elementId).scrollTop = elementScrollTop;
    }
}

function treeviewScrollToId() {
	/*
	var id = queryString("id");
	if (id != "false") {
		treeviewScrollToId(id);
	}
	if (CustomerUserId) {
		treeviewScrollToId(CustomerUserId);
	}
	*/
	
	if ((null != TreeViewNodeSelectedId) && (TreeViewNodeSelectedId.length > 0))
	{
		treeviewScrollToId(TreeViewNodeSelectedId);
	}
	
}

function treeviewScrollToId(id) {
	var elTreeNode;
	if ((null != id) && (id.length > 0))
	{
		elTreeNode = document.getElementById(id);
		if (elTreeNode) {
			elTreeNode.scrollIntoView(true);
			var tree = document.getElementById("TreeDiv");
			if (tree)
			{
				tree.scrollLeft = 0;
			}
		} // if (elTreeNode)
	}
}


