		var myConn = new XHConn();
		var myObj;
		var mySwapObj;
		var pid;
		var cid;
		var myCID;
		var skinpath;
		
		function toggleElement(obj){
			if (obj.style.visibility == 'hidden'){
				obj.style.visibility = 'visible';
				obj.style.display = 'block';
			} else {
				obj.style.visibility = 'hidden';
				obj.style.display = 'none';
			}
		}
		
		//////////////////////////////////
		//      Content Functions				//
		//////////////////////////////////

		function addContent(obj,pid,cid,lid){
			myObj = obj;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=addContent&pid="+pid+"&cid="+cid+"&lid="+lid, addContentAction);				
		}
		
		function addContentAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			widgInit();
			newdiv = null;
		}

		function editContent(obj,frmname){
			myObj = obj;
				
			pid = document.forms[frmname].elements["pid"].value;
			cid = document.forms[frmname].elements["cid"].value;
			
			title = document.getElementById("title"+pid+"_"+cid).value;
			content = document.forms[frmname].elements["content"+pid+"_"+cid].value;
			langid = document.forms[frmname].elements["lang"+pid+"_"+cid].value;
			
			if (!myConn) alert("XMLHTTP not available.");
			//myConn.connect("admin/ajax.liveedit.php", "POST", "do=editContent&pid="+pid+"&cid="+cid+"&title="+escape(title)+"&content="+escape(content)+"&langid="+langid, editContentAction);			
			//alert(escape(content));
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=editContent&pid="+pid+"&cid="+cid+"&title="+escape(title)+"&content="+escape(content)+"&langid="+langid, editContentAction);
		}
		
		function editContentAction(oXML){
			myObj.innerHTML = oXML.responseText;
		}

		//////////////////////////////////
		//      Module Functions				//
		//////////////////////////////////
		
		function editModuleTitle(obj,frmname){
			myObj = obj;
				
			pid = document.forms[frmname].elements["pid"].value;
			cid = document.forms[frmname].elements["cid"].value;
			
			title = document.getElementById("title"+pid+"_"+cid).value;
			
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=editModuleTitle&pid="+pid+"&cid="+cid+"&title="+escape(title), editModuleTitleAction);			
		}
		
		function editModuleTitleAction(oXML){
			myObj.innerHTML = oXML.responseText;
		}
		
		function drawModuleList(obj,cid,pid){
			myObj = obj;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=drawModuleList&pid="+pid+"&cid="+cid, drawModuleListAction);					
		}
		
		function drawModuleListAction(oXML){
			myObj.innerHTML = oXML.responseText;
		}
		
		function addModule(obj,pid,cid,mid){
			myObj = obj;
			myCID = cid;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=addModule&pid="+pid+"&cid="+cid+"&mid="+mid, addModuleAction);				
		}
		
		function addModuleAction(oXML){				
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;	
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			
			if(con = document.getElementById("container"+myCID)){
	
				if(con.childNodes[0].nodeName != "DIV"){
					scr = con.childNodes[1].getAttribute("jspath");
				} else {
					scr = con.childNodes[0].getAttribute("jspath");
				}
				
				if(scr!=""){
					alreadyinc = false;
					
					head = document.getElementsByTagName("head")[0];
					incscripts = head.getElementsByTagName("script");
					
					for(i=0;i < incscripts.length; i++){
						if(incscripts[i].src == scr){
							alreadyinc = true;
						}
					}
					
					if(!alreadyinc){
						var e = document.createElement("script");
						e.src = scr;
						e.type="text/javascript";
						document.getElementsByTagName("head")[0].appendChild(e);
					}
				}
			}

			widgInit();
			newdiv = null;
		}
		
		function getInclude(obj,val,mpid){
			myObj = obj;
			val = escape(val);
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("/admin/ajax.liveedit.php", "POST", "do=getInclude&mpid="+mpid+"&val="+val, getIncludeAction);
		}
		
		function getIncludeAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			newdiv = null;
		}
		
		//////////////////////////////////
		//      Common Functions				//
		//////////////////////////////////
		
		function liveUpdateText(obj){
			if(obj.theInput.parentNode.parentNode.previousSibling.nodeName!='FORM'){
				container = obj.theInput.parentNode.parentNode.previousSibling.parentNode;
			} else {
				container = obj.theInput.parentNode.parentNode.previousSibling;
			}

			textareaid = obj.theTextarea.getAttribute("oldid");

			if(textareaid.indexOf("title")>=0){
				title = getElementsByClass('contentBoxTitle',container);
				if(title.length==1){
					title[0].innerHTML = obj.theIframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;
				} else {
					title = getElementsByClass('moduleBoxTitle',container);
					if(title.length==1){
						title[0].innerHTML = obj.theIframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;
					}
				}
			} else if (textareaid.indexOf("content")>=0) {
				content = getElementsByClass('contentBoxContent',container);
				if(content.length==1){
					content[0].innerHTML = obj.theIframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;
				}
			}

			return false;
		}
		
		function changeLanguage(obj,pid,cid,langid){
			myObj = obj;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=getContent&pid="+pid+"&cid="+cid+"&langid="+langid, changeLanguageAction);	
		}
		
		function changeLanguageAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			widgInit();
			newdiv = null;
		}
		
		function changeSkin(obj,pid,cid,skinid){
			myObj = obj;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=changeSkin&pid="+pid+"&cid="+cid+"&skinid="+skinid, changeSkinAction);	
		}
		
		function changeSkinAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			widgInit();
			newdiv = null;
		}
		
		function deleteContent(obj,pid,cid,type){
			if(window.confirm('Are you sure you want to delete this '+type+'?')){
				myObj = obj;
				if (!myConn) alert("XMLHTTP not available.");
				if(type=='content'){
					langid = document.getElementById('lang'+pid+'_'+cid).value;
					myConn.connect("admin/ajax.liveedit.php", "POST", "do=deleteContent&pid="+pid+"&cid="+cid+"&langid="+langid, deleteContentAction);				
				} else if(type=='module'){
					myConn.connect("admin/ajax.liveedit.php", "POST", "do=deleteModule&pid="+pid+"&cid="+cid, deleteContentAction);
				}
			}
		}
		
		function deleteContentAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			widgInit();
			newdiv = null;
		}
		
		function exitModuleList(obj,pid,cid){
			myObj = obj;
			if (!myConn) alert("XMLHTTP not available.");
			myConn.connect("admin/ajax.liveedit.php", "POST", "do=exitModuleList&pid="+pid+"&cid="+cid, exitModuleListAction);
		}
		
		function exitModuleListAction(oXML){
			newdiv = document.createElement('div');
			newdiv.innerHTML = oXML.responseText;
			myObj.parentNode.replaceChild(newdiv.firstChild,myObj);
			widgInit();
			newdiv = null;			
		}
		
		//////////////////////////////////
		//   Move Container Functions		//
		//////////////////////////////////

		function moveBoxUp(obj,pid,cid,type){
			myObj = obj;
			if(mySwapObj = obj.previousSibling){

				var newtest = getElementsByClass('containerGroup');
				
				for(j=0;j < newtest.length;j++){
					var countRemove = 0;
					for(i=0;i<newtest[j].childNodes.length;i++){
						if(newtest[j].childNodes[i].nodeName != "DIV"){
							countRemove = countRemove + 1;
						}
						if(myObj == newtest[j].childNodes[i]){
							cid = i + (j*7);
							break;
						}
					}		
				}
				
				cid += 1;
				newcid = cid - 1;
				
				cid = cid - countRemove;
				newcid = newcid - countRemove;
				
				//alert(cid);
				//alert(newcid);
				
				swapNodes(myObj,mySwapObj);

				if (!myConn) alert("XMLHTTP not available.");
				myConn.connect("admin/ajax.liveedit.php", "POST", "do=moveBox&pid="+pid+"&cid="+cid+"&newcid="+newcid+"&type="+type, moveBoxUpAction);
			}			
		}
		
		function moveBoxUpAction(oXML){
			
		}
		
		function moveBoxDown(obj,pid,cid,type){
			myObj = obj;
			if(mySwapObj = obj.nextSibling){				
				var newtest = getElementsByClass('containerGroup');
							
				for(j=0;j < newtest.length;j++){
					var countRemove = 0;
					for(i=0;i<newtest[j].childNodes.length;i++){
						if(newtest[j].childNodes[i].nodeName != "DIV"){
							countRemove = countRemove + 1;
						}
						if(myObj == newtest[j].childNodes[i]){
							cid = i + (j*7);
							break;
						}
					}		
				}
				
				cid += 1;
				newcid = cid + 1;
				
				cid -= countRemove;
				newcid -= countRemove;
				
				//alert(cid);
				//alert(newcid);
				
				swapNodes(myObj,mySwapObj);

				if (!myConn) alert("XMLHTTP not available.");
				myConn.connect("admin/ajax.liveedit.php", "POST", "do=moveBox&pid="+pid+"&cid="+cid+"&newcid="+newcid+"&type="+type, moveBoxDownAction);	
			}				
		}
		
		function moveBoxDownAction(oXML){
			
		}
		
		function moveBoxLeft(obj,pid,cid,type){
			myObj = obj;	
				
			var newtest = getElementsByClass('containerGroup');
			
			for(j=0;j < newtest.length;j++){
				var countRemove = 0;
				for(i=0;i<newtest[j].childNodes.length;i++){
					if(newtest[j].childNodes[i].nodeName != "DIV"){
						countRemove = countRemove + 1;
					}
					if(myObj == newtest[j].childNodes[i]){
						tmpcol = j;
						tmpcid = i;
						break;
					}					
				}		
			}
			
			if(newtest[tmpcol-1]){
				if(mySwapObj = newtest[tmpcol-1].childNodes[tmpcid]){			
					cid = (tmpcid + (tmpcol*7))+1;
					newcid = (tmpcid + ((tmpcol-1)*7))+1;
					
					//cid = myObj.id;
					//newcid = mySwapObj.id;
					
					//alert(cid);
					//alert(newcid);
					
					cid = cid - countRemove;
					newcid = newcid - countRemove;
	
					swapNodes(myObj,mySwapObj);
					
					if (!myConn) alert("XMLHTTP not available.");
					myConn.connect("admin/ajax.liveedit.php", "POST", "do=moveBox&pid="+pid+"&cid="+cid+"&newcid="+newcid+"&type="+type, moveBoxRightAction);					
				}
			}
		}
		
		function moveBoxLeftAction(oXML){
			
		}

		function moveBoxRight(obj,pid,cid,type){
			myObj = obj;	
				
			var newtest = getElementsByClass('containerGroup');
			
			for(j=0;j < newtest.length;j++){
				var countRemove = 0;
				for(i=0;i<newtest[j].childNodes.length;i++){
					if(newtest[j].childNodes[i].nodeName != "DIV"){
						countRemove = countRemove + 1;
					}
					if(myObj == newtest[j].childNodes[i]){
						tmpcol = j;
						tmpcid = i;
						break;
					}					
				}		
			}
			
			if(newtest[tmpcol+1]){
				if(mySwapObj = newtest[tmpcol+1].childNodes[tmpcid]){			
					cid = (tmpcid + (tmpcol*7))+1;
					newcid = (tmpcid + ((tmpcol+1)*7))+1;
					//cid = myObj.id;
					//newcid = mySwapObj.id;
					
					//alert(cid);
					//alert(newcid);
					
					cid = cid - countRemove;
					newcid = newcid - countRemove;
	
					swapNodes(myObj,mySwapObj);
					
					if (!myConn) alert("XMLHTTP not available.");
					myConn.connect("admin/ajax.liveedit.php", "POST", "do=moveBox&pid="+pid+"&cid="+cid+"&newcid="+newcid+"&type="+type, moveBoxRightAction);					
				}
			}
		}
		
		function moveBoxRightAction(oXML){

		}
		
		function swapNodes(node1, node2){
			var node2copy = node2.cloneNode(true);
			var node1copy = node1.parentNode.replaceChild(node2copy,node1);
			node2.parentNode.replaceChild(node1copy,node2);
		}
		
		function getElementsByClass(searchClass,node,tag) {
			var classElements = new Array();
			if ( node == null )
				node = document;
			if ( tag == null )
				tag = '*';
			var els = node.getElementsByTagName(tag);
			var elsLen = els.length;
			var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
			for (i = 0, j = 0; i < elsLen; i++) {
				if ( pattern.test(els[i].className) ) {
					classElements[j] = els[i];
					j++;
				}
			}
			return classElements;
		}
