/*---------------------------------------------------------------------------------------------------------------------
Copyright (C) 2002 Multimedia Solutions Corporation.
All rights reserved.

Description:	SPECTRUM TERRA NOVA GENERAL FUNCTIONS
				Juan F. Sarria, Naresh
Date:			04/23/2003
Modified:		04/28/2003
				06/12/2004
----------------------------------------------------------------------------------------------------------------------*/

var SubMenusTop = 120; //117; // Change this variable to position drop down sub menus 
var PageName = GetFileName(document.URL);

NS5 = document.layers;
IE = document.all;
NS6 = document.getElementById && !document.all;

IE = (typeof(IE) != "undefined" && IE != false ) ? true : false;
NS = ((typeof(NS5) != "undefined" && NS5 != false) || (typeof(NS6) != "undefined" && NS6 != false)) ? true : false;

button = new Array (20);
GoToURL = new Array(20);

for (i=0; i<20; i++) { button[i] = new Array(20) }
for (i=0; i<20; i++) { GoToURL[i] = new Array(20) }

var MM_contentVersion = 4;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
		}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

function moveFooter() {
	var iBottom = 0;
	
	if (document.all) {
		if (parseInt(document.body.scrollHeight) > parseInt(document.body.clientHeight)) {
			iBottom = parseInt(document.body.scrollHeight);
		}	
		else iBottom = parseInt(document.body.clientHeight);
		document.all["lyfooter"].style.pixelTop = iBottom - parseInt(document.all["lyfooter"].style.height);
		document.all["lyfooter"].style.visibility = "visible";
	}
	else if (document.layers)	{
		if (document.height > self.innerHeight) {
			iBottom = document.height;
		}	
		else iBottom = self.innerHeight;				
		document.layers["lyfooter"].top = parseInt(iBottom - document.layers["lyfooter"].document.height);
		document.layers["lyfooter"].visibility = "visible";				
	}
	else if (document.getElementById) { //NS6
		if (document.height > self.innerHeight) {
			iBottom = document.height;
		}	
		else iBottom = self.innerHeight;					
		document.getElementById("lyfooter").style.top = (parseInt(iBottom - parseInt(document.getElementById("lyfooter").style.height))) + "px";		
		document.getElementById("lyfooter").style.visibility = "visible";		
		
	}
	
}

function OpenWin(file,w,h) {
	var win1;
	if(win1 == null) win1 = open(file,"Win1","status=yes,scrollbars=1,location=0,menubar=0,resizable=1,toolbar=0,width="+w+",height="+h);
	win1.focus();
}


function OpenDownload(FileName) {
	OpenWin(FileName,450,300);
}

function GetFileName(URL) {
		// Get file name with out the path and the extention
		RetVal = URL;
		rExp = /\\/gi;
		RetVal = RetVal.replace(rExp, "/");
		Path = RetVal.split("/");
		Last = Path.length;
		RetVal = Path[Last-1];
		
		// Just the name without the extension
		//Path = RetVal.split(".");
		//RetVal = Path[0];

		return RetVal;
}

function isEmailAddress(string) {
	var addressPattern = /^(\w+[-])*(\w+[.])*(\w+[-])*\w+\@(\w+[-])*(\w+[.])+\w+$/;
	return addressPattern.test(string);
}

function isZipCode(string) {
	var ZipCodePattern = /^\d{5,}\-{0,1}\d*/;
	return ZipCodePattern .test(string);
}

function openWin2(file,w,h) {
	var win2;
	if(win2 == null) win2 = open(file,"pt2","status=yes,scrollbars=1,location=0,menubar=0,resizable=1,toolbar=0,top=0,left=150,top=50,width="+w+",height="+h);
	win2.focus();
}

function OpenElevation(Key,No,w,h) {
	var win3;
	if(win3 == null) win3 = open("ViewElevation.asp?Key="+Key+"&No=" + No,"pt3","status=yes,scrollbars=1,location=0,menubar=0,resizable=1,toolbar=0,top=0,left=150,top=50,width="+w+",height="+h);
	win3.focus();
}
function SetOrder(Section,FieldName,Order) {
	Exp = "";
	document.cookie = Section + "_Order=" + Order + "; path=/;";
	SetOrder2(Section,FieldName);
}
function SetOrder2(Section,FieldName) {
	//var Exp = new Date();
	//Exp.setTime(Exp.getTime() + 315360000000); // Expire in 10 years from NOW
	Exp = "";
	document.cookie = Section + "=" + FieldName + "; path=/;";
	window.location.reload();
}

function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=415,height=270,left=192,top=175");
}

function OnOff(LayerID, Action) {
	if (IE && document.all[LayerID]) 
	{
		o = document.all[LayerID];
		o.style.visibility = Action;
	}
	else if (NS5 && document.layers[LayerID]) 
	{
		document.layers[LayerID].visibility = Action;
	}
	else if (NS6 && document.getElementById(LayerID)) 
	{
		document.getElementById(LayerID).style.visibility = Action;
	}
	
	if (AdminTools)
	{
		o.style.top = SubMenusTop - 7;
	}
	else
	{
		o.style.top = (Section != 0) ? SubMenusTop: SubMenusTop + 220;
	}
}

function OnOffMAP(LayerID, Action, Sw) {
	if ((Action == 'visible') && (Sw!=1)) OffAllStates('hidden', Sw);
	Layer = LayerID
	rExp = /_TITLE/gi;
	Layer = Layer.replace(rExp, "");
	rExp = /_STATE/gi;
	Layer = Layer.replace(rExp, "");
	OnOff(Layer,Action);
	OnOff(Layer+'_TITLE',Action);
}

function OffAllStates(Action) {
	OnOffMAP('NY',Action,1);
	OnOffMAP('PA',Action,1);
	OnOffMAP('NJ',Action,1);
	OnOffMAP('DE',Action,1);
	OnOffMAP('CT',Action,1);
	OnOffMAP('MD',Action,1);
}

function MapJumpTo(State, County) {
	if (AdminTools == true) {
		window.location = "default.asp?Sec=1&Sub=&ST="+State+"&CT="+County
	} else {
		window.location = "WebContent.asp?Sec=2&Sub=2&ST="+State+"&CT="+County
	}
}

function RegJumpTo(State) {
	window.location = "default.asp?Sec=1&Sub=1&ST="+State
}

function ConfirmAlert(JumpTo) {
   if (confirm("Are you sure you want to delete this record ?")) {
		window.location = JumpTo;
   }
}

function UploadIMG(FileName, Folder, Field) {
	openWin2("UpLoadForm.asp?Type=IMG&FileName=" + FileName + "&Folder=" + Folder + "&Field=" + Field,400,100);
}

function UploadPDF(FileName, Folder, Field) {
	openWin2("UpLoadForm.asp?Type=PDF&FileName=" + FileName + "&Folder=" + Folder + "&Field=" + Field,400,100);
}

function jumpTo(Where, frame)
{
	if (Where != "")
	{
		if (typeof(frame) != "undefined")
		{
			var win1;
			win1 = open(Where,"Win1","status=yes,scrollbars=1,location=1,menubar=1,resizable=1,toolbar=1");
			win1.focus();
		}
		else
		{
			location.href = Where;
		}
	}
}

function TurnOption(o, Color)
{
	o.style.backgroundColor = Color;
}


function OnThisOption(o, Color)
{
	o.style.backgroundColor = Color;
	ChangeChildColor(o, "#FFFFFF");
}

function OffThisOption(o)
{
	o.style.backgroundColor = "";
	ChangeChildColor(o, "");
}

function ChangeChildColor(o, Color)
{
	var i = -1;
	while ( ++i < o.childNodes.length )
	{
		o.childNodes[i].style.color = Color;
	}
}

function setImg(o, Img)
{
	o.src = Img;
}

function ChangeArrow(No, y, Ind)
{	
	var ImageName = "t_" + No + "_" + y;
	var ImageFile = "images/arrow_up_" + Ind + ".gif"
	document.images[ImageName].src = ImageFile;
	
}

function setValue(o, sValue)
{
	for ( var t=0; t < o.length; ++t)
		if (o(t).value == sValue)
			o(t).selected = true;
}

function autoTab(sVal, iLen, sNext) {
	if ( sVal.length == iLen ) {
		Next = eval("document.form." + sNext);
		Next.focus();
	}
}

function setCookieVal(sName, sValue) {
	Exp = "";
	document.cookie = sName + "=" + sValue + "; path=/;";
}

