var regInt   = /^\d*$/;
var regFloat = /^\d*(\.\d*)?$/;
var regFloat5 = /^\d*(\.5)?$/;
var regZip   = /^(\d{5}(\-?\d{4})?)?$/;
//var regPhone = /^(\(?\d{3}\)?[\-\.]?\d{3}[\-\.]?\d{4})?$/;
var regPhone = /^(\(?\d{3}\)?\s*[\-\.]?\s*\d{3}\s*[\-\.]?\s*\d{4})?$/;
var regFax = /^(\(?\d{3}\)?[\-\.]?\d{3}[\-\.]?\d{4})?$/;
var regEmail = /^((\w|\-)+(\.(\w|\-)+)*\@(\w|\-)+(\.(\w|\-)+)+)?$/;
var regSSN = /^(\d{3}[\-\.]?\d{2}[\-\.]?\d{4})?$/;

var BodyLoadCallBack = 0;

var FocusControl = null;
var FocusControl2 = null;

var iTimeOut = null;

function FooterReloc()
{
	var FooterDiv = null;
	var LeftNavBarDiv = null;
	var TopNavBarDiv = null;
	var FooterTop;
	

	if (document.getElementById)
	{
		//IE 6 and Netscape 6 Code
		FooterDiv = document.getElementById("FooterDiv");	
		LeftNavBarDiv = document.getElementById("LeftNavBarDiv");	
		TopNavBarDiv = document.getElementById("TopNavBarDiv");	
	}	
	if ((!FooterDiv) && (document.all))
	{
		//IE 4 and IE 5 Code
		FooterDiv = document.all.FooterDiv;
		TopNavBarDiv = document.all.TopNavBarDiv;
	}	
	if (FooterDiv && LeftNavBarDiv && TopNavBarDiv)
	{
		if (document.all)
		{
			//IE Code
			FooterTop = document.body.scrollHeight - FooterDiv.style.pixelHeight;
			if ((FooterDiv.offsetTop > 0) && (FooterTop > FooterDiv.offsetTop)) 
			{
				FooterDiv.style.pixelTop = FooterTop;
			}	
			FooterDiv.style.pixelLeft = LeftNavBarDiv.offsetLeft;
			LeftNavBarDiv.style.pixelHeight = FooterTop - TopNavBarDiv.offsetHeight;
		}
	}
	
	var ctls = document.getElementsByTagName("iframe");
	if (ctls)
	{
		for (i = 0; i < ctls.length; i++)
		{
			if (ctls[i].id.search(FocusControl) >= 0)
			{
				ctls[i].document.body.onpaste = function() 
				{ 
					setTimeout("RTB_ClearMSWord(" + ctls[i].id + ");",50); 
				};	
			}
		}	
	}		
	
	document.onmousedown = PageOnClick;
	var oDlg = document.getElementById("RTB_linkDialog");
	if (oDlg)
	{
		oDlg.onmove = RTB_DlgMove;
	}
	oDlg = document.getElementById("RTB_imageDialog");
	if (oDlg)
	{
		oDlg.onmove = RTB_DlgMove;
	}
	
	if (FocusControl)
	{
		iTimeOut = window.setTimeout(SetInitialFocus, 100);
	}

	if (BodyLoadCallBack == 1)	
		onBodyLoad();
}

function SetInitialFocus()
{
	window.clearTimeout(iTimeOut);
	var ctls = document.getElementsByTagName("input");
	if (ctls)
	{
		for (i = 0; i < ctls.length; i++)
		{
			if (ctls[i].id.search(FocusControl) >= 0)
			{
				ctls[i].focus();
				return;
			}
		}	
	}		
	var ctls = document.getElementsByTagName("select");
	if (ctls)
	{
		for (i = 0; i < ctls.length; i++)
		{
			if (ctls[i].id.search(FocusControl) >= 0)
			{
				ctls[i].focus();
				return;
			}
		}	
	}		
	var ctls = document.getElementsByTagName("input");
	if (ctls)
	{
		for (i = 0; i < ctls.length; i++)
		{
			if (ctls[i].id.search(FocusControl2) >= 0)
			{
				ctls[i].focus();
				return;
			}
		}	
	}		
	var ctls = document.getElementsByTagName("select");
	if (ctls)
	{
		for (i = 0; i < ctls.length; i++)
		{
			if (ctls[i].id.search(FocusControl2) >= 0)
			{
				ctls[i].focus();
				return;
			}
		}	
	}		
}


var iLastClickY = 0;

function PageOnClick()
{
	if (document.all)
	{
		iLastClickY = window.event.clientY;
		iLastClickX = window.event.clientX;
	}	
}

function RTB_DlgMove()
{
	var oDlg = window.event.srcElement;
	if (oDlg)
	{
		oDlg.style.top = document.body.scrollTop + iLastClickY;				
		if (oDlg.style.pixelTop + oDlg.offsetHeight > document.body.clientHeight + document.body.scrollTop) 
		{
			oDlg.style.pixelTop = document.body.clientHeight + document.body.scrollTop - oDlg.offsetHeight;
		}
		oDlg.style.left = document.body.scrollLeft + iLastClickX;
		if (oDlg.style.pixelLeft + oDlg.offsetWidth > document.body.clientWidth + document.body.scrollLeft) 
		{
			oDlg.style.pixelLeft = document.body.clientWidth + document.body.scrollLeft - oDlg.offsetWidth;
		}
	}	
}	




function HighlightRow(row, color)
{
	row.bgColor = color;
	row.style.backgroundColor = color;
}

function ConfirmDeleteLine(event, obj, objID)
{
	if (!confirm("Are you sure you want to delete this line?"))
	{
		event.cancelBubble = true;
		event.returnValue = false;
		return false;
	}
	return true;
}

function TextBoxBlur(event, obj, fieldId, buttonId)
{
	var sId = obj.id;
	sId = sId.replace(fieldId, buttonId)
	var btn = document.getElementById(sId);
	btn.click();
}

function ShowCalendar(event, fieldId)
{
	var w = 210;
	var h = 140;
	var x = (document.all) ? window.event.screenX : event.screenX;
	var y = (document.all) ? window.event.screenY : event.screenY;
	if ((x + w) > window.screen.availWidth)
	{
		x = x - w;
	}
	if ((y + h) > window.screen.availHeight)
	{
		y = y - h;
	}
	w = w - 6;
	h = h - 2;
	CalendarWindow = window.open('Calendar.aspx?formname=' + fieldId, 'CalendarWindow', 'top=' + y + ',left=' + x + ',width=' + w + ',height=' + h);
	CalendarWindow.focus();
}

function ShowPublicCalendar(event, fieldId)
{
	var w = 210;
	var h = 140;
	var x = (document.all) ? window.event.screenX : event.screenX;
	var y = (document.all) ? window.event.screenY : event.screenY;
	if ((x + w) > window.screen.availWidth)
	{
		x = x - w;
	}
	if ((y + h) > window.screen.availHeight)
	{
		y = y - h;
	}
	w = w - 6;
	h = h - 2;
	CalendarWindow = window.open('/includes/Calendar.aspx?formname=' + fieldId, 'CalendarWindow', 'top=' + y + ',left=' + x + ',width=' + w + ',height=' + h);
	CalendarWindow.focus();
}

function ShowCalendarGrid(event, obj, fieldId, buttonId)
{
	var sId = obj.id;
	sId = sId.replace(buttonId, fieldId)
	ShowCalendar(event, sId);
}	

function ShowPublicCalendarGrid(event, obj, fieldId, buttonId)
{
	var sId = obj.id;
	sId = sId.replace(buttonId, fieldId)
	ShowPublicCalendar(event, sId);
}	

function RTB_ClearMSWord(editorid) 
{ 
	var editor = document.getElementById(editorid); 
	editor.focus(); 

	var corps = editor.document.body; 

	for (var i = 0; i < corps.all.length; i++) 
	{ 
		tag = corps.all[i]; 
		tag.removeAttribute("className","",0); 
		tag.removeAttribute("style","",0); 
	} 

	var html = editor.document.body.innerHTML; 

	//remove font tags and ms-word tags 
	html = html.replace(/<(\/)?((DIV)|(SPAN)|(O:P)|(FONT))( (([^>])+)>|>)/gi, ""); 

	//remove useless paragraphs 
	//html = html.replace(/<P>(&nbsp;)*<\/P>/gi, ""); 

	//replace IE tags 
	//html = html.replace(/<(\/)?(STRONG)( (([^>])+)>|>)/gi, "<$1B>"); 
	//html = html.replace(/<(\/)?(EM)( (([^>])+)>|>)/gi, "<$1I>"); 

	//replace bullets 
	//html = html.replace(/<p>(·|Ø)(&nbsp;)*(([^>])+)<\/p>/gi, "<li>$3</li>"); 

	//remove useless italics (on paste some < u>&nbsp;< /u> may appear) 
	//html = html.replace(/<U>(&nbsp;)*<\/U>/gi, ""); 

	//remove useless paragraphs created 
	//when headers were replaced 
	//html = html.replace(/<P>(<[^>]*>)*(&nbsp;)*(<[^>]*>)*<\/P>/gi,""); 

	editor.document.body.innerHTML = html;
} 

function OpenSitePlan(URL)
{
var aw = screen.availWidth - 20
var ah = screen.availHeight - 20
var WinFeatures = "top=10,left=10,width=" + aw + ",height=" + ah +",toolbar=no,menubar=no,scrollbars=no,titlebar=no";
window.open(URL,"",WinFeatures);
}
