function editView(controller, action, params, title) {
	
	if(!params) {
		params = '';
	}
	
	if(!title) {
		title = 'Redigera information';
	}
	
	// Make Ajax request to fetch selected bookings dialog content
	$.ajax({
      url: "/"+controller+"/"+action+"/"+params,
      global: false,
      type: "GET",
      dataType: "html",
	  cache: false,
      async:false,
      success: function(responseText) {
         $("#edit_profile").html(responseText);
      },
	  error: function(responseText) {
		 $("#edit_profile").html(responseText);
      }
	}
);

	$('#edit_profile').dialog({
		'title':title,
		'autoOpen':false,
		'modal':true,
		'minWidth':550,
		'position': ['auto', 50],
		'buttons':{
			'Avbryt':function(){$("#edit_profile").dialog("close");},
			'Spara':function(){saveView(controller, action, params);}
		}
	});
	$("#edit_profile").dialog("open");
	

	
}

function sendView(controller, action, params, title) {
	
	if(!params) {
		params = '';
	}
	
	if(!title) {
		title = 'Tipsa';
	}
	
	// Make Ajax request to fetch selected bookings dialog content
	$.ajax({
      url: "/"+controller+"/"+action+"/"+params,
      global: false,
      type: "GET",
      dataType: "html",
	  cache: false,
      async:false,
      success: function(responseText) {
         $("#edit_profile").html(responseText);
      },
	  error: function(responseText) {
		 $("#edit_profile").html(responseText);
      }
	}
);

	$('#edit_profile').dialog({
		'title':title,
		'autoOpen':false,
		'modal':true,
		'minWidth':550,
		'position': ['auto', 50],
		'buttons':{
			'Avbryt':function(){$("#edit_profile").dialog("close");},
			'Skicka':function(){saveView(controller, action, params);}
		}
	});
	$("#edit_profile").dialog("open");
	

	
}

function saveView(controller, action, params){
	// Make Ajax request to fetch selected bookings dialog content
	data = $("#"+action+"_form").serialize();
	$.ajax({
		url: "/"+controller+"/"+action+"/"+params,
		global: false,
		type: "POST",
		dataType: "html",
		cache: false,
		data: data,
		async:false,
		success: function(responseText) {
			if (responseText.substr(0,10).indexOf("[__DONE__]") >= 0) {
				// Close dialog
				$("#edit_profile").dialog("close");
				/*replace content with ajax 
				$.get('/applicant/privateprofile?ajax=1', function(data) {
				  $('#content').html(data);
				});
				*/
				if(responseText.length > 10){
					$(location).attr('href',responseText.substr(10,responseText.length));
				}else{
					if (controller == 'applicant') {
						controller = 'arbetskraft';
					} else {
						controller = 'arbetsgivare';
					}
					$(location).attr('href',"/"+controller+"/mitt-konto");
				}
			} else {
				$("#edit_profile").html(responseText);
			}
		},
		error: function(responseText) {
			$("#edit_profile").html(responseText);
		}
	});
		
		
}

function notRegisteredEmployer() {
	// Make Ajax request to fetch selected bookings dialog content
		$.ajax({
		  url: "/site/notregisteredemployer",
		  global: false,
		  type: "GET",
		  dataType: "html",
		  cache: false,
		  async:false,
		  success: function(responseText) {
			 $("#sign_in_dialog").html(responseText);
		  },
			error: function() {
			 $("#sign_in_dialog").html("<p>Webserver error!</p>");
			}
		});

		$('#sign_in_dialog').dialog({
			'title':'Ej inloggad',
			'autoOpen':false,
			'modal':true,
			'minWidth':580,
			'position':['auto', 10],
			close: function(ev, ui) { $(this).dialog("destroy"); }
			
		});
		$("#sign_in_dialog").dialog("open");
}

function contactApplicant(controller, action, params) {
	if(!params) {
		params = '';
	}
	
	// Make Ajax request to fetch selected bookings dialog content
	$.ajax({
      url: "/"+controller+"/"+action+"/"+params,
      global: false,
      type: "GET",
      dataType: "html",
	  cache: false,
      async:false,
      success: function(responseText) {
         $("#edit_profile").html(responseText);
      },
	  error: function(responseText) {
		 $("#edit_profile").html(responseText);
      }
	}
);

	$('#edit_profile').dialog({
		'title':'Kontakta arbetssökande',
		'autoOpen':false,
		'modal':true,
		'minWidth':550,
		'position': ['auto', 50],
		'buttons':{
			'Avbryt':function(){$("#edit_profile").dialog("close");},
			'Skicka meddelande':function(){saveView(controller, action, params);}
		}
	});
	$("#edit_profile").dialog("open");
}

function applyAd(controller, action, params) {
	
	if(!params) {
		params = '';
	}
	
	// Make Ajax request to fetch selected bookings dialog content
	$.ajax({
      url: "/"+controller+"/"+action+"/"+params,
      global: false,
      type: "GET",
      dataType: "html",
	  cache: false,
      async:false,
      success: function(responseText) {
         $("#edit_profile").html(responseText);
      },
	  error: function(responseText) {
		 $("#edit_profile").html(responseText);
      }
	}
);

	$('#edit_profile').dialog({
		'title':'Sök jobb',
		'autoOpen':false,
		'modal':true,
		'minWidth':550,
		'position': ['auto', 50],
		'buttons':{
			'Avbryt':function(){$("#edit_profile").dialog("close");},
			'Skicka ansökan':function(){saveView(controller, action, params);}
		}
	});
	$("#edit_profile").dialog("open");
}

