//
// these routines are written and (c) by Gregory Mertens, unless noted otherwise
// if you can't help it but to copy them
// please give me credit, i worked hard on them
//
//---------------------------------------------------------------------------

//--------------------------------------------------------------------
// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/JavaScript/randomizer.html
//-------------------------------------------------------------------

//-------------------------------------------------------------------

function myVoid (){;}// do nothing for the oclick events w/ explorer (seems to be 5)
//-------------------------------------------------------------------

function rnd() {
	
	// assign a seed if one is not assigned

	if (rnd.seed == null)
		{
		rnd.today=new Date();
		rnd.seed = rnd.today.getTime();
		}

	// assign a seed change
        rnd.seed = (rnd.seed * 9301 + 49297)  % 233280;
        return rnd.seed / (233280.0);
};

//-------------------------------------------------------------------
function rand(number) {
	dog = rnd()*number;
	//alert (rnd.seed);
	return Math.ceil(dog);
};

// end central randomizer

//--------------------------------------------------------------------

//---------------------------------------------------------------------------

// gregory - start
// basis for script - when a user loads a single page from the site, outside of the frame set
// the page will automatically reopen itself within the correct frameset
// this should eliminate/ reduce pages from being loaded without their frame
// this will not work with cookies off
// most of this code was based on code found on www.digitalroom.net/javascript/frame.html
// gregory - end


// Cookie functions from 'Crispy JavaScript Cookies'
// http://www.webreference.com/js/column8/functions.html

//---------------------------------------------------------------------------
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments



function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
//      alert("setting" + name);
//      alert("value " + value);
  document.cookie = curCookie;
}


//---------------------------------------------------------------------------
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
//---------------------------------------------------------------------------
// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
//---------------------------------------------------------------------------
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
//--------------------------------------------------------------------

function get_newURL() {

	//alert("asdf");		

	var newURL = getCookie('newURL');
	if (newURL == null) newURL = "home.htm";

	//window.resizeTo(860, 800);

	deleteCookie('newURL', '/', null);

	//------------------------------
	//alert("asdf");		
	//alert (newURL);
	return newURL;

}// end get_newURL

//-------------------------------------- check page
	// this code comes from www.digitalroom.net/javascript/frame.html
	// and has been modified by gregory mertens

function check_page(){
 //this is legacy
}
//---------------------------------------------------------------------------
	// this code comes from www.digitalroom.net/javascript/frame.html
	// and has been modified by gregory mertens

function check_page_outer(){
	
	  if (top.frames.length == 0) {
		 // document.cookie = "newURL=" + escape(document.URL) + "; path=/;"
		  ver = parseInt(navigator.appVersion, 10);
		  if ( ((navigator.appName == "Netscape") && (ver >= 3)) ||
  		       ((navigator.appName == "Microsoft Internet Explorer") && (ver >= 4)) )
 	  		location.replace("../index.html");
	  else
	  location = "../index.html";
	  };
}
//---------------------------------------------------------------------------

//
// QueryString
//
// based on code from http://javascript.about.com/library/scripts_b/blquerystring.htm
// with modifications by gregory mertens
function QueryString(key,whole_string)
{
	//i added the whole string so that we can call this with one function call
		
	// so first break up the whole string
	QueryString.keys = new Array();
	QueryString.values = new Array();
	
//	var query = window.location.search.substring(1);
	var query = whole_string;
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}


	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
//-------------------------------------------------------------------

