function Ccolor(id,type) {
	tablecolour = '#F6F6F6'
		if (type == 'in') { 
			id.bgColor = tablecolour;
		}
		else {
			id.bgColor = '#FFFFFF';
		}
}

function ColorBg(id,clr) 
{
	id.bgColor = clr;
}
function validate(form) {
	//alert(form);
	var j = 0;
	msg = "";
	for(var i = 0;i < ele.length;i++) {
		if(isBlank(form, ele[i])) {
			invalid(form, ele[i]);
			msg = msg + msgs[i] +"\n";
			j = j +1;
		}
	}
	if(j == 0) {	
		return true;
	}
	else {
		alert(alertMsg + "\n"+ msg);
		return false;
	}
}
function invalid(form, ele) {
	if(!document.layers) {
			document.forms[form].elements[ele].style.backgroundImage = 'url(./images/bcg_input_2.png)';
		}
	return msg;
}

function isBlank(form,ele) {

	str = document.forms[form].elements[ele].value;
	if(str == "") {
		return true;
	}
	else {
		return false;
	}

}

function checkEmail(form,nameEmailField,msg) {
	var email = document.getElementById(nameEmailField);
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
		document.getElementById(nameEmailField).style.borderColor = '#cccccc';
		document.getElementById(nameEmailField).style.backgroundImage = 'url(./images/bcg_input_2.png)';
		
		alert(msg)
		
		return false;		
	}
	else
	{
		document.getElementById(nameEmailField).style.backgroundImage = 'url(./images/bcg_input.png)';
		return true
	}
}

function calcHeight(nameiframe,linkimage,id)
{
  //find the height of the internal page
  var the_height= document.getElementById(nameiframe).contentWindow.document.body.scrollHeight;

  //change the height of the iframe
  document.getElementById(nameiframe).height= the_height;
  
  document.getElementById(linkimage).href = 'html/popup_aziende.html?height=' + the_height + '&width=630&id=' + id + '&modal=true';
}

function deleteRec (msg,url)
{
	var conferma=null;
	conferma = confirm(msg + '?\n');
	if(conferma == false) 
	{
		return false;
	}
	else
	{
		document.location.href = url;
	}
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
        alert('Hai raggiunto il limite di '+limitNum+' caratteri!');
    }
}


function checknumber(form,nameNumberField,msg) {
	var email = document.getElementById(nameNumberField);
	var filter = /([^a-zA-Z])/;
	if (!filter.test(email.value)) {
		document.getElementById(nameNumberField).style.borderColor = '#cccccc';
		document.getElementById(nameNumberField).style.background = '#FF9900';	
		
		alert(msg)
		
		return false;		
	}
	else
	{
		return true
	}
}

function checkVAT(form, pi, cf)
{
   this.disabled = 'true';

   err = 0;
   
	if(cf.length == 16 && !pi)
	{

		var conferma=null;
		conferma=confirm ('NON E\' UNA PARTITA IVA.\n\nSei sicuro che questo è un CLIENTE PRIVATO e non necessita di PARTITA IVA?\n\n - Premi "Ok" per cliente provato\n - premi "Annulla" per inserire la P.IVA');
		if (conferma==false)
		{
			return (false);
		}
		else
		{
			err = 1;
		}

	}   

	if(cf.length > 12 && !pi)
	{
		var validi, i, s, set1, set2, setpari, setdisp;
		if( cf == '' )  return '';
		cf = cf.toUpperCase();
		if( cf.length != 16 )
		{
			err = 4;
		}
		validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		for( i = 0; i < 16; i++ ){
			if( validi.indexOf( cf.charAt(i) ) == -1 )
			{
				err = 4;
			}
		}
		set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
		setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
		s = 0;
		for( i = 1; i <= 13; i += 2 )
			s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
		for( i = 0; i <= 14; i += 2 )
			s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
		if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		{
			err = 4;
		}
	}
	else
	{
		if(cf.length <= 11 && !pi)
		{

			if( cf.length != 11)
			{
				err = 1;
			}

			validi = "0123456789";

			for( i = 0; i < 11; i++ )
			{
				if( validi.indexOf( cf.charAt(i) ) == -1 )
				{
					err = 2;
				}
			}
			s = 0;

			for( i = 0; i <= 9; i += 2 )
			{
				s += cf.charCodeAt(i) - '0'.charCodeAt(0);
			}
			for( i = 1; i <= 9; i += 2 )
			{
				c = 2*( cf.charCodeAt(i) - '0'.charCodeAt(0) );
				if( c > 9 )
				{
					c = c - 9;
				}
				s += c;
			}
			if( ( 10 - s%10 )%10 != cf.charCodeAt(10) - '0'.charCodeAt(0) )
			{
				err = 3;
			}			
		}
	}

	if(err == 3)
	{
		document.forms[form].cf.style.borderColor = '#CCCCCC';
		document.forms[form].cf.style.background = '#FF9900';
		document.forms[form].cf.style.color = '#FFFFFF';

		alert('--------------- Attenzione ---------------\n\nSi prega di inserire una PARTITA IVA valida');
		return false;
 	}
 	
 	if(err == 4)
 	{
		document.forms[form].cf.style.borderColor = '#CCCCCC';
		document.forms[form].cf.style.background = '#FF9900';
		document.forms[form].cf.style.color = '#FFFFFF';

		alert('--------------- Attenzione ---------------\n\nSi prega di inserire un CODICE FISCALE valido');
		return false;
	}

}

function validazione(nomeform)
{

 //imposto la variabile che segnaler l'errore
 var error=0;
 var counter=0;
 //prendo il contenuto html compreso nel mio form
 var form_html=document.forms[nomeform].innerHTML;

 //controllo che il browser supporti questo tipo di funzione
 if(document.getElementsByTagName)
 {
   //predispongo un array con tutti i possibili elementi che conterr la form
   var tipo_dati=new Array('input','textarea','select');

	for(j=0; j < tipo_dati.length; j++)
	{
	var x=document.getElementsByTagName(tipo_dati[j]);

		for(i=0; i < x.length; i++)
		{
		  var valueCampo=x.item(i).value;
		  
		  var obbligatorio=x.item(i).obbligatorio;		 

			if(valueCampo != '' && obbligatorio == 1)
			{             
				
				
				document.forms[nomeform].submit();

			}
			else
			{
				error = error+1;
			}
			
		counter = counter+1;		

		}//for i

	}//for j
	

	if(error == counter)
	{
		alert('tutti i campi sono vuoti');
	}
     


  }
 else
  {
    alert('Il tuo browser non supporta questo tipo di funzione');
    return false;
  }
  
  
	

}//END



function popUp(page, width, height) 
{
	var newWindow = window.open(page,"GenericPage","height=" + height + ",width=" + width + ",toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}

