// 					Document: Basic Utility Javascript Document
//					Originally created for InterWeb
//					Copyright 2000 Interact Public Safety Systems.  All Rights Reserved.
//					Created: John White, 1/5/2003
//************************************************************************************************************
//**MM_goToURL
//**Navigates to another url...used for onclick events (otherwise just use href)
//************************************************************************************************************
function MM_goToURL() { //v2.0
  for (var i=0; i< (MM_goToURL.arguments.length - 1); i+=2) //with arg pairs
    eval(MM_goToURL.arguments[i]+".location='"+MM_goToURL.arguments[i+1]+"'");
  document.MM_returnValue = false;
}
//==================================================================================================
//== displayMessageOnField
//==	Displays a message underneath a field specified as the pID. Right now this is only used
//==	for error messages, but could be used for validation errors and such.
//==================================================================================================
function displayFieldError(pID, pMessage)
{
	//-----------------------------------------------------------------------------
	// Field may already exist from a previous message.
	// Clear field first, just in case
	//-----------------------------------------------------------------------------
	//---clearDisplayFieldMessage(pID)
	var vTargetElement = document.getElementById(pID);
	vTargetElement.className = vTargetElement.className + '_flderror';
	var vNewElement = document.createElement("span");
	vNewElement.id = "flderror_" + pID;
	vNewElement.className = "fielderror";
	vNewElement.appendChild(document.createElement("br"));
	vNewElement.appendChild(document.createTextNode(unescape(pMessage)));
	//-----------------------------------------------------------------------------
	//SMR- vNewElement.parentElement.appendChild(vNewElement);
	//SMR- Can't use the W3C appendChild here because the parent element of the error field
	//SMR-   (a TD element in most cases) might not have an ID attribute.
	//-----------------------------------------------------------------------------
	// Rc added try/catch for potential backward compat. issues; based on above comments.  
	//  Catch code is needed for tech support request form.
    try
	{
		vTargetElement.parentElement.insertAdjacentElement("beforeEnd",vNewElement); 
	}
	catch(err)
	{
		vTargetElement.parentNode.appendChild(vNewElement);
	}
}

//==================================================================================================
//== clearFieldErrors
//==
//==	Clears all field errors from the form. 
//==================================================================================================
function clearFieldErrors()
{
	var vSpanArray = document.getElementsByTagName("span");
	for(i=0;i<vSpanArray.length;i++){
		if(vSpanArray[i].id.substr(0,9) == "flderror_"){
			for(ii=0;ii<vSpanArray[i].parentNode.childNodes.length;ii++){
				tempobj=vSpanArray[i].parentNode.childNodes.item(ii);
				if(tempobj.error){
					var oldstring=tempobj.className;
					var oldlength=oldstring.length;
					var tomatch=/_flderror$/;
					var is_a_match=tomatch.test(oldstring);
					if (is_a_match){
						var newString=oldstring.substring(0, oldlength-9);
						tempobj.className=newString;
						tempobj.removeAttribute('error');
					}
					break;
				}
			}
			vSpanArray[i].style.display='none';
		}
	}
	var gForm=document.forms[0];
    for (i=0;i<gForm.length;i++) 
         {
         var tempobj=gForm.elements[i];
		 var oldstring=tempobj.className;
		 var oldlength=oldstring.length;
		 var tomatch=/_flderror$/;
		 var is_a_match=tomatch.test(oldstring);
         if (is_a_match){
			var newString=oldstring.substring(0, oldlength-9);
			tempobj.className=newString;
		 }
	} 
}

//==================================================================================================
//== ValidationError
//==
//==	Takes the input from a coldfusion invoked validation error and reformats the input to
//==	call the display field error function
//==================================================================================================
function ValidationError(form, field, value, message){
	var vFieldName=field.name;
	displayFieldError(vFieldName, message);
}

//==================================================================================================
//== checkrequired
//==
//==	Scans through all fields that have a class of field_required and calls the displayFieldError
//==	function if there is no value in the field. Also, clears all field errors prior to showing
//==  	new errors
//==================================================================================================
function checkrequired(vFormName) 
{
clearFieldErrors();
try
{
	var gForm = document.forms[vFormName];	
}
catch(err)
{
	var gForm = document.forms[0];	
}
var pass=true;
if (document.images) 
    {
	for (i=0;i<gForm.length;i++) 
         {
		 var tempobj=gForm.elements[i];
         if ((tempobj.className=="field_required")||(tempobj.className=="littlefield_required"))
              {
				if (tempobj.value=='')
                   {
                   displayFieldError(tempobj.name, 'Required Field.');
				   var pass=false;
    				} 
              }
         }   
 	} 
return pass;
}


//==================================================================================================
//== checkDIV
//==
//==	Scans through all fields in a DIV that have a class of field_required and calls the displayFieldError
//==	function if there is no value in the field. DOES NOT CLEAR FIELD ERRORS BEFORE FUNCTIONING!
//==================================================================================================
function checkDIV(vDIVName) 
{
var gDIV=document.getElementById(vDIVName);
var pass=true;
if (gDIV.style.display=='block') 
    {
    for (i=0;i<gDIV.getElementsByTagName('input').length;i++) 
         {
         var tempobj=gDIV.getElementsByTagName('input')[i];
         if (tempobj.className=="field_required") 
              {
				if (tempobj.value=='')
                   {
                   displayFieldError(tempobj.name, 'Required Field.');
				   var pass=false;
    				} 
              }
         }   
    for (i=0;i<gDIV.getElementsByTagName('select').length;i++) 
         {
         var tempobj=gDIV.getElementsByTagName('select')[i];
         if (tempobj.className=="field_required") 
              {
				if (tempobj.value=='')
                   {
                   displayFieldError(tempobj.name, 'Required Field.');
				   var pass=false;
    				} 
              }
         }    
 	} 
return pass;
}
//==================================================================================================
//==
//==
//==		FILTER FUNCTIONS - The following scripts all relate to the filters on listviews
//==
//== 
//==================================================================================================

//==================================================================================================
//==   									gofilter()
//== The following function takes the values in the filter field and then appends them to the the current
//== url as the FilterBy value
//==================================================================================================
		function gofilter(vFuse) { //v2.0
		var valList = "";
		for(i=1;i<__uid;i++){
			 var vFilterBy = document.getElementById("FilterByfld"+i);
			 var SetFilterVal = "FilterBy" + vFilterBy.value + i;
			 var GetFilterVal = document.getElementById(SetFilterVal);
			 //if this is NOT the last field, put a comma at the end of the value
			 if (i==__uid-1){
			 valList += vFilterBy.value+'~'+GetFilterVal.value;
			 }
			 else{
			 valList += vFilterBy.value+'~'+GetFilterVal.value + ",";
			 }
		}	
		MM_goToURL("parent",'index.cfm?fuseaction='+vFuse+'&filterby=' + valList);
	}	
//==================================================================================================

//==================================================================================================
//==   									filtertoggle()
//== Sets the display of all of the filterby fields in the filtertable to none, and then calls
//== showfilter for the field that was selected for that particular row (if there are multiptle rows)
//==================================================================================================
	function filtertoggle(obj) { //v2.0
		var vFiltNum=obj.name.substring(11, 12);
		var tb = document.getElementById('filtertable').getElementsByTagName('tbody')[0];
		// - clone the first row of var tb
		var currentRow=tb.getElementsByTagName('tr')[vFiltNum-1];
		for (i=1;i<currentRow.getElementsByTagName('select').length;i++) {
			TempField=currentRow.getElementsByTagName('select').item(i).style.display = "none";			
		}
		for (i=0;i<currentRow.getElementsByTagName('input').length;i++) {
			TempField=currentRow.getElementsByTagName('input').item(i).style.display = "none";
			if (currentRow.getElementsByTagName('input').item(i).onkeyup != null){
				currentRow.getElementsByTagName('img').item(i).style.display = "none";
			}		
		}
		var filterselector = obj.value+vFiltNum;
		showfilter(filterselector);
	}
//==================================================================================================
//==   									ShowFilter()
//== Called from filtertoggle - Displays the selected field that was selected for that particular row
//==
//==================================================================================================
	function showfilter(vthing){
		var showfilterval = "FilterBy" + vthing;
		var vPony = document.getElementById(showfilterval);
		if (vPony.onkeyup != null){
			vPony.style.display = "inline";
			var vCal = showfilterval + '-look'
			document.getElementById(vCal).style.display = "inline";
		}
		else{
			vPony.style.display = "block";		
		}
	}
//==================================================================================================
//==   									copyRow()
//== Copies a row in filtertable and then appends the row number to each fields id to make it unique
//==
//==================================================================================================
	__uid = 2;
	function copyRow(){
		// - get the tbody of table id="LogTable"
		var tb = document.getElementById('filtertable').getElementsByTagName('tbody')[0]
		// - clone the first row of var tb
		var firstRow=tb.getElementsByTagName('tr')[0];
		var r = firstRow.cloneNode(true);
			tb.appendChild(r);
		// - set the id of the row
		var newRow='row'+__uid;
			tb.lastChild.id=newRow;
		//set the name of the FilterBy select box to indclude the row number
		var s=document.getElementById(newRow);
			//alert(s.innerHTML)
			//s.childNodes[0].firstChild.name='FilterByfld'+__uid;
			//s.childNodes[0].firstChild.id='FilterByfld'+__uid;
		//calculate number of fields of each type
		var HowManySelects =  s.getElementsByTagName('select').length;
		var HowManyInputs =  s.getElementsByTagName('input').length;
		//set the name and id of all select boxes and input fields in the cell
		for (i=0;i<HowManySelects;i++) {
			TempField=s.getElementsByTagName('select')[i];
			var oldString=TempField.name.length;
			var newString=TempField.name.substring(0, oldString-1);
			TempField.name=newString+__uid;
			TempField.id=newString+__uid;
		}
		for (i=0;i<HowManyInputs;i++) {
			TempInput=s.getElementsByTagName('input')[i];
			var oldString=TempInput.name.length;
			var newString=TempInput.name.substring(0, oldString-1);
			TempInput.name=newString+__uid;
			TempInput.id=newString+__uid;
		}
		//increase uid so that next row has correct number appended
		__uid++;
	}
//==================================================================================================
//==   									NumberValidate()
//== Checks to see if a field contains a number.
//==
//==================================================================================================
function NumberValidate(obj){
	if (obj.parentNode.lastChild.className=="fielderror"){
		obj.parentNode.lastChild.removeNode(true);
	}
	if (isNaN(obj.value)) {
	 	displayFieldError(obj.name, 'Must be an integer.');
		obj.focus();		
	} 
}
//==================================================================================================
//==   									isDate()
//== Checks to see if a field contains a properly formatted date.
//==
//==================================================================================================

function isDate(vDate)
{
clearFieldErrors();
var theThing=document.getElementById(vDate);

var strDate=theThing.value;
    if(strDate.length>0)
         {
            var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
             var match=strDate.match(dateregex);
             if (match) 
              {
                       var tmpdate=new Date(match[3],parseInt(match[1])-1,match[2]);
                  if (tmpdate.getDate()==parseInt(match[2], 10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10))
                   { 
                   return true; 
                   }
             }
	 		displayFieldError(theThing.name, 'MM/DD/YYYY');
			theThing.focus();
         return false;
         }
    else
         {
         return true;
         }
} 
//==================================================================================================
//==   									isDateTime()
//== Checks to see if a field contains a properly formatted date & Time.
//==
//==================================================================================================
   
function makeYear(str) {
  if (parseInt(str,10) < 1900) return 1900+parseInt(str,10)
  return str
}
function isDateTime(theForm) {
	clearFieldErrors();
  dateString = theForm.value;
  if (dateString == ''){
  return true
  }
  if (!dateString || 
       dateString.indexOf('/')==-1 || 
       dateString.indexOf(':')==-1) {
    displayFieldError(theForm.name, 'MM/DD/YYYY HH:MM');
    return false
  }

  date = new Date(dateString)
  testDate = dateString.split(' ')[0].split('/')
  testTime = dateString.split(' ')[1].split(':')
  mm = parseInt(testDate[0],10)
  dd = parseInt(testDate[1],10)
  yyyy=makeYear(parseInt(testDate[2],10))
  hh = parseInt(testTime[0],10)
  mins = parseInt(testTime[1],10)
  if (
  date.getMonth()   !=(mm-1) || 
  date.getDate()    !=dd ||
  date.getFullYear()!= yyyy||
  date.getHours()!= hh||
  date.getMinutes()!= mins
  ) { 
     displayFieldError(theForm.name, 'MM/DD/YYYY HH:MM');
     return false
  }
  return true
} 
//==================================================================================================
//==   									CheckLength()
//== Checks to see if a textarea has too many characters.
//==
//==================================================================================================
	  function CheckLength(length) {
		   if (window.event.srcElement.value.length >= length) {
				alert('The description must be less than 255 characters.');
				return false;                         
		   }
	  }
	  
//==================================================================================================
//==   									CleanUp()
//== When a user leaves a text area, checks to see if the user has pasted any funky word characters
//== like smart quotes in the field.  Primarily for description and note fields in Tracker.
//== Field=the id of the field to check
//== Label=the label of the field to be shown in the message
//==================================================================================================
  
function Cleanup(Field, Label)
        {
        var s2 = new String("");
		var pony='n';
		var str=document.getElementById(Field).value;
		clearFieldErrors();
        for (var i = 0; i < str.length; i++) {
           if (str.charCodeAt(i) > 127) {
             // do not include non-ascii character
			pony='y';
           } else {
          s2 = s2 + str.substring(i,i+1);

           }
           }
		   if (pony=='y'){
				var MSG = "Incompatible characters were detected in the text of the " +Label+" field.\n\n" +
						"This normally occurs when text containing smart (curly) quotes or other\n" +
						"special character is pasted into this field from word or excel.\n\n" +
						"Any incompatible characters will be REMOVED from the text.\n\n" +
						"Do you want to continue?\n\n" +						
						"Click OK to continue and REMOVE all special characters.\n" +
						"Click CANCEL to close this window and manually REPLACE the special characters yourself."
				if (confirm(MSG)){
		   			document.getElementById(Field).value=s2;
					}
				else {
					displayFieldError(Field, 'Incompatible characters');
					document.getElementById(Field).focus()
				}
			}
           return true;
        } 
//************************************************************************************************************
//***************************DATE/CALENDAR FUNCTIONS**********************************************************
//**** This is a block of functions that launch, build, and manipulate the
//**** calendar lookup and related date fields
//**** This file contains all functions for manipulating dates
//************************************************************************************************************
//************************************************************************************************************

//==================================================================================================
//== Define and Set Global variables
//==================================================================================================
var gByMonthFixedDay=0;
var gByMonthLatestDay=0;
var gCalSplitDate= new Array()		// used by PopupCalendar
var gCalFieldRef					// used by PopupCalendar

//==================================================================================================
//== displayCalendarOnKey
//==
//== Displays calendar when user hits F9 or Ctrl-up/down arrow
//==================================================================================================
function displayCalendarOnKey(pObject)
{
	var vShow = false;
	if (pObject.onblur){
	//alert(pObject.onblur.toString())
	var bp=pObject.onblur.toString()
	}
	switch (window.event.keyCode)
	{
		case 120:		// f9
			vShow=true;
			break;
		case 32:
		now = new Date();
		if (pObject.value == " "){
			if(bp && bp.indexOf("isDateTime") > -1){
				pObject.value=now.getMonth()+1 + '/' + now.getDate() + '/' + now.getYear() + ' ' + now.getHours() + ':' + now.getMinutes();	
			}
			else{
				pObject.value=now.getMonth()+1 + '/' + now.getDate() + '/' + now.getYear();	
			}
		}
		case 40:
			if (event.altKey) vShow=true;
			break;
	}
	if (vShow)
	{
		var lookupid=pObject.parentNode.lastChild;
		displayCalendar(lookupid);
	}
	window.event.returnValue=false;
}
//==================================================================================================
//== hideCalendar
//==	Hides calendar when user clicks anywhere on the page
//==================================================================================================
function hideCalendar()
{
	if(document.getElementById("iframeCalendar")){
	document.all("iframeCalendar").style.display="none";}
	SelectRedisplayer();
}
//==================================================================================================
//== displayCalendar
//==	displays calendar in iframe
//==	The object passed in is always the image object
//==================================================================================================
function displayCalendar(pObject,ralph)
{
	var vDivX=window.event.x
	var vDivY=window.event.y
	var vDivWidth = 140		// 7=borders
	var vDivHeight = 150	// 27=borders+buttons
	var vDivMargin = 0		// extra space for dropshadow and frame and buttons

	var vCalendar=document.all("iframeCalendar")

	//----------------------------------------------------------
	// store the parent element fieldid and value
	// into variables on the window so the calender
	// htc can handle setting of initial and selected values
	//----------------------------------------------------------
	var fieldid=pObject.previousSibling.previousSibling.name;
	gCalFieldRef=document.getElementById(fieldid);

	var vCurrentValue = document.all(fieldid).value
	if (vCurrentValue == "")
	{
		var vToday		= new Date()
		gCalSplitDate.year	= vToday.getFullYear();
		gCalSplitDate.month= vToday.getMonth() + 1;
		gCalSplitDate.day	= vToday.getDate();
	}
	else
	{
		//gCalSplitDate = splitYearMonthDay(vCurrentValue)
		//if (!isValidDate(gCalSplitDate)) return	// don't open window
	}
	//----------------------------------------------------------
	// Launch the popup
	//----------------------------------------------------------
	vCalendar.scrolling = "no";
	if(ralph && ralph!=''){
	vCalendar.src = "includes/calendar.cfm?&caller="+fieldid+"&cdate="+vCurrentValue+"&time="+ralph;
		}
	else{
	vCalendar.src = "includes/calendar.cfm?&caller="+fieldid+"&cdate="+vCurrentValue+"&time=no";
	}
	//----------------------------------------------------------
	// Position and Display the calendar
	//----------------------------------------------------------
	vCalendar.style.position = "absolute"
	vCalendar.style.display	= "block";
	vCalendar.style.width = vDivWidth;
	vCalendar.style.height = vDivHeight;
	vCalendar.style.border = "0px solid black";

	setElementPosition(vCalendar.id, fieldid, 0, 0 , 'left', 'bottom', 'left', 'down')
	
	vCalendar.focus();
	
	SelectHider('iframeCalendar');
}
//==================================================================================================
//==ReturnDate()
//==
//==  Returns the date passed from the calendar to the calling form
//==  
//==================================================================================================
function ReturnDate(iMonth, iDay, iYear, iField, iTime){
	if (iTime=='no'){
	document.getElementById(iField).value=iMonth + "/" + iDay + "/" + iYear;
	}
	else{
	clearFieldErrors();
	if (iTime=='time'){var iTime = '13:00'}
	document.getElementById(iField).value=iMonth + "/" + iDay + "/" + iYear + " "+iTime;
	}
	hideCalendar();	
	document.getElementById(iField).focus();
	document.getElementById(iField).blur();
}
//==================================================================================================
//== getElementPosition
//==
//==	retrieves an array of x,y coordinates for any element
//==	pElement is string id or a reference to the element object for which to locate
//==================================================================================================
function getElementPosition(pElement)
{
	var vSearch = 1; //SMR-  loop condition
	if(typeof(pElement) == "object")
	{
		var vObjToCheck = pElement;
	}
	else
	{
		var vObjToCheck = document.getElementById(pElement);
	}
	var vTagName = vObjToCheck.tagName;
	var vLeft = 0// x - coordinate
	var vTop = 0// y - coordinate
	//-------------------------------------------------------
	// Loop through parent elements looking calculating
	// total offset.
	//-------------------------------------------------------
	do
	{
		if (vTagName != "") //SMR- This should never happen
		{
			//-------------------------------------------------------
			//  body is the last item to check, stop after calculating it
			//-------------------------------------------------------
			if(vTagName.toLowerCase( ) != "body")
			{
				vLeft = vLeft + vObjToCheck.offsetLeft;
				vTop = vTop + vObjToCheck.offsetTop;
				if(vTagName.toLowerCase( ) == "table" && vObjToCheck.border != 0)
				{
					//-------------------------------------------------------
					// for some reason, tables loose 1px if they have a border defined
					//-------------------------------------------------------
					vLeft = vLeft + 1;
					vTop = vTop + 1;
				}

				vObjToCheck = vObjToCheck.offsetParent;  //SMR- next parent
				vTagName = vObjToCheck.tagName;			 //SMR- next parent's tag

			}
			else
			{
				vSearch = 0; //SMR- body tag has been processed, end loop
			}
		}
		else
		{
			vSearch = 0; //SMR- something is wrong, end loop and return 0,0 relative to client area
		}
	}
	while (vSearch == 1);

	//-------------------------------------------------------
	// return array of coordinates[x,y]
	//-------------------------------------------------------
	var rvCoordinates = new Array(vLeft,vTop);

	return rvCoordinates;
}

//==================================================================================================
//== setElementPosition
//==
//==	sets the position of an element relative to another
//==	pElementToMove is string id or reference to the element object to be moved
//==    pElementToMoveTo is string id or reference to the element object to move in relation to
//==
//==	phAlign is:		left (def),		center,			right
//==	pVAlign is:		top,			middle,			bottom (default)
//==	pHDraw  is:		left (def),		right
//==	pVDraw	is:		up,				down (default)
//==
//==	pHDraw is from the alignment point,
//==			left --draw the left edge of object and draw towards the right
//==			right--draw the right edge of the object and draw towards the left
//==	pVDraw is from the alignment point,
//==			up  --draw the botoom edige of the object and paint upwards
//==			down--draw the top edge of the object and paint downwards
//==================================================================================================
function setElementPosition(pElementToMove, pElementToMoveTo, pXPad, pYPad, pHAlign, pVAlign, pHDraw, pVDraw)
{
	var vXPad;
	var vYPad;
	var vPos = getElementPosition(pElementToMoveTo); //SMR - get position of destination
	if(typeof(pElementToMove) == "object")
	{
		var vSourceElement = pElementToMove;
	}
	else
	{
		var vSourceElement = document.getElementById(pElementToMove);
	}
	if(typeof(pElementToMoveTo) == "object")
	{
		var vTargetElement = pElementToMoveTo;
	}
	else
	{
		var vTargetElement = document.getElementById(pElementToMoveTo);
	}
	var vPosLeft = vPos[0];
	var vPosTop = vPos[1];
	var vTargetWidth = vTargetElement.offsetWidth;
	var vTargetHeight = vTargetElement.offsetHeight;
	var vSourceWidth = vSourceElement.offsetWidth;
	var vSourceHeight = vSourceElement.offsetHeight;
	var vPageBottom = document.body.scrollHeight;
	var vPageEdge = document.body.scrollWidth;
	var vScreenBottom = document.body.scrollTop + document.body.clientHeight;
	var vScreenEdge = document.body.scrollLeft + document.body.clientWidth;

	vXPad = (pXPad) ? pXPad : 0;
	vYPad = (pYPad) ? pYPad : 0;

	switch (pHAlign)
	{
		case "left" :
			break;
		case "center" :
			vPosLeft += vTargetWidth / 2;
			break;
		case "right" :
			vPosLeft += vTargetWidth;
			break;
		default :
			pHAlign = "left";
	}
	switch (pVAlign)
	{
		case "top" :
			break;
		case "middle" :
			vPosTop += vTargetHeight / 2;
			break;
		case "bottom" :
			vPosTop += vTargetHeight;
			break;
		default :
			pVAlign = "bottom";
			vPosTop += vTargetHeight;
	}
	switch (pHDraw)
	{
		case "left" :
			vPosLeft = vPosLeft + vXPad;
			break;
		case "right" :
			vPosLeft = vPosLeft - vSourceWidth - vXPad;
			break;
		default :
			pHDraw = "left";
			vPosLeft = vPosLeft + vXPad;
	}
	switch (pVDraw)
	{
		case "up" :
			vPosTop = vPosTop - vSourceHeight - vYPad;
			break;
		case "down" :
			vPosTop = vPosTop + vYPad;
			break;
		default :
			pVDraw = "down";
			vPosTop = vPosTop + vYPad;
	}
	//----------------------------------------------------------------
	// begin checks to see if source would render off screen,
	//	if so change orientation
	//----------------------------------------------------------------
	if (vPosTop + vSourceHeight > vScreenBottom) //off the bottom of screen
	{
		vPosTop = vPosTop - vSourceHeight;

		if (pVAlign == "bottom")
			vPosTop = vPosTop - vTargetHeight - (2 * vYPad);

		if (pVAlign == "top")
			vPosTop = vPosTop + vTargetHeight - (2 * vYPad);
	}
	//----------------------
	// off the top of screen
	//----------------------
	if (vPosTop < document.body.scrollTop)
	{
		vPosTop = vPosTop + vSourceHeight;

		if(pVAlign == "top")
			vPosTop = vPosTop + vTargetHeight + (2 * vYPad);

		if(pVAlign == "bottom")
			vPosTop = vPosTop - vTargetHeight + (2 * vYPad);
	}
	//----------------------
	// off the right of screen
	//----------------------
	if (vPosLeft + vSourceWidth > vScreenEdge)
	{
		vPosLeft = vPosLeft - vSourceWidth;
		if(pHAlign == "right")
			vPosLeft = vPosLeft - vTargetWidth - (2 * vXPad);

		if(pHAlign == "left")
			vPosLeft = vPosLeft + vTargetWidth - (2 * vXPad);
	}
	//----------------------
	// off the left of screen
	//----------------------
	if (vPosLeft < document.body.scrollLeft)
	{
		vPosLeft = vPosLeft + vSourceWidth;
		if(pHAlign == "left")
			vPosLeft = vPosLeft + vTargetWidth + (2 * vXPad);

		if(pHAlign == "right")
			vPosLeft = vPosLeft - vTargetWidth + (2 * vXPad);
	}


	//----------------------------------------------------------------
	// second set of checks to make sure the re-render isn't still off screen..
	//----------------------------------------------------------------
	if(vPosLeft <= document.body.scrollLeft)		// off left of screen
		vPosLeft = document.body.scrollLeft + 3;

	if(vPosLeft + vSourceWidth >= vScreenEdge)		// off right of screen
		vPosLeft = vScreenEdge - vSourceWidth - 3;

	if(vPosTop <= document.body.scrollTop)			// off top of screen
		vPosTop = document.body.scrollTop + 3;

	if(vPosTop + vSourceHeight >= vScreenBottom)	// off bottom of screen
		vPosTop = vScreenBottom - vSourceHeight - 3;

	vSourceElement.style.position = "absolute";
	vSourceElement.style.posLeft = vPosLeft; //SMR- set x
	vSourceElement.style.posTop = vPosTop; //SMR- set y
	return vPosLeft;
}
//==================================================================================================
//== SelectHider()
//== Hides any select boxes that are below a div or iframe so that they don't
//== display on top of it.  Pass through the id of the div or iframe
//==================================================================================================
function SelectHider(ElNameO){
	var veasy=document.getElementById(ElNameO);
	var roro=getElementPosition(veasy);
	var chTop=roro[1];
	var chLeft=roro[0];
	var vDivWidth=veasy.offsetWidth;
	var vDivHeight=veasy.offsetHeight;
	//--alert(chLeft + '--' + chTop + '--' + vDivWidth + '--' + vDivHeight);
	var chRight=chLeft + vDivWidth;
	var chBottom=chTop + vDivHeight;
    for (i=0;i<document.getElementsByTagName('select').length;i++) 
         {
		
         var tempobj=document.getElementsByTagName('select')[i];
			 if (tempobj.style.display!='none'){
			var bobo=getElementPosition(tempobj);
			var tp=bobo[1];
			var bm=tp + tempobj.offsetHeight;
			var lt=bobo[0];
			var rt=lt + tempobj.offsetWidth;
				if ((tp >= chTop && tp <= chBottom && lt >= chLeft && lt <= chRight) || (tp >= chTop && tp <= chBottom && rt >= chLeft && rt <= chRight) || (bm >= chTop && bm <= chBottom && rt >= chLeft && rt <= chRight) || (bm >= chTop && bm <= chBottom && lt >= chLeft && lt <= chRight)){
					//if(vSpanArray[i-1].id.substr(0,9) == "flderror_")
					var theClass=tempobj.className;
					tempobj.className="HideSelec_" + theClass;
					tempobj.style.display='none';
				}
			 }
		 }
	if (document.getElementsByTagName('object')[0]){
	document.getElementsByTagName('object')[0].style.display='none';
	}
	}
//----------------------------------------------------------
// If Select boxes were hidden when a div or iframe was displayed, 
// this sets them back to their previous state.
//----------------------------------------------------------
function SelectRedisplayer(){
    for (i=0;i<document.getElementsByTagName('select').length;i++) 
         {		
         var tempobj=document.getElementsByTagName('select')[i];
			 if (tempobj.style.display=='none' && tempobj.className.substr(0,10) == "HideSelec_"){
			 		var theClass=tempobj.className;
					var theLength=theClass.length;
					var newString=theClass.substring(10, theLength);
					tempobj.className=newString;
					tempobj.style.display='inline';
				}
			 }
	if (document.getElementsByTagName('object')[0]){
	document.getElementsByTagName('object')[0].style.display='inline';
	}
}
//==================================================================================================
//==deleteRecord()
//==
//==  Script that displays an alert and then redirects to the delete circuit
//==  if the user tries to delete a record
//==  variables: 
//==     RecName - value that will appear in the message popup.
//==     FuseAction - fuseaction for the delete function, usually an act_ file..
//==================================================================================================
function deleteRecord(RecName, FuseAction){
	var DeleteMSG = "This will permanently delete the " + RecName + " record from InterWeb.\n\n" +
					"Do you want to continue?"
		if (confirm(DeleteMSG)){
			var DeleteAction="index.cfm?fuseaction=" + FuseAction;
			document.forms[0].action=DeleteAction;
			document.forms[0].submit();
			}		
	}
//==================================================================================================
//==menuover/menuoff()
//==
//==  Script that changes the menus on mouseover and mouseout
//==================================================================================================
function menuover(obj){
obj.className='TNBoxSettd_sel';
obj.style.cursor = "hand"
}
function menuoff(obj){
	obj.className='TNBoxSettd';
}	

/********************* Dispatcher Object aids in sending events to the gui ********************************/
function Dispatcher() {
	
	var objects = new Array();
	this.objects = objects;
	
	function register(obj) {
		objects.push(obj);
	}
	
	function unregister(obj) {
		for(var i = 0; i < objects.length; i++) {
			if(objects[i] == obj) {
				objects.splice(i,1);
			}
		}
	}

	function mmdown(e) {
		for(var i = 0; i < objects.length; i++) {
			objects[i].mmdown(e);
		}
	}
	
	function mmup(e) {
		for(var i = 0; i < objects.length; i++) {
			objects[i].mmup(e);
		}
	}
	
	function mmove(e) {
		for(var i = 0; i < objects.length; i++) {
			objects[i].mmove(e);
		}
	}
	
	function checkBrowser(){
		this.ver=navigator.appVersion
		this.dom=document.getElementById?1:0
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
		this.ie4=(document.all && !this.dom)?1:0;
		this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
		this.ns4=(document.layers && !this.dom)?1:0;
		this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
		return this;
	}
	bw=new checkBrowser();
	
	if(bw.ns4)  document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
	
	document.onmousedown=mmdown;
	document.onmouseup=mmup;
	document.onmousemove=mmove;	
	
	this.register = register;
	this.unregister = unregister;
	this.mmdown = mmdown;
	this.mmup = mmup;
	this.mmove = mmove;
}

//these functions go with cfchart/jpg over ajax
function xx_set_visible(id, e, value){
	if (!xx_supported_client()) return ;
	xx_get_by_id(id).style.visibility= value ? "visible" : "hidden";
	if(value) xx_move_tag(id,e);
	xx_get_by_id(id).style.display=value ? "" : "none";
}

function xx_move_tag(id,e){
	if (!xx_supported_client()) return ;
	var popup = xx_get_by_id(id);
	if (popup.style.visibility!="visible") return ;

	var ns6=document.getElementById && !document.all
	var ie=document.all

	var iebody = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

    var dx = 10, dy = 10;
 	var posX=(ns6)?e.pageX : event.x+iebody.scrollLeft;
	var posY=(ns6)?e.pageY : event.y+iebody.scrollTop;

	var rightedge=ie&&!window.opera? iebody.clientWidth-event.clientX: window.innerWidth-e.clientX-20
	var bottomedge=ie&&!window.opera? iebody.clientHeight-event.clientY : window.innerHeight-e.clientY-20

	if (rightedge-dx<popup.offsetWidth)
		posX=ie? iebody.scrollLeft+event.clientX-popup.offsetWidth : window.pageXOffset+e.clientX-popup.offsetWidth;

	if (bottomedge-dy<popup.offsetHeight) {
		posY=ie? iebody.scrollTop+event.clientY-popup.offsetHeight : window.pageYOffset+e.clientY-popup.offsetHeight;
		dy =-dy;
    }

    popup.style.left=posX+dx+"px";
    popup.style.top=posY+dy+"px";

}

function xx_supported_client() { 	return (document.all) || (document.getElementById);}
function xx_get_by_id(id) { return document.all? document.all[id]: document.getElementById? document.getElementById(id) : "" }