	var win = null;		
	
	function openPag(theURL, myWidth, myHeight) {
		
		winName = "SickGirlPupUp";
		//myWidth = "560";
		//myHeight = "560";
		//theURL = 'photosets_slide.php?f=' + foto + '&n=' + galleria;
		features = "toolbar=0,menubar=0,scrollbars=1,resizable=0,status=0,location=0,directories=0,copyhistory=0"
		isCenter = "true";			
		
		if(window.screen)if(isCenter)if(isCenter=="true"){
	    var myLeft = (screen.width-myWidth)/2;
	    var myTop = (screen.height-myHeight)/2;
	    features+=(features!='')?',':'';
	    features+=',left='+myLeft+',top='+myTop;
	  }		  		
		
		win = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	
		if(win.window.focus){win.window.focus();}
	
  	}	
	
	function closePag() {
	  if (win && win.open && !win.closed) win.close();
	} 

/****************************************************************/

	var win = null;		
	
	function openDep(foto, galleria) {
		
		winName = "SickgirlPhotosets";
		myWidth = "560";
		myHeight = "560";
		theURL = 'photosets_slide.php?f=' + foto + '&n=' + galleria;
		features = "toolbar=0,menubar=0,scrollbars=0,resizable=0,status=0,location=0,directories=0,copyhistory=0"
		isCenter = "true";			
		
		if(window.screen)if(isCenter)if(isCenter=="true"){
	    var myLeft = (screen.width-myWidth)/2;
	    var myTop = (screen.height-myHeight)/2;
	    features+=(features!='')?',':'';
	    features+=',left='+myLeft+',top='+myTop;
	  }		  		
		
		win = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	
		if(win.window.focus){win.window.focus();}
	
  	}	
	
	function closeDep() {
	  if (win && win.open && !win.closed) win.close();
	} 


/******************************************************************/

	var win = null;		
	
	function openAlbum(foto, album) {
		
		winName = "SickgirlAlbum";
		myWidth = "560";
		myHeight = "560";
		theURL = 'album_slide.php?f=' + foto + '&n=' + album;
		features = "toolbar=0,menubar=0,scrollbars=0,resizable=0,status=0,location=0,directories=0,copyhistory=0"
		isCenter = "true";			
		
		if(window.screen)if(isCenter)if(isCenter=="true"){
	    var myLeft = (screen.width-myWidth)/2;
	    var myTop = (screen.height-myHeight)/2;
	    features+=(features!='')?',':'';
	    features+=',left='+myLeft+',top='+myTop;
	  }		  		
		
		win = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	
		if(win.window.focus){win.window.focus();}
	
  	}	
	
	function closeDep() {
	  if (win && win.open && !win.closed) win.close();
	} 


/******************************************************************/
function divOnOff(objid,vis)
{
	var obj;
	try {
		if(objid.parentNode){
			//it's an object. we needn't do anything
			obj = objid;
		} else {
			//it's not an object
			obj = document.getElementById(objid);
		}
	} catch(e) {
		//it's not an object and the browser errors on undefined properties
		obj = document.getElementById(objid);
	}
	if(vis){		
		if (obj.style.visibility == 'hidden') {
			obj.style.visibility = 'visible';
		} else {
			obj.style.visibility = 'hidden';
		}
	} else {
		if (obj.style.display == 'none') {
			obj.style.display = 'block';
		} else {
			obj.style.display = 'none';
		}
	}
	return true;
}

	function cta() {
		var el = document.getElementsByTagName('textarea');
		for (var i = 0; i < el.length; i++) {
			el[i].style.display='none';
		}		
	}

	function swaptexarea(nome) {
		
		cta();
		document.getElementById(nome).style.display = 'block';
		document.getElementById(nome).focus();
		
	}
	
	function checkmodprofilo(obj) {
		
		var er = 0;
		var erstr = '';
	
		gg=obj.data_gg.value;
	   mm=obj.data_mm.value;
	   aa=obj.data_aa.value;
		
		if(gg != '' || mm != '' || aa != '') {
		   strdata=gg+"/"+mm+"/"+aa;
		   data = new Date(aa,mm-1,gg);
		   daa=data.getFullYear().toString();
		   dmm=(data.getMonth()+1).toString();
		      //dmm=dmm.length==1?"0"+dmm:dmm
		   dgg=data.getDate().toString();
		      //dgg=dgg.length==1?"0"+dgg:dgg
		   dddata=dgg+"/"+dmm+"/"+daa
		   
		  if(dddata!=strdata)
	      {
	      erstr = erstr + "Verificare la data inserita\n";
	      er = 1;
	      alert(erstr);
			return false;	
	      }
		}
		
		// modifica password
		pwNew =obj.pass_new.value;
		pwRep =obj.pass_rep.value;
		if(pwNew.length != 0) {
			if(pwNew.length > 5) {			
				if(pwRep == '') {
					alert('Inserisci nuovamente la password per conferma.');
					obj.pass_rep.focus();
					return false;			
				}
				else if(pwRep != pwNew) {
					alert('Le due password non corrispondono.');
					obj.pass_rep.focus();
					return false;			
				}
				alert('Hai cambiato la tua password.\nDevi effettuare nuovamente il login con i tuoi nuovi dati.');
			}
			else {
				alert('La nuova password deve avere minimo 6 caratteri');
				obj.pass_new.focus();
				return false;		
			}
		}		
   }


/***************** AGGIUNGE TOGLIE CAMPO ********************/
var arrInput = new Array(0);
  var arrInputValue = new Array(0);

function addInput() {
  //arrInput.push(createInput(arrInput.length));
  arrInput.push(arrInput.length);
  //arrInputValue.push(arrInputValue.length);
  arrInputValue.push("");
  display();
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value) {
  return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}
/**************************************************************/


  /////////////////////////
 // HOME PHOTOSET PAGER // 
/////////////////////////

function writeps(texte) {
	document.getElementById('pscont').innerHTML = texte;
}

function getps(pag) {
	if(pag != '') {
		if(texte = psfile('home_photosets_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writeps('ERRORE');
			else
				writeps(texte);
		}
	}
}

function psfile(fichier) {
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
  
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	
	if(xhr_object.readyState == 4) 
		return(xhr_object.responseText);
	else 
		return(false);
}

  ///////////////////////////
 // HOME ins utenti PAGER // 
///////////////////////////

function writeiut(texte) {
	document.getElementById('iutcont').innerHTML = texte;
}

function getiut(pag) {
	if(pag != '') {
		if(texte = psfile('home_blogs_utenti_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writeiut('ERRORE');
			else
				writeiut(texte);
		}
	}
}

  ///////////////////////////
 // HOME SG PAGER         // 
///////////////////////////

function writeisg(texte) {
	document.getElementById('isgcont').innerHTML = texte;
}

function getisg(pag) {
	if(pag != '') {
		if(texte = psfile('home_blogs_sg_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writeisg('ERRORE');
			else
				writeisg(texte);
		}
	}
}

  /////////////////////////////
 // HOME NUOVI UTENTI PAGER // 
/////////////////////////////

function writenut(texte) {
	document.getElementById('nutcont').innerHTML = texte;
}

function getnut(pag) {
	if(pag != '') {
		if(texte = psfile('home_nuovi_utenti_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writenut('ERRORE');
			else
				writenut(texte);
		}
	}
}

  /////////////////////
 // HOME LOGORROICO // 
/////////////////////

function writelut(texte) {
	document.getElementById('lutcont').innerHTML = texte;
}

function getlut(pag) {
	if(pag != '') {
		if(texte = psfile('home_logorroico_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writelut('ERRORE');
			else
				writelut(texte);
		}
	}
}
////////////////////////


  ///////////////
 // HOME NEWS // 
///////////////

function writenews(texte) {
	document.getElementById('newscont').innerHTML = texte;
}

function getnews(pag) {
	if(pag != '') {
		if(texte = psfile('home_news_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writenews('ERRORE');
			else
				writenews(texte);
		}
	}
}
////////////////////////

  //////////////////////
 // UTENTE NOTIFICHE // 
//////////////////////

function writenot(texte) {
	document.getElementById('notcont').innerHTML = texte;
}

function getnot(pag) {
	if(pag != '') {
		if(texte = psfile('utente_home_notifiche_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writenot('ERRORE');
			else
				writenot(texte);
		}
	}
}
////////////////////////

  /////////////////////
 // HOME PHOTOSETS2 // 
/////////////////////

function writeph2(texte) {
	document.getElementById('ph2cont').innerHTML = texte;
}

function getph2(pag) {
	if(pag != '') {
		if(texte = psfile('home_photosets2_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writeph2('ERRORE');
			else
				writeph2(texte);
		}
	}
}
////////////////////////

  /////////////////
 // HOME ALBUM  // 
/////////////////

function writeal(texte) {
	document.getElementById('alcont').innerHTML = texte;
}

function getal(pag) {
	if(pag != '') {
		if(texte = psfile('home_album_lib.php?p='+escape(pag))) {
			if(texte == 2)
				writeph2('ERRORE');
			else
				writeal(texte);
		}
	}
}
////////////////////////

//////// AJAX ////////////////
/* Crea un'istanza dell'oggetto XmlHttpRequest
 */
var ajax;
function setAjax() {
	//if(window.ActiveXObject)
	ajax = new XMLHttpRequest();
}


function elemento(id_elemento) {
	var elemento;
	if(document.getElementById)
		elemento = document.getElementById(id_elemento);
	else
		elemento = document.all[id_elemento];
	return elemento;
};

/* cerca utenti
 */

function cercaUtenti(nome, ancheProfilo) {
	//cunn = document.getElementById("cunn");
	//alert("nl: " + nome.length);
	if(nome.length > 2) {
		setAjax();
		ajax.onreadystatechange = handleStateChange;
		ajax.open("GET", "utenti_lib.php?cerca=" + nome, true);
		//ajax.open("GET", "aaa.xml", true);
		ajax.send(null);
	} else {
		var elemento = document.getElementById("cercautenti_risposta");
		clearData(elemento);
	}
}

function handleStateChange() {
	if(ajax.readyState == 4) {
		if(ajax.status == 200) {
			var elemento = document.getElementById("cercautenti_risposta");
			clearData(elemento);
			
			var xmldoc = ajax.responseXML;
			var utenti = xmldoc.getElementsByTagName("utente");
			
			if(utenti.length == 0) {
				var cdiv = document.createElement("div");
				cdiv.setAttribute("style", "color:red; font-weight:bold; font-size:120%; padding:4px; margin:4px;");
				cdiv.style.cssText = "color:red; font-weight:bold; font-size:120%; padding:4px; margin:4px;";
				var txt = document.createTextNode("La ricerca non ha prodotto nessun risultato.");
				cdiv.appendChild(txt);
				elemento.appendChild(cdiv);
			}
			else {
				for(var i = 0; i < utenti.length; i++) {
					var utente = utenti[i];
					var nomi = utente.getElementsByTagName("nome")[0];
					var nome = nomi.childNodes[0].nodeValue;
					var sesso = utente.getElementsByTagName("sesso")[0].childNodes[0].nodeValue;
					var reg = utente.getElementsByTagName("attivita")[0].childNodes[0].nodeValue;
					var foto = utente.getElementsByTagName("foto")[0].childNodes[0].nodeValue;
					
					//var strnome = '<a href="utenti.php">' + nome + '</a>';
					var cdiv = creaDiv(nome, sesso, reg, foto);
					elemento.appendChild(cdiv);
				}
			}
		}
	}
}

function creaDiv(nome, sesso, reg, foto) {
	var cdiv = document.createElement("div");
	cdiv.setAttribute("style", "width:160px; height:30px; float:left; padding:4px; margin:4px; background:#FFFFFF; border:1px solid #d0d0d0;");
	cdiv.style.cssText = "width:160px; height:30px; float:left; padding:4px; margin:4px; background:#FFFFFF; border:1px solid #d0d0d0;";

	var im = document.createElement("img");
	im.setAttribute("src", foto);
	im.setAttribute("style", "float:left; width:30px; height:30px; vertical-align:top;");
	im.style.cssText = "float:left; width:30px; height:30px; vertical-align:top;";

	var ddiv = document.createElement("div");
	ddiv.setAttribute("style", "margin-left:35px;");
	ddiv.style.cssText = "margin-left:35px;";
	
	var ca = document.createElement("a");
	ca.setAttribute("href", "utente.php?nome=" + nome);
	ca.setAttribute("style", "display:block;");
	ca.style.cssText = "display:block;";
	
	var txtd = document.createTextNode("(" + sesso + ") " + nome);
	var br = document.createElement("br");
	var txte = document.createTextNode("Att: " + reg); 
	
	ca.appendChild(txtd);
	ca.appendChild(br);
	ca.appendChild(txte);
	ddiv.appendChild(ca);	
	
	cdiv.appendChild(im);
	cdiv.appendChild(ddiv);
	
	return cdiv
}

function clearData(elemento) {
	var ind = elemento.childNodes.length;
	for(var i = ind - 1; i >= 0; i--) {
		elemento.removeChild(elemento.childNodes[i]);	
	}
}


/***************** BLOG ************************/
function fade( elId ) {
	$( elId ).animate({ backgroundColor : "yellow" }, { queue:true, duration:1000 });
	$( elId ).animate({ backgroundColor : "transparent" }, { queue:true, duration:1000 });
}

function blogCmtPub( cmtId ) {
	/** id="cmt31219" **/
	//fade("#cmt" + cmtId);
	//var cosa = "#hdBlogCmt" + cmtId;
	//$("cmt31222").animate({ "color": "#ff0000" }, 500);
	
	//utente_blog_lib.php?cmtpubl=<?php echo $cmt['id'] ?>
	/*****/
	$.get("utente_blog_lib.php", { cmtpubl: cmtId , ajax: "true" },
	function(){
		$("#lnkBlogCmtPub" + cmtId).animate({"opacity": '0'}, 'slow');
	});
	/*********/

}

function photosetCmtPub( cmtId ) {
	/** id="cmt31219" **/
	//fade("#cmt" + cmtId);
	//var cosa = "#hdBlogCmt" + cmtId;
	//$("cmt31222").animate({ "color": "#ff0000" }, 500);
	
	//utente_blog_lib.php?cmtpubl=<?php echo $cmt['id'] ?>
	/*****/
	$.get("photoset_commenti_lib.php", { cmtpubl: cmtId , ajax: "true" },
	function(){
		$("#lnkPsCmtPub" + cmtId).animate({"opacity": '0'}, 'slow');
	});
	/*********/
}

function albumCmtPub( cmtId ) {
	$.get("album_commenti_lib.php", { cmtpubl: cmtId , ajax: "true" },
	function(){
		$("#lnkAlCmtPub" + cmtId).animate({"opacity": '0'}, 'slow');
	});
	/*********/
}

/********
$(".loading").bind("ajaxSend", function(){
	$(this).html('<img src="grafica/loading.gif" />Caricamento...');	
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });
/***********/

/******* RATING ***********/
/* AJAX Star Rating v1.0.1, Programming by Ulyses */
/* Updated September 4th, 2007 */


var starGo='', starNum=0;
function CANE(v) { return(document.getElementById(v)); }
function CANES(v) { return(document.getElementById(v).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function absPos(o) { var r={x:o.offsetLeft,y:o.offsetTop}; if(o.offsetParent) { var v=absPos(o.offsetParent); r.x+=v.x; r.y+=v.y; } return(r); } 
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }

function starUpdate(e,o,uid,psid) { 
var v=parseInt(CANE('starUser'+starNum).innerHTML); 
starNum=o.id.substr(4); 
CANE('starCurr'+starNum).title=v; 
//req=new XMLHttpRequest(); req.open('GET','photoset_rating_ajax?vote='+v+'&uid='+uid+'&psid='+psid,false); req.send(null); 
$.get("photoset_rating_ajax.php", { vote: v , uid: uid , psid: psid },
	function(result){
		postRating(psid, v);
	});

//alert(' e: ' + e + '\n o: ' + o + '\n uid: ' + uid + '\n psid: ' + psid);

}

function starRevert() { var v=parseInt(CANE('starCurr'+starNum).title); CANES('starCurr'+starNum).width=Math.round(v*84/100)+'px'; CANE('starUser'+starNum).innerHTML=(v>0?Math.round(v)+'%':''); CANE('starUser'+starNum).style.color='#888'; document.onmousemove=''; }
function starCurr(e,o) {

	function starMove(e) { var p=absPos(CANE('star'+starNum)); starNum=o.id.substr(4);

		var eX=xy(e)-p.x, eY=xy(e,1)-p.y;		
		
		if(eX<1 || eX>84 || eY<0 || eY>19) { starGo=''; starRevert(); } else { CANES('starCurr'+starNum).width=eX+'px'; CANES('starUser'+starNum).color='#111'; CANE('starUser'+starNum).innerHTML=Math.round(eX/84*100)+'%'; }
		
	}

	if(!starGo) { starGo=1; document.onmousemove=starMove; }

}

function postRating(psid, v) {
	$("#userRating").html(v);
	$.get("photoset_rating_ajax.php", { postRating: psid },
	function(result){
		//$("#avgRating").animate({"opacity": '0'}, 'slow');
		$("#avgRating").html(result);
		//$("#avgRating").animate({"opacity": '1'}, 'slow');
	});
}

/**********/
