function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return (xmlHttp);
}

function makePOSTRequest(divNeed, url, parameters) {
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4&&xmlHttp.status==200) {
			document.getElementById(divNeed).innerHTML=xmlHttp.responseText;
			xmlHttp=null;
		} else {
			document.getElementById(divNeed).innerHTML="<div align='left'><img name='loading' src='images/wait.gif' align='absmiddle' />"+str_waiting+"</div>";
		}
	};
	xmlHttp.open('POST', url+'.php', true);
	//alert(url);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}
function makePOSTNoPage(url, parameters) {
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4&&xmlHttp.status==200) {
			eval(xmlHttp.responseText);
			xmlHttp=null;
		}
	};
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}
function alerter(message) {
	alert(message);
}

function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(divShow).innerHTML=xmlHttp.responseText;
	} else {
		document.getElementById(divShow).innerHTML = "<img name='loading' src='images/ajax-loader.gif' />Đang tải dữ liệu...";
	}	
}

function clr_div(divNeed) {
	alert(divNeed);
	document.getElementById(divNeed).innetHTML="";
}


function load_module(divNeed,url,parameters) {
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4&&xmlHttp.status==200) {
			document.getElementById(divNeed).innerHTML=xmlHttp.responseText;
			xmlHttp=null;
		} else {
			document.getElementById(divNeed).innerHTML="<div align='center' style='padding-top:5px;'><img name='loading' src='images/ajax-loader.gif' align='absmiddle' /></div";
		}
	};
	xmlHttp.open('POST', url+".php", true);
	//alert(parameters);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.send(parameters);
	
}

function loadPage(links){
	var url = ""+links.href+"";
	var index = url.indexOf("#");
	if(index == -1) {
		parameters = "id=0&page=1";
		load_module("content", "home", parameters);		
	}
	else {
		var mod = url.substring(index+1);
		var params = mod.split("/", 3);	
		
		//An hien home banner
		str_mod = params[0];
				
		if(!params[0]) {
			params[0] = "home";
			params[1] = 0;
			params[2] = 1;
		}
		location.href = url;
		parameters = "id="+params[1]+"&page="+params[2];		
		load_module("content", params[0], parameters);		
	}
	scrollTop();
	
}
function loadPage1(links){
	var url = ""+links.href+"";
	var index = url.indexOf("#");
	if(index == -1) {
		parameters = "id=0&page=1";
		load_module("content", "home", parameters);		
	}
	else {
		var mod = url.substring(index+1);
		var params = mod.split("/", 3);	
		
		//An hien home banner
		str_mod = params[0];
				
		if(!params[0]) {
			params[0] = "home";
			params[1] = 0;
			params[2] = 1;
		}
		location.href = url;
		parameters = "id="+params[1]+"&page="+params[2];		
		load_module("content", params[0], parameters);		
	}	
	
}
function loadContent(links){
	/*var url = ""+links.href+"";
	var index = url.indexOf("#");	
	var mod = url.substring(index+1);
	var params = mod.split("/", 3);		
	location.href = url;
	parameters = "id="+params[1]+"&page="+params[2];		
	load_module("ajax_content", params[0], parameters);
	
	scrollTop();*/
	var url = ""+links.href+"";
	var index = url.indexOf("#");
	if(index == -1) {
		parameters = "id=0&page=1";
		load_module("ajax_content", "home", parameters);
	}
	else {
		var mod = url.substring(index+1);
		var params = mod.split("/", 3);		
		if(!params[0]) {
			params[0] = "home";
			params[1] = 0;
			params[2] = 1;
		}
		location.href = url;
		parameters = "id="+params[1]+"&page="+params[2];		
		load_module("ajax_content", params[0], parameters);
	}
	scrollTop();
}

/*
* var parameters = "action=reorder";
* parameters = parameters + "&order_arr=" + order_arr;
*/
function postData(url, parameters) {
	xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4&&xmlHttp.status==200) {
			eval(xmlHttp.responseText);
			xmlHttp=null;
		}
	};
	xmlHttp.open('POST', url+".php", true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
	//alert(parameters);
}

/*test*/
function postRequest(url,parameters,div_result) {
	xmlHttp = GetObject(); 
	divResult = div_result;
	xmlHttp.onreadystatechange = stateChange; 
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //Khai bao de server nhan phuong thuc POST
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function checkUser() {
	if(trim(document.frmRegisterUser.txtUsername.value)!='') {
		sendRequest("checkUserExist.php?param="+ document.frmRegisterUser.txtUsername.value,'check_result');
	}
}
function checkSubmit() {	 
	//check
	if (trim(document.frmRegisterUser.txtUsername.value) == '') {
		alert(checkSubmit_1);
		document.frmRegisterUser.txtUsername.focus();
		return false;
	}
	if (!simple_text(document.frmRegisterUser.txtUsername.value)) {
		alert(checkSubmit_2);
		document.frmRegisterUser.txtUsername.focus();
		return false;
	}
	if ( (document.frmRegisterUser.txtUsername.value).length < 4 || (document.frmRegisterUser.txtUsername.value).length > 30 ) {
		alert(checkSubmit_3);
		document.frmRegisterUser.txtUsername.focus();
		return false;
	}
	if (document.getElementById('check_result').innerHTML.indexOf('!')!=-1) {
		alert(checkSubmit_4);
		document.frmRegisterUser.txtUsername.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtPassword.value) == '') {
		alert(checkSubmit_5);
		document.frmRegisterUser.txtPassword.focus();
		return false;
	}
	if ( (document.frmRegisterUser.txtPassword.value).length < 6 || (document.frmRegisterUser.txtPassword.value).length > 30 ) {
		alert(checkSubmit_6);
		document.frmRegisterUser.txtPassword.focus();
		return false;
	}
	if (document.frmRegisterUser.txtPassword.value != document.frmRegisterUser.txtPassword2.value ) {
		alert(checkSubmit_7);
		document.frmRegisterUser.txtPassword2.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtFullname.value) == '') {
		alert(checkSubmit_8);
		document.frmRegisterUser.txtFullname.focus();
		return false;
	}		
	if (trim(document.frmRegisterUser.txtAddress.value) == '') {
		alert(checkSubmit_9);
		document.frmRegisterUser.txtAddress.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtCompanyName.value) == '') {
		alert(checkSubmit_11);
		document.frmRegisterUser.txtCompanyName.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtPhone.value) == '') {
		alert(checkSubmit_12);
		document.frmRegisterUser.txtPhone.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtFax.value) == '') {
		alert(checkSubmit_13);
		document.frmRegisterUser.txtFax.focus();
		return false;
	}
	if (trim(document.frmRegisterUser.txtEmail.value) == '') {
		alert(checkSubmit_14);
		document.frmRegisterUser.txtEmail.focus();
		return false;
	}
	if ((!isEmail(document.frmRegisterUser.txtEmail.value)) && document.frmRegisterUser.txtEmail.value != "") {
		alert(checkSubmit_10);
		document.frmRegisterUser.txtEmail.focus();
		return false;
	}
}

function checkContact() {	 
	//check
	if (trim(document.frmContact.txtCompany.value) == '') {
		alert(checkSubmit_16);
		document.frmContact.txtCompany.focus();
		return false;
	}
	if (trim(document.frmContact.txtAddress.value) == '') {
		alert(checkSubmit_9);
		document.frmContact.txtAddress.focus();
		return false;
	}
	if (trim(document.frmContact.txtPhone.value) == '') {
		alert(checkSubmit_12);
		document.frmContact.txtPhone.focus();
		return false;
	}
	if (trim(document.frmContact.txtFax.value) == '') {
		alert(checkSubmit_13);
		document.frmContact.txtFax.focus();
		return false;
	}
	if (trim(document.frmContact.txtEmail.value) == '') {
		alert(checkSubmit_14);
		document.frmContact.txtEmail.focus();
		return false;
	}
	if ((!isEmail(document.frmContact.txtEmail.value)) && document.frmContact.txtEmail.value != "") {
		alert(checkSubmit_10);
		document.frmContact.txtEmail.focus();
		return false;
	}
	
	if (trim(document.frmContact.txtDirector.value) == '') {
		alert(checkSubmit_17);
		document.frmContact.txtDirector.focus();
		return false;
	}		
	if (trim(document.frmContact.txtContactPerson.value) == '') {
		alert(checkSubmit_18);
		document.frmContact.txtContactPerson.focus();
		return false;
	}
	if (trim(document.frmContact.txtPosition.value) == '') {
		alert(checkSubmit_19);
		document.frmContact.txtPosition.focus();
		return false;
	}
	if (trim(document.frmContact.txtField.value) == '') {
		alert(checkSubmit_20);
		document.frmContact.txtField.focus();
		return false;
	}
	if (trim(document.frmContact.txtTotalEmployee.value) == '') {
		alert(checkSubmit_21);
		document.frmContact.txtTotalEmployee.focus();
		return false;
	}
	if (trim(document.frmContact.txtCA.value) == '') {
		alert(checkSubmit_22);
		document.frmContact.txtCA.focus();
		return false;
	}
	if (trim(document.frmContact.txtPlace.value) == '') {
		alert(checkSubmit_23);
		document.frmContact.txtPlace.focus();
		return false;
	}
	if (trim(document.frmContact.txtPlace1.value) == '' && trim(document.frmContact.txtPlace2.value) == '' && trim(document.frmContact.txtPlace3.value) == '' ) {
		alert(checkSubmit_24);
		document.frmContact.txtPlace1.focus();
		return false;
	}
	if ( document.frmContact.txtAttach1.value != "" && document.frmContact.txtAttach1.value.lastIndexOf(".doc") == -1&& document.frmContact.txtAttach1.value.lastIndexOf(".xls") == -1&& document.frmContact.txtAttach1.value.lastIndexOf(".pdf") == -1) {
		alert(checkSubmit_25);
		document.frmContact.txtAttach1.focus();
		return false;
	}
	if ( document.frmContact.txtAttach2.value != "" && document.frmContact.txtAttach2.value.lastIndexOf(".doc") == -1&& document.frmContact.txtAttach2.value.lastIndexOf(".xls") == -1&& document.frmContact.txtAttach2.value.lastIndexOf(".pdf") == -1) {
		alert(checkSubmit_25);
		document.frmContact.txtAttach2.focus();
		return false;
	}
	if ( document.frmContact.txtAttach3.value != "" && document.frmContact.txtAttach3.value.lastIndexOf(".doc") == -1&& document.frmContact.txtAttach3.value.lastIndexOf(".xls") == -1&& document.frmContact.txtAttach3.value.lastIndexOf(".pdf") == -1) {
		alert(checkSubmit_25);
		document.frmContact.txtAttach3.focus();
		return false;
	}
}

function postFaqs(txtFullname, txtContent, txtEmail, topic, links, mod) {
	var params = "mod="+mod;	
	params = params + "&txtFullname="+txtFullname;
	params = params + "&txtContent="+txtContent;	
	params = params + "&txtEmail="+txtEmail;
	params = params + "&txtTopic="+topic;
	params = params + "&hdURL="+encodeURIComponent(links.href);		
	makePOSTRequest('div_comment', 'checkAndSaveData', params);
	document.getElementById('txtName').value = "";
	document.getElementById('txtEmail').value = "";
	document.getElementById('editor').value = "";
}