
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 myBestTrim(str){  
		str = str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
		return str;
 } 
 
 //cookie
 function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
 //end cookie
 
function locdau(str){

	str= str.toLowerCase();
	str = str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
	str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
	str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
	str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
	str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
	str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
	str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
	str= str.replace(/đ/g,"d");
	str= str.replace(/!|@|\$|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\'| |\"|\&|\#|\[|\]|~/g,"-");
	str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-
	str= str.replace(/^\-+|\-+$/g,"");//cắt bỏ ký tự - ở đầu và cuối chuỗi
	str= str.replace(/^\ +|\ +$/g,"");//cắt bỏ ký tự - ở đầu và cuối chuỗi
	return str;
}

function searchSite(){
	var oForm = document.getElementById( 'frmSearch' );	
	/*var sQuery = '';		
	var sQuery2 = '';
	var myCars=new Array(); // regular array (add an optional integer
	if ( oForm.x_strSearch.value != '' ){
		myBestTrim(oForm.x_strSearch.value);
		myCars[0] = oForm.x_strSearch.value;
		Set_Cookie( "searchvl", myCars, "", "", "", "" )
		sQuery += locdau(oForm.x_strSearch.value);	
	}
	if(REWRITE){
			window.location.href = oForm.linkSearch.value+'search/'+sQuery+'.html';
	}
	else window.location.href = 'index.php?sys_sOption=search'+sQuery;*/
	if(oForm.x_strSearch.value == ""){
		alert("Nhập từ khóa tìm kiếm");	
		oForm.x_strSearch.focus();
		return false;
	}else return true;
	
}		

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;
	}
    
}

function setFile(elementId,theWidth,theHeight)
	{
		var theTop=(screen.height/2)-(theHeight/2);
		var theLeft=(screen.width/2)-(theWidth/2);
		var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",scrollbars=yes";
		var win = window.open('../FCKeditor/editor/plugins/ajaxfilemanager/ajaxfilemanager.php?editor=form&elementId='+elementId, 'FileImageManager',features);		
		return false;
	}
	
	function addFile() {
		var br = document.createElement("br")
		var newInput = document.createElement("input");
		newInput.name = "x_color[]";
		newInput.type = "text";
		document.getElementById("list").appendChild(br);
		document.getElementById("list").appendChild(newInput);
	}
	function removeElement(divNum) {
	  var d = document.getElementById('list');
	  var olddiv = document.getElementById(divNum);
	  d.removeChild(olddiv);
	}
	
	function addEvent() {
	  var ni = document.getElementById('list');
	  var numi = document.getElementById('theValue');
	  var num = (document.getElementById("theValue").value -1)+ 2;
	  numi.value = num;
	  var divIdName = "my"+num+"Div";
	  var newdiv = document.createElement('div');
	  newdiv.setAttribute("id",divIdName);

	  
	  newdiv.innerHTML = "<input type=\"text\" class=\"input\" size=\"60\" name=\"x_img_color[]\" value=\"\" id='x_img_color_"+ num +"' readonly=\"readonly\" />&nbsp;<button onclick=\"return setFile('x_img_color_"+ num +"','800','600');\">Browse</button>&nbsp;&nbsp;Màu &nbsp;&nbsp;<input type=\"text\" class=\"input\" size=\"30\" name=\"x_color[]\" value=\"\" id='x_color_"+ num +"'   />&nbsp; &nbsp;Giá &nbsp;<input type=\"text\" class=\"input\" size=\"20\" name=\"x_price_color[]\" value=\"\" id='x_price_color_"+ num +"'   />&nbsp; &nbsp;<a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\"> Xóa </a>";
	  ni.appendChild(newdiv);
}



function removeElement(divNum) {
  var d = document.getElementById('list');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}


	function changeImg(floatimg,img,titlep,price) {
      	floatimg.setAttribute("src", img);
	  	//window.document.title = titlep;
		var pricecolor = document.getElementById('pricecolor');
		pricecolor.innerHTML = price;
    }
 function showcontent1(ele,titlec){
			//alert("asd")
		   	 ele.style.display = "";
			  window.document.title = titlec;
		   }
		   
var newwindow = ''
function popitup(url) {
if (newwindow.location && !newwindow.closed) {
    newwindow.location.href = url;
    newwindow.focus(); }
else {
    newwindow=window.open(url,'htmlname','width=404,height=316,resizable=1');}
}

function tidy() {
if (newwindow.location && !newwindow.closed) 
{
   newwindow.close();
  }
}
function changer_x_supp() {
  var x_supp = document.getElementById('x_supp');
  if(x_supp.value == 0){
	  document.getElementById('x_supp_valid').value = 2;
  }
}
function changer_x_hdh() {
  var x_supp = document.getElementById('x_hdh');
  if(x_supp.value == 0){
	  document.getElementById('x_hdh_valid').value = 2;
  }
}
function changer_x_price() {
  var x_supp = document.getElementById('x_price');
  if(x_supp.value == 0){
	  document.getElementById('x_price_valid').value = 2;
  }
}
function checkbox1(){
	  
	var alen=document.frmSearchleft.x_type1.length;
	$k = 0;
	for(var i=0;i<alen;i++){
			if(document.frmSearchleft.x_type1[i].checked==true){
				$k = $k + 1;
			}
	}
	if ($k > 0)
	{
		 document.getElementById('x_check').value = 0;
	}else
	{
		 document.getElementById('x_check').value = 2;
	}				
	
}

function change_price(temp){
	document.getElementById('cboprice').value = temp;
	document.mainForm.submit();	
}

function pagingChangePage2(){
	var oForm = document.getElementById( 'mainForm' );	
	if(oForm.x_cateId.value != 0){
		var sQuery = '&c_id=' + oForm.x_cateId.value;
	}
	if(oForm.cboprice.value != 0){
		var cQuery = '&cboprice='+oForm.cboprice.value;
	}else{
		var cQuery = "";
	}
	if(REWRITE){
		window.location.href = oForm.linkCate.value+'?page='+oForm.page2.value+cQuery;
	}else{
		window.location.href = 'index.php?sys_sOption='+oForm.sys_sOption.value+'&sys_sTask='+oForm.sys_sTask.value+sQuery+'&page='+oForm.page2.value+cQuery;
	}	
	
}

