﻿// Nguyen Thanh Binh - 0923.686.993 - Thanhbinh101287@gmail.com - Y!M: Thanhbinh101287

function loadDefault()
{
	selected();
	scrollTop('btnTop');
	Weblink('slWeblink');
}

function Compare()
{
	var ck = $('input[name="ProductID"]:checked');
	var list='';
	if(ck.length>1 && ck.length<=10)
	{
		ck.each(function(e){
			list=list+$(this).val()+',';
		});
		list=list.substr(0,list.length-1);
		window.location.href="compare.aspx?list="+list;
	}
	else
		alert(ck.length+" sản phẩm! Số sản phẩm so sánh từ 2 -> 10");
}

function GetAjax(url,where)
{	
	$('#'+where).hide();
	$('#'+where).load(url, function(e) {
		$(this).show("slow");
	});
}

function AddCart(id)
{
	window.location.href="cart.aspx?add="+id+"&count=1";
}

function Weblink(where)
{
	$('#'+where).change(function(){
		if($(this).val()!="")
			window.open($(this).val(), '_blank');
	});
}

function popup(url,name,windowWidth,windowHeight){
    var myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	var mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	var properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=yes, top="+mytop+",left="+myleft;
    var newwindow = window.open(url,name,properties);
}

function selected()
{
	$("select").each(function(){
		var title = $(this).attr("title").split(',');
		$(this).find("option").each(function(){
			for(i=0;i<title.length;i++)
				if($(this).val()==title[i])
					$(this).attr("selected","selected");
		});
	});
	//$('html, body').animate({scrollTop: $(document).height()}, 1000).animate({scrollTop: '0px'}, 500);
}

function poll()
{
	$('#frmPoll #btnSend').click(function(){
		if($('input[name="radiodVote"]:checked').val()!=null)
		{
			$.post("actions.aspx", { acType: $('#acType').val(), radiodVote: $('input[name="radiodVote"]:checked').val(),PollID: $('#PollID').val()}, 
			function(data){ 
				return; 
			});
		}
	});
}

function City(code)
{
	var optionIndex = 1;
	document.getElementById('slDistrict').length=1;
	for(i=0;i<=jCity.length;i++)
	{
		if(jCity[i]==code)
		{
			var optionname = new Option(jCityName[i], jDistrict[i]); 
			document.getElementById('slDistrict').options[optionIndex]=optionname;
			optionIndex++;
		}
	}
}

function PostCity(code)
{
	var optionIndex = 1;
	document.getElementById('slPostDistrict').length=1;
	for(i=0;i<=jPostCity.length;i++)
	{
		if(jPostCity[i]==code)
		{
			var optionname = new Option(jPostCityName[i], jPostDistrict[i]); 
			document.getElementById('slPostDistrict').options[optionIndex]=optionname;
			optionIndex++;
		}
	}
}

function scrollTop(where)
{
	$('#'+where).click(function() {
		$('html, body').animate({scrollTop: '0px'}, 500);
		return false;
	});
}
function popup(url,name,windowWidth,windowHeight){
    var myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	var mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	var properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=yes, top="+mytop+",left="+myleft;
    var newwindow = window.open(url,name,properties);
}


function ShowGoldPrice(where){
	var sHTML = '';	
	sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ĐVT: tr.đ/lượng</div>');
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="font-size:10px;width:30%;">Loại</td>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="text-align:center;font-size:10px;width:35%;">Mua</td>');
	sHTML = sHTML.concat('		<td class="td-weather-title" style="text-align:center;font-size:10px;width:35%;">Bán</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('</table>');
	document.getElementById(where).innerHTML= sHTML;
}

function ShowForexRate(where){
	var sHTML = '';
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-forex">');
	for(var i=0;i<vForexs.length;i++){
		sHTML = sHTML.concat('	<tr>');
		sHTML = sHTML.concat('		<td class="td-weather-title">').concat(vForexs[i]).concat('</td>');
		sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vCosts[i]).concat('</td>');
		sHTML = sHTML.concat('	</tr>');
	}
	sHTML = sHTML.concat('</table>');
	document.getElementById(where).innerHTML= sHTML;
}


function Stock(id)
{
	$.ajax({
		type: "GET",
		url: "getxml.aspx?url=http://fpts.com.vn/ListFile/_"+id+"_0.xml",
		success: function(xml) {
			$('.sdlie-stock').fadeOut("slow", function(){
				$(xml).find('Item').each(function(){
					$('#sDate').html($(this).find('sDate').text());
					$('#sChange').html($(this).find('sChange').text());
					$('#sChangePercent').html($(this).find('sChangePercent').text());
					$('#sTotalTrade').html($(this).find('sTotalTrade').text());
					$('#sTotalShare').html($(this).find('sTotalShare').text());
					$('#sTotalValue').html($(this).find('sTotalValue').text());
					if(id==1)
					{
						if(parseFloat($(this).find('sChange').text())<0)
						{
							$('#sIndex').css("color","red"); 
							$('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/down.gif" />');
							$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ho_red.png');
						}
						else
						{
							$('#sIndex').css("color","green"); 
							$('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/up.gif" />');
							$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ho_green.png');
						}
						$('#sIndex').append('VN-Index: '+$(this).find('sIndex').text());
					}
					else if(id==2)
					{ 
						if(parseFloat($(this).find('sChange').text())<0)
						{
							$('#sIndex').css("color","red");
							$('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/down.gif" />');
							$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ha_red.png');
						}
						else
						{
							$('#sIndex').css("color","green"); 
							$('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/up.gif" />');
							$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ha_green.png');
						}
						$('#sIndex').append('HAX-Index: '+$(this).find('sIndex').text());
					}
				});
			}).fadeIn("show");
		}
	});
}


function editorBasic(id)
{
	CKEDITOR.replace( id,
	{
		toolbar :
		[
			 ['Source','-','Bold','Italic','Underline','Strike'],
			 ['NumberedList','BulletedList','-','Outdent','Indent'],
			 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			 ['TextColor','BGColor'],['Font','FontSize']
		]
	});
}


function checked(name,str)
{
	var title = str.split(',');
	$('input[name='+name+']').each(function(){
		$(this).each(function(){
			for(i=0;i<title.length;i++)
				if($(this).val()==title[i])
					$(this).attr("checked","checked");
		});
	});
}

function datetime(where, lang)
{
	var date = new Date();
	var dd = date.getDate();
	var mm = date.getMonth();
	var yyyy = date.getFullYear();
	var yy= date.getYear();
	var day = date.getDay();
	
	var day_vn=new Array("Thứ hai","Thứ ba","Thứ tư","Thứ năm","Thứ sáu","Thứ bẩy","Chủ nhật");
	
	var day_en=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var month_en=new Array("January","February","March","April","May","June","August","September","October","November","December");

	if(lang=='VN')
		$('#'+where).append(day_vn[day]+', '+dd+'/'+mm+'/'+yyyy);
	else if(lang=='EN')
		$('#'+where).append(day_en[day]+', '+month_en[mm]+' '+dd+', '+yyyy);
}

//Bảng tính vay

 
function removeComma(x)
{
	numcom = x.length;	
	for(i=0;i<numcom;i++)
	{
		x=x.replace(",","");
	}
	return x;
}
 
function doTraTruoc()
{
	var gia = document.getElementById('gia').value;
	var truoc = document.getElementById('truoc').value;
 
	if(truoc!="" && truoc!="0" && gia!="" && gia!="0")
	{
		gia = removeComma(gia);
		gia = parseInt(gia);
		truoc = removeComma(truoc);
		truoc = parseInt(truoc);
 
		var phantram = Math.round((truoc/gia)*100);
		document.getElementById('phantram').value = phantram;
	}
		doTraTruoc1();
}
 
 
function doTraTruoc1()
{
	var phantram = document.getElementById('phantram').value;
	var gia = document.getElementById('gia').value;
 
	if (parseInt(phantram) >100) {
		phantram = '100';
	}
 
	if (phantram !="" && phantram!="0" && gia!="" && gia!="0") {
		gia=removeComma(gia);
		gia=parseInt(gia);
		phantram=parseInt(phantram);
		var truoc=Math.round((phantram/100)*gia);
		document.getElementById('truoc').value=truoc;
	}		
}
 
 
function doThangNam()
{
	var thang=document.getElementById('thang').value;
 
	if(thang!="" && thang!="0")
	{
		thang=parseInt(thang);
		nam=Math.round((thang/12));
		document.getElementById('nam').value=nam;
	}
	doThangNam1();
}
 
 
function doThangNam1()
{
	var nam=document.getElementById('nam').value;
 
	if(nam!="" && nam!="0")
	{
		nam=parseInt(nam);
		thang=nam*12;
		document.getElementById('thang').value=thang;
	}	
}
 
 
function doTinh()
{
	
	var lai = document.getElementById('lai').value;
	var thang = document.getElementById('thang').value;
	var nam = document.getElementById('nam').value;
	var truoc = document.getElementById('truoc').value;
	var gia = document.getElementById('gia').value;
 
 
	flag=true;
	if(lai=="" || lai=="0")
	{
		flag=false;
		document.getElementById('lai').lai.focus();
	}
	if(thang=="" || thang=="0")
	{
		flag=false;
		document.getElementById('thang').focus();
	}
	if(truoc=="" || truoc=="0")
	{
		flag=false;
		document.getElementById('truoc').focus();
	}
	if(gia=="" || gia=="0")
	{
		flag=false;
		document.getElementById('gia').focus();
	}
	if(flag)
	{	
		gia=removeComma(gia);
		gia=parseInt(gia);
		truoc=removeComma(truoc);
		truoc=parseInt(truoc);
		thang=parseInt(thang);
		nam=parseInt(nam);
		lai=parseFloat(lai);	
		document.getElementById('lai').value=lai;
		document.getElementById('nam').value=thang/12;
		document.getElementById('phantram').value=(truoc/gia)*100;
		var phaitra=(((gia-truoc)/thang) + ((gia-truoc)*lai/100));
		document.getElementById('phaitra').value=Math.round(phaitra);
	}
 
}
 
 
function doReset() {
	document.getElementById('gia').value="1,000,000,000";
	document.getElementById('truoc').value="100,000,000";
	document.getElementById('thang').value="180";
	document.getElementById('lai').value="1";
	document.getElementById('phantram').value="0";
	document.getElementById('nam').value="0";
	document.getElementById('phaitra').value="0";

}

var itemsPerPage = 5, ci = itemsPerPage - 1, total = 0, minLeft = 0, maxLeft = 0, left = 0, speed = 15000;
var obj, s, w, st, items;
function slideInit() {
    obj = jQuery('#promoitems');
    items = jQuery('#promoitems > .item');
    total = s = items.length;
    w = jQuery('.item').width();
    
    if (total > itemsPerPage) {
        // Reset width for slider
        obj.css('width', w * s + 'px');

        // Set margin left min when click next button
        minLeft = -w * itemsPerPage * (total % itemsPerPage == 0 ? parseInt(total / itemsPerPage) : parseInt(total / itemsPerPage) + 1);
        maxLeft = -w * itemsPerPage;

        // Set slide continuos
        jQuery(obj).append(jQuery('#promoitems div.item:lt(' + (itemsPerPage - s % itemsPerPage) + ')').clone());
        for (var i = 0; i < itemsPerPage; i++)
            jQuery(obj).prepend(jQuery('#promoitems div.item').eq(s - 1).clone());
        s = jQuery('.item').length;
        jQuery(obj).css('width', w * s + 'px').css('margin-left', -w * itemsPerPage + 'px');

        // Reset left
        left = -itemsPerPage * w;

        // Mouse click
        jQuery('.promo-page #slidenext').click(function () { slideNext(); });
        jQuery('.promo-page #slideprev').click(function () { slidePrev(); });

        // Auto sliding
        st = setTimeout('slideNext()', speed);
    }
    else {
        jQuery('.promo-page').remove();
    }
}

function slideNext() {
    left -= itemsPerPage * w;
    if (left < minLeft) left = minLeft;

    jQuery(obj).animate(
		{ marginLeft: left },
		{ queue: false, duration: 800, complete: adjustNext }
	)
    // Auto sliding image
    if (st != null) clearTimeout(st);
    st = setTimeout('slideNext()', speed);
}

function slidePrev() {
    left += itemsPerPage * w;
    if (left > maxLeft) left = 0;
    jQuery(obj).animate(
		{ marginLeft: left },
		{ queue: false, duration: 800, complete: adjustPrev }
	)
    // Auto sliding image
    if (st != null) clearTimeout(st);
    st = setTimeout('slidePrev()', speed);
}

function adjustNext() {
    ci += itemsPerPage;
    if (left == minLeft) {
        jQuery('#promoitems div.item:lt(' + itemsPerPage + ')').remove();
        var curInd = ci % total;
        for (i = 0; i < itemsPerPage; i++) {
            curInd += 1;
            if (curInd > total - 1) curInd = 0;
            obj.append(items.eq(curInd).clone());
        }
        obj.css('margin-left', left + (w * itemsPerPage) + 'px');
        if (ci > total) ci = ci % total;
    }
}

function adjustPrev() {
    ci -= itemsPerPage;
    if (left == 0) {
        jQuery('#promoitems div.item:gt(' + (s - itemsPerPage - 1) + ')').remove();
        var curInd = ci - itemsPerPage;
        if (curInd < 0) curInd = total + curInd;
        for (var i = 0; i < itemsPerPage; i++) {
            if (curInd < 0) curInd = total - 1;
            obj.prepend(items.eq(curInd).clone());
            curInd--;
        }
        obj.css('margin-left', maxLeft + 'px');
        if (ci < 0) ci = ci += total;
    }
}

function ShowGoldPriceen(where) {
    var sHTML = '';
    //sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ÄVT: tr.Ä‘/lÆ°á»£ng</div>');
    sHTML = sHTML.concat('<table border="1px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:30%;"></td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Buy</td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Sell</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('</table>');
    document.getElementById(where).innerHTML = sHTML;
}

function ShowGoldPricevn(where) {
    var sHTML = '';
    //sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ÄVT: tr.Ä‘/lÆ°á»£ng</div>');
    sHTML = sHTML.concat('<table border="1px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:30%;"></td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Mua</td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Bán</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('</table>');
    document.getElementById(where).innerHTML = sHTML;
}
function ShowGoldPriceEN(where) {
    var sHTML = '';
    //sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ÄVT: tr.Ä‘/lÆ°á»£ng</div>');
    sHTML = sHTML.concat('<table border="1px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:30%;"></td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Buy</td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Sell</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('</table>');
    document.getElementById(where).innerHTML = sHTML;
}

function ShowGoldPriceVN(where) {
    var sHTML = '';
    //sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ÄVT: tr.Ä‘/lÆ°á»£ng</div>');
    sHTML = sHTML.concat('<table border="1px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:30%;"></td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Mua</td>');
    sHTML = sHTML.concat('		<td class="td-weather-title" style="width:35%;">Bán</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('	<tr>');
    sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
    sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
    sHTML = sHTML.concat('	</tr>');
    sHTML = sHTML.concat('</table>');
    document.getElementById(where).innerHTML = sHTML;
}

function ShowForexRate(where) {
    var sHTML = '';
    sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-forex">');
    for (var i = 0; i < vForexs.length; i++) {
        if (vForexs[i] == 'USD' || vForexs[i] == 'GBP' || vForexs[i] == 'EUR') {
            sHTML = sHTML.concat('	<tr>');
            sHTML = sHTML.concat('		<td class="td-weather-title">').concat(vForexs[i]).concat('</td>');
            sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vCosts[i]).concat('</td>');
            sHTML = sHTML.concat('	</tr>');
        //    break;
        }
    }
    sHTML = sHTML.concat('</table>');
    document.getElementById(where).innerHTML = sHTML;
}


function Stock(id) {
    $.ajax({
        type: "GET",
        url: "getxml.aspx?url=http://fpts.com.vn/ListFile/_" + id + "_0.xml",
        success: function (xml) {
            $('.sdlie-stock').fadeOut("slow", function () {
                $(xml).find('Item').each(function () {
                    $('#sDate').html($(this).find('sDate').text());
                    $('#sChange').html($(this).find('sChange').text());
                    $('#sChangePercent').html($(this).find('sChangePercent').text());
                    $('#sTotalTrade').html($(this).find('sTotalTrade').text());
                    $('#sTotalShare').html($(this).find('sTotalShare').text());
                    $('#sTotalValue').html($(this).find('sTotalValue').text());
                    if (id == 1) {
                        if (parseFloat($(this).find('sChange').text()) < 0) {
                            $('#sIndex').css("color", "red");
                            $('#sIndex').html('<img src="http://solieu5.vcmedia.vn/www/cafef/images/down.gif" />');
                            $('#sImageChart').attr('src', 'http://cafef.vn/HomeMountainChartImage/ho_red.png');
                        }
                        else {
                            $('#sIndex').css("color", "green");
                            $('#sIndex').html('<img src="http://solieu5.vcmedia.vn/www/cafef/images/up.gif" />');
                            $('#sImageChart').attr('src', 'http://cafef.vn/HomeMountainChartImage/ho_green.png');
                        }
                        $('#sIndex').append('VN-Index: ' + $(this).find('sIndex').text());
                    }
                    else if (id == 2) {
                        if (parseFloat($(this).find('sChange').text()) < 0) {
                            $('#sIndex').css("color", "red");
                            $('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/down.gif" />');
                            $('#sImageChart').attr('src', 'http://cafef.vn/HomeMountainChartImage/ha_red.png');
                        }
                        else {
                            $('#sIndex').css("color", "green");
                            $('#sIndex').html('<img src="http://solieu7.cafef.vn/www/dantri/images/up.gif" />');
                            $('#sImageChart').attr('src', 'http://cafef.vn/HomeMountainChartImage/ha_green.png');
                        }
                        $('#sIndex').append('HAX-Index: ' + $(this).find('sIndex').text());
                    }
                });
            }).fadeIn("show");
        }
    });
}


function ShowWeatherInVietNamen(div) {
    ShowWeatherBox(4, div);
    ShowWeatherBox(6, div);
    ShowWeatherBox(9, div);
}

function ShowWeatherBox(vId, div) {

    var sLink = '';
    sLink = 'cross.aspx?id='+vId;

    $.ajax({
        type: "GET",
        url: sLink,
        dataType: "xml",
        complete: function (req) {
            
            var vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather, vCity;
            vAdImg = req.responseXML.getElementsByTagName('AdImg').item(0).firstChild.nodeValue;
            vAdImg1 = req.responseXML.getElementsByTagName('AdImg1').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild != null)
                vAdImg2 = req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild != null)
                vAdImg3 = req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild != null)
                vAdImg4 = req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild != null)
                vAdImg5 = req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild.nodeValue;
            vWeather = req.responseXML.getElementsByTagName('Weather').item(0).firstChild.nodeValue;
            vCity = req.responseXML.getElementsByTagName('City').item(0).firstChild.nodeValue;
            GetWeatherBox(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather, vCity, div);
        }
    });
    
}

function GetWeatherBox(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather, vCity, div) {
    var sHTML = '';
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg).concat('" class="img-weather1" alt="" />');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg1).concat('" class="img-weather" alt="" />');
    if (vImg2 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg2).concat('" class="img-weather" alt="" />');
    if (vImg3 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg3).concat('" class="img-weather" alt="" />');
    if (vImg4 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg4).concat('" class="img-weather" alt="" />');
    if (vImg5 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg5).concat('" class="img-weather" alt="" />');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" />');
    $(div).append('<tr><td width="50%">' + locdau(vCity) + '</td><td>' + sHTML + '</td></tr>');

}

function ShowWeatherInVietNamvn(div) {
    ShowWeatherBoxvn(4, div);
    ShowWeatherBoxvn(6, div);
    ShowWeatherBoxvn(9, div);
}

function ShowWeatherBoxvn(vId, div) {

    var sLink = '';
    sLink = 'cross.aspx?id=' + vId;

    $.ajax({
        type: "GET",
        url: sLink,
        dataType: "xml",
        complete: function (req) {

            var vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather, vCity;
            vAdImg = req.responseXML.getElementsByTagName('AdImg').item(0).firstChild.nodeValue;
            vAdImg1 = req.responseXML.getElementsByTagName('AdImg1').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild != null)
                vAdImg2 = req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild != null)
                vAdImg3 = req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild != null)
                vAdImg4 = req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild.nodeValue;
            if (req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild != null)
                vAdImg5 = req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild.nodeValue;
            vWeather = req.responseXML.getElementsByTagName('Weather').item(0).firstChild.nodeValue;
            vCity = req.responseXML.getElementsByTagName('City').item(0).firstChild.nodeValue;
            GetWeatherBoxVN(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather, vCity, div);
        }
    });

}

function GetWeatherBoxVN(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather, vCity, div) {
    var sHTML = '';
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg).concat('" class="img-weather1" alt="" />');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg1).concat('" class="img-weather" alt="" />');
    if (vImg2 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg2).concat('" class="img-weather" alt="" />');
    if (vImg3 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg3).concat('" class="img-weather" alt="" />');
    if (vImg4 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg4).concat('" class="img-weather" alt="" />');
    if (vImg5 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg5).concat('" class="img-weather" alt="" />');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" />');
    $(div).append('<tr><td width="50%">' + vCity + '</td><td>' + sHTML + '</td></tr>');

}



function locdau(str) {  
  str= str.toLowerCase();  
  str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");  
  str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");  
  str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");  
  str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");  
  str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");  
  str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");  
  str= str.replace(/đ/g,"d");  
//  str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-"); 
/* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */ 
//  str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1- 
//  str= str.replace(/^\-+|\-+$/g,"");  
//cắt bỏ ký tự - ở đầu và cuối chuỗi  
  return str.toUpperCase();
}

var g_isPostBack = false;
function windowOnBeforeUnload() {
    var IsClose = false;
    if (g_isPostBack == true)
        return; // Let the page unload

    if (window.event) {
        //window.event.returnValue = 'Are you sure?'; // IE
        //alert('release ie lib');
        IsClose = true;
    }
    else {
        //return 'Are you sure?'; // FX
        //alert('firefox lib');
        IsClose = true;
    }
    
    if(IsClose) {
        $.ajax({
            url: 'close.aspx',
            success: function (data) {
            }
        });
    }
    
    
}

window.onbeforeunload = windowOnBeforeUnload;
