function debug(val){
	$('#debug').html(val);
}

function redirect(url, new_window){
	if(new_window){
		window.open(url);
	}else{
		window.location.href=url;
	}
}

function consolePopup(url){
	win = window.open(url, "theconsole", "width="+screen.width+",height="+screen.height+",status=yes,scrollbars=yes,resizable=yes, toolbar=no,status=no, menubar=no, location=no ,directories=no, top=0, left=0");
   	win.focus();
}

function checkAddressAvailability(){
	
	var url = '/index.php?action=checkAddressAvailability&address=' + $('#email_local').val() + '@' + $('#email_domain').val();
	
	$.ajax({
		type: "GET",
		url: url,
		success: function(response){
			try{
				
				if(response == 1){
					$('#nameisfree').show();
					$('#nameisoccupied').hide();
					return;
				}
				
				$('#nameisfree').hide();
				$('#nameisoccupied').show();
			}
			catch(e){ }
			
		},  
		beforeSend: function(){
		},
		complete: function(){
		}
	});
	
}

function updateRemainingChars(e, max_chars){
	
	// truncate if required
	if($(e).val().length > max_chars){
		$(e).val( $(e).val().substring(0, max_chars) );
	}
		
	$('#remainingchars').html(max_chars - $(e).val().length);
}

function updateSMSToSend(e, max_chars){
	
	var chars = $(e).val().length;
	var number_sms = Math.ceil($(e).val().length / 153);
		
	$('#numbersms').html(number_sms);
}


