﻿function Download(s)
{
	if(s!=null && s!="")
		window.open(s,"","width=0;heigth=0");
	else
	{
		alert("Không tồn tại");
	}	
}
function show(id,tb){
		w = screen.availWidth-10;
		h = screen.availWidth;
		window.open("view.aspx?id="+trimSpace(id)+"&tb="+tb,"","top=0,left=0,width="+w+",height="+h+",resizable=0,scrollbars=1,status=1");
	}
function trimSpace(s)
{
	for(i=0;i<s.length;i++)
		s = s.replace("&nbsp;"," ");
	while(s.charCodeAt(0)==32 && s.length>1)
	{
		s=s.substr(1,s.length)
	}
	
	//-------------------------
	if(s.charCodeAt(0)==32 && s.length==1)
		return "";
	else
		return s;	
}
//Cac function xu ly Main, MainFull
function Main_GhiChu_Click(XKH,CNDK){
	Main_AddVar("ActiveIBound:" + XKH + "|PageLevel:TrangCon|Activecontrol:" + CNDK); 
	Main_Submit();
}
//Cac function xu ly IBound
function IB_Click(CNDK,TuKhoa,TuKhoa_Customize){
	Main_AddVar("ActiveIBound:" + TuKhoa + "|PageLevel:TrangCon|ActiveControl:" + CNDK);
	Main_DelVar("ASPNAME|CustomizeMaCNDK|CustomizeKey|" + TuKhoa_Customize);
	Main_Submit();
}
function IBEx_Click(strAddVar,strDelVar,CNDK,aspName){
	var strAddVarEx = "";
	var strDelVarEx = "";
	if(CNDK!= null&&aspName!= null&&CNDK!=""&&aspName!=""){
		strAddVarEx = "PageLevel:TrangCon|ActiveIBound:GROUPEX|ActiveControl:" + CNDK + "|ASPNAME:" + aspName;
		strDelVarEx = "CustomizeMaCNDK|CustomizeKey";
		strAddVar = (strAddVar!= "")?(strAddVarEx + "|" + strAddVar):(strAddVarEx);
		strDelVar = (strDelVar!= "")?(strDelVarEx + "|" + strDelVar):(strDelVarEx);
	}	
	Main_AddVar(strAddVar);
	Main_DelVar(strDelVar);
	Main_Submit();
}
function SubMenu_Click(CNDK,TuKhoa,TuKhoa_Customize,strAddVar,strDelVar){
	Main_AddVar("ActiveIBound:" + TuKhoa + "|PageLevel:TrangCon|Activecontrol:" + CNDK + "|" + strAddVar);
	var strDelVarEx = "ASPNAME|CustomizeMaCNDK|CustomizeKey|" + TuKhoa_Customize;
	if(strDelVar!= "") strDelVarEx += "|" + strDelVar;
	Main_DelVar(strDelVarEx);
	Main_Submit();
}
function IB_Over(src){
	src.className = "IB_Text_Hover";
	span = src.getElementsByTagName("span");
	if(span.length>0){
	 span[0].className = src.className;
	}
}
function IB_Out(src){
	src.className = "IB_Text";
	span = src.getElementsByTagName("span");
	if(span.length>0){
	 span[0].className = src.className;
	}
}
function IBoundRight_Title_Over(src){
	src.className = "IB_Right_Text_Hover";
}
function IBoundRight_Title_Out(src){
	src.className = "IB_Right_Text";
}
function SubIB_Over(src){
	src.className = "SubIB_Text_Hover";
}
function SubIB_Out(src){
	src.className = "SubIB_Text";
}
//Cac function xu ly Bound
function Bound_Xuly(Index,OldVal,TuKhoa,KieuLoai){
	if(Index==1 && OldVal=="1") Index=2;
	if(Index==3 && OldVal=="3") Index=2;
	if (Index==5){
		Main_AddVar(TuKhoa + ":" + Index.toString() + "|CustomizeKey:" + TuKhoa);
		if (KieuLoai=="C"){
			Main_DelVar("ActiveControl|ActiveTab");
		}
	}else{
		Main_AddVar(TuKhoa + ":" + Index.toString());
	}
}
function Bound_Frame_Click(KieuLoai,DuongDan){
	//Bound một Frame//Frame có liên kết
	if (KieuLoai=="F"){
		sFeature="";
		window.open (DuongDan,"_blank", sFeature, true);
		return true;
	}
	return false;
}
function Bound_Click(CNDK,TuKhoa,KieuLoai,DuongDan){
	//Xử lý Frame_Title_Click nếu có
	if (Bound_Frame_Click(KieuLoai,DuongDan)){
		return;
	}
	Main_AddVar("PageLevel:TrangCon|ActiveBound:" + TuKhoa + "|ActiveControl:" + CNDK);
	Main_Submit();
}
function Bound_Over(src){
	src.className = "Caption_Text_Hover";
}
function Bound_Out(src){
	src.className = "Caption_Text"; 
}
function Bound_XuLyHelp(HeplFile){
	OpenWin("Help/index.aspx?test="+HeplFile);
}
//Các function phục vụ xử lý Status
function Status_Item_Over(src){
	if (src.id.toUpperCase()!=Status_SelectedID.toUpperCase()){
		src.className = "Status_Text_Hover";
	}
}
function Status_Item_Out(src){
	if (src.id.toUpperCase()!=Status_SelectedID.toUpperCase()){
		src.className = "Status_Text_Normal";
	}
}
//Các function phục vụ xử lý Footer
function Footer_Item_Over(src){
	if (src.id.toUpperCase()!=Footer_SelectedID.toUpperCase()){
		src.className = "Footer_Text_Hover";
	}
}
function Footer_Item_Out(src){
	if (src.id.toUpperCase()!=Footer_SelectedID.toUpperCase()){
		src.className = "Footer_Text_Normal";
	}
}
//Liên kết nội dung
function Insert_Link(strAddVar,FunctionId){
	if(strAddVar!=""){
		var strVar = strAddVar.split("|");
		if(strVar[0]!="LKNDN")
		{
			Main_AddVar(strAddVar + "|PageLevel:TrangCon|ActiveIBound:LINK|ActiveControl:" + FunctionId);
			Main_DelVar("ASPNAME|CustomizeMaCNDK|CustomizeKey");
			Main_Submit();
		}else{
			Path = "Common/TextEditor/LKNDN.aspx?" + strVar[1];			
			Link_File (Path)
		}
	}
}
function Link_File(strPath){
	var w1 = 716, h1=480;
	var strTop = parseInt((screen.height - h1)/2)-20;
	var strLeft = parseInt((screen.width - w1)/2);
	args="width="+w1+"px,height="+h1+"px,top="+strTop+"px,left="+strLeft+"px,resizable=0,scrollbars=1,status=1";	
	window.open(strPath,"mainwindow",args);		
}
function Main_PageSize(VarPageSize){
	CancelBubble();
	Main_AddVar(VarPageSize);		
	Main_Submit();
} 
///////////////
function Main_AddVar(strValue){
	var oldVal = document.getElementById(Index_hidAddVVS_ClientID).value;
	if(oldVal!="") strValue = oldVal + "|" + strValue;
	document.getElementById(Index_hidAddVVS_ClientID).value = strValue;
	document.getElementById(Index_hidActived_ClientID).value = "TRUE";
}
function Main_DelVar(strValue){
	var oldVal = document.getElementById(Index_hidAddVVS_ClientID).value;
	if(oldVal!="") strValue = oldVal + "|" + strValue;
	document.getElementById(Index_hidDelVVS_ClientID).value = strValue;
	document.getElementById(Index_hidActived_ClientID).value = "TRUE";
}
function CancelBubble(){
	if(document.all) window.event.cancelBubble = true;
}
function Main_Submit(){
	document.getElementById("frmIndex").submit();
}
function EventElement(mEvent){
	var nav = navigator.userAgent.toLowerCase();	
	if (nav.indexOf('msie') > -1)	return window.event.srcElement; //IE
	else if (mEvent.target)			return mEvent.target;//Netscape and Firefox		
	return null;
}
function Event(mEvent){	
	var nav = navigator.userAgent.toLowerCase();	
	if (nav.indexOf('msie') > -1)	return window.event; //IE
	else if (mEvent.target)			return mEvent;//Netscape and Firefox		
	return null;
}
function OpenWin(Path) {
	var w1 = 716, h1=480;
	var strTop = parseInt((screen.height - h1)/2)-20;
	var strLeft = parseInt((screen.width - w1)/2);
	args="width="+w1+"px,height="+h1+"px,top="+strTop+"px,left="+strLeft+"px,resizable=0,scrollbars=1,status=1";	
	window.open(Path,"mainwindow",args);
	window.event.returnValue = false;
}
function Trim(str){
    var strT='';
    for (u=0;u<str.length;u++){
        if (str.charAt(u)!=' ')
        strT=strT + str.charAt(u);  
    }
    return strT;
}
//////////////////////
function showDateVN(strDate){
	var dt = new Date(strDate);			
	var strarrDay = new Array("Chủ nhật", "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy"); 
	var strarrMonth = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); 
	var strThu = dt.getDay();
	strThu = strarrDay[strThu] + ", ";
	var strDay = dt.getDate();
	if (strDay<10) strDay="0" + strDay;
	var strMonth = dt.getMonth();
	strMonth= strarrMonth[strMonth];
	var strYears = dt.getYear();
	if (strYears<1900) strYears += 1900;
	
	var strdate = "&nbsp;" + strThu + " " + strDay + "/" + strMonth + "/" + strYears;
	document.getElementById("spnDate").innerHTML = strdate;
}
function isMaxLength(title,maxLength,ctrl)
{
	s = trimSpace($(ctrl).value);
	if(s!=null && s!="" && s.length>maxLength)
	{
		alert("Chiều dài tối đa của " + title + " là " + maxLength + " ký tự!");
		$(ctrl).focus();
		return false;
	}	
	return true
}
function showImage(url){
	var img = new Image();	
		img.src = url;		
		window.open(url,"","width="+(img.width)+",height="+(img.height));
}
