/*-------------------------------------------------------------------------------------------------
	JQUERY
---------------------------------------------------------------------------------------------------*/

$(document).ready(function(){
						   
	carregaClip("#news_loader", "#news_lista", "news_chamadas", "");

});



/*-------------------------------------------------------------------------------------------------
	CARREGA CONTEUDO AJAX
---------------------------------------------------------------------------------------------------*/

function carregaClip(objLoad, objList, p, resto)
{
	$(objList).fadeOut("fast", function(){
		$(objLoad).fadeIn("normal");
		$.ajax({
			url: p+".php"+resto,
			cache: false,
			dataType: 'html',
			data: { localhost: 0 },
			success: function(html){
				$(objLoad).fadeOut("fast", function(){
					$(objList).fadeIn("normal"); 
					$(objList).empty().append(html);
				}); 
			}
		});	
	}); 
}


/*-------------------------------------------------------------------------------------------------
	POPUP POSIÇÃO PADRÃO
---------------------------------------------------------------------------------------------------*/

function abrePopupMenor(pagina,largura,altura,rolagem)
{
	window.open(pagina,"_blank","width="+largura+",height="+altura+",top=80,left=80,scrollbars="+rolagem+",toolbar=no,location=no,directories=no,menubar=no");
}


/*-------------------------------------------------------------------------------------------------
	VALIDA CONTACT US
---------------------------------------------------------------------------------------------------*/

function enviaContato()
{
	with (document.contact)
	{
		if (nome.value == "" || nome.value.length == 0)
		{
			alert("Fill in the name.");
			nome.focus();
			return;
		}
		
		if (email.value == "" || email.value.length == 0 || !isEmail(email))
		{
			alert("Fill in the e-mail correctly.");
			email.focus();
			return;
		}
		
		if (emailok.value != email.value)
		{
			alert("Fill in the e-mail correctly.");
			email.focus();
			return;
		}
		
		if (mensagem.value == "" || mensagem.value.length == 0)
		{
			alert("Fill in the message.");
			mensagem.focus();
			return;
		}
		
		submit();	
	}
}


/*-------------------------------------------------------------------------------------------------
	VALIDA APPLY NOW
---------------------------------------------------------------------------------------------------*/

function enviaApplyNow()
{
	with (document.applynow)
	{		
		if (programa.value == "")
		{
			alert("Fill in the program.");
			programa.focus();
			return;
		}
		
		if (destino.value == "")
		{
			alert("Fill in the destination.");
			destino.focus();
			return;
		}
		
		if (duracao.value == "")
		{
			alert("Fill in the duration.");
			duracao.focus();
			return;
		}
		
		if (inicio.value == "")
		{
			alert("Fill in the program start.");
			inicio.focus();
			return;
		}
		
		if (nome.value == "")
		{
			alert("Fill in the name.");
			nome.focus();
			return;
		}
		
		if (sobrenome.value == "")
		{
			alert("Fill in the last name.");
			sobrenome.focus();
			return;
		}
		
		if (chamado.value == "")
		{
			alert("Fill in the prefer to called.");
			chamado.focus();
			return;
		}
		
		if (email.value == "" || email.value.length == 0 || !isEmail(email))
		{
			alert("Fill in the e-mail correctly.");
			email.focus();
			return;
		}
		
		if (dia.value == "" || dia.value.length == 0)
		{
			alert("Fill in the day of bith.");
			dia.focus();
			return;
		}
		
		if (mes.value == "" || mes.value.length == 0)
		{
			alert("Fill in the month of bith.");
			mes.focus();
			return;
		}
		
		if (ano.value == "" || ano.value.length == 0)
		{
			alert("Fill in the year of bith.");
			ano.focus();
			return;
		}
		
		if (sexo[0].checked == false && sexo[1].checked == false)
		{
			alert("Fill in the gender.");
			return;
		}
		
		if (nacionalidade.value == "")
		{
			alert("Fill in the nationality.");
			nacionalidade.focus();
			return;
		}
		
		submit();	
	}
}

function applyAddDestino()
{
	p0 = "<option value=\"\" selected=\"selected\"></option>";
	p1 = "<option value=\"Porto Alegre\">Porto Alegre</option>";
	p2 = "<option value=\"Rio de Janeiro\">Rio de Janeiro</option>";
	p3 = "<option value=\"Salvador\">Salvador</option>";
	
	with (document.applynow)
	{
		if (programa.value != "Short Term LIVE Brazil") {
			$("#destino").empty().html(p0+p1+p3);
		} else {
			$("#destino").empty().html(p0+p1+p2+p3);	
		}
	}
}

function applyAddDuracao()
{
	p0 = "<option value=\"\" selected=\"selected\"></option>";
	p1 = "<option value=\"6 months\">6 months</option>";
	p2 = "<option value=\"12 months\">12 months</option>";
	
	var s0 = "";
	
	for (i=4; i<=12; i++)
	{
		s0 += "<option value=\""+i+"\">"+i+" weeks</option>";	
	}
	
	with (document.applynow)
	{
		if (programa.value != "Short Term LIVE Brazil") {
			$("#duracao").empty().html(p0+p1+p2);
		} else {
			$("#duracao").empty().html(p0+s0);	
		}
	}
}


/*-------------------------------------------------------------------------------------------------
	PADRÃO
---------------------------------------------------------------------------------------------------*/

function isEmail(str)
{
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
   
    if (typeof(str.value) == "string")
	{
        if (er.test(str.value))
		{ 
			return true; 
		}
    }
	else if (typeof(str) == "object")
	{
        if (er.test(str))
		{
           return true;
        }
    }
	else
	{
        return false;
    }
}

function isInteger(str)
{
	var er = new RegExp(/^[0-9]+$/);
	
	if (er.test(str.value)) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
}

