/* generate a random number */
function rand($max_val) {
   var $rand_no = Math.random();
   $rand_no = $rand_no * $max_val;
   $rand_no = Math.ceil($rand_no);
   return $rand_no;
}

/* calculate how far the window has been scrolled */
function f_scrollTop() {
   var n_win = window.pageYOffset ? window.pageYOffset : 0;
   var n_docel = document.documentElement ? document.documentElement.scrollTop : 0;
   var n_body = document.body ? document.body.scrollTop : 0;
   var result = f_filterResults(n_win, n_docel, n_body);
   return result;
}
function f_filterResults(n_win, n_docel, n_body) {
   var n_result = n_win ? n_win : 0;
   if (n_docel && (!n_result || (n_result > n_docel))) {
      n_result = n_docel;
   }
   var result = n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
   return result;
}

/* respond to change in window width */
//function windowResized() {
//	var $loginLeft = $("#login_register").position().left;
//	var $lastTab = $("#nav_tabs li:last");
//	var $navbarRight = $("#nav_tabs li:last").position().left + $("#nav_tabs li:last").width();
//	
//	if ($loginLeft < $navbarRight) {
//	  $("div#login_register").css("top", 75 );
//	} else {
//	  $("div#login_register").css("top", 105 );
//	  //alert($loginLeft + " not < " + $navbarRight);
//	}
//}

/* classes to form input elements that are the same as the types.
   - e.g. input elements of type="text" get given class="text", of type="button" -> class="button"
*/
function changeInputs() {
   var els = document.getElementsByTagName('input');
   var elsLen = els.length;
   var i = 0;
   for ( i=0;i<elsLen;i++ ) {
      if ( els[i].getAttribute('type') ) {
         if ( els[i].getAttribute('type') == "text" )
            els[i].className = 'text';
         else
            els[i].className = 'button';
      }
   }
}
