// popupwindow profiles
var profiles =
{
	regions:
	{
		height:500
		,width:500
	}
	,event_booths:
	{
		width:300
		,height:400
		,scrollbars:1
		,resizable:1
		,toolbar:0
		,location:0
	}
	,newwindow:
	{
		scrollbars:1
		,toolbar:1
		,location:1
		,status:1
		,menubar:1
	}
	,checks:
	{
		height:250
		,width:400
	}
	,nigp_external_meetings:
	{
		scrollbars:1
		,height:500
		,width:500
	}
};


function MakeSure(item)
{
	var msg = "";
	var newwindow = false;
	var type = item.attr('rel');
	switch(type)
	{
		case "record": msg = resources.MakeSureRecord;
		break;

		case "records": msg = "WARNING!\nDeleting records is irreversible.\nIf you are sure you want to delete these records, click \"OK\"";
		break;

		case "cart": msg = resources.MakeSureCart;
		break;
		
		case "unpublish": msg = resources.MakeSureUnpublish;
		break;
		
		case "deactivate": msg = resources.MakeSureDeactivate;
		break;
		
		case "vacant": msg = resources.MakeSureVacant;
		break;
		
		case "invoice": msg = resources.MakeSureInvoice;
		break;
		
		case "login_member": msg = resources.MakeSureLoginMember;
		break;
		
		case "merge": msg = resources.MakeSureMergeMember;
		break;
		
		case "login_admin": msg = resources.MakeSureLoginAdmin;
		break;
	}
	
	if(confirm(msg))
	{
		if (newwindow)
		{
			item.popupwindow();
		}
		
		return true;
		
	}
	else
	{
		return false;
	}
}

$(function(){
	
	$("a.removefile").bind("click", function(){
		$(this).parents("div:first").hide().prev("input:hidden").val("");
		return false;
	});
		
	$(".popupwindow").popupwindow(profiles);
	
	$("table.maindisplay tbody>tr:odd").addClass("odd");
	$("table.formtable tr").removeClass("odd");
	
	$(".makesure").bind("click", function(){
		return MakeSure($(this));
	});
	
	$("form").each(function(){
		var $that = $(this);
		$that.submit(function(){
			$that.find("input[type='image'],input[type='submit']").attr("disabled", "true");
		});
	});
	
	$("#NewHeaderSelect").bind("change", function(){
		var i = $(this).val();
		if(i != "11111111-1111-1111-1111-111111111111"){
			$("#NewHeaderRow").hide();
			$("#NewHeaderError").hide();
			$("#NewHeaderField").val("");
		}else{
			$("#NewHeaderRow").show();
			$("#NewHeaderError").show();
			$("#NewHeaderField").get(0).focus();
		}
	}).change();
	
	$("#NewTypeSelect").bind("change", function(){
		var i = $(this).val();
		if(i != "11111111-1111-1111-1111-111111111111"){
			$("#NewTypeRow").hide();
			$("#NewTypeError").hide();
			$("#NewTypeField").val("");
		}else{
			$("#NewTypeRow").show();
			$("#NewTypeError").show();
			$("#NewTypeField").get(0).focus();
		}
	}).change();
	
	$(".clear_radio").bind("dblclick", function(){
		$(this).attr("checked", false);
	});
	
	$("#EventManagerBooths").show();
	$("input[name=item_s]").each(function(){
		$(this).bind("click dblclick", function(){
			ToggleBoothSelection();		
		});
	});

	//alert($("#AutoFillBoothNumber").val());

	$("#AutoFillBoothNumber").bind("click", function(){
		var regex = /(^\d$)/;
		var a = $("input[name=autonumber]").val();
		var b = parseInt(a);
		if(isNaN(b)) return;
		$(".boothnumber").each(function()
		{
			this.value = b;
			b++;
		});
	});
	
	function ToggleBoothSelection()
	{
		if ($("input[name=item_s]").length > 0 && $("#EventManagerBooths").is('*'))
		{
			var that = $("#EventManagerBooths");
			var that2 = that.find('select');
			if($("input[name=item_s]:checked").is(".sponsorbooth"))
			{
				that.hide();
				that2.val("");
			}
			else
			{
				that.show();
			}
		}
	}
	
	ToggleBoothSelection();
	
	// meeting photos
	$(".meetingphotos").cycle({
		fx: 'scrollLeft'
		,pause: 1
		,timeout: 7000
	});

});