// Copyright 2001 AgênciaClick


// Basics
var verifyTab=true
function isDef(S){return(eval('typeof('+S+')')!='undefined'&&eval('typeof('+S+')')!='unknown')}

function BUGdivIEmac(){return((is.mac&&is.ie)?'<div></div>':'')}
function BUGdivNE(){return ((is.ns4)?'<div style="position:absolute;top:-10">&nbsp;</div><link rel="stylesheet" href="../../css/boticario.css">':'')+((is.ns4&&is.win)?'<link rel="stylesheet" href="../../css/boticario_ns.css">':'')}

function toId(S){
    S=S.toLowerCase()
    if(S.indexOf('?')!=-1)S=S.substring(0,S.indexOf('?'))
    return S
}


// Forms


//novo
function DFStopTab(f){
    verifyTab=false
    f.select()
}

function DFCheckTab(){verifyTab=true}

function cFormField(f){
    if((f.value.length==f.maxLength)&&(verifyTab)){
    for(var i=0;i<f.form.length;i++){
        if(f.form[i]==f&&f.form[i+1]){f.form[i+1].focus();break}
        }
    }
}
// function cFormField(obj){
    //if(obj.value.length==obj.maxLength){
    //  for(var i=0;i<obj.form.length;i++){
    //      if(obj.form[i]==obj){obj.form[i+1].focus();break}
    //  }
    //}
//}


// Outros

// Abre um popup com telas de configurações de softwares
function PopConfig(software,numero,tamW,tamH) {
str = "pop_configs.asp?software="+software+"&numero="+numero+"&w="+tamW+"&h="+tamH
opc = "width="+tamW+" height="+tamH
  window.open(str,'popup',opc);
}

function openPopup(url,w,h,other){
    url=url.replace(/[ ]/g,'%20')
    popup=window.open(url,'popup_'+toId(url),'left=0,top=18,width='+w+',height='+h+',scrollbars=1'+((other)?','+other:''))
    other=other||''
    if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
    popup.focus()
}
function openPopupStock(url,w,h,other){
    url=url.replace(/[ ]/g,'%20')
    popup=window.open(url,'popup_'+toId(url),'left=0,top=18,width='+w+',height='+h+',scrollbars=0'+((other)?','+other:''))
    other=other||''
    if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
    popup.focus()
}

// Manipulação de SELECTs
function mOption(strId, strText, className) {
  this.id = strId;
  this.text = strText;
    this.className = className;
}
function fSetOptions(vOptions, fSelect, strSelected) {
  fSelect.length = vOptions.length;
    for (i=0; i<vOptions.length; i++) {
      fSelect.options[i].value = vOptions[i].id; 
      fSelect.options[i].text = vOptions[i].text;
            if(vOptions[i].className)fSelect.options[i].className = vOptions[i].className;
      if (vOptions[i].id==strSelected)
        fSelect.options[i].selected=true;
      }
}

function fSetOptionsSP(vOptions, fSelect, strSelected) {
  fSelect.length = vOptions.length;
    for (i=0; i<vOptions.length; i++) {
      fSelect.options[i].value = vOptions[i].id; 
      fSelect.options[i].text = vOptions[i].text;
      fSelect.options[25].selected=true;      
            if(vOptions[i].className)fSelect.options[i].className = vOptions[i].className;
      if (vOptions[i].id==strSelected)
        fSelect.options[i].selected=true;
      }
}
//Limpa campo
function clean(objCampo) {
    objCampo.value = ''
}

//Funcao para validar campo de busca das paginas
function ValidaBusca(){
    b = document.formbusca.txt_busca;
    if(b.value == ""){
        alert("Digite pelo menos uma palavra para busca!");
        b.focus();
        return false;
    }
    return true;
}

function doSel(obj) {
  var i = 0
  for (i = 0; i < obj.length; i++)
    if (obj[i].selected == true)
      if (i != 0) //ignore the first option
        eval(obj[i].value);
}

function ValidaLogin() {
    l = document.formlogin;
    if(!ValidaEmail(l)){
        return false;   
    }
    if(l.senha.value == ""){
        alert("Senha deve ser preenchido!");
        l.senha.focus();
        return false;
    }
    return true;
}

function explica(texto) {

}


function checanum(campo) {
    straux = campo.value + '#';
    i = 0;
    while (straux.charAt(i)!='#')   {
        if ( ( (straux.charAt(i)>='0') && (straux.charAt(i)<='9') ) || (straux.charAt(i)=='-') || (straux.charAt(i)=='.'))
            i++;
        else
        {
            campo.value = '';
//          campo.focus();
            return false;
        }
    }
    return true;
}

function CheckNome(campo) {
    valor = campo.value;
    for (var i=1; i < valor.length; i++) {
        if (valor.charAt(i)==" ") 
          if ((valor.charAt(i + 1)!=" ") && (valor.charAt(i + 1)!=""))
            return true;
    }
    return false;
}


function ChecaEmail(campo) {
    size=campo.value.length;
    i=1;
    numA=0;
    numP=0;
    lugarA=true;
    while (i<=size)
    {
        if (campo.value.charAt(i)!=" ") {
            if (campo.value.charAt(i)=="@") {
                numA++;
                if (campo.value.charAt(i+1)=="")
                    lugarA=false;
            }
            if (campo.value.charAt(i)==".") {
                numP++;
                if (campo.value.charAt(i+1)=="")
                    lugarA=false;
                if ( (campo.value.charAt(i+1)=="@") || (campo.value.charAt(i-1)=="@") )
                    lugarA=false;
        }
    }
    else lugarA=false;
        i++;
    }
    if ( (lugarA) && (numA==1) && (numP>0) ){
        return true;
    }
    return false;
}

function checaano(campo) {
    checanum(campo);
    if (campo.value=="")
    {
        return false;
    }
    data1=new Date();
    ano=data1.getYear();
    if (ano==99) {
        ano += 1900;
    } 
    else 
        ano += 2000;
    if (campo.value > 1800) {
        if( 1 > (ano - campo.value) )
            conf1=confirm(" Confirma o ano do seu nascimento ( " +  campo.value + " ) ?" );
        else
            return true;
            if (conf1)
          return true;
    }
    campo.value="";
    campo.focus();
    return false;
}


function checadia(campo) {
    checanum(campo);
    if (campo.value=="")
    {
        return false;
    }

    if(campo.value>31)
    {
        campo.value = '';
        campo.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function checames(campo) {
    checanum(campo);
    if (campo.value=="")
    {
        return false;
    }
    if(campo.value>12)
    {
        campo.value = '';
        campo.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function checaData(campo1, campo2, campo3) {
    dia = campo1.value;
    mes = campo2.value;
    ano = campo3.value;

    if(!checadia(campo1)){
      return false;
    }
    if (!checames(campo2)){
      return false;
    }
    if (!checaano(campo3)){
      return false;
    }
    if ((mes == 2) && (dia > 28)){
      return false;
    }
    if ((mes % 2) && (mes < 8) && (dia == 31)){
      return false;
    }
    if ((!(mes % 2)) && (mes >= 8) && (dia == 31)){
      return false;
    }
    
    return true;
}

function ValidaEmail(l) {
    if(l.email.value == "") {
        alert("E-mail deve ser preenchido!");
        l.email.focus();
        return false;
    }else{
        if(!ChecaEmail(l.email)) {
            alert("Digite um e-mail válido!");
            l.email.focus();
            return false;
        }
    }
    return true;
}

function SubmitFormComprar() {
    if (document.Login.logon_name.value == "" || document.Login.logon_name.value.length == 0){
        alert("Por favor, preencha o campo 'email'.");
        document.Login.logon_name.focus();
        return;
    }
    if (document.Login.user_security_password.value == "" || document.Login.user_security_password.value.length == 0){
        alert("Por favor, preencha o campo 'senha'.");
        document.Login.user_security_password.focus();      
        return;
    }
    document.Login.submit();
}

// Mecanismo de abertura e fechamento dos sub-itens
function cMn(obj) {
    var objChld = getElm(obj.id + '_int');
    var parentId = obj.parentNode.id;
    var posN1 = parentId.substr( parentId.indexOf('_') , parentId.lastIndexOf('_') - 5 );
    
    if(objChld.style.display == ''){
        objChld.style.display = 'none';
        if (obj.id.indexOf('mn1')!=-1) cI('bl_' + obj.id,'bl_mn_mais');
        if (obj.id.indexOf('mn2')!=-1) cI('bl_' + obj.id,'bl_mn_mais_int');
    }else{
        objChld.style.display = '';
        if (obj.id.indexOf('mn1')!=-1) cI('bl_' + obj.id,'bl_mn_menos');
        if (obj.id.indexOf('mn2')!=-1) cI('bl_' + obj.id,'bl_mn_menos_int');
    }
}

function getElm(id){return (is.ie4)?d.all[id]:d.getElementById(id)}

