/*
All Code Copyright 2003 Matthew Knight for KVMGalore.com
-- If you steal this, you suck, because do you have any idea 
   how long it's taken me to write such a killer js library??
All Rights Reserved, blah blah blah.
*/

d = document;
l = (d.layers)?1:0; 
op = navigator.userAgent.toLowerCase().indexOf('opera')!=-1; // Opera ?

function switchImg(n,s) {
	if ( l && (document.layers.length>0) ) {
		for (i=0; i<d.layers.length; i++) {			
			if (d.layers[i].document.images[n]) {			
				d.layers[i].document.images[n].src = s;
			}
		}	
	} else {
		d.images[n].src = s;
	}
}

var preloaded = false;
function menuPreload() {
     if (document.images) {
          home_on = createImage("http://www.hsacfunding.com/images/home_on.gif");
          apply_on = createImage("http://www.hsacfunding.com/images/apply_on.gif");
          atty_on = createImage("http://www.hsacfunding.com/images/atty_on.gif");
          plaintiff_on = createImage("http://www.hsacfunding.com/images/plaintiff_on.gif");
          about_on = createImage("http://www.hsacfunding.com/images/about_on.gif");
          contact_on = createImage("http://www.hsacfunding.com/images/contact_on.gif");
          arrow_on = createImage("http://www.hsacfunding.com/images/arrow_on.gif");
          arrow_off = createImage("http://www.hsacfunding.com/images/shim.gif");
          preloaded = true;
     }
}

function createImage(loc) {
     if (document.images) {
          rslt = new Image();
          rslt.src = loc;
          return rslt;
     }
}

function hilite(o) {
var parEl = o.parentNode;
while (parEl && parEl.className != "unhilite") { parEl = parEl.parentNode ? parEl.parentNode : 0 }
if (parEl) parEl.className = "hilite";
}

function unhilite(o) {
var parEl = o.parentNode;
while (parEl && parEl.className != "hilite") { parEl = parEl.parentNode ? parEl.parentNode : 0 }
if (parEl) parEl.className = "unhilite";
}

win = false;
function pop(url,w,h) {
if ( (win) && (!win.closed) ) {
win.location = url;
win.focus();
} else {
win = window.open((url), 'popupwin', 'top=10,left=10,width='+w+',height='+h+',resizable=yes,toolbar=no,status=yes,scrollbars=yes');
win.focus();
}
}

function isEmpty(s) {
return ((s == null) || (s.length == 0));
}

function isDigit(c) {
return ((c >= "0") && (c <= "9"))
}

var whitespace = " \t\n\r";
function isWhitespace(s) {
    if (isEmpty(s)) return true;
    for (var i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

var digitsInZipCode = 5;
function isZip(s) {
	return ( isInteger(s) && (s.length == digitsInZipCode) );
}

var digitsInPhone = 10;
function isPhone(s) {
	return ( isInteger(s) && (s.length == digitsInPhone) );
}

function isInteger(s) {
	var isInt = true;
    if (!isEmpty(s)) { 
    	for (var i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        	if (!isDigit(c)) {
				isInt = false;
				break;
			}
		}
    } else {
		isInt = false;
	}
    return isInt;
}

function isMoney(s) {
	var isMoney = true;
	var founddot = 0;
    if (!isEmpty(s)) { 
    	for (var i = 0; i < s.length; i++) {   
        // Check that current character is number, or a dot, where only one dot can be found.
        var c = s.charAt(i);
			if (c == ".") {
				founddot++;
			} else if (!isDigit(c)) {
				isMoney = false;
				break;
			}
		}
    } else {
		isMoney = false;
	}
    return (founddot > 1 ? false : isMoney);
}

var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var dayofweek = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
function isDate(m,d,y) {
	m++; m--; // easy way to strip leading 0's
	var dateObj = new Date(y,m,d,0,0,0);
	var dateMonth = dateObj.getMonth();
	return (dateMonth==m);
}
function formatTime(dat) {
	var h = dat.getHours();
	var m = dat.getMinutes();
	var timStr = (h>12?h-12:h)+":"+(m<10?"0"+m:m)+" "+(h>=12?"pm":"am")
	return timStr;
}
function formatDate(dat) {
	var datStr = dayofweek[dat.getDay()]+", "+months[dat.getMonth()]+" "+dat.getDate()+", "+dat.getYear();
	return datStr;
}
function formatDateAndTime(dat) {
	return formatDate(dat)+" - "+formatTime(dat);
}
function isEmail (s) {
    if (isEmpty(s)) return false;   
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")) {
		i++;
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")) {
		i++;
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function getLeft(anchorstr) {
	var nLeftPos = 0;
	if (l) {
		var found=0;
		for (var i=0; i<d.anchors.length; i++) {
			if (d.anchors[i].name == anchorstr) {
				found=1;
				break;
			}
		}
		nLeftPos = ( found==0 ? 0 : d.anchors[i].x );
	} else {
		var e = gE(anchorstr);
	    var nLeftPos = e.offsetLeft;
	    var eParElement = e.offsetParent;
	    while (eParElement != null) {
	        nLeftPos += eParElement.offsetLeft;
	        eParElement = eParElement.offsetParent;
	    }
	}
    return nLeftPos;
}
function getTop(anchorstr) {
	var nTopPos = 0;
	if (l) {
		var found=0;
		for (var i=0; i<d.anchors.length; i++) {
			if (d.anchors[i].name == anchorstr) {
				found=1;
				break;
			}
		}
		nTopPos = ( found==0 ? 0 : d.anchors[i].y );
	} else {
		var e = gE(anchorstr);
	    var nTopPos = e.offsetTop;
	    var eParElement = e.offsetParent;
	    while (eParElement != null) {
	        nTopPos += eParElement.offsetTop;
	        eParElement = eParElement.offsetParent;
	    }
	}
    return nTopPos;
}
function gE(e,f){if(l){f=(f)?f:self;V=f.document.layers;if(V[e])return V[e];for(W=0;W<V.length;)return(gE(e,V[W++]));}if(d.all)return d.all[e];return d.getElementById(e);}
function sE(e){if(l)e.visibility='show';else e.style.visibility='visible';}
function hE(e){if(l)e.visibility='hide';else e.style.visibility='hidden';}
function sZ(e,z){if(l)e.zIndex=z;else e.style.zIndex=z;}
function sX(e,x){if(l)e.left=x;else if(op)e.style.pixelLeft=x;else e.style.left=x;}
function sY(e,y){if(l)e.top=y;else if(op)e.style.pixelTop=y;else e.style.top=y;}
function wH(e,h){if(l){Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}

function getCookie(n) {
var searchStr = n + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(searchStr);
		if (offset != -1) {
			offset +=searchStr.length;
			end = document.cookie.indexOf(";", offset);
			if (end==-1) {
				end=document.cookie.length;
			}
			return unescape(document.cookie.substring(offset,end));
		}
	} else {
		return false;
	}
}

function setCookie(n,v,e) {
document.cookie = n + "=" + escape(v) +
	((e == null) ? "" : ( "; expires=" + e.toGMTString() ));
}

function expiration(days) {
var expires = new Date();
var today = new Date();
expires.setTime( today.getTime() + (1000*60*60*24*parseInt(days)) );
return expires;
}