// JavaScript Document

// funzione per riempire gli input con Int 

var v = new Array();
v["username"] = 'Utente'; // [nome del campo] = 'descrizione che volete compaia all'interno del campo'
v["password"] = 'Password';
v["testo_rtf"] = 'Scrivi qui il tuo messaggio č necessario essere registrato';
//v["SearchedTxt"] = '...';

function InputDel(campo) {
	if (campo.value.search(v[campo.name])== 0 ) {
		campo.value= '';
	}	
}

function InputFill(campo) {
	if (campo.value=='') {
		campo.value= v[campo.name];
	}	
}

// Funzione per controllare l'invio della pagina

function ControlloInvio(theForm) {
	if (theForm.mail.value == "" || theForm.mail.value == "email*") {
    	alert("Per favore inserire la mail del destinatario, grazie.");
    	theForm.mail.focus();
    	return (false);
	}
	if (theForm.mittente.value == "" || theForm.mittente.value == "mittente*") {
    	alert("Per favore inserire il nome del mittente, grazie.");
    	theForm.mittente.focus();
    	return (false);
	}

}


// Funzione per controllare il numero di caratteri nel testo della mail

function CheckChars1(obj) {
  l_max = 250;
  l = obj.value.length;
  obj.form.total_chars1.value = l;
  if (l <= l_max) {
    return true;
  } else {
    window.alert('Attenzione: il testo supera i '+l_max+' caratteri consentiti');
    obj.value=obj.value.substring(0,l_max);
    obj.form.total_chars1.value = l_max;
    return false;
  }
}

function CheckChars2(obj) {
  l_max = 3000;
  l = obj.value.length;
  document.form2.total_chars2.value = l;
  if (l <= l_max) {
    return true;
  } else {
    window.alert('Attenzione: il testo supera i '+l_max+' caratteri consentiti');
    obj.value=obj.value.substring(0,l_max);
    document.form2.total_chars2.value = l_max;
    return false;
  }
}

function CheckChars3(obj) {
  l_max = 400;
  l = obj.value.length;
  document.form2.total_chars2.value = l;
  if (l <= l_max) {
    return true;
  } else {
    window.alert('Attenzione: il testo supera i '+l_max+' caratteri consentiti');
    obj.value=obj.value.substring(0,l_max);
    document.form2.total_chars2.value = l_max;
    return false;
  }
}

function CheckChars4(obj) {
  l_max = 1000;
  l = obj.value.length;
  document.form2.total_chars2.value = l;
  if (l <= l_max) {
    return true;
  } else {
    window.alert('Attenzione: il testo supera i '+l_max+' caratteri consentiti');
    obj.value=obj.value.substring(0,l_max);
    document.form2.total_chars2.value = l_max;
    return false;
  }
}

// funzioni per generare i pdf 

function PopUp(page,w,h,t,s,m) 
	{
	popwidth = w;
	popheight = h;
    if (!t) {t = 'no'};
	if (!s) {s = 'no'};
	if (!m) {m = 'no'};
	OpenWin = this.open(page, "prn", "toolbar=" + t + ", menubar=" + m +", location=no, scrollbars=" + s + ", resizable=no, width="+popwidth+", height="+popheight+", left=" + Math.floor((screen.width - popwidth) / 2) + ", top=" + Math.floor((screen.height - popheight) / 2));
}

function URLEncode(s)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = s;
	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(s)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = s;
   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 PopCitta(page) {
	if (document.form1.paese.selectedIndex != 113) {
    	alert("Se si č scelto un paese diverso dall'Italia non č necessario\ncompilare i campi Indirizzo, CAP, Cittā e provincia. Grazie");
		document.form1.indirizzo.value = " ";
		document.form1.cap.value = " ";
		document.form1.citta.value = " ";	
		document.form1.provincia.value = " ";			
		return(false);
  }
  s = window.document.form1.cap.value;
  c = window.document.form1.citta.value;
  if (s.length < 2) {
    window.alert("Immettere almeno due cifre del cap, grazie");
    return false;
  }
  Dialog(page, function (param) {
                 a = new Array;
                 if (param) {
                   a = param[0].split(/\|/);
                   window.document.form1.citta.value = param[1];
                   window.document.form1.provincia.value = a[1];
                   window.document.form1.cap.value = a[2];
                   //window.document.form1.res.value = 1;
                 }
               },
         null);
  if (window.document.form1.citta.value) {return true} else {return false}
};

function PopupPic(sPicURL) {
 popwidth = 250;
 popheight = 400;
 window.open( "/popup/popup.html?"+sPicURL, "", "left=" + Math.floor((screen.width - popwidth) / 2) + ",top=" + Math.floor((screen.height - popheight) / 2) + "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width="+popwidth+",height="+popheight);
}

function PopUpMail(page) {
popwidth = 440;
popheight = 410;
OpenWin = this.open(page, "PopWin2", "toolbar=no, menubar=no, location=no, scrollbars=no, resizable=no, width="+popwidth+", height="+popheight+", left=" + Math.floor((screen.width - popwidth) / 2) + ", top=" + Math.floor((screen.height - popheight) / 2));
};

 var ShowVideo;
 Ext.onReady(function(id){
	Ext.QuickTips.init();
    var iconPath = '/extjs/resources/images/silk/icons/';
    ShowVideo = function (id, title, width, height, type) {
      
      if(!type){type='flv'} 
      if(!width){width=640} 
      if(!height){height=480}
      var dlg = new Ext.Window({
        title: title,
        width: width,
        height: height,
        modal: true,
        resizable: false,
        maximizable: false,
        closeAction: "close",
        hideMode: 'offset',
        autoScroll: false,
        method: 'POST',
        id: 'videoDlg',
        bodyStyle: 'background-color: #000000',
		html:'<div id="_Video"></div>'
      });
      dlg.show();
      var mask = Ext.get(dlg.mask.id);
      mask.setStyle('width', '100%');
		  var container = Ext.getCmp('videoDlg').getEl();
		  var w = container.getWidth()-14;
		  var h = container.getHeight()-33;
		  var so = new SWFObject('/swf/mediaplayer.swf','Video',w,h,'8');
		  so.addParam('allowscriptaccess','always');
		  so.addParam('allowfullscreen','true');
		  so.addParam('wmode', 'transparent');
		  so.addVariable('autostart', 'true');
		  so.addVariable('file', URLEncode('http://flash.callipigia.com/callipigia/italianascosta.eu/'+ id + '.'+type));
		  so.addVariable('skin','/swf/modieus.swf');
		  so.write('_Video');    }
  });


    var myMask;
	Ext.onReady(function(){
    myMask = new Ext.LoadMask(Ext.getBody(), { msgCls: 'x-mask-loading', msg:"Caricamento file in corso, attendere..."});
   });

