$(document).ready( function(){
	// famous in left column
	$(".famous_item_head").click(function () {
		famous_body = $(this).next();
		famous_body.slideToggle(600);
		
		tag_parent = $(this).parent();
		if(tag_parent.hasClass('famous_openned'))
			tag_parent.removeClass('famous_openned').addClass('famous_closed');
		else 
			tag_parent.removeClass('famous_closed').addClass('famous_openned');
	})
	
});
function InputFocus(textdefault,control) {
    text = control.value;
    if (text == textdefault) control.value = "";
}
function InputBlur(textdefault,control) {
    text = control.value;
    if (text == "") control.value = textdefault;
}
function changeCaptcha(){
	var date = new Date();
	var captcha_time = date.getTime();
	$("#imgCaptcha").attr({src:root+'libraries/jquery/ajax_captcha/create_image.php?'+captcha_time});
}	
function control_submit_form_comment(){
	if(!check_form_comment()){
		return false;
	}
	submit_form_comment();
}
// check form comment
function check_form_comment(){
	if($('#name').val() == '' || $('#name').val() == 'Họ tên'){
		alert('Bạn phải nhập họ tên');
		return false;
	}
	if($('#email').val() == '' || $('#email').val() == 'Email'){
		alert('Bạn phải nhập email');
		return false;
	}
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(!$('#email').val().match(emailExp)){
		alert('Bạn phải nhập đúng định dạng email');
		return false;
	}
	
	if($('#txtCaptcha').val() == '' || $('#txtCaptcha').val() == 'Mã kiểm tra'){
		alert('Bạn phải nhập mã hiển thị');
		return false;
	}
	if($('#text').val() == '' || $('#text').val() == 'Nội dung'){
		alert('Bạn phải nhập nội dung');
		return false;
	}
	return true;
}
function submit_form_comment(){
	name = $('#name').val();
	email = $('#email').val();
	text = $('#text').val();
	txtCaptcha = $('#txtCaptcha').val();
	content_id = $('#content_id').val();
	$.ajax({
		  url: root+"index.php?module=news&view=news&task=save_comment&raw=1",
		  type: 'POST',
		  data: {name:name,email:email, text:text,content_id:content_id,txtCaptcha:txtCaptcha},
		  cache: false,
		  success: function(json){
		  		json = jQuery.trim(json);
		  		if(json){
		  			alert(json);
			  		$('#name').val('');
			  		$('#email').val('');
			  		$('#text').val('');
			  		$('#txtCaptcha').val('');
			  		changeCaptcha();
		    		return 0;
		  		} 

		  },
		  error: function()
		  {
			 return false;
		  }
	});
}
/***** share new follow email *****/
function sendEmail(url_encode){
	openMeExt(root+'index.php?module=news&view=mail&raw=1&url='+url_encode, 0, 0, 0, 0, 0, 0, 1, 1, 515, 480, 0, 0, '', 0);
	return false;
//	window.open(root+'index.php?module=news&view=mail&raw=1&u='+url_encode);
}
function openMeExt(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft, vID, vCounter){
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight-140).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');

	if (vCentered){
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}

	else{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}
	if (typeof(vCounter) == 'undefined'){
		vCounter = 0;
	}
	if (typeof(vID) == 'undefined')	{
		vID = 0;
	}
	open(sLink, '_blank', winDef);
	if (typeof(vLink.href) != 'undefined')	{
		return false;
	}
}


