//* Author  : Roy Whittle  (Roy@Whittle.com)
var AnimationRunning = false;
var FrameInterval    = 30;

function AnimatedImage(name, n, ext)
{
        if(document.images)
        {
                this.num_frames = n;
                this.name       = "b"+name;
                this.index      = 0;
                this.state      = "CLOSED";

                for(var i=0 ; i<n ; i++)
                {
                        this[i]=new Image();
                        this[i].src = img_location + "b" + name + i + ext;
                }
        }

}
function AnimatedDetail(name)
{
        if(document.images)
        {
                this.name       = name;
                this.index      = 0;
                this.state      = "OFF";

                this[0] = new Image();
                this[0].src = small_img_location + name + ".jpg";
        }

}


function Animate()
{
        AnimationRunning = false;
        for(var i=0 ; i<Btn.numButtons ; i++)
                switch(Btn[i].state)
                {
                        case "OPENING" :
                                if(Btn[i].index < Btn[i].num_frames-1)
                                {
                                        Btn[i].index++;
                                        document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
                                        AnimationRunning = true;
                                }
                                else
                                        Btn[i].state = "OPEN";

                                break;

                        case "OPEN_CLOSE" :
                                if(Btn[i].index < Btn[i].num_frames-1)
                                {
                                        Btn[i].index++;
                                        document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
                                }
                                else
                                        Btn[i].state = "CLOSING";

                                AnimationRunning = true;
                                break;

                        case "CLOSING" :
                                if(Btn[i].index > 0)
                                {
                                        Btn[i].index--;
                                        document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
                                        AnimationRunning = true;
                                }
                                else
                                        Btn[i].state = "CLOSED";

                                break;
                }
        if( AnimationRunning )
                setTimeout("Animate()",FrameInterval);
}
function start_animation()
{
        if(!AnimationRunning)
                Animate();
}
function turn_on(btn_name)
{
        for(var i=0; i<Btn.numButtons ; i++)
                if(Btn[i].name == btn_name )
                {
                        switch(Btn[i].state)
                        {
                                case "CLOSED"     :
                                case "CLOSING"    :
                                case "OPEN_CLOSE" :
                                        Btn[i].state = "OPENING";
                                        start_animation();
                                        break;
                                case "OFF" :
                                        document.images["detail"].src=Btn[i][0].src;
                                        Btn[i].state = "ON";
                                        break;
                                default :
                                        break;
                        }
                }

}
function turn_off(btn_name)
{

        for(var i=0; i<Btn.numButtons ; i++)
                if(Btn[i].name == btn_name )
                {
                        switch(Btn[i].state)
                        {
                                case "OPEN"       :
                                        Btn[i].state = "CLOSING";
                                        start_animation();
                                        break;
                                case "OPENING"  :
                                        Btn[i].state = "OPEN_CLOSE";
                                        start_animation();
                                        break;
                                case "ON" :
                                        //document.images["detail"].src=Btn[i][0].src;
                                        document.images["detail"].src = ee.src;
                                        Btn[i].state = "OFF";
                                        break;
                                default :
                                        break;
                        }
                }
}
//function empty() {
//        if(document.images) {
//                document.images["detail"].src = ee.src;
//        }
//}

function AnimatedButtons()
{
        this.numButtons = 6;
        this[0]=new AnimatedImage(0,5,".jpg");
        this[1]=new AnimatedImage(1,5,".jpg");
        this[2]=new AnimatedImage(2,5,".jpg");
        this[3]=new AnimatedImage(3,5,".jpg");
        this[4]=new AnimatedImage(4,5,".jpg");
        this[5]=new AnimatedImage("top",2,".gif");
}


// basic checks of the input fields:
function chkForm(which)
    {
//     if (which == "acc") {
          // only with acc the name is mandatory
         if(document.Formular.realname.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.realname.value = "Please enter your name details!";
             document.Formular.realname.focus();
             return false;
         }
//     }


     // test email with every version.
     if(document.Formular.email.value == "")
      {
       //alert("Your e-mail address is a required input field!");
       document.Formular.email.value = "Please enter your email address!";
       document.Formular.email.focus();
       return false;
      }
     if(document.Formular.email.value.indexOf('@') == -1)
      {
       alert("Your e-mail address is of illegal format!");
       document.Formular.email.focus();
       return false;
      }


     // check dates
     if ((which == "acc") || (which == "enq")) {
          // only with acc and enq
         if(document.Formular.nr_of_people.options[0].selected == true)
         {
             alert("Please enter the number of people staying!");
             return false;
         }
         if(document.Formular.arrival_date.value == "MM/DD/YYYY")
         {
             alert("What is your date of arrival?");
             //document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.arrival_date.focus();
             return false;
         }
         if(document.Formular.departure_date.value == "MM/DD/YYYY")
         {
             alert("What is your date of departure?");
             //document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.departure_date.focus();
             return false;
         }
     }


     if (which == "acc") {
         if(document.Formular.Credit_Card.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
         if(document.Formular.Card_Number.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.Card_Number.value = "Credit Card number is missing!";
             document.Formular.Card_Number.focus();
             return false;
         }
         if(document.Formular.Card_Holder_Name.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.Card_Holder_Name.value = "Card holder name is missing!";
             document.Formular.Card_Holder_Name.focus();
             return false;
         }
         if(document.Formular.Expiration_Month.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
         if(document.Formular.Expiration_Year.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
     }



     if ((which != "acc") || (which == "enq")) {
          // only with acc the comment is mandatory
         if(document.Formular.comment.value == "")
         {
             //alert("What was your question / hint / comment again?");
             document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.comment.focus();
             return false;
         }
     }
    }

function checkEmail(email) {
  var proto  = "(mailto:)?";
  var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
  var regex  = "^" + proto + "?" + usr + "\@" + domain + "$";

  var rgx    = new RegExp(regex);
  return rgx.exec(email) ? true : false;
}
