﻿// INÍCIO: FUNÇÃO PARA TROCA DA IMAGEM DO BOX DE LOGIN: 'NOVA BUSCA' //
var randomNumber=Math.floor(Math.random()*2)
if(randomNumber==0){
	//alert('banner homem');
	document.getElementById("ConteudoQuadro").style.background = "url('../../imagens2009/bkProfissional.jpg') no-repeat bottom right";
} else if (randomNumber==1){
	document.getElementById("ConteudoQuadro").style.background = "url('../../imagens2009/bkMenina.jpg') no-repeat bottom right";
}
// FIM: FUNÇÃO PARA TROCA DA IMAGEM DO BOX DE LOGIN: 'NOVA BUSCA' //

function acessar(url)
    {
        var path = location.pathname;	
        //document.write(path);
        var local = location.host;
        path = path.split('.');
        if (path[1]=='aspx'){
            window.location = "http://" + local + url +"?idHierarquia=1";
        }else{
			url = url.split('.');
            if(url[1]=='aspx'){
				document.write("http://" + local + "/SessionTransferCandidato.asp?simples=sim&dir=grava&url="+url[0]+"."+url[1]);
				window.location = "http://" + local + "/SessionTransferCandidato.asp?simples=sim&dir=grava&url="+url[0]+"."+url[1];
            }else{
                window.location = "http://" + local + url[0] +"."+url[1] + "?idHierarquia=1";
            }
        }
    }	

function sair()
{
	var local = location.host;
	var path = location.pathname;
	
	path=path.split('.');
	if(path[1]=='aspx'){
		window.location = "http://" + local + "/novabusca/default.aspx?param=deslogar";
	}else{
		window.location = "http://" + local + "/Candcada/Minha_Pagina_Login_Out.asp";
	}
}
    var codigoVaga;
    var isNav4, isNav, isIE;
    if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
      isNav = (navigator.appName=="Netscape") ? true : false;
      isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
      isIE8 = (navigator.appVersion.indexOf("MSIE 8.0") != -1)?true: false;
    }
    if (navigator.appName=="Netscape") {
	    isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
    }
   
    function fcnSelOnEnter(obj,nStr,e)
    {   
        var k = (isIE) ? event.keyCode : e.which;
        
        if(k=='13')
        {
            if(document.getElementById('listHolder'))
            {
                if($get('listHolder').style.display == "block")
                {
                    $get('selector').selectedIndex = 0;
                    setOption('txtBusca',$get('selector').options[0].value);
                }
                
            }
            
       }
      
   }

function loadTopo(urlCriarTopo,divRendTopo,idHierarquia)
{
	if (window.XMLHttpRequest)
	{
		xmlhttpTopo = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttpTopo = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttpTopo!= null)
	{
	    var parametro = "?idHierarquia="+idHierarquia;
	    xmlhttpTopo.open("POST",urlCriarTopo+parametro,true);
		xmlhttpTopo.send(parametro);
		xmlhttpTopo.onreadystatechange = function()
		{
			if(xmlhttpTopo.readyState == 4)
			{
				if (xmlhttpTopo.status==200)
				{
					document.getElementById(divRendTopo).innerHTML = xmlhttpTopo.responseText;
				}
				else
				{
					alert("Problemas durante o processo.\nPor favor tente novamente!!!\nErro:" + xmlhttpTopo.statusText);
					alert(xmlhttpTopo.responseText);
				}
			}
		}
	}
	return;
}
   
    function checkList(obj,nStr,e) {
    	
	    var k = (isIE) ? event.keyCode : e.which;
	    var T = findPosY(obj); 
	    var L = findPosX(obj); 
	    var list = document.getElementById('listHolder');
    	
	    if(!list) {
		    var list = document.createElement('DIV');
		    list.id = 'listHolder';
		    document.body.appendChild(list);
    		
	    }
	    if(isIE)
	    {
            list.style.top= (T+obj.offsetHeight+3);
//	        list.style.left=L;
	        list.style.display='none';
//    	    
	    }
	    else
	    {
	        list.style.top= (T+obj.offsetHeight+3+"px");
//	        list.style.left=(L+"px");
	        list.display='none';
//    	    
	    }    
        	
	    var txt=obj.value;
       
	    if (txt) {
    		
		    var str='<select class="list" TabIndex="5"'+
				    'onclick="setOption(\''+obj.id+'\',this.options[this.selectedIndex].value)"'+
				    'onkeyup="if(event.keyCode==13){setOption(\''+obj.id+'\','+
				    'this.options[this.selectedIndex].value)};if(event.keyCode==27){'+
				    'document.getElementById(\'listHolder\').style.display=\'none\';'+
				    'document.getElementById(\''+obj.id+'\').focus()};" id="selector" size="13"'+
				    'onblur="document.getElementById(\'listHolder\').style.display=\'none\';'+
				    'document.getElementById(\'txtHiddenList\').value=\'0\';"'+
				    'onfocus="document.getElementById(\'txtHiddenList\').value=\'1\';">';
			   
		    var match=false
    		 
		    var sharedString = ""; 
		    if(txt.length >=3){
    		    
			    for(a=0;a<nStr.length;a++){
			        sharedString = nStr[a].split("§");
				    if(sharedString[0].toLowerCase().indexOf(txt.toLowerCase()) > -1){
					    match=true
					    str+=('<option value="'+nStr[a].replace(/\'/gi,'’')+'">'+sharedString[0]+'</option>');
				    }
			    }
			    
		    }
		    str+='</select>'
    		
    		
		    if(match){
    		
			    list.innerHTML=str
			    list.style.display='block'
			    var sel=document.getElementById('selector')
			    
			    if(k=='40') {
			       sel.style.display = "block";
			       sel.selectedIndex = "0";
				   sel.focus();
				   
			    }
    			
			    if(k=='13'){
			       document.getElementById('listHolder').style.display='none';
			       
			       if(sel)
				   {
				    var valorDiv = sel.value.split("§");
					document.getElementById("txtBusca").value = valorDiv[0]; 
					document.getElementById("txtValorBusca").value = valorDiv[0];  
				   }
			       
    			}
			    
			    			    
		    }
	    }
    	
    }

    function setOption(obj,val){
        sharedString = val.split("§")
	    var obj=document.getElementById(obj);
    	
	    obj.value=sharedString[0]
	    obj.focus()
	    document.getElementById('listHolder').style.display='none'
	}

    function findPosX(obj){
    	
	    var curleft;
	    if(isIE && isIE8 == false)
	    {
	        curleft=-3;
	    }
	    else
	    {
	        curleft=-3;
	    }
	    if(obj.offsetParent) {
    	
		    while(obj.offsetParent){
			    curleft+=obj.offsetLeft
			    obj=obj.offsetParent;
		    }
	    } else if(obj.x)
		    curleft+=obj.x;
		    return curleft;
    }

    function findPosY(obj){
	    var curtop=0;
	    if(obj.offsetParent){
		    while(obj.offsetParent){
			    curtop+=obj.offsetTop
			    obj=obj.offsetParent;
		    }
	    } else if(obj.y)
		    curtop+=obj.y;
		    return curtop;
    }
    
        function hideList()
        {   
            
            if (document.getElementById('listHolder'))
            {
                if(document.getElementById('txtHiddenList').value == '0')
                {
                    document.getElementById('listHolder').style.display='none';
                }
            }
            
        }
        function fcnDefineBusca()
        {
            $get("txtHiddenBusca").value = "true";
            $get("txtHiddenFacet").value = "false";
        } 
        function fcnAtivaLogin()
        {
            if($get("divLogin").style.display == "none")
            {
                $get("divLogin").style.display = "block";
            }
            else
            {
                $get("divLogin").style.display = "none";
            }
        }


        function loadXMLString(txt) 
        {
        try 
          {
          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
          xmlDoc.async="false";
          xmlDoc.loadXML(txt);
          return xmlDoc; 
          }
        catch(e)
          {
          try 
            {
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(txt,"text/xml");
            return xmlDoc;
            }
          catch(e) {alert(e.message)}
          }
        return null;
        }

        var xmlhttp=null;
        var xmlDOM=null;

		function loadXMLDoc(email,senha)
        {
			loadXMLDocGenerica(email, senha, "../funcoes/verify_login_candidatoAJAX.asp");		
		}
		
		function loadXMLDocEmpresa(email,senha)
        {
			loadXMLDocGenerica(email, senha, "../funcoes/verify_login_empresaAJAX.asp");		
		}
		
        function loadXMLDocGenerica(email,senha, redirect)
        {		
           	var carrDiv = "<div id='CentralCarr' style='width:450px; height:225px;'><div class='topoQuadro'><p>Carregando</p></div><div class='conteudoQuadro'><img id=\"imgProgress\" src=\"/imagens2009/ajax-miniloader.gif\"/ style='margin:70px 0;'></div></div>";
			//<div class='TopoCarr'></div><div class='ContCarr'>
			$get('divCarregaLogin').innerHTML = carrDiv;
            $get('divLogin').style.display = "none";
            $get('divCarregaLogin').style.display = "block";
            
            var url = redirect;

       	    if (window.XMLHttpRequest)
              {
              xmlhttp=new XMLHttpRequest();
              }
            else if (window.ActiveXObject)
              {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }           

              try
              {
              xmlDOM=new ActiveXObject("Microsoft.XMLDOM");
              }
            catch(e)
              {
              try 
                {
                xmlDOM=document.implementation.createDocument("","",null);
                }
              catch(e) {alert(e.message)}
              }

             
            if (xmlhttp!=null)
            {            			
				parameters = "LOGIN=" + encodeURI(email) + "&EMAIL=" + encodeURI(email) + "&SENHA=" + encodeURI(senha);
				xmlhttp.open("POST", url, true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", parameters.length);
				xmlhttp.setRequestHeader("Connection", "close");
				xmlhttp.send(parameters);
	
				
				xmlhttp.onreadystatechange = function()				
				{
					if(xmlhttp.readyState == 1)
					{
						$get('divLogin').style.display = "none";
						$get('divCarregaLogin').style.display = "block";
					}
					if(xmlhttp.readyState == 2)
					{
						$get('divLogin').style.display = "none";
						$get('divCarregaLogin').style.display = "block";
					}
					if(xmlhttp.readyState == 3)
					{
						$get('divLogin').style.display = "none";
						$get('divCarregaLogin').style.display = "block";
					}
				    if(xmlhttp.readyState == 4)
					{
					  if (xmlhttp.status==200)
					  {
						xmlDOM = loadXMLString(unescape(xmlhttp.responseText.replace(/\+/g," ")));
						fcnRedirect(xmlDOM.getElementsByTagName("redirecionar")[0].childNodes[0].nodeValue,xmlDOM.getElementsByTagName("mensagem")[0].childNodes[0].nodeValue,xmlDOM.getElementsByTagName("status")[0].childNodes[0].nodeValue);
						
						$('#dvBanner').empty();
                        $("#dvBanner").load("/BannerAsp.aspx?pagina=" + window.location.href);
					  }
					  else
					  {
						alert("Problemas durante o processo.\nPor favor tente novamente!!!\nErro:" + xmlhttp.statusText);
					  }
					}
				}
             }
             
        return;    
	    }

        function fcnRedirect(redirecionar,mensagem,status)
        {
            if(redirecionar == "True")
            {              
                document.location = mensagem;
            }
            else
            {
                if(status == "1" || status == "2")//login incorreto
                {
					$get('divCarregaLogin').style.display = "none";
					document.getElementById('logErro').innerHTML = "<h1>Login/Senha Incorretos</h1>";
					$get('divLogin').style.display = "block";	
                }
                else if(status == "3" )
				{
					$get('divCarregaLogin').style.display = "none";
					document.getElementById('logErro').innerHTML = "<h1>"& mensagem &"</h1>";
					$get('divLogin').style.display = "block";	
				}
				else if(status == "4")
				{
					fcnTransferSessionEmpresa();
				}
				else
                {
					
                    fcnTransferSession();     
                }
            }
        }
        function fcnTransferSession()
        {
			var loginCandidato;
            var url = '../SessionTransferCandidato.asp?simples=sim&dir=grava&url=default.aspx';
            if (window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();
            }
            else if (window.ActiveXObject)
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            if (xmlhttp!=null)
            {
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);            
            }
            xmlhttp.onreadystatechange = function() 
			        {
                        if(xmlhttp.readyState == 4) 
		                { 
		                    if (xmlhttp.status !=200)
		                    {
		                        //Erro gerado na 
		                       alert("Problemas durante o processo de tranferencia de sessions!!!\n\nErro:" + xmlhttp.statusText);
		                       $.modal.close();
		                    } 
		                    else
		                    {
		                        if(codigoVaga != "login")
                                {
									loginCandidato = codigoVaga.split('$');
									enviarCurr(loginCandidato[0],loginCandidato[1]);
                                }
                                else
                                {
                                    $.modal.close();
                                }
								
								$get('divCarregaLogin').style.display = "none";
								document.getElementById('chamada').innerHTML="<div></div>";
								document.getElementById('candidato').innerHTML =  xmlDOM.getElementsByTagName("candidato")[0].childNodes[0].nodeValue;
								document.getElementById('falsoCandidato').innerHTML =  xmlDOM.getElementsByTagName("candidato")[0].childNodes[0].nodeValue;			
								$get('txtHiddenName').Value= xmlDOM.getElementsByTagName("candidato")[0].childNodes[0].nodeValue;
															
								document.frm_login_candidato.txtPlano.value = "true";
								loadTopo('MenuInclude.ashx','menuInclude',1);
								$get('divLogado').style.display = "block";
								$get('divNaoLogado').style.display = "none";
								$.modal.close();
     	                    }
		                }
                    }
         }                                  

		function fcnTransferSessionEmpresa()
        {
			var loginEmpresa;
            var url = '../SessionTransferEmpresa.asp?simples=sim&dir=grava&url=/Empresa_projeto/MinhaPagina/MinhaPagina.asp';
            if (window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();
            }
            else if (window.ActiveXObject)
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            if (xmlhttp!=null)
            {
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);            
            }
            xmlhttp.onreadystatechange = function() 
			        {
                        if(xmlhttp.readyState == 4) 
		                { 
		                    if (xmlhttp.status !=200)
		                    {
		                        //Erro gerado na 
		                       alert("Problemas durante o processo de tranferencia de sessions!!!\n\nErro:" + xmlhttp.statusText);
		                       $.modal.close();
		                    } 
		                    else
		                    {
		                        if(codigoVaga != "login")
                                {
									loginCandidato = codigoVaga.split('$');
									enviarCurr(loginCandidato[0],loginCandidato[1]);
                                }
                                else
                                {
                                    $.modal.close();
                                }
								

								$.modal.close();
     	                    }
		                }
                    }
         }
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();