﻿// JScript File
 //inicialze event mouseOver e mouseDown no menu
   window.onload = iniciar;
 
   function iniciar(){
    var nodes = $("menu").getElementsByTagName("div");
    for(var i = 0; i < nodes.length; i++){
        var div = nodes[i];
        if(div.className != "menuSelect"){
            div.onmouseover = function(){
                 this.style.backgroundColor = "#458bc0";
                 var itemOver = this.getElementsByTagName("a");
                  itemOver[0].style.textDecoration = "none";
                  itemOver[0].style.color = "White";
                  this.title = itemOver[0].title;
            }
            div.onmouseout = function(){
                 this.style.backgroundColor = "White";
                 var item = this.getElementsByTagName("a");
                 item[0].style.color = "#458bc0";
                 item[0].style.textDecoration = "underline";
                 this.title = item[0].title;
            }
        }else{
               var item = div.getElementsByTagName("a");
               div.title = item[0].title;
        }
    }
 
   }
    function hideWater(obj, name){
      if(obj.value != '' && obj.value == name){ 
         obj.value= '';
      }
    }
    function blockWater(obj, name){
      if(obj.value == '' && obj.value != name){
         obj.value= name;
      }
    }
    
 function font(tipo){
      var nodesA = $("containerConteudo").getElementsByTagName("a");
      var nodesSpan = $("containerConteudo").getElementsByTagName("span");
      for(var x =0; x < nodesA.length; x++){
          if(nodesA[x].className != "" && nodesA[x].className != "titleBoxBold"  && nodesA[x].className != "titleNoticiaBold"){
             var value = nodesA[x].style.fontSize.replace("px","");
              if(value != 'undefined' && tipo == "-"){
                 try{
                    if(value == ""){
                       value = 13;
                    }else if(value > 12){
                        value = parseInt(value) - 1;
                    }
                 }catch (e){
                      value = 13;
                 }
                 
              }else if(value != 'undefined' && tipo == "+"){
                   try{
                      if(value == ""){
                       value = 15;
                      }else if(value < 16){
                            value = parseInt(value) + 1;
                      }
                      }catch(e){
                               value = 15;
                       }
              }
              if(value > 12){
             
                nodesA[x].style.fontSize = value+ "px";
              }else if(value < 16){
                nodesA[x].style.fontSize = value+ "px";
              }
          }
      }
       for(var i =0; i < nodesSpan.length; i++){
             var value = nodesSpan[i].style.fontSize.replace("px","");
              if(value != 'undefined' && tipo == "-"){
                 try{
                    if(value == ""){
                       value = 13;
                    }else if(value > 12){
                        value = parseInt(value) - 1;
                    }
                 }catch (e){
                      value = 13;
                 }
                 
              }else if(value != 'undefined' && tipo == "+"){
                   try{
                      if(value == ""){
                       value = 15;
                      }else if(value < 16){
                            value = parseInt(value) + 1;
                      }
                      }catch(e){
                               value = 15;
                       }
              }
              if(value > 12){
             
                nodesSpan[i].style.fontSize = value+ "px";
              }else if(value < 16){
                nodesSpan[i].style.fontSize = value+ "px";
              }
      }

    }
    
    function getConteudo()
    {
     try{
         window.scrollTo(0,408);
         setTimeout("$('titleContato').focus()",1);
        }catch(e){alert(e.message);}
    }
    
    function validar(lct)
    {
      if(lct.id == "xhtml"){
         window.open('http://validator.w3.org/check?uri=http%3A%2F%2Fwww.cdigital.com.br%2Findex.aspx');
      }else if(lct.id == "css")
      {
        window.open('http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.cdigital.com.br%2Findex.aspx');
      }
    }
    function readTag(id,e){
        var isIE = document.all;
        var key = (isIE)? e.keyCode : e.which;
        var name = window.navigator.appName;
        if(name.indexOf("Opera") > -1){key = 13;}
        if(key == 0){key = event.button;}
        if(key == 13 || key == 1 || e.Button == 1){
            if(id == 20){
              $("titleContato").innerHTML = "Formulário de contato";
              $("formEmail").style.display = 'block'; 
              var nodes = $("containerSolucoes").getElementsByTagName("div");
                  for(var i = 0; i < nodes.length; i++){
                     if(nodes[i].className == "positionNovidade"){
                        nodes[i].innerHTML = "";
                     }
                  } 
             window.scrollTo(0,408);
             setTimeout("$('titleContato').focus()",1);
            }else{
                  var nodes = $("containerSolucoes").getElementsByTagName("div");
                  for(var i = 0; i < nodes.length; i++){
                     if(nodes[i].id == "formEmail"){
                        $("formEmail").style.display = 'none';
                     }
                  }
       
                  getDetalhes(id,e);
                 }
        }
    }
    
     function getDetalhes(id,e){

          var url = "AjaxPages/ajaxContato.aspx";
          var pars = "_cat="+id;
          var myAjax = new Ajax.Request(url, 
          {
        	    method: 'GET',
                parameters: pars, 
                cache:false,
                onComplete: ProcessarResposta

          });
     }
     
         function ProcessarResposta(xmlResp){
          var XMLDoc = xmlResp.responseXML; 
          var node = XMLDoc.getElementsByTagName("Conteudo");
          var catTitle="";
          var str = "";
          for(var i =0; i < node.length; i++){
             var div = "<div class='positionNovidade'>";
             catTitle = node[i].getElementsByTagName("CAT")[0].firstChild.nodeValue;
             var img = node[i].getElementsByTagName("Img")[0].firstChild.nodeValue;
             var title = node[i].getElementsByTagName("Title")[0].firstChild.nodeValue;
             var desc = node[i].getElementsByTagName("Detalhes")[0].firstChild.nodeValue;
             
             div +="<img src='images/thumb/"+img+"' align='left'/>";
             div += "<span class='titleRep' style='cursor:default;'>"+title+"</span><br />";
             div += "<span class='resRep' style='cursor:default;'>"+desc+"</span></div>";
             str += div;
          }

          var divFresh;
          var divs = $("containerSolucoes").getElementsByTagName("div");
          for(var i = 0; i < divs.length; i++){
               if(divs[i].id == "formEmail"){
                 divFresh = divs[i].innerHTML;
               }
          }
          $("containerSolucoes").innerHTML = "<div id='formEmail' style='display:none;'>"+divFresh+"</div>";
          $("containerSolucoes").innerHTML +=str;
          $("titleContato").innerHTML = catTitle;

          //Focus no conteudo seleciona pela tag ou leia mais...
         window.scrollTo(0,408);
         setTimeout("$('titleContato').focus()",1);
         }

 function limpar()
 {
  $("txtEmail").value ="";
  $("txtMsg").value ="";
  $("txtTel").value ="";
  $("txtNome").value ="";
 }
 
 function enviar()
 {
  var email = $("txtEmail").value;
  var msg = $("txtMsg").value;
  var tel = $("txtTel").value;
  var nome= $("txtNome").value;
  if(nome != "" && email != "" && msg != "" && nome != " " && email != " " && msg != " "){
    var url = "AjaxPages/contactAjax.aspx";
    var pars = "nome="+nome+"&email="+email+"&tel="+tel+"&msg="+msg;
    var myAjax = new Ajax.Request(url, 
    {
      method: 'GET',
      parameters: pars, 
      cache:false,
      onComplete: RespostaContato

    });
  }else{alert('Ops! Os campos: nome, e-mail e mensagem são obrigatórios.')}
 }
 
 function RespostaContato(xmlResp){
   $("txtEmail").value ="";
   $("txtMsg").value =xmlResp.responseText;
   $("txtTel").value ="";
   $("txtNome").value ="";
 }
 
     function enviarNews(){
      var name = $("txtName").value;
      var mail = $("txtMail").value;
      if(name != "" && mail != ""){
         var url = "AjaxPages/ajaxContato.aspx";
         var pars = "mail="+mail+"&name="+name;
         var myAjax = new Ajax.Request(url, 
         {
         	method: 'GET',
        	parameters: pars, 
        	cache:false,
        	onComplete: respSucesso

          });
      }else
           {
            alert('Ops por favor digite nome e e-mail para efetuar o cadastro.');
           }
    }
    
    function respSucesso(xml){
       alert('Informações enviadas. Obrigado!');
       $("txtName").value= "Nome";
       $("txtMail").value= "E-mail";
    }
    
    function forwardHome(){
     window.location= 'index.aspx';
    }
    
//    function search(){
//    try{
//     var qry0=$("txtBusca").value;
//     var sp = qry0.split(" ");
//     var letter = qry0.substring(0,1).toUpperCase();
//     var qry0= qry0.replace(qry0.substring(0,1), letter);
//     var qry1= qry0.toLowerCase();
//     var qry2= qry0.toUpperCase();
//     var as = document.body.getElementsByTagName("a");
//     for (var i =0; i <  as.length; i++){
//        if(as[i].id != 'undefined' && as[i].id != null){
//          if(as[i].getAttribute("rel") == "title"){
//            as[i].style.backgroundColor = "White";   
//          }
//          if(as[i].getAttribute("rel") == "res"){
//            as[i].style.backgroundColor = "White";   
//          }
//           if(as[i].getAttribute("rel") == "Index"){
//             as[i].style.backgroundColor = "Transparent";   
//           }
//         }
//     }
//     if(qry0.length > 1){
//         var aTitle = new Array();
//         var aRes = new Array();
//         var contTitle = 0;
//         var contRes = 0;
//         for (var i =0; i <  as.length; i++){
//            if(as[i].id != 'undefined' && as[i].id != null){
//              if(as[i].getAttribute("rel") == "title"){
//                aTitle[contTitle]= as[i].id;
//                ++contTitle;
//              }
//              if(as[i].getAttribute("rel") == "res"){
//                aRes[contRes]= as[i].id;
//                ++contRes;
//              }
//              if(as[i].getAttribute("rel") == "Index"){
//                 aTitle[contTitle]= as[i].id;
//                 ++contTitle;  
//              }
//             }
//         }
//         var j;
//         var ate;
//         for (j = 0; j < aTitle.length; j++){
//                  if($(aTitle[j]).innerHTML.indexOf(qry0) > -1){
//                     $(aTitle[j]).style.backgroundColor = "yellow";
//                  }
//                  if($(aTitle[j]).innerHTML.search(qry1) > -1){
//                     $(aTitle[j]).style.backgroundColor = "yellow";
//                  }
//                  if($(aTitle[j]).innerHTML.search(qry2) > -1){
//                     $(aTitle[j]).style.backgroundColor = "yellow";
//                  }

//         }
//           for (j = 0; j < aRes.length; j++){
//              if($(aRes[j]).innerHTML.search(qry0) > -1){
//                   $(aRes[j]).style.backgroundColor = "Silver";
//              }
//              if($(aRes[j]).innerHTML.search(qry1) > -1){
//                   $(aRes[j]).style.backgroundColor = "Silver";
//              }
//              if($(aRes[j]).innerHTML.search(qry2) > -1){
//                   $(aRes[j]).style.backgroundColor = "Silver";
//              }
//                
//         }
//         alert(sp[1]);
//     }
//     }catch (e){
//      //alert(e.message);
//     }
//    }
//    
//      
//    tick = setInterval(function(){
//          if($("txtBusca").value.length < 2){
//             search();
//          }
//    },500);
//    