
// functions.js (arainia.com)
// Copyright © 1995-2005 Logan Mueller, All rights reserved.

function RowOverlay(rowObj, clrNew)
{
	rowObj.style.backgroundColor = clrNew;
	rowObj.style.cursor = "pointer";
}

function EditHelp(ctrl,szHelpText,bFocus)
{
    if (bFocus)
        EditHelpEx(ctrl,szHelpText,bFocus,'#000000');
    else
        EditHelpEx(ctrl,szHelpText,bFocus,'#cccccc');
}

function EditHelpEx(ctrl,szHelpText,bFocus,clrText)
{
    if (bFocus)
    {
        ctrl.style.color = clrText;

        if (ctrl.value == szHelpText)
            ctrl.value = '';
    }
    else
    {
        if (ctrl.value == '')
        {
            ctrl.style.color = clrText;
            ctrl.value = szHelpText;
        }

    if (ctrl.value == szHelpText)       // Support refresh
            ctrl.style.color = clrText;
    }
}

function TableRowOverlay(rowObj,clrNew)
{
	var aryCells = rowObj.getElementsByTagName('td');
	var nCells = aryCells.length;

	for (var iCell = 0; iCell < nCells; iCell++)
	{
		aryCells[iCell].style.backgroundColor = clrNew;
		aryCells[iCell].style.cursor = "pointer";
	}
}

function ApplyMouseOver(nStyle,bOver,obj)
{
	if (nStyle == 0)
	{
		if (bOver)
		{
			obj.style.borderColor = "#ddd";
			obj.style.borderStyle = "solid";
			obj.style.cursor = "pointer";
		}
		else
		{
			obj.style.borderColor = "#ccc";
			obj.style.borderStyle = "solid";
		}
	}
}

function ApplyOverLink(obj,bOver)
{
	if (bOver)
	{
		obj.style.borderWidth = 1;
		obj.style.borderStyle = "solid";
		obj.style.padding = 2;
		obj.style.borderColor = "#aaa";
		obj.style.backgroundColor = "#ddd";
	}
	else
	{
		obj.style.borderWidth = 0;
		obj.style.borderStyle = "none";
		obj.style.padding = 3;
//		obj.style.borderColor = "#efefef";
		obj.style.backgroundColor = "transparent";
	}
}

function RowBorder(rowObj, clrNew)
{
	if (clrNew == null)
	{
		rowObj.style.borderWidth = 0;
		rowObj.style.borderStyle = "none";		// Hide border
		rowObj.style.padding = 10;				// Reapply padding (CSS should be initially 10)
	}
	else
	{
		rowObj.style.borderWidth = 1;
		rowObj.style.borderStyle = "solid";		// Show border
		rowObj.style.borderColor = clrNew;		// Set border color
		rowObj.style.padding = 9;				// Adjust padding (CSS should be initially 10)
		rowObj.style.cursor = "pointer";
	}
}

function MakeButtonCore(szBtnText, szBtnLink, nWidth, bPressed, nHeight, clrText, nFontSize)
{
	if (bPressed)
	{
		document.write('<TD><IMG SRC="/btn-start-pressed.jpg" WIDTH=1 ' +
			'HEIGHT=' + nHeight + '></TD><TD WIDTH=' + nWidth + ' HEIGHT=' + nHeight + 
			' ALIGN=center ' +
			'BACKGROUND="/btn-gradient-pressed.jpg"><A STYLE="color: ' + clrText + 
			'; font-size: ' + nFontSize + 'px;" HREF="' + szBtnLink + 
			'">' + szBtnText + '</A></TD><TD>' +
			'<IMG SRC="/btn-end-pressed.jpg" WIDTH=1 HEIGHT=' + nHeight + '></TD>');
	}
	else
	{
		document.write('<TD><IMG SRC="/btn-start.jpg" WIDTH=1 ' +
			'HEIGHT=' + nHeight + '></TD><TD WIDTH=' + nWidth + ' HEIGHT=' + nHeight + 
			' ALIGN=center ' +
			'BACKGROUND="/btn-gradient.jpg"><A STYLE="color: ' + clrText + 
			'; font-size: ' + nFontSize + 'px;" HREF="' + szBtnLink + 
			'">' + szBtnText + '</A></TD><TD>' +
			'<IMG SRC="/btn-end.jpg" WIDTH=1 HEIGHT=' + nHeight + '></TD>');
	}
}

function MakeButtonEx(szBtnText, szBtnLink, nWidth, bPressed)
{
	MakeButtonCore(szBtnText, szBtnLink, nWidth, bPressed, 27, 
		bPressed ? '#000' : 'navy', 12);
}

function MakeButton(szBtnText, szBtnLink, nWidth)
{
	MakeButtonEx(szBtnText,szBtnLink,nWidth,false);
}

function MakeHierarchy(aryLinks,szCurrent)
{
	document.write('<TABLE HEIGHT=25 WIDTH=100% BORDER=0 CELLPADDING=1 ' +
		'CELLSPACING=0 BGCOLOR=efefef><TR><TD><FONT SIZE=1>&nbsp;\n');
   
	for (var iItem = 0; iItem < aryLinks.length; iItem += 2)
	{
		document.write(
			'<A HREF="' + aryLinks[iItem] + '" ' +
			'ONMOUSEOVER="ApplyOverLink(this,true);" ' +
			'ONMOUSEOUT="ApplyOverLink(this,false);" ' +
			'STYLE="padding: 3px; height: 10px;" ' +
			'>&nbsp;' +
			aryLinks[iItem + 1] + '&nbsp;</A>' +
			'<FONT STYLE="padding: 3px; height: 10px; color: #666;">|</FONT>');
	}

	document.write('<FONT STYLE="padding: 3px; height: 10px;">' + 
		szCurrent + '</FONT>\n');
	document.write('</FONT></TD>');
  
	if (aryLinks.length >= 2)       // Make [Up] link, if necessary
	{
		document.write('<TD WIDTH=0 ALIGN=right><DIV ' +
			'ONMOUSEOVER="ApplyOverLink(this,true);" ' +
			'ONMOUSEOUT="ApplyOverLink(this,false);" ' +
			'STYLE="padding: 3px; height: 11px; width: 40px; margin: 0px;">' +
			'<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>' +
			'<TR><TD>' +
			'<A HREF="' + aryLinks[aryLinks.length - 2] + '">' +
			'<IMG SRC="/navigate-up.gif" WIDTH=13 HEIGHT=12 BORDER=0></A>' +
			'</TD><TD><A HREF="' + aryLinks[aryLinks.length - 2] + 
			'"><FONT SIZE=1>&nbsp;&nbsp;Up&nbsp;&nbsp;&nbsp;</A></FONT>' +
			'</FONT></TD></TR></TABLE></DIV></TD>');
	}

	document.write('</TR></TABLE><DIV STYLE="border-top: 1px solid #bbb; ' +
		'width: 100%; margin-bottom: 0px; font-size: 0px;">\n');
}

function WriteCurrentDate()
{
	var aryMonths = new Array(13);
	
	aryMonths[1]  = "January";
	aryMonths[2]  = "February";
	aryMonths[3]  = "March";
	aryMonths[4]  = "April";
	aryMonths[5]  = "May";
	aryMonths[6]  = "June";
	aryMonths[7]  = "July";
	aryMonths[8]  = "August";
	aryMonths[9]  = "September";
	aryMonths[10] = "October";
	aryMonths[11] = "November";
	aryMonths[12] = "December";
	
	var time = new Date();
	var szMonth = aryMonths[time.getMonth() + 1];
	var nDate = time.getDate();
	var nYear = time.getYear();
	if (nYear < 2000) nYear = nYear + 1900;
	
	document.write(szMonth);
	document.write(" " + nDate + ", " + nYear);
}

function MakeFooter()
{
	MakeFooterEx(true);
}

function MakeFooterEx(bIncludeSpacing)
{
	var time = new Date();
	var nYear = time.getYear();
	if (nYear < 2000) nYear = nYear + 1900;
	
	if (bIncludeSpacing)
	{
		document.write('<DIV ID=divBottomMargin STYLE="margin: 0px; height: 20px;"></DIV>');
	}

	var szLinkCode = '<A ONMOUSEOVER="ApplyOverLink(this,true);" ' +
			'ONMOUSEOUT="ApplyOverLink(this,false);" ' +
			'STYLE="padding: 3px; height: 10px; font-weight: normal;" ' +
			'HREF="http://arainia.com/';
	var szSplit = '<FONT STYLE="padding-top: 3px; padding-bottom: 3px; ' +
		'height: 10px;" COLOR=666666>|</FONT>';
    
	document.write('<DIV ID=divBottom ' +
		'STYLE="border-top: 1px solid #ccc; width: 100%; ' +
		'position: absolute; ' +
		'margin-bottom: 0px; ' +
		'background-color: #f5f5f5; font-size: 0px;">' +
		'<TABLE HEIGHT=28 WIDTH=100%><TR><TD>' +
		'<FONT FACE="tahoma,arial,helvetica" SIZE=1>' +
		'&nbsp;&nbsp;&nbsp;Copyright &#169 ' + nYear + 
		' <A HREF="http://arainia.com/about.html">Arainia Solutions LLC</A>, ' + 
		'All rights reserved.' +
		'</FONT>' +
		'</TD>' +
		'<TD ALIGN=center>' +
		'<FONT STYLE="font-size: 9px;" COLOR=333333>' +
		szLinkCode + 'software.html">&nbsp;software downloads&nbsp;</A>' + szSplit +
		szLinkCode + 'services.html">&nbsp;sites & services&nbsp;</A>' + szSplit +
		szLinkCode + 'hosting.html">&nbsp;web hosting&nbsp;</A>' + szSplit +
		szLinkCode + 'support.html">&nbsp;customer care&nbsp;</A>' + szSplit +
		szLinkCode + 'about.html">&nbsp;about arainia&nbsp;</A> ' +
		'</FONT>' +
		'</TD>');
		
	if (document.body.clientHeight < document.body.scrollHeight)
	{
		document.write('<TD WIDTH=0 ALIGN=right><DIV ' +
			'ONMOUSEOVER="ApplyOverLink(this,true);" ' +
			'ONMOUSEOUT="ApplyOverLink(this,false);" ' +
			'STYLE="padding: 3px; height: 11px; width: 40px; margin: 0px;">' +
			'<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>' +
			'<TR><TD>' +
			'<A HREF="javascript:window.scrollTo(0,0);">' +
			'<IMG SRC="/navigate-top.gif" WIDTH=12 HEIGHT=13 BORDER=0></A>' +
			'</TD><TD><A HREF="javascript:window.scrollTo(0,0);">' + 
			'<FONT SIZE=1>&nbsp;&nbsp;Top&nbsp;&nbsp;</A></FONT>' +
			'</FONT></TD></TR></TABLE></DIV></TD>');
	}
	else
	{
		document.write('<TD>&nbsp;&nbsp;</TD>'); 
	}
 
	document.write('</TR></TABLE></DIV>');

	HookLoadAndResize();
}

var g_fnOnLoad = document.onload;
var g_fnOnResize = window.onresize;

function HookLoadAndResize()
{
    g_fnOnLoad = document.onload;
    document.onload = HookOnLoad();

    // Inject resize functionality

    g_fnOnResize = window.onresize;
    window.onresize = function (evt) { HookOnResize(); };
}

var g_rgOnResizeMethods = new Object();

function AddResizeCode(strCode)
{
	g_rgOnResizeMethods[g_rgOnResizeMethods.length] = strCode;
}

function HookOnResize()
{
    RepositionFooter();

	for (var idx = 0; idx < g_rgOnResizeMethods.length; idx++)
	{
		eval(g_rgOnResizeMethods[idx])(evt);
	}

    var evt;

	if (g_fnOnResize)
	{
	    eval(g_fnOnResize)(evt);
	}
}

function HookOnLoad()
{
    RepositionFooter();

    eval(g_fnOnLoad);
}

function SetElementImage(szElementID,szImageFile)
{
	var element = document.getElementById(szElementID);
	element.style.backgroundImage = 'url(' + szImageFile + ')';
	element.style.backgroundPosition = "top left";
	element.style.backgroundRepeat = "no-repeat";
}

function SetElementOverlay(element,szImageFile,bShow)
{
	if (element.style.backgroundImage == '' ||
		element.style.backgroundImage == 'url(' + szImageFile + ')')
	{
		if (bShow)
		{
			element.style.backgroundImage = 'url(' + szImageFile + ')';
			element.style.cursor = "pointer";
		}
		else
			element.style.backgroundImage = '';
			
		element.style.backgroundPosition = "top left";
		element.style.backgroundRepeat = "no-repeat";
	}
}

function RepositionFooter()
{
    var divBottomMargin = document.getElementById("divBottomMargin");

    if (divBottomMargin)
    {
        var divBottom = document.getElementById("divBottom");

        if (divBottom)
        {
            var nNewTop = document.body.clientHeight -
                divBottom.offsetHeight;

            var nMaxTop = divBottomMargin.offsetTop;
            var objOffsetNext = divBottomMargin.offsetParent;

            while (objOffsetNext)
            {
                nMaxTop += objOffsetNext.offsetTop;
                objOffsetNext = objOffsetNext.offsetParent;
            }

            nMaxTop += divBottomMargin.offsetHeight;

            if (nNewTop < nMaxTop)
            {
                nNewTop = nMaxTop;
            }

            divBottom.style.top = nNewTop;
        }
    }
/*
	if (document.body.clientHeight >= document.body.scrollHeight)
	{
		var divBottom = document.getElementById("divBottom");

		if (divBottom)
		{		
			divBottom.style.top = document.body.clientHeight -
				divBottom.offsetHeight;  
		}
	}
*/
}

function WriteFooter()
{
	var time = new Date();
	var nYear = time.getYear();
	if (nYear < 2000) nYear = nYear + 1900;

	document.write('<TABLE HEIGHT=30 WIDTH=98%><TR><TD VALIGN=top>' +
		'<CENTER><FONT FACE="tahoma,arial,helvetica" SIZE=1>' +
		'Copyright &#169 1995-' + nYear + 
		' <A HREF="http://arainia.com/about.html">Arainia.Com</A>, All rights reserved.' +
		'</FONT></CENTER>' +
		'</TD><TD VALIGN=top ALIGN=right>' +
		'<FONT SIZE=1>' +
		'<A HREF="http://arainia.com/software.html">software downloads</A> | ' +
		'<A HREF="http://arainia.com/services.html">sites & services</A> | ' +
		'<A HREF="http://arainia.com/hosting.html">web hosting</A> | ' +
		'<A HREF="http://arainia.com/support.html">customer care</A> | ' +
		'<A HREF="http://arainia.com/about.html">about arainia</A> ' +
		'</FONT>' +
		'</TD></TR></TABLE>');
}

var g_szCurrentAudio = ""; 

function InstallAudioPlayer(szNewAudio)
{
	var bWMP7;
	var szClassID = "CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95";
	
	// Check if Media Player 7 is installed, if so then use its special ClassID
	
	if (navigator.appName != "Netscape") 
		//bWMP7 = new ActiveXObject('WMPlayer.OCX');
	
	if (bWMP7) szClassID = "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6";
	
	if (szNewAudio == g_szCurrentAudio) return;
	g_szCurrentAudio = szNewAudio; 
	
	// AudioArea should exist
	
	document.getElementById("AudioArea").innerHTML =  
		"<OBJECT ID=\"AudioPlayer\" CLASSID=\"" + szClassID + "\" " +  
		"TYPE=\"application/x-oleobject\" HEIGHT=70 WIDTH=300>" +  
		"<PARAM NAME=\"FileName\" VALUE=\"" + g_szCurrentAudio + "\" />" +  
		"<PARAM NAME=\"AutoStart\" VALUE=\"1\" />" +  
		"<PARAM NAME=\"TransparentAtStart\" VALUE=\"1\" />" +  
		"<PARAM NAME=\"ShowControls\" VALUE=\"1\" />" +  
		"<PARAM NAME=\"EnableFullScreenControls\" VALUE=\"1\" />" +  
		"<PARAM NAME=\"AnimationAtStart\" VALUE=\"0\" />" +  
		"<PARAM NAME=\"ShowStatusBar\" VALUE=\"1\" />" +  
		"<PARAM NAME=\"ShowDisplay\" VALUE=\"0\" />" +
		"<EMBED TYPE=\"application/x-mplayer2\" SRC=\"" + g_szCurrentAudio + "\" " +
		"NAME=\"AudioPlayer\" WIDTH=300 HEIGHT=70 ShowStatusBar=1 ShowControls=1 " +
		"AnimationAtStart=0 AutoStart=1 ShowDisplay=0></EMBED>" +
		"</OBJECT>";
		
	// Make sure Internet Explorer starts playing the file
		
	document.AudioPlayer.fileName = g_szCurrentAudio;
}

function PopupURL(szURL)
{
	PopupURLEx(szURL,0,0,660,500);
}

function PopupURLEx(szURL,nX,nY,nWidth,nHeight)
{
	javascript:window.open(szURL,'Form','width=' + nWidth + ',height=' + nHeight + 
		',top=' + nY + ',left=' + nX + ',' +
		'toolbar=yes,location=no,directories=no,status=no,menubar=yes,' +
		'scrollbars=yes,resizable=yes');
	
	void(0);
}

function AddValueToList(edt,lst,szEmptyText)
{
	if (edt.value == "")
		return;
	
	if (lst.length == 1 && szEmptyText != "" && szEmptyText != null)
	{
		if (lst[0].text == szEmptyText)
		lst[0] = null;
	}
	
	var nNewIndex = lst.length;
	
	lst[nNewIndex] = new Option(edt.value,edt.value);
	
	lst[nNewIndex].selected = true;
	edt.value = "";
}

function RemoveValueFromList(lst,szEmptyText)
{
	var nSelIndex = lst.selectedIndex;
	
	lst[nSelIndex] = null;
	if (nSelIndex >= lst.length) nSelIndex--;
	
	if (lst.length == 0 && szEmptyText != "" && szEmptyText != null)
	{
		lst[0] = new Option(szEmptyText,0);
		nSelIndex = 0;
	}
	
	lst[nSelIndex].selected = true;
}

function SelectAllList(lst)
{
	var nItems = lst.length;
	
	lst.multiple = true;
	
	for (var iItem = 0; iItem < nItems; iItem++)
		lst[iItem].selected = true;
}

function FindObjPos(obj)
{
	var offsetTrail = obj;
	var offsetLeft = 0;
	var offsetTop = 0;
	
	while (offsetTrail)
	{
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}

	if (navigator.userAgent.indexOf('Mac') != -1 && 
		typeof document.body.leftMargin != 'undefined')
	{
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	
	return {X:offsetLeft,Y:offsetTop};
}

function MakeFrameForText(szID, nMiniHeight, bHeader)
{
	MakeFrameForTextCore(szID, nMiniHeight, bHeader, 472);
}

function MakeFrameForTextCore(szID, nMiniHeight, bHeader, nWidth)
{
	if (bHeader)
	{
		var szWidth = nWidth;

		// Firefox takes padding and border into account

		if (navigator.userAgent.indexOf('Firefox') != -1)
			szWidth = nWidth - 22;

		document.write('<DIV ID="' + szID + 'frame" STYLE="height: ' + 
			nMiniHeight + 'px; ' +
			'width: ' + szWidth + 'px; background-color: #efefef; ' +
			'overflow: hidden; ' +
			'border: 1px solid #ccc; padding: 0px 10px; color: black;">' +
			'<DIV ID="' + szID + 'text" STYLE="padding: 10px 0px;">');
	}
	else
	{
		document.write('</DIV></DIV>' + 
			'<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>' +
			'<TR><TD WIDTH=100%>&nbsp;</TD><TD>' +
			'<DIV ONCLICK="AmendFrameForText(' +
			'this,\'' + szID + '\',' + nMiniHeight + ');" ' +
			'ONMOUSEOVER="this.style.cursor = \'pointer\';" ' +
			'STYLE="width: 100%; text-align: ' +
			'right; font-weight: bold; font-size: 10px;">[More...]</DIV>' +
			'</TD></TR></TABLE>');	
	}
}

function AmendFrameForText(obj,szID,nMiniHeight)
{
	if (document.getElementById(szID + 'frame').offsetHeight < nMiniHeight + 5) 
	{
		document.getElementById(szID + 'frame').style.height = 
			document.getElementById(szID + 'text').offsetHeight - 10;
			
		obj.innerHTML = '[Close]';
	}
	else 
	{
		document.getElementById(szID + 'frame').style.height = nMiniHeight;

		obj.innerHTML = '[More...]';
	}
	
	// Reposition footer, only if scrolling is involved
	
	if (document.body.scrollHeight > document.body.clientHeight)
	{
		var divBottom = document.getElementById("divBottom");

		if (divBottom)
		{		
			divBottom.style.top = document.body.scrollHeight -
				divBottom.offsetHeight;  
		}
	}
}

var g_strAgent = navigator.userAgent.toLowerCase();
var g_bIE = (g_strAgent.indexOf('msie') != -1 && g_strAgent.indexOf('opera') == -1);
var g_bFireFox = (g_strAgent.indexOf('firefox') != -1);


