﻿//--------------------------------------------------------------
function $(id){
	return document.getElementById(id);
}

function ChkEmail(str){
	return (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str));
}

//--------------------------------------------------------------
function IsEmpty(str){
	return (/^(\s)*$/.test(str));
}

//--------------------------------------------------------------
function EventKeyDwon(cb){
	if(event.keyCode == 13)
		cb();
}

//--------------------------------------------------------------

function EncodeHtml(str){
	str = str.replace(/</gi,"&lt;");
	str = str.replace(/>/gi,"&gt;");
	str = str.replace(/\+/gi,"&#43;");
	return str;	
}

function DecHtml(str){
	str = str.replace(/&gl;/gi,"<");
	str = str.replace(/&gt;/gi,">");
	return str;	
}

function ChkAll(obj,pre){
    var chks = document.getElementsByTagName("input");
    for(var i=0;i<chks.length;i++){
        if(chks[i].type == "checkbox" && chks[i].id.indexOf(pre) != -1){
            chks[i].checked = obj.checked;
       } 
    }
}

function GetChkAllValues(pre){
     var chks = document.getElementsByTagName("input");
    var ids = "";
    for(var i=0;i<chks.length;i++){
        if(chks[i].type == "checkbox" && chks[i].id.indexOf(pre) != -1){
            if(chks[i].checked){
                ids += chks[i].value + ",";
           } 
       } 
    }
    if(ids.length != 0){
        ids = ids.slice(0,ids.length-1);
    }
    return ids;
}

function OutFlashView(strImgs,strUlrs,strTexts,width,height){
	var focus_width=width;
	var focus_height=height;
	var text_height=0;
	var swf_height = focus_height+text_height;

	var pics=strImgs;
	var links=strUlrs;
	var texts=strTexts;

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="/skins/images/play.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
	document.write('<embed src="/skins/images/play.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); 
	document.write('</object>');
}

function OutFlashHtml(strSrc){
    var html = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"450\" height=\"400\">"
	+"<param name=\"movie\" value=\""+strSrc+"\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#F0F0F0\">"
	+"<embed src=\""+strSrc+"\" wmode=\"opaque\"   type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />"
	+"</object>";
	return html;
}

function ShowMsg(msgId,msg){
    $(msgId).innerHTML = msg;
}

//--------------------------------------------------------------
var Ajax = {};
Ajax.getXmlHttpObject = function(){
	var objReq;
	if (window.XMLHttpRequest){
		objReq = new XMLHttpRequest();
		if (objReq.overrideMimeType){
			objReq.overrideMimeType("text/xml");
		}
	}else if(window.ActiveXObject){
		try{
			objReq = new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch(e){
			try{
				objReq = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				objReq = false;
			}
		}
	}
	return objReq;
};

Ajax.getText = function(uri,aysn){
	var obj = this.getXmlHttpObject();
	if (aysn){
		obj.onreadystatechange = function(){
			if (obj.readyState == 4){
				if (obj.status == 200){
					aysn(obj.responseText);
				}
			}
		}
	}
	uri += (uri.indexOf("?") != -1)?"&":"?";
	uri += "rnd="+(Math.random());
	obj.open("GET",uri,aysn?true:false);
	obj.send(null);
	if(aysn){return null;}
	return obj.responseText;
};

Ajax.Update = function(uri,eleid){
	var obj = this.getXmlHttpObject();
	obj.onreadystatechange = function(){
		if (obj.readyState == 4){
			if (obj.status == 200){
				document.getElementById(eleid).innerHTML = obj.responseText;
			}
		}
	}
	uri += (uri.indexOf("?") != -1)?"&":"?";
	uri += "rnd="+(Math.random());
	obj.open("GET",uri,true);
	obj.send(null);
}

Ajax.PostData = function(uri,data,cb){
	var obj = this.getXmlHttpObject();
	if (cb){
		obj.onreadystatechange = function(){

			if (obj.readyState == 4){
			{	if (obj.status == 200)					        cb(obj.responseText);
				}
			}
		}
	}

	uri += (uri.indexOf("?") != -1)?"&":"?";
	uri += "rnd="+(Math.random());
	obj.open("POST",uri,cb?true:false);
	obj.setRequestHeader("content-length",data.length); 
	obj.setRequestHeader("content-type","application/x-www-form-urlencoded");
	obj.send(data);
	if(cb){return null;}
	return obj.responseText;
}

// PopUi

function PopUI(id,html,evt){	
	var objDiv = document.createElement("div");
	document.body.appendChild(objDiv);
	objDiv.id = "pop_ui_"+id;
		
	objDiv.style.position="absolute";
	objDiv.style.zIndex=4000;
	objDiv.style.padding="5px";
	objDiv.innerHTML = html;
	
	x = evt.clientX?evt.clientX:evt.pageX;
	y = evt.clientY?(evt.clientY + document.documentElement.scrollTop):evt.pageY;
	y = y+10;
	if(x <= 0)
		x = 30;
		
	objDiv.style.left = x + "px";
	objDiv.style.top = y + "px";

	var ifrBg = document.createElement("iframe");
	ifrBg.src="about:blank";

	ifrBg.id = "ifr_ui_"+id;
	ifrBg.style.position="absolute";
	ifrBg.style.zIndex = "3800";

	ifrBg.style.margin = "0";
	ifrBg.style.overflow="hidden";
	ifrBg.style.scrolling="no";
	ifrBg.style.frameborder = "0";
	ifrBg.style.border="0";
	document.body.appendChild(ifrBg);	

	var nDivHeight = objDiv.clientHeight;
	var nDivWidth = objDiv.clientWidth;

	ifrBg.style.width =nDivWidth + "px";
	ifrBg.style.height = nDivHeight + "px";

	ifrBg.style.left = objDiv.style.left;
	ifrBg.style.top = objDiv.style.top;
	ifrBg.style.filter="alpha(opacity=0);-moz-opacity:0";
}

function HidePopUI(id){
	var div = document.getElementById("pop_ui_"+id);
	if(div != null)
		document.body.removeChild(div);
	var ifr = document.getElementById("ifr_ui_"+id);
	if(ifr != null)
		document.body.removeChild(ifr);
	
}


function PopDialog(id,html,evt, flag){	
	var objDiv = document.createElement("div");
	document.body.appendChild(objDiv);
	objDiv.id = "pop_dlg_"+id;
		
	objDiv.style.position="absolute";
	objDiv.style.zIndex=4000;
	objDiv.style.padding="5px";
	objDiv.innerHTML = html;
	if (flag == "point"){
	    	x = evt.clientX?evt.clientX:evt.pageX;
	        y = evt.clientY?(evt.clientY + document.documentElement.scrollTop):evt.pageY;
	        y = y+2;
	        if(x <= 0)
		        x = 30;
	}else{
        x = (screen.width - objDiv.clientWidth)/2;
	    y = (screen.height - objDiv.clientHeight - 100)/2;
	}
		
	objDiv.style.left = x + "px";
	objDiv.style.top = y + "px";

	var ifrBg = document.createElement("iframe");
	ifrBg.src="about:blank";

	ifrBg.id = "ifr_dlg_"+id;
	ifrBg.style.position="absolute";
	ifrBg.style.zIndex = "3800";

	ifrBg.style.margin = "0";
	ifrBg.style.overflow="hidden";
	ifrBg.style.scrolling="no";
	ifrBg.style.frameborder = "0";
	ifrBg.style.border="0";
	document.body.appendChild(ifrBg);	

	var nDivHeight = objDiv.clientHeight;
	var nDivWidth = objDiv.clientWidth;

	ifrBg.style.width =screen.width - 20 + "px";
	ifrBg.style.height = screen.height - 20 + "px";

	ifrBg.style.left = 0;
	ifrBg.style.top = 0;
	ifrBg.style.filter="alpha(opacity=6);-moz-opacity:0.6";
}

function HidePopDialog(id){
	var div = document.getElementById("pop_dlg_"+id);
	if(div != null)
		document.body.removeChild(div);
	var ifr = document.getElementById("ifr_dlg_"+id);
	if(ifr != null)
		document.body.removeChild(ifr);
	
}