var CONFIG_USE_DIALOG=true;

function DIY_Browser() {
 d=document;
 this.agent=navigator.userAgent.toLowerCase();
 this.major = parseInt(navigator.appVersion);
 this.dom=(d.getElementById)?1:0; // true for ie6, ns6
 this.ns=(d.layers);
 this.ns4up=(this.ns && this.major >=4);
 this.ns6=(this.dom&&navigator.appName=="Netscape");
 this.op=(this.agent.indexOf('opera')!=-1&&this.major<7);
 this.opera5=(this.agent.indexOf("Opera 5")>-1);
 this.ie=(d.all);
 this.ie4=(d.all&&!this.dom)?1:0;
 this.ie4up=(this.ie && this.major >= 4);
 this.ie5=(d.all&&this.dom);
 this.ie6=(this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera5)?1:0;
 this.win=((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1));
 this.mac=(this.agent.indexOf("mac")!=-1);

}


var oBw = new DIY_Browser();

function getH(o) { var h=0; if (oBw.ns) { h=(o.height)? o.height:o.clip.height; return h; } h=(oBw.op)? o.style.pixelHeight:o.offsetHeight; return h; }
function setH(o,h) { if(oBw.ns) {if(o.clip) o.clip.bottom=h;}else if(oBw.op)o.style.pixelHeight=h;else o.style.height=h; }

function getW(o) { var w=0; if(oBw.ns) { w=(o.width)? o.width:o.clip.width; return w; } w=(oBw.op)? o.style.pixelWidth:o.offsetWidth; return w; }
function setW(o,w) { if(oBw.ns) {if(o.clip) o.clip.right=w;}else if(oBw.op)o.style.pixelWidth=w;else o.style.width=w; }

function getX(o) { var x=(oBw.ns)? o.left:(oBw.op)? o.style.pixelLeft:o.offsetLeft; return x;}
function setX(o,x) { (oBw.ns)? o.left=x:(oBw.op)? o.style.pixelLeft=x:o.style.left=x; }

function getY(o) {  var y=(oBw.ns)? o.top:(oBw.op)? o.style.pixelTop:o.offsetTop; return y;}
function setY(o,y) { (oBw.ie||oBw.dom)? o.style.top=y:(oBw.ns)? o.top=y:o.style.pixelTop=y; }

function getPageX(o) { if(oBw.ns) { var x=(o.pageX)? o.pageX:o.x; return x; } else if (oBw.op) {  var x=0; while(eval(o)) { x+=o.stylo.pixelLeft; e=o.offsetParent; } return x; } else { var x=0; while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } return x; } }

function getPageY(o) { if(oBw.ns) { var y=(o.pageY)? o.pageY:o.y; return y; } else if (oBw.op) {  var y=0; while(eval(o)) { y+=o.stylo.pixelTop; o=o.offsetParent; } return y; }  else { var y=0; while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; } return y; } }
//function setPos(o,x,y) { ylib_setX(o,ylib_getPageX(o)+x);ylib_setY(o,ylib_getPageY(o)+y); }


/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function setShow(_w,_h) {
	if (isDOM)
	{
		if (_h=='s') document.getElementById(_w).style.visibility='visible';
		if (_h=='h') document.getElementById(_w).style.visibility='hidden';
	}
	else if (isIE) {
		if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
		if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
	}
	else if(isNS4)
	{
		if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
		if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
	}
}

function checkValidObject(checkObj) {
	return(typeof(checkObj) != "undefined");
}

function loadPageTo(url){
	window.location=url;
}

function loadPage(url,height,width){
	var editWin=window.open(url,"_blank","resizable=yes,left=20,top=20,alwaysRaised=yes,scrollbars=yes,_blank,height="+height+",width="+width);	
}

function xloadPage(url,height,width){
	// Problem with cookie
	//if(oBw.ie6 && CONFIG_USE_DIALOG)	
	//	popupForm("Popup Form", url, window, width, height)
	//else
		loadPage(url,height,width);
}


function popupWindow(target, width, height)
{
	popupWindow(target, width, height,null);
}


function popupWindow(target, width, height,myStyle)
{
	if(!width) width=400;
	if(!height) height=400;

	/* For center window
	if (document.all || document.layers) {
   	w = screen.availWidth;
   	h = screen.availHeight;
	}
	var leftPos = (w-width)/2, topPos = (h-height)/2;
	*/
	var leftPos = 20, topPos = 20;
	
	if (!myStyle) myStyle = "resizable=yes,status=no,scrollbars=yes";
	myStyle+=",left=" + leftPos + ",top=" + topPos + ",width="+width+",height="+height+"";
	window.open(target,"_blank",myStyle);		
}


function popupDialog(target, arg, width, height)
{
	if(!width) width=400;
	if(!height) height=400;
	if(!arg) arg="";
	
	myStyle = "font-family:Arial; font-size:10; dialogWidth:" + width +"px; dialogHeight:"+ height + "px";
	myStyle +="center:yes; resizable:no; status:no"; 

	// Add kill cache time
	myTime = new Date(); 
	if(target.indexOf("?")>0)
		target+="&xkct=" + myTime.getTime();
	else
		target+="?xkct=" + myTime.getTime();		
	return showModalDialog(target, arg, myStyle);
}

function popupForm(title, target, arg, width, height)
{
	//alert("userAgent:"+navigator.userAgent.toLowerCase()+" version:"+parseInt(navigator.appVersion)+" ie6:"+oBw.ie6);
	myUrl = "/webmod/dwlib/mod_iframe.html?target=" + escape(target) + "&title="+ escape(title);
	
	width+=10;
	height+=30;
	var needReload=popupDialog(myUrl,arg,width,height);
	if(needReload) {
		window.location.reload();
	}	
}

function getObjectByName(objName) {
	return(document.getElementsByName(objName)[0]);
}

function imageUpload2(siteID,cntID,imgID,imgField,imgName,imgDIV,viewParam,langID){	
	imgID = getObjectByName(imgName).value;
	
	var param="action=upload";
	param+="&siteID="+siteID;
	param+="&accountID="+siteID;
	param+="&cntID="+cntID;
	param+="&imgID="+imgID;
	param+="&imgField="+imgField;
	param+="&imgName="+imgName;
	param+="&imgDIV="+imgDIV;
	param+="&langID="+langID;
	param+="&"+viewParam;
	
	myTime = new Date(); 
	param+="&xt"+myTime.getTime(); // kill cache
	//alert("uploadImg:"+param);	
	
	window.open("/diyep/site/?page=common/upload&vmode=noframe&accountID="+siteID+"&"+param,
		"diyep_uploader","left=20,top=20,resizable=yes,width=480,height=250,scrollbars=yes");
}
function imageUpload(siteID,cntID,imgID,imgField,imgName,imgDIV,viewParam,langID){
	
	//imgID=document.all[imgName].value;
	// for netscape
	imgID = getObjectByName(imgName).value;
	
	var param="action=upload";
	param+="&siteID="+siteID;
	param+="&cntID="+cntID;
	param+="&imgID="+imgID;
	param+="&imgField="+imgField;
	param+="&imgName="+imgName;
	param+="&imgDIV="+imgDIV;
	param+="&langID="+langID;
	param+="&"+viewParam;
	
	myTime = new Date(); 
	param+="&xt"+myTime.getTime(); // kill cache
	//alert("uploadImg:"+param);	
	
	window.open("/pxuploader/?"+param,
		"diyep_uploader","left=20,top=20,resizable=yes,width=480,height=250,scrollbars=yes");
}
function imageDelete(siteID,cntID,imgID,imgField,imgName,imgDIV,viewParam){
	// Init
	imgID= getObjectByName(imgName).value;
	if(imgID=="" ||imgID=="0") {return;}
	
	// Checking
	if(siteID=="" ||siteID=="0") {alert("Wrong siteID");return;}
	if(imgName=="") {alert("Wrong imgName");return;}

	var param="action=delete";
	param+="&siteID="+siteID;
	param+="&accountID="+siteID;
	param+="&cntID="+cntID;
	param+="&imgID="+imgID;
	param+="&imgField="+imgField;
	param+="&imgName="+imgName;
	param+="&imgDIV="+imgDIV;
	param+="&"+viewParam;
	//alert("uploadImg:"+param);	
	
	var imgObj=getObjectByName(imgName);
	imgObj.value="0";
	
	var divObj=document.getElementById(imgDIV);
	divObj.innerHTML="<img src='/webmod/uploader/?"+param+"'/>";
}

function bazsCertUpload(siteID,langID){
	
	var param="action=upload";
	param+="&siteID="+siteID;
	param+="&cntID="+siteID;
	param+="&imgID="+siteID;
	param+="&imgField="+siteID;
	param+="&imgName="+siteID;
	param+="&imgDIV="+siteID;
	param+="&langID="+langID;
	param+="&mode=bazs.cert";
	
	myTime = new Date(); 
	param+="&xt"+myTime.getTime(); // kill cache
	
	window.open("/pxuploader/?"+param,
		"diyep_uploader","left=20,top=20,resizable=yes,width=480,height=250,scrollbars=yes");
}

function bazsCertUpload2(siteID,langID){
	var param="action=upload";
	param+="&siteID="+siteID;
	param+="&imgID="+siteID;
	param+="&imgField="+siteID;
	param+="&imgName="+siteID;
	param+="&imgDIV="+siteID;
	param+="&langID="+langID;
	param+="&mode=bazs.cert";
	
	myTime = new Date(); 
	param+="&xt"+myTime.getTime(); // kill cache
	
	window.open("/diyep/site/?page=common/uploadCert&vmode=noframe&accountID="+siteID+"&"+param,
		"diyep_uploader","left=20,top=20,resizable=yes,width=480,height=250,scrollbars=yes");		
}

function getCheckBoxValue(checkbox){
	var counter=0;
	for (counter=0;counter<checkbox.length;counter++)
	{	
		if (checkbox[counter].checked){
			return(checkbox[counter].value);
		}
	}
}


/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function setShow(_w,_h) {
	
	if (oBw.dom)
	{
		
		if (_h=='s') document.getElementById(_w).style.visibility='visible';
		if (_h=='s') document.getElementById(_w).style.display='block';
		if (_h=='h') document.getElementById(_w).style.visibility='hidden';
		if (_h=='h') document.getElementById(_w).style.display='none';
	}
	else if (oBw.ie) {
		if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
		if (_h=='s') eval("document.all."+_w+".style.display='block';");
		if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
		if (_h=='h') eval("document.all."+_w+".style.display='none';");
	}
	else if(oBw.ns)
	{
		if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
		if (_h=='s') eval("document.layers['"+_w+"'].display='block';");
		if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
		if (_h=='h') eval("document.layers['"+_w+"'].display='none';");
	}
}

function removeHTML(str) {
	if (str==null) return(null);
	re = /<([^\s\>]{1,})[^>]*>/gi
	
	var newstr=str.replace(re, "");
	return newstr;
}


function showListAdminBlock() {
				

				
				var timeOutAdminID=0;
				
				var listAdmin = $("#listAdmin");
				var listAdminBlock = $("#listAdminBlock");
				var listAdminFrame = $("#listAdminFrame");
				var listAdminArrowLeft = $("#listAdminArrowLeft");
				
				var iframeBaseURL=listAdminFrame.attr('title');
				
				//show
				$(".ui-icon-information").mouseover(function() {  
					
						var msgCode = $(this).attr("msgCode");
						var iframeURL = iframeBaseURL + "&msgCode="+msgCode;						
						
						clearTimeout(timeOutAdminID);
						timeOutAdminID=0;
							
						listAdmin.show();
						listAdminFrame.attr('src',iframeURL);
						
						listAdmin.css('left', $(this).offset().left - listAdminFrame.width() - $(this).width());
						listAdmin.css('top',$(this).offset().top + ($(this).height()/2));
				});
				
				
				$("#listAdminBlock, #listAdminArrowLeft").mouseover(function() {
					clearTimeout(timeOutAdminID);
				});
				
				
				$("#listAdminBlock, #listAdminArrowLeft, .ui-icon-information").mouseout(function() {
					clearTimeout(timeOutAdminID);
			 		timeOutAdminID=setTimeout(function() {
			 			listAdmin.hide();
						listAdminFrame.attr('src',"");
			 		}, 250);
				});
				
}

