
//general hover function changes state and uses jquery-ui themes
$(function(){
   $('.ui-state-default').live('mouseover', function(){
      $(this).addClass('ui-state-hover');
   });

   $('.ui-state-default').live('mouseout', function(){
      $(this).removeClass('ui-state-hover');
   });

   $('.timeline').live('mouseover', function(){
      $(this).addClass('ui-state-hover');
   });

   $('.timeline').live('mouseout', function(){
      $(this).removeClass('ui-state-hover');
   });

   $('.ui-state-error').live('click', function(){
      $(this).hide();
   });

   $('.ui-state-highlight').live('click', function(){
      $(this).hide();
   });

});

//load tabs
$(function(){
   $('.tabs').tabs({
      spinner: 'Loading..'
   });
});



function urlencode (str) {
   // URL-encodes string
   //
   // version: 910.813
   // discuss at: http://phpjs.org/functions/urlencode
   // +   original by: Philip Peterson
   // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

   var hexStr = function (dec) {
      return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
   };

   var ret = '',
   unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
   str = (str+'').toString();

   for (var i = 0, dl = str.length; i < dl; i++) {
      var ch = str.charAt(i);
      if (unreserved.test(ch)) {
         ret += ch;
      }
      else {
         var code = str.charCodeAt(i);
         if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt
            ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
            i++; // skip the next one as we just retrieved it as a low surrogate
         }
         // We never come across a low surrogate because we skip them, unless invalid
         // Reserved assumed to be in UTF-8, as in PHP
         else if (code === 32) {
            ret += '+'; // %20 in rawurlencode
         }
         else if (code < 128) { // 1 byte
            ret += hexStr(code);
         }
         else if (code >= 128 && code < 2048) { // 2 bytes
            ret += hexStr((code >> 6) | 0xC0);
            ret += hexStr((code & 0x3F) | 0x80);
         }
         else if (code >= 2048) { // 3 bytes (code < 65536)
            ret += hexStr((code >> 12) | 0xE0);
            ret += hexStr(((code >> 6) & 0x3F) | 0x80);
            ret += hexStr((code & 0x3F) | 0x80);
         }
      }
   }
   return ret;
}

function sleep (seconds) {
   // Delay for a given number of seconds
   var start = new Date().getTime();
   while (new Date() < start + seconds*1000) {}
   return 0;
}

function show_error_message(message){
   if(message.length > 0){
      message = message + '&nbsp;&nbsp;&nbsp;[ Click To Close ]';
      $(".ui-state-error").empty();
      $(".ui-state-error").append(message);
      $(".ui-state-error").show();
   }
}

function show_highlight_message(message){
   if(message.length > 0){
      message = message + '&nbsp;&nbsp;&nbsp;[ Click To Close ]';
      $(".ui-state-highlight").empty();
      $(".ui-state-highlight").append(message);
      $(".ui-state-highlight").show();
   }
}

//this function will show hide elements
//options are show and hide arrays
//options_show["1","2","3","4"]
function show_hide(options_show, options_hide){
   $.each(options_show, function(){
      $('.'+this).show();
   });
   $.each(options_hide, function(){
      $('.'+this).hide();
   });
   return false;
}






