var Popup = new Popup();

function Popup() {
	this.taketour = function() {
		var html = '';
		html+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="900" height="500" id="Tennis_site_tour" align="middle">';
		html+='<param name="allowScriptAccess" value="sameDomain" />';
		html+='<param name="allowFullScreen" value="false" />';
		html+='<param name="movie" value="http://statics.tenniscontact.com/takeatour.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />';
		html+='<embed src="http://statics.tenniscontact.com/takeatour.swf" quality="high" bgcolor="#ffffff" width="900" height="500" name="Tennis_site_tour" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html+='</object>';
		
		this.setSizeAndPosition(910,540,18,5);
		$("#popup_content").html(html);
		Popup.open();
	};
	
	this.open = function(){
		document.getElementById("popup").className='popup';
		document.getElementById("bgpopup").className='bgpopup';
		
		$("#bgpopup").animate({opacity: 0.7}, 900 );
	    $("#popup").animate({opacity: 1}, 600 );
	};
	
	this.close = function(){
		$("#bgpopup").animate({opacity: 0}, 500);
		$("#popup").animate({opacity: 0}, 200);
		
		setTimeout(this.remove,500);
	};
	
	this.remove = function() {
		document.getElementById("popup").className='popup_h';
		document.getElementById("bgpopup").className='bgpopup_h';
	};
	
	this.privacy = function(option) {
		if(option==3){
			$("#popup_title").html("<h1>Set privacy</h1>");
			
			var html='';
			html+='<div>You can give a list of emails addresses of the people who will be able to see your photo album or enter a password which you will be able to give to the people you want. An email will be sent to the emails you put below to invite those people to view your photo album. If you specify a password then they will receive it and will have to specify it to see the album otherwise the password is auto-generated.</div><br/>';
			html+='<div>List of emails address</div>';
			html+='<div><textarea id="emails" style="width:350px;"></textarea><br/>(comma separated)</div><br/>';
			html+='<div>Choose a password</div>';
			html+='<div><input type="text" id="password" /></div><br/>';
			html+='<div style="text-align:center;">';
			html+='<input type="button" value="OK" onclick="Misc.setPrivacy();" />&nbsp;&nbsp;&nbsp;';
			html+='<input type="button" value="Cancel" onclick="Popup.close();" />';
			html+='</div>';
			
			this.setSizeAndPosition(450,350,43,18);
			$("#popup_content").html(html);
			Popup.open();
		}
	};
	
	this.participant = function(idEvent) {
		var html='';
		html+='<h1>Enter your phone</h1>';
		html+='<div>You can enter your phone number which will be visible from the event\'s organizer only who will then be able to join you if necessary</div>';
		html+='<br/>';
		html+='<div>Your phone</div>';
		html+='<div><input type="text" name="phone" id="phone" /></div><br/>';
		html+='<div><input type="button" value="Participate" onclick="Misc.participate('+idEvent+');" /></div>';
		
		this.setSizeAndPosition(250,210,43,18);
		$("#popup_content").html(html);
		Popup.open();
	};
	
	this.country = function(path) {
		$("#popup_title").html("Add a country");
		
		var html='';
		html+='<div style="margin-top:4px;">Name</div>';
		html+='<div><input type="text" id="name" /></div>';
		html+='<br/>';
		html+='<input type="submit" value="Add" onclick="Country.add(\''+path+'\');" />';
		
		this.setSizeAndPosition(250,130,43,18);
		$("#popup_content").html(html);
		Popup.open();
	};
	
	this.region = function(path) {
		var id = document.getElementById("country").selectedIndex;
		
		var idCountry = document.getElementById("country").options[id].value;
		
		if(idCountry != "") {
			$("#popup_title").html("Add a region");
			
			var html='';
			html+='<div style="margin-top:4px;">Name</div>';
			html+='<div><input type="text" id="name" /></div>';
			html+='<br/>';
			html+='<input type="submit" value="Add" onclick="Region.add('+idCountry+');" />';
			
			this.setSizeAndPosition(250,130,43,18);
			$("#popup_content").html(html);
			Popup.open();
		} else {
			alert("You need to select a country first");
		}
	};
	
	this.friends = function(login,id) {
		var html = '';
		html+='<h1 class="space">Add '+login+' as a friend</h1>';
		html+='<div>Are you sure you want to add '+login+' as a friend?</div><br/>';
		html+='<div style="text-align:center;"><input type="submit" onclick="Friends.add('+id+',\''+login+'\');return false;" value="Yes"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="Popup.close();" value="No"/></div>';
		
		$("#popup_content").html(html);
		Popup.setSizeAndPosition(250,140,43,18);
		Popup.open();
	};
	
	this.forgotPassword = function(path) {
		$("#popup_title").html("Forgot your password?");
		
		var html = '';
		html+='<div>What is your email address?</div>';
		html+='<div><input type="text" name="email" id="email" /></div><br/>';
		html+='<div style="text-align:center;"><input type="button" onclick="Misc.forgotPassword(\''+path+'\');" value="Ok" /></div>';
	
		$("#popup_content").html(html);
		Popup.setSizeAndPosition(250,110,43,18);
		Popup.open();
	};
	
	this.writeMessage = function(id,login,path) {
		if(!login) {
			login="";
		}
		if(!id || id == 0) {
			id="";
		}
		
		$("#popup_title").html("Write a message");
		
		var html='';
		html+='<div>To</div>';
		html+='<div><input type="text" name="to" id="to" value="'+login+'" onkeyup="Misc.findUser(this.value,\''+path+'\');" /><input type="hidden" name="idReceiver" id="idReceiver" value="'+id+'" /></div>';
		html+='<div id="users"></div>';
		
		html+='<div>Subject</div>';
		html+='<div><input type="text" name="subject" id="subject" /></div><br/>';
		
		html+='<div>Message</div>';
		html+='<div><textarea name="message" id="message"></textarea></div>';
		
		html+='<div><input type="radio" name="privacy" value="public" /> Public message (all)</div>';
		html+='<div><input type="radio" name="privacy" value="friends" /> Public message (friends)</div>';
		html+='<div><input type="radio" name="privacy" value="private" checked /> Private message</div>';
		
		html+='<br/><div><input type="button" value="Send" onclick="Message.send(\''+path+'\');return false;" /></div>';
	
		$("#popup_content").html(html);
		
		if(id==-1){
			var idMessage;
			if($("#idMessage")){
				idMessage = document.getElementById('idMessage').value;
				
				if(idMessage) {
					Message.get(idMessage, path);
				}
			}
		}
		
		Popup.setSizeAndPosition(430,490,38,6);
		Popup.open();
	};
	
	this.setSizeAndPosition = function(width,height,left,top) {
		$("#popup").width(width);
		$("#popup").height(height);
		document.getElementById("popup").style.left=left+"%";
		document.getElementById("popup").style.top=top+"%";
	};
	
	this.IE6 = function() {
		var browser=navigator.appName;
		var b_version=navigator.appVersion;
		var start = b_version.indexOf("MSIE");
		var version=b_version.substring(start+5,start+6);
		
		if(browser=="Microsoft Internet Explorer" && version<=6){
			jQuery.get("/ajax/ie6",function(json){
				$("#popup_content").html(json);
	
				Popup.setSizeAndPosition(800,480,22,5);
				Popup.open();
			});
		}
	};
	
	this.removePicture = function(id, path) {
		$("#popup_title").html("Remove a picture");
		
		var html='';
		html+='<div>Are you sure you want to remove this picture?</div><br/>';
		html+='<div style="text-align:center;">';
		html+='<input type="button" onclick="Misc.removePicture('+id+',\''+path+'\');" value="Yes" />';
		html+='&nbsp;&nbsp;&nbsp;';
		html+='<input type="button" onclick="Popup.close();" value="No" />';
		html+='</div>';
		
		$("#popup_content").html(html);
		
		Popup.setSizeAndPosition(320,100,40,15);
		Popup.open();
	};
}