// JavaScript Document
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{ if(popUpWin) { if(!popUpWin.closed) popUpWin.close();  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,resizable=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
//  popUpWin = open(URLStr, 'popUpWin', 'scrollbars=yes,resizable=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var popUpWin2=0;
function popUpWindowN(URLStr)
{ if(popUpWin2) { if(!popUpWin2.closed) popUpWin2.close();  }
//  popUpWin2 = open(URLStr, 'popUpWin2', 'fullscreen,toolbar=no,scrollbars=no,location=no,directories=no,status=no,menubar=no,resizable=yes');
//  popUpWin2 = open(URLStr, 'popUpWin2', 'fullscreen,resizable=yes');
popUpWin2 = open(URLStr, 'popUpWin2', 'scrollbars=no,location=no,directories=no,status=no,menubar=no, left=0, top=0, width='+screen.availWidth+', height='+screen.availHeight+'');
}


function PonEmail(nombre,dominio,extension,texto) {
	z = nombre + '@' + dominio + '.' + extension;
//	a = '<a href="mailto:'+z+'" class="mainlevel">'+texto+'</a>'; 
	a = '<a href="mailto:'+z+'">'+texto+'</a>'; 
	document.write(a);
}


//********************************************************************
// MODULO ENCARGADO DE GESTIONAR LAS VALIDACIONES DEL FORM DE RESERVAS
//********************************************************************
function formValidation(form){
if(notEmpty(form.nombre)){
if(notEmpty(form.apellidos)){
if(notEmpty(form.direccion)){
if(notEmpty(form.telefono)){
if(notEmpty(form.email)){
if(notEmpty(form.fecha_in)){
if(notEmpty(form.fecha_out)){
if(notEmpty(form.n_noches)){
if (!IsNumeric(form.telefono.value)) { 
      alert('Telefono incorrecto - Sólo debe introducir cifras');
      form.telefono.focus(); 
      return false; 
    } 
if (echeck(form.email.value)==false){
      alert('Dirección de correo incorrecta');
      form.email.focus(); 
      return false; 
    } 
if (esFecha(form.fecha_in.value)==false){
		form.fecha_in.focus(); 
		return false; 
	}
if (esFecha(form.fecha_out.value)==false){
		form.fecha_out.focus(); 
		return false; 
	}
if (form.fecha_out.value<=form.fecha_in.value){
		alert('La fecha final debe ser posterior a la inicial');
		form.fecha_out.focus(); 
		return false; 
	}

return true;
}}}}}}}}
return false;
}

//********************************************************
var dtCh= "-";
var minYear=2004;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function esFecha(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("El formato de la fecha debe ser: aaaa-mm-dd")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Por favor, introduzca un mes correcto")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Por favor, introduzca un día correcto")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Por favor, introduzca el año usando 4 dígitos entre "+minYear+" y "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Por favor, introduzca correctamente la fecha")
		return false
	}
return true
}
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){return false}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false}
		if (str.indexOf(at,(lat+1))!=-1){return false}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false}
		if (str.indexOf(dot,(lat+2))==-1){return false}
		if (str.indexOf(" ")!=-1){return false}
 		return true					
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.+";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function notEmpty(elem){
var str = elem.value;
if(str.length == 0){
	alert("Debe rellenar todos los campos obligatorios (*)");
	return false;
	} else {
	return true;
	}
}
//****************************************************************
// FIN MODULO (FORM VALIDATION)
//****************************************************************



//****************************************************************
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
    }

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
		        if (theAction == 'out') {
		            theCells[c].setAttribute('bgcolor', '', 0);
		        }else{
					theCells[c].setAttribute('bgcolor', newColor, 0);
				}
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
		        if (theAction == 'out') {
		            theCells[c].style.backgroundColor = '';
		        }else{
                	theCells[c].style.backgroundColor = newColor;
				}
            }
        }
    } // end 5

    return true;
} 
// end of the 'setPointer()' function
//****************************************************************
