
var glbDebug    = 0;
var glbCurrentDateYYYY_MM_DD	= "";
var glbCurrentDateMM_DD_YYYY	= "";
var glbCurrentDateDD_MM_YYYY	= ""
var glbCurrentYear      	= ""; //YYYY
var glbCurrentDay      		= ""; //DD
var glbCurrentMonth    		= ""; //MM
var glbCurrentDayoftheWeek	= ""; //Sunday<->Saturday
var glbDASH                     = "-";

getCurrentDate(glbDASH);

function makeArray() {
  var args = makeArray.arguments;
  for (var i = 0; i < args.length; i++) {
    this[i] = args[i];
  }
  this.length = args.length;
}

function getCurrentDate(sdsep) {
  if ( (sdsep == null) || (sdsep == "") ) { sdsep = "-"};
  var sdDays = new makeArray("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  
  var sdCurrent = new Date();
  if (sdCurrent.getDate() < 10) {
     glbCurrentDay = "0" + sdCurrent.getDate();
  }
  else {
     glbCurrentDay = sdCurrent.getDate();
  }
  glbCurrentMonth = sdCurrent.getMonth() + 1;
  if (glbCurrentMonth < 10) {
     glbCurrentMonth = "0" + glbCurrentMonth;
  }
  
  glbCurrentYear = sdCurrent.getFullYear();
  glbCurrentDayoftheWeek = sdDays[sdCurrent.getDay()];
  glbCurrentDateYYYY_MM_DD = "" + glbCurrentYear  + sdsep + glbCurrentMonth + sdsep + glbCurrentDay;
  glbCurrentDateMM_DD_YYYY = "" + glbCurrentMonth + sdsep + glbCurrentDay   + sdsep + glbCurrentYear;
  glbCurrentDateDD_YY_YYYY = "" + glbCurrentDay + sdsep + glbCurrentMonth   + sdsep + glbCurrentYear; 
  if (glbDebug > 0) { alert ("Today is " + glbCurrentDayoftheWeek + ", " + glbCurrentDateMM_DD_YYYY) };
}

function relative(resourceURL, locationURL) {
	var relativePath = "";
	
	if ( (resourceURL.indexOf("http://") == 0) || (resourceURL.indexOf("https://") == 0) || resourceURL.indexOf("javascript:pop") ==0 ) { //		
		return resourceURL;
	}
	else if (resourceURL.indexOf("#") == 0) {
			relativePath = "#";
			return relativePath;
	}
	
	aResource = resourceURL.substring(1, resourceURL.length).split("/");
	aLocation = locationURL.substring(1, locationURL.length).split("/");

	// first, remove anything in either path that is common
	var start = 0;
	
	for (m=0; m<aResource.length; m++) {
		if (m <= aLocation.length && aResource[m] != aLocation[m]) {
			start = m;			
			break;					
		}
	}
	
	aResource = aResource.slice(start, aResource.length);
	aLocation = aLocation.slice(start, aLocation.length);
	
	// then, get the relativePathative path from locationURL to the root
	var n = 0;
	while (n < aLocation.length-1) {
		relativePath += "../";
		n++;		
	}

	// lastly, add each remaining element of the resource path to the relativePath path.
	for (p=0; p<aResource.length; p++) {
		relativePath = (p==aResource.length-1)?relativePath + aResource[p]:relativePath + aResource[p] + "/";
	}

	return relativePath;
}