function check_email(st){
	var emailReg = "^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,3})$";
	var regex = new RegExp(emailReg);
	return regex.exec(st);
}
function comment_kiemtra(){
	var email = $("#email");
	var descriptions = $("#descriptions");
	var fullname = $("#fullname");
	var phone = $("#phone");
	var content_comment=$("content_comment");
	if(fullname.val() == ''){
		alert('Vui lòng nhập vào họ tên của bạn!');	
		fullname.focus();
		return false;	
	}
	if(phone.val() == ''){
		alert('Vui lòng nhập vào số điện thoại của bạn của bạn!');	
		phone.focus();
		return false;	
	}
	if(email.val() == '') {
		alert('Vui lòng nhập vào địa chỉ email của bạn!');	
		email.focus();
		return false;
	}
	if(content_comment.val() == '') {
		alert('Vui lòng nhập vào nội dung góp ý!');	
		content_comment.focus();
		return false;
	}
	if(!check_email(email.val())) {
		alert('Vui lòng nhập vào địa chỉ email của bạn theo đúng định dạng!');	
		email.focus();
		return false;
	}
	if(descriptions.val() == ''){
		alert('Vui lòng nhập vào nội dung phản hồi của bạn!');	
		descriptions.focus();
		return false;	
	}
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

$(document).ready (function(){	
	$("#frmContact").submit(function(){
		var message = $('#message');
		var fullname = $('#fullname');
		var email = $('#email');
	 
		if(fullname.val() == '') {
			alert('Vui lòng nhập Họ & Tên!');	
			fullname.focus();
			return false;
		} 

		if(email.val() == '') {
			alert('Vui lòng nhập Email!');	
			email.focus();
			return false;
		} 
		if(!check_email(email.val())) {
			alert('Vui lòng nhập Email theo đúng định dạng!');	
			email.focus();
			return false;
		}
		
		if(message.val() == '') {
			alert('Vui lòng nhập Nội dung liên hệ');	
			message.focus();
			return false;		
		} 
		return true;								 
	});	
	
	if($('#full_name').html()){
		var html_login = $('.block_id_237').html();
		$('.block_id_237').html('');
		var html_center_right = $('.center_right').html();
		html_center_right = html_login+html_center_right;
		$('.center_right').html(html_center_right);
	}
		

	if($('#referer_keyword').val()==1){
		//$('.id_51').html('');		
		//$('.id_51').hide();	
		//$('.id_47').html('');	
		//$('.id_47').hide();				
	}	
	
	$("#frmSupport").submit(function(){
		var title = $('txtTitle');
		var message = $('#txtMessage');
		var fullname = $('#txtFullname');
		var email = $('#txtEmail');
	 
	 	if(title.val() == '') {
			alert('Vui lòng nhập Chủ đề!');	
			title.focus();
			return false;
		}
		
		if(fullname.val() == '') {
			alert('Vui lòng nhập Họ & Tên!');	
			fullname.focus();
			return false;
		} 

		if(email.val() == '') {
			alert('Vui lòng nhập Email!');	
			email.focus();
			return false;
		} 
		if(!check_email(email.val())) {
			alert('Vui lòng nhập Email theo đúng định dạng!');	
			email.focus();
			return false;
		}
		
		if(message.val() == '') {
			alert('Vui lòng nhập Nội dung liên hệ');	
			message.focus();
			return false;		
		} 
		return true;								 
	});	
	
	$("#frmCheckdomain").submit(function(){
		var loading;
		var results;
		
		form 	= document.getElementById('frmCheckdomain');
		loading = document.getElementById('loading');
		results = document.getElementById('results');

		if($('#domain').val() == "")
		{
			alert('Vui lòng nhập tên miền');
			$('#domain').focus();
			return false;
		}
		
		results.style.display = 'none';
		$('#results').html('');
		
		loading.style.display = 'inline';
		
		$.post('/?block_id=119&act=check&domain=' + escape($('#domain').val()) + '&ext=' + escape($('#ext').val()),{
		}, function(response){
			results.style.display = 'block';
			$('#results').html(unescape(response));	
			loading.style.display = 'none';
		});
		return false;
	});
	
	$("#frmQuestion").submit(function(){
		var email = $("#email");
		var phone = $("#phone");
		if(email.val() == '') {
			alert('Vui lòng nhập vào địa chỉ email của bạn!');	
			email.focus();
			return false;
		}
		if(!check_email(email.val())) {
			alert('Vui lòng nhập vào địa chỉ email của bạn theo đúng định dạng!');	
			email.focus();
			return false;
		}
		if(phone.val() == ''){
			alert('Vui lòng nhập vào số điện thoại của bạn!');	
			phone.focus();
			return false;	
		}
	});
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}

	 $(".views").fancybox({
			'titleShow'			: false,
			'width'				: 410,
			'height'			: 300,
			'autoScale'			: false,
			'overlayOpacity'    : 0.8,
			'overlayColor'      : '#000',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	
	$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'width'				: 410,
		'height'			: 300,
		'titlePosition' 	: 'inside',
		'titleFormat'		: 'formatTitle'
	});
});

function disableEnterKey(e)
{
	 var key;
	 var kq;
	 var noidung=$("#noidungtraloi");
	 
	 if(window.event)
		  key = window.event.keyCode;     //IE
	 else
		  key = e.which;     //firefox

	 if(key == 13){
		  kq=document.getElementById("noidungtraloi").value+'<br/>';
		  noidung.attr("value",kq);
	 }
	 else
		  return true;
}

function Ajax_UpdateStatus(obj,href){
	var idUpdate;
	var url = href;		
	var idUpdate= $(obj).attr('idUpdate');	
	var valueUpdate;
	if($(obj).attr('type')=='checkbox'){
		if(obj.checked==true){
			valueUpdate = 1;
		}else{
			valueUpdate = 0;		
		}			
	}
	else
	{
		valueUpdate = obj.value;
	}
	$.post(url, {	   
	   request_type: "Ajax", 
	   fieldUpdate: $(obj).attr('field'),
	   idUpdate:idUpdate,
	   valueUpdate:valueUpdate
	},
   function(data){
   });
}
function capnhatgia(id)
{
	value = $("#price_sales"+id).val();
	var url="/?block_id=135&id="+id+"&value="+value;
	$.post(url, {	   
	   request_type: "Ajax"
	},
   function(data){
   });
}
function gradient(id, level)
{
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.top = '250px';
	box.style.left = '475px';
	box.style.display="block";
	return;
} 
function fadein(id)
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 400) + 10);
		level += 0.01;
	}
} 
// Open the lightbox
function openbox(id_box,formtitle)
{
	var box = document.getElementById(id_box);
	document.getElementById('zme-boxy-modal').style.display='block';
	var btitle = document.getElementById('zme-boxy-title');
	btitle.innerHTML = formtitle;
	gradient(id_box, 0);
	fadein(id_box);
}
// Close the lightbox
function closebox(id)
{
	document.getElementById(id).style.display='none';
	document.getElementById('zme-boxy-modal').style.display='none';
}
// Marque
function marque (id){
	var speed1=30
	var march = document.getElementById(id);
	var march1 = document.getElementById("march1");
	var march2 = document.getElementById("march2");
	march2.innerHTML=march1.innerHTML
	function Marquee2(){
		if(march2.offsetHeight-march.scrollTop<=0)
			march.scrollTop-=march1.offsetHeight
		else{
			march.scrollTop++
		}
	}
	var MyMar2=setInterval(Marquee2,speed1)
	march.onmouseover=function() {clearInterval(MyMar2)}
	march.onmouseout=function() {MyMar2=setInterval(Marquee2,speed1)}
}
