// JQUERY
$(document).ready(function() {
	$('#header #login').Watermark('Informe sua conta');
	//$('#header #senha').Watermark('digite sua senha');

	//if(!$.browser.msie || $.browser.version != 6) {
	//}
	
	// Slides Vantagens
	$(".vantagens p.titulo").click(function() {
		var $this = $(this);
		if($this.is('.menos')) {										
			$(this).removeClass("menos").addClass("mais").next("p.texto").slideToggle(300).siblings("p.texto").slideUp("slow");
		}
		else {	
			$(this).removeClass("mais").addClass("menos").next("p.texto").slideToggle(300).siblings("p.texto").slideUp("slow");
		}
		$(this).siblings().removeClass("menos").addClass("mais");
	});

	// Slide Proposta de Valor
	$(".proposta").click(function() {
		$("ul.modulos").slideDown(600);
	});
	
	$(".fechar").click(function() {
		$("ul.modulos").fadeOut(600);
	});		
		

	
	// PNGFix IE6
	$("#icone_selo_demo, #icone_selo_demo2, #promocao").pngfix();
});
// FIM JQUERY


// Pegar tamanho da tela
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  arrayScroll = new Array(scrOfX,scrOfY);
  return arrayScroll;
}

//
// FUNCOES DA LAYER BLACK E WINDOW FLOAT
//

// Configura a Layer Black para ocupar toda a altura da tela
function layer_black() {
	layer = new getObj('layer_black');	
	arr = getPageSize();
	layer.style.height = arr[1] + 'px';
}

// Muda a opacidade com fade
function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    nova_opacidade = Math.round(parseInt(fromOpacity) + (delta * stepNum));
    SetOpacity(document.getElementById(elemId), nova_opacidade);

    if (stepNum < steps) {
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
    }
    else {    
	    if (!nova_opacidade) {
	    	document.getElementById(elemId).style.display = 'none';
	    }
    }
}

var intervalo = 0;
function fadein_layer_black() {
	layer_black();
	document.getElementById('layer_black').style.display = 'block';	
	FadeOpacity('layer_black', 0, 50, 300, 15);	
	
	// Define a funcao de posicionamento para rodar em loop
	intervalo = window.setInterval("posicionar_window_float()",500);
}

function fadeout_layer_black() {
	layer_black();
	FadeOpacity('layer_black', 50, 0, 500, 15);
	
	// Desliga o intervalo de posicionamento
	clearInterval(intervalo);
	//window.setTimeout(function() { clearInterval(intervalo); }, 20000);
}

function posicionar_window_float() {	
	var win = new getObj('window');
	var win_conteudo = new getObj('win_conteudo');
	var arrW = getPageSize();
	var arrS = getScrollXY();
	
	var scrolly = arrS[1]; // Acha a posicao do scroll na tela
	var height = arrW[3]; // Acha a altura da tela (documento)	

	// Muda a posicao da janela para ficar sempre a 10% do top
	var nova_posicao = (height * 0.1) + scrolly;	
	win.style.top = nova_posicao+'px';

	// Muda o tamanho da janela para ficar do tamanho de 80% da altura da tela
	var altura_atual = document.getElementById('window').offsetHeight
	var nova_altura = Math.round((height * 0.8));
	var nova_altura_win = nova_altura - 45;
	
	
	if (altura_atual != nova_altura) {				
		win.style.height = nova_altura + 'px';
		win_conteudo.style.height = nova_altura_win + 'px';
	}	
}

function posicionar_loadingMessage() {	
	var win = new getObj('boxloadingMessage');
	var arrW = getPageSize();
	var arrS = getScrollXY();
	
	var scrolly = arrS[1]; // Acha a posicao do scroll na tela
	var height = arrW[3]; // Acha a altura da tela (documento)

	// Muda a posicao da janela para ficar sempre a 10% do top
	var nova_posicao = (height * 0.5) + scrolly;	
	win.style.top = nova_posicao+'px';	
}

//
// FIM: FUNCOES DA LAYER BLACK E WINDOW FLOAT
//

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function popUp(URL, width, height) {
	//day = new Date();
	//id = day.getTime();
	//id = 1111111;
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");	
	window.open(URL,'popupRozenlandia','height='+height+',width='+width+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0');
}

function popUpAutoatendimento(URL, width, height) {	
	window.open(URL,'popupAgoraos','height='+height+',width='+width+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0');
}

function autoatendimento_palco() {
	layer = new getObj('palco_popup');	
	arr = getPageSize();
	layer.style.height = arr[1] + 'px';
}

// Retorna o codigo da tecla pressionada
function key_press(evt) {
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	return charCode;
}

// Altera o endereco url na pagina de assinatura de acordo com o que for digitado no campo login
function alterar_url_conta() {
	campo_conta = new getObj('campo_conta');
	span_conta = new getObj('nome_conta');
	span_conta.obj.innerHTML = (!campo_conta.obj.value) ? 'nome-da-conta' : campo_conta.obj.value;
}

function so_texto(evt) {
	var charCode = key_press(evt);
	var correctos = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","z","y","w","-","_","1","2","3","4","5","6","7","8","9","0");

	cadenaTecla=(String.fromCharCode(charCode));
	if (charCode == 8 || charCode == 9 || charCode == 13 || charCode == 116) {
		return true;
	}
	for (i=0; i < correctos.length; i++) {
		if ((correctos[i] == cadenaTecla)) {
			return true;
		}
	}
	alert("Somente Letras Minusculas, Numeros, Underline e Ifen sao permitidos");
	return false;
}

function isNumberKey(evt) {
	var charCode = key_press(evt);
	var correctos = new Array("1","2","3","4","5","6","7","8","9","0");

	cadenaTecla=(String.fromCharCode(charCode));
	if (charCode == 8 || charCode == 9 || charCode == 13) {
		return true;
	}
	for (i=0; i < correctos.length; i++) {
		if ((correctos[i] == cadenaTecla)) {
			return true;
		}
	}
	return false;
}
function SubmitTheForm(form) {
	document.forms[form].submit();
}

function remover_objeto(id_objeto) {
	if (confirm("Confirma exclusão?")) {
		if (typeof(id_objeto) == 'object') {
			id_objeto.parentNode.parentNode.removeChild(id_objeto.parentNode);
		}
		else {
			var obj = new getObj(id_objeto);
			obj.obj.parentNode.parentNode.removeChild(obj.obj.parentNode);
		}
		return true;
	}
	return false;
}

// JS de Cliente

function cliente_recuperar_senha() {
	cpf = new getObj('campo_cpf');
	email = new getObj('campo_email');
	if (!email.obj.value) {
		alert("Preencha o e-mail!");
		email.obj.focus();
		return;
	}
	else if (!cpf.obj.value) {
		alert("Preencha o CPF/CNPJ!");
		cpf.obj.focus();
		return;
	}
	SubmitTheForm('form_senha');
}

// Contato

function validar_contato() {
	nome = new getObj('campo_nome');
	email = new getObj('campo_email');
	telefone = new getObj('campo_telefone');
	assunto = new getObj('campo_assunto');
	mensagem = new getObj('campo_info');
	if (!nome.obj.value) {
		alert("Digite seu nome!");
		nome.obj.focus();
		return;
	}
	if (!email.obj.value) {
		alert("Digite seu e-mail!");
		email.obj.focus();
		return;
	}
	if (!telefone.obj.value) {
		alert("Coloque seu telefone com DDD!");
		telefone.obj.focus();
		return;
	}
	if (!mensagem.obj.value) {
		alert("Digite sua mensagem!");
		mensagem.obj.focus();
		return;
	}
	SubmitTheForm('form_fale');
}

