<!--//--><![CDATA[//><!--
function track_ga(trackercat, tracktag)
{
    if (trackercat!="")
        _gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
    if (tracktag!="")
        _gaq.push(['_trackPageview', tracktag]);
}



sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]>

objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
objects[i].outerHTML = objects[i].outerHTML;
}


$(document).ready(function(){
   // Change the image of hoverable images
   $(".imgHoverable").hover( function() {
       var hoverImg = HoverImgOf($(this).attr("src"));
       $(this).attr("src", hoverImg);
     }, function() {
       var normalImg = NormalImgOf($(this).attr("src"));
       $(this).attr("src", normalImg);
     }
   );
});

function HoverImgOf(filename)
{
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1_hover.$2");
}
function NormalImgOf(filename)
{
   var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}


/* ========= FORM functions ========= */

function show_error(id)
{
    document.getElementById(id).style.background="#ffb608";
}

function clear_errors(which)
{
    for (i=0;i<document.forms[which].elements.length;i++)
    {
        if ( (document.forms[which].elements[i].type != "button") && (document.forms[which].elements[i].type != "reset") && (document.forms[which].elements[i].id!="fieldset") )
            document.forms[which].elements[i].style.background="";
    }
}


function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
        return false;

   if(field.value.match(emailExp))
           return true;
   else 
           return false;
   
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailid)
{
    clear_errors(whichform);
    
    //check mandatory fields
    var man = mandatory_fields.split(",");
    for (i=0;i<man.length;i++)
    {
        if (document.getElementById(man[i]).value == "")
        {
            show_error(man[i]);
            alert ("You must fill all the mandatory fields (*)");
            return false;
        }
    }        

    if (emailid!="")
    {
        if (!checkEmail(emailid))
        {
            show_error(emailid);
            alert ("Your email address is not valid.");
            return false;
        }
    }
    
    //check numeric fields
    if (numericfields != "")
    {
        var numeric = numericfields.split(",");
        for (i=0;i<numeric.length;i++)
        {
            document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
            
            if (isNaN (document.getElementById(numeric[i]).value))
            {
                show_error(numeric[i]);
                alert (numeric[i]+": should be a number. Plase check and try again!");
                return false;
            }
        }
    }
    if (formid == 'cform') {
        track_ga('', '/virtual/reservation-form');
    }
    document.getElementById(formid).submit();
}

