<!--
/*******************************************************************************
* Copyright © Building Strong Marriages, Inc.
*******************************************************************************/

var whitespace = " \t\n\r";
var digits = "0123456789";
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP";

function $id(id) 
{
	return document.getElementById(id);
}

function $name(name) 
{
	return document.getElementByName(name);
}

function trim(s)
{
	if (s.length > 0)
	{	
		//Trim leading whitespace
		while (whitespace.indexOf(s.substring(0, 1)) > -1)
		{
			s = s.substring(1, s.length);
		}
	
		//Trim trailing whitespace
		while (whitespace.indexOf(s.substring((s.length - 1), s.length)) > -1)
		{
			s = s.substring(0, (s.length - 1));
		}
	}
	
	return s;
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0));
}

function isWhitespace(s)
{   
	var i;
	
    if (isEmpty(s))
    {
		return true;
	}
	
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1)
        {
			return false;
		}
    }
    return true;
}

function isDigit(c)
{   
	return ((c >= "0") && (c <= "9"));
}

function isInteger(s)
{   
	var i;
	
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c))
        { 
			return false;
		}
    }
    return true;
}
		
function isNumber(s)
{   
	var i;
	
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if ((!isDigit(c)) && (c != "."))
        { 
			return false;
		}
    }
    return true;
}

function isEmail(s)
{
	var spacePos = s.indexOf(" ");
	var atPos = s.indexOf("@");
	var dotPos = s.indexOf(".", atPos);
	var endPos = s.length;
	var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check = /@[\w\-]+\./;
	var checkend = /\.[a-zA-Z]{2,3}$/;
			
	if (spacePos >= 0) 
	{
		return false;
	}

	if (atPos < 2) 
	{
		return false;
	}
						
	if (dotPos < (atPos + 2))	
	{
		return false;
	}

	if (endPos <= dotPos) 
	{
		return false;
	}
	
	if (((s.search(exclude) != -1) || (s.search(check)) == -1) || (s.search(checkend) == -1))
	{
		return false;
	}
		
	return true;
}

function isStateCode(s)
{   
	var aUSStateCodes = USStateCodes.split(USStateCodeDelimiter);
		
	for (var i = 0; i < aUSStateCodes.length; i++)
	{
		if (s == aUSStateCodes[i])
		{
			return true
		}
	}
		
	return false;
}

function isZIPCode(s)
{  
	return (isInteger(s) && (s.length == 5));
}

function warnInvalid(theField, s)
{   
	var sType = theField.type;
	
	if (!isEmpty(sType))
	{ 
		theField.focus();
    }
    
    if (sType == "text")
    {
		theField.select();
    }
    alert(s);
    return false;
}	

function getRadioButtonValue(radio)
{   
	for (var i = 0; i < radio.length; i++)
	{			
		if (radio[i].checked)
		{ 
			return radio[i].value;
		}
	}
}
		
function isOneChecked(radio)
{
	var bChecked = false; 
	
	if (!isEmpty(radio.length)) 
	{
		for (var i = 0; i < radio.length; i++)
		{			
			if (radio[i].checked)
			{
				bChecked = true; 
			}
		}
	}
	else 
	{
		if (radio.checked)
		{
			bChecked = true; 
		}
	}
	return bChecked;
}		

function CountSelections(radio)
{
	var nCount = 0;  

	if (!isEmpty(radio.length)) 
	{ 
		for (var i = 0; i < radio.length; i++)
		{			
			if (radio[i].checked)
			{
				nCount++; 
			}
		}
	}
	else 
	{
		if (radio.checked)
		{
			nCount++; 
		}
	}
	return nCount;
}	

function CountElements(element)
{
	var nCount = 0;  

	if (!isEmpty(element.length)) 
	{
		nCount = element.length; 
	}
	else 
	{
		nCount = 1;
	}
	return nCount;
}		

function limitEntry(e, allow)
{
	var key;
	var keychar;

	if (window.event)
	{
		key = window.event.keyCode;
	}
	else if (e)
	{
		key = e.which;
	}
	else
	{
		return true;
	}
		
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
	{
		return true;
	}
	else if (((allow).indexOf(keychar) > -1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function openWindow(sWindowName, sURL, nWidth, nHeight, nLeft, nTop, bToolbar, bLocation, bDirectories, bStatus, bMenubar, bScrollBars, bResizable, bSetFocus) 
{
	var sWindowAttributes = "toolbar=" + (bToolbar ? "yes" : "no");
	sWindowAttributes += ",location=" + (bLocation ? "yes" : "no");
	sWindowAttributes += ",directories=" + (bDirectories ? "yes" : "no"); 
	sWindowAttributes += ",status=" + (bStatus ? "yes" : "no");	
	sWindowAttributes += ",menubar=" + (bMenubar ? "yes" : "no");
	sWindowAttributes += ",scrollbars=" + (bScrollBars ? "yes" : "no");	
	sWindowAttributes += ",resizable=" + (bResizable ? "yes" : "no");								
	sWindowAttributes += ",height=" + ((nHeight > 0) ? nHeight : (screen.availHeight));
	sWindowAttributes += ",width=" + ((nWidth > 0) ? nWidth : (screen.availWidth));
	sWindowAttributes += ",left=" + ((nLeft > 0) ? nLeft : ((screen.availWidth - nWidth)/2));
	sWindowAttributes += ",top=" + ((nTop > 0) ? nTop : ((screen.availHeight - nHeight)/2));

	var win = window.open(sURL, sWindowName, sWindowAttributes);
	win.opener = self;

	if (bSetFocus)
	{
		win.focus();
	}
}

function swapImages(imageIndex, imageName)
{
	if (is_nav4up || is_ie5up)
	{
		if ((document[imageName]) && (imageArray[imageIndex]))
		{
			document[imageName].src = imageArray[imageIndex].src;
		}
	}
}

function hideLayer(objLayer)
{
	if (objLayer)
	{
		if (objLayer.className != 'Hidden')
		{
			objLayer.className = 'Hidden';
		}
	}
}

function showLayer(objLayer)
{
	if (objLayer)
	{
		if (objLayer.className == 'Hidden')
		{
			objLayer.className = '';
		}
	}
}

function element_setClass(sElement, sClassName)
{
	$id(sElement).className = sClassName;
}

function getViewportHeight() 
{
	var offset = 0;
	
	if (window.innerHeight != window.undefined) 
	{
		return window.innerHeight - offset;
	}
	
	if (document.compatMode == 'CSS1Compat') 
	{
		return document.documentElement.clientHeight;
	}
	
	if (document.body) 
	{
		return document.body.clientHeight; 
	}
	
	return window.undefined; 
}

function getViewportWidth() 
{
	var offset = 0;
	
	if (window.innerWidth != window.undefined) 
	{
		return window.innerWidth - offset;
	}
			 
	if (document.compatMode == 'CSS1Compat') 
	{
		return document.documentElement.clientWidth;
	}
	 
	if (document.body) 
	{
		return document.body.clientWidth; 
	}
}

function getScrollTop() 
{
	if (self.pageYOffset) 
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		return document.body.scrollTop;
	}
}

function getScrollLeft() 
{
	if (self.pageXOffset)
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body)
	{
		return document.body.scrollLeft;
	}
}

function addEvent(o, eventType, handler)
{
	if (o.addEventListener)
	{
		o.addEventListener(eventType, handler, false);
		return true;
	} 
	else if (o.attachEvent)
	{
		var r = o.attachEvent("on" + eventType, handler);
		return r;
	} 
	else 
	{
		return false;
	}
}

function removeEvent(o, eventType, handler, useCapture)
{
	if (o.removeEventListener)
	{
		o.removeEventListener(eventType, handler, useCapture);
		return true;
	} 
	else if (o.detachEvent)
	{
		var r = obj.detachEvent("on" + eventType, handler);
		return r;
	} 
	else 
	{
		//alert("Handler could not be removed");
		return false;
	}
}

String.format = function()
{
    if (arguments.length == 0)
	{
        return null;
	}
 
    var s = arguments[0];

    for (var i = 1; i < arguments.length; i++)
    {
        s = s.replace(new RegExp("\\{" + (i - 1) + "\\}", "gm"), arguments[i]);

    }
    
    return s;
}

function buildAddress(address, city, state, zip)
{
	return formatAddress(address, city, state, zip, ", ");
}

function buildDisplayAddress(address, city, state, zip)
{
	return formatAddress(address, city, state, zip, "<br />");
}

function formatAddress(address, city, state, zip, seperator)
{
	var csz = "";
	var addressFormatted = "";

	if (location)
	{
		addressFormatted += ((address != null) && (address.length > 0)) ? address : "";
		csz += ((city != null) && (city.length > 0)) ? city : "";
		
		if ((state != null) && (state.length > 0))
		{
			csz += ((csz.length > 0) ? ", " : "") + state;
		}
		
		if ((zip != null) && (zip.length > 0))
		{
			csz += ((csz.length > 0) ? " " : "") + zip;
		}
		
		if ((addressFormatted.length > 0) && (csz.length > 0))
		{
			addressFormatted += seperator + csz;
		}
		else
		{
			addressFormatted += csz;
		}
	}
	
	return addressFormatted;
}
//-->