// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function showImg(url,tit,elem){

  if (!$(elem).onclick) {
	myLightWindow.createElement(elem);
	exampleCreated = false;
  }	
}

function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name){

if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
	    c_start=c_start + c_name.length+1; 
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function ajax_do (url) {
        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
		pageTracker._trackPageview(""+ url +"" );
		
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;
		
        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

function ajax_get_pag (url, el) {

		// Has element been passed as object or id-string?
        if (typeof(el) == 'string') {
                el = document.getElementById(el);
        }
		
		// Valid el?
        if (el == null) { return false; }

        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = 'http://localhost/' + url;
        }
		
			
		// Create getfile URL
       	getfile_url = 'get_file.php?url=' + url + '&el=' + escape(el.id);

        // Do Ajax
        ajax_do (getfile_url);
		
        return true;
}


function agradece(nome,pag){
	ajax_get("lojas/agradece_contato.php?nome="+nome+"&pag="+pag+"","miolo");
}
	
function validar_campos() {
	if(document.getElementById("nome").value=="" || document.getElementById("data").value=="" ||  document.getElementById("rg").value=="" || document.getElementById("cpf").value=="" || document.getElementById("fone_residencial").value=="" || document.getElementById("ddd_residencial").value=="" || document.getElementById("endereco").value=="" || document.getElementById("numero").value=="" || document.getElementById("bairro").value=="" || document.getElementById("cep").value=="" || document.getElementById("cep2").value=="" || document.getElementById("cidade").value=="" || document.getElementById("estado").selectedIndex == 0){
	alert("Preencha corretamente todos os campos marcados com (*) antes de enviar!");
	return false;
/*}else{
	ajax_get("franquia/cadastro/envia_email.php","miolo");*/
}
}

 function pause(numberMillis)
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true)
{
now = new Date();
if (now.getTime() > exitTime)
return;
}
} 	


function scrolla(){
if (window.ActiveXObject){
setTimeout("document.getElementById('divcartilha').scrollIntoView(true);",100);
}else{
setTimeout("document.getElementById('divcartilha').scrollIntoView();",100);
}
}

function marker(secao){
document.getElementById("marker").style.display="";
switch (secao) {
	case "1":
		document.getElementById("marker").style.marginLeft="25px";
		break;
	case "2":
		document.getElementById("marker").style.marginLeft="105px";
		break;
	case "3":
		document.getElementById("marker").style.marginLeft="200px";
		break;
	case "4":
		document.getElementById("marker").style.marginLeft="280px";
		break;
	case "5":
		document.getElementById("marker").style.marginLeft="360px";
		break;
	case "6":
		document.getElementById("marker").style.marginLeft="450px";
		break;
}


}	
	
	
function revela_texto(object){
  for (var j=1; j <10; j++){
	if (j==object){
		document.getElementById("0"+j).scrollIntoView();
		document.getElementById("0"+j).style.display="";
	}else{
	 	document.getElementById("0"+j).style.display="none";
	}
  }
}


function ajax_get_ancora (url, el, ancora) {
		setCookie('path',url,'1');
		
		document.location.href = "lang.php?ancora="+ancora+"";
        
		/*
		// Has element been passed as object or id-string?
        if (typeof(el) == 'string') {
            el = document.getElementById(el);
        	el.innerHTML = "<center><img src='./images/novas/carregando.gif' vspace='5'><br><br><br><br><br></center>";
		}
	
        // Valid el?
        if (el == null) { return false; }

        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
               // url = 'http://localhost/' + url;
			    url = 'http://webftp:8090/marelli/site/' + url;
        }
		
			
		// Create getfile URL
        getfile_url = 'get_file.php?url=' + url + '&el=' + escape(el.id);

        // Do Ajax
        ajax_do (getfile_url);

		if (url.indexOf("ancora=a")!= -1){

			var browserName=navigator.appName; 
			
			if (browserName.indexOf("Explorer")!= -1) {
  				
				setTimeout("document.getElementById('"+ancora+"').scrollIntoView();",3000);

			}else{
				
				setTimeout("document.getElementById('"+ancora+"').scrollIntoView(true);",3000);
				
			}		
				
		}
        return true;
		*/
}


function ajax_get_image(url,idobj)
    {
		
		pageTracker._trackPageview(url);
			
		var objeto = document.getElementById(idobj);
		objeto.innerHTML = "<center><img src='./images/novas/carregando2.gif' vspace='5'></center>";
				
        if (window.ActiveXObject) // IE
        	req = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest) // not IE
        	req = new XMLHttpRequest();
        
        req.onreadystatechange=function() 
        {
            if (req.readyState==4)
            {
				
				pause(1200);
				objeto.innerHTML = req.responseText;
		
            }
			
					
        }
		
        req.open("GET", url, true);
        req.send(null);
		
    }

function validamailiso() {
	if(document.getElementById("txt_nome").value=="" || document.getElementById("txt_mail").value=="" ||  document.getElementById("txt_cidade").value=="" || document.getElementById("txt_comentario").value==""){
	alert("Preencha corretamente todos os campos antes de enviar!");
}else{

	ajax_get_mail("envia_email_iso.php","formiso", document.getElementById("txt_nome").value , document.getElementById("txt_mail").value, document.getElementById("txt_cidade").value, document.getElementById("txt_comentario").value);
}
}	

function ajax_get_mail (url,idobj,obj1,obj2,obj3,obj4) {

		// Has element been passed as object or id-string?
        if (typeof(el) == 'string') {
                el = document.getElementById(idobj);
        }
		
		// Valid el?
        if (el == null) { return false; }

        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = 'http://localhost/' + url;
        }
		
			
		// Create getfile URL
       	getfile_url = 'get_file.php?url=' + url +"?nome="+ obj1 +"&email="+  obj2+"&cidade="+ obj3 +"&msg="+ obj4 + '&el=' + escape(el.id);

        // Do Ajax
        ajax_do (getfile_url);
		
        return true;
}

	

	
  	
function ajax_get(url,idobj){
		setCookie('path',url,'1');
		
		document.location.href = "lang.php";
		/*
		path = getCookie('path');
		
		//alert(path+"  -   aki path");
		//alert(url+"  -   aki url");
		if(path == ""){
			createCookie('path',url,'1');
		}else{
			setCookie('path',url,'1');
		}
		
		//pause(2000);
		path_atual = getCookie('path');
					
		// testar lingua + url		
		lingua = getCookie('lingua');
		
		//alert(lingua+"  -   aki lingua");
		//alert(path_atual+"  -   aki pathatual");
	
		
		//IE e firefox
		if(lingua == "es/"){
		
			lin_url = "es/"+path_atual;
			setCookie('lingua',lingua,'1');
			//valida se a url for a index.php
			if(path_atual == "index.php" || path_atual == "./"){
				url = "home.php";
				setCookie('path',url,'1');
				ajax_get_es("home.php",idobj);
			}else{
				ajax_get_es(lin_url,idobj);
			}
		}
		
		else{
		
			if(path_atual == "index.php" || path_atual == "./"){
				url = "home.php";
				setCookie('path',url,'1');
			}
		
		pageTracker._trackPageview(""+ url +"" );
		
		var objeto = document.getElementById(idobj);
		objeto.innerHTML = "<center><img src='./images/novas/carregando.gif' vspace='5'><br><br><br><br><br><br></center>";
				
        if (window.ActiveXObject) // IE
        	req = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest) // not IE
        	req = new XMLHttpRequest();
        
        req.onreadystatechange=function() 
        {
            if (req.readyState==4)
            {
				pause(1200);
				objeto.innerHTML = req.responseText;
            }		
        }
		
        req.open("GET", url, true);
        req.send(null);
		
		}
		*/
    }

function ajax_get_es(url,idobj)
    {
		pageTracker._trackPageview(""+ url +"" );
		var objeto = document.getElementById(idobj);
		objeto.innerHTML = "<center><br><br><br><br><img src='./es/images/novas/carregando.gif' vspace='5'><br><br><br><br><br><br><br></center>";
				
        if (window.ActiveXObject) // IE
        	req = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest) // not IE
        	req = new XMLHttpRequest();
        
        req.onreadystatechange=function() 
        {
            if (req.readyState==4)
            {
				pause(1200);
				objeto.innerHTML = req.responseText;
            }		
        }
		
        req.open("GET", url, true);
        req.send(null);
		
    }


function ajax_get_server(url,idobj){
		
		
		pageTracker._trackPageview(""+ url +"" );
		
		var objeto = document.getElementById(idobj);
		objeto.innerHTML = "<center><br><br><br><br><img src='./images/iso14001/carregando_iso.gif' vspace='5'><br><br><br></center>";
				
        if (window.ActiveXObject) // IE
        	req = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest) // not IE
        	req = new XMLHttpRequest();
        
        req.onreadystatechange=function() 
        {
            if (req.readyState==4)
            {
				pause(1200);
				objeto.innerHTML = req.responseText;
            }		
        }
		
        req.open("GET", url, true);
        req.send(null);
		

    }	


function check(obj){
	setCookie('lingua',obj,'1');
	
	var noticia = document.getElementById("ancora");	
	if (noticia != null){
		 noticia = document.getElementById("ancora").value;
		 document.location.href = "lang.php?ancora="+noticia;
	}else{
		document.location.href="lang.php";
		}
}

function submit_pais(object) {
if (object == 0){
alert("Por favor selecione um País válido para realizar a consulta.");
return false;
}
else
{
ajax_get_image("menu_locais.php?id_pais=" + object +"","locais");
}
}

function submit_estado(object){
if (document.getElementById("estado").selectedIndex == 0){
alert('Por favor selecione um Estado válido para ver a localidade.');
return false;
}
else
{
ajax_get("lojas/" + document.getElementById("estado").value + "","miolo");
}
}



function ajustatbl(){
var h;
if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
    h = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
   	h = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   	//IE 4 compatible
   	h = document.body.clientHeight;
}
document.getElementById("tblgeral").style.height = h + "px";
}

