function GotoQuotazioni(tipo_fondo)
{
	var param = "?tipo_fondo=" + tipo_fondo + "";
	var link  = "home_quotazione_fondi.asp" + param;
	
	document.location = link;
}

function SelQuotazione(tipo_fondo, tipo_quotazione)
{
	var param = "?tipo_fondo=" + tipo_fondo + "";
	param = param + "&tipo_quotazione=" + tipo_quotazione + "";
	
	var link  = "home_quotazione_fondi.asp" + param;
	
	document.location = link;
}


function getDataDa()
{
	return document.frm.giorno_da_field.options[document.frm.giorno_da_field.options.selectedIndex].value+"/"+
	document.frm.mese_da_field_desc.options[document.frm.mese_da_field_desc.options.selectedIndex].value +"/"+
	document.frm.anno_da_field.options[document.frm.anno_da_field.options.selectedIndex].value;
}
function getDataA()
{
	return document.frm.giorno_a_field.options[document.frm.giorno_a_field.options.selectedIndex].value+"/"+
	document.frm.mese_a_field_desc.options[document.frm.mese_a_field_desc.options.selectedIndex].value +"/"+
	document.frm.anno_a_field.options[document.frm.anno_a_field.options.selectedIndex].value;
}

function giorni_da(dd, mm)
{
	mesi_da();
	giornoselezionato=document.frm.giorno_da_field.value;
	lst = document.frm.giorno_da_field.options.length; 
	for (i = lst; i >= 0; i--) 
	{ 
		document.frm.giorno_da_field.options[i] = null; 
	} 

	gg = getDaysInMonth(document.frm.mese_da_field_desc.value,document.frm.anno_da_field.options[document.frm.anno_da_field.selectedIndex].text);
	ini = 1;
	
	if (parseInt(document.frm.anno_da_field.value)==parseInt(yyMin))
	{
		if (parseInt(document.frm.mese_da_field_desc.value)==parseInt(mmMin))	
		{
			ini = ddMin;
		}
	}
	else
	{
		if (parseInt(document.frm.anno_da_field.value)==parseInt(yyMax))
		{
			if (parseInt(document.frm.mese_da_field_desc.value)==parseInt(mmMax))
			{
				gg = ddMax;
				if (parseInt(giornoselezionato) > parseInt(ddMax))
				{
					giornoselezionato = parseInt(ddMax);
				}
			}
		}		
	}	

	x=1;
	for(i=ini; i<=gg;i++) 
	{ 
		
		document.frm.giorno_da_field.options[x-1] = new Option(i,i,false,false); 
		x++;
	} 	
	document.frm.giorno_da_field.value = giornoselezionato;
}

function mesi_da()
{
	ini = 1;
	ende = 12;
	
	meseselezionato=document.frm.mese_da_field_desc.value;
	
	if (parseInt(document.frm.anno_da_field.value)==parseInt(yyMin))
	{
		ini = mmMin;
	}
	else
	{
		if (parseInt(document.frm.anno_da_field.value)==parseInt(yyMax))
		{
			ende = mmMax;
			if (parseInt(meseselezionato) > parseInt(mmMax))
			{
				meseselezionato = parseInt(mmMax); 
			}
			
		}
	}

	lst = document.frm.mese_da_field_desc.options.length; 
	for (i = lst; i >= 0; i--) 
	{ 
		document.frm.mese_da_field_desc.options[i] = null; 
	} 
	
	x=1;
	for(i=ini; i<=ende;i++) 
	{ 
		
		document.frm.mese_da_field_desc.options[x-1] = new Option(mese[i],i,false,false); 
		x++;
	} 	
	document.frm.mese_da_field_desc.value = meseselezionato;
}

function giorni_a()
{
	mesi_a();
	giornoselezionato=document.frm.giorno_a_field.value;
	lst = document.frm.giorno_a_field.options.length; 
	for (i = lst; i >= 0; i--) 
	{ 
		document.frm.giorno_a_field.options[i] = null; 
	} 

	ini = 1;
	gg = getDaysInMonth(document.frm.mese_a_field_desc.value,document.frm.anno_a_field.options[document.frm.anno_a_field.selectedIndex].text);
	
	if (parseInt(document.frm.anno_a_field.value)==parseInt(yyMax))
	{		
		if (parseInt(document.frm.mese_a_field_desc.value)==parseInt(mmMax))
		{
			gg = ddMax;
		}
	}
	else
	{
		if (parseInt(document.frm.anno_a_field.value)==parseInt(yyMin))
		{
			if (parseInt(document.frm.mese_a_field_desc.value)==parseInt(mmMin))
			{
				ini = ddMin;
			}
		}
	}
	
	x=1;
		
	for(i=ini; i<=gg;i++) 
	{ 
		
		document.frm.giorno_a_field.options[x-1] = new Option(i,i,false,false); 
		x++;
	} 	
	document.frm.giorno_a_field.value = giornoselezionato;
}

function mesi_a()
{
	ini = 1;
	ende = 12;
	if (parseInt(document.frm.anno_a_field.value)==parseInt(yyMax))
	{
		ende = mmMax;
	}
	else
	{
		if (parseInt(document.frm.anno_a_field.value)==parseInt(yyMin))
		{
			ini = mmMin;
		}			
	}

	meseselezionato=document.frm.mese_a_field_desc.value;
	lst = document.frm.mese_a_field_desc.options.length; 
	for (i = lst; i >= 0; i--) 
	{ 
		document.frm.mese_a_field_desc.options[i] = null; 
	} 

	x=1;
	for(i=ini; i<=ende;i++) 
	{ 
		
		document.frm.mese_a_field_desc.options[x-1] = new Option(mese[i],i,false,false); 
		x++;
	} 	
	document.frm.mese_a_field_desc.value = meseselezionato;
}

//passare al grafico i valori delle combo

function getDaysInMonth(month,year)  
{
   var days;

   if (month==1 || month==3 || month==5 || month==7 || month==8 ||
      month==10 || month==12)  days=31;
   else if (month==4 || month==6 || month==9 || month==11) days=30;
   else if (month==2)  {
      if (leapYear (year)==1)  days=29;
      else days=28;
   }
        return (days);
}

function leapYear (Year) 
{
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0))
    {
    	return (1);
    }
    else
    {
    	return (0);
    }
}

function sendFondo(iFlag)
{
	if (iFlag=='1')
	{
		if (bDate == 'True') 
		{
			err = checkDate();
			if(err==false)
			{
				alert("La data di inizio deve essere precedente alla data di fine")
				return false;
			}
		}
	}

	url = 'quotazione_fondi.asp';
	document.frm.action = url;
	document.frm.submit();
	return true;
}

function checkDate()
{	
	var dataIni;
	var dataEnd;

	dataIni = getDataDa();
	dataEnd = getDataA();

	RE = /[^\d^/^\-^\.]/gi
	dataIni = dataIni.replace(RE,"");
	dataEnd = dataEnd.replace(RE,"");
	RE = /[\-\.]/gi
	dataIni = dataIni.replace(RE,"/");
	dataEnd = dataEnd.replace(RE,"/");
	
	d1 = isDate(dataIni);
	d2 = isDate(dataEnd);
	
	if (d1 >= d2) 
	{
		return false;
	}
	return true;
}

function isDate(str) { 
	spz = str.split("/"); 
	dat = new Date(spz[2], spz[1]-1, spz[0]); 
	if	( 
		dat.getFullYear() == parseFloat(spz[2]) &&
		dat.getMonth() == (parseFloat(spz[1])-1) &&
		dat.getDate() == parseFloat(spz[0]) 
		) {
			return dat;
	}
	return false;
}

function popup(id_fondo, data_da, data_a, descrizione_fondo) 
{
	var w = 800;
	var h = 550;
	var l = ((screen.width-w)/2);
	var t = ((screen.height-h)/2);

	window.open("grafico.asp?id_fondo=" + id_fondo +"&data_da=" + data_da + "&data_a=" + data_a  + "&descrizione_fondo=" + descrizione_fondo   ,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +"toolbar=no,directories=no,menubar=no,resizable=no");	
}
