// JavaScript Document
var ventana_secundaria;
function abrirVentana(){ 
//guardo la referencia de la ventana para poder utilizarla luego 
ventana_secundaria = window.open("zzzzzz.html","miventana","width=300,height=200,menubar=no") 
} 

function cerrarVentana(){ 
//la referencia de la ventana es el objeto window del popup. Lo utilizo para acceder al método close 
ventana_secundaria.close() 
} 

function trim(str)
{
  return str.replace(/^\s*|\s*$/g,"");
}

function FullFillLength(str,len,charUnit)
{
  while(trim(str).length < len)
  {
    str = charUnit + str;
  }
  return str;
}

function checkSubmit(lang)
{
  var msg;
  switch(lang)
  {
    case "SP":
        msg = "Debe seleccionar una provincia para realizar la consulta";
        break;
    case "EN":
        msg = "You must choose a region in order to carry out your query";
        break;
    case "FR":
        msg = "Vous devez sélectionner une province pour réaliser la recherche";
        break;
    case "GR":
        msg = "Sie müssen für die Anfrage eine Provinz auswählen";
        break;
    case "IT":
        msg = "È necessario selezionare una provincia per continuare";
        break;
  }
  if(trim(document.forms[0].provincia.options[document.forms[0].provincia.selectedIndex].value).length == 0)
  {
    alert(msg);
    return false;
  }
  else
  {
      changeStyle('LayerAvailability', 'on');
      var dia = FullFillLength((parseInt(document.forms[0].checkIn_Day_ID.selectedIndex)+1).toString(),2,'0');
      var mes = FullFillLength((parseInt(document.forms[0].checkIn_Month_ID.options[document.forms[0].checkIn_Month_ID.selectedIndex].value) + 1).toString(),2,'0');
      if (dia!='00') {
      document.forms[0].checkIn.value =
                           mes + '/' +
                           dia + '/' +
                           document.forms[0].checkIn_Year_ID.value;
      } else {
          //
      }
    var dateCheckIn = new Date(document.forms[0].checkIn.value);
    var date = dateCheckIn.getDate();
    date += parseInt(document.forms[0].snoches.options[document.forms[0].snoches.selectedIndex].value);
    dateCheckIn.setDate(date);
    var dateCheckOut = new Date(dateCheckIn);
    document.forms[0].checkOut.value = FullFillLength((dateCheckOut.getMonth() + 1).toString(), 2, '0') + "/" + FullFillLength(dateCheckOut.getDate().toString(), 2, '0') + "/" + dateCheckOut.getFullYear().toString();
    return true;
  }
}

function checkSubmitBookState()
{

    changeStyle('LayerAvailability', 'on');
    var dateCheckIn = new Date(document.forms[0].checkIn.value);
    var date = dateCheckIn.getDate();
    date += parseInt(document.forms[0].snoches.options[document.forms[0].snoches.selectedIndex].value);
    dateCheckIn.setDate(date);
    var dateCheckOut = new Date(dateCheckIn);
    document.forms[0].checkOut.value = FullFillLength((dateCheckOut.getMonth() + 1).toString(),2,'0') + "/" + FullFillLength(dateCheckOut.getDate( ).toString(),2,'0') + "/" + dateCheckOut.getFullYear( ).toString();
    return true;
}

function checkSubmit2(lang)
{
    var msg0;
    var msg1;
    var msg2;
    var msg3;
    var msg4;
    var msg5;
    var msg6;

    switch(lang)
    {
        case "SP":
            msg0 = "Es necesario introducir el nombre y apellidos de la persona que realiza la reserva";
            msg1 = "Debe seleccionar una tarjeta de crédito";
            msg2 = "Debe introducir el número de la tarjeta de crédito";
            msg3 = "Debe introducir el mes de caducidad de la tarjeta de crédito";
            msg4 = "Debe introducir el año de caducidad de la tarjeta de crédito";
            msg5 = "Debe introducir el nombre y apellidos del titular de la tarjeta de crédito";
            msg6 = "Debe aceptar las condiciones de compra para continuar con el proceso de reserva";
            msg7 = "El email introducido no tiene un formato correcto.\nPor favor introduzcalo de nuevo";
            msg8 = "Porfavor, revise los datos de caducidad de la tarjeta de crédito";
            msg9 = "Debe introducir un email de contacto";
            msg10 = "Debe introducir un Teléfono de contacto";
            msgcvv = "Debe introducir el codigo CVV";
            break;
        case "FR":
            msg0 = "Veuillez indroduire le prénom et le nom de la personne qui réalise la réservation";
            msg1 = "Veuillez sélectionner une carte de crédit";
            msg2 = "Veuillez introduire le numéro de la carte de crédit";
            msg3 = "Veuillez introduire le mois d'expiration de la carte de crédit";
            msg4 = "Veuillez introduire l'année d'expiration de la carte de crédit";
            msg5 = "Veuillez introduire le prénom et le nom du titulaire de la carte de crédit";
            msg6 = "Vous devez accepter les conditions d'achat pour continuer la réservation";
            msg7 = "Le format de l'e-mail introduit n'est pas correct.\nVeuillez l'introduire de nouveau ";
            msg8 = "Veuillez vérifier la date d'expiration de la carte de crédit";
            msg9 = "Veuillez introduire un e-mail";
            msg10 = "Veuillez introduire un numéro de téléphone";            
            msgcvv = "Debe introducir el codigo CVV";
            break;
        case "EN":
            msg0 = "The name and surname of the person making the reservation must be entered";
            msg1 = "Please select a credit card";
            msg2 = "Please enter the credit card number";
            msg3 = "Please enter the month of expiry of the credit card ";
            msg4 = "Please enter the expiry year of the credit card";
            msg5 = "Please enter the name and surname given on the card";
            msg6 = "Please accept the terms and conditions to proceed with the reservation process";
            msg7 = "The email address entered does not have a valid format. Please enter it again";
            msg8 = "Please check the expiry date of the credit card";
            msg9 = "Please enter an email";
            msg10 = "Please enter a phone number";            
            msgcvv = "You must enter the code CVV";
            break;            
        case "GR":
            msg0 = "Es müssen Vorname und Nachname(n) der Person eingegeben werden, die die Buchung vornimmt";
            msg1 = "Sie müssen eine Kreditkarte auswählen";
            msg2 = "Sie müssen die Kreditkartennummer eingeben";
            msg3 = "Sie müssen den Monat der Gültigkeit der Kreditkarte eingeben";
            msg4 = "Sie müssen das Jahr der Gültigkeit der Kreditkarte eingeben";
            msg5 = "Sie müssen Vornamen und Nachname(n) des Kreditkarteninhabers eingeben";
            msg6 = "Sie müssen die Verkaufsbedingungen akzeptieren, um mit dem Buchungsprozess fortzufahren";
            msg7 = "Die eingegebene E-Mail-Adresse hat ein falsches Format. Bitte geben Sie sie erneut ein";
            msg8 = "Bitte überprüfen Sie die Gültigkeitsangaben der Kreditkarte";
            msg9 = "Please enter an email";
            msg10 = "Please enter a phone number";
            msgcvv = "Debe introducir el codigo CVV";
            break;
        case "IT":
            msg0 = "È necessario introdurre il nome e il cognome della persona che effettua la prenotazione";
            msg1 = "È necessario selezionare una carta di credito";
            msg2 = "È necessario introdurre il numero della carta di credito";
            msg3 = "È necessario introdurre il mese di scadenza della carta di credito";
            msg4 = "È necessario introdurre l’anno di scadenza della carta di credito";
            msg5 = "È necessario introdurre il nome e il cognome del titolare della carta di credito";
            msg6 = "È necessario accettare le condizioni di acquisto per continuare con il processo di prenotazione";
            msg7 = "L’indirizzo e-mail non è stato introdotto correttamente. Vi preghiamo di introdurlo di nuovo";
            msg8 = "Vi preghiamo di rivedere la scadenza della carta di credito";
            msg9 = "Please enter an email";
            msg10 = "Please enter a phone number";        
            msgcvv = "Debe introducir el codigo CVV";
            break;
    }

    if(trim(document.forms[0].txtFullName.value) == "")
    {
        alert(msg0);
        return false;
    }
    if(trim(document.forms[0].txtEmail.value) == "")
    {
        alert(msg9);
        return false;
    }
    if(trim(document.forms[0].txtPhone.value) == "")
    {
        alert(msg10);
        return false;
    }        
    if(trim(document.forms[0].cbxCardType.options[document.forms[0].cbxCardType.selectedIndex].value) == "00")
    {
        alert(msg1);
        return false;
    }
    if(trim(document.forms[0].txtCardNumber.value) == "")
    {
        alert(msg2);
        return false;
    }    
    if(trim(document.forms[0].textCVV.value) == "")
    {
        alert(msgcvv);
        return false;
    }    
    if(trim(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value) == "00")
    {
        alert(msg3);
        return false;
    }

    /*
    else
    {        
        var currentDate = new Date();
        var month = currentDate.getMonth() + 1;
        
        var h = parseInt(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value);
        alert(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value);
        alert(parseInt(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value), 10);
        alert("-");
        var a = "07";
        alert(parseInt(a, 10));
        var b = "08";
        alert(parseInt(b, 10));
        var c = "09";
        alert(parseInt(c, 10));
        var d = "10";
        alert(parseInt(d, 10));
                
        if(parseInt(trim(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value), 10) < month)
        {
            alert(msg8);
            return false;
        }
    }
    */    

    if(trim(document.forms[0].cbxYearLimit.options[document.forms[0].cbxYearLimit.selectedIndex].value) == "00")
    {
        alert(msg4);
        return false;
    }
    if(trim(document.forms[0].txtTitular.value) == "")
    {
        alert(msg5);
        return false;
    }
    if(document.forms[0].chkConditions.checked == false)
    {
        alert(msg6);
        return false;    
    }
    
    if(trim(document.forms[0].txtEmail.value) != "")
    {
        if(isValidEmail(trim(document.forms[0].txtEmail.value)))
        {
        // jgg Muestra la ventana de "trabajando" y desactiva el boton de confirmar 
        // reserva, para evitar reservas duplicadas
        document.forms[0].Submit.disabled='true';
        changeStyle('LayerBooking', 'on');
        // fin jgg
            return true;
        }
        else
        {
            alert(msg7);
            return false;
        }
    }
    
    var currentDate = new Date();
    var currenMonth = currentDate.getMonth() + 1;
    var currentYear = currentDate.getFullYear();
    var selectedYear = "20" + trim(document.forms[0].cbxYearLimit.options[document.forms[0].cbxYearLimit.selectedIndex].value);    
    
    if(currentYear == parseInt(selectedYear))
    {
        if(parseInt(trim(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value), 10) < currenMonth)
        {
            alert(msg8);
            return false;
        }    
    }
        
    /*
    var h = parseInt(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value);
    alert(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value);
    alert(parseInt(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value), 10);
    alert("-");
    var a = "07";
    alert(parseInt(a, 10));
    var b = "08";
    alert(parseInt(b, 10));
    var c = "09";
    alert(parseInt(c, 10));
    var d = "10";
    alert(parseInt(d, 10));

    trim(document.forms[0].cbxYearLimit.options[document.forms[0].cbxYearLimit.selectedIndex].value)    
    if(parseInt(trim(document.forms[0].cbxMonthLimit.options[document.forms[0].cbxMonthLimit.selectedIndex].value), 10) < month)
    {
        alert(msg8);
        return false;
    }
    */
            
    /*if(!Mod10(trim(document.forms[0].txtCardNumber.value),lang))
    {
        return false;
    }*/
    return true;
}

function checkSubmitSendBono(lang)
{
  var msg0;
  var msg1;
  switch(lang)
  {
    case "SP":
        msg0 = "Debe introducir una dirección de email";
        msg1 = "El email introducido no tiene un formato correcto.\nPor favor introduzcalo de nuevo";
        break;
    case "EN":
        msg0 = "Please enter an email";
        msg1 = "The email entered is not vaid, please enter it again";
        break;
    case "FR":
        msg0 = "Vous devez introduire une adresse e-mail";
        msg1 = "La format de l'adresse e-mail introduite n'est pas correct, veuillez l'introduire de nouveau";
        break;
    case "GR":
        msg0 = "Please enter an email";
        msg1 = "The email entered is not vaid, please enter it again";
        break;
    case "IT":
        msg0 = "Please enter an email";
        msg1 = "The email entered is not vaid, please enter it again";
        break;
  }
  if(trim(document.forms[0].txtEmail.value) == "")
  {
    alert(msg0);
    return false;
  }
  else
  {
    if(isValidEmail(trim(document.forms[0].txtEmail.value)))
    {
        return true;
    }
    else
    {
        alert(msg1);
        return false;
    }
  }
}

function isValidEmail(strEmail)
{
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    
   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
    {
      return false;
    } 
       // JGG validacion del segundo email
       return (strEmail==trim(document.forms[0].txtEmail2.value));
//    return true; 
}


function goToUrl(banner)
{
  switch(banner)
  {
    case "banner_top_sp":
        document.location.href="../spa/barcelona/hoteles-en-europa.html";
        break;
    case "banner_top_en":
        document.location.href="http://www.hotelsbarcelona.orgen/hotels-in-europe.html";
        break;
    case "banner_top_fr":
        document.location.href="http://www.hotelsbarcelona.orgfr/hotels-en-europe.html";
        break;
    case "banner_top_it":
        document.location.href="http://www.hotelsbarcelona.orgit/hotel-in-europa.html";
        break;
    case "banner_top_gr":
        document.location.href="http://www.hotelsbarcelona.orggr/hotels-in-der-welt.html";
        break;
    case "banner_home_sp": // index.html
        break;
    case "banner_home_en": // index.html
        break;
    case "banner_home_fr": // index.html
        break;
    case "banner_home_it": // index.html
        break;
    case "banner_home_gr": // index.html
        break;
    case "banner01_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-grand-marina.htm";
        break;
    case "banner01_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-grand-marina.htm";
        break;
    case "banner01_fr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/fr/hotel-barcelone-eurostars-gaudi.html";
        break;
    case "banner01_it.jpg":
        document.location.href="http://www.hotelsbarcelona.org/it/hotel-barcellona-eurostars-gaudi.html";
        break;
    case "banner01_gr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/gr/hotel-barcelona-eurostars-gaudi.html";
        break;
    case "banner02_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-barbera-parc.htm";
        break;
    case "banner02_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-barbera-parc.htm";
        break;
    case "banner02_fr.jpg":
        document.location.href="../fr/barcelona/hotel-barcelone-eurostars-grand-marina.html";
        break;
    case "banner02_it.jpg":
        document.location.href="../it/barcelona/hotel-barcellona-eurostars-grand-marina.html";
        break;
    case "banner02_gr.jpg":
        document.location.href="../gr/barcelona/hotel-barcelona-eurostars-grand-marina.html";
        break;
    case "banner03_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-cristal-palace.htm";
        break;
    case "banner03_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-cristal-palace.htm";
        break;
    case "banner03_fr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/fr/hotel-de-valence-eurostars-gran-valencia-603119.html";
        break;
    case "banner03_it.jpg":
        document.location.href="http://www.hotelsbarcelona.org/it/hotel-di-valencia-eurostars-gran-valencia-603119.html";
        break;
    case "banner03_gr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/gr/hotel-vonn-valencia-eurostars-gran-valencia-603119.html";
        break;    
    case "banner04_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-gaudi.htm";
        break;
    case "banner04_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-gaudi.htm";
        break;
    case "banner04_fr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/fr/hotel-de-rome-eurostars-international-palace-603134.html";
        break;
    case "banner04_it.jpg":
        document.location.href="http://www.hotelsbarcelona.org/it/hotel-di-roma-eurostars-international-palace-603134.html";
        break;
    case "banner04_gr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/gr/hotel-vonn-roma-eurostars-international-palace-603134.html";
        break;
    case "banner05_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-laietana-palace.htm";
        break;
    case "banner05_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-laietana-palace.htm";
        break;
    case "banner05_fr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/fr/hotel-de-london-royal-eagle-450280.html";
        break;
    case "banner05_it.jpg":
        document.location.href="http://www.hotelsbarcelona.org/it/hotel-di-londra-royal-eagle-450280.html";
        break;
    case "banner05_gr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/gr/hotel-vonn-london-royal-eagle-450280.html";
        break;
    case "banner06_sp.jpg":
        document.location.href="http://www.hotelsbarcelona.org/spa/barcelona/hotel-barcelona-eurostars-parc-del-valles.htm";
        break;
    case "banner06_en.jpg":
        document.location.href="http://www.hotelsbarcelona.org/en/barcelona/hotel-barcelona-eurostars-parc-del-valles.htm";
        break;
    case "banner06_fr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/fr/hotel-de-paris-la-fleche-d-or-002120.html";
        break;
    case "banner06_it.jpg":
        document.location.href="http://www.hotelsbarcelona.org/it/hotel-di-parigi-la-fleche-d-or-002120.html";
        break;
    case "banner06_gr.jpg":
        document.location.href="http://www.hotelsbarcelona.org/gr/hotel-vonn-paris-la-fleche-d-or-002120.html";
        break;                                        
  }
}

function changeStyle(id, newClass) {
    identity=document.getElementById(id);
    identity.className=newClass;
}

function Mod10(ccNumb,lang) {  // v2.0
    var valid = "0123456789";  // Valid digits in a credit card number
    var len = ccNumb.length;  // The length of the submitted cc number
    var iCCN = parseInt(ccNumb);  // integer of ccNumb
    var sCCN = ccNumb.toString();  // string of ccNumb
    sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
    var iTotal = 0;  // integer total set at zero
    var bNum = true;  // by default assume it is a number
    var bResult = false;  // by default assume it is NOT a valid cc
    var temp;  // temp variable for parsing string
    var calc;  // used for calculation of each digit
    var msg0;
    var msg1;
    var msg2;
    var msg3;
    var msg4;
    var msg5;
    var msg6;
    alert(lang);
    switch(lang)
    {
        case "SP":
            msg0 = "Introduzca solo dígitos en el campo número de tarjeta de crédito";
            msg1 = "Longitud incorrecta en el número de tarjeta de crédito";
            msg2 = "El número de tarjeta de crédito introducido no es correcto";
            break;
        case "EN":
            msg0 = "Please only enter numbers in the credit card field";
            msg1 = "The lenght of the credit card number is wrong";
            msg2 = "The credit card number entered is wrong";
            break;
        case "FR":
            msg0 = "Veuillez n'introduire que des nombres dans le champ de la carte de crédit";
            msg1 = "Longueur du numéro de carte de  crédit incorrecte";
            msg2 = "Le numéro de carte de crédit introduit est incorrect";
            break;
        case "GR":
            msg0 = "Please only enter numbers in the credit card field";
            msg1 = "The lenght of the credit card number is wrong";
            msg2 = "The credit card number entered is wrong";
            break;
        case "IT":
            msg0 = "Please only enter numbers in the credit card field";
            msg1 = "The lenght of the credit card number is wrong";
            msg2 = "The credit card number entered is wrong";
            break;
    }

    // Determine if the ccNumb is in fact all numbers
    for (var j=0; j<len; j++)
    {
        temp = "" + sCCN.substring(j, j+1);
        if (valid.indexOf(temp) == "-1"){bNum = false;}
    }
    // if it is NOT a number, you can either alert to the fact, or just pass a failure
    if(!bNum)
    {
        alert(msg0);
        return false;
    }

    // Determine if it is the proper length 
    if((len == 0)&&(bResult))
    {  // nothing, field is blank AND passed above # check
        alert(msg1);
        return false;
    }
    else
    {  
        // ccNumb is a number and the proper length - let's see if it is a valid card number
        if(len >= 15)
        {
            // 15 or 16 for Amex or V/MC
            for(var i=len;i>0;i--)
            {  // LOOP throught the digits of the card
                calc = parseInt(iCCN) % 10;  // right most digit
                calc = parseInt(calc);  // assure it is an integer
                iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
                i--;  // decrement the count - move to the next digit in the card
                iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
                calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
                calc = calc *2;                                 // multiply the digit by two
                // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
                // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
                switch(calc)
                {
                    case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
                    case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
                    case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
                    case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
                    case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
                    default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
                }                                               
                iCCN = iCCN / 10;  // subtracts right most digit from ccNum
                iTotal += calc;  // running total of the card number as we loop
            }  // END OF LOOP
            if ((iTotal%10)==0)
            {  // check to see if the sum Mod 10 is zero
                bResult = true;  // This IS (or could be) a valid credit card number.
            }
            else
            {
                alert(msg2);
                return false;
            }
        }
    }
    // change alert to on-page display or other indication as needed.
    alert("hasta aquí hemos llegado");
    alert(bResult);
    return false;
    //return bResult; // Return the results
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeStyle (id,newClass) {
        identity=document.getElementById(id);
        identity.className=newClass;
}

function MM_swapImgRestore() { //v3.0
  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_findObj(n, d) { //v4.01
  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() { //v3.0
  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];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj1,obj2){
    if(document.getElementById){
    var el = document.getElementById(obj1);
    var im = document.getElementById(obj2);
    var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
        if(el.style.display != "block")
        { //DynamicDrive.com change
            for (var i=0; i<ar.length; i++){
                if (ar[i].className=="submenu") //DynamicDrive.com change
                ar[i].style.display = "none";
            }
            el.style.display = "block";
            im.src="/images/up.gif";
        }
        else
        {
            el.style.display = "none";
            im.src="/images/down.gif";
        }
    }
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
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;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate
