// Here are some useful functions.

//Gives you url paramaters.
function aryValueOf(ary, index) {
	for(i = 0; i < ary.length; i++)
		if(ary[i] == index) break;
	if(i <= ary.length) 
		return ary[i+1];
	else return "";
}

//This will return the value of a URL variable under "&" notation, or "/" notation.
function QueryString( param ) {
	var begin,end;

	var locStr = window.location.toString();
       // (& Version)
       // If the amount of characters after the filename is greater than 1 AND
       // the paramater name we want is in the query string....
       if(self.location.search.length > 1 && self.location.search.indexOf(param) > -1) {
		begin=self.location.search.indexOf(param) +param.length+1;
		end=self.location.search.indexOf("&",begin);

		if(end==(-1)) {
			end=self.location.search.length;
		}

		return(self.location.search.substring(begin,end));

       } else {
              locStr = locStr.split('/');
              return(aryValueOf(locStr, param));
       }
}

//Returns the value of a cookie.
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;
}

//This function is used to extract the value once the cookie is found based on its offset.
//This function is used by GetCookie 
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//This sets a cookie.
function SetCookie (name, value) { 
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

