for( var key in currencies )
{
	document.getElementById('eform_from_currency').options[document.getElementById('eform_from_currency').options.length] = new Option("WebMoney "+key,key);
	document.getElementById('eform_to_currency').options[document.getElementById('eform_to_currency').options.length] = new Option("WebMoney "+key,key);
}

document.getElementById('eform_from_currency').value = "WMZ";
document.getElementById('eform_to_currency').value = "WMR";

EformUpdateAmount();
function EformUpdateAmount()
{
	// Создаем ссылки для удобства
	form_from_currency = document.getElementById('eform_from_currency');
	form_to_currency = document.getElementById('eform_to_currency');
	form_course = document.getElementById('eform_course');
	form_reserve = document.getElementById('eform_reserve');
	
	form_from_amount = document.getElementById('eform_from_amount');
	form_from_acurrency = document.getElementById('eform_from_acurrency');
	
	form_to_amount = document.getElementById('eform_to_amount');
	form_to_aamount = document.getElementById('eform_to_aamount');
	
	form_with_commission = document.getElementById('eform_with_commission');
	form_with_acommission = document.getElementById('eform_with_acommission');
	
	form_purse = document.getElementById('eform_purse');
	form_apurse = document.getElementById('eform_purse_currency');
	
	form_email = document.getElementById('eform_email');
	
	
	// Устанавливаем курс
	if( courses[form_from_currency.value+"_"+form_to_currency.value]==undefined )
	{
		form_course.innerHTML = '<font color="red">обмен не проводится</font>';
	}
	else
	{
		form_course.innerHTML = (courses[form_from_currency.value+"_"+form_to_currency.value][0]<1 ? 1 : courses[form_from_currency.value+"_"+form_to_currency.value][0]).toFixed(3)+' '+form_from_currency.value+' = '+(courses[form_from_currency.value+"_"+form_to_currency.value][0]<1 ? 1/courses[form_from_currency.value+"_"+form_to_currency.value][0] : 1).toFixed(3)+' '+form_to_currency.value;
	}
	
	//Устанавливаем резерв
	form_reserve.innerHTML = currencies[form_to_currency.value].toFixed( 2 )+' '+form_to_currency.value;
	
	// Устанавливаем меняемую валюту
	form_from_acurrency.innerHTML = form_from_currency.value;
	
	//Устанавливаем с учетом коммиссии
	form_with_commission.value = (Math.ceil( form_from_amount.value*1.008*100 )/100).toFixed(2);
	form_with_acommission.innerHTML = form_from_currency.value;
	
	//Устанавливаем получаемую сумму
	form_to_amount.value = (parseInt( (courses[form_from_currency.value+"_"+form_to_currency.value]==undefined ? 0 : form_from_amount.value/courses[form_from_currency.value+"_"+form_to_currency.value][0] )*100 )/100).toFixed( 2 )
	form_to_aamount.innerHTML = form_to_currency.value;
	
	//Установим кошелек
	form_purse.value = form_to_currency.value.substr( -1 );
	form_apurse.innerHTML = form_to_currency.value;
}
function EformSubmit()
{
	// Создаем ссылки для удобства
	form_from_currency = document.getElementById('eform_from_currency');
	form_to_currency = document.getElementById('eform_to_currency');
	form_course = document.getElementById('eform_course');
	form_reserve = document.getElementById('eform_reserve');
	
	form_from_amount = document.getElementById('eform_from_amount');
	form_from_acurrency = document.getElementById('eform_from_acurrency');
	
	form_to_amount = document.getElementById('eform_to_amount');
	form_to_aamount = document.getElementById('eform_to_aamount');
	
	form_with_commission = document.getElementById('eform_with_commission');
	form_with_acommission = document.getElementById('eform_with_acommission');
	
	form_purse = document.getElementById('eform_purse');
	form_apurse = document.getElementById('eform_purse_currency');
	
	form_email = document.getElementById('eform_email');
	
	if( courses[form_from_currency.value+"_"+form_to_currency.value]==undefined )
	{
		alert( "Обмен по данному направлению не проводится." );
		return false;
	}
	else if( form_from_amount.value<courses[form_from_currency.value+"_"+form_to_currency.value][1] )
	{
		alert( "Минимальная меняемая сумма равна "+courses[form_from_currency.value+"_"+form_to_currency.value][1]+" "+form_from_currency.value+"." );
		return false;
	}
	else if( courses[form_from_currency.value+"_"+form_to_currency.value][2]!=0 && form_from_amount.value>courses[form_from_currency.value+"_"+form_to_currency.value][2] )
	{
		alert( "Максимальная меняемая сумма равна "+courses[form_from_currency.value+"_"+form_to_currency.value][2]+" "+form_from_currency.value+"." );
		return false;
	}
	else if( form_to_amount.value>currencies[form_to_currency.value] )
	{
		alert( "Максимальная получаемая сумма равна "+currencies[form_to_currency.value]+" "+form_to_currency.value+"." );
		return false;
	}
	else if( !/^[ZREUYBG][0-9]{12}$/.test( form_purse.value ) )
	{
		alert( "Неверный формат введенного кошелька." );
		return false;
	}
	else if( form_purse.value.substr( 0,1 )!=form_to_currency.value.substr( -1 ) )
	{
		alert( "Введенный кошелек указан не в получаемой валюте." );
		return false;
	}
	else if( !/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,3}$/i.test( form_email.value ) )
	{
		alert( "Неверный формат введенного Email адреса." );
		return false;
	}
	else
	{
		return true;
	}
}
