//Função Para Replace!
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }
    return str;
}


var orFSize=11;

function CtrlFontSize(type,cmd1,cmd2,cmd3)
{
	if(type=="me")
	{
		if(orFSize>11)
		orFSize-=2;
		ById(cmd1).style.fontSize=orFSize;
		ById(cmd2).style.fontSize=orFSize;
		ById(cmd3).style.fontSize=orFSize;
	}else{
		if(orFSize<=20)
		orFSize+=2;
		ById(cmd1).style.fontSize=orFSize;
		ById(cmd2).style.fontSize=orFSize;
		ById(cmd3).style.fontSize=orFSize;
	}
}


/*CHECAGEM DO FORMULÁRIO DE CONTATO*/

function checkContato(){
	
	var pnome = ById('pnome').value;
	var email = ById('email').value;
	
	var mensagem = ById('mensagem').value;
	
	if(pnome == ""){	
		alert("Campo Requerido (Nome)!")
		ById('pnome').focus();	
	}else if(email == ""){
		alert("Campo Requerido (E-Mail)!");
		ById('email').focus();
	}else if(!eh_email(email)){
		alert("E-mail inválido!");
		ById('email').focus();	
	}else if(mensagem == ""){
		alert("Campo Requerido (Mensagem)!");
		ById('mensagem').focus();
	}else{
		document.contato.submit();
	}
}

//Checa se uma data é válida

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2078;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("O formato da data terá de ser: dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Entre com um mês válido!")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Entre com um dia válido!")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Entre com um ano de quatro dígitos válido entre  "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Entre com uma data válida!");
		return false
	}
return true
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/


/* MOSTRAR OU OCULTAR UMA CAMADA */
function sh_layer(camada){
	eval("var stats=document.getElementById('"+camada+"').style.display;");
	if(stats=="block"){
		eval("document.getElementById('"+camada+"').style.display='none';");
		}else{
			eval("document.getElementById('"+camada+"').style.display='block';");
			}
	
	}
/*xx MOSTRAR OU OCULTAR UMA CAMADA xx*/

/*CHECAGEM DO FORMULÁRIO DE MENSAGENS DO FÓRUM*/
function checkFrmForum(){
	var autor = document.frmMensagem.autor.value;
	var email = document.frmMensagem.email.value;
	
	autor = replaceAll(autor," ","");
	email = replaceAll(email," ","");
	
	if(autor == ""){	
		alert("Campo Requerido (Autor)!")
		document.frmMensagem.autor.focus();	
	}else if(email == ""){
		alert("Campo Requerido (E-Mail)!");
		document.frmMensagem.email.focus();
	}else if(!eh_email(email)){
		alert("E-mail inválido!");
		document.frmMensagem.email.focus();	
	}else{
		document.frmMensagem.submit();
	}
}
/*FIM DA CHECAGEM DO FORMULÁRIO DE MENSAGENS DO FÓRUM*/


/*
Função para validação de CPF
*/
function isCPF(st) {
if (st == "")
return (false);
l = st.length;

//aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
if ((l == 9) || (l == 8))
{
for (i = l ; i < 10; i++)
{
st = '0' + st
}
}
l = st.length;
st2 = "";
for (i = 0; i < l; i++) {
caracter = st.substring(i,i+1);
if ((caracter >= '0') && (caracter <= '9'));
st2 = st2 + caracter;
}
if ((st2.length > 11) || (st2.length < 10))
return (false);
if (st2.length==10)
st2 = '0' + st2;
digito1 = st2.substring(9,10);
digito2 = st2.substring(10,11);
digito1 = parseInt(digito1,10);
digito2 = parseInt(digito2,10);
sum = 0; mul = 10;
for (i = 0; i < 9 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10) * mul;
sum += tproduct;
mul--;
}
dig1 = ( sum % 11 );
if ( dig1==0 || dig1==1 )
dig1=0;
else
dig1 = 11 - dig1;
if (dig1!=digito1)
return (false);
sum = 0;
mul = 11;
for (i = 0; i < 10 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10)*mul;
sum += tproduct;
mul--;
}
dig2 = (sum % 11);
if ( dig2==0 || dig2==1 )
dig2=0;
else
dig2 = 11 - dig2;
if (dig2 != digito2)
return (false);
return (true);
}
/*
Fim da Função para validação do CPF
*/

/*
Função para validação de e-mail
*/
function eh_email(mail){
var ret = false;
if (typeof(mail) != "undefined"){
mail = mail.match(/(\w+)@(.+)\.(\w+)$/);
if (mail != null){
if ((mail[3].length==2) || (mail[3].length==3))
ret = true;
}
}
return ret;
}
/*
Fim da função de validação de e-mail
*/

/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Função para validação de preenchimento dos campos do formulário de cadastro
*/
function CheckCad(){

	var CADASTRO_NOME 				= ById('primeiro_nome').value;
	var CADASTRO_EMAIL 				= ById('email').value;

if (CADASTRO_NOME == ""){
		alert("Campo Requerido (Nome)!")
		ById('primeiro_nome').focus();
	}
	else if(CADASTRO_EMAIL == ""){
		alert("Campo Requerido (E-mail)!")
		ById('email').focus();
	}
	else if(!eh_email(CADASTRO_EMAIL)){
		alert("E-mail inválido!")
		ById('email').focus();
	}
	else{
		//alert("Tudo Ok!")
		ById('CadAdd').submit();
	}
}
/*
Fim da função de validação de preenchimento dos campos do formulário de cadastro
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/


/* ====================================================== */
var cell
var colorCell

// funções para hover das ceculas
function CellOver(cell,colorCell)
{
	eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
function CellOut(cell,colorCell)
{
	eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
/* ====================================================== */


/*=============================================
Função do menu de categorias da loja virtual
==============================================*/
function changeCat(cat,num,numDiv)
{
eval("var optionFine=document.all."+cat+".style.visibility;");

	if(optionFine == "visible")
	{
		eval("document.all."+cat+".style.visibility='hidden'");
		eval("document.all."+cat+".style.overflow='hidden'");
		eval("document.all.sp"+numDiv+".src='imagens/plus.gif';");
	}else{
		for(var i=1;i<=num;i++)
		{
			eval("document.all.tabela"+i+".style.visibility='hidden';");
			eval("document.all.tabela"+i+".style.overflow='hidden';");
			eval("document.all.sp"+i+".src='imagens/plus.gif';");
		}
	eval("document.all."+cat+".style.visibility='visible'");
	eval("document.all."+cat+".style.overflow='visible'");
	eval("document.all.sp"+numDiv+".src='imagens/minus.gif';");
	}
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/


/* ====================================================== */
// ativa ou desativa o botao de cadastro
function checkAceito()
{
	if(document.all.aceito.value == "yes")
	{
		document.all.btenviar.disabled = true;
		document.all.aceito.value = "no";
	}else{
		document.all.btenviar.disabled = false;
		document.all.aceito.value = "yes";
	}
}
/* ====================================================== */

function showtxt(){
	var emailShow = ById('eMailNewsLetter');

	if(emailShow.value == ''){
		emailShow.value = ' Digite seu e-mail'
	}
}

function hidetxt(){
var emailHide = ById('eMailNewsLetter');

	if(emailHide.value == ' Digite seu e-mail'){
		emailHide.value='';
	}
}

function getBrowser()
{
	if(window.XMLHttpRequest)
	{
		return "mozilla";
	}
	else if(window.ActiveXObject)
	{
		return "ie";
	}
}
 
function doXMLRequester()
{
	if(getBrowser() == "ie")
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(getBrowser() == "mozilla")
	{
		return new XMLHttpRequest();
	}
}


// **************************************************
// * Calendário
// * Autor : Peter M Jordan - uranking@uranking.com *
// * página: www.uranking.com                       *
// **************************************************

// construindo o calendário
function popdate(obj,div,tam,ddd)
{
    if (ddd) 
    {
        day = ""
        mmonth = ""
        ano = ""
        c = 1
        char = ""
        for (s=0;s<parseInt(ddd.length);s++)
        {
            char = ddd.substr(s,1)
            if (char == "/") 
            {
                c++; 
                s++; 
                char = ddd.substr(s,1);
            }
            if (c==1) day    += char
            if (c==2) mmonth += char
            if (c==3) ano    += char
        }
        ddd = mmonth + "/" + day + "/" + ano
    }
  
    if(!ddd) {today = new Date()} else {today = new Date(ddd)}
    date_Form = eval (obj)
    if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
  
    ano = today.getFullYear();
    mmonth = today.getMonth ();
    day = today.toString ().substr (8,2)
  
    umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
    days_Feb = (!(ano % 4) ? 29 : 28)
    days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

    if ((mmonth < 0) || (mmonth > 11))  alert(mmonth)
    if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
    if ((mmonth + 1) == 12) {month_next  = 0;  year_next  = ano + 1} else {month_next  = mmonth + 1; year_next  = ano}
    txt  = "<table bgcolor='#eeeeee' style='border:1px solid #333333;' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"' class=fonte_padrao>"
    txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF'><tr>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString()  + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
    txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>x</b></a></td></tr></table></td></tr>"
    txt += "<tr><td colspan='7' align='right' bgcolor='#eeeeee' class='mes'>" + ano.toString()
    txt += " " + umonth[mmonth] + " <div id='popd' style='position:absolute'></div></td></tr>"
    txt += "<tr bgcolor='#333333'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
    today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
    diainicio = today1.getDay () + 1;
    week = d = 1
    start = false;

    for (n=1;n<= 42;n++) 
    {
        if (week == 1)  txt += "<tr bgcolor='#eeeeee' align=left>"
        if (week==diainicio) {start = true}
        if (d > days[mmonth]) {start=false}
        if (start) 
        {
            dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
            day_dat   = dat.toString().substr(0,10)
            day_today  = date_Form.toString().substr(0,10)
            year_dat  = dat.getFullYear ()
            year_today = date_Form.getFullYear ()
            colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
			var mmonthNeo = mmonth+1;
			if(mmonthNeo<10){var mmonthNeo="0"+mmonthNeo;}
			var dNeo=d;
			if(dNeo<10){var dNeo="0"+dNeo;}
            txt += "<td"+colorcell+" align=left><a href=javascript:block('"+  dNeo + "/" + (mmonthNeo).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'>"+ dNeo.toString() + "</a></td>"
            d ++ 
        } 
        else 
        { 
            txt += "<td class='data' align=left> </td>"
        }
        week ++
        if (week == 8) 
        { 
            week = 1; txt += "</tr>"} 
        }
        txt += "</table>"
        div2 = eval (div)
        div2.innerHTML = txt 
}
  
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
  txt  = "<table bgcolor='#eeeeee' border='0' width=80 class='mes' >"
  for (n = 0; n < 12; n++) { txt += "<tr><td align=left><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
  txt += "</table>"
  popd.innerHTML = txt
}

// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
  txt  = "<table bgcolor='#eeeeee' border='0' width=160 class='mes'>"
  l = 1
  for (n=1991; n<2012; n++)
  {  if (l == 1) txt += "<tr>"
     txt += "<td align=left><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
     l++
     if (l == 4) 
        {txt += "</tr>"; l = 1 } 
  }
  txt += "</tr></table>"
  popd.innerHTML = txt 
}

// função para fechar o calendário
function force_close(div) 
    { div2 = eval (div); div2.innerHTML = ''}
    
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{ 
    force_close (div)
    obj2 = eval(obj)
    obj2.value = data 
}




/*BLOCO DE FUNÇÕES PARA DISPOSIÇÃO DE GLOSSÁRIO NA TELA*/

function getPosicaoElemento(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}


var sitShowCmd = 0;
function displayExpress(id)
{
	sitShowCmd=1;
	idCmd = "glossExpress"+id;
	ById(idCmd).style.display="block";
	
	var wDiv = ById(idCmd).offsetWidth;
	var hDiv = ById(idCmd).offsetHeight;
	
	var spLeft = getPosicaoElemento("ImgPos"+id).left;//ById("CMD"+id).offsetLeft;
	var spTop = getPosicaoElemento("ImgPos"+id).top;//ById("CMD"+id).offsetTop;
	
	var lDiv = spLeft-(wDiv/4);
	var tDiv = spTop-hDiv;
	
	ById(idCmd).style.left=lDiv;
	ById(idCmd).style.top=tDiv;
	
	//alert(id+"-"+spLeft+"-"+spTop);
}


function hideExpress(id)
{
		idCmd = "glossExpress"+id;
		ById(idCmd).style.display="none";
/*	sitShowCmd=0;
	var vrId = id;
	setTimeout("hideExpressExe("+vrId+")",10)
*/
}

function hideExpressExe(id)
{
	if(sitShowCmd==0)
	{
		idCmd = "glossExpress"+id;
		ById(idCmd).style.display="none";
	}
}