// JavaScript Document

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menu_principal");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;

/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

function Validar() {
	var bRet=true;
	if (document.frmInfo.Nombre.value == '') {
		alert('Introduzca su nombre');
		bRet=false;
		return bRet;
	}
	if (document.frmInfo.Email.value == '')
	{
		alert('Introduzca su email');
		bRet=false;
		return bRet;
	}

	if (document.frmInfo.Consulta.value == '')
	{
		alert('Introduzca la consulta');
		bRet=false;
		return bRet;
	}
	

	if (document.frmInfo.domicilio.value == '')
	{
		alert('Introduzca su domicilio');
		bRet=false;
		return bRet;
	}
	
	
	return bRet;
}

function incluir_flash(sURL, nWidth, nHeight, sColor){
	var sFlash = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' id='flash_forum' width='" + nWidth + "' height='" + nHeight + "'>";
	sFlash += "<param name='movie' value='" + sURL + "'><param name='quality' value='high'><param name='bgcolor' value='" + sColor + "'>";
	sFlash += "<embed src='" + sURL + "' type='application/x-shockwave-flash' width='" + nWidth + "' height='" + nHeight + "' bgcolor='" + sColor + "' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>";
	document.write(sFlash);
}


function abrir_callejero(){
	window.open('http://maps.google.com/maps?f=q&hl=es&q=Chauchina,+Spain&ie=UTF8&ll=37.201193,-3.772581&spn=0.006435,0.010042&z=17&iwloc=addr&om=1','Callejero','toolbar = 0,location = 0,directories = 0,status = 0,menubar = 0,scrollbars = 0 , width = 960, height = 720, left = 0,top = 0');
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  var strCookie = name + "=" + escape(value) + expire + "; path=/";
  document.cookie = strCookie;
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function addListeners()
{
	if ( document.getElementById('cmdSubmit') )
		addEvent(document.getElementById('cmdSubmit'), 'click', accessKeySetter, false);
}

function hideWarning()
{
	var elwarn = document.getElementById('warning');
	if (elwarn)  elwarn.style.display="none";
	var elsetter = document.getElementById('setter');
	if (elsetter)  elsetter.style.display="block";
}

function addEvent(elm, evType, fn,useCapture)
{
		if(elm.addEventListener)
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent)
		{
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else
		{
			elm['on' + evType] = fn;
		}
}

function accessKeySetter()
{
	//get the accesskeys values and build into a string to save in cookie
	var strKeyVals="";	
	//the phrases below, such as homelink, searchlink should be the 
	//same as the id of the element that you want these to apply to
	strKeyVals += "accesibilidad=" + document.forms['frmAccessKeys'].txthomelink.value + "@@";
	strKeyVals += "servicios=" + document.forms['frmAccessKeys'].txtsearchlink.value + "@@";
	strKeyVals += "ordenanzas=" + document.forms['frmAccessKeys'].txtheadinglink.value + "@@";
	strKeyVals += "quever=" + document.forms['frmAccessKeys'].txtapplylink.value + "@@";
	strKeyVals += "alojamiento=" + document.forms['frmAccessKeys'].txtnavlink.value + "@@";
	strKeyVals += "tramites=" + document.forms['frmAccessKeys'].txttoplink.value + "@@";
	strKeyVals += "noticias=" + document.forms['frmAccessKeys'].txttoplink.value + "@@";
	strKeyVals += "agenda=" + document.forms['frmAccessKeys'].txttoplink.value + "@@";
	strKeyVals += "telefonos=" + document.forms['frmAccessKeys'].txttoplink.value + "@@";
	strKeyVals += "transportes=" + document.forms['frmAccessKeys'].txttoplink.value + "@@";
	//this last value is to store whether the accesskeyhint should be rendered on screen
	strKeyVals += "showhint=" + document.forms['frmAccessKeys'].chkshowhint.checked + "@@";
	//write the cookie
	writeCookie("accesskeys",strKeyVals,(24*365));
}

function writeOutAccessKeys()
{
	//get the cookie
	var strAccessKeys = readCookie("accesskeys");
	//split up the values
	var arrAccesskeys = strAccessKeys.split("@@");
	//loop through the values stored (we take off two, as the last piece of data stored is a boolean)
	var blnShowHints 	= (strAccessKeys.indexOf("showhint=true")!=-1);
	
	for (i=0;i<(arrAccesskeys.length-2);i++)
		{
		var thisAccessKey 	= arrAccesskeys[i].split("=");
		var accessKayEl 	= thisAccessKey[0];
		var accessKayAttrib	= thisAccessKey[1];
		//if a value has been, apply it to the respective element using the dom
		if (accessKayAttrib.length>0)
			{
			//set the attribute
			document.getElementById(accessKayEl).setAttribute('accesskey', accessKayAttrib);
			//set a nice title attribute too
			if (document.getElementById(accessKayEl).tagName=="A")
				{
				var strLinkPhrase = document.getElementById(accessKayEl).childNodes[0].nodeValue;
				}
			if ((document.getElementById(accessKayEl).tagName=="INPUT")
			 && ((document.getElementById(accessKayEl).type=="submit")||(document.getElementById(accessKayEl).type=="button")))
				{
				var strLinkPhrase = document.getElementById(accessKayEl).value;
				}
			document.getElementById(accessKayEl).setAttribute('title', strLinkPhrase + ', access key = ' + accessKayAttrib);
			//display the accesskey hint, if that's been chosen
			if (blnShowHints)
				{
				strLinkPhrase = strLinkPhrase + " [" + accessKayAttrib + "]";
				if (document.getElementById(accessKayEl).tagName=="A")
					{
					document.getElementById(accessKayEl).childNodes[0].nodeValue = strLinkPhrase;
					}
				if (document.getElementById(accessKayEl).tagName=="INPUT")
					{
					document.getElementById(accessKayEl).value = strLinkPhrase;
					}
				}
			//finally, use the dom to fill the form fields in, according to previous choice
			document.forms['frmAccessKeys'].elements['txt' + accessKayEl].value = accessKayAttrib;
			}
		}
	//last bit to clean up - re-instate the checkbox status according to the cookie
	if (blnShowHints)
	{
	document.forms['frmAccessKeys'].elements['chkshowhint'].checked="checked";
	}
}

addEvent(window, 'load', addListeners, false);
addEvent(window, 'load', hideWarning, false);
addEvent(window, 'load', writeOutAccessKeys, false);