//  Ajax Functions
//todo
var modo_1=new Array("")
//off road
var modo_2=new Array("Enduro","Motocross")
//carretera
var modo_3=new Array("No","Si")
	
var provincias_1=new Array("-","Andalucía","Asturias","Baleares","Canarias","Castilla y León","Castilla-La Mancha","...")
var provincias_2=new Array("-","Salta","San Juan","San Luis","La Rioja","La Pampa","...")
var provincias_3=new Array("-","Cali","Santamarta","Medellin","Cartagena","...")
var provincias_4=new Array("-","Aisne","Creuse","Dordogne","Essonne","Gironde ","...") 
	
function cambia_provincia(){
    //tomo el valor del select del pais elegido
    var pais
    pais = document.commentForm.pais[document.commentForm.pais.selectedIndex].value
    //miro a ver si el pais está definido
    if (pais != 0) {
       //si estaba definido, entonces coloco las opciones de la provincia correspondiente.
       //selecciono el array de provincia adecuado
       mis_provincias=eval("provincias_" + pais)
       //calculo el numero de provincias
       num_provincias = mis_provincias.length
       //marco el número de provincias en el select
       document.commentForm.provincia.length = num_provincias
       //para cada provincia del array, la introduzco en el select
       for(i=0;i<num_provincias;i++){
          document.commentForm.provincia.options[i].value=mis_provincias[i]
          document.commentForm.provincia.options[i].text=mis_provincias[i]
       }
    }else{
       //si no había provincia seleccionada, elimino las provincias del select
       document.commentForm.provincia.length = 1
       //coloco un guión en la única opción que he dejado
       document.commentForm.provincia.options[0].value = "-"
       document.commentForm.provincia.options[0].text = "-"
    }
    //marco como seleccionada la opción primera de provincia
    document.commentForm.provincia.options[0].selected = true
}

function cambia_modo(){
    var modo
    modo = document.commentForm.modo[document.commentForm.modo.selectedIndex].value
	
	//si es offroad    modo = 2 entonces;
    if (modo == 2) {
		//hago invi los "hiddens"
	   document.getElementById('textCarr').style.display = "none";
	   document.getElementById('cualCarr').style.display = "none"; 	   
       
	   mis_tipo=eval("modo_" + modo)
       num_tipo = mis_tipo.length
       document.commentForm.tipo.length = num_tipo
       for(i=0;i<num_tipo;i++){
          document.commentForm.tipo.options[i].value=mis_tipo[i]
          document.commentForm.tipo.options[i].text=mis_tipo[i]
       }
    }else{
	
		//si es carretera    modo = 3 entonces;    
		if (modo == 3) { 
			   document.getElementById('textCarr').style.display = "inline"; 
			   mis_tipo=eval("modo_" + modo)
		       num_tipo = mis_tipo.length
		       document.commentForm.tipo.length = num_tipo
		       for(i=0;i<num_tipo;i++){
		          document.commentForm.tipo.options[i].value=mis_tipo[i]
		          document.commentForm.tipo.options[i].text=mis_tipo[i]
				} 
			} else {
	   document.getElementById('textCarr').style.display = "none";
	   document.getElementById('cualCarr').style.display = "none"; 	
	   document.commentForm.tipo.length = 1
       document.commentForm.tipo.options[0].value = "-"
       document.commentForm.tipo.options[0].text = "-"
	    }
	    document.commentForm.tipo.options[0].selected = true
	}
}

function muestra_cual(){
	var cualci = document.getElementById('cualcircuito').value;
	
	if (cualci == "Si"){
			document.getElementById('cualCarr').style.display = "inline"; 
		} else {
			document.getElementById('cualCarr').style.display = "none"; 	
		}
		
}

function callPage(pageUrl, divElementId, loadinglMessage, pageErrorMessage) {
     var req;
     document.getElementById(divElementId).innerHTML = loadinglMessage;
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responsefromServer(req, divElementId, pageErrorMessage);};
     req.open("GET",pageUrl,true);
     req.send(null);
  }
function responsefromServer(req, divElementId, pageErrorMessage) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
         output = req.responseText;
         document.getElementById(divElementId).innerHTML = output;
         } else {
         document.getElementById(divElementId).innerHTML = pageErrorMessage+"\n"+output;
         }
      }
  }
  
//   DW functions
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Home Functions


function filtreBus(){

	coffroa = document.getElementById('coffroa');
	ccar = document.getElementById('ccar');
	ctodo = document.getElementById('ctodo');
	var busqtres = "";
	
	if (coffroa.src == 'http://www.locosporlasmotos.es/images/btncheck2.jpg'){
		busqtres = "off%20road";
	}

	if (ccar.src == 'http://www.locosporlasmotos.es/images/btncheck2.jpg'){
		busqtres = "carretera";
	}

	if (ctodo.src == 'http://www.locosporlasmotos.es/images/btncheck2.jpg'){
		busqtres = "todo";
	}
	
	laurl = "&bus="+busqtres;

	return laurl;
}
 
function swapImage(changeCheck){

	coffroa = document.getElementById('coffroa');
	ccar = document.getElementById('ccar');
	ctodo = document.getElementById('ctodo');

	if (changeCheck == "1"){
		coffroa.src = 'images/btncheck2.jpg';
		ccar.src = 'images/btncheck.jpg';
		ctodo.src = 'images/btncheck.jpg';
	}
	
	if (changeCheck == "2"){
		coffroa.src = 'images/btncheck.jpg';
		ccar.src = 'images/btncheck2.jpg';
		ctodo.src = 'images/btncheck.jpg';
	}

	if (changeCheck == "3"){
		coffroa.src = 'images/btncheck.jpg';
		ccar.src = 'images/btncheck.jpg';
		ctodo.src = 'images/btncheck2.jpg';
	}

} 
  
function cargaEditor() {
			alert("cargaeditor function");
			$('.editable').richeditor("holotas!");				
			};

	
function holaCateg(){
		jQuery.ajax({
        type: "GET",
        url: "acorSlides.php",
		beforeSend: function(){
			jQuery("#accorActu").html("<img src=../images/ajax-loader.gif /> Cargando...");
		},
		success: function(html){
			jQuery("#accorActu").html("").append(html);
			jQuery("#example").accordion({ 
			    autoHeight: false 
			});
		}
	});
}

function cargaFormSli(id, cont) {

		urlSlides = "cateprev.php?id="+id+"&co="+cont;
		location.href=urlSlides;		
}

function cargaDirecta(id, cont){
		
		urlSlides = "cateprev.php?id="+id+"&co="+cont;
		location.href=urlSlides;	
}

function cleanSearchFirst() {
	searchboxy = document.getElementById('search');
	if( searchboxy.value == "Ingrese palabra a buscar..."){
		searchboxy.value = "";
	}
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

function cargaLogin(){
	document.getElementById('registro').style.display = "none";
	document.getElementById('ingresa').style.display = "none";
	
	callPage('login.php', 'cargaformlogin', '<img src=../images/ajax-loader.gif  width=12 height=12 /> Cargando...', 'Error Cargando');	
}

function imgResiseHtml(imgAResis){
	var widImg = document.getElementById(imgAResis);
	
	if (widImg.width > 350 ) {
		widImg.width = '350';
	}
} 


			


