// JavaScript Document
var myWindow;
function openCenteredWindow(url, width, height) 
{
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2) - 20);
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",status,resizable,scrollbars,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}
function openChangPass(url)
{
    var width = 400;
    var height = 300;
	
	openCenteredWindow(url, width, height);
}
function openSanPham(idSanPham)
{
 
	var url = pathForLanguage + "?action=viewtraining&idSanPham="+idSanPham;
	document.location = url;
}

function openSanPham2(idSanPham,loai)
{
 
	var url = pathForLanguage + "?action=viewproducts&idSanPham="+idSanPham+"&loai="+loai;

	document.location = url;

}

function Dangky(idSanPham)
{
 
	var url = pathForLanguage + "?action=dangky&idSanPham="+idSanPham;

	document.location = url;

}
function Login(){

	var url = "/control/login/loginExecute2.php";
	document.chinh.action = url;
	document.chinh.submit()
	

}

function Timkiem(idSanPham)
{
 
	var url = pathForLanguage + "?action=dangky&idSanPham="+idSanPham;

	document.location = url;

}

function openGiaoThuongDialog(url)
{
    var width = 500;
    var height = 500;
	
	openCenteredWindow(url, width, height);
	
}
function openUserDialog(userId)
{
    var width = 400;
    var height = 300;
	var param = "";
	if(typeof(userId)!="undefined")
		param = "?userId="+userId;
	var url = "addLop.php"+param;
	
	openCenteredWindow(url, width, height);
}
function openUserDialog33(userId)
{
    var width = 400;
    var height = 300;
	var param = "";
	if(typeof(userId)!="undefined")
		param = "?userId="+userId;
	var url = "capnhatanh.php"+param;
	
	openCenteredWindow(url, width, height);
}

function openUserDialog2(userId)
{
    var width = 800;
    var height = 600;
	var param = "";
	if(typeof(userId)!="undefined")
		param = "?userId="+userId;
	var url = "capnhatkhoa.php"+param;
	
	openCenteredWindow(url, width, height);
}
function openUserDialogkhoahoc(userId)
{
    var width = 800;
    var height = 600;
	var param = "";
	if(typeof(userId)!="undefined")
		param = "?userId="+userId;
	var url = "capnhatdieukien.php"+param;
	
	openCenteredWindow(url, width, height);
}
function openUserDialoglichhoc(userId)
{
    var width = 800;
    var height = 600;
	var param = "";
	if(typeof(userId)!="undefined")
		param = "?userId="+userId;
	var url = "capnhatlichtoan.php"+param;
	
	openCenteredWindow(url, width, height);
}

/*
 *
*/
function pathForBanner(language)
{
	switch(language)
	{
		case "VN":
			document.location.href="/vietnamese/";
			break;
		case "EN":
			document.location.href="/english/";
			break;
	}
	return;
}

function urlForActionIndex(action)
{
	if(typeof(action)=="undefined")
		return false;
		
	action = action.toLowerCase()
	var url = "";
	switch(action)
	{
		case "home":
			url = "/";
			break;	
		case "about":
			url = pathForLanguage + "?action=about";
			break;	
		case "products":
			url = pathForLanguage + "?action=products";
			break;	
		case "parners":	
			url = pathForLanguage + "?action=parners";
			break;
		case "sotay":	
			url = "http://www.pace.edu.vn/news";
			break;
		case "forum":	
			url = pathForLanguage + "?action=forum";
			break;
		case "web":	
			url = pathForLanguage + "?action=web";
			break;
		case "dangky":	
			url = pathForLanguage + "?action=dangky";
			break;
		case "inhouse":	
			url = pathForLanguage + "?action=inhouse";
			break;	
		case "workplan":	
			url = pathForLanguage + "?action=workplan";
			break;	
		case "tonvinh":	
			url = pathForLanguage + "?action=tonvinh";
			break;
	}
	
	document.location = url;
	return;
}

function userChangeLanguage(language)
{
	var href = window.location.search;
	
	var query = webPath;
	if(language=="VN")
		query+="vietnamese/";
	else
		query+="english/";
		
	if(href.indexOf("?")>=0)
		query += href.substr(href.indexOf("?"));
	
	//alert(query);
	window.location.href = 	query;
}

function disableForm(documentObj, bool)
{
	var logic = true;
	if(typeof(bool)!="undefined")
		logic = bool;
		
	for (var i = 0; i < documentObj.forms.length; i++) 
	{
    	for (var j = 0; j < documentObj.forms[i].elements.length; j++) 		
			if(documentObj.forms[i].elements[j].type!="hidden")
			{
 				documentObj.forms[i].elements[j].disabled = logic;
	        }
	}
		
    for (i = 0; i < documentObj.links.length; i++) 
	{
    	documentObj.links[i].disabled = logic;
	}
}
//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');

function preloadImages()

{

  if(document.images)

  {

    if(!document.imageArray) document.imageArray = new Array();

    var i,j = document.imageArray.length, args = preloadImages.arguments;

    

    for(i=0; i<args.length; i++)

    {

      if (args[i].indexOf("#")!=0)

      {

        document.imageArray[j] = new Image;

        document.imageArray[j++].src = args[i];

      }

    }

  }

}

function resetMessageForm()
{
	setTimeout("resetMessageFormInternal()",2000);
}
function resetMessageFormInternal()
{
	document.getElementById("message").innerText=" ";	
}
// Cac ham kiem tra du lieu
String.prototype.trim = function() {

	var str=this;

	if(str.length==0) return str;

	while(str.search("  ")>=0)
		str = str.replace("  "," ");


	while(str.charAt(0)==" ")
		str = str.substring(1);

	while(str.charAt(str.length-1)==" ")
		str = str.substring(0, str.length-1);

  return str;
}

String.prototype.reverse = function() {
	var Arr = this.trim().split(" ");
	Arr.reverse();

	return Arr.join(" ");
}

String.prototype.isEmpty = function() {
	var str = this;
	if(str=="")
		return true;
	else
		return false;
}
String.prototype.isEmail = function() {
	var str = this;
	var email=/^[A-Za-z0-9][\w-.]+@[A-Za-z0-9]([\w-.]+[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	
	return(email.test(str)); 
}
/* With RegExp */
function isEmail(who) {
	var email=/^[A-Za-z0-9][\w-.]+@[A-Za-z0-9]([\w-.]+[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;
	return(email.test(who));
}
function goPageChaoMua(pageChaoMua)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + pageChaoMua;
	pageForAll += "&currentPageChaoBan=" + document.f.currentPageChaoBan.value;
	pageForAll += "&currentPageTimDoiTac=" + document.f.currentPageTimDoiTac.value;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = pathForLanguage+"?action=danhsachgiaothuong&"+pageForAll;
}
function goPageChaoBan(pageChaoBan)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + document.f.currentPageChaoMua.value;
	pageForAll += "&currentPageChaoBan=" + pageChaoBan;
	pageForAll += "&currentPageTimDoiTac=" + document.f.currentPageTimDoiTac.value;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = pathForLanguage+"?action=danhsachgiaothuong&"+pageForAll;
}
function goPageTimDoiTac(pageTimDoiTac)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + document.f.currentPageChaoMua.value;
	pageForAll += "&currentPageChaoBan=" + document.f.currentPageChaoBan.value;
	pageForAll += "&currentPageTimDoiTac=" + pageTimDoiTac;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = pathForLanguage+"?action=danhsachgiaothuong&"+pageForAll;
}


function goPageSearchChaoMua(pageChaoMua)
{
	document.f.currentPageChaoMua.value=pageChaoMua;
	document.f.submit();;
}
function goPageSearchChaoBan(pageChaoBan)
{
	document.f.currentPageChaoBan.value=pageChaoBan;
	document.f.submit();;
}
function goPageSearchTimDoiTac(pageTimDoiTac)
{
	document.f.currentPageTimDoiTac.value=pageTimDoiTac;
	document.f.submit();
}


// For control

function goPageChaoMuaForControl(pageChaoMua)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + pageChaoMua;
	pageForAll += "&currentPageChaoBan=" + document.f.currentPageChaoBan.value;
	pageForAll += "&currentPageTimDoiTac=" + document.f.currentPageTimDoiTac.value;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = webPath+"control/giaoThuong.php?"+pageForAll;
}
function goPageChaoBanForControl(pageChaoBan)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + document.f.currentPageChaoMua.value;
	pageForAll += "&currentPageChaoBan=" + pageChaoBan;
	pageForAll += "&currentPageTimDoiTac=" + document.f.currentPageTimDoiTac.value;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = webPath+"control/giaoThuong.php?"+pageForAll;
}
function goPageTimDoiTacForControl(pageTimDoiTac)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + document.f.currentPageChaoMua.value;
	pageForAll += "&currentPageChaoBan=" + document.f.currentPageChaoBan.value;
	pageForAll += "&currentPageTimDoiTac=" + pageTimDoiTac;
	pageForAll += "&currentPageThongTin=" + document.f.currentPageThongTin.value;
	document.location.href = webPath+"control/giaoThuong.php?"+pageForAll;
}
function goPageThongTinForControl(pageThongTin)
{
	var pageForAll = "";
	pageForAll += "currentPageChaoMua=" + document.f.currentPageChaoMua.value;
	pageForAll += "&currentPageChaoBan=" + document.f.currentPageChaoBan.value;
	pageForAll += "&currentPageTimDoiTac=" + document.f.currentPageTimDoiTac.value;
	pageForAll += "&currentPageThongTin=" + pageThongTin;
	document.location.href = webPath+"control/giaoThuong.php?"+pageForAll;
}

//End for control




function chiTietGiaoThuong(idGiaoThuong)
{
	document.location.href = pathForLanguage+"?action=chitietgiaothuong&idGiaoThuong="+idGiaoThuong;
}

function chiTietDoanhNghiep(ID_DN)
{
	document.location.href = pathForLanguage+"?action=chitietdoanhnghiep&ID_DN="+ID_DN;
}
function chiTietDoanhNghiepAlone(ID_DN)
{
	document.location.href = pathForLanguage+"chiTietDoanhNghiepAlone.php?action=chitietdoanhnghiep&ID_DN="+ID_DN;
}

function searchGiaoThuong(value)
{
	//document.location.href = pathForLanguage+"?action=searchgiaothuong&searchContent="+value;
	document.f.submit();
}
function searchDoanhNghiep(value)
{
	document.location.href = pathForLanguage+"?action=searchdoanhnghiep&searchContent="+value;
}
/*
function detailDoanhNghiep(id)
{
	document.location.href = pathForLanguage+"?action=detaildoanhnghiep&id="+id;
}
*/
function goPageDoanhNghiep(page)
{
	document.location.href=pathForLanguage+"?action=danhsachdoanhnghiep&currentPage="+page;
}
function goPageSearchDoanhNghiep(page)
{
	document.f.currentPage.value = page;
	document.f.submit();
}

function goPageSanPham(page)
{
	document.location.href=pathForLanguage+"?action=langnghe&currentPage="+page;
}
function displayAllDoanhNghiep()
{
	document.location.href=pathForLanguage+"?action=danhsachdoanhnghiep&displayAll=1";
}  
function displayGTCM()
{
	if(document.getElementById("GT_CM").style.display=="none")
		document.getElementById("GT_CM").style.display="block";	
	
}

function hideGTCM()
{
	if(document.getElementById("GT_CM").style.display=="block")
		document.getElementById("GT_CM").style.display="none";	
	
}
