﻿//Handle the month lookups.  Does not account for leap year
var arrMonthLookup = {
                     '1' : {numDays : 31, abbr : 'Jan'},
                     '2' : {numDays : 29, abbr : 'Feb'},
                     '3' : {numDays : 31, abbr : 'Mar'},
                     '4' : {numDays : 30, abbr : 'Apr'},
                     '5' : {numDays : 31, abbr : 'May'},
                     '6' : {numDays : 30, abbr : 'Jun'},
                     '7' : {numDays : 31, abbr : 'Jul'},
                     '8' : {numDays : 31, abbr : 'Aug'},
                     '9' : {numDays : 30, abbr : 'Sep'},
                     '10' : {numDays : 31, abbr : 'Oct'},
                     '11' : {numDays : 30, abbr : 'Nov'},
                     '12' : {numDays : 31, abbr : 'Dec'}
                    };


function getGetThereSessionVariable() {
   return readCookie('GetThereSessionVariable') ? 
          readCookie('GetThereSessionVariable') :
          'NEWREC';
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


//Gets the cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//Prefix with zero..LZ = Leading Zero
function LZ(x){return(x<0||x>9?"":"0")+x}


function makeDefaultButton(event, buttonID)
{
    if (event.keyCode == '13')
    {
        //document.getElementById(buttonID).click(); // DOESN'T WORK IN FIREFOX
        event.returnValue = false;
        event.cancel = true;
    }
}

function validateEmail(str) 
{    
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 return true					
}

function textAreaLimit(taObj, maxL) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function textAreaCount(taObj,Cnt,maxL) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) objCnt.innerText=maxL-objVal.length;
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

