var TreeViewNodeSelectedId = "";

function FixSize() {

	var myWidth = 0, myHeight = 0;

    //include all padding/margins
	//var Head = 75, Tools = 110, Margin = 8, Footer = 65, TabSetOne = 30, TabSetTwo = 35;
	var Head = 70, Tools = 110, Margin = 4, Footer = 72, TabSetOne = 34, TabSetTwo = 34;
	var BodyHeight = 0, PHPanelsHeight = 0, ListPanelHeight = 0, MarketingPanelHeight = 0;
	var divBody, divMultipage, divPHPanels, divTitlelist, divListPanel, divMarketingPanel;

    // browserdetect.js
	BrowserDetect.init();
	
    if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version < 8))
    {
		//IE 6+ in 'standards compliant mode'
		//myWidth = document.documentElement.clientWidth; 
		myHeight = document.documentElement.clientHeight;

		BodyHeight = myHeight - Head - Tools - Margin - Footer - 5;
        PHPanelsHeight = BodyHeight - TabSetOne - 5;
        MarketingPanelHeight = ListPanelHeight = PHPanelsHeight - TabSetTwo - 5;
        
    }
    else if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version >= 8))
    {
		//IE 6+ in 'standards compliant mode'
		//myWidth = document.documentElement.clientWidth; 
		myHeight = document.documentElement.clientHeight;

		BodyHeight = myHeight - Head - Tools - Margin - Footer - 5;
        PHPanelsHeight = BodyHeight - TabSetOne - 5;
        MarketingPanelHeight = ListPanelHeight = PHPanelsHeight - TabSetTwo - 5;    }
    else
    {
        //Non-IE
	    //  --> document.all('theBody') for firefox use <--
		//myWidth = window.innerWidth; 
		myHeight = window.innerHeight;

	    BodyHeight = myHeight - Head - Tools - Margin - Footer;
	    PHPanelsHeight = BodyHeight - TabSetOne - 5;
        MarketingPanelHeight = ListPanelHeight = PHPanelsHeight - TabSetTwo - 5;
    }
    
    divBody = document.getElementById('bodyDiv');
    divPHPanels = document.getElementById('PHPanelsDiv');
    divListPanel = document.getElementById('pnlListDiv');
    divMarketingPanel = document.getElementById('pnlMarketingDiv');
    
    if (divBody && (BodyHeight > 0))
        divBody.style.height=BodyHeight+'px';
    if (divPHPanels && (PHPanelsHeight > 0))
        divPHPanels.style.height=PHPanelsHeight+'px';
    if (divListPanel && (ListPanelHeight > 0))
        divListPanel.style.height=ListPanelHeight+'px';
    if (divMarketingPanel && (MarketingPanelHeight > 0))
        divMarketingPanel.style.height=MarketingPanelHeight+'px';

}


function MPBasicFixSize() {

	var myWidth = 0, myHeight = 0;

    //include all padding/margins
	var Head = 80, Margin = 5, Footer = 72;
	var BodyHeight = 0, PHPanelsHeight = 0;
	var divBody, divPHPanels;

    // browserdetect.js
	BrowserDetect.init();

    if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version < 8))
    {
		//myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;

		Margin = 10; 

		BodyHeight = myHeight - Head - Margin - Footer;
        PHPanelsHeight = BodyHeight - Margin;
    }
    else if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version >= 8))
    {
		//myWidth = document.documentElement.clientWidth; 
		myHeight = document.documentElement.clientHeight;

		Margin = 10; 

	    BodyHeight = myHeight - Head - Margin - Footer;
	    PHPanelsHeight = BodyHeight - Margin;
    }
    else
    {
	    //Non-IE
	    //  --> document.all('theBody') for firefox use <--
		//myWidth = window.innerWidth; 
		myHeight = window.innerHeight;

		Margin = 10; 

	    BodyHeight = myHeight - Head - Margin - Footer;
	    PHPanelsHeight = BodyHeight - Margin;
    }
	
    divBody = document.getElementById('bodyDiv');
    divPHPanels = document.getElementById('PHPanelsDiv');
    
    if (divBody && (BodyHeight > 0))
        divBody.style.height=BodyHeight+'px';
    if (divPHPanels && (PHPanelsHeight > 0))
        divPHPanels.style.height=PHPanelsHeight+'px';
}


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 getCPIWindow() {
	return top.frames["cpi"];
}


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 closePopup() {
	var main = window.opener;
	if (main) {
		main.location.reload();
		var cpi = main.top.opener;
		if (cpi) { 
			var home = cpi.getCPIWindow();
			home.doCPIPostBack(); 
		}
		main.focus();
	}
	window.close();
} // function closePopup()


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() {
	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)
	}
}

function SetFocus(elementId)
{
    if (document.getElementById(elementId)!=null)
        document.getElementById(elementId).focus();
}


function getDocumentElement(win, id) {
	// win is a variable that points to the window want to search for id in
	var obj = null;
	if (win.document.getElementById(id)) {
		obj = win.document.getElementById(id);
	}
	else if (win.document.all) {
		obj = win.document.all(id);
	}
	return obj;
}


function htmlEncode(value)
{
    return $('<div/>').text(value).html();
}


function htmlDecode(value)
{
    return $('<div/>').html(value).text();
}
