// JavaScript Document

function set_version(lg){
	
	location.href = "http://www.tcdot.com/teste/index.php?lang="+lg;
}

		$(document).ready(function() { 
			$(".box1").corner(); 
			$(".box2").corner(); 
			$("#newsletter").corner();
			$("#box-valor").corner();
		});
		

function dados_fisicos(){
	$GEBId("cnpj1").value = "";
	$GEBId("fisi").style.display = "";
	$GEBId("cpf").style.display = "";
	$GEBId("raz").style.display = "none";
	$GEBId("nomeFantasia").style.display = "none";
	$GEBId("cgc").style.display = "none";
}
function dados_juridicos(){
	$GEBId("cnpj2").value = "";
	$GEBId("fisi").style.display = "none";
	$GEBId("cpf").style.display = "none";
	$GEBId("raz").style.display = "";
	$GEBId("nomeFantasia").style.display = "";
	$GEBId("cgc").style.display = "";
}


function stripBad(string) {
    for (var i=0, output='', valid="eE+/*-0123456789.()"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
} 

function calc1(num1, num2) {	
	a = stripBad(num1) / 100;
	b = a * stripBad(num2);
	return b;
}


function setDiscount(preco, type){
	
	var strip = preco.replace(/^R\$/, "").replace(/,00$/, "");
		
		if(type == "men"){
			
			$GEBId("total").innerHTML = preco;
			$GEBId("cliTot").value = strip;
			$GEBId("discount").innerHTML = "0";
			$GEBId("period").innerHTML = "Mensal";
		}
		
		
		if(type == "tri"){
			var raz = "4";
			totTemp = strip * 3;
			totTempNum = strip * 3;
			totTemp+="";
			mark = calc1(raz, totTemp);
			factor = Math.ceil(mark);
			tot = totTempNum - factor;			
		
			$GEBId("total").innerHTML = "R$"+tot+",00";
			$GEBId("cliTot").value = tot;
			$GEBId("discount").innerHTML = raz;
			$GEBId("period").innerHTML = "Trimestral";
		}
		
		if(type == "sem"){
			var raz = "8";
			totTemp = strip * 6;
			totTempNum = strip * 6;
			totTemp+="";
			mark = calc1(raz, totTemp);
			factor = Math.ceil(mark);
			tot = totTempNum - factor;
			$GEBId("total").innerHTML = "R$"+tot+",00";
			$GEBId("cliTot").value = tot;
			$GEBId("discount").innerHTML = raz;
			$GEBId("period").innerHTML = "Semestral";
		}
		
		/*if(type == "anu"){ // anual
			var raz = "15";
			totTemp = strip * 12;
			totTempNum = strip * 12;
			totTemp+="";
			mark = calc1(raz, totTemp);
			factor = Math.ceil(mark);
			tot = totTempNum - factor;
			$GEBId("total").innerHTML = "R$"+tot+",00";
			$GEBId("cliTot").value = tot;
			$GEBId("discount").innerHTML = raz;
			$GEBId("period").innerHTML = "Anual";
		}*/
		
		var endcover = calcDate(type);
		
		$GEBId("data_fim").innerHTML = endcover;
		$GEBId("cover").value = endcover;
	
}


function calcDate(tip){

	var data = new Date();
	var mili = data.getTime();
	var unita = 86400000;
	
	if(tip == "men") var add = unita * 30;
	if(tip == "tri") var add = unita * 90;
	if(tip == "sem") var add = unita * 180;
	if(tip == "anu") var add = unita * 365;
	
	var datfim = mili + add;
	
	var final = new Date(datfim);
	
	dia = final.getDate();
	dia+="";	
	if(dia.match(/^\d$/)) dia = "0"+dia;
	
	mes = final.getMonth();
	mes++;
	mes+="";
	if(mes.match(/^\d$/)) mes = "0"+mes;
	
	ano = final.getYear();
	if(!document.all) ano+=1900;

	return dia+"/"+mes+"/"+ano;
	
}

function checknewsletter(mail){
var pattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(mail == "") {
		alert("Digite seu e-mail");
		return false;
	}else{
		if(!pattern.test(mail)){
				alert("E-mail inválido");
				return false;
		}
	}
	
}

function val_contato(form, lang){
var pattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	if(form.nome.value == "") {
		if(lang == "portugues") alert("Nome obrigatório");
		else  alert("Enter your name");
		return false;
	}
	
	if(form.email.value == "") {
		if(lang == "portugues") alert("Email obrigatório");
		else  alert("Enter your e-mail");
		return false;
	}else{
		if(!pattern.test(form.email.value)){
		if(lang == "portugues") alert("E-mail inválido");
		else  alert("Invalid e-mail address");
				return false;
		}
	}
	
	if(form.assunto.options[form.assunto.options.selectedIndex].value == 5){
	
		if(form.curriculo.value == ""){
		if(lang == "portugues") alert("Currículo obrigatório para Hospedagem Profissional");
		else  alert("For the professional option you must upload your CV");
			return false;
		}
	
	}
	
		if(form.mensagem.value == "") {
		if(lang == "portugues") alert("Mensagem obrigatório");
		else  alert("Enter your message");
		return false;
	}
	
return true;	
	
}


//////////////    support funcs   /////////////////////////////////////////////////////
function $GEBId(id,doc) { return (doc || document).getElementById(id); }

function $GEBTn(nome,doc) { return (doc || document).getElementsByTagName(nome); }
