
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}







function stdzSlashes(dm) {
	var len = dm.elements.length;
	var i = 0;
	for(i = 0; i < len; i++) {
		if( dm.elements[i].value ) {
			dm.elements[i].value = dm.elements[i].value.replace(RegExp("\'{1}" , "g"), "\\\'");
		}
	}
	return true;
}


function addSlashes( sText ) {
	if( sText) {
		return sText.replace(RegExp("\'{1}" , "g"), "\\\'");
	} else
		return sText;
}


function isNaturalNumber( sText ) {
    var re = /^[\d]+$/;
	return re.test( sText );
}


function isIntNumber( sText ) {
    if( sText.toString( ) == '-0' ) return false;
	
	var re = /^\-?[\d]+$/;
	return re.test( sText );
	
}

 
function isFloatNumber( sText ) {
	if( sText.toString( ) == '-0' ) return false;
	
	var re = /^\-?[\d]+$/;
	if( re.test( sText ) ) return true;
	re = /^\-?[\d]+\.[\d]+$/;
	return re.test( sText );
} 


function isEmpty( sText ) {
	if( !sText ) return false;
    
	return true;
}


function isNumberFormat( sText, sFormat ) {
	var specCharPattern = /[\D]/;
	var specChar = sFormat.match( specCharPattern );
	var aNum = sFormat.split( specChar );
	
	var sCmd = "var re = /^";
	for( var iC = 0; iC < aNum.length; iC++ ) {
		if( iC != 0 )
			sCmd += "\\" + specChar; 
		sCmd += "[0-9]{" + aNum[iC] + "}";
	}
	sCmd += "$/;";
	eval( sCmd );
	return re.test( sText );
}


// validates that the entry is formatted as an email address
function isEmail( sText ) 
{
    var str = sText;
	if(str == "") {
        //alert("Verify the email address format.");
        return false;
    }
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        //alert("Verify the email address format.");
        return false;
    } else {
        return true;
    }
}


function isValidInput( ) {
	var sText = "";
	var bEmptyAllowed = true;
	var bSpaceAllowed = true;
	
	switch( arguments.length ) {
		case 1:
			sText = arguments[0];
			break;
		case 2:
			sText = arguments[0];
			bEmptyAllowed = arguments[1];
			break;
		case 3:
			sText = arguments[0];
			bEmptyAllowed = arguments[1];
			bSpaceAllowed = arguments[2];
			break;
	}
	
	if( bEmptyAllowed ) {
		if( bSpaceAllowed )
			var re = /^[a-zA-Z0-9_\-\s]*$/;
		else 
			var re = /^[a-zA-Z0-9_\-]*/;
	}
	else {
		if( bSpaceAllowed )
			var re = /^[a-zA-Z0-9_\-\s]+$/;
		else 
			var re = /^[a-zA-Z0-9_\-]+$/; 
	}
	
	return re.test( sText );
			
}


function printPage() { print(document); }


function getInput( p_sFormId, p_sInputName ) {
	var oForm = document.getElementById( p_sFormId );
	eval( "var vInputVal = oForm." + p_sRadioName + ".value;" );
	return vInputVal;
}


function getRadio( p_sFormId, p_sRadioName ) {
	var oForm = document.getElementById( p_sFormId );
	
	var checkedVal;
	eval( "var aRadio = oForm." + p_sRadioName + ";" );
	if( aRadio.length ) {
		for( var iC = 0; iC < aRadio.length; iC++ ) {
			if( aRadio[iC].checked ) {
				checkedVal = aRadio[iC].value;
				break;
			}
		}
	} else {
		if( aRadio.checked ) {
			checkedVal = aRadio.value;
		}
	}
	
	return checkedVal;
}


/*
 *	Param:
 *		p_sGName: multiple select box name(not including '[]')
 *	Return:
 *		option array (option within the multiple select box)
 *		checked option number
 *		unchecked option number
 *		checked values array
 */
function getOptionGroup( p_sGName ) {
	var oSelect = document.getElementById( p_sGName + '[]' );
	var aInput = oSelect.getElementsByTagName( "option" );
	var aCheckOption = new Array( );
	var aCheckedValue = new Array( );
	var aTemp = p_sGName.split( "[]" );
	var sGName = aTemp[0];
	
	var iNum = 0;
	var iCheckedNum = 0;
	var iUncheckedNum = 0;
	for( var iC = 0; iC < aInput.length; iC++ ) {
		aCheckOption[iNum++] = aInput[iC];
		if( aInput[iC].selected == true ) {
			aCheckedValue[iCheckedNum] = aInput[iC].value;
			iCheckedNum ++;
		}
		else
			iUncheckedNum++;
	}
	
	return Array( aCheckOption, iCheckedNum, iUncheckedNum, aCheckedValue );
}


//-- Functions set controls checkbox groups interaction
/*
 *	Call on 'checkall' checkbox
 *	Param:
 *		p_sGName: checkbox group name(including '[]')
 */
function checkAll( p_sGName ) {
	var aTemp2 = p_sGName.split( "[]" );
	var sGName = aTemp2[0];
	var oCheckAll = document.getElementById( sGName + "All" );
	var aTemp = getCheckGroup( p_sGName );
	var aCheckbox = aTemp[0];
	var iCheckedNum = aTemp[1];
	
	for( var iC = 0; iC < aCheckbox.length; iC++ ) {
		aCheckbox[iC].checked = oCheckAll.checked;
	}
	
}


/*
 *	Call on each checkbox in group
 *	Param:
 *		p_sGName: checkbox group name(including '[]')
 *		p_vValue: checkbox value
 */
function checkOne( p_sGName, p_vValue ) {
	var aTemp2 = p_sGName.split( "[]" );
	var sGName = aTemp2[0];
	var oCheckAll = document.getElementById( sGName + "All" );
	
	var aTemp = getCheckGroup( p_sGName );
	var aCheckbox = aTemp[0];
	var iCheckedNum = aTemp[1];
	
	if( iCheckedNum == aCheckbox.length )
		oCheckAll.checked = true;
	else
		oCheckAll.checked = false;
}


/*
 *	Param:
 *		p_sGName: checkbox group name(not including '[]')
 *	Return:
 *		checkbox array(checkboxes in the group)
 *		checked checkbox number
 *		unchecked checkbox number
 *		checked values array
 */
function getCheckGroup( p_sGName ) {
	var aInput = document.getElementsByTagName( "input" );
	var aCheckbox = new Array( );
	var aCheckedValue = new Array( );
	var aTemp = p_sGName.split( "[]" );
	var sGName = aTemp[0];
	var iNum = 0;
	var iCheckedNum = 0;
	var iUncheckedNum = 0;
	for( var iC = 0; iC < aInput.length; iC++ ) {
		if( aInput[iC].type == "checkbox" && aInput[iC].name == sGName + "[]" ) {
			aCheckbox[iNum++] = aInput[iC];
			if( aInput[iC].checked == true ) {
				aCheckedValue[iCheckedNum] = aInput[iC].value;
				iCheckedNum ++;
			}
			else
				iUncheckedNum++;
		}
	}
	
	return Array( aCheckbox, iCheckedNum, iUncheckedNum, aCheckedValue );
}
//-- End

function changeTab( vTab ){
	if ( vTab == 'xecu' ){
		document.getElementById( 'xecu' ).innerHTML = "<img src=\"layouts/default/images/xecu_1.jpg\" width=\"80\" height=\"26\" id=\"Image2\" onmouseover=\"MM_swapImage('Image2','','layouts/default/images/xecu_1.jpg',1)\" onmouseout=\"MM_swapImgRestore()\" onclick=\"changeTab( 'xecu' );\" />";	
		document.getElementById( 'xemoi' ).innerHTML = "<img src=\"layouts/default/images/xemoi_1.jpg\" width=\"80\" height=\"26\" id=\"Image1\" onmouseover=\"MM_swapImage('Image1','','layouts/default/images/xemoi.jpg',1)\" onmouseout=\"MM_swapImgRestore()\"  onclick=\"changeTab( 'xemoi' );\"  />";	
		document.getElementById( 'location' ).style.display = 'block';
		document.getElementById( 'type' ).value = 'xecu';
	}
	if ( vTab == 'xemoi' ){
		document.getElementById( 'xecu' ).innerHTML = "<img src=\"layouts/default/images/xecu.jpg\" width=\"80\" height=\"26\" id=\"Image2\" onmouseover=\"MM_swapImage('Image2','','layouts/default/images/xecu_1.jpg',1)\" onmouseout=\"MM_swapImgRestore()\" onclick=\"changeTab( 'xecu' );\" />";	
		document.getElementById( 'xemoi' ).innerHTML = "<img src=\"layouts/default/images/xemoi.jpg\" width=\"80\" height=\"26\" id=\"Image1\" onmouseover=\"MM_swapImage('Image1','','layouts/default/images/xemoi.jpg',1)\" onmouseout=\"MM_swapImgRestore()\"  onclick=\"changeTab( 'xemoi' );\"  />";	
		document.getElementById( 'location' ).style.display = 'none';
		document.getElementById( 'type' ).value = 'xemoi';
	}
	
}

function delImg( pImg, id, type ) {		
	var Params		= new Object();
	Params.id	= id;
	Params.pathImg	= pImg;
	Params.sType	= type;
	oRootEngine.m_bEnableChangeAppPath = false;
	oRootEngine.setParam( Params );
	oRootEngine.doAsyncTaskImp( 'about', '', 'unImg',
	function ( result ) {
		if( result == 1 ){
			document.getElementById('disImg').innerHTML = '';	
			document.getElementById('btnDel').innerHTML = '';				
		}		
		oRootEngine.m_bEnableChangeAppPath = true;
		return false;
	});
}

function delImgHotel( pImg, id, type, divImg, divDel, sImg ) {		
	var Params		= new Object();
	Params.id	= id;
	Params.pathImg	= pImg;
	Params.sType	= type;
	Params.sImg	= sImg;
	oRootEngine.m_bEnableChangeAppPath = false;
	oRootEngine.setParam( Params );
	oRootEngine.doAsyncTaskImp( 'about', '', 'unImg',
	function ( result ) {
		if( result == 1 ){
			document.getElementById(divImg).innerHTML = '';	
			document.getElementById(divDel).innerHTML = '';				
		}		
		oRootEngine.m_bEnableChangeAppPath = true;
		return false;
	});
}

function showImage(name) {
	var address = name;
	window.open( address, Math.round(Math.random()*10000), "copyhistory=no,width=500,height=500,directories=0,menubar=0,resizable=0,status=0,tollbar=0,scrollbars=0");
}

function openImageNews(vLink) {
    var sLink = typeof vLink.href == "undefined" ? vLink : vLink.href;
    if (sLink == "") {
        return false;
    }
    var image = new Image;
    image.src = sLink;
    if (image.height != 0) {
        vHeight = image.height;
        vWidth = image.width;
    }
    winDef = "status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height=".concat(vHeight).concat(",").concat("width=").concat(vWidth).concat(",");
    winDef = winDef.concat("top=").concat((screen.height - vHeight) / 2).concat(",");
    winDef = winDef.concat("left=").concat((screen.width - vWidth) / 2);
    newwin = open("", "_blank", winDef);
    newwin.document.writeln("<title>Images</title><body topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">");
    newwin.document.writeln("<a href=\"\" onClick=\"window.close(); return false;\"><img src=\"", sLink, "\" alt=\"", "Dong lai", "\" border=0></a>");
    newwin.document.writeln("</body>");
    if (typeof vLink.href != "undefined") {
        return false;
    }
}

function getTimeNow(){
	dayname = new Array("Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy");
	monthname = new Array("Tháng Một", "Tháng Hai", "Tháng Ba", "Tháng Tư", "Tháng Năm", "Tháng Sáu", "Tháng Bảy", "Tháng Tám", "Tháng Chín", "Tháng Mười", "Tháng Mười Một", "Tháng Mười Hai");	
	now = new Date();
	daynum = now.getDay();
	day = dayname[daynum];
	date = now.getDate();
	monthnum = now.getMonth();
	month = monthname[monthnum];
	if( now.getYear() == 108 ){
		var vYear = '2008';	
	}else{
		var vYear = now.getYear();	
	}
	document.write(""+day+", "+date+", "+month+", "+vYear);	
}

function searchSite(){
	var oForm = document.getElementById( 'frmSearch' );	
	var sQuery = '';						
	if ( oForm.x_strSearch.value != '' ){
		sQuery +='&key='+oForm.x_strSearch.value;	
	}
	if(REWRITE) window.location.href = oForm.linkSearch.value+'?'+sQuery;
	else window.location.href = 'index.php?sys_sOption=search'+sQuery;
	
	
}		

function getImgSize(imgSrc){
	var newImg = new Image();
	newImg.src = imgSrc;
	var height = newImg.height;
	var width = newImg.width;
	//alert ('The image size is '+width+'*'+height);
}

function changeImage( image ){
	if(image.src != "" ){
		var src = document.getElementById( "imgDisplay" ).src;
		document.getElementById( "imgDisplay" ).src=image.src;
		if(document.getElementById( "imgDisplay" ).height > 440) document.getElementById( "imgDisplay" ).height = 440;
		//image.src = src;
	}
    
}