// Nguyen Thanh Binh - 0923.686.993 - Thanhbinh101287@gmail.com - Y!M: Thanhbinh101287

function loadDefault()
{
	if($('.menu_left').length==0)
		$('.content_center').css({'width' : '754px','margin':'0'});
	selected();
	scrollTop('btnTop');
	scrollTop('btnTop2');
}

function Weblink(where)
{
	$('#'+where).change(function(){
		if($(this).val()!="")
			window.open($(this).val(), '_blank');
	});
}

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 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 scrollTop(id)
{
	$('#'+id+'').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)
					{
						$('#sIndex').html('VN-Index: '+$(this).find('sIndex').text());
						$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ho_red.png');
					}
					else if(id==2)
					{
						$('#sIndex').html('HNX-Index: '+$(this).find('sIndex').text());
						$('#sImageChart').attr('src','http://cafef.vn/HomeMountainChartImage/ha_red.png');
					}
				});
			}).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)
{
	var date = new Date();
	var dd = date.getDate();
	var mm = date.getMonth()+1;
	var yyyy = date.getFullYear();
	var yy= date.getYear();
	$('#'+where).append(dd+'/'+mm+'/'+yyyy);
}
