/* cac ham hien thi showpopup Jquery */
function TNCom_getDocumentSize(val)
{
	var xScroll,yScroll,value;
	
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)	
	return arrayPageSize[val]
}// end function

function jb_active_tab(obj){
		var curentTab=obj.id;
		var curentContent=curentTab.replace("tab","cont");

		curentContent_1=curentTab.replace("tab","cont");
		var tabs=$('#' + curentTab).parent().children();
		var contents=$('#' + curentContent).parent().children();

		$(tabs).each( function(){								
				$(this).attr('class','');
		});		
		
		$(contents).each( function(){								
				$(this).hide();
		});	
		
		$('#' + curentTab).addClass('active');
		//$('#' + curentContent).fadeIn('show');	
		$('#' + curentContent).show();	
		var pos =0;
		
		switch (curentTab){
			case "tab1":
				pos='left top';
				break;
			case "tab2":
				pos='left center';
				break;
			case "tab3":
				pos='left bottom';
				break;
			case "tab7":
				pos='left top';
				break;
			case "tab8":
				pos='left center';
				break;
			case "tab9":
				pos='left bottom';
				break;	
			}
			
		$('#'+curentTab).parent().css({'backgroundPosition':pos});

}
function jb_active_tab_btin(obj){
		var curentTab=obj.id;
		var curentContent=curentTab.replace("tab","cont");

		curentContent_1=curentTab.replace("tab","cont");
		var tabs=$('#' + curentTab).parent().children();
		var contents=$('#' + curentContent).parent().children();

		$(tabs).each( function(){								
				$(this).attr('class','');
		});		
		
		$(contents).each( function(){								
				$(this).hide();
		});	
		
		$('#' + curentTab).addClass('active');
		$('#' + curentContent).fadeIn('slow');	
		var pos =0;
		
		switch (curentTab){
			case "tab3":
				pos='left top';
				break;
			case "tab4":
				pos='left center';
				break;
			case "tab5":
				pos='left bottom';
				break;
			}
		$('#'+curentTab).parent().css({'backgroundPosition':pos});

}

/*
	script active menu
*/

function jb_active_mnu(mnulv1_id, mnulv2_id){
		

}

var g_itemID;
function delitem(){
	$('.delthis').click(function(){
		var itemDisplay=$(this).parent().parent().children('.displaynow').length;
		var itemID=$(this).parent().attr('id');
		var bID="b"+itemID.substring(4,itemID.length);
		$('#'+bID).parent().show();
		$(this).parent().removeClass('displaynow');
		if(itemDisplay<2) $(this).parent().parent().hide();
		return false;
	});
}
function edititem(){
	
	$('.editthis').click(function(){
		g_itemID=$(this).parent().attr('id');
		
		
		document.getElementById('contlist').innerHTML = "";
		switch(g_itemID)
		{
			case "itemmajor":
				ajax_loadIndustry();
				break;
			case "itemlocal":
				ajax_loadLocation();
				break;
			case "itemsalary":
			// Ngan lai
				ajax_loadSalary();
				break;
			case "itemexperience":
				// Ngan lai
				ajax_loadExperience();
				break;
			case "itemlevel":
				ajax_loadLevel();
				break;
			case "itemkind":
			// Ngan lai
				ajax_loadWorkingType();
				break;
		}
		
		if(g_itemID=='itemkey'){
			$("#listmajor").addClass('type2');
			$('.txteditkey').val($('#'+g_itemID).children('.data').text());
		}
		else{
			//$("#listmajor").attr('class','');
			//var h=($("#contlist li").length*14+10)<190?($("#contlist li").length*14+10):188;
			//$('#contlist').css('height',h);
		}
		
		$("#listmajor").css("top",$(this).parent().offset().top);
		var boxw=$("#listmajor").width()+8;
		$("#listmajor").css("left",$(this).parent().offset().left-boxw);
		$("#listmajor").slideDown();
		return false;
	});
	$('.btncontinue').click(function(){						 
		$('#'+g_itemID).children('.data').text($('.txteditkey').val());
		closeboxfilter();
	});
	
	$('#closeicon').click(function(){
		closeboxfilter();
	});
}
function closeboxfilter()
{
	$("#listmajor").slideUp("slow",function(){
		$("#listmajor").attr('class','');										
	});
	return false;
}
function getListValue(obj)
{
	$('#'+g_itemID).children('.data').text($(obj).text());
	closeboxfilter();
	return false;
}
function changeSearchKey(obj){
	var pID=$(obj).parent().parent().attr("id");
	var itemID="item"+pID.substring(1,pID.length);
	$('#'+itemID).children('.data').text($(obj).text());
	$('#'+itemID).parent().show();
	$('#'+itemID).addClass('displaynow');
	$('#'+pID).parent().hide();
	return false;
}
function changeKeyWord(val){
	$('#itemkey').children('.data').text(val);
	$('#itemkey').parent().show();
	$('#itemkey').addClass('displaynow');
	return false;
}
jQuery(document).ready(function(){
	delitem();
	edititem();
});


//cho phep nhung ky tu tu A->Z, a->z, 0->9,va cac ky tu _-
function CheckUsernameChar(stringIn)
{
	retval = false
     var i;
     for ( i=0; i <= stringIn.length-1; i++) 
	 {
         if ( ( ( stringIn.charCodeAt(i) >= 48)&&(stringIn.charCodeAt(i) <= 57)) || ((stringIn.charCodeAt(i) > 64)&&(stringIn.charCodeAt(i) <= 90)) || ((stringIn.charCodeAt(i) >= 97)&&(stringIn.charCodeAt(i) <= 122)) || (stringIn.charCodeAt(i) == 95) || (stringIn.charCodeAt(i) == 45) )
		 {
           	retval = true;
         }
		 else
		 {
			retval = false;
			break;
         }
     }
     return retval;
}

// kiem tra xem user nhap vao username co tren 6 ky tu va duoi 20 ky tu khong? de hien thi button check len
function CheckStatus()
{
	var frm 	= document.frmRegisterForm;
	var strUsername = frm.username.value;
	
	if ( strUsername != '' && ( strUsername.length >= 6 && strUsername.length <= 20 ) )
	{
		document.getElementById('btCheck').disabled	= false;
		bolUsernameChecked = false;
		return true;
	}
	else
	{
		document.getElementById('btCheck').disabled	= true;
		return false;
	}

}

//kiem tra unicode cho password Checkchar1
function CheckCharPassword(stringIn)
{
	retval = false
     var i;
     for (i=0;i<=stringIn.length-1;i++) 
	 {
         if (((stringIn.charCodeAt(i) >= 8)&&(stringIn.charCodeAt(i) <= 127)) && (stringIn.charCodeAt(i)!=34) && (stringIn.charCodeAt(i)!=39) && (stringIn.charCodeAt(i)!=32))
		 {
           	retval = true;
         }
		 else
		 {
			retval = false;
			break;
         }
     }
     return retval;
}

//kiem tra cac ky tu dat biet @,<,>,!,$,%,(,),=,#,{,},[,],",^,~,`,,/,\,|,*,.,+,: cho fullname CheckChar
function CheckCharFullName(stringIn) 
{
	if ((stringIn.indexOf("@") >= 0)||(stringIn.indexOf("<") >= 0)||(stringIn.indexOf(">") >= 0)||(stringIn.indexOf("!") >= 0)||(stringIn.indexOf("$") >= 0)||(stringIn.indexOf("%") >= 0)|| (stringIn.indexOf("=") >= 0)||(stringIn.indexOf("#") >= 0)||(stringIn.indexOf("{") >= 0)||(stringIn.indexOf("}") >= 0)||(stringIn.indexOf("[") >= 0)||(stringIn.indexOf("]") >= 0)||(stringIn.indexOf("|") >= 0)||(stringIn.indexOf('"') >= 0) ||(stringIn.indexOf(".") >= 0) ||(stringIn.indexOf(";") >= 0) ||(stringIn.indexOf("?") >= 0) ||(stringIn.indexOf(",") >= 0) ||(stringIn.indexOf("+") >= 0) ||(stringIn.indexOf("&") >= 0) ||(stringIn.indexOf(":") >= 0) ||(stringIn.indexOf("\\") >= 0) ||(stringIn.indexOf("/") >= 0) ||(stringIn.indexOf("*") >= 0) ||(stringIn.indexOf("`") >= 0) ||(stringIn.indexOf("~") >= 0) ||(stringIn.indexOf("^") >= 0) ||(stringIn.indexOf("-") >= 0)||(stringIn.indexOf("_") >= 0))
	{
		return false;
	}
	return true;
}

// kiem tra co dung la dia chi email.
function CheckEmail(stringIn)
{
	var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
	if ( stringIn.search(re) == -1 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

// kiem tra so dien thoai
function CheckTel(str)
{
	var pattern = "0123456789-+() ";
	if (str.length > 0) {
		if (str.length < 5) {
			return false;
		} else {
			for (var a=0; a<pattern.length; a++) {
				if (pattern.indexOf(str.charAt(a),0) == -1) return false;
			}
		}
	}
	return true;	
}

// kiem tra la kieu so
function checkNumber(str)
{
	var pattern = "0123456789";
	if (str.length > 0) {
		for (var a=0; a<pattern.length; a++) {
			if (pattern.indexOf(str.charAt(a),0) == -1) return false;
		}
	}
	return true;	
}

