
// menu
var g_obj;
var g_tout;
(function($) {
	$.fn.TNActiveMenu = function() 
	{	
		var intDis=$(this).offset().left-$("#menu").offset().left+$(this).width()/2;
		var intsubw=itemW($(this).children(".submenu"));
		var intmargin=Math.round(intDis - intsubw/2);
		if((intmargin+intsubw)>974) intmargin=974-intsubw-5;
		if(intmargin<0) intmargin=0;
		$(this).children(".submenu").css("padding-left",intmargin);
		$(this).children(".submenu").width(974);
		if($(this).hasClass("active")){
			$(this).addClass("over");
			$(this).prev().addClass("preactive");
		}
		$(this).mouseover(function(){
			$(g_obj,".main_menu .active").removeClass("over");
			$(g_obj,".main_menu .active").prev().removeClass("preactive");
			clearTimeout(g_tout);
			$(this).addClass("over");
			$(this).prev().addClass("preactive");	
		});
		$(this).mouseout(function(){
			g_obj=this;
			clearTimeout(g_tout);
			g_tout=setTimeout(function(){
				$(g_obj).removeClass("over");
				$(g_obj).prev().removeClass("preactive");
				$(".main_menu .active").addClass("over");
				$(".main_menu .active").prev().addClass("preactive");
			},200);
		});
		function itemW(objitem){
			var w=0;
			var ratio=8.8;
			if($.browser.msie) ratio=7.8;
			for(i=0;i<$(objitem).length;i++)
			{
				w=w+$(objitem).children("li"+"eq:("+i+")").text().length*ratio;
			}
			return Math.round(w);
		}
	};
})(jQuery);
$('.main_menu .item').each(function(){
     $(this).TNActiveMenu();
 });


// quick search box
function doQuickSearchJob()
{
	
	var frm = document.frmQuickSearchJob;		
	var keyword =  $("#txtKeyword").val().replace(/^\s+|\s+$/g, '');
		
	industry_id = frm.industry_id.value;
	location_id = frm.location_id.value;	
	if(keyword =='' && industry_id=='' && location_id=='')
	{
		jAlert(TXT_INPUT_SEARCH_CONDITION,TXT_MESSAGE_TITLE);
		return false;
	}
	
	if(keyword)
	{
		keyword = keyword.replace(/["'"]/g,'');
		if(parseInt(keyword.length) < 2 || checkInputNormalText(keyword)==false)
		{
			jAlert(TXT_INVALID_KEYWORD,TXT_MESSAGE_TITLE);		
			return false;
		}
	}		
	return true;
}


function isBlackListTag(strCheck)
{
	var arrList = new Array();
	arrList[0] = "<";
	arrList[1] = ">";
	arrList[2] = "=";
	arrList[3] = "#";
	arrList[4] = "[";
	arrList[5] = "]";
	arrList[6] = "{";
	arrList[7] = "}";
	arrList[8] = "*";
	arrList[9] = "^";
	arrList[10] = "~";
	arrList[11] = "\$";
	for(var i=0;i<arrList.length;i++)
	{
		if(strCheck.indexOf(arrList[i])>=0)	
			return true;	
	}
	return false;
}

function checkInputNormalText(strCheck)
{
	if(strCheck=="" || isBlackListTag(strCheck)) return false;
	return true;
}		
	
	
// share link
function shareLink(type)
{
	switch(type)
	{
		case 'yume':
			window.open('http://yume.vn/share_partners/link?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title), 'yumeshare','toolbar=1,status=0,width=980,height=475,scrollbars=1,menubar=1,location=1,resizable=1','_blank');
			break;
		case 'facebook':
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer',',width=980,height=600');		
			break;
		case 'yahoo':
			document.getElementById('yahoo_share').href="ymsgr:im?msg="+document.title+' '+location.href;		
			break;
		case 'yahoo2':
			document.getElementById('yahoo_share2').href="ymsgr:im?msg="+document.title+' '+location.href;		
			break;
		case 'twitter':
			window.open('http://twitter.com/home?status=Reading:'+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer',',width=980,height=600');		
			break;
		case 'linkedin':
			window.open('http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer',',width=980,height=600');		
			break;
	}
	return false;
}	
	
	
	
	
	
