// The following 3 functions (getCookieVal, getCookie, and setCookie work together for any page that requires a session cookie.
// get the cookies value
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

document.onkeydown = function(e){
		var KeyID = (window.event) ? event.keyCode : e.keyCode;
		if (KeyID == 13)
			if(formdoc){
				formdoc.submit();
			}
		}



function getCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
  }

function setCookie (name, value) {
    document.cookie = name + "=" + escape(value);
  }



//Sets the page defaults for enterable fields in any form.
function setDefault(theForm, element, value)
{
	for (i = 0; i < theForm.elements[element].length; i++)
	{
		if (theForm.elements[element][i].value == value)
		{
			theForm.elements[element].selectedIndex = i;
		}
	}
}

function encode_cookie(cookie_value) {

  // This variable holds the encoded cookie characters
  var coded_string = ""
  
  // Run through each character in the cookie value
  for (var counter = 0; counter < cookie_value.length; counter++) {
  
    // Add the characters numeric code to the string
    var encode_value = (cookie_value.charCodeAt(counter) * 1) + 88
    coded_string += ""+ encode_value
    
    // Separate each code with a plus sign (+)
    if (counter < cookie_value.length - 1) {
      coded_string += "+"
    }
  }
  return coded_string
}

function decode_cookie(coded_string) {

  // This variable holds the decoded cookie value
  var cookie_value = ""
  
  // Use + to split the coded string into an array
  var code_array = coded_string.split("+")
  
  // Loops through the array
  for (var counter = 0; counter < code_array.length; counter++) {

    // Convert the codes into a character and 
    // add it to the cookie values string
    var decode_value = (code_array[counter] * 1) - 88;
    cookie_value += String.fromCharCode(decode_value)
  }
  
  return cookie_value
}

   function setcookie(name, value, expires, path, domain, secure) {
     value = escape(value);
     expires = (expires) ? ';expires=' + expires.toGMTString() :'';
     document.cookie = name + '=' + value + expires+";path=/";
   }


function newWindow(href) {
	window.open(href);
}

function newWindowWithOptions(href, winWidth, winHeight, allowResize, allowScroll) {
	var options = 'width=' + winWidth +',height=' + winHeight + ',resizable=' + allowResize + ',scrollbars=' + allowScroll +',toolbar=no,location=no,directories=no,menubar=no,left=0,top=0,screenX=0,screenY=0'
	window.open(href,'new_window_with_option', options);
}

function loadDate() {
	var timeOfDay = "AM";
	var currentTime = new Date();
	var day = currentTime.getDate();
	if(day.toString().length <=1) {
	   day="0"+day;
	}
	var month = currentTime.getMonth()+1;
	if(month.toString().length <=1) {
	   month="0"+month;
	}
	var year = currentTime.getFullYear();
	var hours = currentTime.getHours();
	if(hours.toString().length <=1) {
	   hours="0"+hours;
	}
	var minutes = currentTime.getMinutes();
	if(minutes.toString().length<=1) {
	   minutes="0"+minutes;
	}
	var seconds = currentTime.getSeconds();
	if(seconds.toString().length <=1) {
	   seconds="0"+seconds;
	}
	if(hours >= 12) {
	   timeOfDay = "PM";
	}
	var time = month+"."+day+"."+year+" at "+hours+":"+minutes+":"+seconds+" "+timeOfDay;
	document.getElementById('showTime').innerHTML = ' '+time;
}

function getCalendarDate()
{
	var months = new Array(13);
	months[0] = "January";
	months[1] = "February";
	months[2] = "March";
	months[3] = "April";
	months[4] = "May";
	months[5] = "June";
	months[6] = "July";
	months[7] = "August";
	months[8] = "September";
	months[9] = "October";
	months[10] = "November";
	months[11] = "December";
	var day = new Array(7);
	day[0] = "Sunday";
	day[1] = "Monday";
	day[2] = "Tuesday";
	day[3] = "Wednesday";
	day[4] = "Thursday";
	day[5] = "Friday";
	day[6] = "Saturday";

	var now = new Date();
	var monthnumber = now.getMonth();
	var monthname = months[monthnumber];
	var monthday = now.getDate();
	var weekday = day[now.getDay()];
	var year = now.getYear();
	if(year < 2000) { year = year + 1900; }
	var dateString = weekday +', '+ monthname + ' ' + monthday + ', ' + year;
	document.getElementById('showTime').innerHTML = ' '+dateString;
} 

	

	function getSelectedRadio(buttonGroup) {		
	   // returns the array number of the selected radio button or -1 if no button is selected
	   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	      for (var i=0; i<buttonGroup.length; i++) {
	         if (buttonGroup[i].checked) {
	            return i
	         }
	      }
	   } else {
	      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
	   }
	   // if we get to this point, no radio button is selected
	   return -1;
	} // Ends the "getSelectedRadio" function

	function getSelectedRadioValue(buttonGroup) {
	   // returns the value of the selected radio button or "" if no button is selected
	   var i = getSelectedRadio(buttonGroup);
	   if (i == -1) {
	      return "";
	   } else {
	      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
	         return buttonGroup[i].value;
	      } else { // The button group is just the one button, and it is checked
	         return buttonGroup.value;
	      }
	   }
	} // Ends the "getSelectedRadioValue" function

//  Published at: scripts.tropicalpcsolutions.com
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded) 
        window.location.replace(window.location+"?reloaded=true");
}