// class passprotection
function passprotection(){
	this.id=0;
	this.show_dialog = passprotection_show_dialog ;
	this.check_pass = passprotection_check_pass;
	this.dialog_info = passprotection_dialog_info;
}
function passprotection_dialog_info(msg, type){
	style= "ui-state-highlight ui-corner-all";
	if (type){
		if (type == 'E')
			style = "ui-state-error ui-corner-all";
	}
	$('#enterphotopass_info').attr('class',style);
	$('#enterphotopass_info_text').text(msg);
	$("#enterphotopass_info").show();
}

function passprotection_show_dialog(id){
	this.id = id;

	$("#enterphotopass_load").hide();
	$("#enterphotopass_info").hide();
	$("#enterphotopass_body").show();
	$('#enterphotopass_info_text').text('');

	$('#enterphotopass_pass').val("");
    $("#enterphotopass").dialog();
    $("#enterphotopass").dialog('open');
}
function passprotection_check_pass(){
	pas = $('#enterphotopass_pass').val();
	if (pas == '' )
		return 0;
	$("#enterphotopass_load").show();
	$("#enterphotopass_body").hide();
	this_class = this; 


	$.post("checkpass.php",{ imageid: this.id, password: pas}, 
		function(res){
			$("#enterphotopass_load").hide();
			if (res=="Y"){
			    $("#enterphotopass").dialog('close');
				window.location.reload();
			}else{
				this_class.dialog_info(err_photo_protection_pass_incorrect, 'E');
			}
		}
	);

}
passprotect=new passprotection();
