// JavaScript Document

///////////////////////////////////////////////////
//Administração
///////////////////////////////////////////////////
//Novo
function acao()	{	}
///////////////////////////////////////////////////
//input obrigatorio correto
function inputOk(obj)	{
	var classes = obj.className;
	if (classes.indexOf("inputOk") || classes.indexOf("inputErro")) {
		var classes = obj.className;
		classes = classes.replace(/inputErro/i, "inputOk");
		obj.className = classes;
/*	}else if (obj.classNames() == 'precoOk' || obj.classNames() == 'precoErro') {
		obj.className = 'precoOk';
	}else{
		obj.className = 'dataOk';
*/	}
}
///////////////////////////////////////////////////
function novo(url)	{
	window.location = url;
	return;
}
///////////////////////////////////////////////////
//Excluir
function excluir(url, tipo, form)	{
	var cr = confirm("Deseja realmente excluir " + tipo + "?");
	if (cr == true)	{
		if (form != null)	{
			form.action = url;
			form.submit();
		}else{
			window.location = url;
		}
	}else{
		return;
	}
}
///////////////////////////////////////////////////
function atualiza (foto, arquivo) {
	foto.src = "file:///"+arquivo.value;
}
///////////////////////////////////////////////////


//muda cor input
function mudaCor (obj)	{
	obj.style.backgroundColor = '#FFFFFF';
}
//////////////////////////////////////////////////
//limpa campo
function limpaCampo (id)	{
	$(id).innerHTML = '';
}
//limpa input
function limpaInput (id, texto)	{
	if ($(id).value == 'Digite seu e-mail aqui...' || $(id).value == 'E-mail cadastrado com sucesso.' || $(id).value == 'Erro ao cadastrar e-mail.')	{
		$(id).value = texto;
	}
	$(id).style.color = '#000000';
}

//////////////////////////////////////////////////
//Valida EMAIL
function checarEmail(campo){
	x = 0;
	email=campo;
  	carac_invalido = " /:,;";
  	if (email == ""){
		return false;
  	}
  	for (i=0; i<carac_invalido.length; i++){
    	carac_errado = carac_invalido.charAt(i);
    	if (email.indexOf(carac_errado,0) > -1){
			return false;
    	}
  	}

  	atPos = email.indexOf("@",1);
  	if (atPos == -1){
		return false;
  	}

  	if (email.indexOf("@",atPos+1) != -1){
		return false;
  	}
  	periodPos = email.indexOf(".",atPos)

  	if (periodPos == -1){
		return false;
  	}

  	if (periodPos+3 > email.length){
		return false;
  	}
	return true;
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

function linki()	{
	$('textoDrive').style.color = '#000000';
}

/////////////////////////////////////////////////////
/////////////////////////////////////////////////////

// JavaScript Document
function flash(arq, x, y)	{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+x+'" height="'+y+'">');
	document.write('<param name="movie" value="'+arq+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+arq+'" width="'+x+'" height="'+y+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>');
	document.write('</object>');
}

///////////////////////////////////////////////////
///////////////////////////////////////////////////
// digitar soh numeros
///////////////////////////////////////////////////
///////////////////////////////////////////////////
var _tabIndex = "";

function _onload(){
	if( _tabIndex != "" )
		document.getElementById( _tabIndex ).focus();
}


///////////////////////////////////////////////////
onload = _onload
///////////////////////////////////////////////////

function cloneLinha( clone , destino , posicao ){
	var objClone = clone.getElementsByTagName("tr")[0].cloneNode( true );
	if( posicao == "antes" )
		destino.parentNode.insertBefore( objClone , destino );
	else
		destino.appendChild( objClone );
}

///////////////////////////////////////////////////

function removeElemento( obj , pai ){
	var newPai = pai.firstChild.nextSibling,
		elementos = pai.getElementsByTagName("tr"),
		qnt = pai.getElementsByTagName("input"),
		objDel = pai.childNodes[0].childNodes

	if( qnt.length > 1 )
		if( !newPai )
			obj.removeNode(true)
		else
			newPai.removeChild( elementos[0] );
}

///////////////////////////////////////////////////

function apagaValueCodFoto( f , v , ind ){
	f.elements[ind].value = v
}

///////////////////////////////////////////////////
Evento = function(){}
///////////////////////////////////////////////////

Evento.prototype.addEvent = function( o , t , f ){
	o.addEventListener ? o.addEventListener( t , f , true ) : o.attachEvent( "on" + t , f )
}

///////////////////////////////////////////////////

Restrict = function( f ){
	this.items = []
	this._function = f
}

///////////////////////////////////////////////////
Restrict.prototype = new Evento()
///////////////////////////////////////////////////

Restrict.prototype.addItem = function( o ){
	this.items.push( o )
}

///////////////////////////////////////////////////

Restrict.prototype.start = function(){
	for( var i = 0 ; i < this.items.length ; i++ ){
		this.addEvent( this.items[i] , "keypress" , this.restrict )
		this.items[i]._function = this._function
	}
}

///////////////////////////////////////////////////

Restrict.prototype.restrict = function( e ){
	var eDefault = e,
		e = typeof( e ) == "undefined" ? event : e,
		flag = true,
		$this = e.target ? e.target : e.srcElement
	if( e.srcElement )
			e.returnValue = $this._function( String.fromCharCode( e.keyCode ) )
		else{
			flag = !( e.keyCode == 9 || e.keyCode == 8 )
			e.cancelBubble = !flag ? false : !$this._function( String.fromCharCode( e.which ) );
			if( e.cancelBubble ){
				e.preventDefault()
				e.stopPropagation()				
			}
	}				
}
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////

///////////////////////////////////////////////////
//mascara data
///////////////////////////////////////////////////
function FormataData(Campo, teclapres){
	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");

	tam = vr.length + 1 ;

	if (tecla != 9 && tecla != 8) {
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam < 8)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2,2)+ '/' + vr.substr(4,tam-4);
	}
}
///////////////////////////////////////////////////

function checkdate( month, day, year ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: checkdate(12, 31, 2000);
    // *     returns 1: true
    // *     example 2: checkdate(2, 29, 2001);
    // *     returns 2: false
    // *     example 3: checkdate(03, 31, 2008);
    // *     returns 3: true
 
    var myDate = new Date();
    myDate.setFullYear( year, (month - 1), day );
 
    return ( (myDate.getMonth()+1) == month );
}


//////////////////////////////////////////////////
//Site
//////////////////////////////////////////////////

//altera valores do contador
function chageBDvalues (obj) {
	$('numContador').innerHTML = obj.value;
}

//select noticias e opniao
function selectNews (url, obj) {
	if (obj.value != '') {
		window.location= url+'?cod='+obj.value
	}
}


//validar comentarios
function valComment() {
	nome = $("nome").value.strip();
	if (nome.empty())	{
		alert('Digite seu Nome para prosseguir.');
		$("nome").focus();
		return;
	}
	
	email = $("email").value.strip();
	if (email.empty())	{
		alert('Digite seu E-mail para prosseguir.');
		$("email").focus();
		return;
	}else{
		if(!checarEmail(email))	{
			alert('E-mail invalido.');
			$("email").focus();
			return;
		}
	}
	
	txt = $("mensagem").value.strip();
	if (txt.empty())	{
		alert('Digite uma Mensagem para prosseguir.');
		$("mensagem").focus();
		return;
	}
	
	$("form").submit();
}

//Enviar Msg
function valMsg() {
	nome = $("nome").value.strip();
	if (nome.empty())	{
		alert('Digite seu Nome para prosseguir.');
		$("nome").focus();
		return;
	}
	
	email = $("email").value.strip();
	if (email.empty())	{
		alert('Digite seu E-mail para prosseguir.');
		$("email").focus();
		return;
	}else{
		if(!checarEmail(email))	{
			alert('E-mail invalido.');
			$("email").focus();
			return;
		}
	}
	
	txt = $("mensagem").value.strip();
	if (txt.empty())	{
		alert('Digite uma Mensagem para prosseguir.');
		$("mensagem").focus();
		return;
	}
	
	url = 'enviar_email.php?email='+email+'&nome='+nome+'&texto='+txt;
	
	area = 'response';
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
	
	//$("form").submit();
}

///////////////////////////////////////////////////
//validar cadastro de newsletter
function valNews() {
	email = $("emailNews").value.strip();
	if (email.empty())	{
		alert('Digite seu E-mail para prosseguir.');
		$("emailNews").focus();
		return;
	}else{
		if(!checarEmail(email))	{
			alert('E-mail invalido.');
			$("emailNews").focus();
			return;
		}
	}
	
	$("form").submit();
}

