//Detección navegador
if (navigator.appName == "Netscape") {
  		document.write("<link rel='stylesheet' href='../css/firefox.css' type='text/css'>");
}
if (navigator.appName == "Microsoft Internet Explorer") {
  		var a = new Array;
  		a = navigator.appVersion.split(";");

  		if (a[1].indexOf ("MSIE 6") == 1) {
    		document.write("<link rel='stylesheet' href='../css/ie6.css' type='text/css'>");
  		} 
  		else if (a[1].indexOf ("MSIE 7") == 1) {
    		document.write("<link rel='stylesheet' href='../css/ie7.css' type='text/css'>");
  		} else {
    		document.write("<link rel='stylesheet' href='../css/ie8.css' type='text/css'>");
  		}
}
//Calendario
var fecha=new Date();
var mes = fecha.getMonth() +1;
var ano = fecha.getFullYear();
var sentido = -1;
var mes2;
//rollover bitwell
bitwell = new Image();
bitwell.src = '../img/rollover_bitwell.gif';
//imágenes idiomas
ingles = new Image();
ingles.src = '../img/bandera_eng_rollover.gif';
español = new Image();
español.src = '../img/bandera_esp_rollover.gif';

//Ajax:
var http = createRequestObject();
var httpPost = createRequestObject();
var timeOut = "";

function createRequestObject() {
	var ro;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		ro = new XMLHttpRequest();
	}
	return ro;
}  

function compra(id,idioma){
               var http = createRequestObject();
				http.open("get", "cuenta.php?id="+id+"&lng="+idioma);
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){             
                                if (http.responseText) { 
										var resp = http.responseText;
										
										document.getElementById('cuenta').innerHTML = resp;
                                }
                        } 
                };
                http.send(null);  
  
}

function calenda(operacion,idioma){
if (operacion==-1) {
	document.getElementById('calendario2').innerHTML = document.getElementById('calendario1').innerHTML;
	cambia = 'calendario1';
} else {
	document.getElementById('calendario1').innerHTML = document.getElementById('calendario2').innerHTML;
	cambia = 'calendario2';
}
               var http = createRequestObject();
				mes = mes + operacion;
				if (mes == 0) {
					mes = 12;
					ano = ano - 1;
				}
				if (mes == 13) {
					mes = 1;
					ano = ano + 1;
				}
				if (sentido == operacion) {
					http.open("get", "calendar.php?mes="+mes+"&ano="+ano+"&idioma="+idioma);
				} else {
					mes2 = (mes + operacion);
					if (mes2 == 0) {
						mes2 = 12;
						ano = ano - 1;
					}
					if (mes2 == 13) {
						mes2 = 1;
						ano = ano + 1;
					}
					http.open("get", "calendar.php?mes="+mes2+"&ano="+ano+"&idioma="+idioma);
				}
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){             
                                if (http.responseText) { 
										var resp = http.responseText;
										
										document.getElementById(cambia).innerHTML = resp;
                                }
                        } 
                };
                http.send(null);  
  
}


//Javascript:
function busca(idioma) {
  location.href = 'http://www.monegroscycles.com/index.php?pag=tienda&lng='+idioma+'&query='+document.getElementById('buscar').value;
}
function borra_blg(id,pagina,idioma) {
if (confirm("¿Estás segur@ de querer eliminar este registro?") == true) {
	document.location.href = "http://www.monegroscycles.com/index.php?pag=blog&del="+id+"&lng="+idioma+"&p="+pagina;
}
}
function borra_img(id,pagina,idioma) {
if (confirm("¿Estás segur@ de querer eliminar esta categoría (todas las fotos de la categoría serán eliminadas)?") == true) {
	document.location.href = "index.php?pag=en_la_carretera&del="+id+"&lng="+idioma+"&p="+pagina;
}
}
function borra_pht(id,pagina,galeria,idioma) {
if (confirm("¿Estás segur@ de querer eliminar esta foto?") == true) {
	document.location.href = "index.php?pag=en_la_carretera&gal="+galeria+"&del="+id+"&lng="+idioma+"&p="+pagina;
}
}
function reemplaza(actual,elegido){
  variable = location.href
  location.href = variable.replace(actual,elegido);
}
function foco(objeto){
  objeto.style.border='#c8baaa 2px solid';
}
function defoco(objeto){
  objeto.style.border='#7a1413 2px solid';
}
function validar_o(e) { 
var tecla = window.event.keyCode;
if (tecla < 48 || tecla > 57) {
		window.event.keyCode=0;
}
}
function validar_orden(valor,maximo) { 
  if (parseInt(document.getElementById('orden').value) > parseInt(maximo))  {
    document.getElementById('orden').value = valor;
  }
}
function agendea() {
/*Primero el título */
if(document.getElementById('titulo').value=='')
{
	alert("Necesito un título.")
	return
}
/* la forma de verificar el formato es la que ya comentamos */
var f=document.getElementById("fecha").value;
re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
if(f.length==0 || !re.exec(f))
{
	alert("La fecha no tiene formato correcto.")
	return
}
 
/* comprobamos que la fecha es válida */
var d = new Date()
/* la función tiene como entrada: año, mes, día */
d.setFullYear(f.substring(6,10), 
	      f.substring(3,5)-1,
	      f.substring(0,2))
 
/* ¿el mes del objeto Date es el mes introducido por el usuario?
   OJO: getMonth() devuelve el número de mes del 0 al 11
 
   ¿el día del objeto Date es el día introducido por el usuario?
   OJO: getDate() devuelve el día del mes */
if(d.getMonth() != f.substring(3,5)-1 
	|| d.getDate() != f.substring(0,2))
{
	alert("Fecha no válida.")
	return
}
document.form_agenda.submit();
}

function ingles_on() {
  document.getElementById('ingles').src = ingles.src;
}
function ingles_off() {
  document.getElementById('ingles').src = '../img/bandera_eng_normal.gif'; 
}
function español_on() {
  document.getElementById('español').src = español.src; 
}
function español_off() {
  document.getElementById('español').src = '../img/bandera_esp_normal.gif'; 
}

function ver_menu(num) {
	ocultar_menu_h();
	switch(num){
	case 1:
		document.getElementById("submenu1").style.visibility = "visible";
		document.getElementById("submenu2").style.visibility = "hidden";
		document.getElementById("submenu3").style.visibility = "hidden";
		break;	
	case 2:
		document.getElementById("submenu1").style.visibility = "hidden";
		document.getElementById("submenu2").style.visibility = "visible";
		document.getElementById("submenu3").style.visibility = "hidden";
		break;
	case 3:
		document.getElementById("submenu1").style.visibility = "hidden";
		document.getElementById("submenu2").style.visibility = "hidden";
		document.getElementById("submenu3").style.visibility = "visible";
		break;	}
}
function ocultar_menu(num) {
	switch(num){
	case 1:
		document.getElementById("submenu1").style.visibility = "hidden";
	case 2:
		document.getElementById("submenu2").style.visibility = "hidden";
	case 3:
		document.getElementById("submenu3").style.visibility = "hidden";	}
}
function ver_menu_h() {
		ocultar_menu(1);
		ocultar_menu(2);
		document.getElementById("bitwell").src = '../img/rollover_bitwell.gif'; 
		document.getElementById("cascos").style.visibility = "visible";
		document.getElementById("accesorios").style.visibility = "visible";
}
function ocultar_menu_h() {
		document.getElementById("bitwell").src = '../img/bitwell.gif'; 
		document.getElementById("cascos").style.visibility = "hidden";
		document.getElementById("accesorios").style.visibility = "hidden";
}

