var FirstSelCur;
var SecondSelCur;
var FirstAffCur;
var SecondAffCur;
var stype;

var CurrencyPriority = new Array();

//Relative
CurrencyPriority["EUR"] = 100;
CurrencyPriority["GBP"] = 90;
CurrencyPriority["AUD"] = 80;
CurrencyPriority["NZD"] = 70;
CurrencyPriority["USD"] = 60;
CurrencyPriority["CAD"] = 50;
CurrencyPriority["CHF"] = 46;
CurrencyPriority["SGD"] = 45;
CurrencyPriority["DKK"] = 44;
CurrencyPriority["PLN"] = 43;
CurrencyPriority["CCK"] = 42;
CurrencyPriority["HKD"] = 41;
CurrencyPriority["HUF"] = 40;
CurrencyPriority["LVL"] = 39;
CurrencyPriority["NOK"] = 38;
CurrencyPriority["SKK"] = 37;
CurrencyPriority["ZAR"] = 36;
CurrencyPriority["SEK"] = 35;
CurrencyPriority["HRK"] = 34;
CurrencyPriority["LTL"] = 33;
CurrencyPriority["MXN"] = 32;
CurrencyPriority["RUB"] = 31;
CurrencyPriority["JPY"] = 30;

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function ShowForm()
{
with (document.f)
{
FirstSelCur = pair.value.substring(0,3);
SecondSelCur = pair.value.substring(4,7);
if (currency.value != SecondSelCur)
{
if (CurrencyPriority[currency.value] > CurrencyPriority[SecondSelCur])
{
 FirstAffCur = currency.value;
 SecondAffCur = SecondSelCur;
}
else
{
 FirstAffCur = SecondSelCur;
 SecondAffCur = currency.value;
}
document.getElementById("pricet").className = "open";
document.getElementById("divinput").className = "open";
if (currency.value == FirstAffCur) {stype = " Ask price";} else {stype = " Bid price"};
document.getElementById("pricet").innerHTML = "Current " + FirstAffCur + "/" + SecondAffCur + stype + ":";
}
else
{
document.getElementById("pricet").className = "closed";
document.getElementById("divinput").className = "closed";
FirstAffCur = 0;
SecondAffCur = 0;
}
}
}


function CalcPV()
{
with (document.f)
{
    var errors = [];
    errors['ls'] = document.getElementById('error_ls');
    errors['price'] = document.getElementById('error_price');
    
    for(var j in errors){
        if(errors[j]){
            errors[j].className = 'error closed';
        }
    }
    
	if(!ls.value)
	{
        errors['ls'].innerHTML = 'Enter your position size.';
        errors['ls'].className = 'error open';
		return false;
	}
	else if((!price.value) && (currency.value != SecondSelCur))
	{
        errors['price'].innerHTML = 'Enter the current price.';
        errors['price'].className = 'error open';
		return false;
	}
	var t;
	var UnitCosts;

	if (currency.value != "JPY" && currency.value != "HUF") UnitCosts = 0.0001; else UnitCosts = 0.01
	if (SecondAffCur != 0)
	{
	 if (stype == " Ask price") {if (SecondAffCur == "JPY" || SecondAffCur == "HUF") UnitCosts = UnitCosts / (price.value / 100); else UnitCosts = UnitCosts / price.value;}
	 else {if (SecondAffCur == "JPY" || SecondAffCur == "HUF") UnitCosts = (UnitCosts * price.value) / 100; else UnitCosts = UnitCosts * price.value;}
	}
	pip.value = UnitCosts * ls.value;
	createCookie('psc_currency',currency.value,31);
}
	return true;
}