var hidestatusmode=0;
function getHTTP(){
var xmlhttp=false;
if (window.XMLHttpRequest)
{
  try{
  xmlhttp = new XMLHttpRequest();
  } catch(e) {
	xmlhttp = false;  
  }
} else if (window.ActiveXObject)
  {
	  try{
 		 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch(e){
		  xmlhttp = false;
	  }
  }
  return xmlhttp;
}//end of function getHTTP
function getData(url, objid){
	xmlhttp = getHTTP();
	xmlhttp.open("GET", url, true);
	ret = "";
	xmlhttp.onreadystatechange= function() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200){
				obj = document.getElementById(objid);
				if (obj){
					obj.innerHTML = xmlhttp.responseText;
				}
			} else obj.innerHTML = "Can not render !";//end if status
		}//end if
	}//end of function
	xmlhttp.send(null);
}//end of getData
function refreshBlock(id, st, ed, pid){
	obj = document.getElementById("block"+id);
	if (obj){
		obj.innerHTML = "loading...";
	}
	if (!pid) pid="";
	getData("../rss/rss.render.php?blockid="+id+"&status="+st+"&editable="+ed+"&pageid="+pid, "block"+id);	
}
function getRSSURL(id, st, ed){
	return "../rss/rss.render.php?blockid="+id+"&status="+st+"&editable="+ed;	
}
function loadBlock(xmlobj, objid, st, ed){
	xmlobj.open("GET", "../rss/rss.render.php?blockid="+objid+"&status="+st+"&editable="+ed, true);
	ret = "";
	xmlobj.onreadystatechange= function() {
		if (xmlobj.readyState==4) {
			if (xmlobj.status==200){
				obj = document.getElementById(objid);
				if (obj){
					obj.innerHTML = xmlobj.responseText;
				}
			} else obj.innerHTML = "Can not render !";//end if status
		}//end if
	}//end of function
	xmlobj.send(null);
}//end of loadBlock
function showData(frame, canvas){
	fobj = document.getElementById(frame);
	if (!fobj) return;
	if (fobj.contentWindow.document.body.innerHTML=="") return;
	cobj = document.getElementById(canvas);
	if (!cobj) return;
	cobj.innerHTML = fobj.contentWindow.document.body.innerHTML;
	window.scrollTo(0,0);
}
function updateCanvas(frameid, canvasid){
	if (!frameid) return;
	if (!canvasid) return;
	cobj = document.getElementById(canvasid);
	if (!cobj) alert("Canvas not found !");
	fobj = document.getElementById(frameid);
	if (!fobj) alert("Target frame not found !");
	cobj.innerHTML = fobj.contentWindow.document.body.innerHTML;
	// set target for all links and forms
	aobjs = cobj.getElementsByTagName("a");
	if (!aobjs) aobjs = cobj.getElementsByTagName("A");
	k = 0;
	for(i=0;i<aobjs.length;i++){
		e = aobjs[i];
		if (e.href.indexOf(".php")>0 || e.href.indexOf(".asp")>0) e.target = frameid;
	}
	// set target for all forms
	aobjs = cobj.getElementsByTagName("form");
	if (!aobjs) aobjs = cobj.getElementsByTagName("FORM");
	for(i=0;i<aobjs.length;i++){
		e = aobjs[i];
		e.target = frameid;
	}
}//end of updateCanvas
function updateView(frameid, canvasid){
	if (!frameid) return;
	if (!canvasid) return;
	cobj = document.getElementById(canvasid);
	if (!cobj) alert("Canvas not found !");
	fobj = document.getElementById(frameid);
	if (!fobj) alert("Target frame not found !");
	cobj.innerHTML = fobj.contentWindow.document.body.innerHTML;
}//end of updateView
function movePage(frm, n){
	pobj = document.getElementById(frm).page;
	p = pobj.value;
	if (n==-1 && p>1){
		pobj.value--;
		document.getElementById(frm).submit();
	}
	if (n==1 && p<pobj.options.length){
		pobj.value++;
		document.getElementById(frm).submit();
	}
}
function movePage2(frm, n){
	pcobj = "pagecount";
	pobj = document.getElementById(frm).page;
	p = pobj.value;
	if (n==-1 && p>1){
		pobj.value--;
		document.getElementById(frm).submit();
	}
	if (n==1 && p<document.getElementById(pcobj).value){
		pobj.value++;
		document.getElementById(frm).submit();
	}
}
function openSearch(objname){
	objs = document.getElementsByName(objname);
	if (!objs) return false;
	obj = objs[0];
	txt = prompt("Nhập từ khóa","", "Tìm kiếm");
	if (!txt) return;
	if (txt=="") return;	
	ret = -1; retval = "";
	for (i=0;i<obj.length;i++){
		v = obj.options[i].value;
		t = obj.options[i].text;
		if ((t.toUpperCase().indexOf(txt.toUpperCase())>=0) || (v.toUpperCase().indexOf(txt.toUpperCase())>=0)) {
			ret = i; retval = v;
			i = obj.length;
		}
	}
	if (ret!=-1) obj.value = retval;
	// obj.focus();
}
function removePortlet(id){
	if (!window.confirm("Chắc chắn xóa ?")){
		return;
	}	
	frm = document.getElementById("__frameContext");
	if (!frm) return;
	frm.src = "../rss/removeBlock.php?key="+id;
	obj = document.getElementById("block"+id);
	if (!obj){
		alert("Không tìm thấy portlet !");
		return;
		}
	obj.style.display = "none";
	// remove div containing portlet
	hobj = document.getElementById("colnum"+id);
	if (hobj){
		colobj = document.getElementById("column"+hobj.value);
		if (colobj) {
			colobj.removeChild(obj);
			brobj = document.getElementById("br"+id);
			if (brobj) colobj.removeChild(brobj);
		}
	}//end if 
}//end of removePortlet
function showFormTag(obj, i){
	tabs = document.getElementsByTagName("td");
	for(k=0;k<tabs.length;k++){
		tab = tabs[k];
		if (tab.className=="activeTab") tab.className = "deactiveTab";
	}
	obj.className = "activeTab";
	divs = document.getElementsByTagName("div");
	for(k=0;k<divs.length;k++){
		div = divs[k];
		if (div.id.indexOf("_divTag")>0) div.style.display = "none";
	}
	div = document.getElementById("__divTag"+i);
	if (div) div.style.display = "";
}
function changeStackTab(o, sid, tabid, ttype){
	ac = "activeTab"+ttype;
	dc = "deactiveTab"+ttype;
	// change Tab show
	tabobj = document.getElementById(tabid);
	if (!tabobj) return;
	childobjs = tabobj.getElementsByTagName("td");
	for(i=0;i<childobjs.length;i++){
		obj = childobjs[i];
		if (obj.className==ac) obj.className = dc;
	}
	o.className = ac;
	// change div show
	divobjs = document.getElementsByTagName("div");
	for(i=0;i<divobjs.length;i++){
		if (divobjs[i].id.indexOf(tabid)>0) divobjs[i].style.display = "none";
	}
	divobj = document.getElementById(sid);
	divobj.style.display = "";
	return true;
}
function toogleObject(obj1, obj2){
	tabobj = document.getElementById(obj1);
	statusobj = document.getElementById(obj2);
	if (tabobj.style.display=="none"){
		tabobj.style.display = "";
		if (statusobj) statusobj.value = "1";
	} else {
		tabobj.style.display = "none";
		if (statusobj) statusobj.value = "0";
	}
}//end of function

function hidestatus(){
	window.status='';
	return true;
}
function mycontext(){
	window.status='';
	return false;
}
if (document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN)
if (hidestatusmode==1){
	document.onmouseover=hidestatus;
	document.onmouseout=hidestatus;
	document.onmousedown=hidestatus;
	document.onactivate=hidestatus;
	document.onbeforeactivate=hidestatus;
	document.onbeforedeactivate=hidestatus;
	document.ondeactivate=hidestatus;
	document.oncontextmenu = mycontext;
	window.defaultStatus = "#";
}
