/*
START - CONTROLLA LUNGHEZZA PASSWORD
*/
function checkPassLength(curPass, curControl)
{
    if (curPass.length < 8 && curPass != '')
    {
        alert("ATTENZIONE!\n\nLa lunghezza minima consentita per la password e\' di 8 caratteri!");
        curControl.value = '';
        curControl.focus();
    }
}

/*
START - CONTROLLI SULLE DATE FORM MESSA A REDDITO
*/
function checkDDDate(curDDDate)
{
    if (curDDDate != '')
    {
        var myDDDate=new Date();
        var today = new Date()

        var myDDDateArray = curDDDate.split('/');

        myDDDate.setFullYear(parseInt(myDDDateArray[2]), parseInt(myDDDateArray[1]) - 1, parseInt(myDDDateArray[0]));

        if (myDDDate>today)
        {
          alert("ATTENZIONE!\n\nLa data di decorrenza deve essere antecedente o uguale alla data di registrazione decorrenza!");
          document.forms[0].ctl00$childContentPlaceHolder$DD.value = '';
          document.forms[0].ctl00$childContentPlaceHolder$DD.focus();
        }
        else
        {
          //data OK
        }
    }
}

function checkDCPDate(curDCPDate, curDDDate)
{
    if (curDCPDate != '' && curDDDate != '')
    {
        var myDCPDate =new Date();
        var myDDDate = new Date()

        var myDCPDateArray = curDCPDate.split('/');
        var myDDDateArray = curDDDate.split('/');

        myDCPDate.setFullYear(parseInt(myDCPDateArray[2]), parseInt(myDCPDateArray[1]) - 1, parseInt(myDCPDateArray[0]));
        myDDDate.setFullYear(parseInt(myDDDateArray[2]), parseInt(myDDDateArray[1]) - 1, parseInt(myDDDateArray[0]));

        if (myDCPDate>myDDDate)
        {
          //data OK
        }
        else
        {
          alert("ATTENZIONE!\n\nLa data del primo canone periodico deve essere successiva alla data di decorrenza!");
          document.forms[0].ctl00$childContentPlaceHolder$DCP.value = '';
          document.forms[0].ctl00$childContentPlaceHolder$DCP.focus();
        }
    }
}

function checkDEDate(curDEDate, curDCPDate)
{
    if (curDEDate != '' && curDCPDate != '')
    {
        var myDEDate = new Date()
        var myDCPDate =new Date();

        var myDEDateArray = curDEDate.split('/');
        var myDCPDateArray = curDCPDate.split('/');

        myDEDate.setFullYear(parseInt(myDEDateArray[2]), parseInt(myDEDateArray[1]) - 1, parseInt(myDEDateArray[0]));
        myDCPDate.setFullYear(parseInt(myDCPDateArray[2]), parseInt(myDCPDateArray[1]) - 1, parseInt(myDCPDateArray[0]));

        if (myDEDate>myDCPDate)
        {
          //data OK
        }
        else
        {
          alert("ATTENZIONE!\n\nLa data estinzione deve essere successiva alla data del primo canone periodico!");
          document.forms[0].ctl00$childContentPlaceHolder$DE.value = '';
          document.forms[0].ctl00$childContentPlaceHolder$DE.focus();
        }
    }
}
/*
END - CONTROLLI SULLE DATE FORM MESSA A REDDITO
*/

//formatto gli importi
//controlla valmin e valmax
function checkMinMaxFreeRata(curValMax, curValMin, curEditValControl) {
    if (curEditValControl.value != '')
    {
	    if ((Math.min(curEditValControl.value.replace(',','.'), curValMin.replace(',','.')) == curEditValControl.value.replace(',','.')) && curEditValControl.value != curValMin)
	    {
		    alert('ATTENZIONE!\n\n<GUADAGNA DI PIU\'> valore troppo basso.');
		    curEditValControl.value = '';
            document.forms[0].ctl00$childContentPlaceHolder$freeRata.focus();
	        return false;
	    }
	    else if ((Math.max(curEditValControl.value.replace(',','.'), curValMax.replace(',','.')) == curEditValControl.value.replace(',','.')) && curEditValControl.value != curValMax)
	    {
		    alert('ATTENZIONE!\n\n<GUADAGNA DI PIU\'> valore troppo alto.');
		    curEditValControl.value = '';
            document.forms[0].ctl00$childContentPlaceHolder$freeRata.focus();
	        return false;
	    }
	    else
	    {
	        return true;
	    }
	}
	else
	{
        return true;
	}
}

function checkFreeRata()
{
    if (document.forms[0].ctl00$childContentPlaceHolder$freeRata.value == '')
    {
        alert('ATTENZIONE!\n\nSpecificare l\'importo della rata!');
        document.forms[0].ctl00$childContentPlaceHolder$freeRata.focus();
        return false;
    }
}

function applayFreeRata()
{
    if (document.forms[0].ctl00$childContentPlaceHolder$freeRata.value != '')
    {
		var answer = confirm("ATTENZIONE!\n\nE\' stato indicato un canone diverso da quello proposto dal sitema!\nConfermare con il tasto OK per procedere ignorando tale dato.\nAnnullare per interrompere l\'operazione ed effettuare il ricalcolo\ndegli importi selezionando il tasto <GUADAGNA DI PIU\'>.");
		if (answer)
		{
            document.forms[0].ctl00$childContentPlaceHolder$freeRata.value = '';
            return true;
        } else {
            return false;
        }
    }
}

function removeFrameIfExist()
{
    var myFullLocation_array = document.location.href.split('/');
    var myLocation = myFullLocation_array[myFullLocation_array.length - 1];
    if (self.parent.frames.length != 0 && myLocation == 'error.aspx')
    {
        self.parent.location = document.location.href;
    }
}

function checkContraCodeGrenke (curStr, myEvent){

	var key = window.event ? myEvent.keyCode : myEvent.which;
	
	if (key == 8 || key == 0)
	{
	    return true;
	}
	else
	{
	    if (key > 47 && key < 123 && key != 58 && key != 59 && key != 60 && key != 61 && key != 62 && key != 63 && key != 64 && key != 91 && key != 92 && key != 93 && key != 94 && key != 95 && key != 96) {
		    //lettere
		    if (key > 64 && key < 123 && (curStr.length != 0 && curStr.length != 1 && curStr.length != 2)) {
			    return false;
		    }
		    if (key > 47 && key < 58 && (curStr.length != 3 && curStr.length != 4 && curStr.length != 5 && curStr.length != 6 && curStr.length != 7 && curStr.length != 8 && curStr.length != 9 )) {
			    return false;
		    }
	    } else {
		    return false;
	    }
    }
}

