/**
 * @author rocky2000
 */

$(document).ready(function(){

	// hide informational banners
	if ($('#status_msg').length > 0)
	{
		setTimeout(function () { 
		$('#status_msg').fadeOut('slow');
		},3000);
	}
	
	
	
	$("ul#primary-nav > li > ul").hide();
	
	$("ul#primary-nav > li").click(function(e)
	{
		var clicked = $(e.target);
		
	    // Ensure we're checking which list item is clicked,
	    // other children should be allowed
	    if(!clicked.is('li') && clicked.parents('li').length > 0) {
	        // :first ensures we do not select higher level list items
	        clicked = clicked.parents('li:first');
	    }
	    // If clicked list item is a child of another list item, we'll exit here
	    if(clicked.is('#primary-nav > li')) {
			$("ul#primary-nav > li > ul").hide();
			if($("ul", $(this)).length > 0)
			{	
				$("ul", $(this)).show();
				return false;
			}
			
	    }
		
	});
	
		
 
	// Render hint input fields
	$('input[title!=""], textarea[title!=""]').hint();
});


function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function r2(n) {

  ans = n * 1000
  ans = Math.round(ans /10) + ""
  while (ans.length < 3) {ans = "0" + ans}
  len = ans.length
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans
} 

function str_replace(search, replace, subject) {
    var temp = subject.split(search);
    return temp.join(replace);
}

function cachableTimeStr()
{
	var dateObj	  =	new Date();
	dateObj = new Date();
	var timeStr = dateObj.getTime();
	dateObj = null;
	return timeStr;
}



/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);

