Cookie = function () {
   this.Cookie = Cookie;
   this.name = 'Cookie';
   this.version = '1.0v';
}

var cookie = Cookie.prototype;

cookie.getValue = function(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
}

cookie.get = function(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen) 
    {           
     var j = i + alen;                             
     if (document.cookie.substring(i, j) == arg)
        return this.getValue(j);
        i = document.cookie.indexOf(" ", i) + 1;
     if (i == 0) 
        break; 
    }
    return null;
}

cookie.set = function(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if(expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

cookie.remove = function(name, path, domain) {
	if ( this.get( name ) ) 
	document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") +	( ( domain ) ? ";domain=" + domain : "" ) +	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

Passaporte = function (codSite,codRecurso) {
   this.Passaporte = Passaporte;
   this.name = 'Passaporte';
   this.version = '1.0v';
   this.Cookie = new Cookie();
   
   this.codSite = codSite;
   this.codRecurso = codRecurso; 
}

var passaporte = Passaporte.prototype;

passaporte.logout = function()
{
	href = location.href;
	myDomain = href.substring(0,href.lastIndexOf('/')) + '/';
	myDomain = myDomain.replace(/.*\.(.*\..*\..*?)\/.*$/,"$1");
	this.Cookie.remove('usuario',"/",myDomain);
	this.Cookie.remove('Ticket',"/",myDomain);
	//this.display();
}

passaporte.login = function()
{
	var inputUsuarioValue = document.getElementById("loginHlp.autenticacaoTo.login").value;
	var inputSenhaValue = document.getElementById("loginHlp.autenticacaoTo.senha").value;
	if((inputUsuarioValue.indexOf('@',0) < 0) || (!inputSenhaValue)) {
		
		alert('Email e senha são obrigatórios.');
				
	} else {
		document.loginForm.submit();
	}
}

passaporte.enviarSenha = function()
{
	document.loginFormReenviarSenha.submit();
}

passaporte.cadastro = function()
{
	location.href = 'http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=130&COD_RECURSO=1229&URL_RETORNO='+window.location.href
}

passaporte.cadastropopup = function()
{
	var link = 'http://passaporte.abril.com.br/autenticaUsuario.do?metodo=checarTipoAutenticacao&COD_SITE=130&COD_RECURSO=1229&URL_RETORNO='+window.location.href
	popscroll(link,800,650,'Passaporte');
}

passaporte.display = function() {

	this.pstLogin = document.getElementById('pstLogin');
	this.pstLogout = document.getElementById('pstLogout');		
	this.pstLoginOutros = document.getElementById('pstLoginOutros');
	this.pstLogoutOutros = document.getElementById('pstLogoutOutros');
	

	if( ( this.Cookie.get('usuario') == null) && (this.Cookie.get('ticket') == null) ) {
		document.loginForm.URL_RETORNO.value = window.location.href;
		this.pstLogin.style.display = 'block';
		this.pstLogout.style.display = 'none';
		if(this.pstLoginOutros){
			this.pstLoginOutros.style.display = 'block';
		}
		if(this.pstLogoutOutros){
			this.pstLogoutOutros.style.display = 'none';
		}
	} else {
		this.pstLogin.style.display = 'none';
		this.pstLogout.style.display = 'block';
		if(this.pstLoginOutros){
			this.pstLoginOutros.style.display = 'none';
		}
		if(this.pstLogoutOutros){
			this.pstLogoutOutros.style.display = 'block';
		}
	}
}

passaporte.meuRegistro = function() {
	userCookie = this.Cookie.get('usuario');

	var codigo = '';
	
	if(userCookie != null) {
		valores = userCookie.split(';');
		codigo = valores[0];
	}

	if(userCookie == null) {
		location.replace('http://passaporte.abril.com.br/alteraUsuario.do?metodo=prepararAlterarDadosUsuario&COD_SITE=' + this.codSite + '&COD_RECURSO='+this.codRecurso+'&URL_RETORNO='+window.location.href);
	} else {
		location.replace('http://passaporte.abril.com.br/alteraUsuario.do?metodo=prepararAlterarDadosUsuario&COD_SITE=' + this.codSite + '&COD_RECURSO='+this.codRecurso+'&URL_RETORNO='+window.location.href);
	}
}

passaporte.getUsuario =  function() {
	userCookie = this.Cookie.get('usuario');
	if (userCookie != null) {
		var Usuario = new Array;		
		Usuario = userCookie.split(';');		
		if (Usuario.length < 2){
		   Usuario = userCookie.split('%3B')
		}		
		for(var x=0;x < Usuario.length;x++) {
			Usuario[x] = Usuario[x].replace(/\+/gi, " ")
		}
		return Usuario;
	} else {
		return "NÃ£o existe o nome do usuÃ¡rio.";
	}
};

passaporte.keySubmit = function(e) {
    try {
        var key = ( window.event ) ? window.event.keyCode : e.which;
        if ( key == 13 ) {
            this.login();
        }
    }catch(e){}
}
 	 
 	 
 	 