
var cur_month;
var last_month;

function $$(o) { return document.getElementById(o); }

var fxmonths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var fxdate=new Date();
var fxmonth=fxdate.getMonth();
var fxyear=fxdate.getYear(); 
if (fxyear<1900)fxyear+=1900;
var fxyear2=fxyear;
var lastmonth=fxmonth-1;
if (fxmonth==0){
	lastmonth=11;
	fxyear2=fxyear-1; 
}
var cPath1="/retail/files/kursy/"+fxtype1+"_FX_"+fxyear+"_"+fxmonths[fxmonth]+".xml?a="+fxdate.getTime();
var cPath2="/retail/files/kursy/"+fxtype1+"_FX_"+fxyear+"_"+fxmonths[lastmonth]+".xml?a="+fxdate.getTime();
//var cPath2="/retail/files/kursy/"+fxtype1+"_FX_"+fxyear2+"_"+fxmonths[lastmonth]+".xml?a="+fxdate.getTime();
var oPath1="/retail/files/kursy/"+fxtype1+"_FX_"+fxyear2+"_"+fxmonths[lastmonth]+".xml?a="+fxdate.getTime();
var oPath2="/retail/files/kursy/"+fxtype1+"_FX_"+fxyear2+"_"+fxmonths[lastmonth-1]+".xml?a="+fxdate.getTime();
try {
	var fxkursy1=XML_load(cPath1,"kurs");
	var cur_month=fxmonth+1;
	cur_month=cur_month.toString();
	if(cur_month<10) cur_month="0"+cur_month;
	var last_month=lastmonth+1;
	last_month=last_month.toString();
	if(last_month<10) last_month="0"+last_month;
	var fxkursy2=XML_load(oPath1,"kurs");
} catch(err) {
	var fxkursy1=XML_load(cPath2,"kurs");
	var cur_month=lastmonth+1;
	var last_month=lastmonth;
	var fxkursy2=XML_load(oPath2,"kurs");
}


var days=XML_query('select data from fxkursy1 where 1 limit 0;');
if(!days)
{
	var fxkursy1=XML_load(cPath2,"kurs");
	var cur_month=lastmonth+1;
	cur_month=cur_month.toString();
	if(cur_month<10) cur_month="0"+cur_month;
	var fxkursy2=XML_load(oPath2,"kurs");
	var last_month=lastmonth;
	last_month=last_month.toString();
	if(last_month<10) last_month="0"+last_month;
}

var xml_data=XML_query('select data from fxkursy1 where waluta="CHF-USD Visa" limit 0;');
var dzis=xml_data[xml_data.length-1];
var fxdata1=XML_query('select waluta,kupno from fxkursy1 where data="'+dzis+'" limit 0;');
var fxdata2=XML_query('select waluta,kupno from fxkursy2 where data="'+dzis+'" limit 0;');


var fx=new Array();
fx['veb_chf']=fxdata1[0][1];
fx['veb_gbp']=fxdata1[1][1];
fx['veb_usd']=fxdata1[2][1];
fx['veb_eur']=fxdata1[3][1];
fx['veb_pln']=fxdata1[4][1];
fx['veb_chf1']=fxdata1[5][1];
fx['veb_gbp1']=fxdata1[6][1];
fx['veb_eur1']=fxdata1[7][1];
fx['veb_usd1']=fxdata1[8][1];
fx['veb_pln1']=fxdata1[9][1];
fx['mc_chf']=fxdata1[10][1];
fx['mc_gbp']=fxdata1[11][1];
fx['mc_usd']=fxdata1[12][1];
fx['mc_eur']=fxdata1[13][1];
fx['mc_pln']=fxdata1[14][1];


function Sel_kursy()
{
var xml_data=XML_query('select data from fxkursy1 where waluta="CHF-USD Visa" limit 0;');
var xml_data1=XML_query('select data from fxkursy2 where waluta="CHF-USD Visa" limit 0;');
var selekcik=document.getElementsByTagName("select");
for(a=0;a<selekcik.length;a++)
{
if(selekcik[a].className=="Sel_kursy")
{
var sin=selekcik[a].innerHTML;
var y="";
	for(x=(xml_data.length-1);x>=0;x--)
	{
	y+="<option>"+xml_data[x]+"</option>";	
	}
	for(x=(xml_data1.length-1);x>=0;x--)
	{
	
	y+="<option>"+xml_data1[x]+"</option>";	
	}
$(selekcik[a]).html( $(y) );
}
}
}

$(document).ready(function(){
$('select.Sel_kursy').change(function(){
var val=$(this).val();
var id=this.id;
Zm_kursy_cards(val,id);
});
});

function Zm_kursy_cards(a,x)
{
var y=a.split("-");
if (y[1]==cur_month) var fxdata1=XML_query('select waluta,kupno from fxkursy1 where data="'+a+'" limit 0;');
if (y[1]==last_month) var fxdata1=XML_query('select waluta,kupno from fxkursy2 where data="'+a+'" limit 0;');

var fx=new Array();
fx['veb_chf']=fxdata1[0][1];
fx['veb_gbp']=fxdata1[1][1];
fx['veb_usd']=fxdata1[2][1];
fx['veb_eur']=fxdata1[3][1];
fx['veb_pln']=fxdata1[4][1];
fx['veb_chf1']=fxdata1[5][1];
fx['veb_gbp1']=fxdata1[6][1];
fx['veb_eur1']=fxdata1[7][1];
fx['veb_usd1']=fxdata1[8][1];
fx['veb_pln1']=fxdata1[9][1];
fx['mc_chf']=fxdata1[10][1];
fx['mc_gbp']=fxdata1[11][1];
fx['mc_usd']=fxdata1[12][1];
fx['mc_eur']=fxdata1[13][1];
fx['mc_pln']=fxdata1[14][1];

var kom0=document.getElementById(x+'0');
var kom1=document.getElementById(x+'1');
var kom2=document.getElementById(x+'2');
var kom3=document.getElementById(x+'3');
var kom4=document.getElementById(x+'4');

if((x=='veb0')||(x=='veb1')) {
var kom5=document.getElementById(x+'5');
var kom6=document.getElementById(x+'6');
var kom7=document.getElementById(x+'7');
var kom8=document.getElementById(x+'8');
var kom9=document.getElementById(x+'9')
x='veb';
kom5.innerHTML=eval("fx['"+x+"_chf1']");
kom6.innerHTML=eval("fx['"+x+"_pln1']");
kom7.innerHTML=eval("fx['"+x+"_gbp1']");
kom8.innerHTML=eval("fx['"+x+"_usd1']");
kom9.innerHTML=eval("fx['"+x+"_eur1']");
};
if((x=='veb0')||(x=='veb1')) x='veb';
kom0.innerHTML=eval("fx['"+x+"_chf']");
kom1.innerHTML=eval("fx['"+x+"_pln']");
kom2.innerHTML=eval("fx['"+x+"_gbp']");
kom3.innerHTML=eval("fx['"+x+"_usd']");
kom4.innerHTML=eval("fx['"+x+"_eur']");
}

function archiwum() {
	var ar=$$('fx_cb_arch');
	var fx=$$('fx_cb');
	fx.style.display="none"; 
	ar.style.display="block"; 
}

function getArchiwum() {
	var ds=$$('cDay');
	window.location.href="?content=cb_ps_kursy&date="+ds.value;
}

function theseDays() {
	document.write('<select id="cDay">');
	for (var fa=0;fa<days.length;fa+=13)
		document.write('<option value="'+days[fa][0]+'">'+days[fa][0]+'</option>');
	document.write('<'+'/select>');
}



function kursyPDF() {
	var o = $$('kursyPdf');
	var d = new Date();
	if ( o && o.href )  {
		o.href= o.href + '?a=' + d.getTime();
	}
}