function RedirectRequest(ID, Name, Category)
{
				//alert("PageX.aspx?id=" + ID);
				document.location = Category + ".aspx?id=" + ID;
        //document.location = "PageX.aspx?id=" + ID;
}    
function GetAdminStat()
{
//alert("getadminstat")
	var sParams = "";
	sParams = AddPostParam(sParams, "tag", "getAdminStat")
	var url = "PageController.aspx"
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest()
		xmlhttp.open("post",url,false)
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send(sParams);
		if (xmlhttp.readyState==4)
		{
			// if "OK"
			if (xmlhttp.status==200)
			{	
				if (xmlhttp.responseText == "true")
				{
					
				}
				else
				{
					parent.window.location = "logon.aspx"
				}

			}
			else
			{
				parent.window.location = "logon.aspx"
			}
		}
		else
		{
			parent.window.location = "logon.aspx"
		}
	}
	else if (window.ActiveXObject)
	{
		//alert("utility:line46")
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.open("post",url,false)
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.send(sParams);
			if (xmlhttp.readyState==4)
			{
			// if "OK"
				if (xmlhttp.status==200)
				{	
					if (xmlhttp.responseText == "true")
					{
						
					}
					else
					{
						parent.window.location = "logon.aspx"
					}
				}
				else
				{
					parent.window.location = "logon.aspx"
				}
			}
			else
			{
				parent.window.location = "logon.aspx"
			}
		}
		else
		{
				parent.window.location = "logon.aspx"
		}
	}

}

function saveComboItem(ddPageType)
{
	var sParams = "";
	var pageType = document.getElementById("ddPageTypes2")
		
	sParams = AddPostParam(sParams, "page_id", getPageID())
	sParams = AddPostParam(sParams, "tag", "savePageType")
	sParams = AddPostParam(sParams, "page_type", pageType.value)
	
	var url = "PageController.aspx"
	SendRequest(url, sParams);
}

function DeletePageAndChildren(PageID)
{
	var sParams = "";
	sParams = AddPostParam(sParams, "page_id", PageID)
	sParams = AddPostParam(sParams, "tag", "deletePage")

	var url = "PageController.aspx"
	SendUpdateRequest(url, sParams);
}

function loadAdminNewPage()
{
	var sParams = "";
	sParams = AddPostParam(sParams, "tag", "adminNewPage")
	var url = "PageController.aspx"
	SendRequest(url, sParams);
}


function SaveNewPage(pageID, txtNewPageName, ddPageType)
{
	var sParams = "";
	var txtPageName = document.getElementById(txtNewPageName)
	var pageType = document.getElementById(ddPageType)
		
	sParams = AddPostParam(sParams, "parent_id", pageID)
	sParams = AddPostParam(sParams, "tag", "addNewPage")
	sParams = AddPostParam(sParams, "page_type", pageType.value)
	sParams = AddPostParam(sParams, "page_name", txtPageName.value)
	
	var url = "PageController.aspx"
	SendUpdateRequest(url, sParams);
}


function getPageID()
{
	var qs = new Querystring();
	var pageID = qs.get("id");
	
	return pageID
}

function getEdit()
{
	var qs = new Querystring();
	var edit = qs.get("edit");
	
	return edit
}

function popUp(URL) {
						window.open(URL, 'id', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=725,height=500');
			}

function AddPostParam(sParams, sParamName, sParamValue)
{
	if (sParams.length > 0)
	{
		sParams += "&";
	}
	//alert(sParams + encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue));
	return sParams + encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
}

function SendRequest(url,sParams)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest()
		xmlhttp.open("post",url,false)
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send(sParams);
		if (xmlhttp.readyState==4)
		{
			// if "OK"
			if (xmlhttp.status==200)
			{	
			
				//alert("in xmlhttpChange2")
				//put html in DIV
				var xResponse =	xmlhttp.responseText.split('^')
				//alert(xmlhttp.responseText)
				var xTag = xResponse[0]
				var xTagContent = xResponse[1]
				//alert(xTag)
				//alert(xTagContent)
				var xElement = document.getElementById(xTag)
				if (xElement != null)
				{
					if (xTagContent == "<hide>")
					  {
							xElement.style.visibility = "hidden";
							xElement.style.display = "none";
					  }
					  else
					  {
							xElement.innerHTML = xTagContent
						}
				}
				else
				{
					//alert("xelement is null");
				}
			}
			else
			{
				//alert("Problem retrieving XML data" + xmlhttp.status + "<br>" + xmlhttp.responseText)
				document.getElementById('DivProd').innerHTML = xmlhttp.responseText
			}
		}
	}
	else if (window.ActiveXObject)
	{
	//alert(url)
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
		  //alert(sParams)
			xmlhttp.open("post",url,false)
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.send(sParams);
			if (xmlhttp.readyState==4)
			{
				// if "OK"
				if (xmlhttp.status==200)
				{	
					//alert("sendRequest: " + xmlhttp.responseText)
					var xResponse =	xmlhttp.responseText.split('^')
					//alert(xmlhttp.responseText)
					
					var xTag = xResponse[0]
					var xTagContent = xResponse[1]
						//alert(xTag)
					var xElement = document.getElementById(xTag)
					//alert(xElement)
					
					if (xElement != null)
					{
					  //alert(xTag)
					  //alert(xTagContent)
					  if (xTagContent == "<hide>")
					  {
					  //alert("hide")
							xElement.style.visibility = "hidden";
							xElement.style.display = "none";
					  }
					  else
					  {
							xElement.innerHTML = xTagContent
						}
					}
					else
					{
						//alert("xelement is null: " + xTag);
					}
				}
				else
				{
					var xElement = document.getElementById(xTag).innerHTML = xmlhttp.responseText
					if (xElement != null)
					{
						xElement.innerHTML = "Problem retrieving XML data" + xmlhttp.status + "<br>" + xmlhttp.responseText
					}
					else
					{
						//alert("xelement is null");
					}
				}
			}

		}
	}
}

function SendUpdateRequest(url,sParams)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest()
		xmlhttp.open("post",url,false)
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send(sParams);

		if (xmlhttp.readyState==4)
		{
			// if "OK"
			if (xmlhttp.status==200)
			{	
				//alert(xmlhttp.responseText);
				//put html in DIV
				var xResponse =	xmlhttp.responseText
				if (xResponse == "true")
				{
				//alert(xResponse);
					document.location = "AdminNav.aspx";				
				}
				else
				{
				//return error message.
				}
			}
			else
			{
				//alert("Problem retrieving XML data" + xmlhttp.status + "<br>" + xmlhttp.responseText)
				document.getElementById('DivProd').innerHTML = xmlhttp.responseText
			}
		}
	}
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		xmlhttp.open("post",url,false)
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send(sParams);
		
		if (xmlhttp.readyState==4)
		{
			// if "OK"
			if (xmlhttp.status==200)
			{	
				//alert(xmlhttp.responseText);
				//put html in DIV
				var xResponse =	xmlhttp.responseText
				if (xResponse == "true")
				{
				//alert(xResponse);
					document.location = "AdminNav.aspx";				
				}
				else
				{
				//return error message.
				}
			}
			else
			{
				//alert("Problem retrieving XML data" + xmlhttp.status + "<br>" + xmlhttp.responseText)
				document.getElementById('DivProd').innerHTML = xmlhttp.responseText
			}
		}
	}
}

function xmlhttpChange()
{
	//alert("in ready state: " + xmlhttp.readyState)
	// if xmlhttp shows "loaded"
	
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{	
			
			//alert("in xmlhttpChange2")
			//put html in DIV
			var xResponse =	xmlhttp.responseText.split('^')
			//alert(xmlhttp.responseText)
			var xTag = xResponse[0]
			var xTagContent = xResponse[1]
			var xElement = document.getElementById(xTag)
			if (xElement != null)
			{
				xElement.innerHTML = xTagContent
			}
			else
			{
				//alert("xelement is null");
			}
		}
		else
		{
			//alert("Problem retrieving XML data" + xmlhttp.status + "<br>" + xmlhttp.responseText)
			document.getElementById('DivProd').innerHTML = xmlhttp.responseText
		}
	}
}

function openDiv(xElement,xEditElement)
{
	var xDiv = document.getElementById(xElement);
	xDiv.style.visibility = "visible";
	xDiv.style.display = "block";
	
	var xEditTargetDiv = document.getElementById(xEditElement);
	//alert(xEditTargetDiv.style.border);
	xEditTargetDiv.style.border = "dotted 2px red";
	//alert(xEditTargetDiv.style.border);
}
		
function closeDiv(xElement, xEditElement)
{
	var xDiv = document.getElementById(xElement);
	xDiv.style.visibility = "hidden";
	xDiv.style.display = "none";
	
	var xEditTargetDiv = document.getElementById(xEditElement);
	if (xEditTargetDiv != null)
	{
		xEditTargetDiv.style.border = "0";
	}
}

function openADiv(xElement)
{
	var xDiv = document.getElementById(xElement);
	xDiv.style.visibility = "visible";
	xDiv.style.display = "block";
}

function closeADiv(xElement)
{
	var xDiv = document.getElementById(xElement);
	xDiv.style.visibility = "hidden";
	xDiv.style.display = "block";
}

var oHiddenFrame = null;

function getServerInfo1()
{
	if (oHiddenFrame == null)
	{
		oHiddenFrame = document.createElement("iframe");
		oHiddenFrame.name = "hiddenFrame";
		oHiddenFrame.id = "hiddenFrame";
		oHiddenFrame.style.height = "0px";
		oHiddenFrame.style.width = "0px";
		oHiddenFrame.style.postion = "absolute";
		oHiddenFrame.style.visibility = "hidden";
		document.body.appendChild(oHiddenFrame);
	}
	
	setTimeout(function () {
		frames["hiddenFrame"].location.href = "HiddenFrameExample.aspx"
		}, 10);
}

function getServerInfo()
{
//alert("hello");
	this.form.target = 'hiddenImgFrame';
	this.form.action = 'HiddenFrameExample.aspx';


}
 
function handleResponse(sResponseText)
{
	//alert("The Server returned: " + sResponseText);
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
