var performSignout = function() {
	$("#signout").replaceWith("<img src='/images/indicator.gif'/>");

     $.getJSON("/home.mat?json=signout", "",   function(json){
		 document.location = json.data; 
  });
}

/* form */
function submitCreateForm(action)
{	
	if ( ! fieldsOK() )
	{
		showPopupText('Some fields are empty or invalid');
		return;
	}

	var form = $(".createForm");
	
	if (action != undefined) {
		var url = form.attr("action");
		form.attr("action", url + "&action=" + action);
	}
	
    form.submit();	
	
	return true;
}

/* validation */
function fieldsOK()
{
	var ok = true;
	
	$(".mandatory :input:visible").each( function() {
				
		var color = "#fff";	
		
		var val = $(this).val();
		if ((val == '') || (val == 0) || (val == null))
		{
			ok = false;
			color = '#FFD1D1';
		}
		
		$(this).css('background-color', color);
	});

	$(".field .email:visible").each( function() {
		var val = $(this).val();
		 
		if (val.length > 0) { 
			var color = "#fff";	
			
			if ( (val.indexOf('@') <= 0) || (val.indexOf('.') <= 0) || (val.indexOf(' ') > 0) )
			{
				ok = false;
				color = '#FFD1D1';
			}
			
			$(this).css('background-color', color);
		}
		
	});

	return ok;
}

/* ui */
var replaceWithIndicator = function(id, text) {
	var html = "<img align='absmiddle' border='0' src='/images/indicator.gif'/>";
	if (text != undefined)
	  html = html + ' ' + text;
	  
	$(id).html(html);		
}

function showPopupURL(url, iframe, w, h) {
	if (iframe == undefined) iframe = false;
	if (w == undefined) w = '450';
	if (h == undefined) h = '370';
	  
	$.fn.colorbox({href: url, opacity: 0.5,open:true, width: w, height: h, iframe: iframe}); 
}

function showPopupHTML(html, w, h) {
	if (w == undefined) w = '450';
	if (h == undefined) h = '370';

	html = "<div class='popup'>" + html + "</div>";
	
	$.fn.colorbox({html: html, opacity: 0.5, open:true, width: w, height: h}); 
}

function showPopupText(text) {
	$.prompt(text);
}

function promptYesNo(text, callbackFunc) {
	return $.prompt(text,{ buttons: { Yes: true, No: false }, callback: callbackFunc } );
}

/* analytics */
function trackAction(actionURL)
{
	pageTracker._trackPageview(actionURL);
}
