//////////////////////////////////////////////////////////////////////////////////
//
//		jqueryllä toteutettu popup ikkuna
//		19.03.2010  by  Veikko Salminen
//
//////////////////////////////////////////////////////////////////////////////////

document.write('<div id="dialog"></div>');

var dialog;

function show_popup(content, header, update_on_close) {
	
	if (dialog.dialog('isOpen')) {
		dialog.html(content);
	
	//dialog.title = "Ikkuna";
	
		dialog.dialog({
			title: header,
			buttons: {
				'Close': function() {
					if (update_on_close)
						location.reload(true);
					else
						$(this).dialog('close');
				}
			}
			});
	
	
	
		$('.ui-dialog-buttonpane button:contains(Close)').attr("id","dialog_box_Close-button");            
		$('#dialog_box_Close-button').html(lang[8]);  
	
		p_c = 0;
		while (document.getElementById("datepicker_"+(p_c))) {
			$("#datepicker_"+(p_c)).datepicker();
			p_c++;
		}
	}
}

function show_popup_form(content, header) {
	
	if (dialog.dialog('isOpen')) {
		dialog.html(content);
	
		dialog.dialog({
			title: header,
			buttons: {
				'Close': function() {
					$(this).dialog('close');
				},
				'Save': function() {
					document.getElementById("collector_form").submit();
				}
			}
			});
			
		$('.ui-dialog-buttonpane button:contains(Close)').attr("id","dialog_box_Close-button");            
		$('#dialog_box_Close-button').html(lang[8]);  
		$('.ui-dialog-buttonpane button:contains(Save)').attr("id","dialog_box_Save-button");            
		$('#dialog_box_Save-button').html(lang[7]);  
	
		p_c = 0;
		while (document.getElementById("datepicker_"+(p_c))) {
			$("#datepicker_"+(p_c)).datepicker();
			p_c++;
		}
		
		$("#multiselect").multiSelect();
	}
}
//////////////////////////////////////////////////////////
// funktio platform-kalenterille
//////////////////////////////////////////////////////////
function show_platform_calendar_form(content,header,type) {
	if (dialog.dialog('isOpen')) {
		dialog.html(content);
	
		dialog.dialog({
			title: header,
			buttons: {
				'Close': function() {
					$(this).dialog('close');
				},
				'Save': function() {
          ajaxSubmit(type);
					//document.getElementById("collector_form").submit();
				}
			}
			});
		$('.ui-dialog-buttonpane button:contains(Close)').attr("id","dialog_box_Close-button");            
		$('#dialog_box_Close-button').html(lang[8]);  
		$('.ui-dialog-buttonpane button:contains(Save)').attr("id","dialog_box_Save-button");            
		$('#dialog_box_Save-button').html(lang[7]);  
	
		p_c = 0;
		while (document.getElementById("datepicker_"+(p_c))) {
			$("#datepicker_"+(p_c)).datepicker();
			p_c++;
		}
	}
}
function show_popup_confirm(question, url, func) {
	
	$("#dialog").html('<br /><span style=\"font-size: 150%;\">'+question+'</span>');
		
	dialog = $("#dialog").dialog({
			modal: true,
			title: lang[67],
			width: 500,
			buttons: {
				"No": function() {
					$(this).dialog('close');
				},
				"Yes": function() {
					if (func) {
						$(this).dialog('close');
						func();
					}
					else
						window.location.href=url;
				}
			}
		});
		
		$('.ui-dialog-buttonpane button:contains(Yes)').attr("id","dialog_box_Yes-button");            
			$('#dialog_box_Yes-button').html(lang[65]);  
			$('.ui-dialog-buttonpane button:contains(No)').attr("id","dialog_box_No-button");            
			$('#dialog_box_No-button').html(lang[66]);
}

function show_static_popup(header, content) {
	$("#dialog").html(content);
//	alert(set_width ? set_width : 500);
	dialog = $("#dialog").dialog({
			modal: true,
			title: header,
			width: 500,
			zIndex: 110,
			buttons: {
				"Peruuta": function() {
					$(this).dialog('close');
				}
			}
		});
		
		$('.ui-dialog-buttonpane button:contains(Peruuta)').attr("id","dialog_box_Peruuta-button");            
		$('#dialog_box_Peruuta-button').html(lang[8]);  
}

function show_popup_url(url, header, type, update_on_close, set_width) {
	//dialog = document.getElementById("dialog");
	$("#dialog").html('<img src=\"images/ajax-loader.gif\"><span style=\"font-size: 150%\"> '+lang[62]+'</span>');
//	alert(set_width ? set_width : 500);
	dialog = $("#dialog").dialog({
			modal: true,
			title: lang[68],
			width: set_width ? set_width : 500,
			zIndex: 110,
			buttons: {
				"Peruuta": function() {
					$(this).dialog('close');
				}
			}
		});
		
		$('.ui-dialog-buttonpane button:contains(Peruuta)').attr("id","dialog_box_Peruuta-button");            
		$('#dialog_box_Peruuta-button').html(lang[8]);  
	
	if (type == "popup") {
		aw_get_content_from(url, function(content) {show_popup(content, header, update_on_close);});
	}
	else if (type != undefined && type != "") {
		aw_get_content_from(url, function(content) {show_platform_calendar_form(content,header,type);});
	}
	else {
		aw_get_content_from(url, function(content) {show_popup_form(content, header);});
	}
}

