function homepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.positanonews.it');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
    alert("Questa azione č disabilitata in questo browser.\nSe la si vuole abilitare inserire about:config nell'indirizzo, e cambiare il valore di signed.applets.codebase_principal_support a true");  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://www.asp.net/130.aspx');
 }
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

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 = '<br /><br /><br /><br /><center><span style="font-size:20px;">Caricamento...</span></center>';
	   document.getElementById(target).style.height = '170px';
	   
	   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;		   
  		   document.getElementById(target).style.height = '100%';
	   } else {
		   document.getElementById(target).innerHTML = "Attenzione si č verificato un'errore nell'elaborazione dei dati"; //+escape(req.statusText);
		   myOpacity.toggle();
	   }
   }
}

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;
     	}	
}