	// 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 onChangeCatAdmin(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/news/listnews.php?aj=true&cid=' + cat_id;
		httpRequest('GET',url,true,'main_content');
}
function onChangeCatAdminProducts(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/products/list.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 reOrderChildren(thisFrm, moduleName) {
		//alert(thisFrm.name);
		var url = 'modules/solienlac/list.php?aj=true&param=reorder&mname=' + moduleName;
		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 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 doActionProduct(frm, qstring, mySelect) {
		if (mySelect.options[mySelect.selectedIndex].value != 'moveto_cat') {
			document.listnews.action = '?module=products&action=list&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 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 onChangProductsImage(thisSelect) {
		var product_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/products/image_products.php?aj=true&pid=' + product_id;
		
		httpRequest('GET',url,true,'main_content');
}

function onChangeCatAdminsolienlac(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/solienlac/list.php?aj=true&cid=' + cat_id;
		
		httpRequest('GET',url,true,'main_content');
}
function onChangeCatVideo(thisSelect) {
		var cat_id = thisSelect.options[thisSelect.selectedIndex].value;
		var url = 'modules/video/index.php?aj=true&cid=' + cat_id;
		
		httpRequest('GET',url,true,'main_content');
}

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 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 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 reOrderManufacture(thisFrm) {
	var url = 'modules/manufacture/list.php?aj=true&param=reorder';
	//alert(url);
	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 changeLinkCat(myRadio,strQuery) {
		radioValue = myRadio.value;
		
		url = "modules/categories/listcat.php?link_type=" + radioValue + strQuery;
		//alert(url);
		httpRequest('GET',url,true,'main_content');
	
}

function changeSupport(mySelect) {
		//alert(getChecked());
		optionValue = mySelect.options[mySelect.selectedIndex].value;
		var url = 'modules/support/list_support_value.php?aj=true&mname=menu&supporter_id=' + optionValue;
		//alert(url);
		httpRequest('GET',url,true,'main_content');
}
function changeCatTypeList(mySelect) {
		optionValue = mySelect.options[mySelect.selectedIndex].value;
		url = "modules/categories/listcat.php?aj=true&mname=menu&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 changeLinkType(myRadio) {
		var radioValue = myRadio.value;
		/* Reset */
		$('#selected_link_id').attr('value','');
		$('#selected_name').html('');
		/********/
		if (radioValue == 'news') {
			url = "modules/categories/show_list_news.php?aj=true&cat_type=" + radioValue;
			httpRequest('GET',url,true,'link_to');
		} else if (radioValue == 'product') {
			$('#menu_link_to').show();
			url = "modules/categories/show_list_products.php?aj=true&cat_type=" + radioValue;
			httpRequest('GET',url,true,'link_to');
		} else if (radioValue == 'news_category') {
			url = "modules/categories/show_category_tree.php?aj=true&cat_type=0&module_name=news&cb_name=cb_link_id";
			httpRequest('GET',url,true,'link_to');
		} else if (radioValue == 'products_category') {
			url = "modules/categories/show_category_tree.php?aj=true&cat_type=0&module_name=products&cb_name=cb_link_id";
			httpRequest('GET',url,true,'link_to');
		} else if (radioValue == 'url') {
			$('#menu_link_to').show();
			$('#link_to').html('<input type="text" name="url" value="" size="40" class="textbox" />');
		}
		
	
}

function onClickLink (a_obj) {
	var selected_news = document.getElementById('selected_news');
	//selected_news.innerHTML = a_obj.innerHTML;
	$('#selected_name').html(a_obj.innerHTML);
	var str_link_id = a_obj.id;
	var link_id = str_link_id.substr(7);
	$('#selected_link_id').attr('value',link_id);
	//alert('Hi');
	return false;
}

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) {
		alert('File anh khong hop le !');
		return false;
	} else {
		var ext = uploadFile.match(/(.{3}$)/)[1];
		if (ext.toLowerCase() != 'jpg' && ext.toLowerCase() != 'gif' && ext.toLowerCase() != 'png') {
			alert('File anh 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');
		//alert(url);
		/*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';
		//}
		if (url.indexOf('.emice') != -1) {
			var url = url.replace('.emice', '.ajax');
		} else {
			url += '&aj=true';
		}	
		//alert(url);
		httpRequest('GET', url, 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';
		}
		var response = $.ajax({
		  type: "GET",
		  async: false,
		  url: fastURL,
		  dataType: "html"
		  //data: queryString
		}).responseText;
		var updateBlock = document.getElementById(block_to_update);
		updateBlock.innerHTML = response;
		//httpRequest('GET', fastURL, true, block_to_update);
		return false;
	}
	
	
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Email không hợp lệ")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email không hợp lệ")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Email không hợp lệ")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Email không hợp lệ")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Email không hợp lệ")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Email không hợp lệ")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Email không hợp lệ")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(txtMail){

	var emailID=txtMail  //document..frmSample.txtEmail

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

 // hoannet add menu show
 
 var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

function initsidebarmenu(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
  if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
   ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
  else //else if this is a sub level submenu (ul)
    ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
  for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
  ultags[t].style.visibility="visible"
  ultags[t].style.display="none"
  }
  }
}

if (window.addEventListener)
window.addEventListener("load", initsidebarmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", initsidebarmenu)

 
 
 
 
