//<!--

function provincias(){
	document.writeln("<option value=''></option>");
	document.writeln("<optgroup label='Andalucía' style='font-style:normal;'>");
	document.writeln("<option value='Almería'>Almería</option>");
	document.writeln("<option value='Cádiz'>Cádiz</option>");
	document.writeln("<option value='Córdoba'>Córdoba</option>");
	document.writeln("<option value='Granada'>Granada</option>");
	document.writeln("<option value='Huelva'>Huelva</option>");
	document.writeln("<option value='Jaén'>Jaén</option>");
	document.writeln("<option value='Málaga'>Málaga</option>");
	document.writeln("<option value='Sevilla'>Sevilla</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Aragón' style='font-style:normal;'>");
	document.writeln("<option value='Huesca'>Huesca</option>");
	document.writeln("<option value='Teruel'>Teruel</option>");
	document.writeln("<option value='Zaragoza'>Zaragoza</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Asturias' style='font-style:normal;'>");
	document.writeln("<option value='Asturias'>Asturias</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Baleares' style='font-style:normal;'>");
	document.writeln("<option value='Baleares'>Baleares</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Canarias' style='font-style:normal;'>");
	document.writeln("<option value='Gran Canaria'>Gran Canaria</option>");
	document.writeln("<option value='Tenerife'>Tenerife</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Cantabria' style='font-style:normal;'>");
	document.writeln("<option value='Cantabria'>Cantabria</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Castilla La Mancha' style='font-style:normal;'>");
	document.writeln("<option value='Albacete'>Albacete</option>");
	document.writeln("<option value='Ciudad Real'>Ciudad Real</option>");
	document.writeln("<option value='Cuenca'>Cuenca</option>");
	document.writeln("<option value='Guadalajara'>Guadalajara</option>");
	document.writeln("<option value='Toledo'>Toledo</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Castilla y León' style='font-style:normal;'>");
	document.writeln("<option value='Ávila'>Ávila</option>");
	document.writeln("<option value='Burgos'>Burgos</option>");
	document.writeln("<option value='León'>León</option>");
	document.writeln("<option value='Palencia'>Palencia</option>");
	document.writeln("<option value='Salamanca'>Salamanca</option>");
	document.writeln("<option value='Soria'>Soria</option>");
	document.writeln("<option value='Valladolid'>Valladolid</option>");
	document.writeln("<option value='Zamora'>Zamora</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Catalunya' style='font-style:normal;'>");
	document.writeln("<option value='Barcelona'>Barcelona</option>");
	document.writeln("<option value='Girona'>Girona</option>");
	document.writeln("<option value='Lleida'>Lleida</option>");
	document.writeln("<option value='Tarragona'>Tarragona</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Ceuta y Melilla' style='font-style:normal;'>");
	document.writeln("<option value='Ceuta'>Ceuta</option>");
	document.writeln("<option value='Melilla'>Melilla</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='C. Valenciana' style='font-style:normal;'>");
	document.writeln("<option value='Alicante'>Alicante</option>");
	document.writeln("<option value='Castellón'>Castellón</option>");
	document.writeln("<option value='Valencia'>Valencia</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Extremadura' style='font-style:normal;'>");
	document.writeln("<option value='Badajoz'>Badajoz</option>");
	document.writeln("<option value='Caceres'>Caceres</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Galicia' style='font-style:normal;'>");
	document.writeln("<option value='A Coruña'>A Coruña</option>");
	document.writeln("<option value='Lugo'>Lugo</option>");
	document.writeln("<option value='Pontevedra'>Pontevedra</option>");
	document.writeln("<option value='Ourense'>Ourense</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='La Rioja' style='font-style:normal;'>");
	document.writeln("<option value='La Rioja'>La Rioja</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Madrid' style='font-style:normal;'>");
	document.writeln("<option value='Madrid'>Madrid</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Murcia' style='font-style:normal;'>");
	document.writeln("<option value='Murcia'>Murcia</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='Navarra' style='font-style:normal;'>");
	document.writeln("<option value='Navarra'>Navarra</option>");
	document.writeln("</optgroup>");
	document.writeln("<optgroup label='País Vasco' style='font-style:normal;'>");
	document.writeln("<option value='Álava'>Álava</option>");
	document.writeln("<option value='Guipúzcoa'>Guipúzcoa</option>");
	document.writeln("<option value='Vizcaya'>Vizcaya</option>");
	document.writeln("</optgroup>");
}


/*////////////////////////////////////////////////////////////////////////////
 Dibuja una capa con opacidad dependiendo de que el browser sea IE o Mozilla
////////////////////////////////////////////////////////////////////////////*/
function divTrans(nombre,opacidadie,opacidadmoz){
	if(document.all)
		document.writeln("<div id='"+nombre+"' style='filter:alpha(opacity="+opacidadie+");'></div>");
	else
		document.writeln("<div id='"+nombre+"' style='opacity:"+opacidadmoz+";'></div>");
}

/*////////////////////////////////////////////////////////////////////////////
  Pinta una imagen en el visor de modelos
////////////////////////////////////////////////////////////////////////////*/
function pintaCelda(u,a,c){
	document.writeln("<span class='imagen_linea'>");
	document.writeln("<a href='"+c+"'>");
	document.writeln("<img src='images/"+u+"' alt='"+a+"' />");
	document.writeln("</a>");
	document.writeln("</span>");
}

/*////////////////////////////////////////////////////////////////////////////
  Control de menú y submenu
////////////////////////////////////////////////////////////////////////////*/
function Browser() {
  var ua, s, i;
  this.isIE    = false;  
  this.isNS    = false;  
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {
  var el;
  if (activeButton == null)
    return;

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  if (el == activeButton)
    return;

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

function buttonClick(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  button.blur();

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    menuInit(button.menu);
  }

  if (activeButton != null)
    resetButton(activeButton);

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {
  var button;

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {
  var x, y;

  button.className += " menuButtonActive";

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function resetButton(button) {
  removeClassName(button, "menuButtonActive");

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}


function menuMouseover(event) {
  var menu;
  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {
  var item, menu, x, y;
  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  item.className += " menuItemHighlight";

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    menuInit(item.subMenu);
  }

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  var maxX, maxY;

  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE && browser.version < 6) {
    maxX = document.body.scrollLeft + document.body.clientWidth;
    maxY = document.body.scrollTop  + document.body.clientHeight;
  }
  if (browser.isIE && browser.version >= 6) {
    maxX = document.documentElement.scrollLeft + document.documentElement.clientWidth;
    maxY = document.documentElement.scrollTop  + document.documentElement.clientHeight;
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {
  if (menu == null || menu.activeItem == null)
    return;

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

function menuInit(menu) {
  var itemList, spanList
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN")
    textEl  = null
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth 
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }
}

function getContainerWith(node, tagName, className) {
  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {
  var i, list;
  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {
  var i, curList, newList;
  if (el.className == null)
    return;
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AJAX
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// var xmlHttp: Es la variable donde se crearán los objetos XMLHttp.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var xmlHttp=newHttpObject();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// bool function newHttpObject()
//
// Crea un objeto XMLHttp. 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newHttpObject(){ 
	var objXMLHttp=null;
	
	if(window.XMLHttpRequest)
		objXMLHttp=new XMLHttpRequest();
	else 
		if(window.ActiveXObject)
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	
	return objXMLHttp;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// void function lockAll(string idformulario)
//
// Bloquea todos los elementos del formulario que tiene por id idformulario
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function lockElements(idformulario){
		var formulario=document.getElementById(idformulario);
		var i;		
		
		for(i=0;i<formulario.elements.length;i++) formulario.elements[i].disabled=true;		
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// void function unLockAll(string idformulario)
//
// Desbloquea todos los elementos del formulario que tiene por id idformulario
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function unLockElements(idformulario){
		var formulario=document.getElementById(idformulario);
		var i;		
		
		for(i=0;i<formulario.elements.length;i++) formulario.elements[i].disabled=false;		
}

// Genera las colecciones en un select a partir de la gama seleccionada
function sendMail(idformu,from,dest,subject,msg,name,tel){
	var desde=document.getElementById(from).value;
	var destino=dest;
	var asunto=subject;
	var mensaje=document.getElementById(msg).value;
	var fromname=document.getElementById(name).value;
	var telefono=document.getElementById(tel).value
	
	if(document.getElementById('nombre').value.length<1){
		alert("Indícanos tu nombre, por favor.");
		document.getElementById('nombre').focus();
		return(false);
	}
	if(document.getElementById('mail').value.length<1){
		alert("Indícanos tu e-mail, por favor.");
		document.getElementById('mail').focus();
		return(false);
	}
	if(document.getElementById('mensaje').value.length<1){
		alert("Indícanos tu consulta, por favor.");
		document.getElementById('mensaje').focus();
		return(false);
	}

	if(!document.getElementById('politica').checked){
		alert("Debes aceptar la política de privacidad");
		return(false);
	}



	
	// Bloqueo de elementos del formulario
	document.getElementById('imagen').src='interface/contacto.jpg'
	lockElements(idformu);
		
	// Comienzo de verificación mediante AJAX
	xmlHttp.open("POST","mail.php",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send("from="+desde+"&to="+destino+"&subject="+asunto+"&body="+mensaje+"&fromname="+fromname);
		
	// Función de verificación AJAX
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.respondeText=="1") document.getElementById('imagen').src='interface/sended.jpg';
			else document.getElementById('imagen').src='interface/sended.jpg';
			
			unLockElements(idformu);
		}
	}
}
function loadCountries(idformu,idpais,actual){
			selec=document.getElementById(idpais);
	
			xmlHttp=newHttpObject();
	
			if(xmlHttp==null){
				alert("Tu navegador no soporta AJAX, por favor utiliza Mozilla Firefox o Internet Explorer."); 
				return(false);
			}
			
			// Bloqueo de elementos del formulario
			//lockElements(idformu);
			
			// Comienzo de verificación mediante AJAX
			xmlHttp.open("POST","paises.php",true);
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlHttp.send("");
			
			// Función de verificación AJAX
			xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState==4){
					if(xmlHttp.responseText=="0"){
						alert("Hubo un error al generar las lineas!");
						unLockElements(idformu);
						return(false);
					}else{
						datos=xmlHttp.responseText.split(";");
						for(i=0;i<datos.length;i+=2){
							opt=document.createElement("option");
							opt.text=datos[i+1];
							opt.value=datos[i];
							selec.options[selec.options.length]=opt;
							if(actual==datos[i]){ 
								selec.options[selec.options.length-1].selected=true;
								
							}
							
						}
						//unLockElements(idformu);
					}
					loadStates('tiendas','pais','prov');
				}
			}
	}
	
	function loadStates(idform,idpaises,idprov){
			paises=document.getElementById(idpaises);
			selec=document.getElementById(idprov);
			
			xmlHttp=newHttpObject();
	
			if(xmlHttp==null){
				alert("Tu navegador no soporta AJAX, por favor utiliza Mozilla Firefox o Internet Explorer."); 
				return(false);
			}
			
			// Bloqueo de elementos del formulario
			//lockElements(idform);
			
			// Comienzo de verificación mediante AJAX
			xmlHttp.open("POST","paises.php",true);
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlHttp.send("pais="+paises.options[paises.selectedIndex].value);

			// Función de verificación AJAX
			xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState==4)
					if(xmlHttp.responseText=="0"){
						alert("Hubo un error al generar las provincias/estados!");
						//unLockElements(idform);
						return(false);
					}else{
						datos=xmlHttp.responseText.split(";");
						while(selec.options.length>0) selec.remove(0);
						if(datos.length>=2){
							opt=document.createElement("option");
							opt.text="Selecciona";
							opt.value="-1";
							selec.options[selec.options.length]=opt;
							for(i=0;i<datos.length;i+=2){
								opt=document.createElement("option");
								opt.text=datos[i+1];
								opt.value=datos[i];
								selec.options[selec.options.length]=opt;
								if(actual==datos[i]) selec.options[selec.options.length-1].selected=true;
							}
							//unLockElements(idform);
						}else{
							opt=document.createElement("option");
							opt.text="No hay provincias para este país";
							opt.value="-1";
							selec.options[selec.options.length]=opt;
							//unLockElements(idform);
						}
					}
			}
	}
//-->