// JavaScript Document
/* ----- Code by: boy_infotech ---- */
if (window.parent!=window){ 
	alert('Trang web ban dang vao khong phai la website chinh thuc cua Vatgia.com.');
	window.open(location.href, '_top', '');
}

function addToCartButton(record_id, estore_id, estore_name, vatgia_verified, map_friend, direct_add_to_cart_link, baokim_payment, redirect){
	strReturn	= '<div class="add_to_cart_button">';
	if(vatgia_verified == 1) strReturn	+= '<div class="vatgia_verified">Hãy đặt hàng tại đây<br />để được đảm bảo an toàn <img class="tooltip_content" tooltipContent="vatgia_verified_text" src="/images/question.gif" style="cursor:pointer" /></div>';
	if(direct_add_to_cart_link != ""){
		strReturn	+= '<div><a href="' + direct_add_to_cart_link + '"><img src="/images/btn_order.gif" /></a></div>';
		strReturn	+= '<div class="end"><a href="/home/addfavorites.php?addto=product&record_id=' + record_id + '&redirect=' + redirect + '" rel="nofollow"><img src="/images/btn_order_favorites.gif" /></a></div>';
	}
	else{
		strReturn	+= '<div><a href="/home/addtocart.php?iPro=' + record_id + '&estore_id=' + estore_id + '&estore_name=' + estore_name + '&return=' + redirect + '"><img src="/images/btn_order.gif" /></a></div>';
		strReturn	+= '<div class="or">Hoặc</div>';
		strReturn	+= '<div>';
			if(map_friend !== null){
				strReturn	+= '<select id="friend_id"><option value="0">- Chọn người nhận hàng -</option>';
				$.each(map_friend, function(key, value){
					strReturn	+= '<option value="' + key + '">' + value + '</option>';
				});
				strReturn	+= '</select>';
			}
			strReturn	+= '<a href="javascript:;" onClick="window.location.href=\'/home/buynow.php?iPro=' + record_id + '&iUse=' + estore_id + '&iUf=\' + parseInt($(&quot;#friend_id&quot;).val())"><img src="/images/btn_order_1_click.gif" /></a>';
		strReturn	+= '</div>';
		strReturn	+= '<div' + (baokim_payment == 0 ? ' class="end"' : "") + '><a href="/home/addfavorites.php?addto=product&record_id=' + record_id + '&redirect=' + redirect + '" rel="nofollow"><img src="/images/btn_order_favorites.gif" /></a></div>';
		if(baokim_payment == 1) strReturn	+= '<div class="baokim_pay_now end">An toàn hơn qua Baokim.vn<br /><a href="/home/baokim_pay_now.php?iPro=' + record_id + '&iUse=' + estore_id + '" target="_blank"><img src="/images/btn_order_baokim.gif" /></a></div>';
	}
	strReturn	+= '</div>';
	return strReturn;
}

function change_description(id_show, id_data){
	document.getElementById(id_show).innerHTML = document.getElementById(id_data).innerHTML;
}

function change_class(id_hide, id_show, num_record){
	for(i=1; i<=num_record; i++){
		document.getElementById(id_hide + i).className = 'text_tab_1';
	}
	document.getElementById(id_show).className = 'text_tab_2';
}

function changeClass(id, classN){
	document.getElementById(id).className = classN;
}

function show_price_usd(use_name, price, price_usd, exchange){
	document.write('<span class="pro_v2_price_usd" style="cursor:pointer" onClick="alert(\'' + price + ' VNĐ = ' + price_usd + ' USD\\nTỉ giá tại cửa hàng ' + use_name + ': 1 USD = ' + exchange + ' VNĐ\')">USD?</span>');
}

function user_history(){
	if(document.getElementById("show_user_history_content").className == 'show_user_history_content_open'){
		changeClass('show_user_history_content', 'show_user_history_content_close');
		document.getElementById("show_user_history_image").src = "/images/downarrow.png";
	}
	else{
		changeClass('show_user_history_content', 'show_user_history_content_open');
		document.getElementById("show_user_history_image").src = "/images/uparrow.png";
	}
}

function change_class_news(id_hide, id_show, num_record){
	for(i=1; i<=num_record; i++){
	eval("document.all." + id_hide + i + ".className='text_tab_news_1'");
	}
	eval("document.all." + id_show + ".className='text_tab_news_2'");
}

function change_tab(id_tab, num_data, arrId, arrClass, id_show, id_data){
	for(i=0; i<num_data; i++){
		for(j=0; j<arrId.length; j++){
			document.getElementById(arrId[j] + i).className = "";
		}
	}
	for(i=0; i<arrId.length; i++){
		document.getElementById(arrId[i] + id_tab).className = arrClass[i];
	}
	if(id_show != "" && id_data != ""){
		document.getElementById(id_show).innerHTML = document.getElementById(id_data).innerHTML;
	}
}

function product_season(pro_id, type){
	document.write('<a title="Sản phẩm theo mùa" rel="nofollow" style="cursor:pointer; color:#000000" onClick="window.open(\'/ajax/user_product_season.php?pro_id=' + pro_id + '\',\'\',\'width=600,height=500,menubar=0,resizable=1,scrollbars=1,statusbar=0,titlebar=0,toolbar=0\')"><img align="absmiddle" src="/images/icon_season_' + type + '_v2.gif" /> Theo mùa</a>');
}

function show_picture(type, picture){
	window.open('/home/showpicture.php?type=' + type + '&picture=' + picture,'','scrollbars=yes,resizeable=1,width=300,height=300')
}

function change_image(id, img){
	ob = document.getElementById(id);
	ob.src = img;
}
/* ----- End code by: boy_infotech ---- */

// dinhtoan1905@yahoo.co.uk code
function SetViewTableDiv(tableName)
{
    var str = document.getElementById(tableName + 'Loc').style.display;
    if (str == 'block')
    {
        document.getElementById(tableName + 'Loc').style.display = "none";
        document.getElementById(tableName).src = "/css1/AdImgDown.gif";
    }
    else
    {
        document.getElementById(tableName + 'Loc').style.display = "block";
        document.getElementById(tableName).src = "/css1/AdImgUp.gif";
    }
    
}
function tab_page(select_id,count_tab){
	for(i=1;i<=count_tab;i++){
		document.getElementById("text_page_"+i).style.display='none';
		document.getElementById("tab_page_"+i).className='';
	}
		document.getElementById("text_page_"+select_id).style.display='inline';
		document.getElementById("tab_page_"+select_id).className='bg_tab_select';
}
// end dinhtoan1905@yahoo.co.uk code
function save_cookie(cookie_name, cookie_value){
	document.cookie = cookie_name + "=" + cookie_value;
}

function getCookie(c_name){
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1){ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function hoidap_reply_thankyou_point(point){
	rate_max = 5;
	for(i=1; i<=rate_max; i++){
		star_image = (i <= point) ? "/images/star_green.gif" : "/images/star_none.gif";
		document.write('<img align="absmiddle" src="' + star_image + '" />');
	}
}

//Tao star binh chọn
function generateVote(numberstar){
	numberstar = parseFloat(numberstar)
	var intStar = parseInt(numberstar);
	//Kiểm tra sai số
	if (intStar < 0) { intStar = 0; numberstar = 0; }
	if (intStar > 10) { intStar = 10; numberstar = 10; }
	//Ghi star xịn ra
	for (i=1;i<=intStar;i++) document.write('<img align="absmiddle" border="0" src="http://static.vatgia.com/images/star1.gif" />');
	//Neu intStar!=numberstar thi them 0,5 vao va cong intStar them 1
	if (intStar!=numberstar){ document.write('<img align="absmiddle" border="0" src="http://static.vatgia.com/images/star2.gif" />'); intStar++;}
	//ghi ra so sao = 0 con lai 
	for (i=intStar+1;i<=10;i++) document.write('<img align="absmiddle" border="0" src="http://static.vatgia.com/images/star0.gif" />');
}

//Tao star binh chọn
function generateVote_v2(numberstar){
	numberstar = parseFloat(numberstar)
	var intStar = parseInt(numberstar);
	//Kiểm tra sai số
	if (intStar < 0) { intStar = 0; numberstar = 0; }
	if (intStar > 10) { intStar = 10; numberstar = 10; }
	//Ghi star xịn ra
	for (i=1;i<=intStar;i++) document.write('<img align="absmiddle" border="0" src="/images/icon_star.gif" />');
	//Neu intStar!=numberstar thi them 0,5 vao va cong intStar them 1
	if (intStar!=numberstar){ document.write('<img align="absmiddle" border="0" src="/images/icon_star_half.gif" />'); intStar++;}
	//ghi ra so sao = 0 con lai 
	for (i=intStar+1;i<=10;i++) document.write('<img align="absmiddle" border="0" src="/images/icon_star_off.gif" />');
}

//Tao star binh chọn
function generateVote_poll_v2(numberstar){
	numberstar = parseFloat(numberstar)
	var intStar = parseInt(numberstar);
	//Kiểm tra sai số
	if (intStar < 0) { intStar = 0; numberstar = 0; }
	if (intStar > 10) { intStar = 10; numberstar = 10; }
	//Ghi star xịn ra
	for (i=1;i<=intStar;i++) document.write('<img align="absmiddle" border="0" src="/images/pro_v2_star_1.gif" />');
	//Neu intStar!=numberstar thi them 0,5 vao va cong intStar them 1
	if (intStar!=numberstar){ document.write('<img align="absmiddle" border="0" src="/images/pro_v2_star_2.gif" />'); intStar++;}
	//ghi ra so sao = 0 con lai 
	for (i=intStar+1;i<=10;i++) document.write('<img align="absmiddle" border="0" src="/images/pro_v2_star_0.gif" />');
}

function notice_alert(type, url){
	switch(type){
		case "price":
			str = '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/notice_price.gif" /> Báo sai giá</a>';
			break;
		case "stock":
			str = '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/notice_stock.gif" /> Báo hết hàng</a>';
			break;
		case "hoidap_useful_vote":
		case "hoidap_reply_useful_vote":
			str = '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</a> &nbsp; ';
			str = str + '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</a>';
			break;
		default:
			str = '<img align="absmiddle" hspace="5" src="/images/notice_price.gif" style="cursor:pointer" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'" />';
			break;
	}
	document.write(str);
}

function notice_alert_hoidap(url, thumb_up, thumb_down){
	str = '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</a> <b>(' + thumb_up + ')</b> &nbsp; &nbsp; ';
	str = str + '<a href="#not_login" onClick="if(confirm(\'Xin bạn vui lòng đăng nhập để sử dụng tính năng này !\\nBạn hãy click vào OK để đến trang đăng nhập.\')) window.location.href=\'/home/login.php?redirect=' + url + '\'"><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</a> <b>(' + thumb_down + ')</b>';
	document.write(str);
}

function notice_pro_alert_link(pro_id, u_id, u_name){
	if(confirm('Bạn có chắc chắn sản phẩm này là lỗi không?')){
		load_data('/ajax/product_error_name.php?iUse=' + u_id + '&iPro=' + pro_id, 'notice_shop_verified');
	}
}
function notice_pro_alert_price(pro_id, u_id, u_name){
	if(confirm('Bạn đã kiểm tra và chắc chắn giá tại cửa hàng ' + u_name + ' là sai?')){
		load_data('/ajax/notice_price.php?iUse=' + u_id + '&iPro=' + pro_id, 'notice_shop_verified');
	}
}
function notice_pro_alert_stock(pro_id, u_id, u_name){
	if(confirm('Bạn đã kiểm tra và chắc chắn sản phẩm cửa hàng ' + u_name + ' đã hết hàng?')){
		load_data('/ajax/notice_stock.php?iUse=' + u_id + '&iPro=' + pro_id, 'notice_shop_verified');
	}
}
function notice_product_drop(status, pro_id, u_id, u_name, logged, url){
	str = "";
	if(logged == 1){
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_pro_alert_price(' + pro_id + ',' + u_id + ',&quot;' + u_name + '&quot;); &gt;Báo sai giá&lt;/div&gt;';
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_pro_alert_stock(' + pro_id + ',' + u_id + ',&quot;' + u_name + '&quot;); &gt;Báo hết hàng&lt;/div&gt;';
	}
	else{
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_alert_not_login(); &gt;Báo sai giá&lt;/div&gt;';
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_alert_not_login(); &gt;Báo hết hàng&lt;/div&gt;';
		/*
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_pro_alert_price(' + pro_id + ',' + u_id + ',&quot;' + u_name + '&quot;); &gt;Báo sai giá&lt;/div&gt;';
		str = str + '&lt;div style=cursor:pointer onMouseOver=this.style.background=&quot;#CCCCCC&quot;; onMouseOut=this.style.background=&quot;none&quot;; onClick=notice_pro_alert_stock(' + pro_id + ',' + u_id + ',&quot;' + u_name + '&quot;); &gt;Báo hết hàng&lt;/div&gt;';
		*/
	}
	document.write('<a style="cursor:pointer" onMouseOver="domTT_activate(this, event, \'content\', \'' + str + '\', \'styleClass\', \'notice_product\', \'type\', \'velcro\');"><img align="absmiddle" hspace="5" src="/images/notice_price.gif" /></a>');
}
function notice_product(type, pro_id, u_id, u_name){
	if(type == "price"){
		str = '<a style="font-size:9px" title="Báo sai giá sản phẩm của gian hàng này" href="#np" onclick="if (confirm(\'Bạn đã kiểm tra và chắc chắn giá tại cửa hàng ' + u_name + ' là sai?\')){load_data(\'/ajax/notice_price.php?iUse=' + u_id + '&iPro=' + pro_id + '\', \'div_notice_' + u_id + '\'); }"><img align="absmiddle" border="0" src="/images/notice_price.gif" /> Báo sai giá</a>';
	}
	else{
		str = '<a style="font-size:9px" title="Báo hết hàng tại cửa hàng này" href="#ns" onclick="if (confirm(\'Bạn đã kiểm tra và chắc chắn sản phẩm cửa hàng ' + u_name + ' đã hết hàng?\')){load_data(\'/ajax/notice_stock.php?iUse=' + u_id + '&iPro=' + pro_id + '\', \'div_notice_' + u_id + '\'); }"><img align="absmiddle" border="0" src="/images/notice_stock.gif" /> Báo hết hàng</a>';
	}
	document.write(str);
}

function notice_hoidap_useful_vote(hd_id, type, url, not_vote, thumb_up, thumb_down){
	if(not_vote == 1){
		str = '<span title="Bạn không được vote cho câu hỏi của mình"><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</span> <b>(' + thumb_up + ')</b> &nbsp; &nbsp; ';
		str = str + '<span title="Bạn không được vote cho câu hỏi của mình"><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</span> <b>(' + thumb_down + ')</b>';
	}
	else{
		switch(type){
			case -1:
				str = '<span><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</span> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<span class="current"><img align="absmiddle" border="0" src="/images/thumb_down_ok.gif" />Không</span> <b class="vote_down">(' + thumb_down + ')</b>';
				break;
			case 0:
				str = '<a href="/hoidap/hoidap_useful_vote.php?record_id=' + hd_id + '&vote=1&redirect=' + url + '" rel="nofollow" onMouseOver="change_image(\'hoidap_thumb_up_' + hd_id + '\', \'/images/thumb_up_ok.gif\')" onMouseOut="change_image(\'hoidap_thumb_up_' + hd_id + '\', \'/images/thumb_up.gif\')"><img id="hoidap_thumb_up_' + hd_id + '" align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</a> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<a href="/hoidap/hoidap_useful_vote.php?record_id=' + hd_id + '&vote=-1&redirect=' + url + '" rel="nofollow" onMouseOver="change_image(\'hoidap_thumb_down_' + hd_id + '\', \'/images/thumb_down_ok.gif\')" onMouseOut="change_image(\'hoidap_thumb_down_' + hd_id + '\', \'/images/thumb_down.gif\')"><img id="hoidap_thumb_down_' + hd_id + '" align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</a> <b class="vote_down">(' + thumb_down + ')</b>';
				break;
			case 1:
				str = '<span class="current"><img align="absmiddle" border="0" src="/images/thumb_up_ok.gif" />Có</span> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<span><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</span> <b class="vote_down">(' + thumb_down + ')</b>';
				break;
		}
	}
	document.write(str);
}

function notice_hoidap_reply_useful_vote(hdr_id, type, url, not_vote, thumb_up, thumb_down){
	if(not_vote == 1){
		str = '<span title="Bạn không được vote cho câu trả lời của mình"><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</span> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
		str = str + '<span title="Bạn không được vote cho câu trả lời của mình"><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</span> <b class="vote_down">(' + thumb_down+ ')</b>';
	}
	else{
		switch(type){
			case -1:
				str = '<span><img align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</span> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<span class="current"><img align="absmiddle" border="0" src="/images/thumb_down_ok.gif" />Không</span> <b class="vote_down">(' + thumb_down+ ')</b>';
				break;
			case 0:
				str = '<a href="/hoidap/hoidap_reply_useful_vote.php?record_id=' + hdr_id + '&vote=1&redirect=' + url + '" rel="nofollow" onMouseOver="change_image(\'hoidap_reply_thumb_up_' + hdr_id + '\', \'/images/thumb_up_ok.gif\')" onMouseOut="change_image(\'hoidap_reply_thumb_up_' + hdr_id + '\', \'/images/thumb_up.gif\')"><img id="hoidap_reply_thumb_up_' + hdr_id + '" align="absmiddle" border="0" src="/images/thumb_up.gif" />Có</a> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<a href="/hoidap/hoidap_reply_useful_vote.php?record_id=' + hdr_id + '&vote=-1&redirect=' + url + '" rel="nofollow" onMouseOver="change_image(\'hoidap_reply_thumb_down_' + hdr_id + '\', \'/images/thumb_down_ok.gif\')" onMouseOut="change_image(\'hoidap_reply_thumb_down_' + hdr_id + '\', \'/images/thumb_down.gif\')"><img id="hoidap_reply_thumb_down_' + hdr_id + '" align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</a> <b class="vote_down">(' + thumb_down+ ')</b>';
				break;
			case 1:
				str = '<span class="current"><img align="absmiddle" border="0" src="/images/thumb_up_ok.gif" />Có</span> <b class="vote_up">(' + thumb_up + ')</b> &nbsp; &nbsp; ';
				str = str + '<span><img align="absmiddle" border="0" src="/images/thumb_down.gif" />Không</span> <b class="vote_down">(' + thumb_down+ ')</b>';
				break;
		}
	}
	document.write(str);
}

function user_buddy_list(type, user_loginname, buddy_id, authen_code, url){
	if(type == 0){
		document.write('<img alt="Thêm ' + user_loginname + ' vào danh sách bạn thân" align="absmiddle" border="0" hspace="5" src="/images/add_2.gif" style="cursor:pointer" onClick="if(confirm(\'Bạn có muốn thêm ' + user_loginname + ' vào danh sách bạn bè hay không?\')) window.location.href=\'/home/add_buddy_list.php?iUse=' + buddy_id + '&redirect=' + url + '\'" />');
	}
	else{
		document.write('<img alt="Xóa ' + user_loginname + ' khỏi danh sách bạn thân" align="absmiddle" border="0" hspace="5" src="/images/del.gif" style="cursor:pointer" onClick="if(confirm(\'Bạn có muốn xóa ' + user_loginname + ' khỏi danh sách bạn thân không?\')) window.location.href=\'/home/remove_buddy_list.php?iUse=' + buddy_id + '&authen_code=' + authen_code + '&redirect=' + url + '\'" />');
	}
}
