// Start slideshow if on page
$(document).ready(function(){     
  $('#jquery_slideshow').each(function() {                     
     $(this).cycle({
      speed: 4000,
      timeout: 6000
     });          
  });
});

// Start slideshow if on page
$(document).ready(function(){     
  $('#jquery_complex_slideshow').each(function() {                     
     $(this).cycle({
      speed: 2750,
      timeout: 500
     });          
  });
});  
  

// Start featured prop slideshow
 $(document).ready(function(){  
$('.featuredProp').each(function() {                     
     $(this).cycle({
      speed: 750,
      timeout: 6000
     });          
  }); 
});            

// Initialize flipkey dhtml
$(document).ready(function(){  
  $('.flip_key_reviews').each(function() {                     
     $(this).cycle({
      speed: 750,
      timeout: 6000
     }).cycle('pause');          
  }); 
  
 $('.flipkey_next').click(function() {
   $('.flip_key_reviews').cycle('next');
   return false;
 });
 
 $('.flipkey_prev').click(function() {
   $('.flip_key_reviews').cycle('prev');
   return false;
 });  
});            


/* Initialize links opening DOM lightbox windows */
$(document).ready(function(){  
 $('.defaultDOMWindow').openDOMWindow({ 
  eventType:'click', 
  loader:1, 
  loaderImagePath:'/custom/slimbox/css/loading.gif', 
  loaderHeight:31, 
  loaderWidth:31 
  }); 
});

$(document).ready(function(){
  isLoaded = 1;
});

// Detail page javascript

// open new window function - takes url,width,height as parameters
// Used in email to friend
function openWindow(sURL, width, height) {
  var sFeatures = "top=50,left=50,height=" + height + ",width=" + width + ",status=yes,scrollbars=yes,resizable=1,menubar=0";
  var oSampWin = window.open(sURL,"_newwindow",sFeatures);
}


$(document).ready(function(){
  $("#tabs").tabs();
  $('#hidden_cal').hide();
  $('a#toggle_cal').click(function() {
    if ($(this).html()=='View more calendar months &gt;&gt;') {
      $(this).html('View fewer calendar months >>');
    } else {
      $(this).html('View more calendar months >>');
    }
    $('#hidden_cal').toggle(400);
    return false;
  });
});

// Featured prop controls
var slideshow_off = false;

function slideshow(op) {
 $('.featuredProp').cycle(op);
 if (op == 'pause') {
  slideshow_off = true;
  $(".slideshow_pause").css('display', 'none');
  $(".slideshow_resume").css('display', 'inline');
 } else if (slideshow_off) {
  $('.featuredProp').cycle('pause');
 }
}

function resume() {
 $('.featuredProp').cycle('resume', true);
 slideshow_off = false;
  $(".slideshow_pause").css('display', 'inline');
  $(".slideshow_resume").css('display', 'none');
}

function clear_preset() {
  var value = $('.preset_form .preset_field').val('').removeClass('preset_field');
}

//Clear form fields with preset instruction values
$(document).ready(function() {
  $('.preset_form').click(function() {
    $(this).find('.preset_field').val('');
    $(this).find('.preset_field').removeClass('preset_field');    
  });
});

function getParameter (parameterName) {
  var queryString = window.location.search.substring(1);
  var parameterName = parameterName + "=";
  if (queryString.length == 0) {
    return;
  }

  var begin = queryString.indexOf(parameterName);
  if (begin == -1) { 
    return;
  }

  begin += parameterName.length;
  var end = queryString.indexOf ( "&" , begin );
  if (end == -1) {
     value = queryString.substring(begin);
  } else {
     value = queryString.substring(begin, end);
  }

  value = unescape(value);
  return value;
}

function translate(lang) {
 var url = getParameter('u');
 if (!url) {
  url = location.href;
 }
 
 if (lang == 'en') {
  top.location = url;
  return false;
 }

 // Set the 'u' parameter to contain this page's URL 
 var hidden = document.getElementById('u');  
 hidden.value = url; 

 // Set the 'langpair' parameter to translate to our desired language
 var lang_pair = document.getElementById('langpair');
 lang_pair.value = 'en|' + lang;
 
 // Submit the google translation form request
 var form = document.getElementById('translate');
 form.submit();

 return false;
}

// JS fix for css width-limited select boxes for IE
function ie_width_fix(id) {
 var menu_open = false; 
 
 $(id).mouseover(function(e) {  
  $(id).addClass("active");
 });
 
 $(id).mouseout(function(e) {  
  if (!menu_open) {
   $(id).removeClass("active");
  }
 });
 
 $(id).focus(function(e) {  
  menu_open = true;
 });
 
 $(id).blur(function(e) {  
  menu_open = false;  
  $(id).removeClass("active");
 });
 
$(id).change(function(e) {  
  menu_open = false;  
  $(id).removeClass("active");
  $(id).blur();
 });
 
 $(id).blur();
};

// Additional email validation for forms


 function isValidEmail(email) {

 

                                    invalidChars = " /:,;"

           

                                    if (email == "") {                                                             // cannot be empty

                                                return false

                                    }

                                    for (i=0; i<invalidChars.length; i++) {         // does it contain any invalid characters?

                                                badChar = invalidChars.charAt(i)

                                                if (email.indexOf(badChar,0) > -1) {

                                                            return false

                                                }

                                    }

                                    atPos = email.indexOf("@",1)                             // there must be one "@" symbol

                                    if (atPos == -1) {

                                                return false

                                    }

                                    if (email.indexOf("@",atPos+1) != -1) {     // and only one "@" symbol

                                                return false

                                    }

                                    periodPos = email.indexOf(".",atPos)

                                    if (periodPos == -1) {                                                      // and at least one "." after the "@"

                                                return false

                                    }

                                    var periodDiff = periodPos - atPos;
                                    if (periodDiff == 1) {  //must have a domain name
                                                //alert("Email address must have a domain name");
                                                return false;
                                    }

                                    if (periodPos+3 > email.length)    {                       // must be at least 2 characters after the "."

                                                return false

                                    }

                                    return true

                        }

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
    alert("Email address seems incorrect (check @ and .'s)");
    return false;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.");
    return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
      for (var i=1;i<=4;i++) {
        if (IPArray[i]>255) {
            alert("Destination IP address is invalid!");
        return false;
        }
    }
    return true;
}
var domainArray=domain.match(domainPat);
if (domainArray==null) {
    alert("The domain name doesn't seem to be valid.");
    return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if ((domArr[domArr.length-1] != "info") &&
    (domArr[domArr.length-1] != "name") &&
    (domArr[domArr.length-1] != "arpa") &&
    (domArr[domArr.length-1] != "coop") &&
    (domArr[domArr.length-1] != "aero")) {
        if (domArr[domArr.length-1].length<2 ||
            domArr[domArr.length-1].length>3) {
                alert("The address must end in a three-letter domain, or two letter country.");
                return false;
        }
}
if (len<2) {
   var errStr="This address is missing a hostname!";
   alert(errStr);
   return false;
}
return true;
}
function UPTvalidateform(thisform)
{
  
  if (emailCheck(thisform.email.value)) 
  { 

        if (document.getElementById('unsubscribe') 
            && !document.getElementById('unsubscribe').checked) {
        
        } else {
            
        }
    return false;
  }
  else
  {
    return true;
  }
}
