function setField(which, action)
{
	campo = document.getElementById(which);
	if(action == 'clear')
	{
		switch(which)
		{
			case 'email_1':
			case 'email_2':
				if(campo.value == "Email_")
				{
					campo.value = "";
				}
			break;		
		}
	}
	else
	{
		switch(which)
		{
			case 'email_1':
			case 'email_2':
				if(campo.value == "")
				{
					campo.value = "Email_";
				}
			break;		
		}		
	}	
}

function login(which, name)
{	
	$.ajax({
	type: "POST",
	url: "/login/private/app/process.php?action=login",
	data: $('#login_'+which).serialize(),
	async: false,
	success: function(html)
		{	
			if(html == 'error2')
			{			
			$('#login_div_1').hide();
			$('#register').slideDown(600);	
			$('#register_form_container').hide(0);
			$('#register_error_container').slideDown(300);
			$('#register_alert_detail').replaceWith('<div class="register_alert_detail" id="register_alert_detail">El usuario no esta habilitado para entrar a '+name+' <div class="register_row"><a href="javascript:showRegister(3);"><div class="register_row_type left" style="margin:5px 23px 0px 0px;"ª>Cerrar</div><div class="left"><img src="/login/public/images/img/cancelar.png" /></div></a> <div class="clear"></div></div></div>');
			}
			else if(html == 'error1')
			{				
			$('#login_div_1').hide();
			$('#register').slideDown(600);	
			$('#register_form_container').hide(0);
			$('#register_error_container').slideDown(300);
			$('#register_alert_detail').replaceWith('<div class="register_alert_detail" id="register_alert_detail">Usuario y/o password incorrectos <div class="register_row"><a href="javascript:showRegister(3);"><div class="register_row_type left" style="margin:5px 23px 0px 0px;"ª>Cerrar</div><div class="left"><img src="/login/public/images/img/cancelar.png" /></div></a>  <div class="clear"></div></div></div>');
			}
			else if(html == 'error3')
			{				
			$('#login_div_1').hide();
			$('#register').slideDown(600);	
			$('#register_form_container').hide(0);
			$('#register_error_container').slideDown(300);
			$('#register_alert_detail').replaceWith('<div class="register_alert_detail" id="register_alert_detail">Su usuario ha sido deshabilitado, por favor <a href="mailto:martin@ladevi.com">contactese con el administrador</a> para reactivarlo.<div class="register_row"><a href="javascript:showRegister(3);"><div class="register_row_type left" style="margin:5px 23px 0px 0px;"ª>Cerrar</div><div class="left"><img src="/login/public/images/img/cancelar.png" /></div></a>  <div class="clear"></div></div></div>');
			}
			else
				document.location.href=html;
		}
	});
}
validateForm();
function validateForm()
{
	$.ajax({
	type: "POST",
	url: "private/app/process.php?action=validate_preregister",
	data: $('#register_form').serialize(),
	async: false,
	success: function(html)
		{
			if(html == 'ok')
			{
				submitRegister();
			}
			else
			{
				$('#register_form_container').slideUp(300);
				$('#register_error_container').slideDown(300);
				$('#register_alert_detail').replaceWith("<div class=\"register_alert_detail\" id=\"register_alert_detail\">"+html+"</div>");
			}					
		}
	});
}

function closeErrors()
{
	$('#register_form_container').slideDown(300);
	$('#register_error_container').slideUp(300);
}
	
function submitRegister()
{
	document.register_mirror.first_name.value = document.register_form.first_name.value;
	document.register_mirror.last_name.value = document.register_form.last_name.value;
	document.register_mirror.email.value = document.register_form.email.value;
	document.register_mirror.password.value = document.register_form.password.value;		
	document.register_mirror.country.value = document.register_form.country.value;
	$('#register_mirror').submit();
}

function getDocHeight() 
	{
		var D = document;
			return Math.max(
			Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			Math.max(D.body.clientHeight, D.documentElement.clientHeight)
		);
	}
	
function getDocWidth() 
	{
		var D = document;
			return Math.max(
			Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
			Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
			Math.max(D.body.clientWidth, D.documentElement.clientWidth)
		);
	}
	
function showSection(sec)
{
	if(sec == 2)
	{
		$('#sky_container').slideUp(600);	
		$('#pasto').slideUp(600);			
		$('#plane_over').hide();
		$('#cartel').hide();		
		$('#marquesina_container').hide();
		
		$('#section_1').removeClass('section_1_container');
		
		
		$("body").addClass('body_new');
		$("body").removeClass('body');
		$('#section_2_container').show();
		$('#section_2').slideDown(600);	
		$('#bajada_container').width(800);
		$('#bajada').height(102);
		$('#bajada_1').hide();
		$('#bajada_2').show();
		
	}
	if(sec == 1)
	{
		$("body").removeClass('body_new');
		$("body").addClass('body');
		$('#sky_container').slideDown(600);	
		$('#pasto').slideDown(600);			
		$('#plane_over').slideDown(600);
		$('#cartel').slideDown(600);		
		$('#marquesina_container').show();			
		$('#section_1').addClass('section_1_container');
		
		$('#section_2').slideUp(600);	
		$('#section_2_container').hide();
		$('#bajada_container').width(700);
		$('#bajada').height(125);
		$('#bajada_1').show();
		$('#bajada_2').hide();
	}
}

function showRegister(which)
{
	switch(which)
	{		
		case 1:
			$('#register').show(600);	
			$('#login_div_1').hide();
			$('#register_error_container').slideUp(600);
			$('#register_form_container').slideDown(1200);
		break;
		case 2:
			showSection(1);
			$('#register').show(600);	
			$('#login_div_1').hide();
			$('#register_error_container').slideUp(600);
			$('#register_form_container').slideDown(1200);
		break;
		case 3:
			$('#register').slideUp(600);	
			$('#register_form_container').slideDown(1200);
			$('#register_error_container').slideUp(600);
			$('#login_div_1').show();
		break;
		
	}
}

function showSelectCountry(action)
{
	if(action = 'show')
		$('#countries').show();
	else
		$('#countries').hide();
}

function setCountry(id, name)
{
	selecter = document.getElementById('country_selecter');
	id_input = document.getElementById('country');
	selecter.value = name;
	id_input.value = id;
	$('#countries').hide();
}
where = 0;
scroller_where = 0;
position = 0;

scroller_up_height = 32;
scroller_down_height = 178;
function scroll(dir)
{
	proportion = ( 146 / $('#countries_text').height());
	variable = $('#countries_text').css('margin-top');
	variable = variable.substring(0, (variable.length - 2));
	variable = parseInt(variable);
	
	if(dir > 0)
	{
		speed = 300 / dir;
		if(where != 0)
			where += dir*200;
		if(where > 0)
			where = 0;
		variable = where;
		$('#countries_text').animate({marginTop:where}, speed,'linear');
		scroller_where = -variable * proportion;		
		$('#scroll_up').animate({height:(scroller_up_height+scroller_where)}, speed,'linear');
		$('#scroll_down').animate({height:(scroller_down_height-scroller_where)}, speed,'linear');/*
		$('#scroll_up').height(scroller_up_height+scroller_where);
		$('#scroll_down').height(scroller_down_height-scroller_where);*/	
	}
	else
	{
		speed = -300 / dir;
		if(where > -($('#countries_text').height()-200))
			where +=dir*200;
		if(where < -($('#countries_text').height()-200))
			where = -($('#countries_text').height()-150);
		variable = where;
		$('#countries_text').animate({marginTop:where}, speed,'linear');
		scroller_where = -variable* proportion;	
		$('#scroll_up').animate({height:(scroller_up_height+scroller_where)}, speed,'linear');
		$('#scroll_down').animate({height:(scroller_down_height-scroller_where)}, speed,'linear');/*
		$('#scroll_up').height(scroller_up_height+scroller_where);
		$('#scroll_down').height(scroller_down_height-scroller_where);*/
	}
}


