
function resizeMe(){
var myWidth = 0;
var myHeight = 0;
if( typeof( window.innerWidth ) == "number" ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in ’standards compliant mode’
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
}

//alert(document.getElementById('mainContent').offsetHeight);
//document.getElementById('mainContent').style.height = (document.getElementById('mainContent').offsetHeight) + "px";


function popup(url){
		window.open(url, '', 'top=2, left=400, width=400, height=300, toolbar=no, location=no ,status=no, menubar=yes, scrollbars=yes, resizable=yes');
}

function ahah(url,target) {
   try {
	   document.getElementById(target).innerHTML = 'Loading...';
	   if (window.XMLHttpRequest) {
		   req = new XMLHttpRequest();
		   req.onreadystatechange = function() {ahahDone(target);};
		   req.open("GET", url, true);
		   req.send(null);
	   } else if (window.ActiveXObject) {
		   req = new ActiveXObject("Microsoft.XMLHTTP");
		   if (req) {
			   req.onreadystatechange = function() {ahahDone(target);};
			   req.open("GET", url, true);
			   req.send();
		   }
	   }
	}catch(z){ 
   		//alert(z.description.toString())
	}
} 

function ahahDone(target) {
   if (req.readyState == 4) {
	   if (req.status == 200 || req.status == 304) {
		   results = req.responseText;
		   document.getElementById(target).innerHTML = results;
	   } else {
		  // document.getElementById(target).innerHTML = "Attenzione si č verificato un'errore nell'elaborazione dei dati"; //+escape(req.statusText);
	   }
   }
}

function textCounter2(field, maxlimit) {
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
}

function inviaCommento(id, logged){
		
		tinyMCE.triggerSave();
	    var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()	;
		var strTime = hours+ "."+minutes+"."+seconds;
		var testo = escape(document.modulo.testoc.value);
		var email = escape(document.modulo.email.value);
		var nome = escape(document.modulo.nome.value);
		var stage = escape(document.modulo.stage.value);
		var code = escape(document.modulo.code.value);
		var queryString = "?id="+id+"&testo="+testo+"&email="+email+"&nome="+nome+"&i="+strTime+"&stage="+stage+"&logged="+logged+"&code="+code;
		ahah('salva_commenti.php'+queryString,'commenti');
}



function check_rispostaSondaggio(i){
		var form = document.forms["modulo_"+i];
		var voce="";
		for (var j=0; j<form.answer.length; j++) {
  			if (form.answer[j].checked) {
   				voce = form.answer[j].value;
    			break;
  			}
		}
		if(voce == ""){
			alert("Scegli una risposta");
			return false;
		}
		if(form.code.value == ""){
			alert("Scrivi il codice di sicurezza");
			return false;
		}
}

function rispostaSondaggio(id, i){
		var form = document.forms["modulo_"+i];
		var voce="";
		for (var j=0; j<form.answer.length; j++) {
  			if (form.answer[j].checked) {
   				voce = form.answer[j].value;
    			break;
  			}
		}
		if(voce == ""){
			alert("Scegli una risposta");
			return;
		}
		var queryString = "?stage=1&sondaggio="+id+"&voce="+voce;
		ahah('risposta_sondaggio.php'+queryString,'target_'+i);
}


function mailing(){

	if(document.modulo_email.email.value==""){
		alert("Inserisci l'email");
		document.modulo_email.email.focus();
		return false;
	}
	EmailAddr = document.modulo_email.email.value;
  	 Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  		 if (Filtro.test(EmailAddr)){
	   	document.modulo_email.email.focus();
		}
		else{
    	  alert("Indirizzo e-mail non valido");
    	  document.modulo_email.email.focus();
    	  return false;
     	}	
}
