$(document).ready(function()
{

	$("#pay_amount_ron").live( 'change', function() {
		$("#pay_amount").val( ($("#pay_amount_ron").val() / ($("#usd_rate").val() * $("#usd_rate_comision").val()) ) );//.toFixed(2) //dont truncate if you want in the transaction the exactly RON amount to be saved
		$("#pay_amount_showed").val( ($("#pay_amount_ron").val() / ($("#usd_rate").val() * $("#usd_rate_comision").val()) ).toFixed(2) );
	});

	$(".expand").live('click', function() {
		var target	= $(this).attr('href');
		
		var targetState = $(target).css('display');
		
		if( targetState == 'block' ) {
			$(target).css('display', 'none');
		} else {
			$(target).css('display', 'block');
		}
	});
	
	$("#ronpay_currency").live( 'click', function() {
		alert("RonPay currency: BNR + 1.99% * BNR\n1 EUR = " + $("#ronpay_eur").val() + " RON\n1 USD = " + $("#ronpay_usd").val() + " RON");
	});
	
	$("#prepaygenerationWithApprovelCheckBox").live( 'click', function() {
		var chk = document.getElementById("prepaygenerationWithApprovelCheckBox");
		if (chk.checked) 
			changeFormTarget("prepaygenerationForm", "");
		else
			changeFormTarget("prepaygenerationForm", "_blank");
	});

	$("#accountType").live( 'click', function() {
		
		var selection = $(this).val();
		
		if( selection == "user" ) {
			
			
			$("#CompanyName").attr('disabled', 'disabled');
			$("#CUI").attr('disabled', 'disabled');
			$("#CompanyManagerCNP").attr('disabled', 'disabled');
			
			$("#CompanyName").val('');
			$("#CUI").val('');
			$("#CompanyManagerCNP").val('');
			
			$("#CNP").removeAttr('disabled');
			$("#new_username").removeAttr('disabled');
			
		} else if( selection = "company" ) {
			
			$("#CNP").attr('disabled', 'disabled');
			$("#new_username").attr('disabled', 'disabled');
			
			$("#CNP").val('');
			$("#new_username").val('');
			
			$("#CompanyName").removeAttr('disabled');
			$("#CUI").removeAttr('disabled');;
			$("#CompanyManagerCNP").removeAttr('disabled');
			
		} 
		
	} );
	
	
}
);

function changeFormTarget(formName, newTarget)
{
	var form = document.getElementById(formName);
	form.target = newTarget;
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1325598-12']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();



function utmx_section(){}function utmx(){}
(function(){var k='1292636731',d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n.
length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
d.write('<sc'+'ript src="'+
'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
utmx("url",'A/B');

var _gaq = _gaq || [];
_gaq.push(['gwo._setAccount', 'UA-8153312-1']);
_gaq.push(['gwo._trackPageview', '/1292636731/test']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


/*
Function: convertToCurrency(source, rate, destination)

	Arguments:
	source - control of the source RON amount
	rate - control of the rate value
	destination - control of the destination
*/
function convertToCurrency()
{
	if(arguments[2] == null || arguments[2] == "") 
	{
		return;
	}	
	else
	{
		dest = arguments[2];
	}
	if(arguments[0] == null || arguments[0] == "") 
	{
		dest.value = "";
		return;
	}
	else
	{
		source = arguments[0];
	}
	if(arguments[1] == null || arguments[1] == "") 
	{
		dest.value = "";
		return;
	}
	else
	{
		rate = 	arguments[1];
	}

	
	dest.value = (source.value / rate.value).toFixed(2);
}

function convertToRON()
{
	if(arguments[2] == null || arguments[2] == "") 
	{
		return;
	}	
	else
	{
		dest = arguments[2];
	}
	if(arguments[0] == null || arguments[0] == "") 
	{
		dest.value = "";
		return;
	}
	else
	{
		source = arguments[0];
	}
	if(arguments[1] == null || arguments[1] == "") 
	{
		dest.value = "";
		return;
	}
	else
	{
		rate = 	arguments[1];
	}

	
	dest.value = (source.value * rate.value).toFixed(2);
}





