	var FOLDER_USERS = "users";	


	function getQmpeopleUserUrl(id) {
		var thelink = "";
		var mode = "FILENAME";
		
		switch(id) {
			case "1000000" :
				id = "community";
				break;
			case "1000001" : 
				id = "helpdesk";
				break;
			case "1000002" : 
				id = "info";
				break;
		}		
		
		switch(mode) {
			case "PARAMETER" : 
				thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
				break;
			case "FILENAME" : 
				if ( isNaN(id) ) { // se è stato passato un nickname
					thelink = _HTTP_HOST + FOLDER_USERS + "/" + id;
				} else { // se è stato passato un qmpid
					thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
				}
				break;
		}
		return thelink;
	}	
	
	function openQmpeopleWindow(nickname) {
		var url = _HTTP_HOST + FOLDER_USERS + "/";
		if ( typeof(nickname) != "undefined" ) {
			url = getQmpeopleUserUrl(nickname);
		}
		var win = window.open(url,"winqmpeople","width=800,height=600,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");
		win.focus( );
		return false;
	}	
	
	
	function changeToQmpeople( id ) {
		var opener = window.opener;
		if ( opener != null ) {
			opener.location.replace( getQmpeopleUserUrl(id) );
		}
		return false;
	}			
	
	function openMessageComposerWindow2( nickname, type ) {
		var url, win;

		url = _HTTP_HOST + "messages/MessageComposer.asp";
		if ( typeof(nickname) != "undefined" ) {
			url += "?recipient=" + nickname;
		}
		if ( typeof(type) != "undefined" ) {
			url += "&type=" + type;
		}
		win = window.open(url,"winmessage","width=600,height=430,top=100,left=100");
		win.focus( );
		return false;
	}	
		
	function openSurveySubmitWindow( ) {
		var url = _HTTP_HOST + "survey/default.asp";
		var win = window.open(url,"winsurveysubmit","width=500,height=450,top=100,left=100");
		return false;		
	}
		
	function openDailyMindSubmitWindow( ) {
		var url = _HTTP_HOST + "dailyminds/default.asp";
		var win = window.open(url,"windailymindsubmit","width=500,height=350,top=100,left=100");
		return false;		
	}
	
	function openTopQmpUserBannerSubmitWindow( ) {
		var url = _HTTP_HOST + "arena/submitbanner.asp";
		var win = window.open(url,"wintopqmpuserbannersubmit","width=600,height=450,top=50,left=50");
		return false;		
	}	
	
	function openJokesSubmitWindow( ) {
		var url = _HTTP_HOST + "jokes/default.asp";
		var win = window.open(url,"winjokessubmit","width=500,height=350,top=100,left=100");
		return false;		
	}	
	
	function openContactsWindow( ) {
		var url = _HTTP_HOST + "contatti.asp";
		var win = window.open(url,"wincontacts","width=500,height=350");
		win.focus( );
		return false;
	}
	
	function openUpdateErrorWindow( ) {
		var url = _HTTP_HOST + "updateerror.asp";
		var win = window.open(url,"winupdateerror","width=400,height=250,top=100,left=100");
		win.focus( );
		return false;
	}
	
	function openRegistrationWindow( ) {
		var url = _HTTP_HOST + "signup/default.asp";
		window.document.location.href = url;
		return false;
	}
	
	function openAddPhotoWindow( ) {
		var url = _HTTP_HOST + "photofunctions/profileaddphoto.asp";
		var win = window.open(url,"winAddPhoto","left=50,top=50,width=500,height=380");
		return false;			
	}
	
	function openOneTimeAdvPopupWindow( ) {
		var url = _HTTP_HOST + "adv/advonetimepopup.asp";
		var win = window.open(url,"winAdvOneTimePopup","left=200,top=150,width=350,height=300,resizable=no");
		win.focus( );
		return false;
	}		
	
	function openHelpPopupWindow(section) {
		var url = _HTTP_HOST + "help/help.asp?section=" + section;
		var win = window.open(url,"winHelpPopup","left=200,top=100,width=520,height=550,scrollbars=yes");
		win.focus;
		return false;
	}

	function profilePhotoSendPhoto( ) {
		var filepath = window.document.formsendphoto.photo_file.value;
		var fileextension = "";
		if ( filepath != "" ) {
			fileextension = right(filepath,4);
			
			if ( fileextension.toLowerCase( ) == ".jpg" ) {
				window.document.formsendphoto.submit( );
				return false;
			}
			fileextension = right(filepath,5);
			
			if ( fileextension.toLowerCase( ) == ".jpeg" ) {
				window.document.formsendphoto.submit( );
				return false;
			}
			window.alert(PROFILEPHOTOINVALIDFILEFORMATTEXT);
		}
		return false;
	}	
	
	function subscribeNewsletter( ) {
		window.document.newsletterform.submit( );
		return false;
	}
	
	function myQmpeopleOpenWindow(nickname) {
		var url = _HTTP_HOST + "users/myqmpeople.asp";
		if ( typeof(nickname) != "undefined" ) {
			url = _HTTP_HOST + "users/myqmpeople.asp?command=SEEKCONTACT&nickname=" + nickname;
		}
		var win = window.open(url,"winmyqmpeople","width=500,height=550");
		return false;
	}
	
	function myQmpeopleOpenAddUserWindow(nickname) {
		var url = _HTTP_HOST + "users/addtomyqmpeople.asp";
		if ( typeof(nickname) != "undefined" ) {
			url = _HTTP_HOST + "users/addtomyqmpeople.asp?nickname=" + nickname;
		}
		var win = window.open(url,"winmyqmpeople","width=500,height=220");
		return false;
	}
	
	
	function SetCookie(name, value, expires, path, domain, secure) {
	    document.cookie = name + "=" + escape (value) +
	         ((expires) ? "; expires=" + expires.toGMTString() : "") +
	         ((path) ? "; path=" + path : "") +
	         ((domain) ? "; domain=" + domain : "") +
	         ((secure) ? "; secure" : "");
	}

	function getCookieVal(offset) {
	     var endstr = document.cookie.indexOf (";", offset);
	     if (endstr == -1) {
	         endstr = document.cookie.length;
	     }
	     return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie(name) {
	   var arg = name + "=";
	   var alen = arg.length;
	   var clen = document.cookie.length;
	   var i = 0;
	   while (i < clen) {
	     var j = i + alen;
	     if (document.cookie.substring(i, j) == arg)
	       return getCookieVal (j);
	     i = document.cookie.indexOf(" ", i) + 1;
	     if (i == 0) break; 
	   }
	   return null;
	}

	function testCookie( ) {
		SetCookie("test","yes");
		if ( GetCookie("test") == null ) {
			self.location.replace(_HTTP_HOST + "QMP_DisabledCookie.asp");
		} 
	}	
	
	function userPhotoUrl( usrid,photoname ) {
		var url = _HTTP_HOST + "users/photo/" + "USER_" + usrid + "/" + photoname;
		return url;
	}
		
	function getPhotoUrl( usrid, photoname, gender, type ) {
		var url;
		gender = gender.toLowerCase( );
		if ( photoname == null || photoname.toLowerCase( ) == "null" || photoname == "" || photoname.toLowerCase( ) == "nothing" ) {
			switch( type.toLowerCase( ) ) {
				case "photo" : 
					if ( gender == "m" ) {
						url = _HTTP_HOST + "images/standardmale.jpg";
					} else if ( gender == "f" ) {
						url = _HTTP_HOST + "images/standardfemale.jpg";
					} else {
						url = _HTTP_HOST + "images/blank.gif";
					}
					break;
				case "avatar" : 
					if ( gender == "m" ) {
						url = _HTTP_HOST + "images/standardmale_avatar.jpg";
					} else if ( gender == "f" ) {
						url = _HTTP_HOST + "images/standardfemale_avatar.jpg";
					} else {
						url = _HTTP_HOST + "images/blank.gif";
					}	
					break;
				case "thumb" : 
					if ( gender == "m" ) {
						url = _HTTP_HOST + "images/standardmale_thumb.jpg";
					} else if ( gender == "f" ) {
						url = _HTTP_HOST + "images/standardfemale_thumb.jpg";
					} else {
						url = _HTTP_HOST + "images/blank.gif";
					}
					break;
			}
		} else {
			url = userPhotoUrl(usrid,photoname);
			url += "_" + type + ".jpg";
		}
		return url;
	}
	
	function countryToHostnameLookup(countrycode) {
		var hostname = "http://www.quantomipiaci.it";
		//countrycode = parseInt(countrycode,10);
		switch(countrycode) {
			case 98 : // Italia
				hostname = "http://www.quantomipiaci.it";
				break;
			case 213: // Inghilterra
				break;
			case 214: // Stati uniti
				break;
			case 0: // International
				break;
			case 13: // Australia
				break;
			case 144: // Nuova Zelanda
				break;
			case 96: // Irlanda
				break;
			case 187: // Sudafrica
				break;
		}
		return hostname;
	}
	
	function closePopupWindow( ) {
		window.close( );
		return false;
	}
	
	function sendPostData(formobject) {
		formobject.submit( );
		return false;
	}
	
	function UserCard( ) {
		var UC_PHOTOALTTEXT = "Foto di [nickname]";
		var UC_NICKNAMETITLETEXT = "Vai alla pagina personale di [nickname]";
		
		var UC_LOGGED_SENDMESSAGEICONALTTEXT = "Invia un messaggio a [nickname]";
		var UC_UNLOGGED_SENDMESSAGEICONALTTEXT = "Registrati ora e invia un messaggio a [nickname]";
		
		var UC_LOGGED_ADDTOFAVORITESTALTTEXT = "Aggiungi [nickname] all'elenco dei tuoi amici";
		var UC_UNLOGGED_ADDTOFAVORITESTALTTEXT = "Registrati ora e aggiungi [nickname] all'elenco dei tuoi amici";
		
		var UC_LOGGED_ONLINE_CHATICONALTTEXT = "Invita [nickname] in chat";
		var UC_LOGGED_OFFLINE_CHATICONALTTEXT = "[nickname] non è online, non puoi chiamarlo in chat";
		
		var UC_UNLOGGED_ONLINE_CHATICONALTTEXT = "Registrati ora e invita subito [nickname] in chat";
		var UC_UNLOGGED_OFFLINE_CHATICONALTTEXT = "Registrati ora e invita [nickname] in chat quando è online";
		
		var UC_WEBSITEICONALTTEXT = "Visita il sito web di [nickname]";
		var UC_NOWEBSITEICONALTTEXT = "[nickname] non ha una sito web";
		
		this._NL = "\r\n"
		this.type = "avatar"; // tipi possibili : "avatar" o "thumb"
		this.nickname = "";
		this.photourl = "";
		this.photoid = "";
		this.isonline = false;
		this.islogged = true;
		this.background = "";
		this.nicknametitletext = "";
		this.gotoopener = false;
		this.target = "_self";
		
	
		// gli attributi alt delle immagini
		this.photoalttext = "";
		this.sendmessageiconalttext = "";
		this.addtofavoritesiconalttext = "";
		this.chaticonalttext = "";
		this.websiteiconalttext = "";
		
		// gli url delle icone 
		this.sendmessageiconurl = "";
		this.addtofavoritesiconurl = "";
		this.chaticonurl = "";
		this.websiteiconurl = "";

		// gli url dei link associati alle icon
		this.messagesurl = _HTTP_HOST + FOLDER_REGISTER;
		this.addtofavoritesurl = _HTTP_HOST + FOLDER_REGISTER;
		this.chaturl = _HTTP_HOST + FOLDER_CHAT + "/?chat_con=" + this.nickname;
		this.websiteurl = "#";
		
		// gli event handler dei link associati alle icone
		this.messageslinkhandler = "";
		this.addtofavoriteslinkhandler = "";
		this.chatlinkhandler = "";
		this.websitelinkhandler = "";

		this.setup = function( ) {
			/*************************************************************************/
			/* il blocco di codice seguente imposta tutti i percorsi delle immagini  */
			/* delle icone in funzione del tipo ( avatar/thumb ), dello stato di     */
			/* online e della presenza o meno di un sito web utente.                 */
			/*************************************************************************/
			if ( this.type == "avatar" ) {
				this.sendmessageiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconmessageactive2.gif";
				this.addtofavoritesiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconfavoritesactive2.gif";
				if ( this.isonline == true ) {
					this.chaticonurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconchatactive2.gif";
				} else {
					this.chaticonurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconchatinactive2.gif";
				}
				if ( this.websiteurl != "#" ) {
					this.websiteiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconhomepageactive.gif";
				} else {
					this.websiteiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardiconhomepageinactive.gif";
				}
			} else {
				this.sendmessageiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconmessageactive2.gif";
				this.addtofavoritesiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconfavoritesactive2.gif";
				if ( this.isonline == true ) {
					this.chaticonurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconchatactive2.gif";
				} else {
					this.chaticonurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconchatinactive2.gif";
				}
				if ( this.websiteurl != "#" ) {				
					this.websiteiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconhomepageactive.gif";
				} else {
					this.websiteiconurl = _HTTP_HOST + FOLDER_IMAGES + "/usercardthumbiconhomepageinactive.gif";
				}
			}
			
			/*************************************************************************/
			/* il blocco di codice seguente imposta gli url dei link associati alle  */
			/* icone in funzione dello stato di loggato                              */
			/*************************************************************************/
			if ( this.islogged == true ) {
				this.messagesurl = "#";
				this.addtofavoritesurl = "#";
				if ( this.isonline == true ) {
					this.chaturl = _HTTP_HOST + FOLDER_CHAT + "/" + CHATPARAMETER_PART1 + "_" + CHATPARAMETER_PART2 + "_" + this.nickname;
				} else {
					this.chaturl = "#";
				}
			} else {
				this.messagesurl = _HTTP_HOST + FOLDER_REGISTER;
				this.addtofavoritesurl = _HTTP_HOST + FOLDER_REGISTER;

				if ( this.isonline == true ) {
					this.chaturl = _HTTP_HOST + FOLDER_CHAT + "/" + CHATPARAMETER_PART1 + "_" + CHATPARAMETER_PART2 + "_" + this.nickname;
				} else {
					this.chaturl = "#";
				}
			}
			
			/*************************************************************************/
			/* se non ne sono stati definiti di specifici, vengono impostati gli     */
			/* handler di default. Come impostazione predefinita, per gli utenti non */
			/* loggati non è previsto alcun handler.                                 */
			/*************************************************************************/
			if ( this.islogged == true ) {
				if ( this.messageslinkhandler == "" ) {
					this.messageslinkhandler = "onclick=\"" + composeFunctionCall("openMessageComposerWindow2",this.nickname) + "\"";
				}
				if ( this.addtofavoriteslinkhandler == "" ) {
					this.addtofavoriteslinkhandler = "onclick=\"" + composeFunctionCall("myQmpeopleOpenAddUserWindow",this.nickname) + "\"";
				}
			}
			
			/*************************************************************************/
			/* il blocco di codice seguente imposta il testo alt delle icone         */
			/* in funzione dello stato di loggato, di online, della presenza di un   */
			/* sito web utente e dell'eventuale testo alternativo eventualmente      */
			/* passato in fase di creazione dell'oggetto.                            */
			/*************************************************************************/
			if ( this.islogged == true ) {
				this.sendmessageiconalttext = UC_LOGGED_SENDMESSAGEICONALTTEXT;
				this.addtofavoritesiconalttext = UC_LOGGED_ADDTOFAVORITESTALTTEXT;
				
				if ( this.isonline == true ) {
					this.chaticonalttext = UC_LOGGED_ONLINE_CHATICONALTTEXT;
				} else {
					this.chaticonalttext = UC_LOGGED_OFFLINE_CHATICONALTTEXT;
				}
			} else {
				this.sendmessageiconalttext = UC_UNLOGGED_SENDMESSAGEICONALTTEXT;
				this.addtofavoritesiconalttext = UC_UNLOGGED_ADDTOFAVORITESTALTTEXT;
				if ( this.isonline == true ) {
					this.chaticonalttext = UC_UNLOGGED_ONLINE_CHATICONALTTEXT;
				} else {
					this.chaticonalttext = UC_UNLOGGED_OFFLINE_CHATICONALTTEXT;
				}
			}
		
			if ( this.websiteurl != "#" ) {
				this.websiteiconalttext = UC_WEBSITEICONALTTEXT;
			} else {
				this.websiteiconalttext = UC_NOWEBSITEICONALTTEXT;
			}

			if ( this.photoalttext == "" ) {
				this.photoalttext = UC_PHOTOALTTEXT;
				this.photoalttext = this.photoalttext.replace("[nickname]",this.nickname);
			} 
			
			if ( this.nicknametitletext == "" ) {
				this.nicknametitletext = UC_NICKNAMETITLETEXT;
				this.nicknametitletext = this.nicknametitletext.replace("[nickname]",this.nickname);
			} 

			this.sendmessageiconalttext = this.sendmessageiconalttext.replace("[nickname]",this.nickname);
			this.addtofavoritesiconalttext = this.addtofavoritesiconalttext.replace("[nickname]",this.nickname);
			this.chaticonalttext = this.chaticonalttext.replace("[nickname]",this.nickname);
			this.websiteiconalttext = this.websiteiconalttext.replace("[nickname]",this.nickname);
		}
		
		this.cleanUp = function( ) {
			this.nicknametitletext = "";
			this.photoalttext = "";
			this.websiteurl = "#";
			this.nickname = "";
			this.photourl = "";
			this.photoid = "";
			
			this.messageslinkhandler = "";
			this.addtofavoriteslinkhandler = "";
			this.chatlinkhandler = "";
			this.websitelinkhandler = "";
			this.target = "_self";
		}
		
		this.getUserCard = function( ) {
			this.setup();
			var text = "";
			if ( this.type == "avatar" ) {
				text += "<div class=\"Usercard\">" + this._NL;
			} else {
				text += "<div class=\"UsercardThumb\">" + this._NL;
			}
			text += "<div class=\"UserPhoto\"" + ( this.photoid == "" ? "" : " id=\"" + this.photoid + "\"" ) + "><img src=\"" + this.photourl + "\" border=\"1\" alt=\"" + this.photoalttext + "\"></div>" + this._NL;
			text += "<div class=\"MessageIcon\"><a href=\"" + this.messagesurl + "\" " + this.messageslinkhandler + " target=\"" + this.target + "\"><img src=\"" + this.sendmessageiconurl + "\" border=\"0\" alt=\"" + this.sendmessageiconalttext + "\"></a></div>" + this._NL;
			text += "<div class=\"FavoritesIcon\"><a href=\"" + this.addtofavoritesurl + "\" " + this.addtofavoriteslinkhandler + " target=\"" + this.target + "\"><img src=\"" + this.addtofavoritesiconurl + "\" border=\"0\" alt=\"" + this.addtofavoritesiconalttext + "\"></a></div>" + this._NL;
			if ( this.isonline == true ) {
				text += "<div class=\"ChatIcon\"><a href=\"" + this.chaturl + "\" " + this.chatlinkhandler + " target=\"" + this.target + "\"><img src=\"" + this.chaticonurl + "\" border=\"0\" alt=\"" + this.chaticonalttext + "\"></a></div>" + this._NL;
			} else {
				text += "<div class=\"ChatIcon\"><img src=\"" + this.chaticonurl + "\" border=\"0\" alt=\"" + this.chaticonalttext + "\"></div>" + this._NL;
			}
			
			/*
			if ( this.websiteurl != "#" ) {
				text += "<div class=\"HomeIcon\"><a href=\"" + this.websiteurl + "\" " + this.websitelinkhandler + "><img src=\"" + this.websiteiconurl + "\" border=\"0\" alt=\"" + this.websiteiconalttext + "\"></a></div>" + this._NL;
			} else {
				text += "<div class=\"HomeIcon\"><img src=\"" + this.websiteiconurl + "\" border=\"0\" alt=\"" + this.websiteiconalttext + "\"></div>" + this._NL;
			}
			*/
			
			if ( this.gotoopener == true ) {
				text += "<div class=\"Nickname\"><a href=\"" + getQmpeopleUserUrl(this.nickname) + "\" onclick=\"" + composeFunctionCall("changeToQmpeople",this.nickname) + "\">" + this.nickname + "</a></div>" + this._NL;
			} else {
				//text += "<div class=\"Nickname\">" + getQmpeopleUserLink(this.nickname,this.nickname,this.nicknametitletext) + "</div>" + this._NL;
				text += "<div class=\"Nickname\"><a href=\"" + getQmpeopleUserUrl(this.nickname) + "\" target=\"" + this.target + "\">" + this.nickname + "</a>" + "</div>" + this._NL;
			}

			text += "</div>" + this._NL;
			this.cleanUp( );
			return text;
		}
		
		this.draw = function( ) {
			Response.Write(this.getUserCard( ));
		}
	}		
	
	function getQmpeopleUserUrl(id,section) {
		var thelink = "";
		var mode = "FILENAME";
		
		switch(id) {
			case "1000000" :
				id = "community";
				break;
			case "1000001" : 
				id = "helpdesk";
				break;
			case "1000002" : 
				id = "info";
				break;
		}		
		
		switch(mode) {
			case "PARAMETER" : 
				thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
				break;
			case "FILENAME" : 
				if ( isNaN(id) ) { // se è stato passato un nickname
					thelink = _HTTP_HOST + FOLDER_USERS + "/" + id;
					if ( typeof(section) != "undefined" ) {
						thelink += "/" + section;
					}
				} else { // se è stato passato un qmpid
					thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
				}
				break;
		}
		return thelink;
	}				
	
	function getQmpeopleUserLink(id,text,title) {
		// LOCALIZED_CONST
		var QMPEOPLEUSERLINKTITLEPHOTOOF = "Foto di";
		var QMPEOPLEUSERLINKTITLELOOKHISPHOTOES = "Guarda le sue foto";
		
		id = id + ""; // trasforma in stringa
		var thelink = "";
		var mode = "FILENAME";
		
		if ( typeof(title) == "undefined" ) {
			title = "";
		}
		
		switch(id) {
			case "1000000" :
				id = "community";
				break;
			case "1000001" : 
				id = "helpdesk";
				break;
			case "1000002" : 
				id = "info";
				break;
		}
		
		switch(mode) {
			case "PARAMETER" : 
				thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
				break;
			case "FILENAME" : 
				if ( isNaN(id) ) { // se è stato passato un nickname
					thelink = _HTTP_HOST + FOLDER_USERS + "/" + id;
					if ( title == "" ) {
						title = QMPEOPLEUSERLINKTITLEPHOTOOF + " " + id;
					}					
				} else { // se è stato passato un qmpid
					thelink = _HTTP_HOST + FOLDER_USERS + "/?nickname=" + id;
					if ( title == "" ) {
						title = QMPEOPLEUSERLINKTITLELOOKHISPHOTOES
					}					
				}
				break;
		}
		return "<a href=\"" + thelink + "\" title=\"" + title + "\">" + text + "</a>";
	}
		
	function delay(millis) 
	{
		var date = new Date();
		var curDate = null;

		do { 
			curDate = new Date(); 
		} while(curDate-date < millis);
	}		
	
	
	var FOLDER_CHAT = "chat";
	var FOLDER_IMAGES = "images";
	var FOLDER_REGISTER = "signup";
	var FOLDER_USERS = "users";
	
	
	

	
	

