var objFileUtils = new Object();

//The following are already available for use in the location object:
//hash - The URL anchor part including the leading hash mark if one exists 
//host - The URL hostname and port.
//hostname - The URL hostname section 
//href - The entire URL. The following code will load the home CTDP page: 
//pathname - The URL pathname section 
//port - The URL port section. 
//protocol - The URL protocol section including the colon after the protocol name. The values are normally http: or file: 
//search - The URL query string section. This is the section after and including the question mark. 
//target - The URL link's target name


//This is the protocol plus the colon and slashes
objFileUtils.getProtocol = function () {
	if (document.location.href.indexOf("://")==-1) return null;
	return document.location.href.substr(0,document.location.href.indexOf("://")+3);
}

//This is the full URL including the filename, but excluding the trailing hash and querystring
objFileUtils.getFullPath = function () {
	return document.location.protocol+"//"+document.location.hostname+document.location.pathname;
}

//This is the current filename, but excluding the trailing hash and querystring
objFileUtils.getFilename = function () {
	var strFullPath = this.getFullPath();
	if (strFullPath.lastIndexOf("/")<strFullPath.indexOf("://")+3) return null;
	return strFullPath.substr(strFullPath.lastIndexOf("/")+1);
}

//This is the full URL excluding the filename and trailing hash and querystring
objFileUtils.getFullDirectory = function () {
	var strFullPath = this.getFullPath();
	if (strFullPath.lastIndexOf("/")<strFullPath.indexOf("://")+3) return null;
	return strFullPath.substr(0,strFullPath.lastIndexOf("/"));
}

//this is the current directory
objFileUtils.getCurrentDirectory = function () {
	var strFullDirectory = this.getFullDirectory();
	if (!strFullDirectory) return null;
	var intIndexSlash = strFullDirectory.lastIndexOf("/")
	if (intIndexSlash==-1) return null;
	return strFullDirectory.substr(intIndexSlash+1);
}

//this will replace the hostname
objFileUtils.replaceHostname = function (strOriginalUrl,strNewHostname) {
	var intColonSlashIndex = strOriginalUrl.indexOf("://");
	if (intColonSlashIndex==-1) return strOriginalUrl;
	var strProtocol = strOriginalUrl.substr(0,intColonSlashIndex+3);
	var strPath=strOriginalUrl.substr(intColonSlashIndex+3);
	strPath=strPath.substr(strPath.indexOf("/"));
	var strNewUrl=strProtocol+strNewHostname+strPath;
	return strNewUrl;
}

//this is the current directory
objFileUtils.getEventIdDirectory = function () {
	var strFullDirectory = this.getFullDirectory();
	if (!strFullDirectory) return null;
	var intIndexSlash = strFullDirectory.lastIndexOf("/event/")
	if (intIndexSlash==-1) return null;
	var strEventId = strFullDirectory.substr(intIndexSlash+7,5);
	if (strEventId.length==5 && strEventId.charAt(4)=="/") strEventId = strEventId.substr(0,4);
	return strEventId;	
}

//this is the current directory
objFileUtils.getEventIdDirectory2 = function () {
	var strFullDirectory = this.getFullDirectory();
	if (!strFullDirectory) return null;
	var intIndexSlash = strFullDirectory.lastIndexOf("/event/");
	if (intIndexSlash==-1) intIndexSlash = strFullDirectory.lastIndexOf("/events/");
	if (intIndexSlash==-1) return null;
	var intIndexRoot = strFullDirectory.lastIndexOf("/rt/");
	var strEventId = strFullDirectory.substring(intIndexSlash,intIndexRoot);
	strEventId = strEventId.replace(new RegExp("/event/","gi"),"");
	strEventId = strEventId.replace(new RegExp("/events/","gi"),"");
	strEventId = strEventId.replace(new RegExp("/","gi"),"");
	return strEventId;	
}


