﻿// JScript File
function Align_Footer_Reset() {
	return true;
}

function GetWindowHeight(){
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		ht = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		   //IE 6+ in 'standards compliant mode'
		ht = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		ht = document.body.clientHeight;
	}
	return ht;
}

function Align_Footer() {
	/* Resize images/elements on the page to make the page fit the window
	 *
	 * The goal here is twofold:
	 *   1) force "gutter" amount to be off window in scroll area 
	 *   2) make columns (side bars, main content area) have the same height
	 *
	 */
	var WinHt = 1;
	var gutter = 75;
	var Test_Mode = false;
	
	WinHt = GetWindowHeight();
	if (Test_Mode) alert ('Window Height=' + WinHt + '\n' + 'document.body.parentNode.clientHeight=' + 
		document.body.parentNode.clientHeight + '\n' + 'document.documentElement.scrollHeight=' + document.documentElement.scrollHeight);
	try {
		WinHt = GreaterValue(WinHt, document.body.parentNode.clientHeight);
	}
	catch (error) {
		// Nothing
		fail = 0;
	}
	DocHt = (document.documentElement.scrollHeight ? document.documentElement.scrollHeight : WinHt);

	if (document.getElementById) { 
		/* We have a chicken and egg problem
		 * We need to resize the areas to match, but doing so may have an impact on the window
		 * so, identify the longest area first, then adjust its size if necessary to satisfy window sizing
		 * then come back to resizing remaining areas to match
		 */
		var Ele1Bot = document.getElementById("Body_Bottom");
		var Ele2Bot = document.getElementById("Main_Bottom");
		var Footer = document.getElementById("footer");
		// Topper is an alement generally under the header/nav that marks the top of the areas to resize
		var Topper = document.getElementById("topper");
		var Spacer1 = document.getElementById("BSpacer");
		var Spacer2 = document.getElementById("BSpacer2");
		
		if (Test_Mode) alert('WinHt=' + WinHt + '\nDocHt=' + DocHt + '\ngutter=' + gutter);
		if (WinHt + gutter > DocHt){
			var BottomEle;
			if (Ele1Bot && Ele2Bot) BottomEle = BottomElement(Ele1Bot, Ele2Bot);
			else if (Ele1Bot) BottomEle = Ele1Bot;
			else if (Ele2Bot) BottomEle = Ele2Bot;
			if ((BottomEle) && (Footer)) {
				// Slop is space not accounted for in the adj calculation
				// it should be set as appropriate for your html
				// In general, it is the amount of space between the BottomElement and the top of the footer
				Slop = 16;
				if (BottomEle.id == Ele2Bot.id){
					// EPODSW Specific
					Brd = document.getElementById("Main_Bot_Border");
					Slop += (findPos(Brd)[1] + EleHt(Brd)) - (findPos(Ele2Bot)[1] + EleHt(Ele2Bot)); 
					if (Test_Mode) alert('Slop Calc, Slop = ' + Slop + 
						'\n' + Brd.id + '.height = ' + EleHt(Brd) + ', top=' + findPos(Brd)[1] +
						'\n' + Ele2Bot.id + '.height = ' + EleHt(Ele2Bot) + ', top=' + findPos(Ele2Bot)[1]);
				}
				
				var adj = WinHt + gutter - Slop - EleHt(BottomEle) - findPos(BottomEle)[1] - EleHt(Footer); 
				if ((WinHt > adj) && (adj > 0)) {
					try {
						if (Test_Mode) alert('Slop = ' + Slop + 
							'\nBottomEle (' + BottomEle.id + ').absTop = ' + findPos(BottomEle)[1] + 
							'\nBottomEle (' + BottomEle.id + ').height =' + EleHt(BottomEle) + 
							'\nFooter.height =' + EleHt(Footer) + 
							'\nadj=' + adj +  
							'\nabout to set BottomEle (' + BottomEle.id + ').height to ' + (EleHt(BottomEle) + adj));

						BottomEle.style.height = adj + EleHt(BottomEle); 
						if (BottomEle.id == Ele1Bot.id) Spacer1.style.height = adj; 
						else Spacer2.style.height = adj; 
					}
					catch (error) {
						if (Test_Mode) alert('Problem resizing BottomEle');
						fail = 0;
					}
				}
			}
		}
		// Now resize areas so both are same height and inner contents are stretched
		// Slop here is space between the bottom of the area to be resized and the top of the footer
		// it should be set as appropriate for your html
		if (Ele1Bot && Footer && Spacer1){
			Ele1Slop = 16;
			adj = findPos(Footer)[1] - EleHt(Ele1Bot) - findPos(Ele1Bot)[1] - Ele1Slop;
			if (Test_Mode) alert('Slop Calc 01' + 
					'\nFooter (' + Footer.id + ').absTop = ' + findPos(Footer)[1] + 
					'\nEle1Bot (' + Ele1Bot.id + ').absTop = ' + findPos(Ele1Bot)[1] + ', Ele1Slop=' + Ele1Slop +
					'\nEle1Bot (' + Ele1Bot.id + ').calcHeight = ' + EleHt(Ele1Bot) +
					'\nAdjust = ' + adj);
			if ((adj > 0) && (adj > EleHt(Ele1Bot))) {
				Ele1Bot.style.height = adj; 
				Spacer1.style.height = adj;
			}
		} 
						
		if (Ele2Bot && Footer && Spacer2){
			Ele2Slop = 16;
			// EPODSW Specific
			Brd = document.getElementById("Main_Bot_Border");
			Ele2Slop += (findPos(Brd)[1] + EleHt(Brd)) - (findPos(Ele2Bot)[1] + EleHt(Ele2Bot)); 
			adj = findPos(Footer)[1] - EleHt(Ele2Bot) - findPos(Ele2Bot)[1] - Ele2Slop;
			if (Test_Mode) alert('Slop Calc, Slop = ' + Slop + 
				'\n' + Brd.id + '.height = ' + EleHt(Brd) + ', top=' + findPos(Brd)[1] +
				'\n' + Ele2Bot.id + '.height = ' + EleHt(Ele2Bot) + ', top=' + findPos(Ele2Bot)[1] +
				'\nAdjust = ' + adj);
			if ((adj > 0) && (adj > EleHt(Ele2Bot))) {
				Ele2Bot.style.height = adj; 
				Spacer2.style.height = adj;
			}
		}
	} else if (document.layers) {
		var t = eval('document.BSpacer');
		ht = ht - t.pageY;
		t.height = ht - gutter; 
	} else {
		var t = document.all['BSpacer'];
		ht = ht - t.y;
		t.height = ht - gutter; 
	}
	return true;
}

function ResizeImg(t, y, gutter) {
	//alert(t.id + ' ' + y + ' ' + gutter); 
	try {
		t.style.height = y - gutter; 
	}
	catch (error) {
		// Nothing
		fail = 0;
	}
}

function GreaterValue(Val1, Val2)
{
	if (Val1 > Val2) return Val1;
	else return Val2;
}

function EleHt(Ele)
{
	y = Ele.style.height ? Ele.style.height : 0;
	y = GreaterValue(y, Ele.offsetHeight);
	y = GreaterValue(y, Ele.scrollHeight);
	return y;
}

function BottomElement(Ele1, Ele2)
{
	bot1 = findPos(Ele1)[1] + GreaterValue(Ele1.offsetHeight, Ele1.scrollHeight);
	bot2 = findPos(Ele2)[1] + GreaterValue(Ele2.offsetHeight, Ele2.scrollHeight);
	var retele = (bot1 > bot2 ? Ele1 : Ele2);
	//alert('BottomElement for ' + Ele1.id + '[' + bot1 + '] ' + Ele2.id + '[' + bot2 + '], returning ' + retele.id);
	return retele;
}

function ShorterElement(Ele1, Ele2)
{
	ht1 = GreaterValue(Ele1.offsetHeight, Ele1.scrollHeight);
	ht2 = GreaterValue(Ele2.offsetHeight, Ele2.scrollHeight);
	if (ht1 < ht2) return Ele1;
	else return Ele2;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function jsClockTimeZone(){
	// Copyright 1999 - 2001 by Ray Stott
	// OK to use if this copyright is included
	// Script available at http://www.crays.com/jsc
	//var TimezoneOffset = -7  // adjust for time zone
	var localTime = new Date();
	var TimezoneOffset = 0;
	var time =  new Date();
	var hour = time.getHours(); 
	var minute = time.getMinutes();
	var second = time.getSeconds();
	var temp = "" + ((hour > 12) ? hour - 12 : hour);
	if(hour==0) temp = "12";
	if(temp.length==1) temp = " " + temp;
	temp += ((minute < 10) ? ":0" : ":") + minute;
	temp += ((second < 10) ? ":0" : ":") + second;
	temp += (hour >= 12) ? " PM" : " AM";
	WriteDiv("Clock", temp);
	setTimeout("jsClockTimeZone()",1000);
}

function WriteDiv(DName, DVal){
		if (document.getElementById) { 
		var t = document.getElementById(DName);
		t.innerHTML = DVal;
	} else if (document.layers) {
		var tLayer = eval('document.'+DName);
		tLayer.document.open();
		tLayer.document.write(DVal);
		tLayer.document.close();
		RightAlignDiv(DName);
	} else {
		var t = document.all[DName];
		t.innerHTML = DVal;
	}
	return true;
}


function SetStatus(Tx){
	window.status=Tx;
	return true;
}

function openChild(file, window, width, height, options) {
	if (options){
		opts = options
	} else {
		opts = 'resizable=yes'
	}
	var childWindow;
	if (childWindow == null || childWindow.closed){
			childWindow=open(file,window,opts+',width=' + width + ',height=' + height,false);
			if (childWindow.opener == null) childWindow.opener = self;
	} else {
		if ((childWindow.width != width) || (childWindow.height != height)) {
			childWindow.resizeTo(width,height);
		}
		childWindow.location=file;
		childWindow.focus();
	}
	return false;
}

function confirmDelete(e) 
{
	var targ; 
	var nodetype;
	if (!e) var e = window.event;
	targ = (e.target) ? e.target : e.srcElement;
	if(nodetype != null) {
		if (targ.nodeType == 3) targ = targ.parentNode;
	}
	if(targ.id)	{
		// alert('here I am. target=[' + targ.id + ']');
		if (targ.id.toLowerCase().indexOf("delete") >= 0) {        
			return confirm("Do you want to delete this item?");
		} else {
			if (document.getElementById && document.all) window.event.cancelBubble = true;
			else e.stopPropagation();   
		}
	}
}

document.onclick = confirmDelete;
