var mail_data, mail_name, mail_from;
var mail_sent = false;
// AJAX INIT
function $$$(id) {
	return document.getElementById(id);
}
function khoitao_ajax()
{
	var x;
	try 
	{
		x	=	new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
    	try 
		{
			x	=	new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(f) { x	=	null; }
  	}
	if	((!x)&&(typeof XMLHttpRequest!="undefined"))
	{
		x=new XMLHttpRequest();
  	}
	return  x;
}
function	Forward(url)
{
	window.location.href = url;
}
function	_postback()
{
	return void(1);
}
/*So sanh height cua 2 the div tgp_body_content & tgp_right*/
function EqualHeight(elements) { 
    //Xác định chiều cao của cột cao nhất 
    tallest = 0; 
    elements.each(function() { 
        elementHeight = jQuery(this).height(); 
        if(elementHeight > tallest) { 
            tallest = elementHeight; 
        } 
    }); 
    //Chỉnh chiều cao cho tất cả các cột 
    //theo chiều cao của cột cao nhất 
    elements.height(tallest); 
} 

function SkipError()
{
	return true;
}

function news_home(id)
{

	var	query	=	"act=news_home&i="+id;
	var http 	=	khoitao_ajax();
	try
	{
		$$$('loading_news').innerHTML = "<center><img src='/images/ajax-loader.gif' /></center>";
		http.open("POST", "/action.php");
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Cache-control", "no-cache");		
    	http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				if (http.status == 200)
				{
					$$$('loading_news').innerHTML = http.responseText;
				}
				else
				{
					alert('Co loi he thong. Vui long thu lai sau.');
				}
			}
		}
		http.send(query);
	}
	catch (e)
	{
	}
	return false;
}

function ClearDatHangValue() {
    $("#frmDatHang #txtName").val('');
    $("#frmDatHang #txtEmail").val('');
    $("#frmDatHang #txtPhone").val('');
    $("#frmDatHang #txtAddress").val('');
}

function DatHang(id) {

	var soluong 	= $("#frmDatHang #txtSoLuong").val();
	var txtName		= $("#frmDatHang #txtName").val();
	var txtPhone	= $("#frmDatHang #txtPhone").val();
	var txtEmail 	= $("#frmDatHang #txtEmail").val();
    var txtAddress 	= $("#frmDatHang #txtAddress").val();	

	if(!txtName)
	{
		alert("Vui lòng nhập họ tên !");
		$("#frmDatHang #txtName").focus();
		return false;
	}
	if(!txtPhone)
	{
		alert("Vui lòng nhập số điện thoại !");
		$("#frmDatHang #txtPhone").focus();
		return false;
	}
	if(!txtEmail)
	{
		alert("Vui lòng nhập email !");
		$("#frmDatHang #txtEmail").focus();
		return false;
	}
	if(!txtAddress)
	{
		alert("Vui lòng nhập địa chỉ !");
		$("#frmDatHang #txtAddress").focus();
		return false;
	}
	email=txtEmail
	if (!email.match(/^([-\d\w][-.\d\w]*)?[-\d\w]@([-\w\d]+\.)+[a-zA-Z]{2,6}$/)){
		alert('Địa chỉ email không hợp lệ.');
		$("#frmDatHang #txtEmail").focus();
		return false;		
	}
	if(soluong <=0) {
		alert("Vui lòng nhập số lượng !");
		$("#frmDatHang #txtSoLuong").focus();
		return false;
	}
	else
	{
		$.ajax({
			url:'/action.php',
			type: 'POST',
			data:{act:'send_res',txtName:txtName,txtEmail:txtEmail,
				txtPhone:txtPhone,txtAddress:txtAddress,soluong:soluong,masp:id},
			success: function(msg){						
					alert(msg);
					window.location.href = "/san-pham-xem/"+id+"/thiet-bi-dien-da-nang.html";
				}				
		});
	}
}


function checkbox_test(obj){  
  var counter = 0;  // counter for checked checkboxes  
  var i       = 0;  // loop variable  
  var url     = ''; // final url string  
  // get a collection of objects with the specified 'input' TAGNAME  
  var input_obj = obj;
  // loop through all collected objects  
  for (i=0; i < input_obj.length; i++){  
    // if input object is checkbox and checkbox is checked then ...  
    if (input_obj[i].type == 'checkbox' && input_obj[i].checked == true){  
      // ... increase counter and concatenate checkbox value to the url string  
      counter++;  
      url = url + '|' + input_obj[i].value;  
    }  
  }  
  // display url string or message if there is no checked checkboxes  
  if (counter > 0){  
    // remove first '&' from the generated url string  
    url = url.substr(1);  
    // display final url string  
	return url;
    // or you can send checkbox values  
    // window.location.href = 'my_page.php?' + url;  
  }  
  else return "";
}  



//Áp đặt chiều cao cho các cột khi trang 
//đã được load hoàn tất. 
jQuery(window).load(function(){  
	
    // Đặt tọa độ cho biểu tượng loading
//	$(".loading").fadeIn();
//	$(".loading_status").css("top","50%");
//	$(".loading_status").css("left","45%");
	// Kiểm tra IE
	function isIE()
	{
	  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	}
	
   Cufon.replace('h1.title,.tgp_container .tgp_body .body_bottom .tgp_page_left h1.left_title,.tgp_container .tgp_body .body_bottom .tgp_page_right h1.right_title ', {fontFamily:'HP-Hai Au',color: '-linear-gradient(#545454, #545454)'}); 
    Cufon.replace('.tgp_container .tgp_body .body_top .tgp_menu ul li,.tgp_container .tgp_body .body_top .tgp_slide .caption ', {fontFamily:'HP-Hai Au',color: '-linear-gradient(#FFF, #FFF)'}); 

	$(document).ready(function(){
		//$(".loading").fadeOut();
				
		// Fix lỗi css trong IE
		//if (isIE())
//		{
//			$("html").css("overflow","auto");
//			$("html body").css("overflow","hidden");
//		}
		//menu
	
		$("#nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400); 
			},function(){ 
			$(this).find('ul:first').css({visibility: "hidden"}); 
        }); 
		//logo
		$(".logo").jCarouselLite({
			//btnNext: ".next",
			//btnPrev: ".prev",
			auto: true,
			speed: 500, // Toc do chay hinh
			auto: 2000,// Thoi gian chay hinh
			visible: 5
		});
		
		//slide danh muc san pham
		$(".slider").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			speed: false, // Toc do chay hinh
			auto: false,// Thoi gian chay hinh
			visible: 1
		});
		//slide

		$("#slider2").easySlider({ 
				auto: true,
				continuous: true,
				numeric: true

			});
			
		//khach hang
		//Custom settings
		var style_in = 'easeOutBounce';
		var style_out = 'jswing';
		var speed_in = 1000;
		var speed_out = 300;	
	
		//Calculation for corners
		var neg = Math.round($('.qitem').width() / 2) * (-1);	
		var pos = neg * (-1);	
		var out = pos * 2;
		
		$('.qitem').each(function () {
		
			url = $(this).find('a').attr('href');
			img = $(this).find('img').attr('src');
			alt = $(this).find('img').attr('img');
			
			$('img', this).remove();
			$(this).append('<div class="topLeft"></div><div class="topRight"></div><div class="bottomLeft"></div><div class="bottomRight"></div>');
			$(this).children('div').css('background-image','url('+ img + ')');
	
			$(this).find('div.topLeft').css({top:0, left:0, width:pos , height:pos});	
			$(this).find('div.topRight').css({top:0, left:pos, width:pos , height:pos});	
			$(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos , height:pos});	
			$(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos , height:pos});	
	
		}).hover(function () {
		
			$(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});	
			$(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});	
			$(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});	
			$(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out});	
					
		},
		
		function () {
	
			$(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});	
			$(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});	
			$(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});	
			$(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in});	
		
		}).click (function () {
			window.location = $(this).find('a').attr('href');	
		});
		//end khach hang
		
		//san pham
		$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'113px'},{queue:false,duration:160});//Vi tri khi dua chuot vao
		}, function() {
			$(".cover", this).stop().animate({top:'170px'},{queue:false,duration:160}); // Vi tri dua chuot ve = Vi tri ban dau
		});

		$("#frmDatHang #txtSoLuong").live('keyup',function(e) {
			var dt = $(this).val(); 
			if (isNaN(dt)) {	
				dt = dt.substring(0,dt.length - 1); 
				$(this).val(dt);
			}
		});
		//move the image in pixel
		
		//end san pham
		//san pham noi bat
		$('.box_hot_sp').vTicker({
		speed: 500,
		pause: 5000,
		animation: 'fade',
		mousePause: false,
		showItems: 5
		});
	
	});
});



