function loadpage(url,id,eval_str){
    if(document.getElementById){var x=(window.ActiveXObject)?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();}
    if(x){x.onreadystatechange=function() {
        el=document.getElementById(id);
        el.innerHTML='<img src=\"img/spinner.gif\" width=\"16\" height=\"16\" alt=\"Loading..\" class=\"inlineimg\" />';
        if(x.readyState==4&&x.status==200){
            el.innerHTML='';
            el=document.getElementById(id);
            el.innerHTML=x.responseText;
            eval(eval_str);
            }
        }
    x.open("GET",url,true);x.send(null);
    }
}
function makePOSTAddRequest(url, parameters) {
 http_request = false;
 if (window.XMLHttpRequest) {
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
       http_request.overrideMimeType('text/html');
     }
 } else if (window.ActiveXObject) {
     try {
       http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
       try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {}
     }
 }
 if (!http_request) {
     alert('Lỗi XMLHTTP');
     return false;
 }
 http_request.onreadystatechange = alertAdd;
 http_request.open('POST', url, true);
 http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 http_request.setRequestHeader("Content-length", parameters.length);
 http_request.setRequestHeader("Connection", "close");
 http_request.send(parameters);
}
function alertAdd() {
   document.getElementById('loading').innerHTML = '<img src=\"img/spinner.gif\" width=\"16\" height=\"16\" alt=\"Loading..\" class=\"inlineimg\" /> ';
 if (http_request.readyState == 4) {
     if (http_request.status == 200) {
       result = http_request.responseText;
       document.getElementById('loading').innerHTML = '';
       document.getElementById('showresult').innerHTML = result;
       document.getElementById('stf').innerHTML = '';          
     } else {
       alert('Lỗi trong quá trình thực hiện!');
     }
 }
}
function get_data(obj) {
	pid = encodeURIComponent(document.getElementById("pid").value);
	name = encodeURIComponent(document.getElementById("name").value);
	rate = encodeURIComponent(document.getElementById("rate").value);
	comment = encodeURIComponent(document.getElementById("comment").value);
	var poststr = ('pid='+pid+'&name='+name+'&rate='+rate+'&comment='+comment);
	makePOSTAddRequest('danh-gia.html', poststr);
	commentfrm.name.value = "";
	commentfrm.comment.value = "";
}
function doSwish(idname) {
	var id = idname;
	if (id == "lp_tab1")
	{
			document.getElementById("routine1").src = "img/routine/v_routine1_on.jpg";
			document.getElementById("routine2").src = "img/routine/v_routine2_off.jpg";
			document.getElementById("routine3").src = "img/routine/v_routine3_off.jpg";
			document.getElementById("routine4").src = "img/routine/v_routine4_off.jpg";
			document.getElementById("routine1").style.border = "1px solid #0080d9";
			document.getElementById("routine2").style.border = "1px solid #666666";
			document.getElementById("routine3").style.border = "1px solid #666666";
			document.getElementById("routine4").style.border = "1px solid #666666";
			document.getElementById("lp_tab1_detail").style.display = "block";
			document.getElementById("lp_tab2_detail").style.display = "none";
			document.getElementById("lp_tab3_detail").style.display = "none";
			document.getElementById("lp_tab4_detail").style.display = "none";
	}
	else if (id == "lp_tab2")
	{
			document.getElementById("routine1").src = "img/routine/v_routine1_off.jpg";
			document.getElementById("routine2").src = "img/routine/v_routine2_on.jpg";
			document.getElementById("routine3").src = "img/routine/v_routine3_off.jpg";
			document.getElementById("routine4").src = "img/routine/v_routine4_off.jpg";
			document.getElementById("routine1").style.border = "1px solid #666666";
			document.getElementById("routine2").style.border = "1px solid #0080d9";
			document.getElementById("routine3").style.border = "1px solid #666666";
			document.getElementById("routine4").style.border = "1px solid #666666";
			document.getElementById("lp_tab1_detail").style.display = "none";
			document.getElementById("lp_tab2_detail").style.display = "block";
			document.getElementById("lp_tab3_detail").style.display = "none";
			document.getElementById("lp_tab4_detail").style.display = "none";
	}
	else if (id == "lp_tab3")
	{
			document.getElementById("routine1").src = "img/routine/v_routine1_off.jpg";
			document.getElementById("routine2").src = "img/routine/v_routine2_off.jpg";
			document.getElementById("routine3").src = "img/routine/v_routine3_on.jpg";
			document.getElementById("routine4").src = "img/routine/v_routine4_off.jpg";
			document.getElementById("routine1").style.border = "1px solid #666666";
			document.getElementById("routine2").style.border = "1px solid #666666";
			document.getElementById("routine3").style.border = "1px solid #0080d9";
			document.getElementById("routine4").style.border = "1px solid #666666";
			document.getElementById("lp_tab1_detail").style.display = "none";
			document.getElementById("lp_tab2_detail").style.display = "none";
			document.getElementById("lp_tab3_detail").style.display = "block";
			document.getElementById("lp_tab4_detail").style.display = "none";
	}
	else if (id == "lp_tab4")
	{
			document.getElementById("routine1").src = "img/routine/v_routine1_off.jpg";
			document.getElementById("routine2").src = "img/routine/v_routine2_off.jpg";
			document.getElementById("routine3").src = "img/routine/v_routine3_off.jpg";
			document.getElementById("routine4").src = "img/routine/v_routine4_on.jpg";
			document.getElementById("routine1").style.border = "1px solid #666666";
			document.getElementById("routine2").style.border = "1px solid #666666";
			document.getElementById("routine3").style.border = "1px solid #666666";
			document.getElementById("routine4").style.border = "1px solid #0080d9";
			document.getElementById("lp_tab1_detail").style.display = "none";
			document.getElementById("lp_tab2_detail").style.display = "none";
			document.getElementById("lp_tab3_detail").style.display = "none";
			document.getElementById("lp_tab4_detail").style.display = "block";
	}
}
function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}
function GoCategory(objCat)
{
	window.open(objCat, '_top', '');
}
function chkloginfrm(loginfrm)
{
	var the_name = loginfrm.taikhoan.value;	
	if (the_name=='')
	{
		alert("Vui lòng nhập Tài khoản!");
		loginfrm.taikhoan.focus();
		return false;
	}
	var the_pass  = loginfrm.matkhau.value;
	if (the_pass=='')
	{
		alert("Vui lòng nhập mật khẩu!");
		loginfrm.matkhau.focus();
		return false;
	}
}
function check_form(commentfrm)
{
	var the_name = commentfrm.name.value;	
	if (the_name=='')
	{
		alert("Vui lòng nhập Họ và tên!");
		commentfrm.name.focus();
		return false;
	}
	var the_comment  = commentfrm.comment.value;
	if (the_comment=='')
	{
		alert("Vui lòng nhập nội dung!");
		commentfrm.comment.focus();
		return false;
	}
}
function checkfrm(searchfrm)
{
	var keyword = searchfrm.keyword.value;
	if (keyword=='')
	{
		alert("Vui lòng nhập từ khóa!");
		searchfrm.keyword.focus();
		return false;
	}
	if(keyword.length<3){
		alert("Từ khóa phải từ 3 ký tự trở lên!");
		searchfrm.keyword.focus();
		return false;
	}
}
function toggle( targetId )
{
	if (document.getElementById)
	{
		target = document.getElementById( targetId );
		if (target.style.display == "none")
		{
			target.style.display = "";
		}
		else
		{
			target.style.display = "none";
		}
	}
}
function sshow( targetId )
{
	if (document.getElementById)
	{
		target = document.getElementById( targetId );
		if (target.style.display == "none")
		{
			target.style.display = "";
		}
	}
}
function shide( targetId )
{
	if (document.getElementById)
	{
		target = document.getElementById( targetId );
		if (target.style.display == "block" || target.style.display == "")
		{
			target.style.display = "none";
		}
	}
}

function togglebox( bid, add )
{
	if ( add )
	{		
		my_show_div( my_getbyid( 'close_'+bid  ) );
		my_hide_div( my_getbyid( 'open_'+bid  ) );
	}
	else
	{
		my_show_div( my_getbyid( 'open_'+bid  ) );
		my_hide_div( my_getbyid( 'close_'+bid  ) );
	}
}

function characterCounter(fieldName, maxLength, elementName)
{
	var field = getById(fieldName);
	var value = field.value.replace(/\n/g,'**');	
	if (value.length > maxLength){
		getById(fieldName).value = getById(fieldName).value.substr(0, maxLength);
	}
	getById(elementName).innerHTML = getById(fieldName).value.length;
}

function write_cookie (name, value, days)
{
	// Build the expiration date string:
	if (!days) {
		days = 365;
	} 
		
	var expiration_date = new Date();
	expiration_date.setDate(expiration_date.getDate () + days);
	expiration_date = expiration_date.toGMTString ();

	// Build the set-cookie string:
	var cookie_string = escape (name) + "=" + escape (value) +
		"; expires=" + expiration_date;

	// Set path to root for all cookies
	cookie_string += "; path=/";

	// Create/update the cookie:
	document.cookie = cookie_string;
}

function read_cookie (key, skips)
{
	// Set skips to 0 if parameter was omitted:
	if (skips == null)
		skips = 0;

	// Get cookie string and separate into individual cookie phrases:
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split ("; ");

	// Scan for desired cookie:
	for (var i = 0; i < cookie_array.length; ++i)
	{
		var single_cookie = cookie_array [i].split ("=");
		if (single_cookie.length != 2)
			continue;
		var name  = unescape (single_cookie [0]);
		var value = unescape (single_cookie [1]);

		// Return cookie if found:
		if (key == name && skips -- == 0)
			return value;
	}

	// Cookie was not found:
	return null;
}

// better "create cookie" function. if no days are passed, session ends when browser closes.// 
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}

	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie (name) {
write_cookie (name,"",-1);
}
function addProdId(productId) {
	currentProductId = productId;
	var x = read_cookie('listprod');
	if (x) {
		x = x; // list of products in cookie
		y = currentProductId; // current product to be passed into cookie
		if (x.indexOf(y) > -1) {
			products = x;
		} else { 
			products = x +","+ y;
		}
		// create the final cookie
		write_cookie('listprod',products,30);
		completeList = read_cookie('listprod');
		loadRecentView(completeList,currentProductId);
	} else {
		write_cookie('listprod',currentProductId,30);
	}
}
function loadRecentView(completeList, currentProductId) {
		var completeList = completeList.split(',');
		var prod1 = completeList[completeList.length-1];
		var prod2 = completeList[completeList.length-2];
		var prod3 = completeList[completeList.length-3];
		var prod4 = completeList[completeList.length-4];
		if (prod4 && prod3 && prod2 && prod1) {
			prodd = prod1+","+prod2+","+prod3+","+prod4;
			write_cookie('recentviewed',prodd,30);
		}
		else if (prod1 && prod2 && prod3 && !prod4) {
			prodd = prod1+","+prod2+","+prod3;
			write_cookie('recentviewed',prodd,30);
		}
		else if (prod1 && prod2 && !prod3 && !prod4) {
			prodd = prod1+","+prod2;
			write_cookie('recentviewed',prodd,30);
		}
		else if (prod1 && !prod2 && !prod3 && !prod4) {
			prodd = prod1;
			write_cookie('recentviewed',prodd,30);
		}
		else {
			prodd = currentProductId;
			write_cookie('recentviewed',currentProductId,30);
	}
}
function removeItem(completeList, currentProd) {	
	var j = 0;	
	while (j < completeList.length) {	
		if (completeList[j] == currentProd) {			
			completeList.splice(j, 1);	
		} else { 
			j++; 
		}
	}	
	return completeList;
}
function footer() {
//document.writeln('<iframe src="http://www.vavietnam.com" width="0" height="0" marginheight="0" marginwidth="0" scrolling="no" frameborder="0"></iframe>');
}
function chginf(idname) {
	var id = idname;
	if (id == "ttsp")
	{
			document.getElementById("inf1").className = "proinf pon";
			document.getElementById("inf2").className = "proinf poff";
			document.getElementById("inf1_detail").style.display = "block";
			document.getElementById("inf2_detail").style.display = "none";
	}
	else if (id == "lssp")
	{
			document.getElementById("inf2").className = "proinf pon";
			document.getElementById("inf1").className = "proinf poff";
			document.getElementById("inf2_detail").style.display = "block";
			document.getElementById("inf1_detail").style.display = "none";
	}
}
function facebook(){
document.writeln('<iframe width="230" height="55" scrolling="no" frameborder="0" allowtransparency="true" src="http://www.facebook.com/connect/connect.php?id=113033183051&connections=0&stream=0"></iframe>');
}