	var sURL = unescape(window.location.pathname);

	$(function() { 
		$("#profile_new_dialog").dialog("destroy");
		$("#profile_edit_dialog").dialog("destroy");		
		$("#login_dialog").dialog("destroy");

		$("#profile_new_dialog").dialog({
			autoOpen: false,        
		  modal: true,
		  buttons: {

			}
	  });

		$("#profile_edit_dialog").dialog({
			autoOpen: false,        
		  modal: true,
		  buttons: {
		  	Ok: function() {
		    	close_edit();
			}
		}
	  });
	  		
		$("#login_dialog").dialog({
			autoOpen: false,
		  modal: true,
		  buttons: {

		}
	  });
	});
	
	function login_open(lang, site) {
  	$("#login_dialog").dialog("open");
	var randomnumber=Math.floor(Math.random()*100000001)
  	$.post("/profile/login.php", {lang: lang, site: site, rand: randomnumber},
  		function(data){
 	             document.getElementById("login_dialog").innerHTML = "<p>" + data + "</p>";
    	});
  	$("#login_dialog").dialog("option", "width", 305);
  	$("#login_dialog").dialog("option", "position", 'top');    
  	};        

	function profile_help(lang, site, loggedin) {
  	$("#login_dialog").dialog("open");
	var randomnumber=Math.floor(Math.random()*100000001)
  	$.post("/profile/help_profile.php", {lang: lang, site: site, rand: randomnumber, login: loggedin},
  		function(data){
 	             document.getElementById("login_dialog").innerHTML = "<p>" + data + "</p>";
    	});
  	$("#login_dialog").dialog("option", "width", 305);
  	$("#login_dialog").dialog("option", "position", 'top');    
  	};

        function help_close() {
                $("#login_dialog").dialog("close");
        };

	function profile_resentcode(lang, site) {
		var telephone  = document.getElementById("telephonesms").value;
		var lang  = document.getElementById("langsms").value;
		var site  = document.getElementById("sitesms").value;
		var countrycode2 = document.getElementById("countrycodesms");
		var countrycode = countrycode2.options[countrycode2.selectedIndex].value;
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.post("/profile/resent_code.php", {lang: lang, site: site, telephone: telephone, countrycode: countrycode, rand: randomnumber},
  		function(data){
 	             document.getElementById("phoneerror").innerHTML = "<tr><td class=ts_menu colspan=3>" + data + "</td></tr>";
    		});
  	};

	function profile_new_dialog(lang, site) {
    $("#login_dialog").dialog("close");	
	  $("#profile_new_dialog").dialog("open");
		var randomnumber=Math.floor(Math.random()*100000001)
    var telephone =  document.getElementById("telephone").value;
		var passwd    =  document.getElementById("passwd").value;		
  	var countrycode2 =  document.getElementById("countrycode");
		var countrycode = countrycode2.options[countrycode2.selectedIndex].value;
		$.post("/profile/create_profile.php", {rand:randomnumber, lang:lang, site:site, telephone: telephone, countrycode: countrycode, passwd: passwd },
  		function(data){
 	        	     document.getElementById("profile_new_dialog").innerHTML = "<p>" + data + "</p>";
      		});
	  	$("#profile_new_dialog").dialog("option", "width", 305);
  		$("#profile_new_dialog").dialog("option", "position", 'top');                
  	};        

	function sent_link_edit(lang, site, phone, countrycode) {
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.post("/profile/mobile_link.php", {rand:randomnumber, lang:lang, site:site, phone: phone, countrycode: countrycode},
  		function(data){
 	        	     document.getElementById("erroredit").innerHTML = "<p>" + data + "</p>";
      		});
  	};            


	function sent_link(lang, site, phone, countrycode) {
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.post("/profile/mobile_link.php", {rand:randomnumber, lang:lang, site:site, phone: phone, countrycode: countrycode});
  	};        
	function log_out() {
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.post("/profile/logout.php", {rand:randomnumber })
		if (sURL.indexOf("?") == -1)
		{
			sURL = sURL + "?userid=";
		} else {
			sURL = sURL + "&userid=";
		}
	
		window.location.replace( sURL );
  	};            

	function profile_delete(telephone, passwd, countrycode, lang, site) {
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.post("/profile/delete_profile.php", {rand:randomnumber,lang:lang, telephone:telephone, countrycode:countrycode, passwd:passwd, site:site })
		if (sURL.indexOf("?") == -1)
		{
			sURL = sURL + "?userid=";
		} else {
			sURL = sURL + "&userid=";
		}	
		window.location.replace( sURL );
  	};

	function close_edit() {
		$("#profile_edit_dialog").dialog("close");	
		window.location.replace( sURL );
  	};

  	function profile_edit(telephone, passwd, countrycode, lang, site) {
		var randomnumber=Math.floor(Math.random()*100000001)
  		$.get("/profile/load_profile.php", { countrycode: countrycode, telephone: telephone, password: passwd, site: site, lang:lang, rand: randomnumber},
  		function(data){
  			$("#profile_edit_dialog").dialog("open");
			        document.getElementById("profile_edit_dialog").innerHTML = "<p>" + data + "</p>";
			$("#profile_edit_dialog").dialog("option", "width", 305);
  			$("#profile_edit_dialog").dialog("option", "position", 'top'); 
   		});
  	};

  	function profile_search(obj) {
   	var telephone 			= document.getElementById("telephone").value;
		var passwd 						= document.getElementById("passwd").value;
		var countrycode2     = document.getElementById("countrycode");
		var lang             = document.getElementById("lang").value;
		var site             = document.getElementById("site").value;
		var countrycode = countrycode2.options[countrycode2.selectedIndex].value;
		var randomnumber=Math.floor(Math.random()*100000001)
  	$.get("/profile/load_profile.php", { countrycode: countrycode, telephone: telephone, password: passwd, site: site, lang:lang, rand: randomnumber},
  	function(data){
  		if (data.indexOf('Ticket') == -1)
  		{
			$("#login_dialog").dialog("close");
  			$("#profile_edit_dialog").dialog("open");
			        document.getElementById("profile_edit_dialog").innerHTML = "<p>" + data + "</p>";
			$("#profile_edit_dialog").dialog("option", "width", 305);
  			$("#profile_edit_dialog").dialog("option", "position", 'top'); 
  		} else {
  			document.getElementById("phoneerror").innerHTML = "<p>" + data + "</p>"; 			
  		}
   	});
  };
               
	function profile_create(obj) {
			var countrycode = document.getElementById("countrycode").value;
			var phone = document.getElementById("telephone").value;
			var first_name = document.getElementById("first_name").value;
			var last_name = document.getElementById("last_name").value;
			var street = document.getElementById("street").value;
			var streetno = document.getElementById("streetno").value;
			var entrance = document.getElementById("entrance").value;
			var floor = document.getElementById("floor").value;
			var zipcode = document.getElementById("zipcode").value;
			var city = document.getElementById("city").value;
			var email = document.getElementById("email").value;
			var email_repeat = document.getElementById("email").value;
			var code = document.getElementById("passwd").value;
			var code_repeat = document.getElementById("passwd_repeat").value;
			var lang = document.getElementById("lang").value;
      			var site = document.getElementById("site").value;
		  	var randomnumber=Math.floor(Math.random()*100000001)
		  
	       		$.get("/profile/create_new_profile.php", { countrycode: countrycode, phone: phone, first_name: first_name, last_name:last_name, street: street, streetno: streetno, entrance: entrance, floor: floor, zipcode: zipcode, city: city, email: email, code: code,  code_repeat: code_repeat, lang:lang, site:site, randoms: randomnumber},
		  	function(data){
				if (data != "")
				{
		  			document.getElementById("errorcreate").innerHTML = "<p>" + data + "</p>";
				} else {
			  		$.get("/profile/load_profile.php", { countrycode: countrycode, telephone: phone, password: code, site: site, lang:lang, rand: randomnumber},
  					function(data){
						$("#profile_new_dialog").dialog("close");
				  		$("#profile_edit_dialog").dialog("open");
						        document.getElementById("profile_edit_dialog").innerHTML = "<p>" + data + "</p>";
						$("#profile_edit_dialog").dialog("option", "width", 305);
				  		$("#profile_edit_dialog").dialog("option", "position", 'top'); 
				   	});
				}
			});
  };
  
	function profile_save(obj) {
			var countrycode = document.getElementById("countrycode").value;
			var phone = document.getElementById("telephone").value;
			var first_name = document.getElementById("first_name").value;
			var last_name = document.getElementById("last_name").value;
			var street = document.getElementById("street").value;
			var streetno = document.getElementById("streetno").value;
			var entrance = document.getElementById("entrance").value;
			var floor = document.getElementById("floor").value;
			var zipcode = document.getElementById("zipcode").value;
			var city = document.getElementById("city").value;
			var email = document.getElementById("email").value;
			var code_repeat = document.getElementById("passwd_repeat").value;
			var code = document.getElementById("passwd").value;
			 var lang = document.getElementById("lang").value;
      var site = document.getElementById("site").value;
		  var randomnumber=Math.floor(Math.random()*100000001)			
	      $.get("/profile/update_profile.php", { countrycode: countrycode, phone: phone, first_name: first_name, last_name:last_name, street: street, streetno: streetno, entrance: entrance, floor: floor, zipcode: zipcode, city: city, email: email, code: code,  code_repeat: code_repeat, lang:lang, site:site, randoms: randomnumber},
	  		function(data){
			     	document.getElementById("erroredit").innerHTML = "<p>" + data + "</p>";			
	   		});
  	};  
    