﻿// JScript File
//variaveis globais
var html;

 function getDetalhes(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){
        var url = "AjaxPages/indexAjax.aspx";
        var pars = "_con="+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 str = "<div class='positionNovidade'>";
     for(var i =0; i < node.length; i++){
        var img = node[i].getElementsByTagName("Img")[0].firstChild.nodeValue;
        var desc = node[i].getElementsByTagName("Detalhes")[0].firstChild.nodeValue;
        str += "<img src='images/noticia/"+img +"' align='left' /><a href='#' onclick='return false;'>"+desc+"</a>";
        str +="<ul><li onclick=forward();><a title='voltar' href='#' onmousedown=forward(); onKeyDown=forward(); >voltar</a></li><ul>";
        str+="</div>";
     }
     html = $("containerNovidades").innerHTML;
     $("containerNovidades").innerHTML = str;
     window.scrollTo(0,408);
    }
   
   function forward(){
     if(html != ""){
        $("containerNovidades").innerHTML = html;
     }
     html = "";
   }
   

   //inicialze events Window
   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,608);
         setTimeout("$('solTitle').focus()",5);
        }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){
           window.location = "solucoes.aspx?_con="+id;
    }
    
    function readPortfolio(id,e){
        window.location = "portfolio.aspx?_pro="+id;
    }
    
    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('Você precisa digitar nome e e-mail para efetuar o cadastro.')}
    }
    
    function respSucesso(xml){
       alert("Informações enviadas. Obrigado!");
       $("txtName").value= "Nome";
       $("txtMail").value= "E-mail";
    }
    
   var pos;
   function keyValues(){
    var pos= $("txtBusca").value;
    var space = 0;
    for(var j =0; j < pos.length; j++){
         if(pos.charAt(j) == " "){
            space = space + 1;
         }
    }
    
    var url = "AjaxPages/ajaxBusca.aspx";
    var pars = "qryKey="+pos;
    var myAjax = new Ajax.Request(url, 
    {
 	    method: 'GET',
	    parameters: pars, 
	    cache:false,
	    onComplete: sliceValues

    });
  

    }

    function sliceValues(xmlResp){
      var nodes = xmlResp.responseXML.getElementsByTagName("Item");
      if(nodes.length == 0){$("options").style.display = 'none';}
      var ul = "<ul id='ulContainer'>";
      var cont = 0;
      var listItens = new Array(nodes.length);
      
      for (var i = 0; i < nodes.length; i++)
      {     
        prod = nodes[i];
        id = prod.getElementsByTagName("Id")[0].firstChild.nodeValue;
        name = prod.getElementsByTagName("Nome")[0].firstChild.nodeValue;
        var qry = name;
        var ate;
        for(var j =0; j < qry.length; j++){
          if(j >= qry.indexOf(pos)){
             if(qry.charAt(j) != " "){
             ate = j;
             }else{j = qry.length + 1;}
          }
        }
        var w =0;
        var strSlice = 0; 
        for(var t =0; t < qry.length ; t++){
            if(t >= qry.indexOf(pos)){
             if(qry.charAt(t) != " " || ate <= w){
               ++w;
               strSlice= t;
             }else{t = qry.length + 1;}
          }
        }
        
        var li = qry.slice(qry.indexOf(pos),t + 1);
        var a =unescape(li);
        listItens[cont] = "<li><a href='#' onclick='replaceValues(this);'> "+a+" </a></li>";
        ++cont;
     }
     for(var n = 0; n < listItens.length; n++){
        ul += listItens[n];
     }
     ul += "</ul>";
     
     $("options").innerHTML = ul;
      if(nodes.length != 0){$("options").style.display = 'block';}
      
     pos = "";
     
     $("options").onmouseover = function(){
      this.style.display = 'block';
     }
     
     $("options").onmouseout = function(){
      this.style.display = 'none';
     }
    
   }
    
    function replaceValues(str){
      $("txtBusca").value = str.innerHTML;
    }
    
    function search(){
     var qry0=$("txtBusca").value;
     var letter = qry0.substring(0,1).toUpperCase();
     var qry0= qry0.replace(qry0.substring(0,1), letter);
     var aLetters = qry0.slice(" ");
     var qry1= qry0.toLowerCase();

     var qry2= qry0.toUpperCase();

     alert(aLetters);
     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;
         for (j = 0; j < aTitle.length; j++){
              for(var a=0; a < aLetters.length; a++){
                  if($(aTitle[j]).innerHTML.search(aLetters[a]) > -1){
                     alert(aLetters[a]);
                     $(aTitle[j]).style.backgroundColor = "yellow";
                  }
              }
         }
           for (j = 0; j < aRes.length; j++){
                for(var a=0; a < aLetters.length; a++){
                  if($(aRes[j]).innerHTML.search(aLetters[a]) > -1){
                     $(aTitle[j]).style.backgroundColor = "Silver";
                  }
                }   
         }
     }
    }
    
    function populateCookies(c){
      var coo = 'listaBuscados'+ LerCookie("cont") +"=";
      document.cookie = coo + $("txtBusca").value; 
      var cont = parseInt(LerCookie("cont"));
      for(var i=0; i < cont; i++){
        alert(LerCookie("listaBuscados"+ i));
      }
    
    }
     // Função para ler o cookie.
    function LerCookie(strCookie)
    {
        var strNomeIgual = strCookie + "=";
        var arrCookies = document.cookie.split(';');

        for(var i = 0; i < arrCookies.length; i++)
        {
            var strValorCookie = arrCookies[i];
            while(strValorCookie.charAt(0) == ' ')
            {
                strValorCookie = strValorCookie.substring(1, strValorCookie.length);
            }
            if(strValorCookie.indexOf(strNomeIgual) == 0)
            {
                return strValorCookie.substring(strNomeIgual.length, strValorCookie.length);
            }
        }
        return null;
    }

//Função para deletar cookies
    function clearCookies(name)
    {
        document.cookie = name+'=; expires=-1';

    }