var HelpPopup = window.createPopup();
var HelpPopupBody = HelpPopup.document.body;
	HelpPopupBody.onclick = clickHelpPopup;

with(HelpPopupBody.style)
{
	borderLeft = "#000000 1px groove";
	borderTop = "#000000 1px groove";
	borderRight = "#000000 1px groove";
	borderBottom = "#000000 1px groove";
	padding = 0;
	margin = 5;
	backgroundColor = "#fffff3";
	fontSize = "8pt";
	fontFamily = "Arial"
	fontWeight = "normal"
	color = "black";
}
	
function clickHelpPopup(){
	HelpPopup.hide();
}

function showHelp(txt)
{
	HelpPopupBody.innerHTML = txt;
	x = 0;
	y = 0;
	h = 80;
	w = 220;
	HelpPopup.show(x, y, w, h, event.srcElement);
}
	
	
function getDateObject(strDate)
{	//getDateObject will return NaN if strDate cannot be interpreted as a valid date
	if (strDate && strDate != '')
	{	if (strDate.length == 8 && strDate.length.replace(/[\D]/g,'')==8)
		{//assume it is in yyyymmdd format... transform it to dd/mm/yyyy
			strDate = strDate.substr(6,2) + '/' + strDate.substr(4,2) + '/' + strDate.substr(0,4)
		}
		strDate = strDate.replace(/[\.\s\,]/g,'\/');//use only accepted delimeters
	}
	
	return new Date(strDate);
}

//-Function to check format of military time from 0001 to 2400 hrs and works with validateTime() function
function formatTime()
{	var el = event.srcElement;
	if (el.value != '')
	{	if(!validateTime(el,true))
		{	alert("Invalid Time!");
			el.value = '';
			el.focus();
			return false;
		}	
	}
}

function validateTime(time, blnFormat)
{	/*	This function validates for valid military time.  The 'time' parameter
		can be a string or an HTML element.  If its an element and blnFormat is 
		set to true, it will be formated to military time.
		
		Valid military times are 0001 to 2400
	*/
	var strTime = '';
	var intTime = 0;
	var intMinutes = 0;
	var intHours = 0;
	
	if (time.tagName)
	{	if (time.value)
			strTime = time.value;
		else 
			strTime = time.innerText;
	}
	else
		strTime = time;
	
	strTime = strTime.replace(/^0*/,'');	//remove leading zeros
	if (strTime == '')
		return false;
	else
	{	if (/:/.test(strTime))
		//convert from standard to military time
		{	intHours = parseInt(strTime);
			intTime = parseInt(strTime.replace(/:/,''));
			if (/pm/i.test(strTime))
			{	if (intHours < 12)
					intTime += 1200;
			}
		}
		else
			intTime = parseInt(strTime);
	}
	if (!isNaN(intTime) && intTime > 0 && intTime <= 2400)
	{	//left pad with zeros
		strTime = "" + "000" + intTime;
		strTime = strTime.substr(strTime.length-4, 4);
		//check that minutes are less than 60
		intMinutes = parseInt(strTime.substr(strTime.length-2, 2));
		if (intMinutes >= 60)
		{	if (blnFormat)
			{	intTime = intTime - 60 + 100;
				//re left-pad with zeros
				strTime = "" + "000" + intTime;
				strTime = strTime.substr(strTime.length-4, 4);
			}
			else
				return false;
		}
		
		if (intTime > 0 && intTime <= 2400)
		{	
			if (blnFormat && time.tagName && time.value)
				time.value = strTime;
			else
				time.innerText = strTime;
			return true;
		}
		else
			return false;
	}
	else
		return false;
}

function validateDateFields(elYear, elMonth, elDay)
{	var msg = '';
	if (elMonth.value != '' && elDay.value != '' && elYear.value != '')
	{  	if (elMonth.value < 1 ||elMonth.value > 12 )
	  	{	msg += "\nInvalid Month!";
	  		elMonth.focus();
		}
	  	if (elDay.value < 1 ||elDay.value > 31 )
	  	{	msg += "\nInvalid Day!";
	  		elDay.focus();
		}
	  	if (elYear.value == '' || elYear.value.length == 3 || elYear.value.length == 3)	
	  	{	msg += "\nInvalid Year!";
	  		elYear.focus();
		}
	}
	else if (elMonth.value != '' || elDay.value != '' || elYear.value != '')
	{	msg += "\nIncomplete Date!"
	  	if (elMonth.value == '')
	  		elMonth.focus();
		else if (elDay.value == '')
	  		elDay.focus();
		else 
	  		elYear.focus();
	}
	return msg;
}

function CheckTodayDate(el)
{	var d;
	var today_txt;
	if (typeof(el) != 'undefined')
	{	d = new Date();
		today_txt = formatDate(d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate());
		if(DateDifference(el.value, today_txt) < 0)
		{	alert("This Date Cannot Be Greater Than Today's Date!");
			el.value = '';
			el.focus();
			return false;
		}
	}
}

function removeOption(objSelect, strOptionValue)
{	var blnOptionFound = false, j = 0;
	while (j < objSelect.options.length && !blnOptionFound)
	{	if (objSelect.options[j].value == strOptionValue)
		{	blnOptionFound = true;
		}
		j++;
	}
	//move all the options up one, overwriting the option specified by strOptionValue
	if (j > 0)
	{	for (; j < objSelect.options.length; j++)
		{	objSelect.options[j-1].text = objSelect.options[j].text;
			objSelect.options[j-1].value = objSelect.options[j].value;
			objSelect.options[j-1].selected = objSelect.options[j].selected;
			objSelect.options[j-1].defaultSelected = objSelect.options[j].defaultSelected;
		}
	}	
	objSelect.options.length--;//remove the last option
}

function getChecked(el)
{	//returns only the first checked item
	if (el)
	{
		if (el.length >= 0)
		{
			for (i=0; i < el.length; i++)
			{	if (el[i].checked)
				{	return el[i];
					break
				}
			}
		}
		else
		{
			return el;
		}
	}
	else
	{	return null;
	}
}

function resetSelected(el)
{	if (el && el.options)
	{	for (i=0; i < el.options.length; i++)
		{	el.options[i].Selected = el.options[i].defaultSelected;
		}
	}
}

function resetDefaultValues(el)
/*This function will set the defaultValue or defaultChecked attribute 
**of any input, textarea or select tag found in the all collection of 
**the passed in element to the current value.  
**This will mark the elements as "saved".
**That is the checkForUnsavedChanges() function will return an
**empty string.

**NOTE: The defaultValues of buttons and images are ignored as well as
**inputs of type hidden and file.
*/
{	if (el)
		var objInputs = el.all.tags("input");
	else
		var objInputs = document.all.tags("input");
		
	if (objInputs && objInputs.length)
	{	for (i=0; i<objInputs.length; i++)
		{	switch(objInputs[i].type)
			{	case 'radio':
				case 'checkbox':
					objInputs[i].defaultChecked = objInputs[i].checked;
					break;
				case 'text':
				case 'password':
					objInputs[i].defaultValue = objInputs[i].value;
					break;
			}
		}
	}//end inputs
	i = 0;
	if (el)
		var objSelects = el.all.tags("select");
	else
		var objSelects = document.all.tags("select");
		
	if (objSelects && objSelects.length)
	{	for (i=0; i<objSelects.length; i++)
		{	for (j=0; j < objSelects[i].options.length; j++)
			{	objSelects[i].options[j].defaultSelected = objSelects[i].options[j].selected;
			}
		}
	}//end selects
	i = 0;
	if (el)
		var objtextareas = el.all.tags("textarea");
	else
		var objtextareas = document.all.tags("textarea");
	if (objtextareas && objtextareas.length)
	{	for (i=0; i<objtextareas.length; i++)
		{	objtextareas[i].defaultValue = objtextareas[i].value;
		}
	}
}
function disable(e) {
	e.disabled = 'true';
}


function enable(e) {
	e.disabled = '';
}

function checkForUnsavedChanges()
{
/*This function will check for changes in any input or
**select tag.  
**The defaultValue attribute is used to determine the original
**state for input tags, excluding radio and checkboxes.
**defaultChecked is used for radio and checkboxes and
**defaultSelected is used on the select box options.
**NOTE: The values of buttons and images are ignored as well as
**inputs of type hidden and file.
** inputs.
*/
	var blnChangesMade = false, i = 0, j= 0;
	var objInputs = document.all.tags("input");
	if (objInputs && objInputs.length)
	{	while (i<objInputs.length && !blnChangesMade)
		{	switch(objInputs[i].type)
			{	case 'radio':
				case 'checkbox':
					if (objInputs[i].defaultChecked != objInputs[i].checked)
						blnChangesMade = true;
					break;
				case 'text':
				case 'password':
					if (objInputs[i].defaultValue != objInputs[i].value)
						blnChangesMade = true;
					break;
			}
			i++;
		}
	}//end inputs
	i = 0;
	var objSelects = document.all.tags("select");
	if (!blnChangesMade && objSelects && objSelects.length)
	{	while (i<objSelects.length && !blnChangesMade)
		{	j = 0;
			while (j < objSelects[i].options.length && !blnChangesMade)
			{	if (objSelects[i].options[j].selected != objSelects[i].options[j].defaultSelected)
				{	blnChangesMade = true;
				}
				j++;
			}
			i++;
		}
	}//end selects
	i = 0;
	var objtextareas = document.all.tags("textarea");
	if (!blnChangesMade && objtextareas && objtextareas.length)
	{	while (i<objtextareas.length && !blnChangesMade)
		{	if (objtextareas[i].defaultValue != objtextareas[i].value)
				blnChangesMade = true;
			i++;
		}
	}
	
	if (blnChangesMade)
		return "There are unsaved changes.";
}

// The Toggle Function Requires that you use plus.gif and minus.gif 
// and name the image 'expand & (element)'

function toggle(section) {
    if (eval('document.all.'+ section +'.style.display==""')) {
	eval('document.all.'+ section +'.style.display="none"');
	eval('document.expand'+ section +'.src=plus.src');
	}
	else	
	{
	eval('document.all.'+ section +'.style.display=""');
	eval('document.expand'+ section +'.src=minus.src');
	}
}

function hideDisplaySections(strCheckElement, strSectionName) 
{	var objCheckElements = document.all.item(strCheckElement);
	var objSections = document.all.item(strSectionName);
	if (objCheckElements && objCheckElements.length > 0)
		for (i=0; i < objCheckElements.length; i++)
		{	if (objCheckElements[i].getAttribute("checked"))
			{	if (objSections[i])
					objSections[i].style.display = '';
			}
			else
			{	if (objSections[i])
					objSections[i].style.display = 'none';
			}
		}
}

function ReplaceQuotes(checkString)
{
newString = ""; 
count = 0; 

for (i = 0; i < checkString.length; i++) {
	ch = checkString.substring(i, i+1);
	if (ch != "'") {
	newString += ch;
	}
	if (ch == "'" ) {
	newString += "''";
	}
}

return newString;
}


//***** Tab Control *************************

function TabClick( nTab )
{	nTab = parseInt(nTab);
	var oTab;
	if (tabContent.length)
	{
	for (var i = 0; i < tabContent.length; i++)
	{		
		oTab = tabs[i];
		
		if (i == 0)
		{
			oTab.className = "clsTabFirst";
		}
		else
		{
			oTab.className = "clsTab";
		}
		tabContent[i].style.display = "none";
	}
	
	tabContent[nTab].style.display = "block";
	tabs[nTab].className = "clsTabSelected";
	TabDisable()
	}
	//event.returnValue = false;
}

function TabNext()
{	var oTab;
	for (var i = 0; i < tabContent.length; i++)
	{		
		oTab = tabs[i];
		if (oTab.className == "clsTabSelected")
		{
			var n = i + 1;
			TabClick(n);
			break;
		}
	}	
	//event.returnValue = false;
}

function TabBack()
{	var oTab;
	for (var i = 0; i < tabContent.length; i++)
	{	oTab = tabs[i];
		if (oTab.className == "clsTabSelected")
		{	var n = i - 1;
			TabClick(n);
			break;
		}
	}
	
	//event.returnValue = false;
}

function TabDisable()
{	var oTab;
	if (document.all.btnBack && document.all.btnNext)
	{
		//event.cancelBubble = true;
		for (var i = 0; i < tabContent.length; i++)
		{	oTab = tabs[i];
			if (oTab.className == "clsTabSelected")
			{	if (!tabs[i - 1])
				{	document.all.btnBack.disabled = true;
				}
				else
				{	document.all.btnBack.disabled = false;
				}
				
				if (!tabs[i + 1])
				{	document.all.btnNext.disabled = true;
				}
				else
				{	document.all.btnNext.disabled = false;
				}
				break;
			}
		}
	}
	//event.returnValue = false;
}

function Expandtextarea(txt)	
{
	var modalResult
	modalResult = window.showModalDialog("Text-Editor.asp",txt, "dialogHeight: '410px'; dialogWidth: '650px'; center: Yes; help: No; resizable: No; status: No;")
}

	
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments<FONT color=#0000cc>

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getRbValue(rb)
{
var rbValue = '';

	for (i = 0; i < rb.length; i++)
	{
		if (rb[i].checked == true)
		{
			rbValue = rb[i].value;
			break;
		}
	}
	return rbValue;
}


function NumbersOnly()
{	//this is typically assigned to an input's onkeypress
	if (window.event.keyCode > 57 | window.event.keyCode < 48)
	{	window.event.returnValue=false
	}
}

function NumbersOnlyDecimal()
{
	if  (window.event.keyCode > 57 ) 
   {
       window.event.returnValue=false
   }

   if  (window.event.keyCode < 48 ) 
   {
       if  (window.event.keyCode != 45 && window.event.keyCode != 46 ) 
       {
			window.event.returnValue=false
		}
   }
}

function selectFirst()
{
   if (event.srcElement.value == "" || event.srcElement.value == "0")
   {	event.srcElement.selectedIndex = 0;
   }
}

function openModalWindow(page, options)
{
	if (!options || options == "")
		options = "dialogHeight: '" + eval(screen.height - 30) + "px'; dialogWidth: '" + 
			screen.width + "px'; center: Yes; help: No; resizable: No; status: No;";
	else
	{	if (options.search(/dialogWidth/) == -1)
			options += ";dialogWidth: '" + screen.width + "px'";
		if (options.search(/dialogHeight/) == -1)
			options += ";dialogHeight: '" + eval(screen.height - 30) + "px'";
		if ((options.search(/center/) == -1) 
		  && (options.search(/dialogTop/) == -1) 
		  && (options.search(/dialogLeft/) == -1))
			options += ";center: Yes";
		if (options.search(/help:/) == -1)
			options += ";help: No";
		if (options.search(/resizable:/) == -1)
			options += ";resizable: No";
		if (options.search(/status:/) == -1)
			options += ";status: No";						
		options = options.replace(/^;/, "")
	}
	return window.showModalDialog("Modal-Window.asp",	page, options);
}

function retrieveLocalDateTime()
{	var localDate		=   getDate();
	var strTime			=	new Date();
	var localTimeTxt	=	'';
	var localHour		=	strTime.getHours();
	var localMinutes	=	strTime.getMinutes();
	
	//-Padds hours with leading zeros
	if (localHour<10) 
	{	localHour		=	'0'+localHour; 
	}
	//-Padds minutes with leading zeros
	if (localMinutes<10) 
	{	localMinutes	=	'0'+localMinutes; 
	}

	localTimeTxt		=	localHour + ':' + localMinutes;

	var datetimeStr		=	localDate + ' ' + localTimeTxt;
	return datetimeStr;
}

function getTime()
{
	var dt = new Date();
	var m = '0' + dt.getMinutes();
	var h = '0' + dt.getHours();
	return h.substr(h.length - 2, 2) + '' + m.substr(m.length - 2, 2);	
}

function setTime()
{
	var c = event.srcElement.parentElement.children;
	for (var ci = 0; ci < c.length; ci++)
	{	if (c[ci].tagName == 'INPUT')
		{	c[ci].value = getTime();
			c[ci].fireEvent('onchange');
			return;
		}			
	}
}

function selectRadioButton(e,v)
{	if (v.length != 0)
	{
		var i, rb = eval("document.forms[0]." + e);
		for (i=0; i < rb.length; i++)
		{	if (rb[i].value == v)
				rb[i].checked = true
			else
				rb[i].checked = false;
		}
	}
}

function checkAll(e)
{
	for (var i = 0; i < e.length; i++)
	{	e[i].checked = 'true';
	}
}

function uncheckAll(e)
{
	for (var i = 0; i < e.length; i++)
		e[i].checked = '';
}

function checkRequiredFieldsAreFilled(el)
{	if (el)
		var objLabels = el.all.tags("LABEL");
	else
		var objLabels = document.all.tags("LABEL");
		
	var strRequiredElementList = '';
	var objElementToGoTo = '';
	var intMissingCount = 0;
	
	for (i=0; i<objLabels.length; i++)
	{	if (objLabels[i].className == "required")
		{	if (objLabels[i].attributes['for'].nodeValue != '')
			{	var oForEl = document.all(objLabels[i].attributes['for'].nodeValue);
				if (oForEl && oForEl.style && oForEl.style.display != 'none'
				 && oForEl.style.visibility != 'hidden'
				 && !oForEl.disabled)
				{	if (oForEl.value == '')
					{	if (intMissingCount == 0)
						{	objElementToGoTo = oForEl.name;
						}
						else
						{	strRequiredElementList += ', ';
						}
						strRequiredElementList += objLabels[i].innerText.replace(/\s*$/,'');
						intMissingCount += 1;
					}
				}
			}
		}
	}
	if (intMissingCount == 1)
	{	alert(strRequiredElementList + " is a required field.");
	}
	else if (intMissingCount > 1)
	{	alert(strRequiredElementList + " are required fields.");
	}
	if (intMissingCount > 0)
	{	try
		{	document.all(objElementToGoTo).focus();
		}
		catch(e)
		{ return false;
		}
		return false;
	}
	else
	{	return true;
	}
									
}
//This function was created for the victim and subject tabs 
// it populates the organization id and uic txt fields with the selected value
function doPopulateTxtFields()
{
	var el = event.srcElement.id
	sel=document.all.uic_lookup_cd;
	selo=document.all.organization_id;
	//alert(el);
	//alert(sel.selectedIndex);
if(el=='uic_lookup_cd')
	{if(sel.selectedIndex >0)
		{//alert(sel.selectedIndex);
			document.all.organization_id.selectedIndex = sel.selectedIndex;
			document.all.uic_txt.value = sel.options[sel.selectedIndex].text;
			//document.all.uic_id.value=sel.option[sel.selectedIndex].getAttribute("uic_id");
		}
	}
else
	{
	if(selo.selectedIndex >0)
		{//alert(selo.selectedIndex);
			document.all.uic_lookup_cd.selectedIndex = selo.selectedIndex;
			document.all.uic_txt.value = sel.options[sel.selectedIndex].text;			
			
		}
	}
}
function shake(n) 
//shakes the window
{	if (parent.moveBy) 
	{	for (i = 10; i > 0; i--) 
		{	for (j = n; j > 0; j--) 
			{	parent.moveBy(0,i);
				parent.moveBy(i,0);
				parent.moveBy(0,-i);
				parent.moveBy(-i,0);
			}
		}
	}
}
function trim(str)
{	if (str && str != '')
		return str.replace(/^\s*(.*?)\s*$/, "$1");
	else
		return str;
}

function disableKeyEntry()
{
	event.returnValue ="";
}

function doKeypress2()
{
	event.returnValue ="";
}

function doKeypressNoQuotes()
{
	if(event.keyCode== 39 || event.keyCode==34)
	{
		event.returnValue ="";
	}
}

function noDoubleQuotes()
{
	if(event.keyCode==34)
	{
		event.returnValue ="";
	}
}

function hideSelectLists(oContainingElement)
{	/*	This function will hide all the select boxes in oContainingElement.
		If oContainingElement is undefined, then document will be used.
		
		This is useful when you what to cover a select box with an absolutely
		positioned element (SELECT boxes can't be covered... no "Windowed" elements can.
		
		If in oContainingElement an input box with the same name as the select but with
		hdn (for hidden) prepended, then then it will be set to the text of the select box
		and made visible.  In essence it will take the select boxes place momentarily
		so as to minimize the negative visual effect of making the select box invisible.
		
		This function work inconjunction with the showSelectLists... when the absolutely
		position element is removed, or put behind oContainingElement, showSelectLists makes
		the select boxes reappear and the corresponding text boxes disappear.
	*/
	if (!oContainingElement)
		oContainingElement = document;
	var oSelects = oContainingElement.all.tags("SELECT");
	
	for (var i=0; i < oSelects.length; i++)
	{	/*********Instead of hard coding the hidden text boxes they are dynamicaly generated.
		if (oContainingElement.all.item('hdn'+oSelects[i].name)
		 && oContainingElement.all.item('hdn'+oSelects[i].name).tagName == 'INPUT')
		{
		*********/
			var iSelectWidth = oSelects[i].offsetWidth;
			oSelects[i].style.display = 'none';
			
			var oHTML = "<input type='text' name='_hdn"+oSelects[i].name+"'>"
			oSelects[i].insertAdjacentHTML("beforeBegin", oHTML)
			
			//oContainingElement.all.item('_hdn'+oSelects[i].name).style.display = '';
			
			oContainingElement.all.item('_hdn'+oSelects[i].name).style.width = iSelectWidth + 'px';
			if (oSelects[i].selectedIndex >= 0)
				oContainingElement.all.item('_hdn'+oSelects[i].name).value = oSelects[i].options[oSelects[i].selectedIndex].text;
			else
				oContainingElement.all.item('_hdn'+oSelects[i].name).value = '';
		
		/*********
		}
		else
			oSelects[i].style.visibility = 'hidden';
		*********/
	}
}

function showSelectLists(oContainingElement)
{	//See hideSelectLists(oContainingElement)
	if (!oContainingElement)
		oContainingElement = document;
	var oSelects = oContainingElement.all.tags("SELECT");
	
	for (var i=0; i < oSelects.length; i++)
	{	if (oContainingElement.all.item('_hdn'+oSelects[i].name) && oContainingElement.all.item('_hdn'+oSelects[i].name).tagName == 'INPUT')
		{	//oContainingElement.all.item('_hdn'+oSelects[i].name).style.display = 'none';
			oContainingElement.all.item('_hdn'+oSelects[i].name).removeNode(true);
			oSelects[i].style.display = '';			
		}
		else
			oSelects[i].style.visibility = 'visible';
	}
}

function getDate()
{
	var dt = new Date();
	var m, d;
	m = '0' + (dt.getMonth() + 1);
	d = '0' + dt.getDate();
	
	return  dt.getFullYear() + '/' +  m.substr(m.length - 2, 2) + '/' + d.substr(d.length - 2, 2) ;
}

function parseDate()
{
	var dt = new Date();
	var m, d;
		
	m = '0' + (dt.getMonth() + 1);
	d = '0' + dt.getDate();
		
	//frmStatement.mpr_statement_admin_date_txt.value = d;
	return  dt.getFullYear() + '/' +  m.substr(m.length - 2, 2) + '/' + d.substr(d.length - 2, 2) ;
}
	
//textarea validation
function chkLen(s,inLen,errString)
{
    var len=s.length
    if(len>=inLen)
    {
       // alert("The "+errString+" field is too long!\nThe max size is "+inLen+" and you have "+len+".\nPlease shorten this field.");
        return false;
    }
    else
        return true;
}

function selectCountry()
{
	var el = event.srcElement;
	var selCountry = el.getAttribute("selCountry");
	if (el.selectedIndex<1)
		el.selectedIndex = 0;
		
	var country_id = el[el.selectedIndex].getAttribute("country_id");
	
	if (selCountry&&country_id)
	{
		eval('document.all.'+selCountry+'.value='+country_id);
	}		
	else if (selCountry)
	{
		eval('document.all.'+selCountry+'.selectedIndex=0');
	}
}

function moveOptionUp()
{
	var obj = document.all.selOrder;
	for(i=0;i<obj.length;i++)
	{
		if((obj[i].selected) && (i>0))
		{
			obj[i].swapNode(obj[i-1]);
			break;
		}	
	}
}

function moveOptionDown()
{
	var obj = document.all.selOrder;
	for(i=0;i<obj.length;i++)
	{
		if((obj[i].selected)&&(i<obj.length-1))
		{
			obj[i].swapNode(obj[i+1]);
			break;
		}	
	}
}

function pasteNumbersOnly()
{	var Val = window.clipboardData.getData("Text");
	if (isNaN(Val))
		return false;
}

function pasteMaxLength(inLen)
{
	var existing_txt = event.srcElement.value;
	var pasted_txt = window.clipboardData.getData("Text");
	 
	if (existing_txt.length + pasted_txt.length>inLen)
	{
		alert('The text pasted is too long!');
		return false;		
	}
}

function findParentElement(oElement, sParentTagName)
{	/*	Look up the element hierarchy for a element with a tagName of sParentTagName.
		If sParentTagName is undefined or an empty string simply return the parent.
		Return undefined if a match tag is not found or if oElement is undefined.
	*/
	if (oElement && oElement.parentElement && sParentTagName && sParentTagName != '')
	{	sParentTagName = sParentTagName.toUpperCase();
		var oParent = oElement.parentElement;
		while (oParent.tagName != sParentTagName && oParent.parentElement)
		{	oParent = oParent.parentElement;
		}
		if (oParent.tagName == sParentTagName)
			return oParent;
		else
			return;
	}
	else if (oElement)
		return oElement.parentElement;
	else
		return;
}

function populateUnitInfo()
{
	if (document.all.uic_organization_id.selectedIndex > 0)
	{
		with (document.all)
		{	
			if (typeof(unit_address_txt) != 'undefined')	
				unit_address_txt.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('address_txt');
			
			if (typeof(unit_city_txt) != 'undefined')	
				unit_city_txt.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('city_txt');
			
			if (typeof(unit_state_id) != 'undefined')	
				unit_state_id.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('state_id');
			
			if (typeof(unit_country_id) != 'undefined')		
				unit_country_id.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('country_id');
			
			if (typeof(unit_zipcode_txt) != 'undefined')	
				unit_zipcode_txt.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('zip_txt');
			
			if (typeof(unit_phone_txt) != 'undefined')	
				unit_phone_txt.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('phone_txt');
			
			if (typeof(unit_phone_ext_txt) != 'undefined')	
				unit_phone_ext_txt.value = uic_organization_id[uic_organization_id.selectedIndex].getAttribute('phone_ext_txt');

		}
	}
	else
	{
		with (document.all)
		{		
			if (typeof(unit_address_txt) != 'undefined')
				unit_address_txt.value = unit_address_txt.defaultValue;
			
			if (typeof(unit_city_txt) != 'undefined')	
				unit_city_txt.value = unit_city_txt.defaultValue;
				
			if (typeof(unit_state_id) != 'undefined')
				unit_state_id.value = unit_state_id.defaultValue;
				
			if (typeof(unit_country_id) != 'undefined')
				unit_country_id.value = unit_country_id.defaultValue;
				
			if (typeof(unit_zipcode_txt) != 'undefined')
				unit_zipcode_txt.value = unit_zipcode_txt.defaultValue;
				
			if (typeof(unit_phone_txt) != 'undefined')
				unit_phone_txt.value = unit_phone_txt.defaultValue;
				
			if (typeof(unit_phone_ext_txt) != 'undefined')
				unit_phone_ext_txt.value = unit_phone_ext_txt.defaultValue;
		}	
	}
}
function deleteUIC()	
{	if(document.all.uic_id.value != '' )
	{
		if(confirm('Do you want to delete UIC/Organization ? '))
		{	document.all.uic_id.value = '' ;
			document.all.UIC_Organization_txt.value = '' ;		
		}
	}
	
}



function getRadioValue(oRadio)
{	if (typeof(oRadio)!='undefined')
	{	for (i=0;i<oRadio.length;i++)
		{	if (oRadio[i].checked)
				return oRadio[i].value;
		}
	}
}

function emailCheck (emailStr) {
if (emailStr == '')
	return true;
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
   
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address is incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The Email address username is not valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Email Address Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The Email Address domain name is not valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The Email Address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This Email Address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function toggleListing()
{	obj = event.srcElement;
	for(i=0;i<document.all.ifrListing.length;i++)
	{	if(i==obj.value)
			document.all.ifrListing[i].style.display='block';
		else
			document.all.ifrListing[i].style.display='none';	
	}
}

//-Key press validation to check for unsafe input characters
function keypressValidation()
{	if (window.event.keyCode == 34 || window.event.keyCode == 94 || window.event.keyCode == 37 || window.event.keyCode == 42 || window.event.keyCode == 38)
	{	window.event.returnValue=false
	}
}
function keypressValidation2()
{	if (window.event.keyCode == 34 || window.event.keyCode == 94 || window.event.keyCode == 37 || window.event.keyCode == 42 || window.event.keyCode == 38 || window.event.keyCode == 35 || window.event.keyCode == 39)
	{	window.event.returnValue=false
	}
}
//-Paste validation to check for unsafe input characters
function pasteValidation()
{	var pastedString = new String(window.clipboardData.getData("Text"));
	for(i=0;i<=pastedString.length;i++)
	{	if(pastedString.charCodeAt(i) == 34)
		{	window.event.returnValue = false;
		}
		else if(pastedString.charCodeAt(i) == 94)
		{	window.event.returnValue = false;
		}
		else if(pastedString.charCodeAt(i) == 37)
		{	window.event.returnValue = false;
		}
		else if(pastedString.charCodeAt(i) == 42)
		{	window.event.returnValue = false;
		}
		else if(pastedString.charCodeAt(i) == 38)
		{	window.event.returnValue = false;
		}
	}
}

function formatNumber(LenPrecision)		
{	var decimalPart,lenDecimal;	
	var el = event.srcElement;
	parm = el.value;
	arrParm = parm.split('.');
	parm = arrParm[0];
	decimalPart = arrParm[1];

	if (LenPrecision == 0)
	{	decimalPart = '';
	}
	else
	{	if (arrParm.length > 1)
		{	lenDecimal = decimalPart.length;			
		} 
		else
		{	lenDecimal = 0;
			decimalPart = '';
		}	
		
		for (i=0; i< (LenPrecision - lenDecimal); i++)
		{	decimalPart = decimalPart + '0';			
		}
		decimalPart = '.' + decimalPart;
	}	
	
	//takes out all the commas so it is numeric
	parm = parm.replace(/,/g,"")       

	//if number is between 0 and 1000 return
	if (parm < 1000 && parm >= 0)
		el.value = parm + decimalPart;
		
	//comma format the number
	if (parm.length > 9)
		el.value = parm.substr(0,parm.length - 9) + ',' + parm.substr(parm.length - 9,3) + ',' + parm.substr(parm.length - 6,3) + ',' + parm.substr(parm.length - 3,3) + decimalPart
	else if (parm.length > 6)
		el.value = parm.substr(0,parm.length - 6) + ',' + parm.substr(parm.length - 6,3) + ',' + parm.substr(parm.length - 3,3) + decimalPart
	else if (parm.length > 3)
		el.value = parm.substr(0,parm.length - 3) + ',' + parm.substr(parm.length - 3,3) + decimalPart
}

function nullToZero(parm)
{	if(parm.replace(/ /g,'')=='')
		return 0;
	else
		return parm;
}

function NumbersOnlyDecimal()
{	if(window.event.keyCode > 57) 
	{	window.event.returnValue=false
	}
	if  (window.event.keyCode < 48) 
	{	if(window.event.keyCode != 45 && window.event.keyCode != 46) 
	    {	window.event.returnValue=false;
		}
	}
}

function replaceQuotes(parm)
{	return parm.replace(/\'/g,"''")
}

//used for editable elements captures enter key and puts in <br> instead of <p>
function handleEnterKey()
{	if (event.keyCode == 13) 
	{	var sel = window.document.selection;
		if (sel.type == "Control") return; 
		var r = sel.createRange(); 
		r.pasteHTML("<BR>");
		event.cancelBubble = true; 
		event.returnValue = false; 
		r.select();
		r.moveEnd("character", 1); 
		r.moveStart("character", 1);
		r.collapse(false);
		return false;
	}
}

hexColor = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
function mOver(byVal) 
{
	var wBut = 'doc.' + byVal + '.style.cursor="hand";doc.' + byVal + '.style.background =';
	for (i = 0; i < 13; i++) 
	{
		setTimeout(wBut + ' "#'+hexColor[12-i]+'0'+hexColor[12-i]+'0c0";', i * 40);
   	}
}
function mOut(byVal) 
{
	var wBut = 'doc.' + byVal + '.style.background =';
	for (i = 0; i < 12; i++) 
	{
		setTimeout(wBut + ' "#'+hexColor[i]+'0'+hexColor[i]+'0c0";', i * 40);
   	}
}
function blinkIt(byVal) 
{
 	if (!document.all) 
	{
		return;
	}
 	else 
	{
   		for(i=0;i<document.all.tags('blink').length;i++)
		{
      			s=document.all.tags('blink')[i];
      			s.style.color="#FF0000";
      			s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   		}
 	}
}
function Mail(box) 
{
   	domain="aviatorman.com";
   	document.write("<a href='mailto:"+box+"@"+domain+"'>"+box+"@"+domain+"</a>");
} 
function loadFooter()
{
	domain="aviatorman.com";
        box="Woodie";
	document.write("<b><u>CONTACT</u></b><br><a href='mailto:"+box+"@"+domain+"'>"+box+"@"+domain+"</a><br>");
}

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else 
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function centerPic(containingEl, containedEl, wdE1, hdE1)
{	
	var wE1 = screen.availWidth;
	var hE1 = screen.availHeight;

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	containedEl.style.pixelLeft = (wE1/3) - (wdE1/2);
	containedEl.style.pixelTop = posy + (hdE1/4);
}

function centerElement(containingEl, containedEl)
{	containedEl.style.pixelLeft = containingEl.scrollLeft-0 + (containingEl.offsetWidth/2) - (containedEl.offsetWidth/2);
	containedEl.style.pixelTop = containingEl.scrollTop-0 + (containingEl.offsetHeight/2) - (containedEl.offsetHeight/2);	
}
