﻿
function SetCurr(currencyID){ 
	setCookie('currencyID',currencyID);
	setPrice();
}

var currencyCode = ['','USD','EUR','GBP'];

function setPrice(){ 
	var USDPrice = $('#foproduct').children('option:selected').attr('price');
	var currencyID = getCookie('currencyID') || 1;
	var price;
	if(currencyID==1){price=(USDPrice*1.0).toFixed(2);}
	if(currencyID==2){price=(USDPrice*rateEur).toFixed(2);}
	if(currencyID==3){price=(USDPrice*rateGbp).toFixed(2);}
	$('#prctxt').val(price);
	
	$('#ccode').html(currencyCode[currencyID]);
}
	
function setPrice2() { 

	$('#selProduct option').each(function(){ 
		var USDPrice = $(this).attr('price');
		var currencyID = getCookie('currencyID') || 1;
		var price;
		if(currencyID==1){price=(USDPrice*1.0).toFixed(2);}
		if(currencyID==2){price=(USDPrice*rateEur).toFixed(2);}
		if(currencyID==3){price=(USDPrice*rateGbp).toFixed(2);}
		$(this).html($(this).html().replace(/\(.*\)/img,'')+'  ('+price+' '+currencyCode[currencyID]+')');						  
	})

}
	
$(function(){ 
	

	


	if($('#foserver').length>0){
	
		$.get('/inc/xhr.asp?action=GetServerList',{},function(text){ 
			$('#foserver').append($(text));
		});	
		
		$('#foserver').change(function(){ 
			$.get('/inc/xhr.asp?action=GetProductList&ServerID='+$(this).val(),{},function(text){ 
				$('#foproduct').empty().append($(text));
				setPrice();
			});								 
		});
		
		$('#foproduct').change(function(){ setPrice() });	
		
		$('#dobuy').attr('disabled',false).click(function(){
			if(!Number($('#foserver').val())>0 ){alert('Please select your servers!');$('#foserver').focus();return false;}
			if(!Number($('#foproduct').val())>0 ){alert('Please select your products!');$('#foproduct').focus();return false;}
			if($('#charname').val()=='' ){alert('Please fill your charname!');$('#charname').focus();return false;}
			location.href = "payment.asp?pid="+$('#foproduct').val()+"&charname="+decodeURI($('#charname').val());
		});	
		
	}
	
	
	
	
	
	

	
	if($('#selRegion').length>0){

		$('#selRegion').change(function(){ 
			$.get('/inc/xhr.asp?action=GetServerList&RegionID='+$(this).val(),{},function(text){ 
				$('#selServer').empty().append($(text));
				$('#selServer').change();
			});								 
		});
		
		$('#selServer').change(function(){ 
			$.get('/inc/xhr.asp?action=GetProductList2&ServerID='+$(this).val(),{},function(text){ 
				$('#selProduct').empty().append($(text));
				setPrice2();
			});							
		});
		
		$('#selcurrency').change(function(){ 
			setCookie('currencyID',parseInt($(this).val()));
			setPrice2();							  
		});
		
		
		$('#buyit').attr('disabled',false).click(function(){
			if(!Number($('#selServer').val())>0 ){alert('Please select your servers!');$('#selServer').focus();return false;}
			if(!Number($('#selProduct').val())>0 ){alert('Please select your products!');$('#selProduct').focus();return false;}
			if($('#txtCharacter').val()=='' ){alert('Please fill your charname!');$('#txtCharacter').focus();return false;}
			location.href = "payment.asp?pid="+$('#selProduct').val()+"&charname="+decodeURI($('#txtCharacter').val());
		});	
	
	}
	
})


