function Ccolor(id,type) {
	tablecolour = '#F6F6F6'
		if (type == 'in') { 
			id.bgColor = tablecolour;
		}
		else {
			id.bgColor = '#FFFFFF';
		}
}

function ColorBg(id,clr) 
{
	id.bgColor = clr;
}

function validateInline(form, spanid) {
	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 {
		document.getElementById(spanid).innerHTML = "<br><span style='color:#AA0000'><b>" + alertMsg + "</b><br>"+ msg + "</span><br><br>";
		return false;
	}
}


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\r";
			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_attenzione.jpg)';
		}
	return msg;
}

function isBlank(form,ele) {
	str = document.forms[form].elements[ele].value;
	if(str == "") {
		return true;
	}
	else {
		return false;
	}

}

function openPrintable(section, id, lang) 
{
	var newWindow = window.open("./html/printable.html?nid=" + id + "&lang=" + lang,"PrintArtcle","height=500,width=550,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}
function openWin(what, lang) 
{
	var newWindow = window.open("./downloads/curriculum.html?p=" + what + "&lang=" + lang,"Curr","height=650,width=600,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}
function popUp(page, width, height, lang) 
{
	var newWindow = window.open(page,"GenericPage","height=" + height + ",width=" + width + ",toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
}


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)) {			
		alert(msg);		
		return false;		
	}
	else
	{
		return true
	}
}

function styleAlert(message,timeout)
{
	$.blockUI({
	theme:false,
	message:message,
	timeout:timeout
	});
}

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 deleteRec (msg,url)
{
	var conferma=null;
	conferma = confirm(msg + '?\n');
	if(conferma == false) 
	{
		return false;
	}
	else
	{
		document.location.href = url;
	}
}




