﻿// Nguyen Thanh Binh - 0923.686.993 - Thanhbinh101287@gmail.com - Y!M: Thanhbinh101287

function loadDefault()
{
	selected();
	scrollTop('btnTop');
	datetime('datetime', 'EN');
	//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 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","July","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";
 
}
