/*
 * autor: Ciro Feitosa - http://cirofeitosa.com.br
 * julho/2005
 */

function abreJanela(linkJanela, wJanela, hJanela)
{
	var no=Math.random()*10;
	if (wJanela == 0)
		wJanela = 650;
	if (hJanela == 0)
		hJanela = 400;
	window.open(linkJanela, Math.round(no), "width="+wJanela+",height="+hJanela+",toobar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function checaWebmail()
{
	var f = document.forms['form4'];
	if (f.elements['imapuser'].value == '')
	{
		alert('O campo "Login" deve ser preenchido');
		f.elements['imapuser'].focus();
		return false;
	}
	if (f.elements['pass'].value == '')
	{
		alert('O campo "Senha" deve ser preenchido');
		f.elements['pass'].focus();
		return false;
	}

	f.elements['botaover'].value = 'aguarde...';
	return true;
}

function checaContato()
{
	var f = document.forms['formulario'];
	if (f.elements['nome'].value == '')
	{
		alert('O campo "Nome" deve ser preenchido');
		f.elements['nome'].focus();
		return false;
	}
	if (f.elements['email'].value == '')
	{
		alert('O campo "E-mail" deve ser preenchido');
		f.elements['email'].focus();
		return false;
	}
	if (f.elements['mensagem'].value == '')
	{
		alert('O campo "Mensagem" deve ser preenchido');
		f.elements['mensagem'].focus();
		return false;
	}

	var parte1 = f.email.value.indexOf("@");
	var parte2 = f.email.value.indexOf(".");
	var parte3 = f.email.value.length;
	if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
		alert('O campo "E-mail" deve ser conter um endereço de e-mail válido');
		f.email.focus();
		return false;
	}

	f.elements['postar'].value = 'Aguarde...';
	return true;
}

function mostraCamada(idCamada)
{
	 document.getElementById(idCamada).style.display = 'block';
}

function ocultaCamada(idCamada)
{
	 document.getElementById(idCamada).style.display = 'none';
}

function mostra(idAtual, qtCamadas)
{
	if (idAtual == '-1')
		mostraCamada('d_info');
	else
		ocultaCamada('d_info');

	for (var i=0; i<parseInt(qtCamadas); i++)
	{
		if (idAtual == i)
		{
			mostraCamada('d'+i+'_dados');
		}
		else
		{
			ocultaCamada('d'+i+'_dados');
		}
	}
}

function mostra2(idAtual, qtCamadas)
{
	document.forms[0].elements['chk'].value = '0';

	if (idAtual == '-1')
		mostraCamada('d_info');
	else
		ocultaCamada('d_info');

	for (var i=0; i<parseInt(qtCamadas); i++)
	{
		if (idAtual == i)
		{
			mostraCamada('d'+i+'_dados');
		}
		else
		{
			ocultaCamada('d'+i+'_dados');
		}
	}
}

function mudaValorForm(campo, valor)
{
	document.forms['formulario'].elements[campo].value = valor;
}

function checaCampo(campo, valor, tam)
{
	if (tam > 1)
		document.forms['formulario2'].elements[campo][valor].checked = true;
	else
		document.forms['formulario2'].elements[campo].checked = true;
	mudaValorForm('chk', valor);
}

function download(path, idDownload)
{
//	abreJanela(path+'/site/download/'+idDownload, 1, 1);
	abreJanela('site/download/'+idDownload, 1, 1);
}

/********************************************************
* Jonas Raoni Soares Silva
* http://www.joninhas.ath.cx:666
********************************************************/

addEvent = function(o, e, f){
    var a, r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [o[e]] : []);
    r[r.length] = f, o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(f in r)
            a = r[f], a.call ? a.call(o, e) : (o._ = a, o._(e), o._ = null);
        e = null;
    }
};
removeEvent = function(o, e, f){
    for(var i in e = o["_on" + e])
        if(e[i] == f)
            return delete e[i];
    return false;
};

MaskInput = function( f, m ){ //v1.0
    for( var i in ( !/^(.)\^(.*)$/.test( m ) && f.setAttribute( 'maxlength', m.length ), { keypress: 0, keyup: 1 } ) )
        addEvent( f, i, function( e ){
            var patterns = { "1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ }, rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8 };
            function validChar( c, rule ){
                var r = rules[rule] || 0;
                for( var i = 1; i <= r; i<<=1 )
                    if( r & i && patterns[i].test( c ) )
                        break;
                return i <= r || c == rule;
            }
            var k, mC, r, c = String.fromCharCode( k = e.key ), l = f.value.length;
            ( !k || k == 8 ? 1 : ( r = /^(.)\^(.*)$/.exec( m ) ) && ( r[0] = r[2].indexOf( c ) + 1 ) + 1 ? r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : validChar( c, r[1] ) || r[0] : ( l = ( f.value += m.substr( l, ( r = /[A|9|C|\*]/i.exec( m.substr( l ) ) ) ? r.index : l ) ).length ) < m.length && validChar( c, m.charAt( l ) ) ) || e.preventDefault();
        } );
};

autoTab = function(){ //v1.0
    for( var d, f = ( d = document ).forms, i = f.length; i; addEvent( f[--i], "keyup", function( e ){
        var k = e.key, el = ( e = e.target ).form.elements;
        if ( e.value.length >= ( e.getAttribute( "maxlength" ) || e.value.length + 1 ) && /[\wÀ-ÿ ]/.test( String.fromCharCode( k ) ) ){
            for ( k = el.length; el[--k] != e; );
            while( !el[ k = ++k * ( k < el.length ) ].type );
            el[k].focus();
        }
    } ) );
};


/*
 * image protection
 * autores:
 * Ciro Feitosa - http://cirofeitosa.com.br
 * QuirkSMode - http://www.quirksmode.org/js/improt.html
 */
var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;
var msg = 'Esta imagem é protegida por direitos autorais.\nQualquer divulgação não autorizada estará\nsujeita a penas de Lei.';
var x,y,x1,y1,copyAttempt;

function clique()
{
	if (event.button==2||event.button==3)
		oncontextmenu='return false';
}

function init()
{
	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
	}
}

function checkIt(e)
{
	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}

window.onload = init;
document.onmousedown = clique;
document.oncontextmenu = new Function("return false;");
