function writeMail(a,d){document.write('<a href="mailto:' + a + '@'+ d + '">' + a + '@' + d +'<\/a>');}
function writeMailEx(a,d,text){document.write ('<a href="mailto:' + a + '@'+ d + '">' + text +'<\/a>');}

YAHOO.namespace("denator.dialogs");

YAHOO.util.Event.onDOMReady(function () {
	
	var handleCancel = function() {
		this.cancel();
	};
	
	var handleSubmit = function() {
	    document.getElementById('msgback').innerHTML = 'processing please wait ...';
	    this.submit();
	};

	var handleSuccess = function(o) {
	    var response = o.responseText;
	    if(response == "ok") {
	    	YAHOO.denator.dialogs.login.hide();
	    	location.reload(true); // we are logged in, reload page
	    }else{
	    	document.getElementById("msgback").innerHTML = response;  // display error
	    }
	};
	
	var handleFailure = function(o) {
		//alert("Submission failed: " + o.responseText);
	};

    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("loginDialog", "yui-pe-content");

	// Instantiate the Dialog
	YAHOO.denator.dialogs.login = new YAHOO.widget.Dialog("loginDialog", 
							{ width : "300px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  zindex : 200,
							  modal : true,
							  hideaftersubmit : false
							});

	// Wire up the success and failure handlers
	YAHOO.denator.dialogs.login.callback = {
		success: handleSuccess,
		failure: handleFailure
	};
		
	// Render the Dialog
	YAHOO.denator.dialogs.login.render();
	
	YAHOO.util.Event.addListener('buttonLogin',  'click', handleSubmit, YAHOO.denator.dialogs.login, true);
	YAHOO.util.Event.addListener('buttonCancel', 'click', handleCancel, YAHOO.denator.dialogs.login, true);
});

