
var theOpenRow=-1;
function showAgencyDetails(theIndex){
	if(theOpenRow>-1){
		hideAgencyDetails(theOpenRow);
	}
	var theId="show_hide_row_"+theIndex;
	document.getElementById(theId).className="show_row";
	theId="show_hide_details_"+theIndex;
	document.getElementById(theId).innerHTML='<a href="javascript:hideAgencyDetails('+theIndex+');">Hide Details</a>';
	theId="show_hide_details_row_"+theIndex;
	document.getElementById(theId).style.display="";
	theOpenRow=theIndex;
}
function hideAgencyDetails(theIndex){
	theOpenRow=-1;
	var theId="show_hide_row_"+theIndex;
	document.getElementById(theId).className="hide_row";
	theId="show_hide_details_"+theIndex;
	document.getElementById(theId).innerHTML='<a href="javascript:showAgencyDetails('+theIndex+');">Show Details</a>';
	theId="show_hide_details_row_"+theIndex;
	document.getElementById(theId).style.display="none";
}
var theOpenBorough="";
function showBoroughEvents(theBorough){
	hideBoroughEvents(theOpenBorough)
	var theId="all_events"
	if(theBorough.length>0){
		theId=theBorough.replace(" ","_").toLowerCase()+"_events";
	}
	document.getElementById(theId).style.display="";
	theOpenBorough=theBorough;
}
function hideBoroughEvents(theBorough){
	var theId="all_events"
	if(theBorough.length>0){
		var theId=theBorough.replace(" ","_").toLowerCase()+"_events";
	}
	document.getElementById(theId).style.display="none";
	theOpenBorough="";
}

function showPageSettings(){
	var myHeight=0;
	var scrOfY=0;
	if( document.body && document.body.scrollHeight) {
	    //DOM compliant
	    scrOfY = document.body.scrollHeight;
	} else if( document.documentElement && document.documentElement.scrollHeight) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollHeight;
	}
	var theField=document.getElementById("footer_td");
	var posy = theField.offsetTop;
    tempEl = theField.offsetParent;
    while (tempEl != null) {
		posy += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	var theHeight=document.getElementById("page_settings_popup").offsetHeight;
	var theWidth=430;
	document.getElementById("page_settings_shim").style.height=document.body.scrollHeight;
	document.getElementById("page_settings_shim").style.width=document.body.clientWidth;
	document.getElementById("page_settings_shim").style.top = 0;
	document.getElementById("page_settings_shim").style.left = 0;
	document.getElementById("page_settings_shim").style.display = "";
	document.getElementById("page_settings_shim").style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	document.getElementById("page_settings_popup").style.top = 200;
	document.getElementById("page_settings_popup").style.left=227;
	document.getElementById("page_settings_popup").style.display = "";
	document.getElementById("my311SelectDate").style.display = "none";
	if( document.body && document.body.scrollHeight) {
	    //DOM compliant
	    scrOfY = document.body.scrollHeight;
	} else if( document.documentElement && document.documentElement.scrollHeight) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollHeight;
	}
	if(scrOfY>posy){
		document.getElementById("footer_spacer").style.height=(scrOfY-posy)+12+"px";
		document.getElementById("footer_spacer").style.display="";
	}
}
function hidePageSettings(){
	document.getElementById("page_settings_shim").style.display = "none";
	document.getElementById("page_settings_popup").style.display = "none";
	document.getElementById("footer_spacer").style.display="none";
	document.getElementById("my311SelectDate").style.display = "";
}

function showAddressDetails(){
	SetCookie('isExpandDaiCookieValue', 'true');
	if(document.getElementById('address_details_link')){
	  document.getElementById('address_details_link').innerHTML='<a href="javascript:hideAddressDetails()">Hide Details</a>';
	  document.getElementById('address_details').style.display="";
	}
}
function hideAddressDetails(){
    if(document.getElementById('address_details_link')){
      document.getElementById('address_details_link').innerHTML='<a href="javascript:showAddressDetails()">Show Details</a>';
	  document.getElementById('address_details').style.display="none";
    }
	SetCookie('isExpandDaiCookieValue', 'false');
}

function showMap(){
	var theHeight=document.getElementById("map").offsetHeight;
	var theWidth=document.getElementById("map").offsetWidth;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = 253;
	document.getElementById("shim").style.left = 20;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("shim").style.display = "";
	document.getElementById("map").style.top = 253;
	document.getElementById("map").style.left=20;
	document.getElementById("map").style.visibility = "visible";
	document.getElementById("map").style.display = "";
	scrollTo(0,253);
}

function hideMap(){
	document.getElementById("map").style.visibility = "hidden";
	document.getElementById("map").style.display = "none";
	document.getElementById("shim").style.visibility = "hidden";
	document.getElementById("shim").style.display = "none";
}

function selectLocation(theIndex){
	clearSelected();
	var theId="map_locations_"+theIndex;
	document.getElementById(theId).parentNode.id="highlight";	
}

function clearSelected(){
	if(document.getElementById('highlight')){
		document.getElementById('highlight').id='';
	}
}

function toggleIntersection(whichType)
{
	var intersection = document.getElementById("location_info_intersection");
	var street = document.getElementById("location_info_street");
	
	if(whichType.toLowerCase()=="intersection") 
	{
		street.style.display="none";
		intersection.style.display="inline";
	}
	else 
	{
		intersection.style.display="none";
		street.style.display="inline";
	}
}

function toggleFeedback(whichItem){
	if(whichItem=="sr_create"){
		var theStyle = document.getElementById('sr_create_feedback_table').style.display;		
		if(theStyle == "none"){
			document.getElementById('sr_create_feedback_table').style.display = "block";
		}else{			
			document.getElementById('sr_create_feedback_table').style.display = "none";
		}
	}else if(whichItem=="sr_lookup"){
		var theStyle = document.getElementById('sr_lookup_feedback_table').style.display;
		if(theStyle == "none"){
			document.getElementById('sr_lookup_feedback_table').style.display = "block";
		}else{
			document.getElementById('sr_lookup_feedback_table').style.display = "none";
		}
	}else if(whichItem=="hhs"){
		var theStyle = document.getElementById('hhs_feedback_table').style.display;
		if(theStyle == "none"){
			document.getElementById('hhs_feedback_table').style.display = "block";
		}else{
			document.getElementById('hhs_feedback_table').style.display = "none";	
		}
	} else if(whichItem=="picVidSubmission"){
		var theStyle = document.getElementById('picVidSubmission_feedback_table').style.display;
		if(theStyle == "none"){
			document.getElementById('picVidSubmission_feedback_table').style.display = "block";
		}else{
			document.getElementById('picVidSubmission_feedback_table').style.display = "none";	
		}
	}
}

function showWarning(theText){
	var scrOfY=0;
	if( document.body && document.body.scrollTop) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	} else if( document.documentElement && document.documentElement.scrollTop) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	}
	if(scrOfY<165){
		scrOfY=165;
	}
	document.getElementById("warning_text").innerHTML=theText;
	document.getElementById("shim").style.height=document.getElementById("warning_popup").offsetHeight;
	document.getElementById("shim").style.width=document.getElementById("warning_popup").offsetWidth;
	document.getElementById("warning_popup").style.top = scrOfY;
	document.getElementById("warning_popup").style.visibility = "visible";
	document.getElementById("shim").style.top = scrOfY;
	document.getElementById("shim").style.left = document.getElementById("warning_popup").style.left;
	document.getElementById("shim").style.visibility = "visible";
}

function hideWarning(){
	document.getElementById("warning_popup").style.visibility = "hidden";
	document.getElementById("shim").style.visibility = "hidden";
}

function showHelp(helpIndex,theId){
	var theField=document.getElementById(theId);
	var posy = theField.offsetTop;
	var posx = theField.offsetLeft;
	tempEl = theField.offsetParent;
	while (tempEl != null){
		posy += tempEl.offsetTop;
		posx += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	var theHelpIndex=-1;
	for(var i=0;i<helpText.length;i++){
		if(helpText[i][0].toLowerCase()==helpIndex.toLowerCase()){
			theHelpIndex=i;
		}
	}
	if(theHelpIndex>-1){
		document.getElementById("help_title").innerHTML=helpText[theHelpIndex][0];
		document.getElementById("help_text").innerHTML=helpText[theHelpIndex][1];
	}else{
		document.getElementById("help_title").innerHTML="Help Text Missing";
		document.getElementById("help_text").innerHTML="The specified help index ("+helpIndex+") was not found";
	}
	var theHeight=document.getElementById("help_popup").offsetHeight;
	var theWidth=document.getElementById("help_popup").offsetWidth;
	posy=posy+28;
	posx=posx-330;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = posy;
	document.getElementById("shim").style.left = posx;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("help_popup").style.top = posy;
	document.getElementById("help_popup").style.left=posx;
	document.getElementById("help_popup").style.visibility = "visible";
}
function showHelpWithContent(helpIndex,theId,helpContent){
	var theField=document.getElementById(theId);
	var posy = theField.offsetTop;
	var posx = theField.offsetLeft;
	tempEl = theField.offsetParent;
	while (tempEl != null){
		posy += tempEl.offsetTop;
		posx += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	document.getElementById("help_title").innerHTML=helpIndex;
	document.getElementById("help_text").innerHTML=helpContent;
		
	var theHeight=document.getElementById("help_popup").offsetHeight;
	var theWidth=document.getElementById("help_popup").offsetWidth;
	posy=posy+28;
	posx=posx-330;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = posy;
	document.getElementById("shim").style.left = posx;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("help_popup").style.top = posy;
	document.getElementById("help_popup").style.left=posx;
	document.getElementById("help_popup").style.visibility = "visible";
}

function showHelpLabel(theId,helpIndex){
	var theField=document.getElementById(theId);
	var posy = theField.offsetTop;
	var posx = theField.offsetLeft;
	tempEl = theField.offsetParent;
	while (tempEl != null){
		posy += tempEl.offsetTop;
		posx += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	var theHelpIndex=-1;
	for(var i=0;i<helpText.length;i++){
		if(helpText[i][0].toLowerCase()==helpIndex.toLowerCase()){
			theHelpIndex=i;
		}
	}
	if(theHelpIndex>-1){
		document.getElementById("help_title").innerHTML=helpText[theHelpIndex][0];
		document.getElementById("help_text").innerHTML=helpText[theHelpIndex][1];
	}else{
		document.getElementById("help_title").innerHTML="Help Text Missing";
		document.getElementById("help_text").innerHTML="The specified help index ("+helpIndex+") was not found";
	}
	var theHeight=document.getElementById("help_popup").offsetHeight;
	var theWidth=document.getElementById("help_popup").offsetWidth;
	posy=posy+35;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = posy;
	document.getElementById("shim").style.left = posx;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("help_popup").style.top = posy;
	document.getElementById("help_popup").style.left=posx;
	document.getElementById("help_popup").style.visibility = "visible";
}
function hideHelp(){
	document.getElementById("help_popup").style.visibility = "hidden";
	document.getElementById("shim").style.visibility = "hidden";
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function showElements(){
	var arr=showElements.arguments;
	for(i=0;i<arr.length;i++){
		show(arr[i]);
	}
}

function showDetails(theIndex){
	var theLink="show_hide_link_"+theIndex;
	var theDetails="show_hide_"+theIndex;
	var textContent=document.getElementById(theLink).firstChild.firstChild.nodeValue;
	show(theDetails);
	var theNewLink='<a href="javascript:hideDetails(\''+theIndex+'\')">'+textContent+'</a>';
	document.getElementById(theLink).innerHTML=theNewLink;
}

function hideDetails(theIndex){
	var theLink="show_hide_link_"+theIndex;
	var theDetails="show_hide_"+theIndex;
	var textContent=document.getElementById(theLink).firstChild.firstChild.nodeValue;
	hide(theDetails);
	var theNewLink='<a href="javascript:showDetails(\''+theIndex+'\')">'+textContent+'</a>';
	document.getElementById(theLink).innerHTML=theNewLink;
}


function hideElements(){
	var arr=hideElements.arguments;
	for(i=0;i<arr.length;i++){
		hide(arr[i]);
	}
}

function toggleElements(){
	var arr=toggleElements.arguments;
	for(i=0;i<arr.length;i++){
		toggle(arr[i]);
	}
}

function show(whichElement){
	document.getElementById(whichElement).style.display="";
}

function hide(whichElement){
	document.getElementById(whichElement).style.display="none";
}

function toggle(whichElement){
	var theStyle=document.getElementById(whichElement).style;
	theStyle.display = theStyle.display? "":"none";
}

function showResidency(isLocal){
	if(isLocal){
		hide("non-local_resident");
		show("local_resident");
	}else{
		show("non-local_resident");
		hide("local_resident");
	}
}

function showTranslate(){
	//$('#translate_popup').show();
	document.getElementById("translate_popup").style.display="";
	document.getElementById("translate_popup").style.visibility="visible";
}

function hideTranslate(){
	//$('#translate_popup').hide();
	document.getElementById("translate_popup").style.display="none";
	document.getElementById("translate_popup").style.visibility="hidden";
}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) {// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
}			
		
function showHelpLabelText(theId,helpKey, helpText){
	var theField=document.getElementById(theId);
	var posy = theField.offsetTop;
	var posx = theField.offsetLeft;
	tempEl = theField.offsetParent;
	while (tempEl != null){
		posy += tempEl.offsetTop;
		posx += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	if(helpText != null){
		document.getElementById("help_title").innerHTML=helpKey;
		document.getElementById("help_text").innerHTML=helpText;
	}else{
		document.getElementById("help_title").innerHTML="Help Text Missing";
		document.getElementById("help_text").innerHTML="The specified help key ("+helpKey+") was not found";
	}
	var theHeight=document.getElementById("help_popup").offsetHeight;
	var theWidth=document.getElementById("help_popup").offsetWidth;
	posy=posy+35;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = posy;
	document.getElementById("shim").style.left = posx;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("help_popup").style.top = posy;
	document.getElementById("help_popup").style.left=posx;
	document.getElementById("help_popup").style.visibility = "visible";
}


function showHelpLabelText311Online(theId,helpKey, helpTextField, isField){
	var theField=document.getElementById(theId);
	var posy = theField.offsetTop;
	var posx = theField.offsetLeft;
	tempEl = theField.offsetParent;
	var helpText = '';
	if(isField=="true")
	{
		helpText = document.getElementById(helpTextField).value;
	}
	
	while (tempEl != null){
		posy += tempEl.offsetTop;
		posx += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	
	if(helpText != null){
		document.getElementById("help_title").innerHTML=helpKey;
		document.getElementById("help_text").innerHTML=helpText;
	}else{
		document.getElementById("help_title").innerHTML="Help Text Missing";
		document.getElementById("help_text").innerHTML="The specified help key ("+helpKey+") was not found";
	}
	var theHeight=document.getElementById("help_popup").offsetHeight;
	var theWidth=document.getElementById("help_popup").offsetWidth;
	posy=posy+35;
	document.getElementById("shim").style.height=theHeight;
	document.getElementById("shim").style.width=theWidth;
	document.getElementById("shim").style.top = posy;
	document.getElementById("shim").style.left = posx;
	document.getElementById("shim").style.visibility = "visible";
	document.getElementById("help_popup").style.top = posy;
	document.getElementById("help_popup").style.left=posx;
	document.getElementById("help_popup").style.visibility = "visible";
}

function toggleCheckBox(el) {
	var all_unchecked = true;
	var $parent = $(el).closest("div");
	$parent.children("input:checkbox").each(function() {
		if($(this).is(":checked")) {
			all_unchecked = false;
			return false;
		}
	});
	
	if(all_unchecked) {
		//check __empty_checkbox
		$parent.find("span input:checkbox").attr("checked", "checked");
	} else {
		//uncheck __empty_checkbox
		$parent.find("span input:checkbox").removeAttr("checked");
	}
}

function splitDestinationUrl(url)
{
	var actualUrl = url;
	var domainUrl;
	var restOfTheUrl;
	var qwe = actualUrl.indexOf(":");

	if(qwe != -1)
	{
		var domainIndex = qwe + 3;
		var domainEndIndex = actualUrl.indexOf("/", domainIndex);
		domainUrl = actualUrl.substring(domainIndex,domainEndIndex );
		//Check whether URL is for Universal Intake and change if so for webtrends
		var verifyString = actualUrl.substring(domainEndIndex);
		if(verifyString.match("apps/311universalintake/form.htm") == "apps/311universalintake/form.htm")
			restOfTheUrl = "/apps/311universalintake/form.htm";
		else
			restOfTheUrl = verifyString;
	}
	else
	{
		domainUrl = window.location.host;
		restOfTheUrl = "/apps/311/"+actualUrl.substring(0);
	}
	var urlArray = [domainUrl, restOfTheUrl];
	return urlArray;
}





/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDivId, iFrameDivID) {
	// we know that Opera doesn't like something about this, so if we
	// think we're using Opera, don't even try
	var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
	if (is_opera)
		return;
  
	// put a try/catch block around the whole thing, just in case
	try {
		if (!document.getElementById(iFrameDivID)) {
			// don't use innerHTML to update the body, because it can cause global variables
			// that are currently pointing to objects on the page to have bad references
			//document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
			var newNode = document.createElement("iFrame");
			newNode.setAttribute("id", iFrameDivID);
			newNode.setAttribute("src", "javascript:false;document.open();document.write('');document.close();");
			newNode.setAttribute("scrolling", "no");
			newNode.setAttribute ("frameborder", "0");
			document.body.appendChild(newNode);
		}
    
		var pickerDiv = document.getElementById(pickerDivId);
		var iFrameDiv = document.getElementById(iFrameDivID);
    
		try {
			iFrameDiv.style.position = "absolute";
			iFrameDiv.style.width = pickerDiv.offsetWidth;
			iFrameDiv.style.height = pickerDiv.offsetHeight;
			iFrameDiv.style.top = pickerDiv.style.top;
			iFrameDiv.style.left = pickerDiv.style.left;
			iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
			iFrameDiv.style.visibility = pickerDiv.style.visibility ;
			iFrameDiv.style.display = pickerDiv.style.display;
		} catch(e) {
		} 
	} catch(ee) {
	}
}

