showtime = 0;
function changtab(id,count,clear){
	for(i=1;i<=count;i++){
		//document.getElementById('menu'+i).className='menu-normal';
		$('#menu'+i).removeClass('menu-active');
		$('#menu'+i).addClass('menu-normal');
	}
	//document.getElementById('menu'+id).className='menu-active';
	$('#menu'+id).removeClass('menu-normal');
	$('#menu'+id).addClass('menu-active');
	if(clear==1) clearInterval(showtime);
}
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
function mouseout(id,count){
	showtime = setInterval(function() {changtab(id,count,1)},3000);
}
function isEmail(str) {
	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));
}
function check_send_friend(){
	if(document.getElementById("send_name").value == ""){
		alert("Bạn chưa nhập họ và tên");
		document.getElementById("send_name").focus();
		return;
	}
	if(document.getElementById("title-sendFriend").value == ""){
		alert("Bạn chưa nhập tiêu đề tin nhắn");
		document.getElementById("title-sendFriend").focus();
		return;
	}
	if(document.getElementById("message_content").value == ""){
		alert("Bạn chưa nhập nội dung tin nhắn");
		document.getElementById("message_content").focus();
		return;
	}
	if(!isEmail(document.getElementById("send_email").value)){
		alert("Email không đúng định dạng");
		document.getElementById("send_email").focus();
		return;
	}
	var coemail = 0;
	for(i=1;i<=4;i++){
		if(document.getElementById("email_to_friend_"+i).value != ""){
			if(!isEmail(document.getElementById("email_to_friend_"+i).value)){
				alert("Email không đúng định dạng");
				document.getElementById("email_to_friend_"+i).focus();
				return;
			}else{
				coemail = 1;
			}
		}
	}
	if(coemail == 0){
		alert("Bạn chưa nhập email người nhận");
		document.getElementById("email_to_friend_1").focus();
		return;
	}
	if(document.getElementById("scode_friend").value == ""){
		alert("Bạn chưa nhập mã số an toàn");
		document.getElementById("scode_friend").focus();
		return;
	}
	document.sendtofriend.submit();
}
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
	 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   
}
function check_form_comment(){
	var f = document.product_comment;
	if(f.com_title.value=="Tiêu đề"){
		document.getElementById('com_title').value='';
	}
	if(f.com_title.value==""){
		alert("Bạn vui lòng nhập tiêu đề");
		f.com_title.focus();
		return false;
	}
	if(f.com_name.value=="Họ tên"){
		document.getElementById('com_name').value='';
	}
	if(f.com_name.value ==""){
		alert("Bạn vui lòng nhập tên");
		f.com_name.focus();
		return false;
	}
	if(f.com_email.value=="Email"){
		document.getElementById('com_email').value='';
	}
	if(f.com_email.value==""){
		alert("Bạn vui lòng nhập email");
		f.com_email.focus();
		return false;
	}
	if(f.com_content.value==""){
		alert("Bạn vui lòng nhập nội dung");
		f.com_content.focus();
		return false;
	}
	
	if(!IsNumeric(f.capchar.value)){
		alert("Bạn vui lòng nhập mã bảo mật");
		f.capchar.focus();
		return false;
	}
	return true;
}
function addSelect(from,to){
	$("#" + from + " option:selected").each(function(){
		  $("#" + to).append($(this).clone());
		  $(this).remove();
	});
	selectAll(to);
}
function selectAll(selectid){
  $("#"+selectid).each(function(){
		$("#"+selectid+" option").attr("selected","selected"); 
	});
}

/* -----support online----*/
function showContent(id,obj){
	for(i=0;i<=2;i++){
		$("#show-content-"+i).css('display','none');
	}			
	var offset = $(obj).offset();
	$("#show-content-"+id).css({'display':'block','position':'absolute','left':offset.left,'top':offset.top+15});
}
function hideContent(id){
	$("#show-content-"+id).css('display','none');
}
function showTooltip(id){		
	var offset_left = $("#"+id).offset();
	var width_input = $("#"+id).width();
	$("#tooltip-"+id).css({"display":"block","position":"absolute","left":offset_left.left+width_input+20,"margin-top":"-20px"});
}
function showCurrency(){
	var startTable = '<table cellpadding="2" cellspacing="1" border="1" width="100%" class="table-rate">', tr = '';				
	for(var i=0;i<vForexs.length;i++){
		if(vCosts[i] != '-'){
			tr += '<tr><td class="rate-title" align="left"><b>'+vForexs[i]+'</b></td ><td class="rate-value" align="left">'+ vCosts[i]  +'</td></tr>';
		}
	}
	var endTable = '</table>';
	$('.table-forex-rate').append(startTable + tr + endTable);

}
function changeCheckPass(value,obj){
	if($(obj).attr('checked')==true){
		$('#check_change_password').css('display','block');
		$(obj).attr('value',1);
	}else{
		$('#check_change_password').css('display','none');
		$(obj).attr('value',0);
	}
}
function showCart(){	
	$('#show-cart-header').css('display','block');
}
function hideCart(){
	$('#show-cart-header').css('display','none');
}
function checkFieldRegister(value,divid){
	$.post("/vn/checkusername.php", { usename: $("#"+value).val(),type: value },
	function(data){
	  $("#"+divid).html(data);
	} );
}
function checknewsletter(){
	if(document.getElementById("let_email").value == ''){
		alert("Bạn chưa nhập Email");
		document.getElementById("let_email").focus();
		return false;
	}
	if(!isEmail(document.getElementById("let_email").value)){
		alert("Email không đúng định dạng");
		document.getElementById("let_email").focus();
		return false;
	}
	document.newletter.submit();
}
