// Funzioni lavorazione menu_richiesta.js

var tpRequestSubDisabled = '<img src="Images/icona_invia_richiesta_sbiadita.jpg" width="133" height="20">';

var FormRequest          = 'FormRichiesta';
var aMD5AuthField		 = 'md5_Request';		
var aMD5RawField		 = 'md5_Text';		

function RequestSubmit()
{
var CampiOk = true;
var Campi;
var Valore;
var MailErr = false;
var MD5Text = '';
var MD5Value;
	
	document.getElementById( aMD5AuthField ).value = '';  // Azzero il valore di MD5

	Campi = document.getElementById( FormRequest ).elements;
	
	for( xx=0; xx<Campi.length; xx++ )
	{
		Valore = new String( Campi[xx].value );
		Valore = Valore.replace(/^\s+|\s+$/g,'');
		if( Campi[xx].className == 'CssRequestFieldInputNotNull'
			&& Valore == '' )
				CampiOk = false;
				
		if( CampiOk )
		{
			if( Campi[xx].name == 'pi_CON_Email' )
				MailErr = !MailCheck( Valore );

			if( Campi[xx].name.substr( 0, 4 ) != 'md5_' )
				MD5Text = MD5Text + Campi[xx].name + RequestFieldNormalize( Valore );
		}
	}

	if( MailErr )
		alert( "L'indirizzo E-mail inserito non e' corretto.\r\n\r\nRicontrollare l'indirizzo E-mail!" );
	else if( !CampiOk )
		alert( 'Non sono state ancora inserite alcune informazioni obbligatorie.\r\n\r\nInserire le informazioni in tutte le righe scure.' );
	else
	{
		MD5Value = hex_md5( RequestMD5Normalize( '' + GetCookie('Muratastore_Session') + MD5Text ) );
		document.getElementById( aMD5AuthField ).value = MD5Value;
		document.getElementById( aMD5RawField  ).value = RequestMD5Normalize( '' + GetCookie('Muratastore_Session') + MD5Text );
		document.getElementById('DIV_RequestSubmit').innerHTML = tpRequestSubDisabled;
		document.getElementById( FormRequest ).submit();
	}
}

function RequestFieldNormalize( AText )
{
var Normalized = "";

	for( yy=0; yy<AText.length; yy++ )
	{
		if( AText.charAt(yy) != '\r' && AText.charAt(yy) != '\n' )
			Normalized = Normalized + AText.charAt(yy);
	}
	
	Normalized = Normalized.replace(/^\s+|\s+$/g,'');
	
	return( Normalized );
}

function RequestMD5Normalize( AText )
{
var Dictionary = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
var Normalized = "";

	for( xx=0; xx<AText.length; xx++ )
	{
		if( Dictionary.lastIndexOf( AText.charAt(xx) ) == -1 )
			CurCar = '' + (xx % 10);
		else
			CurCar = '' + AText.charAt(xx);
		Normalized = Normalized + CurCar;
	}
	return( Normalized );
}

