try{
HTMLElement.prototype.__defineGetter__.length;
(function(body, removeChild){
    HTMLElement.prototype.__defineGetter__(
        "outerHTML",
        function(){
            var self = body.appendChild(this.cloneNode(true)),
                outerHTML = body.innerHTML;
            body.removeChild(self);
            return outerHTML;
        }
    );
    HTMLElement.prototype.__defineSetter__(
        "outerHTML",
        function(String){
            if(!String)
                removeChild(this);
            else if(this.parentNode){
                body.innerHTML = String;
                while(body.firstChild)
                    this.parentNode.insertBefore(body.firstChild, this);
                removeChild(this);
                body.innerHTML = "";
            };
        }
    );
})(
    document.createElement("body"),
    function(HTMLElement){if(HTMLElement.parentNode)HTMLElement.parentNode.removeChild(HTMLElement);}
);
}catch(e){};

var requestedurl;
var callback;
var xhistory = new Array();

function refreshPage() {
	window.location = currentpageurl;
}

function postFormData(url, params, async, callbackfunc) {
	var xmlhttp;
	
	if (isUnloading()) return false;
	if (async==undefined) async = true;
	callback = undefined;
	requestedurl = url;
	//alert (url);
	xmlhttp=null;
	if (window.XMLHttpRequest) {// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function (event) { state_Change(event, xmlhttp); };
		xmlhttp.open("POST",url,async);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		/*xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");*/
		xmlhttp.send(params);
		if (callbackfunc != undefined) callback = callbackfunc;
		return false;
	} else {
		//window.location = getQueryValues(url, 'requestedcontentid');
		return false;
	}
}

function loadXMLDoc(url, async, callbackfunc) {
	var xmlhttp;
	
	if (isUnloading()) return false;
	
	if (async==undefined) async = true;
	callback = undefined;
	requestedurl = url;
	//alert (url);
	xmlhttp=null;
	if (window.XMLHttpRequest) {// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		var request = '<?xml version="1.0" encoding="UTF-8"?>'+
			'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">'+
			'<SOAP-ENV:Body>'+
			'<getHtmlContentsRequest>'+url.replace(/&/g, '&amp;')+'</getHtmlContentsRequest>'+
			'</SOAP-ENV:Body>'+
			'</SOAP-ENV:Envelope>';
		xmlhttp.onreadystatechange=function (event) { state_Change(event, xmlhttp); };
		xmlhttp.open("POST",baseurl+"admin/CMSsoap.php",async);
		xmlhttp.setRequestHeader("Content-type", "text/xml; charset=utf-8");
		xmlhttp.setRequestHeader('SOAPAction',baseurl+'admin/CMSsoap.php/getHtmlContentsRequest');
		xmlhttp.send(request);
		if (callbackfunc != undefined) callback = callbackfunc;
		return false;
	} else {
		//window.location = getQueryValues(url, 'requestedcontentid');
		return false;
	}
}

function getMetaNode(which) {
	var metas = document.getElementsByTagName('META');
	for (var i=0; i < metas.length; i++)
	    if (metas[i].getAttribute('NAME') == which)
	    	return metas[i]; 
	  var TestVar = metas[i].getAttribute('CONTENT');
}

function navigateBack() {
	if (xhistory.length>2) {
		url = xhistory.pop();
		url = xhistory.pop();
		loadXMLDoc(url, true);
	} else {
		history.back();
	}
}

function state_Change(event, xmlhttp) {
	if ((!isUnloading()) && (xmlhttp.readyState==4)) {// 4 = "loaded"
		if (xmlhttp.status==200) {// 200 = OK
			if (xmlhttp.responseXML!=null) {
				var contentids = xmlhttp.responseXML.getElementsByTagName('contentid');
				var contents = xmlhttp.responseXML.getElementsByTagName('content');
				
				for (var i=0; i<contentids.length; i++) {
					nodevalue = "";
					//alert(contentids[i].firstChild.nodeValue);
					for (var j=0; j<contents[i].childNodes.length; j++) {
						nodevalue = nodevalue + contents[i].childNodes[j].nodeValue;
					}
					
					switch (contentids[i].firstChild.nodeValue) {
						case "title":
							//document.title = nodevalue+' '+pagetitleseparator+' '+basepagetitle; 
							break;
						case "keywords":
						case "description":
							//e = getMetaNode(contentids[i].firstChild.nodeValue);
							//e.setAttribute("content", nodevalue);
							break;
						case "main":
							window.location.hash="main";
							document.getElementById("main").scrollIntoView();
						default:
							xhistory.push(requestedurl);
							e = document.getElementById(contentids[i].firstChild.nodeValue);
							
							if (e != undefined) {
								e.outerHTML = nodevalue;
							}
							break;
					}
				}
			}
			if (callback != undefined) {
				callback();
			}
			return true;
		} else {
			//window.location = getQueryValues(requestedurl, 'requestedcontentid');
			return false;
		}
	}
}
