var regType=null;
var folder = '/';

String.prototype.Reverse = function(){
	var retval = '';
	var len = this.length;
	while (len>0){
		retval+=this.substring(len-1,len);
		len--;
	}
	return retval;
}
String.prototype.decodeMail = function(){
	var retval = this.Reverse();
	retval = retval.replace(/\]dot\[/gi,'.');
	retval = retval.replace(/\]at\[/i,'@');
	return retval;
}
function initEmails(){
	//debug('MAIL TRANSFORM INIT');
	var mailLinks = $('a.nospam').each(function(i, el){
		//debug('ELEMENT FOUND: '+el);
		var temp = $(el).html().decodeMail();
		//debug(temp)
		$(el).attr('href','mailto:' + temp);
		$(el).html(temp);
	});	
}
$(document).ready(function() {	
	//Look for auth links
	initEmails();
	//initRegistration();
	$("a.fancybox").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'titleShow'		: false
	});
	
	if ($('#content.comanda-online','#main').length>0)
		initOrders();
	
});

function initOrders(){
	$.ajax({
		url:'comanda-online/load',
		beforeSend:function(){
			$('#content').html('<h1>Încărcare...</h1>')
		},
		success:function(resp){
			$('#content').html(resp);
			initOrderFunctions();
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert(textStatus);
		}
	});
}

function initOrderFunctions(){
	$('#order_form').attr('action','comenzi/send')
}

function debug(txt){
	$('#debug').html($('#debug').html()+txt+'<br />');
}

