// JavaScript Document
var valorCookie, idiomaAtual;
valorCookie = getCookie("IAPO");

if(valorCookie == null)
	valorCookie = "";

if( valorCookie.indexOf("idioma=Ingles") != -1 ) { // Inglês selecionado
	idiomaAtual = "Ingles"

	txt_branco = "The field ";
	txt_branco2 = " is required.";
	txt_email = "The e-mail address is invalid.";
	txt_data = "The date is invalid. (dd/mm/yyyy)";
	txt_numero1 = "The field ";
	txt_numero2 = " must contain only numbers.";
	txt_url1 = "The field ";
	txt_url2 = " contain an invalid URL.";
	txt_cartaoCredito = "The credit card number is invalid";
	txt_codSeguranca = "The security code must be 3 characters";
	txt_dataValidadeCartao = "Invalid expiration date";
	txt_temCerteza = "Are you sure?";
	txt_senha = "Password";
	
} else if( valorCookie.indexOf("idioma=Espanhol") != -1 ) { // Espanhol selecionado
	idiomaAtual = "Espanhol"

	txt_branco = "El campo ";
	txt_branco2 = " debe llenarse.";
	txt_email = "El e-mail debe ser una dirección de e-mail válida.";
	txt_data = "¡El formato de la fecha no es válido!";
	txt_numero1 = "El campo ";
	txt_numero2 = " debe contener solamente números.";
	txt_url1 = "El campo ";
	txt_url2 = " no contiene una dirección válida";
	txt_cartaoCredito = "El número de la tarjeta de crédito no es válido";
	txt_codSeguranca = "El código de seguridad debe tener 3 caracteres";
	txt_dataValidadeCartao = "Fecha de expiración no válida.";
	txt_temCerteza = "¿Está seguro?";
	txt_senha = "Contraseña";
	
} else {
	idiomaAtual = "Portugues"
	
	txt_branco = "O campo ";
	txt_branco2 = " deve ser preenchido.";
	txt_email = "O e-mail deve ser um endereço de e-mail válido.";
	txt_data = "O formato da data é inválido!";
	txt_numero1 = "O campo ";
	txt_numero2 = " deve conter apenas números.";
	txt_url1 = "O campo ";
	txt_url2 = " não contém um endereço válido.";
	txt_cartaoCredito = "O número do cartão de crédito é inválido";
	txt_codSeguranca = "O código de segurança deve ter 3 caracteres";
	txt_dataValidadeCartao = "Data de validade inválida."
	txt_temCerteza = "Tem certeza?";	
	txt_senha = "Senha";
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

// Limpa o texto do campo quando este recebe o foco
function limpaTextoCampo(campo) {
	if (campo.value==campo.defaultValue) {
		campo.value = "";
	}
}

// Restaura o texto original caso não tenha sido digitado nada
function restauraTextoCampo(campo) {
	if (campo.value=="") {
		campo.value = campo.defaultValue;
	}
}

function limpaPassword( campo ){
 	txt_campo = campo.value
 	if( txt_campo == txt_senha ){
  		campo.value = "";
  		return;
 	}
 
 	if( txt_campo == "" ){
   		campo.value = txt_senha;
 	}
}

function TrocarInputType(oldObject, oType) {
	var newObject = document.createElement('input');
	newObject.type = oType;
		
	if( (oldObject.value == "Senha:" && oType == "password") || (oldObject.value == '' && oType == "text") ) {
		if(oldObject.size) newObject.size = oldObject.size;
		if(oldObject.value) newObject.value = oldObject.value;
		if(oldObject.name) newObject.name = oldObject.name;
		if(oldObject.id) newObject.id = oldObject.id;
		if(oldObject.className) newObject.className = oldObject.className;
		if(oldObject.defaultValue) newObject.defaultValue = oldObject.defaultValue;
		
		if(oldObject.onfocus) newObject.onfocus = oldObject.onfocus;
		if(oldObject.onblur) newObject.onblur = oldObject.onblur;	
	
		oldObject.parentNode.replaceChild(newObject,oldObject);
		
		if(oType == "password") {
			newObject.focus();
			newObject.focus();
			limpaTextoCampo(newObject);
		} else {
			newObject.value = "Senha:";
		}		
	}
	
	return newObject;
}
