	// JavaScript Document
/* xml request
   code by minhlt
   last update: 10 Sep 2006
*/

//************* label & message*******************
var msgExistEmail = 'Email đã tồn tại';
var msgExistUsername = 'Username đã tồn tại';

//************* label & message*******************
var request;
var queryString;
var strResponse;
function httpRequestPost(frm,url, isAsynch, contentType){
    setQueryString(frm);
    httpRequest("POST",url,true, contentType);
}

function setQueryString(frm){
    queryString="";
    var numberElements =  frm.elements.length;
    for(var i = 0; i < numberElements; i++) {
		if((frm.elements[i].name == "chkItem[]") && !frm.elements[i].checked) {
			continue;	
		}
    	queryString += frm.elements[i].name+"="+ encodeURIComponent(frm.elements[i].value)+"&";
    }
	queryString = queryString.substr(0, queryString.length-1);
}

 function httpRequest(requestType, url, isAsynch, contentType) {
	 //return true;
 	if(window.XMLHttpRequest) {
		request = new XMLHttpRequest();		
	} else if(window.ActiveXObject){
		request = new ActiveXObject("Msxml2.XMLHTTP");
		//alert(request);
		if(!request) {
			request = new ActiveXObject("Microsoft.XMLHTTP");
			//alert(request);
		}
	}
	if (request.overrideMimeType) {
       //request.overrideMimeType('text/xml');   
    }
	if(request) {
		initRequest(requestType, url, isAsynch, contentType);
		return false;
	} else {
		return true;
	}
 }
 
var p_ = "modules/map/e_map/";
var ext = '.jpg';

 function initRequest(requestType, url, isAsynch, contentType){
 	request.open(requestType, url, isAsynch);
	request.onreadystatechange = function() {
 	if(request.readyState == 4) {
		if(request.status == 200) {
				//alert(request.responseText);
				if (contentType.length != 0) {
					document.getElementById(contentType).innerHTML = request.responseText;
				} else {
					strResponse = request.responseText;
				}
				
				document.getElementById("loading").style.display="none";
				//dhtmlHistory.add(url,url);
			//}
		} else {
			alert("loi");
		}	
	} else {
		//document.getElementById("loading").style.top = 10 + document.documentElement.scrollTop + 'px';
		document.getElementById("loading").style.display="";	
	} 
 };
	if (requestType == "GET") {
		request.send(null);
	} else {
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    	request.send(queryString);
	}
 }
 
 
function showResult(blockId, content) {
	if (document.getElementById(blockId)) {
		document.getElementById(blockId).innerHTML=content;	
	}
}


function changeLang(lang_id, returnURL) {
	var indexOfStrLang = -1;
	indexOfStrLang = returnURL.indexOf('&clid',0);
	if (indexOfStrLang == -1) {
			location.href = '?clid=' + lang_id;	
	} else {
		returnURL = returnURL.substr(0,returnURL.indexOf('&clid'));
		location.href = '?' + returnURL + '&clid=' + lang_id;	
	}
}

function showhide(blockID){
	var Elem = document.getElementById(blockID);		
	var Img = document.getElementById('image' + blockID);
	 if(Elem.style.display != '') { 
	 	Elem.style.display = '';
	 	Img.src = "images/minus.gif";
	 } else {
	 	Elem.style.display = 'none';
	 	Img.src = "images/plus.gif";
	 }
}

function checkAll(currentChk) {
	var aryItems = new Array();
	aryItems = document.getElementsByName("chkItem[]");
	if (currentChk.checked) {
		for(i = 0, n = aryItems.length; i < n; i++) {
			aryItems[i].checked = true;
		}
	} else {
		for(i = 0, n = aryItems.length; i < n; i++) {
			aryItems[i].checked = false;
		}
	}
}

function showHideEditBlock(block_name, block_id) {
	//alert(block_name);
	if (document.getElementById("edit_block_title").style.display == "none") {
		/*var postX = e.clientX;
		var postY = e.clientY;
		document.getElementById("edit_block_title").style.top = postY + 'px';
		document.getElementById("edit_block_title").style.left = postX + 'px';
		*/
		var url = 'modules/blocksman/frm_edit_title.php?block_name=' + block_name + '&block_id=' + block_id;
		document.getElementById("edit_block_title").style.display = "";
		httpRequest('GET',url,true,'edit_block_title');	
	} else {
		document.getElementById("edit_block_title").style.display = "none";		
	}
	return false;
}

function changeorderservice(myRadio) {
	var service = myRadio.value;
	//alert(service);	
	if (service=="thuevay") {
		document.getElementById("orderservice").style.display = "";
	} else {
		document.getElementById("orderservice").style.display = "none";	
	}
	return true;
}

function onChangeCatAdmin(thisSelect,cat_type) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/news/listnews.php?aj=true&cid=' + cat_id + '&cat_type='+cat_type;
		httpRequest('GET',url,true,'main_content');
}

function onChangeCatProject(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/bv_construction/listconstruction.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}
function onChangeCatAlbum(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/album/imagealbum.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}

function onChangeCatColection(thisSelect) {		
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/colection/image_colection.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}

function onChangeCatAdminJobs(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		//alert(cat_id);
		var url = 'modules/jobs/listjobs.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}
function onChangeCatSearchJobs(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		//alert(cat_id);
		var url = 'modules/jobs/search_jobs.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}
function reOrderCat(thisFrm , modulename) {
		//alert(thisFrm.name);
		var url = 'modules/categories/listcat.php?aj=true&param=reorder&mname=' + modulename ;
		httpRequestPost(thisFrm,url,true,'main_content');
}

function doActionCat(thisFrm, moduleName) {
		//alert(getChecked());
		var url = 'modules/categories/listcat.php?aj=true&param=s_action&mname='+moduleName;
		//alert(url);
		httpRequestPost(thisFrm,url,true,'main_content');
}
function doActionNews(frm, qstring, mySelect) {
		if (mySelect.options[mySelect.selectedIndex].value != 'moveto_cat') {
			document.listnews.action = '?module=news&action=listnews&param=s_action' + qstring;
			//alert(document.listnews.action);
			document.listnews.submit();
		} else {
			document.getElementById("moveto_cat").style.display = "";
			document.frmMoveTo.str_news_id.value = getChecked();
		}
}

 
function doActionProject(frm, qstring, mySelect) {
		if (mySelect.options[mySelect.selectedIndex].value != 'moveto_cat') {
			document.listnews.action = '?module=bv_construction&action=listconstruction&param=s_action' + qstring;
			//alert(document.listnews.action);
			document.listnews.submit();
		} else {
			document.getElementById("moveto_cat").style.display = "";
			document.frmMoveTo.str_prj_id.value = getChecked();
		}
}
function doActionAlbum(frm, qstring, mySelect) {
			document.listnews.action = '?module=album&action=imagealbum&param=s_action' + qstring;
			///alert(document.listnews.action);
			document.listnews.submit();
		
}

function doActionColection(frm, qstring, mySelect) {
			document.listnews.action = '?module=colection&action=image_colection&param=s_action' + qstring;
			///alert(document.listnews.action);
			document.listnews.submit();
		
}

function doActionContact(thisFrm, moduleName,type) {
		//alert(getChecked());
		var url = 'modules/contact/listcontact.php?aj=true&param=s_action&mname='+moduleName +'&type=' +type;
		//alert(url);
		httpRequestPost(thisFrm,url,true,'main_content');
}

function doActionAnswer(thisFrm, moduleName,contat_id) {
		//alert(getChecked());
		var url = 'modules/contact/contactdt.php?aj=true&param=s_action&mname='+moduleName +'&ctid=' +contat_id;
		//alert(url);
		httpRequestPost(thisFrm,url,true,'main_content');
}

function doActionInfo_bv(thisFrm, moduleName) {
		//alert(getChecked());
		var url = 'modules/info_bv/addinfo.php?aj=true&param=s_action&mname='+moduleName;
		//alert(url);
		httpRequestPost(thisFrm,url,true,'main_content');
}


// end  bach viet
function doActionJobs(frm, qstring, mySelect) {
	if (mySelect.options[mySelect.selectedIndex].value != 'moveto_cat') {
			document.listnews.action = '?module=job&action=listjobs&param=s_action' + qstring;
			//alert(document.listnews.action);
			document.listjobs.submit();
		} else {
			document.getElementById("moveto_cat").style.display = "";
			document.frmMoveTo.str_jobs_id.value = getChecked();
		}
}
function doActionBanner(thisFrm) {
		var url = 'modules/banner/listbanners.php?aj=true&param=s_action';
		httpRequestPost(thisFrm,url,true,'main_content');
}

function getChecked() {
	var aryChecked = new Array();
	var str_checked = '';
	aryChecked = document.getElementsByName("chkItem[]");
	for (i = 0, n= aryChecked.length;i < n; i++) {
		if (aryChecked[i].checked) {
				str_checked = str_checked + aryChecked[i].value + "','";
		}
	}
	return str_checked.substr(0,str_checked.length-3);
}
function doActionHomepage() {
		document.homepage.action = '?module=homepage&action=listnewshp&param=s_action';
		document.homepage.submit();
}
function doActionModules() {
	document.modules.action = '?module=modulesman&action=listmodules&param=s_action';
	document.modules.submit();
}
function doActionBlocks(thisFrm) {
	var url = 'modules/blocksman/listblocks.php?aj=true&param=s_action';
	httpRequestPost(thisFrm,url,true,'main_content');
}
function doActionPoll(thisFrm) {
	var url = 'modules/poll/listpoll.php?aj=true&param=s_action';
	httpRequestPost(thisFrm,url,true,'main_content');
}
	function reOrderBlock(thisFrm) {
		var url = 'modules/blocksman/listblocks.php?aj=true&param=reorder';
		httpRequestPost(thisFrm,url,true,'main_content');
	}
function reOrderBanner(thisFrm) {
	var url = 'modules/banner/listbanners.php?aj=true&param=reorder';
	httpRequestPost(thisFrm,url,true,'main_content');
}

function submitEditBlock() {
	//document.block.action = '?module=blocksman&action=listblocks&param=eblock';
	document.blocks.submit();
}
function submitMoveToCat() {
	document.frmMoveTo.action = '?module=news&action=listnews&param=moveto';
	document.frmMoveTo.submit();
}
function hideMoveToBlock() {
	document.getElementById("moveto_cat").style.display = "none";		
}

function changeCatTypeList(mySelect) {
		optionValue = mySelect.options[mySelect.selectedIndex].value;
		url = "modules/categories/listcat.php?aj=true&cat_type=" + optionValue;
		//alert(url);
		httpRequest('GET',url,true,'main_content');
	
}

function changeCatTypeAddCat(myRadio) {
		radioValue = myRadio.value;
		url = "modules/categories/addcat.php?aj=true&cat_type=" + radioValue;
		//alert(url);
		httpRequest('GET',url,true,'main_content');
	
}

function changeCatTypeAdd(myRadio) {
		var radioValue = myRadio.value;
		var module_name = document.categories.module_name.value;
		url = "modules/categories/show_category_tree.php?aj=true&cat_type=" + radioValue + "&module_name=" + module_name;
		//alert(url);
		httpRequest('GET',url,true,'change_cat_type');
	
}
function changeCatTypeAddNews(myRadio) {
		var radioValue = myRadio.value;
		var module_name = 'news';
		url = "modules/categories/show_category_tree.php?aj=true&cat_type=" + radioValue + "&module_name=" + module_name;
		//alert(url);
		httpRequest('GET',url,true,'change_cat_type');
	
}

function changeModuleStaticpage(myRadio) {
		var radioValue = myRadio.value;		
		url = "modules/static_page/liststatic_page.php?aj=true&modulestatic=" + radioValue;
		//alert(url);		
		httpRequest('GET',url,true,'main_content');
	
}

function changeModuleType(myRadio) {
		var radioValue = myRadio.value;		
		url = "modules/news/listnews.php?aj=true&cat_type=" + radioValue;
		//alert(url);		
		httpRequest('GET',url,true,'main_content');
	
}

// get 
function changeCatTypeAddProject(myRadio) {
		var radioValue = myRadio.value;
		var module_name = 'bv_prj';
		url = "modules/categories/show_category_tree.php?aj=true&cat_type=" + radioValue + "&module_name=" + module_name;
		//alert(url);
		httpRequest('GET',url,true,'change_cat_type');
	
}

function showHidePanel(panel_id) {
	var panel = document.getElementById(panel_id);
	if (panel.style.display == '') {
		panel.style.display = 'none';
	} else {
		panel.style.display = '';
	}
}


			
function Scroll() {	
	setInterval("doScroll()",1);
}
	
function doScroll() {
	var divTop;
	if (document.documentElement && document.documentElement.scrollTop) {
		divTop = parseInt(document.documentElement.scrollTop);
	} else if (document.body) {
		divTop = parseInt(document.body.scrollTop);
	}
	var scrollDivLeft = document.getElementById("scrollDivLeft");
	var scrollDivRight = document.getElementById("scrollDivRight");
	var leftTop = parseInt(scrollDivLeft.style.top) + (divTop - parseInt(scrollDivLeft.style.top))/16;
	scrollDivLeft.style.top = leftTop + "px";
	var rightTop = parseInt(scrollDivRight.style.top) + (divTop - parseInt(scrollDivRight.style.top))/16;
	scrollDivRight.style.top = rightTop + "px";
}
		
function confirmActionGet(confirm_url) {
	if(confirm("Bạn có muốn thực hiện thao tác này không?")) {
		location.href=confirm_url;
		return false;
	} else {
		return false;
	}
}

function changeCVType(thisSelect) {
	var cv_type = thisSelect.options[thisSelect.selectedIndex].value;
	var url = '?module=jobs&action=search_cv&cv_type=' + cv_type;
	location.href=url;
}
function changeCVTypeSearch(thisSelect) {
	var cv_type = thisSelect.options[thisSelect.selectedIndex].value;
	var url = '?module=jobs&action=cv_filter&cv_type=' + cv_type;
	location.href=url;
}

function changeCvTypeCreate(cv_type) {
	//radio
	var cv_action = 'create_cv';
	if (cv_type == 'enrol') {
		cv_action = 'create_enrol_cv';
	} else if (cv_type == 'outbound') {
		cv_action = 'create_outbound_cv';
	}
	url = '?module=jobs&action=' + cv_action;
	location.href=url;
}
function changeCvTypeAdmin(cv_type) {
	//radio
	url = '?module=jobs&action=cv_manager&cv_type='+cv_type;
	location.href=url;
}

function addBannerValidate() {
	var uploadFile = document.getElementById("banner_upload").value;
	if (uploadFile.length >5) {
		var ext = uploadFile.match(/(.{3}$)/)[1];
		if (ext.toLowerCase() != 'jpg' && ext.toLowerCase() != 'gif' && ext.toLowerCase() != 'png' && ext.toLowerCase() != 'swf') {
			alert('File khong hop le !');
			return false;
		}
	}	
}

function replaceString(str, needle, replace_by) {
	if (str.length > 0) {
		while (str.search(needle)!=-1) {
			str = str.replace(needle, replace_by);
		}
	}
	return str;
}

/////////////////////////////////
	
	function fastURL(url, isAsync,block_to_update) {
		//alert('Hi');
		/*url = url.substring(url.indexOf('module'));
		var pattern = /module=(\w+)&action=(\w+)[&\s]/;
		var fastURL = url.replace(pattern,"modules/$1/$2.php?");
		if (fastURL.indexOf('aj=false') !=-1) {
			fastURL =fastURL.replace('aj=false',"aj=true");
		} else {
			fastURL += '&aj=true';
		}*/		
		
		var fastURL = url.replace('.htm', '.ajax');
		//alert(fastURL);
		httpRequest('GET', fastURL, true, block_to_update);
		return false;
	}
	
	
	function adminFastURL(url, isAsync,block_to_update) {
		url = url.substring(url.indexOf('module'));
		var pattern = /module=(\w+)&action=(\w+)[&\s]/;
		var fastURL = url.replace(pattern,"modules/$1/$2.php?");
		if (fastURL.indexOf('aj=false') !=-1) {
			fastURL =fastURL.replace('aj=false',"aj=true");
		} else {
			fastURL += '&aj=true';
		}
		httpRequest('GET', fastURL, true, block_to_update);
		return false;
	}
	
	function ChangeAddImageAbum(){
		alert("Hoannet");	
	
	}