﻿
function getArgs() {
  var args = new Object();
  // Get Query String
  var query = location.search.substring(1);
  // Split query at the comma
  var pairs = query.split("&");
  // Begin loop through the querystring
  for(var i = 0; i < pairs.length; i++) {
    // Look for "name=value"
    var pos = pairs[i].indexOf('=');
    // if not found, skip to next
    if (pos == -1) continue;
    // Extract the name
    var argname = pairs[i].substring(0,pos);
    // Extract the value
    var value = pairs[i].substring(pos+1);
    // Store as a property
    args[argname] = unescape(value);
  }
  return args; // Return the Object
}

function translate() {
  var args = getArgs();
  if (args.page) wl_ourl = (args.page);
  top.location.href = wl_url + 'http://dc.gov/translations.asp?page=' + wl_ourl;
}

var totalPPL = 8;
var menuTimeout	= 100;

function rndImg(img, path) {
  if (path == null) {path = ""};
  if (goCookies) {
    var x = myCookie.counter;
  } else {
    var x = parseInt(1 + (Math.random() % 10) * totalPPL);
  }
  var imgString = "" + path + img + x + ".jpg";
  return imgString;
};

function fosRnd(fos) {
  x = document.getElementById(fos).style;
  x.backgroundImage = 'url("' + rndImg('fos_bg_','/images/') + '")';
  x.backgroundRepeat = 'no-repeat';
  x.backgroundPosition = 'bottom right';
};

function posElementX(element, reference) {
	document.getElementById(element).style.left = getAnchorX(reference) - 110;
};

function move_in(img_name,img_src) {
	document[img_name].src="" + img_src;
};

function move_out(img_name,img_src) {
	document[img_name].src="" + img_src;
};

var dropTransURL;
dropTransURL = document.location.href;

drop0 = [
	[],
	[110, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["Main", "http://dc.gov/?portal_link=hr"],
	["Login to DC.Gov", "http://dc.gov/registration/login.asp?portal_link=hr"],
	["Today", "http://dc.gov/more_news.asp?portal_link=hr"],
	["News", "http://dc.gov/mayor/news/index.asp?portal_link=hr"],
	["Calendar", "http://app.calendar.dc.gov/?portal_link=hr"],
	["Closures", "http://dc.gov/closures/?portal_link=hr"],
	["eServices", "http://dc.gov/more_services.asp?category=all&tab=0&portal_link=hr"],
	["Translations", "http://dc.gov/translations.asp?portal_link=hr&page="+dropTransURL]
];
drop1 = [
	[],
	[110, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["DC Guide Home", "http://about.dc.gov/index.asp?portal_link=hr"],
	["Find It", "http://citizenatlas.dc.gov/atlasapps/findit.aspx?portal_link=hr"],
	["Get There", "http://citizenatlas.dc.gov/atlasapps/itinerary.aspx?portal_link=hr"],
	["Where You Live", "http://citizenatlas.dc.gov/atlasapps/reporthometab.aspx?portal_link=hr"],
	["Make a Map", "http://citizenatlas.dc.gov/atlasapps/custommapsearch.aspx?portal_link=hr"],
	["About DC", "http://about.dc.gov/about.asp?portal_link=hr"],
	["DC Statehood", "http://about.dc.gov/statehood.asp?portal_link=hr"]
];
drop2 = [
	[],
	[118, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["Residents Home", "http://rrc.dc.gov/rrc/site/default.asp?rrcNav_GID=0&portal_link=hr"],
	["Live in DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1193&Q=447184&rrcNav_GID=1415&portal_link=hr"],
	["Work in DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1184&Q=447156&rrcNav_GID=1416&portal_link=hr"],
	["Play in DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1182&Q=447149&rrcNav_GID=1417&portal_link=hr"],
	["Move to DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1186&Q=447163&rrcNav_GID=1418&portal_link=hr"],
	["Volunteer in DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1189&Q=447170&rrcNav_GID=1419&portal_link=hr"],
	["Getting Around DC", "http://rrc.dc.gov/rrc/cwp/view.asp?a=1191&Q=447177&rrcNav_GID=1420&portal_link=hr"]
];
drop3 = [
	[],
	[170, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["Business Home", "http://brc.dc.gov/index.asp?portal_link=hr"],
	["Licenses & Permits", "http://brc.dc.gov/licenses/licenses.asp?portal_link=hr"],
	["Development & Incentives", "http://brc.dc.gov/incentives/incentives.asp?portal_link=hr"],
	["Tax Services", "http://brc.dc.gov/tax/tax.asp?portal_link=hr"],
	["Business Planning", "http://brc.dc.gov/planning/planning.asp?portal_link=hr"],
	["Nonprofit Planning", "http://brc.dc.gov/nonprofit/nonprofit.asp?portal_link=hr"],
	["Business Resources", "http://brc.dc.gov/resources/resources.asp?portal_link=hr"]
];
drop4 = [
	[],
	[120, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["Visitors Home", "http://vrc.dc.gov/vrc/site/default.asp?vrcNav_GID=0&portal_link=hr"],
	["Tours", "http://vrc.dc.gov/vrc/cwp/view.asp?a=1196&q=446778&vrcNav_GID=1408&portal_link=hr"],
	["Travel", "http://vrc.dc.gov/vrc/cwp/view.asp?a=1198&q=446820&vrcNav_GID=1409&portal_link=hr"],
	["Accommodations", "http://vrc.dc.gov/vrc/cwp/view.asp?a=1200&q=447233&vrcNav_GID=1407&portal_link=hr"],
	["Visitor Resources", "http://vrc.dc.gov/vrc/cwp/view.asp?a=1199&q=447107&vrcNav_GID=1410&portal_link=hr"]
];
drop5 = [
	[],
	[119, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["DC Government Home", "http://grc.dc.gov/grc/site/default.asp?grcNav_GID=0&portal_link=hr"],
	["DC Council", "http://grc.dc.gov/grc/cwp/view.asp?a=1206&q=447541&grcNav_GID=1421&portal_link=hr"],
	["DC Agencies", "http://dc.gov/agencies/index.asp?portal_link=hr"],
	["Elected Officials", "http://grc.dc.gov/grc/cwp/view.asp?a=1203&Q=447121&grcNav_GID=1424&portal_link=hr"],
	["Courts", "http://grc.dc.gov/grc/cwp/view.asp?a=1201&Q=447114&grcNav_GID=1422&portal_link=hr"],
	["DC Laws", "http://grc.dc.gov/grc/cwp/view.asp?a=1205&Q=447198&grcNav_GID=1423&portal_link=hr"]
];
drop6 = [
	[],
	[105, 0, "#000000", 1, "#FFFFFF", "drop1", "left"],
	["Mayor's Home", "http://dc.gov/mayor/index.shtm?portal_link=hr"],
	["Contact the Mayor", "http://app.dc.gov/apps/about.asp?page=atd&type=dsf&referrer=%5b$DSF_SERVER_NAME$%5d&agency_id=1075&portal_link=hr"],
	["Schedule", "http://dc.gov/mayor/schedule.asp?portal_link=hr"],
	["Photo Gallery", "http://dc.gov/mayor/photogallery.asp?portal_link=hr"],
	["For the Press", "http://dc.gov/mayor/news/index.asp?portal_link=hr"],
	["Newsletter", "http://dc.gov/mayor/newsletter.shtm"],
	["Appointees", "http://dc.gov/mayor/organization.shtm?portal_link=hr"]
];
var tempTable = new Object();
var TimerID = 100;

function constructTable(arrayName) {
	var startPos = 0;
	var tableProperties = startPos + 1;
	var tableElements = tableProperties + 1;
	var tableCode = tableCodeFront = tableCodeMiddle = tableCodeBack = tempText = tempURL = '';

	tempTable = {
		tableWidth: eval(arrayName)[tableProperties][0],
		tablePadding: eval(arrayName)[tableProperties][1],
		tableBorderColor: eval(arrayName)[tableProperties][2],
		tableBorderSize: eval(arrayName)[tableProperties][3],
		tableBGColor: eval(arrayName)[tableProperties][4],
		textClass: eval(arrayName)[tableProperties][5]
	};


	var tableCodeFront = '<table border="0" width="' + tempTable.tableWidth + '" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="' + tempTable.tableBorderColor + '"><table border="0" width="100%" cellspacing="' + tempTable.tableBorderSize + '" cellpadding="' + tempTable.tablePadding + '"><tr><td width="100%" bgcolor="' + tempTable.tableBGColor + '"><img src="http://dc.gov/images/dot.gif" width="1" height="5" alt=""><br><table width="100%" bgcolor="" cellpadding="0" cellspacing="0" border="0">';
	var tableCodeBack = '</table><img src="http://dc.gov/images/dot.gif" width="1" height="5" alt=""><br></td></tr></table></td></tr></table>';

	for (i = tableElements; i < eval(arrayName).length; i++) {
	tempText = eval(arrayName)[i][0];
	tempURL = eval(arrayName)[i][1];
		if (eval(arrayName)[i][2] == '>') {
			tableCodeMiddle += '<tr style="cursor:hand;"><td onmouseover="this.className=\'' + tempTable.textClass + 'On\';" onmouseout="this.className=\'' + tempTable.textClass + 'Off\';" onclick="top.location.href=\'' + tempURL + '\'" class="' + tempTable.textClass + 'Off"><table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td width="5"><img src="http://dc.gov/images/dot.gif" width="5" height="1" alt=" " border="0"></td><td width="100%" class="' + tempTable.textClass + 'Off"><a href="' + tempURL + '">' + tempText + '</a></td><td width="19"><table cellpadding=0 cellspacing=0 border=0><tr><td><a href="' + tempURL + '"><img src="/images/outsidelink_icon.gif" width="14" height="12" alt="external site" border="0"></a></td><td><img src="/images/dot.gif" width="5" height="1" alt=" " border="0"></td></tr></table></td></tr></table></td></tr>';
		} else {
			tableCodeMiddle += '<tr style="cursor:hand;"><td onmouseover="this.className=\'' + tempTable.textClass + 'On\';" onmouseout="this.className=\'' + tempTable.textClass + 'Off\';" onclick="top.location.href=\'' + tempURL + '\'" class="' + tempTable.textClass + 'Off"><table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td width="5"><img src="http://dc.gov/images/dot.gif" width="5" height="1" alt=" " border="0"></td><td width="100%" class="' + tempTable.textClass + 'Off"><a href="' + tempURL + '">' + tempText + '</a></td><td width="5"><img src="http://dc.gov/images/dot.gif" width="5" height="1" alt=" " border="0"></td></tr></table></td></tr>';
		};
  };


	tableCode = tableCodeFront + tableCodeMiddle + tableCodeBack;
	return tableCode;
};

function showtip(state,	name, offsetx, offsety) {
	if (TimerID) clearTimeout(TimerID);
	if (state) {
 		if (document.layers) {
			theString = "<LAYER onmouseout=\"showtip(0)\">" + constructTable(name) + "</LAYER>";
			document.tooltip.document.write(theString);
			document.tooltip.document.close();
			document.tooltip.left = offsetx;
			document.tooltip.top =  offsety;
			document.tooltip.visibility = "show";
		} else {
			if (document.getElementById) {
				elm = document.getElementById("tooltip");
				elm.innerHTML =	constructTable(name);
				elm.style.left = offsetx;
				elm.style.top =	offsety;
				elm.style.visibility = "visible";
			}
		}
	} else {
		if (document.layers) {
			document.tooltip.visibility = "hidden";
		} else if (document.getElementById) {
			elm.style.visibility = "hidden";
		};
	};
};

function showMenu() {
	var totalArguments = arguments.length;
	var onOff = arguments[0];
	var arg1 = arguments[1];
	var arg2 = arguments[2];
	var arg3 = arguments[3];

	if (onOff) {
		clearTimeout(TimerID);
		showtip(1, arg1, arg2, arg3);
		} else {
		clearTimeout(TimerID);
		TimerID	= setTimeout('showtip(0)', menuTimeout);
	};
};

function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if	(document.all) { use_css=true; }
	else if	(document.layers) { use_layers=true; };
	if (use_gebi &&	document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	} else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
	} else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	} else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; };
		};
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
		};
		x=document.anchors[i].x;
		y=document.anchors[i].y;
	} else {
		coordinates.x=0; coordinates.y=0; return coordinates;
	};
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
};

function AnchorPosition_getPageOffsetLeft (el) {
	var ol = el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; };
	return ol;
};

function AnchorPosition_getPageOffsetTop (el) {
	var ot = el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; };
	return ot;
};

function getAnchorX(name) {
	var x =	getAnchorPosition(name);
	return x.x;
};

function getAnchorY(name) {
	var x =	getAnchorPosition(name);
	return x.y;
};

function formHandler(x){
	var URL = x.options[x.selectedIndex].value;
	top.location.href = URL;
};

function Cookie(document, name, hours, path, domain, secure) {
	this.$doc = document;
	this.$name = name;
	if (hours) this.$expiration = new Date((new Date()).getTime() + hours * 3600000); else this.$expiration = null;
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null;
	if (secure) this.$secure = true; else this.$secure = false;
};

function CookieWrite() {
	var cookieval = "";
	for(var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || prop == '') continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ":" + escape(this[prop]);
	};

	var cookie = this.$name + "=" + cookieval;
	if (this.$expiration) cookie += '; expires=' + this.$expiration.toGMTString();
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	if (this.$secure) cookie += '; secure';
	this.$doc.cookie = cookie;
};

function CookieRead() {
	var allcookies = this.$doc.cookie;
	if (allcookies=="") {
		return false;
	};

	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) {
		return false;
	};

	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);
	var a = cookieval.split('&');
	for (var i=0; i<a.length; i++) a[i] = a[i].split(':');
	for (var i=0; i<a.length; i++) this[a[i][0]] = unescape(a[i][1]);
	return true;
};

function CookieDelete() {
	var cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	this.$doc.cookie = cookie;
};

new Cookie();
Cookie.prototype.write = CookieWrite;
Cookie.prototype.del = CookieDelete;
Cookie.prototype.read = CookieRead;

var myCookie = new Cookie(document, "DC", 365, "/");

if (!myCookie.read() || !myCookie.counter) {myCookie.counter = 0};

myCookie.counter++;

if (myCookie.counter > totalPPL) {myCookie.counter = 1};

myCookie.write();

if (!myCookie.read() || !myCookie.counter) {
	goCookies = 0;
} else {
	goCookies = 1;
};

function clearCookie() {myCookie.del()};

function showTooltip() {
	var totalArguments = arguments.length;
	var onOff = arguments[0];
	var arg1 = arguments[1];
	var arg2 = arguments[2];
	var arg3 = arguments[3];
	var arg4 = arguments[4];

	if (onOff) {
		clearTimeout(TimerID);
		tooltipShowHide(1, arg1, arg2, arg3, arg4);
		} else {
		clearTimeout(TimerID);
		TimerID	= setTimeout('tooltipShowHide(0)', menuTimeout);
	};
};

function tooltipShowHide(state,	title, code, offsetx, offsety) {
	if (TimerID) clearTimeout(TimerID);
	if (state) {
 		if (document.layers) {
			theString = "<LAYER onmouseout=\"showTooltip(0)\">" + constructTip(title, code) + "</LAYER>";
			document.tooltip.document.write(theString);
			document.tooltip.document.close();
			document.tooltip.left = offsetx;
			document.tooltip.top =  offsety;
			document.tooltip.visibility = "show";
		} else {
			if (document.getElementById) {
				elm = document.getElementById("smallTooltip");
				elm.innerHTML =	constructTip(title, code);
				elm.style.left = offsetx;
				elm.style.top =	offsety;
				elm.style.visibility = "visible";
			}
		}
	} else {
		if (document.layers) {
			document.tooltip.visibility = "hidden";
		} else if (document.getElementById) {
			elm.style.visibility = "hidden";
		};
	};
};

function constructTip(title, code) {
	var tipFront = '<table width=130 bgcolor=\"#000000\" cellpadding=1 cellspacing=0 border=0 class=\"subLinks\"><tr><td><table bgcolor=\"#FFFFFF\" cellpadding=0 cellspacing=3 border=0 width=100%><tr><td bgcolor=\"#B80000\" style=\"font-family: arial, helvetica; font-weight: bold; font-size: 8pt;color: white;\" nowrap>&nbsp;<strong>' + title + '</strong>&nbsp;</td></tr><tr><td align=\"left\" valign=\"top\" class=\"subLinks\">';
	var tipBack  = '</td></tr></table></td></tr></table>';
	return tipFront + code + tipBack;
}

//**************** Search Form Validator for an empty field 
//**************** and set focus 
//**************** added 6/1/05 

function requireInputText(textbox, message) {
            var reNonSpace = /\S/g;
            if (reNonSpace.test(textbox.value)) 
                        return true;
            else {
                        alert(message);
                        return false;
            }
}
