YAHOO.namespace("admin.container");

// Appropriates dialog boxes for links that require them
// addAction should be generic enough to handle any dialog that needs to be created through setDialog function 
// For each new dialog needed create a new if statement (or replace with a switch statement if the lists gets to large) 
setDialog = function() 
{
	anchors = document.getElementsByTagName("a");
	
	for ( var i = 0; anchors.length > i; i++ )
	{
		// Set actions for CANCEL LISTING links
		if ( anchors[i].className == "cancelListing" )
		{
			document.body.className = "yui-skin-sam";
			anchors[i].id = "cancelListing" + i;
			
			var href = anchors[i].href;
			
			anchors[i].href = "#cancel";
			
			var id = anchors[i].id;
			var header = "Are you sure?";
			var message = "You are about to <strong>PERMANENTLY</strong> remove a job listing. Are you sure that you want to continue?";
			var yesText = "Delete Listing";
			var noText = "Return";
			
			addAction( id, header, message, yesText, noText, href, i );
		}
	}
}

// Uses YUI library to add a custom dialog box
addAction = function( id, header, message, yesText, noText, href, iteration )
{
	// Define various event handlers for Dialog
	var handleYes = function() {
		this.hide();
		window.location = href;
	};
	var handleNo = function() {
		this.hide();
	};

	// Neccessary to have mulitple uses on the same page
	var dialogName = "simpledialog" + iteration;

	// Instantiate the Dialog
	YAHOO.admin.container.simpledialog1 = new YAHOO.widget.SimpleDialog(dialogName, 
																			{
																				width: "400px",
																				fixedcenter: true,
																				visible: false,
																				draggable: true,
																				close: true,
																				text: message,
																				icon: YAHOO.widget.SimpleDialog.ICON_HELP,
																				constraintoviewport: true,
																				buttons: [ 	{ text: yesText, handler:handleYes, isDefault:true },
																							{ text: noText,  handler:handleNo } ]
																			} );
	YAHOO.admin.container.simpledialog1.setHeader(header);
	
	// Render the Dialog
	YAHOO.admin.container.simpledialog1.render("container");

	YAHOO.util.Event.addListener(id, "click", YAHOO.admin.container.simpledialog1.show, YAHOO.admin.container.simpledialog1, true);
	//YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.simpledialog1.hide, YAHOO.example.container.simpledialog1, true);
}