<!--
/* DHTML functions */
var d = document;
var l = (d.layers)?1:0;
var op = navigator.userAgent.toLowerCase().indexOf('opera') != -1;

/* Get Element */
function gE(e,f){
	if(l){
		f=(f)?f:self;
		V=f.document.layers;
		if(V[e])return V[e];
			for(W=0;i<W.length;W++)
				return(gE(e,V[W]));
		}
	if(d.all)return d.all[e];
		return d.getElementById(e);
}


	
function getByTagName(tag) {
		/*---------------------------------------------
		Prima convertiamo in maiuscole il parametro
		tag (la proprietà tagName, che andremo ad
		analizzare è infatti espressa in maiuscole).
		---------------------------------------------*/
		tag = tag.toUpperCase();
		/*---------------------------------------------
		Creiamo poi, un nuovo array relativo all'elemento
		che chiama il metodo, qualora non sia già
		presente
		---------------------------------------------*/
		if(!this["lista"+tag]) {
		this["lista"+tag] = new Array()
		/*---------------------------------------------
		A questo punto scandiamo la collezione all
		alla ricerca di quegli elementi caratterizzati
		dall'avere il tag voluto (quello passato come
		parametro della funzione), e li sistemiamo
		nell'array appena creato.
		---------------------------------------------*/
		for(jtag=0,itag=0; jtag<this.all.length; jtag++) {
		if(this.all[jtag].tagName == tag)
		this["lista"+tag][itag++] = this.all[jtag]
		}
		}
		/*---------------------------------------------
		Restituiamo infine l'array
		---------------------------------------------*/
		return(this["lista"+tag])
}

if(document.all && !document.getElementsByTagName)
document.getElementsByTagName = getByTagName

function RowColor(element){
	var e = gE(element);
	var chk = gE(element.replace('tr','ID_C'));
	
	if (chk != null && chk.checked){
		e.style.color = '#008000';
		}else{
			e.style.color == '#008000' ? e.style.color = '#666666' : e.style.color = '#008000';
		}
}
function Clear(field){
gE(field).value = '';
gE('ID_'+field).value = '';
return false;
}
function AddToList(valore, key, _ID){

var Lista_ID = gE('List_ID');

	var srcData = Lista_ID.value.split(/,/);
	var IsUni = true;
	
	for (var i=0; i < srcData.length; i++){
		if (key == srcData[i]){
		Lista_ID.value = Lista_ID.value.replace(key+"," ,"");
		Lista_ID.value = Lista_ID.value.replace(key ,"");
		IsUni = false;
		}
	}
	
	//if (srcData.length >= <?=$Max?>) IsUni = false;

	if (IsUni != false){
		if (Lista_ID.value.length != 0 && Lista_ID.value.charAt(Lista_ID.value.length - 1) != ","){
			Lista_ID.value += ",";
			}
			Lista_ID.value += key;
		}
}

function setCheckbox(input, chk) {

	for (var i = 0; i <= x.length; i++) {
		var element = 'ID_C-' + i;
		var e = gE(element);
		var row = gE('tr-' + i);
		var valore = gE('Valore-' + i);
		if (e != null && row != null){
		
			if((chk == true && e.checked) || (chk == false && !e.checked)){
				continue;
				}else if (chk == true){
					e.checked = false;
				}else if(chk == false){
					e.checked = true;
					}
					
			setCheckboxColumn(element,valore.value);
			RowColor('tr-' + i);
			
			}// End of if (e != null && row != null)
	}// End of for (i = 0; i <= Item; i++) 
}// End offunction setCheckbox(input, chk)

function setCheckboxColumn(element){
	var e = gE(element);
	if (e != null && !e.disabled){
		var valore = gE(element.replace('ID_C','Valore'));
		AddToList(valore.value, e.value);
	 	!e.checked? e.checked = true : e.checked = false;
	}
}

function setChecked(){
	for(var i = 0; i <= x.length; i++){
		var e = gE('ID_C-' + i);	
		var row = gE('tr-' + i);
		if(e != null && row != null && e.checked) RowColor('tr-' + i);
	}// End of for (i = 0; i <= Item; i++) 
}// End offunction setCheckbox(input, chk)

function openDemo(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  var win = window.open(mypage,myname,settings);
  win.window.focus();
}

function Check_Leng(){
	if(document.Search.search_str.value.length < 3){
		alert('<?=SERCH_MIN_WORD?>."');
			return false;
		}
}

function textCounter(field, countfield) { 
countfield.value = field.value.length; 
}

function minimo(field, minlimit, msg_n){
if (field.value.length < minlimit){
	alert('Il minimo delle battute per il campo ' +msg_n+ ' è di '+minlimit+' battute!!');
	return false;
	}else{
		return true;
		}
}
function ShowHide(Element){
	gE(Element).style.display = gE(Element).style.display=='block' ? 'none':'block';
}
function showHideIcon(currentElement,newElement) {
	gE(currentElement).style.display='none';
	gE(newElement).style.display='block';
}
function Hide(Element){
	gE(Element).style.display = 'none';
}
function Show(Element){
	gE(Element).style.display = 'block';
}
function view_img(Image_Link){
	openDemo('View_Img.php?Image_Link=' +Image_Link ,'view_img',300, 300,'status');
}

// Calcola Prezzo

function Cvalue()
{
  // missing relevant digits
  
  var Costo, Margine, resultV, nVal;
  var frm = document.Insert;
  Costo = frm.Costo.value;
  Margine = frm.Margine.value;
  IVA = frm.IVA.value;
  
  if ( IsNumeric(IVA) == false || IsNumeric(Costo) == false || IsNumeric(Margine) == false) {
    alert("I campi devono essere numerici separati dal punoto per i decimali");
  }
  
  if (Margine < 10) Margine = "1.0" + (Margine*100); else if (Margine >= 10) Margine = "1." + (Margine*100);
  if (IVA < 10) IVA = "1.0" + (IVA*100); else if (IVA >= 10) IVA = "1." + (IVA*100);
  resultV = Costo * Margine * IVA ;

  // 6 relevant digits only, or integer 
  if ( (resultV == parseInt(resultV)) || (resultV > 999999) )
  {
    // mostly integer
    resultV = parseInt( resultV );
  }
  else
  {
    if (resultV > 1)
    {
	resultV = resultV.toString();
	resultV = resultV.substring(0,5);
    } else {
	resultV = resultV.toString();
	resultV = resultV.substring(0,8);
    }
  }

 //document.write(resultV);
  frm.Prezzo.value = "   " + comma(resultV);
}

function comma(num)
{
 var n = Math.floor(num);
 var myNum = num + "";
 var myDec = ""
 
 if (myNum.indexOf('.',0) > -1){
  myDec = myNum.substring(myNum.indexOf('.',0),myNum.length);
 }
 var arr=new Array('0'), i=0; 
 while (n>0) 
   {arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
 arr=arr.reverse();
 
 for ( i in arr) if (i>0) //padding zeros
   while (arr[i].length<3) arr[i]='0'+arr[i];
 return arr.join() + myDec;
}

function cambiaImp(){
            myForm=document.formlogon;
            var imp= myForm.Importo.value;
            var impFormat = puntiInVirgole(imp);
            if(imp==0){
              alert("Inserisci l'importo");
              focus();
              }
            if(imp==impFormat && parseInt(impFormat,10)==impFormat)
              myForm.Importo.value=imp+",00";
            else
              myForm.Importo.value = impFormat;
    }
	
function IsNumeric(strString)
{
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   
   return blnResult;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(Stringa)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = Stringa;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(Stringa)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = Stringa;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext ;
};
function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}
function GiveDec(Hex)
{
   if(Hex == "A")
      Value = 10;
   else
   if(Hex == "B")
      Value = 11;
   else
   if(Hex == "C")
      Value = 12;
   else
   if(Hex == "D")
      Value = 13;
   else
   if(Hex == "E")
      Value = 14;
   else
   if(Hex == "F")
      Value = 15;
   else
      Value = eval(Hex)
   return Value;
}
function GiveHex(Dec)
{
   if(Dec == 10)
      Value = "A";
   else
   if(Dec == 11)
      Value = "B";
   else
   if(Dec == 12)
      Value = "C";
   else
   if(Dec == 13)
      Value = "D";
   else
   if(Dec == 14)
      Value = "E";
   else
   if(Dec == 15)
      Value = "F";
   else
      Value = "" + Dec;
   return Value;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_swapImage() { //v3.0
  var i; var j=0; var x; var a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i; var x; var a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i;
	var j=d.MM_p.length;
	var a=MM_preloadImages.arguments;
	for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve contenere un numero tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+args[i]+' è obbligatorio.\n'; }
  } 
  if (MM_findObj("nuova Password").value != MM_findObj("conferma nuova Password").value) {
  	errors += "- La password è stata scritta due volte in modo diverso.\n";
  }
  if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_popupMsg(msg) { //v1.0
	if (document.MM_returnValue) {
		if (confirm(msg)==true) {
			document.MM_returnValue=true;
		} else {
			document.MM_returnValue=false;
		}
	} 
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('I campi sottoelencati sono incompleti o contengono degli errori:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}

// End -->
