/*
 * *********************************************************************************************
 *  CampVision 2.1.0 
 *  Copyright ©2002-2004 Manage Forward, LLC. All rights reserved. 
 *   
 *  This file may not be redistributed in whole or significant part. 
 *  Please see the included license.txt file for details on usage guidlines 
 * *********************************************************************************************
 */

/* *******************************************************************************************
 * START Base Functions
 * ******************************************************************************************/

/*
 * Confirm that a delete should be occuring
 */

function confirmDelete(URL, Message){

	var Confirm = window.prompt(Message + "\n Enter Yes or No");

	if(Confirm.toLowerCase() == "yes"){
	
		window.location=URL;
	}
}

/*
function confirmDelete() {
	return confirm('Are you sure you wish to delete?');
}
*/


/*
 * Open a new window
 */
function newWindow(file,window,properties,TargetField,TargetDiv) {
	allowExit();
	if (properties=='') properties = 'resizable=yes,scrollbars=yes,width=600,height=450';
	msgWindow=open(file,window,properties);
	if (msgWindow.opener == null) msgWindow.opener = self;
	if (document.forms[0]) {
		if (document.forms[0].elements['TargetField'] && document.forms[0].elements['TargetDiv']) {
			document.forms[0].TargetField.value=TargetField;
			document.forms[0].TargetDiv.value=TargetDiv;
		}
	}
}

/*
 * Set an Id
 */
function setId(EntityId,NameText,TargetField,TargetDiv){

	if (window.opener) {
		if (TargetField.length>0) {
			opener.document.forms[0].elements[TargetField].value = EntityId;
		}
		if (TargetDiv.length>0) {
			opener.document.getElementById(TargetDiv).innerHTML = NameText;
		}
		window.close();
	}
}

/*
 * Sorts a <select>
 */
function sortSelect(slect) {
    var nIndex = slect.selectedIndex;
    var optionsArray = new Array();
    for (var i = 0; i < slect.options.length; i++) {
        optionsArray[i] = {
            'text':slect.options[i].text,
            'value':slect.options[i].value
        };
    }
    optionsArray.sort(sortOptionText);
    slect.length = 0;
    for (var i = 0; i < optionsArray.length; i++) {
        slect.options[i] = new Option(optionsArray[i].text,optionsArray[i].value);
    } slect.selectedIndex = nIndex;
}

/*
 * Sorts a <select> backwards
 */
function sortSelectReverse(slect) {
    var nIndex = slect.selectedIndex;
    var optionsArray = new Array();
    for (var i = 0; i < slect.options.length; i++) {
        optionsArray[i] = {
            'text':slect.options[i].text,
            'value':slect.options[i].value
        };
    }
    optionsArray.reverse(sortOptionText);
    slect.length = 0;
    for (var i = 0; i < optionsArray.length; i++) {
        slect.options[i] = new Option(optionsArray[i].text,optionsArray[i].value);
    } slect.selectedIndex = nIndex;
}

function sortOptionText(a, b) {
    if (a.text < b.text) return -1;
    else if (a.text > b.text) return 1;
    else return 0;
}

/*
 * Removes selected items from a <SELECT>
 */
function removeFromSelect(slect) {
   for(i=0; i < slect.length; i++) {
      if(slect.options[i].selected) {
         slect.options[i] = null;
         i--;
      }
   }
}

/*
 * Moves selected items from a <SELECT> to another <SELECT>
 */
function moveSelectItems(from, to) {
   for(i=0; i < from.length; i++) {
      if(from.options[i].selected) {
	    to.length++; 
             to.options[to.length-1].value = from.options[i].value;
	    to.options[to.length-1].text = from.options[i].text;
       }
   }
   removeFromSelect(from);
   sortSelect(to);
}

/*
 * Selects all the items in a <SELECT> tag
 */
function selectAllItems(slect,hiddenfield) {
    var substringValue = "";
    for (var i = 0; i < slect.length; i++) {
        substringValue = substringValue + slect.options[i].value + ",";
    }
    hiddenfield.value = substringValue.substr(0,(substringValue.length-1));
}

function toggleSelectOption(selectElement) {
	if (selectElement.value == "on") {
		selectElement.value="off"
	} else {
		selectElement.value="on"
	}
}

function setCookie(name, value) {

	var curCookie = name + "=" + escape(value) +
	("; expires=" + "Fri, 01 Jan 2010 06:00:00 GMT");
	document.cookie = curCookie;

}

function setCookieGroup(name, value, group) {

	var prevCookie;
	prevCookie = getCookie(group);
	
	if (prevCookie==null) {
	
		var begin = -1;
		
	} else {
	
		var begin = prevCookie.indexOf("*" + escape(name));
	
	}

	if (begin == -1) {
	
		var curCookie = group + "=" + prevCookie + "*" + escape(name) + "@" + escape(value) + ("; expires=" + "Fri, 01 Jan 2010 06:00:00 GMT");
		document.cookie = curCookie;

	} else {
	
		var end = prevCookie.indexOf("*", begin+1);

		if (end == -1)
			end = prevCookie.length;
		
			var curCookie = group + "=" + prevCookie.substring(0,begin) + "*" + escape(name) + "@" + escape(value) + "*" + prevCookie.substring(end+1,prevCookie.length) + ("; expires=" + "Fri, 01 Jan 2010 06:00:00 GMT");
		document.cookie = curCookie;

	}

}


function getCookieGroup(name, group) {

	var prevCookie;
	prevCookie = getCookie(group);
	
	if (prevCookie==null) {
	
		return "";
		
	} else {
	
		var begin = prevCookie.indexOf("*" + escape(name));
		
		if (begin == -1) {
		
			return "";
			
		} else {

			var beginValue = prevCookie.indexOf("@", begin+1);
			var end = prevCookie.indexOf("*", begin+1);

			if (end == -1)
				end = prevCookie.length;

			var cookieValue = prevCookie.substring(beginValue+1,end);

			return cookieValue;
		}
	}

}

function getCookie(name) {

	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
		} else
		begin += 2;

	var end = document.cookie.indexOf(";", begin);

	if (end == -1)
		end = dc.length;

	return unescape(dc.substring(begin + prefix.length, end));
}

function displayDivFromCookie(divName, defaultStyle, cookieGroup) {

	var savedValue;
	savedValue = getCookieGroup("Display"+divName, cookieGroup);

	if(savedValue>"") {
		document.getElementById(divName).style.display = savedValue;
	} else {
		document.getElementById(divName).style.display = defaultStyle;
	}

}

function changeVisibility(divName, cookieGroup){

	if (document.getElementById(divName).style.display == "block") {
		setCookieGroup("Display"+divName, "none", cookieGroup);
		document.getElementById(divName).style.display = "none";
	} else {
		setCookieGroup("Display"+divName, "block", cookieGroup);
		document.getElementById(divName).style.display = "block";
	}

}

function changeProfileVisibility(divNameToHide, divNameToShow, cookieGroup){

	setCookieGroup("Display"+divNameToHide, "none", cookieGroup);
	document.getElementById(divNameToHide).style.display = "none";
	
	setCookieGroup("Display"+divNameToShow, "block", cookieGroup);
	document.getElementById(divNameToShow).style.display = "block";

}

function singleCheckbox(x){
	if(x.checked){
	
		for(var i=0;i<x.form.elements[x.name].length;i++){
			x.form.elements[x.name][i].checked=false;
		}
		x.checked=true;
	}
}

function divVisible(divName, divCount, divOnNumber) {

	var i;

	for (i=0;i<divCount;i++) {
		document.getElementById(divName + i).style.display = "none";
	}

	document.getElementById(divName + divOnNumber).style.display = "block";
}

function highLightRowClick (row, classOn, classOff) {

	if (row.className==classOn) {
		row.className = classOff;
	} else {
		row.className = classOn;
	}

}

function highLightRowMouseover (row, classOn, classClicked) {

	if (row.className!=classClicked) {
		row.className = classOn;
	}
}

/* Handle the pressing of the enter key on fields */

function keyHandler (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
} 

function checkExitWithoutSaving() {

	if (navigator.appName=="Microsoft Internet Explorer") {

		if (document.okToExit == false) {
			msg = "----------------------------------------------------------\n";
			msg += "Your form has not been saved.\n";
			msg += "----------------------------------------------------------";
			event.returnValue = msg;
		} else {
			return true;
		}
	}
	
}

function stopExitWithoutSaving() {
	document.okToExit = false;
}

function allowExit() {
	document.okToExit = true;
}


/* *******************************************************************************************
 * END Base Functions
 * ******************************************************************************************/

/* *******************************************************************************************
 * START Functions for MD5 Implementation
 * ******************************************************************************************/

/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/* 
 * Perform a simple self-test to see if the VM is working 
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;
  
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
 
    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);
  
}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++) 
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

/* *******************************************************************************************
 * END Functions for MD5 Implementation
 * ******************************************************************************************/


/* *******************************************************************************************
 * START Functions for Entity
 * ******************************************************************************************/

/*
 * Validate an email address
 */
function emailCheck (emailStr,emailType) {

	if (emailStr.length == 0) {
	
		return "\n" + emailType + " Email is required";
	
	}

	var emailPat=/(.+)@(.+)/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		return "\n" + emailType + " Email address seems incorrect (check @ and .'s)";
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		return "\n" + emailType + " Email username doesn't seem to be valid.";
	}

	var IPArray=domain.match(ipDomainPat);

	if (IPArray!=null) {
		for (var i=1;i<=4;i++){
			if (IPArray[i]>255) {
				return "\n" + emailType + " Email Destination IP address is invalid.";
			}
		}
	}

	var domainArray=domain.match(domainPat)

	if (domainArray==null) {
		return "\n" + emailType + " Email domain name doesn't seem to be valid.";
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;

	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		return "\n" + emailType + " Email address must end in a three-letter domain, or two letter country.";
	}

	if (len<2) {
		return "\n" + emailType + " Email address is missing a hostname.";
	}

	return "";
}  

/* *******************************************************************************************
 * END Functions for Entity
 * ******************************************************************************************/

/* *******************************************************************************************
 * START Functions for Contracts
 * ******************************************************************************************/


/*
 * Takes a number and rounds to a currency value
 */

function toCurrency(num) {

  num = cent(Math.round(num*100)/100);

  return num.toString();

}

function cent(amount) {
	return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10== Math.floor(amount*10)) ? amount + '0' : amount);
}

/*
 * Adds additional certification fields to the form.
 */

var counter = 0;

function moreFields(startCounter)
{
	counter++;
	var tempCounter = (Number(counter) + Number(startCounter));
		
	var field = "ContractCertificationCount";
	
	document.getElementsByName(field)[0].value = "";
	document.getElementsByName(field)[0].value = tempCounter;
		
	var newFields = document.getElementById('readroot').cloneNode(true);
	newFields.id = '';
	newFields.style.display = 'block';
	var newField = newFields.childNodes;
	for (var i=0;i<newField.length;i++)
	{
		var theName = newField[i].name
		if (theName)
			newField[i].name = theName + tempCounter;
			
	}
	var insertHere = document.getElementById('writeroot');
	insertHere.parentNode.insertBefore(newFields,insertHere);
}

/*
 * used to remove certification fields and calculate the total
 */

function removeFields(formName, currentField, fieldName)
{

	currentField.parentNode.parentNode.removeChild(currentField.parentNode);
	
	calcTotalCertificationPay(formName, fieldName);
}

/*
 * Calculate the total time at the camp based on the ContractStartDate and the ContractEndDate
 */
function calcTotalDays(startDate, endDate, fieldName) {

	var strError = "";

	if (isDate(startDate)==false ) {
		strError = strError + "Invalid Start Date \n";
	}

	if (isDate(endDate)==false ) {
		strError = strError + "Invalid End Date";
	}

	if (strError.length > 0) {		
		alert(strError);
		return;
	}

	fieldName.value = calcDaysBetween(startDate, endDate);

}

function calcDaysBetween(startDate, endDate) {

	if (isDate(startDate)==false ) {
		return 0;
	}

	if (isDate(endDate)==false ) {
		return 0;
	}
	
	dateStartDate = new Date(startDate);
	dateEndDate = new Date(endDate);
	
	if (dateStartDate<dateEndDate) {

		return calcDateDiff(startDate, endDate);
		
	} else {

		return 0 - calcDateDiff(startDate, endDate);
	
	}

}


/*
 * Calculate the total number of nights based on the ContractStartDate and the ContractEndDate
 */
function calcTotalNights(startDate, endDate, fieldName) {

	var strError = "";

	if (isDate(startDate)==false ) {
		strError = strError + "Invalid Start Date \n";
	}

	if (isDate(endDate)==false ) {
		strError = strError + "Invalid End Date";
	}

	if (strError.length > 0) {
		alert(strError);
		return;
	}

	fieldName.value = (calcDateDiff(startDate, endDate) - 1);

}

/*
 * Calculates the total for Room and Board
 */
function calcRoomAndBoardTotal(rabNights, rabRate, fieldName) {

	var strError = "";

	//Strip out the $ if they decided to put that in
	rabNights = makeNumeric(rabNights);
	rabRate = makeNumeric(rabRate);

	if (rabNights.length == 0) {
		strError = strError + "Room And Board Rate must be entered \n";
	}

	if (rabRate.length == 0) {
		strError = strError + "Room And Board Rate must be entered";
	}

	if (strError.length > 0) {
		alert(strError);
		return;
	}

	//Multiply the values to get the total
	fieldName.value = toCurrency(Number(rabNights) * Number(rabRate));

	return;

}

/*
 * Calculates total compensation based on input passed in
 */
function calcTotalCompensation(strSalary,strTravel,strAgencyFee,strBonus, strCertifications, fieldName) {

	var strError = "";

	//Strip out the $ if they decided to put that in
	strSalary = makeNumeric(strSalary);
	strTravel = makeNumeric(strTravel);
	strAgencyFee = makeNumeric(strAgencyFee);
	strBonus = makeNumeric(strBonus);
	strCertifications = makeNumeric(strCertifications);

	if (strSalary.length == 0) {
		strError = strError + "Salary must be entered \n";
	}

	if (strError.length > 0) {
		alert(strError);
		return;
	}

	//If any of the fields do not have any data, set it to 0
	if (strTravel.length == 0) { strTravel = "0"; }
	if (strAgencyFee.length == 0) { strAgencyFee = "0"; }
	if (strBonus.length == 0) { strBonus = "0"; }
	if (strCertifications.length == 0) { strCertifications = "0"; }

	fieldName.value = toCurrency((Number(strSalary) + Number(strTravel) + Number(strAgencyFee) + Number(strBonus) + Number(strCertifications)));

	return;

}

/*
 * Calculates total compensation per day based on input passed in
 */
function calcTotalCashCompensationPerDay(strTotalDays,strTotalCashCompensation, fieldName) {

	var strError = "";

	//Strip out the $ if they decided to put that in
	strTotalCashCompensation = makeNumeric(strTotalCashCompensation);

	if (strTotalDays.length == 0) {
		strError = strError + "Total Days must be entered \n";
	}

	if (strTotalCashCompensation.length == 0) {
		strError = strError + "Total Cash Compensation must be entered \n";
	}

	if (strError.length > 0) {
		alert(strError);
		return;
	}

	fieldName.value = toCurrency((Number(strTotalCashCompensation)/Number(strTotalDays)));

	return;

}

/*
 * Calculates gross compensation
 */
function calcGrossCompensation(strCashCompensation,strRoomAndBoardTotal,fieldName) {

	var strError = "";

	//Strip out the $ if they decided to put that in
	strCashCompensation = makeNumeric(strCashCompensation);
	strRoomAndBoardTotal = makeNumeric(strRoomAndBoardTotal);

	if (strCashCompensation.length == 0) {
		strError = strError + "Cash Compensation must be entered \n";
	}

	if (strError.length > 0) {
		alert(strError);
		return;
	}

	//If any of the fields do not have any data, set it to 0
	if (strRoomAndBoardTotal.length == 0) { strRoomAndBoardTotal = "0"; }

	fieldName.value = toCurrency(Number(strCashCompensation) + Number(strRoomAndBoardTotal));

	return;

}

/*
 * Calculates total certification pay
 */
function calcTotalCertificationPay(formName, fieldName) {

	var strError = "";
	var total = 0;
	
	for (var e = 0; e < formName.elements.length; e++)
	{
		var currentElement = formName.elements[e].name;
		
		if (currentElement.substring(0, (currentElement.length - 1)) == "ContractCertificationPay"){
		
			var currentValue = formName.elements[e].value;
			
			total = toCurrency(Number(total) + Number(currentValue));
			
		}		
	}

	fieldName.value = Number(total);

	return;

}

/* *******************************************************************************************
 * END Functions for Contracts
 * ******************************************************************************************/


/* *******************************************************************************************
 * START Functions for Reporting
 * ******************************************************************************************/
function nudge(list,direction) {

  var length = list.length;
  var temp = new Object();


  if (direction == 'up') {
    for (var i = 0; i < length; i++) {
      if (list[i].selected) {
        for (var n = 0; n < length; n++) {
          if (n == i) {
            if (n > 0) {
              swapListItems(list,n,(n - 1));
            }
          }
        }
      }
    }
  } else if (direction == 'down') {
    for (var i = (length - 1); i > -1; i--) {
      if (list[i].selected) {
        for (var n = 0; n < length; n++) {
          if (n == i) {
            if (n < (length - 1)) {
              swapListItems(list,n,(n + 1));
            }
          }
        }
      }
    }
  } else if (direction == 'top') {
    for (var i = 0; i < length; i++) {
      if (list[i].selected) {
        for (var n = 0; n < length; n++) {
          if (n == i) {
            if (n > 0) {
              for (var q = 0; q < i; q++) {
                swapListItems(list,(n-q),((n - 1) - q));
              }
            }
          }
        }
      }
    }
  } else if (direction == 'bottom') {
    for (var i = (length - 1); i > -1; i--) {
      if (list[i].selected) {
        for (var n = 0; n < length; n++) {
          if (n == i) {
            if (n < (length - 1)) {
              for (var q = 0; q < length-i-1; q++) {
                swapListItems(list,(n+q),((n + 1) + q));
              }
            }
          }
        }
      }
    }
  } else if (direction == 'reverse') {
  
    sortSelectReverse(list);
  
  } else { 
    sortSelect(list);
  }
}

function swapListItems(list,a,b) { // swaps item a and b in the given form
	var temp = new Object;

	temp.value = list[b].value;
	temp.text = list[b].text;
	temp.selected = list[b].selected;

	list[b].value = list[a].value;
	list[b].text = list[a].text;
	list[b].selected = list[a].selected;

	list[a].value = temp.value;
	list[a].text = temp.text;
	list[a].selected = temp.selected;
}
/* *******************************************************************************************
 * END Functions for Reporting
 * ******************************************************************************************/

function isNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}

	return IsNumber;

}

function makeNumeric(sText) {

	if(isNaN(sText)) {
		return 0;
	}

	if(isNumeric(sText)) {
		return parseFloat(sText);
	}

	var ValidChars = "0123456789.";
	var Char;
	var sNumber = "";

	for (i = 0; i < sText.length; i++) { 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) >= 0) {
		
			sNumber = sNumber + Char;
		}
	}
	
	if(isNaN(parseFloat(sNumber))) {
		return 0;
	} else {
	 	return parseFloat(sNumber);
	}

}

function makeAlpha(sText) {

	var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var Char;
	var sNewText = "";

	for (i = 0; i < sText.length; i++) { 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) >= 0) {
		
			sNewText = sNewText + Char;
		}
	}
	
	return sNewText;

}

function getRadioValue(radioButton) {
	myOption = -1;
	for (i=0; i<radioButton.length; i++) {
		if (radioButton[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		return '';
	}

	return radioButton[myOption].value;
}

function isArray(obj) {
  if(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
  } else {
    return false;
  }
}

/* *******************************************************************************************
 * START Functions for Events
 * ******************************************************************************************/

/*
 * linked list box control and fee control
 */

function selectChange(control, controlToPopulate, capacityDiv, ItemArray, GroupArray, IdArray){

	document.getElementById(capacityDiv).style.display="none";
	// Empty the second drop down box of any choices
	for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;

	if (control.value == ""){
		return;
	}
	
	//show the correct fee check boxes
	showDiv(control);

	//update any activity select boxes that conflict 
	if (typeof EventActivitySelectLastSelectId != "undefined") {
		selectStatus(control);
	}

	var myEle ;
	var x ;

	// Now loop through the array of individual items
	// Any containing the same child id are added to
	// the second dropdown box
	if (control.value>0) {

		for ( x = 0 ; x < ItemArray.length  ; x++ ){
			if ( GroupArray[x] == control.value ){

				// set the no value option
				myEle = document.createElement('option');
				controlToPopulate.appendChild(myEle); 
				myEle.text=ItemArray[x]; 
				myEle.value=IdArray[x];

			}
		}

	}

	if (!myEle){
		document.getElementById(capacityDiv).style.display="none";
	}else{
		document.getElementById(capacityDiv).style.display="block";
	}
  
}



/*
 * linked list box control and fee control
 */

function selectChangeActivity(control, controlToPopulate, capacityDiv, ItemArray, GroupArray, IdArray){

	document.getElementById(capacityDiv).style.display="none";
	// Empty the second drop down box of any choices
	for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;

	if (control.value == ""){
		return;
	}

	var eventId = control.options[control.selectedIndex].value;
	
	//show the correct fee check boxes
	showDiv(control);

	//update any activity select boxes that conflict 
	if (typeof EventActivitySelectLastSelectId != "undefined") {
		selectStatus(control);
	}

	if (eventId==0) {
		document.getElementById(capacityDiv).style.display="none";
	} else {

		var myEle ;
		var x ;

		// Now loop through the array of individual items
		// Any containing the same child id are added to
		// the second dropdown box

		controlToPopulate.options.length = 0;

		if (control.value>0) {

			for ( x = 1 ; x < ItemArray[eventId].length  ; x++ ){
				if ( GroupArray[eventId][x] == control.value ){

					// set the no value option
					myEle = document.createElement('option');
					controlToPopulate.appendChild(myEle); 
					myEle.text=ItemArray[eventId][x]; 
					myEle.value=IdArray[eventId][x];

				}
			}

		}
		

		if (!myEle){
			document.getElementById(capacityDiv).style.display="none";
		}else{
			document.getElementById(capacityDiv).style.display="block";
		}

  
	}
}





/*
 * Hiddes all divs and displays the correct one
 */

function showDiv(control){
	
	a = control.options.length;
	c = control.options[control.selectedIndex].value;

	for (i=0;i<a;i++) {
		b = control.options[i].value;
		if (document.getElementById(b) != null) {
			document.getElementById(b).style.display = "none";
		}
	}

	if (control.value!="select") {
		if (document.getElementById(c) != null) {
			document.getElementById(c).style.display = "block";
		}
	}
}

/*
 * Updates the select box disables enables status based on time conflicts from the selected select box event.
 */
 
function selectStatus(control){

	//get the selected event activity Id

	var eventId = control.options[control.selectedIndex].value;

	//loop the array to find the previously selected value.
	for ( x = 0 ; x < EventActivitySelectLastSelectId.length  ; x++ ){

		if (EventActivitySelectLastSelectId[x] == control.name){

			var lastSelectedId = EventActivitySelectLastSelectedEventId[x];
			
			//set the array to the currently select Id
			EventActivitySelectLastSelectedEventId[x] = eventId;

		}
	}

	//we only have to loop the selects to re-enable them if the last selected Id is greater than 0
	if (lastSelectedId > 0){

		//loop the array to get the last selected event start and end date
		for ( x = 1 ; x < EventActivityIdArray.length  ; x++ ){

			if (EventActivityIdArray[x] == lastSelectedId){

				var controlStartDate 	= EventActivityStartDateArray[x];
				var controlStartTime	= EventActivityStartTimeArray[x];
				var controlEndDate	= EventActivityEndDateArray[x];
				var controlEndTime	= EventActivityEndTimeArray[x];
			}
		}

		//loop the array looking for events that conflict the last selected times
		for ( x = 1 ; x < EventActivityStartDateArray.length  ; x++ ){
				// is the start date inbetween the control start and end dates?																							is the end date between the control start and end date?																							the event start date and end date overlap the conrol dates
			if (((new Date(EventActivityStartDateArray[x]) >= new Date(controlStartDate)) && (new Date(EventActivityStartDateArray[x]) < new Date(controlEndDate))) || ((new Date(EventActivityEndDateArray[x]) > new Date(controlStartDate)) && (new Date(EventActivityEndDateArray[x]) <= new Date(controlEndDate))) || ((new Date(EventActivityStartDateArray[x]) < new Date(controlStartDate)) && (new Date(EventActivityEndDateArray[x]) > new Date(controlEndDate)))){
			
				//check for time conflicts
				var i = 0;
				if (((EventActivityStartTimeArray[x] - controlStartTime) >= 0)	&& ((controlEndTime - EventActivityStartTimeArray[x]) > 0)){
					i = 1;
				}


				if (((EventActivityEndTimeArray[x] - controlStartTime) >  0) &&	((controlEndTime - EventActivityEndTimeArray[x]) >= 0)){
					i = 1;
				}

				if (((controlStartTime - EventActivityStartTimeArray[x]) > 0) && ((EventActivityEndTimeArray[x] - controlEndTime) > 0)){
					i = 1;
				}
			
				if (i == 1){

					//enable the select that conflicts as this is option is no longer selected
					document.forms['eventregistrationeventinsert'].elements[EventActivitySelectIdArray[x]].disabled = false;

					//clear the div title
					document.getElementById(EventActivitySelectIdArray[x]).title = "";
				}
			}
		}


	}//end if
	
	var controlName = control.name

	//call the function to disable the selects
	selectDisable(eventId, controlName);
}

/*
 *this function compaires event times and disables any selects that conflict.
 */

function selectDisable(eventId, controlName){

	//loop the array to get that event start and end date
	for ( x = 0 ; x < EventActivityIdArray.length  ; x++ ){

		if (EventActivityIdArray[x] == eventId){
			
			var eventIndex = x;
			var controlStartDate 	= EventActivityStartDateArray[x];
			var controlStartTime	= EventActivityStartTimeArray[x];
			var controlEndDate	= EventActivityEndDateArray[x];
			var controlEndTime	= EventActivityEndTimeArray[x];
		}
	}

	//loop the array looking for events that conflict with those times
	for ( x = 0 ; x < EventActivityStartDateArray.length  ; x++ ){

		if (((new Date(EventActivityStartDateArray[x]) >= new Date(controlStartDate)) && (new Date(EventActivityStartDateArray[x]) < new Date(controlEndDate))) || ((new Date(EventActivityEndDateArray[x]) > new Date(controlStartDate)) && (new Date(EventActivityEndDateArray[x]) <=	 new Date(controlEndDate))) || ((new Date(EventActivityStartDateArray[x]) < new Date(controlStartDate)) && (new Date(EventActivityEndDateArray[x]) > new Date(controlEndDate)))){
		
			var i = 0;
			if (((EventActivityStartTimeArray[x] - controlStartTime) > 0)	&& ((controlEndTime - EventActivityStartTimeArray[x]) > 0)){
				i = 1;
			}


			if (((EventActivityEndTimeArray[x] - controlStartTime) >  0) &&	((controlEndTime - EventActivityEndTimeArray[x]) > 0)){
				i = 1;
			}

			if (((controlStartTime - EventActivityStartTimeArray[x]) > 0) && ((EventActivityEndTimeArray[x] - controlEndTime) > 0)){
				i = 1;
			}
		
			if (i == 1){
			
		
				if (EventActivitySelectIdArray[x] != controlName){

					//disable the select that conflicts
					document.forms['eventregistrationeventinsert'].elements[EventActivitySelectIdArray[x]].disabled = true;

					//set the div title to the event name that caused the disable
					document.getElementById(EventActivitySelectIdArray[x]).title = EventActivityDisableMessage[eventIndex];
				}
			}
		}
	}


}
/*
 *this function is called on page load to disable any selects that conflict with the defaulted selects from the db
 */

function onLoadSelectDisable(){

	var loopCounter = 1;
	for ( loopCounter=1 ; loopCounter < EventActivitySelectLastSelectedEventId.length ; loopCounter++ ){
		if (EventActivitySelectLastSelectedEventId[loopCounter] != 0){
			selectDisable(EventActivitySelectLastSelectedEventId[loopCounter], EventActivitySelectLastSelectId[loopCounter]);
		}
	}

}

function countSelectedOptions (select) {
	var c = 0;

	for (var i = 0; i < select.options.length; i++) {
		if (select.options[i].selected) {
			c++;
		}
	}

	return c;
}

/*
 * Moves selected items from a <SELECT> to another <SELECT>
 * This specific function also deals with increasing or decreasing
 * a current capacity count
 */
function moveHousingCapacityItems(from, to, addsubtract, EventHousingCapacityId, EventHousingCapacityEntityTypeId, ParticipantArray, ErrorArray) {
		
	var iSelected = 0;
	var currentCapacity = makeNumeric(document.getElementById(EventHousingCapacityId).innerHTML);
	var field = "EventHousingCapacityMin" + EventHousingCapacityId;
	var minCapacity = makeNumeric(document.getElementsByName(field)[0].value);
	var field = "EventHousingCapacityMax" + EventHousingCapacityId;
	var maxCapacity = makeNumeric(document.getElementsByName(field)[0].value);

	var selectedCount = (countSelectedOptions(from));
	
	for(i=0; i < from.length; i++) {

		if(from.options[i].selected) {

			iSelected++;

			var correctType;
			if (addsubtract == '+'){
				
				if (EventHousingCapacityEntityTypeId != ""){
				
					var selectValue = from.options[i].value;

					for (var i = 0 ; i < EventParticipantId.length ; i++){

						if (EventParticipantId[i] == selectValue){
							var index = i;
						}
					}

					var entityName	= EntityName[index];

					var currentParticipantArray = EventParticipantEntityType[index];
					for (var j = 0; j < currentParticipantArray.length; j++) {
						if (EventHousingCapacityEntityTypeId == currentParticipantArray[j].id){
							correctType = 1;
						}
					}

					if (correctType != 1){
						alert(entityName + " does not have the correct entity type for this capacity");
						return;
					}
				}
				
				if(document.eventhousingallocationupdate.processRuleCheckBox.checked){
					for (var j = 0; j < ParticipantArray.length; j++) {

						if (ParticipantArray[j] == selectValue){

							alert("Process rule error for " + entityName + "\n\n" + ErrorArray[j]);
							return;
						}
					}
				}
			}						
		}
	}
	

	if ((addsubtract == '+') && ((currentCapacity + selectedCount) > maxCapacity)) {
		alert ('Adding the selected participants would violate the maximum capacity.');
		return;
	} else if ((addsubtract == '-') && ((currentCapacity - selectedCount) < minCapacity)) {
		alert ('Removing the selected participants violates the minimum capacity.');
	}

	for(i=0; i < from.length; i++) {
		if(from.options[i].selected) {
			to.length++;
			to.options[to.length-1].value = from.options[i].value;
			to.options[to.length-1].text = from.options[i].text;

			if(addsubtract == '+') {
				document.getElementById(EventHousingCapacityId).value = "";
				document.getElementById(EventHousingCapacityId).value =  makeNumeric(currentCapacity) + makeNumeric(selectedCount);
				document.getElementById(EventHousingCapacityId).innerHTML = "";
				document.getElementById(EventHousingCapacityId).innerHTML = document.getElementById(EventHousingCapacityId).value;
			} else {
				if (currentCapacity > 0) {
					document.getElementById(EventHousingCapacityId).value = "";
					document.getElementById(EventHousingCapacityId).value =  makeNumeric(currentCapacity) - makeNumeric(selectedCount);
					document.getElementById(EventHousingCapacityId).innerHTML = "";
					document.getElementById(EventHousingCapacityId).innerHTML = document.getElementById(EventHousingCapacityId).value;
				}
			}
		}
	}

	removeFromSelect(from);
	sortSelect(to);

}

/*
 * gets an event participants entity data from js arrays and displays it to the user
 */
function getEntityInfo() {

	var participantInfo = "";

	for(c=0; c <= document.eventhousingallocationupdate.capacityCount.value; c++) {

		var controlName = "currentEventHousingAllocation" + c;

		var fieldLength = document.getElementsByName(controlName)[0].length;

		for(i=0; i < fieldLength; i++) {
			if(document.getElementsByName(controlName)[0].options[i].selected) {

				var selectValue = document.getElementsByName(controlName)[0].options[i].value;
				
				for (var t = 0 ; t < EventParticipantId.length ; t++){

					if (EventParticipantId[t] == selectValue){
						var index = t;
					}
				}

				//get the participant notes
				var notes = EventParticipantNotes[index];

				//get the participant age
				var age = EntityAge[index];
				
				//get the entity name
				var entityName	= EntityName[index];

				//get the participant birthday
				var bday = EntityBirthDate[index];

				//get the participant grade
				var grade = EntityGrade[index];

				//get the participant education
				var education = EducationDegreeGrantedTypeLongDesc[index];

				//get the entity id
				var EId = EntityId[index];

				//get the entity types
				var types = "";
				var currentParticipantArray = EventParticipantEntityType[index];
				for (var j = 0; j < currentParticipantArray.length; j++) {
					types = types + currentParticipantArray[j].text + "<br>";
				}

				//now that we have all the entity info put it into the div
				var tmpDivText ="	<table width='100%' border='0'>" +
						"		<tr>" +
						"			<td>" +
						"				<a href='entity.php?action=viewentity&EId=" + EId + "' target='_blank'><b>" + entityName + "</b></a><br>" +
						"			</td>" +
						"			<td rowspan='2' valign='top'>" +
						"				" + types +
						"			</td>" +
						"		</tr>" +
						"		<tr>" +
						"			<td valign='top'>" +
						"				<b>Age</b>: " + age + "<br>" +
						"				<b>Birthday</b>: " + bday + "<br>" +
						"				<b>Grade</b>: " + grade + "<br>" +
						"				<b>Education</b>: " + education + "<br>" +
						"			</td>" +
						"			<td >" +
						"			</td>" +
						"		</tr>" +
						"		<tr>" +
						"			<td colspan='2'>" +
						"				<b>Event Participant Notes:</b><br>" +
						"				" + notes + 
						"			</td>" +
						"		</tr>" +
						"	</table>";
						
				participantInfo = participantInfo + tmpDivText;

			}
		}
	}

	if (participantInfo == ""){
		participantInfo = "No participant(s) selected";
	}

	document.getElementById(0).innerHTML = "";
	document.getElementById(0).innerHTML = participantInfo;
 }
	 
function makeOption(text, id) {
   this.text = text;
   this.id = id;
}


/* *******************************************************************************************
 * END Functions for Events
 * ******************************************************************************************/

/* *******************************************************************************************
 * START Functions for Calendar
 * ******************************************************************************************/
// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
	closeHandler(cal);
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format) {

	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have some calendar created
		calendar.hide();                 // so we hide it first.
	} else {
		// first-time call, create the calendar.
		var cal = new Calendar(false, null, selected, closeHandler);
		// uncomment the following line to hide the week numbers
		// cal.weekNumbers = false;
		calendar = cal;                  // remember it in the global var
		cal.setRange(1900, 2070);        // min/max year allowed.
		cal.create();
	}
	
	calendar.setDateFormat(format);    // set the specified date format
	
	calendar.parseDate(el.value);      // try to parse the text in field
	calendar.sel = el;                 // inform it what input field we use
	calendar.showAtElement(el);        // show the calendar below it

	return false;
}

/* *******************************************************************************************
 * END Functions for Calendar
 * ******************************************************************************************/
