// JavaScript Document

/*------------------------------ GENERAL SCRIPTS -----------------------------------------*/

function checkZip(obj,assoc){
	if (obj.value=='' || obj.value=='Value Needed') return;
	var zip = obj.value.split('-')[0].replace(/[^\d]/g,'');
	obj.value=zip;
	if (zip.length!=5){
		alert('Not a valid zip code');
		obj.select();
		obj.focus();
		return;
	}
	if (document.regForm && document.regForm.Mentor_Pref[0].checked){
		var mpref='youth'
	} else if (document.regForm && document.regForm.Mentor_Pref[1].checked) {
		var mpref='adults'
	} else if (document.regForm2 && document.regForm2.i_am[0].checked) {
		var mpref='parent'
	} else if (document.regForm2 && document.regForm2.i_am[1].checked) {
		var mpref='adult'
	}
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	sendStr='act=12&zip='+zip+'&assoc=' + assoc+'&mentor_pref='+mpref
	srvrConnect.send(sendStr);
	if (srvrConnect.responseText.indexOf('OK')!=-1) {
		document.getElementById('zipResponse').innerHTML='';
	} else {
		obj.value='';
		document.getElementById('zipResponse').innerHTML=srvrConnect.responseText;
		obj.focus();
	}
	
}
function confEmail(obj){
		if (obj.value=='') {
			alert('Email address may not be left blank');
			obj.focus();
			return false;
		}
	  	if (obj.value.substr(0,1)=='@' || obj.value.indexOf('@.')!=-1 || obj.value.replace(/[^@]/g,'')!='@'){
			alert('Email address is incorrectly formatted.');
			obj.focus();
			obj.select();
			return false;
		} else {
			var emailStrip=obj.value.replace(/\w/g,'').split('@');
			if (emailStrip[0].replace(/\./g,'').length>0 || emailStrip[1].length<1){
				alert('Email address is incorrectly formatted.');
				obj.focus();
				obj.select();
				return false;
			}
		}
		return true;
	  }

function cycleRadius(matchType){
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send('act=9&match='+matchType);
	document.getElementById('matchList').innerHTML=srvrConnect.responseText;
}

function displayPR(objNum){
	var objStat=document.getElementById('pr'+objNum).style.display;
	var switchStat=document.getElementById('PRswitch'+objNum).innerHTML;
	document.getElementById('pr'+objNum).style.display=objStat=='block'?'none':'block';
	document.getElementById('PRswitch'+objNum).innerHTML=switchStat=='[ CLOSE ]'?'[ VIEW ]':'[ CLOSE ]';
}

function filter(filterStr,matchType){
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send('act=13&filter='+filterStr+'&match='+matchType);
	document.getElementById('matchList').innerHTML=srvrConnect.responseText;
	makeCorners(document.getElementById('matchList'));
}

var mouseX, mouseY, theRule, objTarget, menteeID;

function pickup(e){
	var eid=location.href.split('?')[1].split('=')[1];
	if (eid==11||eid==12) return false;
	if(!e) e=window.event;
	if (e.srcElement) {
		var obj=e.srcElement
	} else {
		var obj=e.target
	}
	mouseX=e.clientX;
	mouseY=e.clientY;
	menteeID=obj.getAttribute('recID');
	var floater=document.createElement('div');
	floater.style.position='absolute';
	floater.style.top=(mouseY+getScrollXY()[1]+2)+'px';
	floater.style.left=(mouseX+15)+'px';
	floater.style.padding='0px 5px';
	floater.style.textTransform='capitalize';
	floater.style.fontSize='8pt';
	floater.style.fontFamily='arial';
	floater.innerHTML=obj.innerHTML.replace(/; /g,'');
	if (floater.innerHTML.indexOf('#')==-1) floater.innerHTML=floater.innerHTML + ', #' + obj.getAttribute('recID');
	floater.style.backgroundColor='#FFFFFF';
	floater.id='float';

	document.body.insertBefore(floater,document.body.firstChild);
	floater.setAttribute('corners','round,4,#FFFFFF,4,0.50');
	makeCorners(floater);
	document.getElementById('float').style.zIndex='2010';
	document.onselectstart=new Function ('return false');
	document.body.style.MozUserSelect='none';
	document.body.style.cursor='default';

	var theRules = (document.styleSheets[0].cssRules?document.styleSheets[0].cssRules:document.styleSheets['primeStyle'].rules);
	for (i=0;i<theRules.length;i++) {
		if (theRules[i].selectorText.toLowerCase()=='.mentorlistover'){
			theRule=theRules[i];
			theRule.style.backgroundColor='#DDAAAA';
			break;
		}
	}
	
	if (obj.parentNode.id.indexOf('mentorsMatches')!=-1){
		var mentorID=obj.parentNode.getAttribute('recID');
		menteeID=obj.getAttribute('menteeID');
		//document.getElementById('mentee-'+menteeID).onmousedown=function(event){pickup(event)};
		//document.getElementById('mentee-'+menteeID).onmouseover=function(){this.className='nameOver'};
		//document.getElementById('mentee-'+menteeID).onmouseout=function(){this.className='name'};
		//document.getElementById('menteeMatched-'+menteeID).checked=false;
		//document.getElementById('menteesMatch-'+menteeID).innerHTML='';
		//document.getElementById('dateMatched-'+menteeID).innerHTML='';
		var td=obj.parentNode;
		obj.parentNode.removeChild(obj);
		if (td.innerHTML=='') document.getElementById('mentorMatched-'+mentorID).checked=false;
		var sendStr='menteeID='+menteeID+'&mentorID='+mentorID+'&act=4&names='+td.innerHTML;
		var resp=getXML(sendStr,'_processAjax.cfm');
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance."));
		}
	}
	
	document.body.onmousemove=function(event){
		if (!event) event=window.event;
		mouseX=event.clientX;
		mouseY=event.clientY;
		document.getElementById('float').style.top=(mouseY+getScrollXY()[1]+5)+'px';
		document.getElementById('float').style.left=(mouseX+15)+'px';
	}
	window.onscroll=function(){
		document.getElementById('float').style.top=(mouseY+getScrollXY()[1]+5)+'px';
	}
	document.body.onmouseup=function(event){
		theRule.style.backgroundColor='';
		document.body.style.MozUserSelect=null;
		document.body.style.cursor='auto';
		document.body.onmouseup=null;
		window.onscroll=null;
		if (!event) event=window.event;
		if (event.srcElement && (event.srcElement.getAttribute('acceptDrop') || event.srcElement.parentNode.getAttribute('acceptDrop'))) { //acceptDrop element must have recID attribute too
			objTarget=(event.srcElement.getAttribute('acceptDrop')?event.srcElement:event.srcElement.parentNode);
			objTarget.innerHTML=objTarget.innerHTML + '<span menteeID='+menteeID+' onMouseDown="pickup(event)">' + (objTarget.innerHTML.length<2?'':'; ') + floater.innerHTML + '</span>';
			dropUpdate();
		} else if (event.target && (event.target.getAttribute('acceptDrop') || event.target.parentNode.getAttribute('acceptDrop'))) {
			objTarget=(event.target.getAttribute('acceptDrop')?event.target:event.target.parentNode);
			objTarget.innerHTML=objTarget.innerHTML + '<span menteeID='+menteeID+' onMouseDown="pickup(event)">' + (objTarget.innerHTML.length<2?'':'; ') + floater.innerHTML + '</span>';
			dropUpdate();
		} else if (event.target && event.target.id=='menteeHolder'){ //Special for Mozilla, overflow:hidden mouseup event
			document.body.onmouseover=function(event) {
				document.body.onmouseover=null;
				objTarget=(event.target.getAttribute('acceptDrop')?event.target:event.target.parentNode);
				objTarget.innerHTML=objTarget.innerHTML + '<span menteeID='+menteeID+' onMouseDown="pickup(event)">' + (objTarget.innerHTML.length<2?'':'; ') + floater.innerHTML + '</span>';
			}
			setTimeout('dropUpdate()',1); //timeout allows mouseup to complete so mouseover can fire...
		}
		document.onselectstart=new Function('return true');
		document.body.onmousemove=null;
		if (document.getElementById('float')) document.body.removeChild(document.getElementById('float'));
	}

}

function dropUpdate(){
	//alert('mentor ID = ' +objTarget.getAttribute('recID') + ' - mentee ID = ' + menteeID);
	if (objTarget!=null){
		var mentorID=objTarget.getAttribute('recID');
		document.getElementById('mentorMatched-'+mentorID).checked=true;
		document.getElementById('menteeMatched-'+menteeID).checked=true;
		document.getElementById('menteesMatch-'+menteeID).innerHTML=document.getElementById('mentor-'+mentorID).innerHTML + ', #' + document.getElementById('mentor-'+mentorID).getAttribute('recID');
		var sendStr='menteeID='+menteeID+'&mentorID='+mentorID+'&names='+document.getElementById('mentorsMatches-'+mentorID).innerHTML+'&act=3';
		var resp=getXML(sendStr,'_processAjax.cfm');
		//crawlXML(resp);
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) obj.focus();
		}
		objTarget=null
		document.getElementById('dateMatched-'+menteeID).innerHTML=resp.getElementsByTagName('date')[0].firstChild.data;
		document.getElementById('mentee-'+menteeID).onmousedown=null;
		document.getElementById('mentee-'+menteeID).onmouseover=null;
	}
}

function getScrollXY() {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return [x, y];
}

function replyToInvite(obj,mentorID,menteeID,recipientType){

	if (obj.getElementsByTagName('input')[0]) obj.getElementsByTagName('input')[0].disabled=true;

	var respBox=document.createElement('div');
	respBox.id='rbox';
	respBox.style.position='absolute';
	respBox.style.backgroundColor='white';
	respBox.style.border='1px solid #110055';
	respBox.style.top='-25px';
	respBox.style.left='50px';
	respBox.style.width='90px';
	respBox.style.height='100px';
	respBox.style.padding='3px';
	respBox.style.fontSize='8pt';
	respBox.setAttribute('corners','round,4,#110055,4,0.70');
	
	var closer=document.createElement('div');
	closer.style.padding='0px 2px';
	closer.style.styleFloat='right';
	closer.style.cssFloat='right';
	closer.style.marginTop='-5px';
	closer.style.height='15px';
	closer.style.color='#770000';
	closer.style.fontWeight='bold';
	closer.style.fontSize='8pt';
	closer.style.fontFamily='arial';
	closer.style.cursor='pointer';
	closer.appendChild(document.createTextNode('X'));
	closer.onclick=function(){
		if (obj.getElementsByTagName('input')[0]) obj.getElementsByTagName('input')[0].disabled=false;
		document.getElementById('rboxnew').parentNode.removeChild(document.getElementById('rboxnew'))
	};
	
	var respForm=document.createElement('form');
	respForm.id='formResp';
	respForm.style.clear='both';
	respForm.style.marginTop='10px';
	respForm.style.marginLeft='10px';
	respForm.style.textAlign='left';
	respForm.style.lineHeight='25px';
	
	
	var radio1label=document.createTextNode('ACCEPT');
	try{
		  if (obj.innerHTML.indexOf('Accepted')!=-1) {
			 var radio1 = document.createElement('<input type="radio" name="invResponse" checked />')
		  } else {
			 var radio1 = document.createElement('<input type="radio" name="invResponse" />');
		  }
    }catch(err){
        var radio1 = document.createElement('input');
        radio1.setAttribute('type', 'radio');
        radio1.setAttribute('name', 'invResponse');
		  if (obj.innerHTML.indexOf('Accepted')!=-1) radio1.checked=true;
    }
	 radio1.style.verticalAlign='middle';
	 radio1.value='1';
	 radio1.onclick=function(){
	 		obj.innerHTML='Accepted'
			sendReply(mentorID,menteeID,recipientType,'accept');
	 };
	
	
	var radio2label=document.createTextNode('DECLINE');
	try{
		  if (obj.innerHTML.indexOf('Declined')!=-1) {
			 var radio2 = document.createElement('<input type="radio" name="invResponse" checked />')
		  } else {
			 var radio2 = document.createElement('<input type="radio" name="invResponse" />');
		  }
	 }catch(err){
		  var radio2 = document.createElement('input');
		  radio2.setAttribute('type', 'radio');
		  radio2.setAttribute('name', 'invResponse');
		  if (obj.innerHTML.indexOf('Declined')!=-1) radio2.checked=true;
	 }
	 radio2.style.verticalAlign='middle';
	 radio2.value='0';
	 radio2.onclick=function(){
			obj.innerHTML='Declined'
			sendReply(mentorID,menteeID,recipientType,'decline');
	 };
	
	
	obj.parentNode.appendChild(respBox);
	makeCorners(document.getElementById('rbox'));
	
	respForm.appendChild(radio1);
	respForm.appendChild(radio1label);
	respForm.appendChild(radio2);
	respForm.appendChild(radio2label);
	
	document.getElementById('rbox').appendChild(closer);
	document.getElementById('rbox').appendChild(respForm);
	
}

function saveComment(obj,act,type){
		srvrConnect.open('post','_processAjax.cfm',0);
		var sendStr='act='+act+'&field='+obj.name+'&value='+escape(obj.value)+'&id=' + document.getElementById('recID').value;
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send(sendStr);
		//document.getElementById('response').innerHTML=srvrConnect.responseText;
		document.getElementById('comments').innerHTML=srvrConnect.responseText;
		obj.value='';
}
	function delComment(id,act,type){
		if (confirm('Are you sure you want to delete this comment?')==true){
			srvrConnect.open('post','_processAjax.cfm',0);
			var sendStr='act='+act+'&cmtID='+id+'&id=' + document.getElementById('recID').value;
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send(sendStr);
			//document.getElementById('response').innerHTML=srvrConnect.responseText;
			document.getElementById('comments').innerHTML=srvrConnect.responseText;
		}
	}

function saveFinger(id){
	var msg='Please confirm that you have had your fingerprints taken and submitted for a background check';
	if (confirm(msg)){
	
			var sendStr='act=16&id=' + id;
			var resp=getXML(sendStr,'_processAjax.cfm');
			var chk=resp.getElementsByTagName('success')[0].firstChild.data;
			if (chk!='true'){
				alert("An error occurred while attempting to save your data. Please try again. If this problem persists, please contact your mentoring administrator for assistance.");
				return false;
			}
			document.location.reload();
	}
}
function sendInvite(obj,mid,uid,matchType){
		var msg='Are you sure you want to send an invitation to the highlighted ' + matchType.replace(/s/g,'') + '?'
		var row=obj.parentNode.parentNode;
		var oldBackColor=row.style.backgroundColor;
		row.style.backgroundColor='#CCCCFF';
		if (!confirm(msg)){
			row.style.backgroundColor=oldBackColor;
			return;
		}
		var sendStr='act=10&mentorID='+mid+'&menteeID='+uid+'&recipType='+matchType;
		var resp=getXML(sendStr,'_processAjax.cfm');
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp;
			if (confirm("An error occurred while attempting to send your email. To try again, click 'OK'. If this problem persists, please click 'Cancel' and contact your mentoring sponsors for assistance."));
		} else {
			obj.parentNode.innerHTML='<em>Sent...</em>';
			row.style.backgroundColor=oldBackColor;
			//var recvr=resp.getElementsByTagName('recipient')[0].firstChild.data;
			//alert(recvr + ' has been invited to the next meet and greet. Please feel free to continue browsing profiles.');
		}
}

function sendReply(mid,uid,recipType,reply){
		var sendStr='act=11&mentorID='+mid+'&menteeID='+uid+'&reply='+reply+'&recipType='+recipType;
		var resp=getXML(sendStr,'_processAjax.cfm');
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp;
			if (confirm("An error occurred while attempting to send your email. To try again, click 'OK'. If this problem persists, please click 'Cancel' and contact your mentoring sponsors for assistance.")) obj.focus();
		}
}

function showFilter(){

}

function showLogin(){
	document.getElementById('loginBox').style.display='block';
	document.getElementsByTagName('body')[0].onclick=function(){document.getElementById('loginBox').style.display='none'}
}

function stopProp(e){
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function subReport(obj){
	var inputs=obj.getElementsByTagName('input');
	var locs='';
	var isMentor=false;
	for (i=0;i<inputs.length;i++){
		if (inputs[i].name=='locations' && inputs[i].checked==true) locs=locs+inputs[i].value+',';
		if (inputs[i].name=='hours') var isMentor=true;
	}
	if (locs==''&&isMentor==true) {
		alert('You must select your meeting locations.')
		return false;
	}
	if (inputs.hours && (inputs.hours.value=='' || parseFloat(inputs.hours.value)!=inputs.hours.value)){
		alert('You must input the number of hours you met during this time period.');
		inputs.hours.focus();
		return false;
	}
	//if (inputs.gpa&&(inputs.gpa.value==''||isFinite(inputs.gpa.value)==false)){
	//	alert('You must estimate the current GPA during this time period. The value must be a number.');
	//	inputs.gpa.focus();
	//	return false;
	//}
	if (inputs.daysAbsent&&(inputs.daysAbsent.value==''||inputs.daysAbsent.value!=parseInt(inputs.daysAbsent.value)||inputs.daysAbsent.value>5)){
		alert('You must include the number of days of unexcused absences during the week prior to the request date. The value must be a number. Zero (0) is acceptable, but the value must be less than 6.');
		inputs.daysAbsent.focus();
		return false;
	}
	var sendStr='act=18&locations='+locs.substr(0,locs.length-1)+'&comments='+document.getElementById('comments').value+'&weekNum='+inputs.wkNum.value;
	var sendStr=sendStr+'&rqstDate='+inputs.rqstDate.value+'&mentorID='+inputs.mentorID.value+'&menteeID='+inputs.menteeID.value;
	var sendStr=sendStr+'&responder='+inputs.responder.value;
	if (inputs.hours) sendStr=sendStr+'&hours='+inputs.hours.value;
	if (inputs.gpa) sendStr=sendStr+'&GPA='+inputs.gpa.value;
	if (inputs.daysAbsent) sendStr=sendStr+'&daysAbsent='+inputs.daysAbsent.value;
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send(sendStr);
	document.getElementById('reportRqstHolder').innerHTML=srvrConnect.responseText;
}

function toggleInactive(matchType){
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send('act=17&match='+matchType);
	if (matchType=='mentors'){
		document.getElementById('mentorList').innerHTML=srvrConnect.responseText;	
	} else if (matchType=='mentees'){
		document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
	}
}
function toggleInactive_v2(matchType){
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send('act=17.2&match='+matchType);
	if (matchType=='mentors'){
		document.getElementById('mentorList').innerHTML=srvrConnect.responseText;	
	} else if (matchType=='mentees'){
		document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
	}
}

/*-------------------------------START IT ALL SCRIPT --------------------------------*/

var isLTIE7=false;

function setup(){
	isSafari=(navigator.appVersion.indexOf('AppleWebKit')!=-1);
	ieVer=parseInt(navigator.appVersion.split("MSIE")[1]);
	isLTIE7=(ieVer<7);
	isLTIE8=(ieVer<8);
	enableOverlayBGM();
	if (ieVer<7&&!window.opera) replacePNG();
	if (document.getElementById('trainingManual')) setupHandbook();
	if (document.location.href.indexOf('introVideo.cfm')==-1){
		if (document.getElementById('nav')) {
			setupNav(document.getElementById('nav')); 
			setInterval('animate()',20);
		}
		if (document.getElementById('time')) setInterval('timer()',992);
		makeCorners(document.body);
		makeDateFields(document.body);
		activateComboBox();
		initAjax();
		if (typeof(words)!='undefined') highlightWord(document.getElementsByTagName("body")[0],words[1]);
		if (document.getElementById('log')) document.getElementById('log').href='javascript: function(){return false}';
	}
	document.onmousedown=selectmouse; // for drag and drop function
	document.onmouseup=endDrag; // for drag and drop also
}

if (location.hostname.indexOf('acer')!=-1 || location.hostname.indexOf('christianmentors')!=-1 || location.hostname.indexOf('biggiantmedia')!=-1) {
	window.onload=setup;
} else {
	isSafari=(navigator.appVersion.indexOf('AppleWebKit')!=-1);
	ieVer=parseInt(navigator.appVersion.split("MSIE")[1]);
	isLTIE7=(ieVer<7);
	isLTIE8=(ieVer<8);
	window.onload=enableOverlayBGM;
}

/*-------------------------SIMPLE DRAG ME SCRIPT --------------------------------*/

var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = (nn6 ? tx + e.clientX - x : tx + event.clientX - x) + 'px';
    dobj.style.top  = (nn6 ? ty + e.clientY - y : ty + event.clientY - y) +'px';
    return false;
  }
}

function selectmouse(e) {
  var fobj       = nn6 ? e.target : event.srcElement;

  while (fobj.tagName != "HTML" && fobj.className != "dragme") {
    fobj = fobj.parentNode;
  }

  if (fobj.className=="dragme") {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = (nn6 ? e.clientX : event.clientX);
    y = (nn6 ? e.clientY : event.clientY);
    document.onmousemove=movemouse;
    return false;
  }
}

function endDrag(){
	//if (dobj){
	//	dobj.style.top='0px';
	//	dobj.style.left='0px';
	//}
	isdrag=false;
}

/*------------------------------------AJAX FUNCTIONS---------------------------------------*/

if (window.ActiveXObject) {
	var dbConnect=new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
	var dbConnect=new XMLHttpRequest();
}

function initAjax(){
	var inputs=document.getElementsByTagName('input');
	for (i=0;i<inputs.length;i++){
		if (inputs[i].getAttribute&&inputs[i].getAttribute('ajaxEnable')!=null){
			if (document.getElementById('menteeIdentifier')!=null) {
				switch(inputs[i].getAttribute('ajaxEnable')){
					case "year": 
						inputs[i].onblur=function(){if(confYear(this,this.value))doAjax(this,2)}
					break
					case "num": 
						inputs[i].onblur=function(){if (confNum(this)) doAjax(this,2)}
					break
					case "date":
						inputs[i].onblur=function(){if(confDate(this,this.value)) doAjax(this,2)}
					break
					case "radio":
						inputs[i].onchange=function(){doAjax(this,2)}
					break
					case "checkbox":
						inputs[i].onchange=function(){doAjax(this,2)}
					break
					case "email":
						inputs[i].onblur=function(){if (confEmail(this))doAjax(this,2)}
					break
					default:
						inputs[i].onblur=function(){doAjax(this,2)}
				}
			}
			if (document.getElementById('mentorIdentifier')!=null) {
				switch(inputs[i].getAttribute('ajaxEnable')){
					case "year": 
						inputs[i].onblur=function(){if(confYear(this,this.value))doAjax(this,1)}
					break
					case "num": 
						inputs[i].onblur=function(){doAjax(this,1)}
					break
					case "date":
						inputs[i].onblur=function(){if(confDate(this,this.value)) doAjax(this,1)}
					break
					case "radio":
						inputs[i].onchange=function(){doAjax(this,1)}
					break
					case "checkbox":
						inputs[i].onchange=function(){doAjax(this,1)}
					break
					case "email":
						inputs[i].onblur=function(){if (confEmail(this))doAjax(this,1)}
					break
					default:
						inputs[i].onblur=function(){doAjax(this,1)}
				}
			}
			if (document.getElementById('sponsorIdentifier')!=null) {
				switch(inputs[i].getAttribute('ajaxEnable')){
					case "year": 
						inputs[i].onblur=function(){if(confYear(this,this.value))doAjax(this,2.1)}
					break
					case "num": 
						inputs[i].onblur=function(){doAjax(this,1)}
					break
					case "date":
						inputs[i].onblur=function(){if(confDate(this,this.value)) doAjax(this,2.1)}
					break
					case "radio":
						inputs[i].onchange=function(){doAjax(this,2.1)}
					break
					case "checkbox":
						inputs[i].onchange=function(){doAjax(this,2.1)}
					break
					case "email":
						inputs[i].onblur=function(){if (confEmail(this))doAjax(this,2.1)}
					break
					default:
						inputs[i].onblur=function(){doAjax(this,2.1)}
				}
			}
			if (inputs[i].getAttribute('ajaxEnable')==15){
				inputs[i].onblur=function(){doAjax(this,15)}
			}
		}
	}
	var inputs=document.getElementsByTagName('textarea');
	for (i=0;i<inputs.length;i++){
		if (inputs[i].getAttribute&&inputs[i].getAttribute('ajaxEnable')!=null){
			if (document.getElementById('sponsorIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,2.1)}
			if (document.getElementById('menteeIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,2)}
			if (document.getElementById('mentorIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,1)}
		}
	}
	var inputs=document.getElementsByTagName('select');
	for (i=0;i<inputs.length;i++){
		if (inputs[i].getAttribute&&inputs[i].getAttribute('ajaxEnable')!=null){
			if (document.getElementById('sponsorIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,2.1)}
			if (document.getElementById('menteeIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,2)}
			if (document.getElementById('mentorIdentifier')!=null) inputs[i].onblur=function(){doAjax(this,1)}
			if (inputs[i].getAttribute('ajaxEnable')==15) inputs[i].onblur=function(){doAjax(this,15)};
		}
	}
}

function ajaxSave(obj){
		str='act=1&field=' + obj.name + '&value=' + obj.value;
		srvrConnect.open('post','_processAjax.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send(str);
		document.getElementById('response').innerHTML=srvrConnect.responseText;
}

function doAjax(obj,act){
	if (obj.type=='checkbox' && obj.checked==false){
		obj.value=0
	} 
	if (obj.name=='mtg_date' || obj.name=='mtg_time'){
		if (document.getElementById('mtg_date').value!='') document.getElementById('next_meet_date').value=document.getElementById('mtg_date').value + ' ' +document.getElementById('mtg_time').value;
		obj=document.getElementById('next_meet_date');
	}
	var sendStr='act='+act+'&field='+obj.name+'&value='+escape(obj.value)+'&id='+(obj.type=='checkbox'?obj.getAttribute('recID'):document.getElementById('recID').value);

	var resp=getXML(sendStr,'_processAjax.cfm');
	//crawlXML(resp);
	var chk=resp.getElementsByTagName('success')[0].firstChild.data;
	if (chk!='true'){
			document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
		if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) {
			if (obj.name!='completeApp') obj.focus();
			return false;
		} else {
			if (obj.value) obj.value='';
			return false;
		}
	}
	return true;
}

function getXML(sendStr,template){
	srvrConnect.open('post',template,0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send(sendStr);
	//alert(srvrConnect.responseText);
	//document.getElementById('response').innerHTML=srvrConnect.responseText;
	var resp=srvrConnect.responseXML;
	var notWhitespace = /\S/
	var xmlData=resp.getElementsByTagName('data')[0];
	//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
	try {
		for (i=0;i<xmlData.childNodes.length;i++){
			if ((xmlData.childNodes[i].nodeType == 3)&&(!notWhitespace.test(xmlData.childNodes[i].nodeValue))) {
				// that is, if it's a whitespace text node
				xmlData.removeChild(xmlData.childNodes[i])
				i--
			}
		}
		return xmlData;
	} catch(err) {
		var xml=document.createDocumentFragment();
		var node=xml.createElement('success');
		xml.appendChild(node);
		var contents=xml.createTextNode('false');
		node.appendChild(contents);
		var node2=xml.createElement('message');
		var contents2=xml.createTextNode(srvrConnect.responseText);
		node2.appendChild(contents2);
		xml.appendChild(node2);
	 	return xml;
	}

}

			var _xmlStr;	
			function crawlXML(doc) {   /* -----PARSES AND DISPLAYS XML DOCUMENT AS UNORDERED LIST  - FOR DEBUGGING -----*/
				if(doc.hasChildNodes()) {  
					_xmlStr+='<ul><li>'+doc.tagName+'> ';       
					for(var i=0; i<doc.childNodes.length; i++) {   
					crawlXML(doc.childNodes[i]);                
					}                                              
					_xmlStr+='</li></ul>';                         
				} else {                                          
					_xmlStr+=doc.nodeValue;                        
				}                                                 
			document.getElementById('response').innerHTML=_xmlStr;	
			} 


/*------------------------------GENERIC FORM VALIDATION SCRIPT----------------------------------------*/

function confYear(obj,val){
	if (obj.value=='') return false;
	var thisYear=new Date();
	thisYear=thisYear.getFullYear();
	if (parseInt(val)>1900 && parseInt(val)<parseInt(thisYear)){
		return true;
	} else {
		alert('Year value seems unlikely');
		obj.select();
		obj.focus();
		setTimeout(function(){obj.select();obj.focus();},10);
		return false;
	}
}
function confNum(obj){
	if (!isFinite(obj.value)){
		alert('This value must be a number');
		obj.select();
		obj.focus();
		setTimeout(function(){obj.select();obj.focus();},10);
		return false;
	} else {
		return true;
	}
}
function val(obj){
	var inputs=obj.getElementsByTagName('input');
	for (ind=0;ind<inputs.length;ind++){
	  if (inputs[ind].getAttribute&&inputs[ind].getAttribute('required')!=null&&(inputs[ind].value==''||inputs[ind].value=='Value Needed')){
		inputs[ind].value='Value Needed';
		inputs[ind].select();
		inputs[ind].focus();
		alert('You omitted a required value. We will take you to the empty field. Please supply a response and submit again');
		return false;
	  }
	  
	  if (inputs[ind].getAttribute&&inputs[ind].getAttribute('type')=='email'&&inputs[ind].value!=''){
	  	if (inputs[ind].value.substr(0,1)=='@' || inputs[ind].value.indexOf('@.')!=-1 || inputs[ind].value.replace(/[^@]/g,'')!='@'){
			alert('Email address is incorrectly formatted.');
			inputs[ind].select();
			inputs[ind].focus();
			return false;
		} else {
			var emailStrip=inputs[ind].value.replace(/\w/g,'').split('@');
			if (emailStrip[0].replace(/\./g,'').length>0 || emailStrip[1].length<1){
				alert('Email address is incorrectly formatted.');
				inputs[ind].select();
				inputs[ind].focus();
				return false;
			}
		}
	  }

	  
	  if (inputs[ind].id=='User_Password' && inputs[ind].value!=document.getElementById('Confirm_Password').value){
	  	alert('Password entries do not match');
		inputs[ind].select();
		inputs[ind].focus();
		return false;
	  }
	  
	}

	var inputs=obj.getElementsByTagName('textarea');
	for (ind=0;ind<inputs.length;ind++){
	  if (inputs[ind].getAttribute&&inputs[ind].getAttribute('required')!=null&&(inputs[ind].value==''||inputs[ind].value=='Value Needed')){
		alert('You omitted a required value. We will take you to the empty field. Please supply a response and submit again');
		inputs[ind].value='Value Needed';
		inputs[ind].select();
		inputs[ind].focus();
		return false;
	  }
	}
	var inputs=obj.getElementsByTagName('select');
	for (ind=0;ind<inputs.length;ind++){
	  if (inputs[ind].getAttribute&&inputs[ind].getAttribute('required')!=null&&inputs[ind].value==''){
		alert('You omitted a required value. We will take you to the empty field. Please supply a response and submit again');
		inputs[ind].focus();
		return false;
	  }
	}
	
	// ------------ SPECIAL FOR CM MODULAR SYSTEM ------------------//
	
	if (document.affReg){
		var sendStr='act=14&pwd='+document.affReg.User_Password.value;
		var resp=getXML(sendStr,'_processAjax.cfm');
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk=='false'){
			alert("An error occurred while attempting to check your password. To try again, please click 'Submit' once more. If this problem persists, please contact Christian Mentors for assistance.");
			return false;
		} 
		if (chk=='taken'){
			alert('Your password is already in use. Please enter and confirm another password, then try submitting again.');
			return false;
		} 
		if (!document.affReg.termsAccepted.checked) {
			alert('You must signify acceptance of our Terms of Use.');
			return false;
		}
		if (document.affReg.web_address.value.indexOf('http')==-1){
			document.affReg.web_address.value='http://' + document.affReg.web_address.value;
		}
		return true;
	}
	
	if (document.regForm){
		if (document.regForm.Mentor_Pref[0].checked!=true && document.regForm.Mentor_Pref[1].checked!=true){
			alert('You must enter your mentoring preference');
			document.regForm.Mentor_Pref[0].focus();
			return false;
		}
		if (document.regForm.submitOK ){
			alert('You are outside our service area or you must change your mentoring preference');
			return false;
		}
	}
	
	if (document.regForm2){
		if (document.regForm2.i_am[0].checked!=true && document.regForm2.i_am[1].checked!=true){
			alert('You must enter your mentoring preference');
			document.regForm2.i_am[0].focus();
			return false;
		}
		if (document.regForm2.submitOK ){
			alert('You are outside our service area or you must change your mentoring preference');
			return false;
		}
	}
	
	if (document.app){
		with (document.app){
			if (typeof(drug_conviction)!='undefined' && drug_conviction[0].checked!=true && drug_conviction[1].checked!=true){
				alert('You must specify whether or not you have been convicted of a drug offense');
				drug_conviction[0].focus();
				return false;
			}
			if (typeof(sex_conviction)!='undefined' && sex_conviction[0].checked!=true && sex_conviction[1].checked!=true){
				alert('You must specify whether or not you have been convicted of a sex offense');
				sex_conviction[0].focus();
				return false;
			}
			if (typeof(sex_finding)!='undefined' && sex_finding[0].checked!=true && sex_finding[1].checked!=true){
				alert('You must specify whether or not a finding has been made and sustained against you');
				sex_finding[0].focus();
				return false;
			}
			if (typeof(pending_charges)!='undefined' && pending_charges[0].checked!=true && pending_charges[1].checked!=true){
				alert('You must specify whether or not you are the subject of pending charges');
				pending_charges[0].focus();
				return false;
			}
			if (typeof(alias)!='undefined' && alias[0].checked!=true && alias[1].checked!=true){
				alert('You must specify whether or not you have ever used and alias');
				alias[0].focus();
				return false;
			}
			if (typeof(felony)!='undefined' && felony[0].checked!=true && felony[1].checked!=true){
				alert('You must specify whether or not you have been convicted of a felony or misdemeanor');
				felony[0].focus();
				return false;
			}
			if (typeof(felony)!='undefined' && (drug_conviction[1].checked==true || sex_conviction[1].checked==true || sex_finding[1].checked==true || pending_charges[1].checked==true || alias[1].checked==true || felony[1].checked==true) && (yes_explanation.value=='' || yes_explanation.value=='Please explain')) {
				alert('You must explain all "Yes" answers');
				yes_explanation.value='Please explain';
				yes_explanation.select();
				yes_explanation.focus();
				return false;
			}	
			if (typeof(faith_agree)!='undefined' && faith_agree.checked!=true){
				alert('You must signify agreement with the Statement of Faith');
				faith_agree.focus();
				return false;
			}
			if (typeof(liability)!='undefined' && liability.checked!=true){
				alert('You must signify agreement with the Liability statement');
				liability.focus();
				return false;
			}
			if (typeof(certification)!='undefined' && certification.checked!=true){
				alert('You must certify your responses');
				certification.focus();
				return false;
			}
		}
		var completeApp=new Object();
		completeApp.name='completeApp';
		completeApp.value=1;
		if (document.getElementById('sponsorIdentifier')!=null) var ok=doAjax(completeApp,2.1);
		if (document.getElementById('menteeIdentifier')!=null) var ok=doAjax(completeApp,2);
		if (document.getElementById('mentorIdentifier')!=null) var ok=doAjax(completeApp,1);
		if (ok==true) document.location.href='module-lounge.cfm?appComplete=true';
		return false;
	}

	// ------------------------END SPECIAL MOD--------------------//
	  
}

/*-------------------------------HANDBOOK SCRIPT -------------------*/

function setupHandbook(){
	var lis=document.getElementsByTagName('img');
	for (i=0;i<lis.length;i++){
		if (lis[i].parentNode.parentNode.className=='handbook'){
			lis[i].onclick=function(ev){
				if (window.event) {
					window.event.cancelBubble=true;
				} else {
					ev.stopPropagation();
				}
				this.src=(this.src.indexOf('expand')!=-1?'images/topic-contract.gif':'images/topic-expand.gif');
				var obj=this.parentNode;
				obj.className=(obj.className=='open'?'':'open');
			};
		}
	}
}

function expand(obj){
	var expanders=document.getElementsByTagName('img');
	for (i=0;i<expanders.length;i++){
		if (expanders[i].parentNode.parentNode.className=='handbook'){
			if (obj.innerHTML.indexOf('Expand')!=-1) { //if expanding
				expanders[i].src='images/topic-contract.gif';
				expanders[i].parentNode.className='open';
			} else { //if contracting
				expanders[i].src='images/topic-expand.gif';
				expanders[i].parentNode.className='';
		}
		}
	}
	obj.innerHTML=(obj.innerHTML=='[ Expand All ]'?'[ Collapse All ]':'[ Expand All ]');
}

/*------------------------------TRANSPARENT PNG REPLACEMENT FOR <IE7 ----------*/

function replacePNG(){
	var xPNG=document.images;
	for (i=0;i<xPNG.length;i++){
		if (xPNG[i].src.toLowerCase().indexOf('.png')!=-1) {
			var file=xPNG[i].src;
			xPNG[i].src='images/1x1.gif';
			xPNG[i].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+file+'", sizingMethod="image")';
		}
	}
}
/*------------------------------NEW IMPROVED OVERLAY SCRIPT------------------------------*/

/*	 USAGE NOTES:

		activateOverlay(type,content,dragTF,scrColor,scrOpacPercent)
		
		type=img,document;
		content=link to image or document;
		dragTF=true for draggable, false for static;
		scrColor=color name or hex code for background screen color;
		scrOpacPercent=0-100, 100 completely opaque
*/

var bodyOv, docElOv;
var bgm_scrollWidth;

function enableOverlayBGM(){

	var scr=document.createElement('div');
		scr.id='bgm_pgScreen';
		scr.style.position='absolute';
		scr.style.top='0px';
		scr.style.left='0px';
		scr.style.width='100%';
		scr.style.height='100%';
		scr.style.zIndex=1000000;
		scr.style.display='none';
	var bgm_overlay=document.createElement('div');
		bgm_overlay.id='bgm_overlay';
		bgm_overlay.style.backgroundImage='url(../images/window-bckgrd.png)';
		bgm_overlay.style.backgroundRepeat='repeat-y';
		bgm_overlay.style.backgroundPosition='center center';
		bgm_overlay.style.border='1px outset #999999';
		bgm_overlay.style.padding='1px 1px 1px 1px';
		bgm_overlay.style.position='absolute';
		bgm_overlay.style.zIndex=1000000;
		bgm_overlay.style.visibility='hidden';
		bgm_overlay.style.overflow='hidden';
		bgm_overlay.style.display='block';
	var bgm_bttnClose=document.createElement('img');
		bgm_bttnClose.id='bgm_Ocloser';
		bgm_bttnClose.src='../images/window-close.png';
		bgm_bttnClose.style.position='absolute';
		bgm_bttnClose.style.top='2px';
		bgm_bttnClose.style.width='32px';
		bgm_bttnClose.style.height='31px';
		bgm_bttnClose.style.cursor='pointer';
		bgm_bttnClose.style.display='none';
		bgm_bttnClose.onclick=function(){closeIt=setInterval('resizeOverlay(0,0)',20)};
		
	document.body.appendChild(scr);
	document.body.appendChild(bgm_overlay);

	bgmScreen=document.getElementById('bgm_pgScreen');
	bgmOverlay=document.getElementById('bgm_overlay');
	bgmOverlay.appendChild(bgm_bttnClose);
	bgm_bttn=document.getElementById('bgm_Ocloser');
	if (isLTIE7) replacePNG(bgm_bttn.parentNode);

	var testBox=document.createElement('div');
	testBox.id='testbox';
	testBox.style.width='150px';
	testBox.style.height='150px';
	testBox.style.position='absolute';
	testBox.style.left='100px';
	testBox.style.top='100px';
	testBox.style.overflow='scroll';
	document.body.insertBefore(testBox,document.body.firstChild);
	bgm_scrollWidth=parseFloat(document.getElementById('testbox').offsetWidth)-parseFloat(document.getElementById('testbox').clientWidth);
	document.body.removeChild(document.getElementById('testbox'));
	
}

var winW, winH, maxW, maxH, ovType;

function getZoom(content,type,dragTF,scrColor,scrOpacPercent){
	type='document';
	dragTF='false';
	scrColor='black';
	scrOpacPercent='70';
	
	if (isLTIE7){
		var sels=document.getElementsByTagName('select');
		for (u=0;u<sels.length;u++){
			sels[u].style.visibility='hidden';
		}
	}
	
	ovType=type;

	if (document.getElementById('bgm_overlayImage')||document.getElementById('bgm_overlayDoc')) {
		bgmScreen.style.display='none';
		bgmOverlay.removeChild(bgmOverlayObj);
		bgmOverlay.style.visibility='hidden';
		bgm_bttn.style.left='0px';
		bgmOverlay.onmousedown=null;
		bgmIndex=1;
		lastX=null;
		lastY=null;
		disableOverlay();
	}

	if (scrColor&&scrOpacPercent){
		bgmScreen.style.backgroundColor=scrColor;
		bgmScreen.style.filter='alpha(opacity='+scrOpacPercent+')';
		bgmScreen.style.opacity=scrOpacPercent/100;
		bgmScreen.style.height=Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)+'px';
		if (isLTIE7) bgmScreen.style.height=document.body.scrollHeight+'px';
		bgmScreen.style.display='block';
	}

	if (dragTF==true) bgmOverlay.className='dragme';
		
	winW=document.documentElement.clientWidth;
	if (winW==0) winW=document.body.clientWidth;
	winH=document.documentElement.clientHeight;
	if (winH==0) winH=document.body.clientHeight;

	if (type=='image'){
		var bgm_overlayImage=document.createElement('img');
			bgm_overlayImage.id='bgm_overlayImage';
			bgm_overlayImage.style.border='1px inset #999999';
			bgm_overlayImage.onload=function(){activate_2('image')};
		bgmOverlay.appendChild(bgm_overlayImage);

		bgmOverlayObj=document.getElementById('bgm_overlayImage');
		bgmOverlayObj.src=content;
		bgmOverlayObj.oncontextmenu=function(){
			alert('Sorry. This image is copyrighted and may not be used without permission.');
			return false;
		}
	}else{
		var bgm_overlayDoc=document.createElement('div');
			bgm_overlayDoc.id='bgm_overlayDoc';
			bgm_overlayDoc.style.border='1px inset #999999';
			bgm_overlayDoc.style.backgroundColor='#000000';
		var bgm_ifr=document.createElement('iframe');
			bgm_ifr.frameBorder='0';
			bgm_ifr.style.width='100%';
			bgm_ifr.style.height='100%';
			bgm_ifr.src=content;
			bgm_ifr.id='bgmIFrame';
			bgm_ifr.name='bgmIFrame';
			if (isSafari) bgm_ifr.onload=function(){
				window.frames['bgmIFrame'].scrollBy(1,100);
			};
		bgmOverlay.appendChild(bgm_overlayDoc);
		bgmOverlayObj=document.getElementById('bgm_overlayDoc');
		bgmOverlayIframe=bgm_ifr;
		//document.documentElement.style.overflow='hidden';
		//document.body.style.paddingRight=bgm_scrollWidth+'px';
		activate_2(type);
	}
}

function disableOverlay(){
		//document.documentElement.style.overflow='auto';
		//document.body.style.paddingRight='0px';
		if (isSafari){
			window.scrollBy(0,1);
		}
}

function activate_2(type){
	var scrollOffset=parseInt(document.body.scrollTop!=0?document.body.scrollTop:document.documentElement.scrollTop);
	if (type=='image'){
		maxW=Math.min(parseInt(bgmOverlayObj.offsetWidth),winW-80);
		maxH=Math.min(parseInt(bgmOverlayObj.offsetHeight),winH-60);
		document.getElementById('bgm_Ocloser').style.display='block';
	} else if (type=='custom'){
		maxW=600;
		maxH=Math.min(parseInt(winH*0.95),530);
		document.getElementById('bgm_Ocloser').style.display='block';
	} else if (type=='login'){
		maxW=400;
		maxH=260;
		document.getElementById('bgm_Ocloser').style.display='block';
	} else if (type=='wait'){
		maxW=400;
		maxH=260;
	} else if (type=='calendar'){

		maxW=250;
		maxH=501;
		document.getElementById('bgm_Ocloser').style.display='block';
	} else {
		maxW=parseInt(winW*0.8);
		maxH=parseInt(winH*0.8);
		document.getElementById('bgm_Ocloser').style.display='block';
	}

	bgmOverlayObj.style.height='0px';
	bgmOverlayObj.style.width='0px';
	bgmOverlay.style.left=(winW/2-10)+'px';
	bgmOverlay.style.top=(winH/2-20)+scrollOffset+'px';
	sizeIt=setInterval('resizeOverlay('+maxW+','+maxH+')',20)
}

var bgmIndex=1;
var objOpac=100;

function resizeOverlay(w,h,act){
	var oWidth=parseInt(bgmOverlayObj.style.width);
	var oHeight=parseInt(bgmOverlayObj.style.height);
	var scrollOffset=parseInt(document.body.scrollTop!=0?document.body.scrollTop:document.documentElement.scrollTop);
	if (bgmOverlay.style.visibility=='hidden')bgmOverlay.style.visibility='visible';
	if (w>0&&h>0){
		if (oWidth<w || oHeight<h){
			if (oWidth<w) {
				bgmOverlayObj.style.width=(oWidth+Math.max((w-oWidth)/2,1))+'px';
				bgm_bttn.style.left=(parseInt(bgmOverlayObj.style.width)-30)+'px';
				bgmOverlay.style.left=(winW/2-parseInt(bgmOverlayObj.style.width)/2-10)+'px';
				lastX=bgmOverlay.style.left;
			} else
			if (oHeight<h) {
				bgmOverlayObj.style.height=(oHeight+Math.max((h-oHeight)/2,1))+'px';
				bgmOverlay.style.top=(winH/2+scrollOffset-parseInt(bgmOverlayObj.style.height)/2-0)+'px';
				lastY=bgmOverlay.style.top;
			}
		} else {
			clearInterval(sizeIt);
			if (!isLTIE7) {
				bgmOverlay.style.position='fixed';
				bgmOverlay.style.top=parseInt(bgmOverlay.style.top)-scrollOffset+'px';
			}
			if (bgmOverlayObj.tagName=='DIV') bgmOverlayObj.appendChild(bgmOverlayIframe);
		}
	} else {
		//if (document.getElementById('bgmIFrame')) bgmOverlayObj.removeChild(bgmOverlayIframe);
		if (bgmScreen.style.display=='block') bgmScreen.style.display='none';
		if (!isLTIE7&&bgmOverlay.style.position=='fixed'){
			bgmOverlay.style.position='absolute';
			lastY=parseInt(bgmOverlay.style.top)+scrollOffset+'px';
			lastX=bgmOverlay.style.left;
		}
		
		if (objOpac>0) {
			bgmOverlay.style.filter='alpha(opacity='+objOpac+')';
			bgmOverlay.style.opacity=objOpac/100;
			objOpac-=20;
				bgmOverlay.style.left=(parseInt(lastX)+(oWidth-parseInt(bgmOverlayObj.style.width))/2)+'px';
				bgmOverlay.style.top=(parseInt(lastY)+(oHeight-parseInt(bgmOverlayObj.style.height))/2)+'px';
		
		/*if (oWidth>60 || oHeight>60){
			if (oWidth>0) {
				bgmOverlayObj.style.width=oWidth*(100-Math.pow(bgmIndex,2))/100+'px';
				bgm_bttn.style.left=(parseInt(bgmOverlayObj.style.width)-38)+'px';
				bgmOverlay.style.left=(parseInt(lastX)+(oWidth-parseInt(bgmOverlayObj.style.width))/2)+'px';
				lastX=bgmOverlay.style.left;
			}
			if (oHeight>0) {
				bgmOverlayObj.style.height=oHeight*(100-Math.pow(bgmIndex,2))/100+'px';
				bgmOverlay.style.top=(parseInt(lastY)+(oHeight-parseInt(bgmOverlayObj.style.height))/2)+'px';
				lastY=bgmOverlay.style.top;
			}
			bgmIndex++;*/
		} else {
			clearInterval(closeIt);
			bgmOverlay.removeChild(bgmOverlayObj);
			bgmOverlay.style.visibility='hidden';
			bgmOverlay.style.filter=null;
			bgmOverlay.style.opacity=1;
			bgmOverlay.onmousedown=null;
			bgmIndex=1;
			objOpac=100;
			lastX=null;
			lastY=null;
			if (isLTIE7){
				var sels=document.getElementsByTagName('select');
				for (u=0;u<sels.length;u++){
					sels[u].style.visibility='visible';
				}
			}
			if (ovType!='image') disableOverlay();
			if (typeof(act)!='undefined' && act=='jump'){document.location.href='ftp.cfm'}
		}
	}
}


/*------------------------------ZOOM OVERLAY SCRIPT -------------------------*/

var pdfAdder=0; 

function getZoom2(url,action){
	pdfAdder=url.indexOf('.pdf')==-1?0:30;
	var size=openOverlay();
	var ifr=document.createElement('iframe');
	ifr.frameBorder='0';
	ifr.style.width=size[0]+'px';
	ifr.style.height=size[1]+'px';
	ifr.id='newFrame';
	ifr.name='newFrame';
	//if (url.indexOf('http://')==-1&&url.indexOf('_returnDetails.cfm?id=')==-1) url='http://'+url;
	//ifr.src=url;
	document.getElementById('rolodex').insertBefore(ifr,document.getElementById('rolodex').firstChild);
	document.getElementById('rolodex').setAttribute('corners','round,0,#CCCCFF,8,0.90');
	makeCorners(document.getElementById('rolodex'));
	
	//alert(url);
	document.getElementById('newFrame').src=url;
	//document.getElementById('newFrame').src='module-lounge.cfm';
	
	var closer=document.createElement('div');
	
	var button=document.createElement('input');
	button.type='button';
	button.value='X';
	button.style.fontFamily='arial';
	button.style.width='20px';
	button.style.border='2px outset white';
	button.style.backgroundColor='#990000';
	button.style.color='white';
	button.style.fontWeight='bold';
	button.style.height='20px';
	button.style.fontSize='8pt';
	button.style.padding='0px 2px';
	button.id='histCloser';
	button.style.position='absolute';
	button.style.left=(size[0]-20)+'px';
	button.style.top='-23px';
	button.zIndex=1000000;
	button.onclick=function(){showLess(this.parentNode.parentNode.parentNode)};

	var button2=document.createElement('input');
	button2.type='button';
	button2.value='Print';
	button2.id='histPrinter';
	button2.style.styleFloat='left';
	button2.style.cssFloat='left';
	button2.style.display='none';
	button2.onclick=function(){printHist()};

	var button3=document.createElement('input');
	button3.type='button';
	button3.value='Create PDF';
	button3.id='makePDF';
	button3.style.styleFloat='left';
	button3.style.cssFloat='left';
	button3.style.display='none';
	button3.onclick=function(){createPDF()};

	var button5=document.createElement('input');
	button5.type='button';
	button5.value='Go to Lounge';
	button5.style.width='90px';
	button5.style.marginRight='10px';
	button5.id='last';
	button5.style.display='none';
	button5.onclick=function(){window.newFrame.document.location.href='module-lounge.cfm'};

	var button6=document.createElement('input');
	button6.type='image';
	button6.src='images/button-forward.gif';
	button6.value='Forward';
	button6.id='next';
	button6.style.display='none';
	button6.onclick=function(){window.newFrame.history.forward()};


	if (url.indexOf('.pdf')==-1){
		closer.style.position='relative';
	} else {
		closer.style.position='relative';
	}
	
	closer.style.top='0px';
	closer.id='closerHolder';
	closer.style.left='0px';
	closer.style.backgroundColor='transparent';
	closer.style.border='none';
	closer.style.padding='0px';
	closer.style.textAlign='left';
	closer.style.position='relative';
	
	closer.appendChild(button5);
	closer.appendChild(button6);
	closer.appendChild(button);
	closer.appendChild(button3);
	closer.appendChild(button2);

	//if (action!='register') {button5.style.display='inline';}
	//if (action=='makePDF'||action=='makeCalendar') button3.style.display='inline';
	//if (action=='makeCalendar') button4.style.display='inline';

	document.getElementById('origEl').insertBefore(closer,document.getElementById('origEl').firstChild);

}

			function openOverlay(){
					if (window.pageYOffset) prevScroll=window.pageYOffset;
			
					document.documentElement.style.overflow='hidden';
					window.scrollBy(0,1);
					if (document.documentElement.scrollTop==0){
						document.body.style.overflow='hidden';
					}
			
					var w=document.documentElement.clientWidth;
					var h=document.documentElement.clientHeight;
					if (h==0) h=document.body.clientHeight;
					if (w==0) w=document.body.clientWidth;
			
					var card=document.createElement('div');
					card.id='rolodex';
					with (card.style){
						overflow='visible';
						backgroundColor='white';
						border='1px #CCCCFF solid';
						borderWidth='25px 5px 5px 5px';
						position= 'absolute';
						zIndex=1001;
						width = Math.max((w-250),800) + 'px';
						height=(h<600?h-50:h-150) + pdfAdder + 'px';
						top=(window.pageYOffset ? (window.pageYOffset) : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop))+(h/2-((parseInt(height)+30)/2))+'px';
						left=Math.max((w/2-(parseInt(width)+20)/2),0)+'px';
					}
					var size=new Array()
					size[0]=card.style.width.replace(/px/,'');
					size[1]=card.style.height.replace(/px/,'');
					
					var screener=document.createElement('div');
					screener.id='screen2';
					with (screener.style){
						position='absolute';
						top=(window.pageYOffset ? (window.pageYOffset) : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop))+'px'
						left='0px';
						width=w+30+'px';
						height=h+10+'px';;
						filter='alpha(opacity=60)';
						opacity='0.60';
						backgroundColor='#000000';
						display='block';
						zIndex=1000;
					}
					
					document.body.insertBefore(card,document.body.firstChild);
			
					document.body.insertBefore(screener,document.getElementById('rolodex'));
					setTimeout('setResize()',1000);
					return size;
			}
			
			function setResize(){
				var url=document.getElementById('newFrame').src;
				window.onresize=function(){showLess(document.body.firstChild.nextSibling,url)};	
			}
			
			function showLess(obj,url){
					window.onresize=null;
					document.body.removeChild(obj);
					if (document.getElementById('screen2')) document.body.removeChild(document.getElementById('screen2'))
					document.documentElement.style.overflow='auto';
					window.scrollBy(0,1);
					if (document.documentElement.scrollTop==0){
						document.body.style.overflow='auto';
					}
					
					if (typeof prevScroll!='undefined' && prevScroll!=0) window.scrollTo(0,prevScroll);
					if (typeof(url)!='undefined') getZoom(url);
			}

function printHist(){
	window.top.frames[0].focus();
	window.top.frames[0].print();
}
function createPDF(){
	window.top.frames[0].document.workOrder.submit();
}
function showButtons(){
	window.top.document.getElementById('showCalendar').style.display='inline';
}

/* -------------------------------SEARCHED WORD HIGHLIGHT FUNCTIONS -------------------------------*/

function highlightWord(node,word) {
  // Iterate into this nodes childNodes
  if (node.hasChildNodes) {
    var hi_cn;
    for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
      highlightWord(node.childNodes[hi_cn],word);
    }
  }

  // And do this node itself
  if (node.nodeType == 3) { // text node
    tempNodeVal = node.nodeValue.toLowerCase();
    tempWordVal = word.toLowerCase();
    if (tempNodeVal.indexOf(tempWordVal) != -1) {
      pn = node.parentNode;
      if (pn.className != "searchword") {
        // word has not already been highlighted!
        nv = node.nodeValue;
        ni = tempNodeVal.indexOf(tempWordVal);
        // Create a load of replacement nodes
        before = document.createTextNode(nv.substr(0,ni));
        docWordVal = nv.substr(ni,word.length);
        after = document.createTextNode(nv.substr(ni+word.length));
        hiwordtext = document.createTextNode(docWordVal);
        hiword = document.createElement("span");
        hiword.className = "searchword";
        hiword.appendChild(hiwordtext);
        pn.insertBefore(before,node);
        pn.insertBefore(hiword,node);
        pn.insertBefore(after,node);
        pn.removeChild(node);
      }
    }
  }
}

/*-------------------------------NAVIGATION SCRIPT --------------------------------*/

var shadows=true;
var primaryVertOffset=25;
var secondaryVertOffset=8;
var horizontalOffset=-259;      /* MUST BE GREATER THAN -(WIDTH OF BUTtON) FOR FIREFOX/OPERA*/
var secondaryHorizontalOffset=0;
var alpha=90;

var colors=new Array('#e1e1e1','#c2c2c2','#999999','#666666','#3e3e3e','#1f1f1f','#0b0b0b')

function setupNav(nav){
	var links=nav.getElementsByTagName('a');
	var lis=nav.getElementsByTagName('li');
	var uls=nav.getElementsByTagName('ul');
	navWidth=links[0].offsetWidth;
	navWidth=260    /* special mod for CM */
	flyouts=new Object();
	closers=new Object();
	tmr=new Object();
	for (m=0;m<uls.length;m++){
		if (uls[m].parentNode.parentNode.id=='nav') {
			uls[m].style.top=primaryVertOffset+'px';
			uls[m].style.marginLeft=horizontalOffset+'px';
		} else {
			uls[m].style.top=secondaryVertOffset+'px';
			uls[m].style.marginLeft=secondaryHorizontalOffset+'px';
		}
		uls[m].id=m;
		// shadow stuff start
		if (shadows){
					if (document.all && !window.opera){
							a=document.createElement('div');
							a.style.width=(navWidth-3)+'px'
							a.style.height=(uls[m].offsetHeight-3)+'px'
							a.className='shadow';
							a.style.border='1px solid  black';
							a.style.backgroundColor='black';
							uls[m].insertBefore(a,uls[m].firstChild);
						
					}else{
					
			for (n=0;n<7;n++){
				a=document.createElement('div');
				a.style.width=navWidth+'px';
				//if (n==0) a.style.backgroundColor='#000000';
				a.style.top=n+'px';
				a.style.left=n+'px';
				a.style.height=uls[m].offsetHeight+'px';
				a.style.position='absolute';
				a.className='navShadow';
				if (window.opera &&parseInt(window.opera.version())<9) 	a.style.borderColor=colors[6-n];
//				a.style.filter='alpha(opacity='+((7-n)*10+n)+')';
				a.style['opacity']=((7-n)/10+n/100);
				a.style['-moz-opacity']=(7-n)/10+n/100;
				a.style['-khtml-opacity']=(7-n)/10+n/100;
				uls[m].insertBefore(a,uls[m].firstChild);
			}
					}
		}
		// shadow stuff end
	}
	for (o=0;o<lis.length;o++){
			lis[o].style.zIndex=lis.length-o;	
	}
	for (i=0;i<links.length;i++){
			if (links[i].parentNode.parentNode.id!='nav'){
				links[i].style.filter='alpha(opacity='+alpha+')';
				links[i].style['opacity']=alpha/100;
				links[i].style['-moz-opacity']=alpha/100;
				links[i].style['-khtml-opacity']=alpha/100;
			}
			links[i].onmouseover=function(){showSub(this)};
			links[i].onmouseout=function(){hideSub(this)};
			links[i].onfocus=function(){this.blur()};
			if (links[i].href.indexOf('#')!=links[i].href.length-1){
				links[i].onclick=function(){hideSub(this)};
			} else {
				links[i].onclick=function(){return false};
			}	
	}
}

function showSub(prime){ 
	var obj=prime;
	var sub=prime.parentNode.getElementsByTagName('ul');
	while (obj.id!='nav'){
		if (obj.tagName.toLowerCase()=='ul' && tmr[obj.id]) clearTimeout(tmr[obj.id]);
		obj=obj.parentNode;
	}
	if (sub.length>0){
		if (tmr[sub[0].id]) clearTimeout(tmr[sub[0].id]);
		flyouts[sub[0].id]=sub[0];
	}
}

function hideSub(prime){
	var sub=prime.parentNode.getElementsByTagName('ul');
	if (sub.length>0){
		  tmr[sub[0].id]=setTimeout('delete flyouts['+sub[0].id+'];closers['+sub[0].id+']='+sub[0].id,125);
	}
	var obj=prime;
	while (obj.id!='nav'){
			if (obj.tagName.toLowerCase()=='ul'){
		 	  tmr[obj.id]=setTimeout('delete flyouts['+obj.id+'];closers['+obj.id+']='+obj.id,125);
			}
			obj=obj.parentNode;
	}
}

function animate(){
	for (j in flyouts){
		delete closers[j];
		var curValue=(isNaN(curValue=parseInt(flyouts[j].style.left))?0:curValue);
		if(curValue<navWidth) {
				flyouts[j].style.left=(curValue+Math.ceil((navWidth-curValue)/2))+'px';
				flyouts[j].style.clip='rect(0px 2500px 2500px ' + (navWidth-curValue-2)+ 'px)';
		} else {
				delete flyouts[j];
		}
	}
	for (k in closers){
		var curUL=document.getElementById(closers[k]);
		var curValue2=parseInt(curUL.style.left);
		if(curValue2>0) {
				curUL.style.left=(curValue2=curValue2-Math.ceil(curValue2/2))+'px';
				curUL.style.clip='rect(0px 2500px 2500px ' + (navWidth-curValue2)+ 'px)';
		} else {
			if (shadows) curUL.style.clip='rect(0px 2500px 2500px ' + (navWidth-curValue2+10)+ 'px)';
			delete closers[k];
		}
	}
}

/*-------------------------------CLOCK SCRIPT --------------------------------*/

var month=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var timeFlag=false;
var timeStr, dayStr, monStr

function timer(){
	calcTime();
	document.getElementById('time').innerHTML=timeStr;
	document.getElementById('time2').innerHTML=timeStr;
	document.getElementById('date').innerHTML=dayStr;
	document.getElementById('date2').innerHTML=dayStr;
	document.getElementById('month').innerHTML=monStr;
	document.getElementById('month2').innerHTML=monStr;
}

function calcTime(){
	var now=new Date();
	var seconds=now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds();
	var minutes=now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes();
	timeStr=now.getHours()>11?((now.getHours()==12?12:now.getHours()-12))+':'+minutes+':'+seconds+' PM':(now.getHours()==0?12:now.getHours())+':'+minutes+':'+seconds+' AM';
	monStr=month[now.getMonth()].toUpperCase().substr(0,3)+' '+now.getFullYear();
	dayStr=now.getDate();
	//return dayStr  + ' - '+ timeStr;
}

/*------------------------------- ROUNDED CORNERS AND DROPSHADOW ROUTINE -------------*/

	function makeCorners(node){
		if (node.hasChildNodes) {
				var iteration;
				for (iteration=0;iteration<node.childNodes.length;iteration++) {
					makeCorners(node.childNodes[iteration]);
				}
		}
		  
  // format for ATTRIBUTE: corners="round,[radius (0 if none)],[color (0 if background or none)],[shadowOffset (0 if none)],[shadowOpacity (0-1)]"
  // ex: corners=round,10,#000FFF,10,0.50"
		  
		if (node.getAttribute&&(sty=node.getAttribute('corners'))){
		   
			var selectBoxes=node.getElementsByTagName('select');
			var tempStorage=new Array();
			for (xx=0;xx<selectBoxes.length;xx++){
				tempStorage[selectBoxes[xx].name]=selectBoxes[xx].selectedIndex
			}			

			var arrSty=sty.split(',');
			sty=arrSty[0];
			cornerRadius=parseInt(arrSty[1]);
			shadowOffset=parseInt(arrSty[3]);
			shadowOpacity=arrSty[4];
			
			var n=node;
			
			if (arrSty[2]!=0) {
				borderColor=arrSty[2];
			} else {
				borderColor=n.style.backgroundColor;
			}
						
			if (parseInt(n.offsetWidth)!=0){  
				elWidth=n.offsetWidth;
				elHeight=n.offsetHeight;
				
			} else {  //ROUTINE TO DETERMINE SIZE OF display:none ELEMENTS
			
				var elTemp=document.createElement('div');
				elTemp.style.position='absolute';
				elTemp.style.visibility='visible';
				elTemp.style.fontSize=n.style.fontSize;
				elTemp.style.lineHeight=n.style.lineHeight;
				elTemp.style.fontFamily=n.style.fontFamily;
				document.body.insertBefore(elTemp,document.body.firstChild);
				nodeTemp=n.cloneNode(true);
				nodeTemp.style.display='block';
				elTemp.appendChild(nodeTemp);
				elWidth=nodeTemp.offsetWidth;
				elHeight=nodeTemp.offsetHeight;
				elTemp.parentNode.removeChild(elTemp);
			
			}
			
			var newDiv=document.createElement('div');
			newDiv.id=n.id;
			newDiv.style.zIndex='2000';
			newDiv.style.width=elWidth+(!document.all?0:0)+'px';
			newDiv.style.styleFloat=n.style.styleFloat;
			newDiv.style.cssFloat=n.style.cssFloat;
			newDiv.style.marginLeft=n.style.marginLeft;
			newDiv.style.marginRight=n.style.marginRight;
			newDiv.style.marginTop=n.style.marginTop;
			newDiv.style.marginBottom=n.style.marginBottom;
			newDiv.style.paddingLeft=n.style.paddingLeft;
			newDiv.style.paddingRight=n.style.paddingRight;
			newDiv.style.paddingTop=n.style.paddingTop;
			newDiv.style.paddingBottom=n.style.paddingBottom;
			newDiv.style.position=n.style.position==''?'relative':n.style.position;
			newDiv.style.top=n.style.top;
			newDiv.style.left=n.style.left;
			newDiv.style.display=n.style.display;

			if (sty=='round' && cornerRadius!=0){
			
				var topCorners=document.createElement('div');
				var bottomCorners=document.createElement('div');
				
				for (i=cornerRadius;i>0;i--){
					var newLine=document.createElement('div');
					newLine.style.height='1px';
					newLine.style.overflow='hidden';
					newLine.style.position='relative';
					newLine.style.zIndex='10';
					var mrgn=cornerRadius-Math.cos(Math.asin(i/cornerRadius))*cornerRadius;
					newLine.style.margin='0px ' + mrgn + 'px';
					newLine.style.backgroundColor=borderColor;
					topCorners.appendChild(newLine);	
				}
				newDiv.appendChild(topCorners);	
				
				var orig=n.cloneNode(true);
				orig.id='origEl';
				orig.style.position='relative';
				orig.style.top='0px';
				orig.style.left='0px';
				orig.style.marginLeft='0px';
				orig.style.marginRight='0px';
				orig.style.marginTop='0px';
				orig.style.marginBottom='0px';
				orig.style.cssFloat='';
				orig.style.styleFloat='';
				orig.style.display='block';
				newDiv.appendChild(orig);
				
				for (i=1;i<=cornerRadius;i++){
					var newLine=document.createElement('div');
					newLine.style.height='1px';
					newLine.style.overflow='hidden';
					newLine.style.position='relative';
					var mrgn=cornerRadius-Math.cos(Math.asin(i/cornerRadius))*cornerRadius;
					newLine.style.margin='0px ' + mrgn + 'px';
					newLine.style.backgroundColor=borderColor;
					bottomCorners.appendChild(newLine);	
				}
				newDiv.appendChild(bottomCorners);	
			
			} else {
			
				var orig=n.cloneNode(true);
				orig.id='origEl';
				orig.style.position='relative';
				orig.style.zIndex=2000;
				orig.style.top='0px';
				orig.style.left='0px';
				orig.style.marginLeft='0px';
				orig.style.marginRight='0px';
				orig.style.marginTop='0px';
				orig.style.marginBottom='0px';
				orig.style.cssFloat='';
				orig.style.styleFloat='';
				orig.style.display='block';
				newDiv.appendChild(orig);
				
			}

			n.parentNode.replaceChild(newDiv,n);
				
			var selectBoxes=newDiv.getElementsByTagName('select');
			for (xx=0;xx<selectBoxes.length;xx++){
				selectBoxes[xx].selectedIndex=tempStorage[selectBoxes[xx].name]
			}	

			if (shadowOffset!=0){
			
				if (orig.style.backgroundColor!='' && orig.style.backgroundColor!='transparent'){
					var shad=document.createElement('div');
					shad.style.width=elWidth+'px';
					var contentBox=document.createElement('div');
					contentBox.style.height=elHeight+'px';
					contentBox.style.width=elWidth+'px';
					contentBox.style.backgroundColor='#000000';
					if (topCorners) shad.appendChild(topCorners.cloneNode(true));
					shad.appendChild(contentBox);
					if (bottomCorners) shad.appendChild(bottomCorners.cloneNode(true));
				} else {
					var shad=newDiv.cloneNode('true')
					var shadInputs=shad.getElementsByTagName('input')
					for (i=0;i<shadInputs.length;i++){
						shadInputs[i].id='';
					}
				}
			
				if (document.all && !window.opera){
					shad.style.position='absolute';
					shad.style.marginLeft='0px';
					shad.style.marginRight='0px';
					shad.style.marginTop='0px';
					shad.style.marginBottom='0px';
					shad.style.top=-shadowOffset/2+'px';
					shad.style.left=-shadowOffset/2+'px';
					shad.style.filter='progid:DXImageTransform.Microsoft.Blur(PixelRadius="'+shadowOffset+'", MakeShadow="true", ShadowOpacity="'+shadowOpacity+'")';
					newDiv.insertBefore(shad,newDiv.firstChild);
				} else {
					shad.style.marginLeft='0px';
					shad.style.marginRight='0px';
					shad.style.marginTop='0px';
					shad.style.marginBottom='0px';
					var allDivs=shad.getElementsByTagName('div');
					for (i=0;i<allDivs.length;i++){
						if (allDivs[i].style.backgroundColor!='' && allDivs[i].style.backgroundColor!='transparent'){
							allDivs[i].style.backgroundColor='#000000';
							allDivs[i].style.borderColor='#000000';
						}
					}
					shad.style.position='absolute';
					shadowOffset+=5;
					for (x=1;x<=shadowOffset;x++){
						var shad2=shad.cloneNode(true);
						shad2.style.top=x+'px';
						shad2.style.left=x+'px';
						shad2.style.zIndex=0;
						shad2.style.opacity=shadowOpacity/(1*x);
						newDiv.insertBefore(shad2,newDiv.firstChild);
					}
				}
			}
		}
	}

/*--------------------------------CUSTOM DATE FIELD SCRIPT-----------------------*/

	function confDate(obj,str){
		if (str=='') return;
		str=str.replace(/-|\./g,'/');
		var dateArray=str.split('/')
		if (dateArray.length<3){
			alert('Improper date format!\n\nThe date must be formatted in the following way: xx/xx/xxxx.');
			obj.value='';
			setTimeout(function(){obj.select()},100);
			return false;;
		}
		if (dateArray[0]>12||dateArray[0]<1){
			alert('Month value seems unlikely!');
			obj.value='';
			setTimeout(function(){obj.select()},100);
			return false;
		}
		if (dateArray[1]>31||dateArray[1]<1){
			alert('Day value seems unlikely!');
			setTimeout(function(){obj.select()},100);
			return false; ;
		}
		for (i=0;i<2;i++){
			if (dateArray[i].length<2) dateArray[i]='0'+dateArray[i];
			if (dateArray[i].length>2){
				alert('Improper date format!\n\nThe date must be formatted in the following way: xx/xx/xxxx.');
			setTimeout(function(){obj.select()},100);
				return false; ;
			}
		}
		if (dateArray[2].length<4){
			alert('Please enter full year (4 digits).');
			setTimeout(function(){obj.select()},100);
			return false; ;
		}
		str=dateArray[0]+'/'+dateArray[1]+'/'+dateArray[2];
		obj.value=str;
	}

/*--------------------------CALENDAR SCRIPT FOR DATE FIELD ---------------------------------*/

	var headerColor='#aaaaff';
	var daysColor='#aaaaaa';
	var bodyColor='#ffffdd';
	var todayColor='#000077';
	var hiliteColor='#ddddff';
	

	var month=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
	var thisMonth, thisYear, origDate, cutoffDate


	function makeCalendar(obj,dir,objShadow,objInput){
		if (obj.firstChild) obj.removeChild(obj.firstChild);
		
		if (cutoffDate!=''&&cutoffDate!=null) {
			var dateParts=cutoffDate.split('/');
			var mo=dateParts[0]-1;
			var dy=dateParts[1];
			var yr=dateParts[2];
			var cutoffDate=new Date(yr,mo,dy)
		} else {
			cutoffDate=new Date(); //----USE IF DATES IN THE PAST ARE NOT ALLOWED, set date to arbitrary date in past to allow past dates
		}
				
		switch(dir){
			case 1:
				thisMonth=thisMonth<11?thisMonth+1:0;
				thisYear=thisMonth==0?thisYear+1:thisYear
				today=new Date(thisYear,thisMonth,1);
				break;
			case -1:
				thisMonth=thisMonth>0?thisMonth-1:11;
				thisYear=thisMonth==11?thisYear-1:thisYear;
				today=new Date(thisYear,thisMonth,1);
				break;
			default:
				today=new Date()
				origDate=today;
				if (cutoffDate>today){
					var today=cutoffDate
				}
				thisMonth=today.getMonth();
				thisYear=today.getFullYear();
		}
	
		var dateArray=new Array(), monthsLength=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		if (Math.floor(today.getFullYear()/4)==today.getFullYear()/4) monthsLength[1]=29;
		var dayNum=today.getDate(), weekDay=today.getDay(), firstDay;
		while (dayNum>7){
			dayNum-=7;
		}
		firstDay=weekDay-dayNum+1;
		firstDay+=(7*(firstDay<0));
		for (i=0;i<42;i++) {
			if (i<firstDay) {
				dateArray[i]=document.createTextNode(' ');
			} else {
				if ((i-firstDay)<monthsLength[thisMonth]) dateArray[i]=document.createTextNode((i+1-firstDay).toString());
			}
		}
	
		var tbl=document.createElement('table');
			tbl.style.border='none';
			tbl.cellPadding='0px';
			tbl.cellSpacing='0px';
			tbl.style.width='100%';
			tbl.style.fontFamily='arial';
			tbl.style.fontSize='8pt';
			tbl.style.position='relative';
			
		var tbdy=document.createElement('tbody');
		
		var row1=document.createElement('tr');
		var c11=document.createElement('td');
			c11.innerHTML='&laquo;';
			c11.style.border='none';
			c11.style.paddingLeft='5px';
			c11.style.cursor='default';
			c11.style.paddingBottom='3px';
			c11.style.backgroundColor=headerColor;
			c11.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+headerColor+'")';
			c11.onclick=function(ev){
				makeCalendar(obj,-1,objShadow,objInput)
				if (document.all) {
					window.event.cancelBubble=true;
				} else {
					ev.stopPropagation();
				}
			}
		var c12=document.createElement('td');
			var ctr=document.createTextNode(month[thisMonth] + ' ' + thisYear);
			c12.style.border='none';
			c12.style.textAlign='center';
			c12.style.fontSize='10pt';
			c12.style.color='#000000';
			c12.style.fontWeight='bold';
			c12.colSpan=5;
			c12.appendChild(ctr);
			c12.style.backgroundColor=headerColor;
			c12.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+headerColor+'")';
		var c13=document.createElement('td');
			c13.style.border='none';
			c13.style.textAlign='right';
			c13.style.paddingRight='5px';
			c13.innerHTML='&raquo;';
			c13.style.paddingBottom='3px';
			c13.style.cursor='default';
			c13.style.backgroundColor=headerColor;
			c13.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+headerColor+'")';
			c13.onclick=function(ev){
				makeCalendar(obj,1,objShadow,objInput);
				if (document.all) {
					window.event.cancelBubble=true;
				} else {
					ev.stopPropagation();
				}
			}
		row1.appendChild(c11);
		row1.appendChild(c12);
		row1.appendChild(c13);
		
		var row2=document.createElement('tr');
		var c21=document.createElement('td');
			c21.innerHTML='S';
			c21.style.textAlign='center';
			c21.style.width='16%';
			c21.style.border='1px outset';
			c21.style.backgroundColor=daysColor;
			c21.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c22=document.createElement('td');
			c22.innerHTML='M';
			c22.style.textAlign='center';
			c22.style.width='14%';
			c22.style.border='1px outset';
			c22.style.backgroundColor=daysColor;
			c22.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c23=document.createElement('td');
			c23.innerHTML='T';
			c23.style.textAlign='center';
			c23.style.width='14%';
			c23.style.border='1px outset';
			c23.style.backgroundColor=daysColor;
			c23.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c24=document.createElement('td');
			c24.innerHTML='W';
			c24.style.textAlign='center';
			c24.style.width='14%';
			c24.style.border='1px outset';
			c24.style.backgroundColor=daysColor;
			c24.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c25=document.createElement('td');
			c25.innerHTML='T';
			c25.style.textAlign='center';
			c25.style.width='14%';
			c25.style.border='1px outset';
			c25.style.backgroundColor=daysColor;
			c25.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c26=document.createElement('td');
			c26.innerHTML='F';
			c26.style.textAlign='center';
			c26.style.width='14%';
			c26.style.border='1px outset';
			c26.style.backgroundColor=daysColor;
			c26.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
		var c27=document.createElement('td');
			c27.innerHTML='S';
			c27.style.textAlign='center';
			c27.style.width='14%';
			c27.style.border='1px outset';
			c27.style.backgroundColor=daysColor;
			c27.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="'+daysColor+'")';
	
		row2.appendChild(c21);
		row2.appendChild(c22);
		row2.appendChild(c23);
		row2.appendChild(c24);
		row2.appendChild(c25);
		row2.appendChild(c26);
		row2.appendChild(c27);
			
	
		tbdy.appendChild(row1);
		tbdy.appendChild(row2);
		
		var dateRow=new Array(), cell=new Array(), dateValue=new Array();
		
		for (j=0;j<dateArray.length;j++){
			if (j/7==Math.floor(j/7)){
				dateRow[Math.floor(j/7)]=document.createElement('tr');
				tbdy.appendChild(dateRow[Math.floor(j/7)]);
			}	
			cell[j]=document.createElement('td')
			cell[j].style.textAlign='center';
			cell[j].style.cursor='default';
			cell[j].appendChild(dateArray[j]);
			if (cell[j].innerHTML==origDate.getDate()&&origDate.getMonth()==today.getMonth()&&origDate.getFullYear()==today.getFullYear()) {
				cell[j].style.backgroundColor=todayColor;
				cell[j].style.color='white';
			}
			var thisDate=new Date(today.getFullYear(),today.getMonth(),dateArray[j].data);
			if(thisDate>=cutoffDate){
				cell[j].onclick=function(){
					if (this.innerHTML!='') objInput.value=((thisMonth+1)<10?'0':'') + (thisMonth+1)+ '/' + ((parseInt(this.innerHTML))<10?'0':'') + this.innerHTML + '/' + thisYear;
					objInput.focus();
					if (document.all) EOT(objInput);  //SEND TO END OF INPUT DATA. ROUTINE EOT PART OF COMBOBOX CODE
	
				}
				cell[j].onmouseover=function(){
					this.style.backgroundColor=hiliteColor;
				}
				cell[j].onmouseout=function(){
					this.style.backgroundColor=bodyColor;
				}
			} else {
				cell[j].style.color='#d5d5d5';
			}
			dateRow[Math.floor(j/7)].appendChild(cell[j]);
		}	
	
	
		tbl.appendChild(tbdy);
		obj.appendChild(tbl);
		objShadow.style.height=parseInt(obj.offsetHeight)+'px';
		
	}

	var z=0, a, b, c;
	
	function makeDateFields(node){

		if (!window.opera){
				  
			var inputs=document.getElementsByTagName('input');
			
			for (i=0;i<inputs.length;i++){
			
				if (inputs[i].getAttribute('type')=='date'){
					z=z+1;
					var n=inputs[i];
					var n2=document.createElement('span');
					var calBox=document.createElement('div');
					var calActivate=document.createElement('div');
					var calShadow=document.createElement('div');
					
					n2.style.marginRight='0px';
					n2.style.position='relative';
					n2.style.lineHeight='normal';
					n2.style.zIndex=500-z;
					n2.style.padding='1px';
					
					n.style.position='relative';
					n.style.verticalAlign='top';
					n.style.margin='0px';
					n.style.width=(n.offsetWidth-8) + 'px';
					n.onchange=function(){confDate(this,this.value);}
					
					calBox.style.position='absolute';
					calBox.style.border='2px outset';
					calBox.style.backgroundColor=bodyColor;
					calBox.style.width=Math.max((parseInt(n.offsetWidth)),120)+'px';
					calBox.style.top=(n.offsetHeight+1)+'px';
					calBox.style.left='0px';
					calBox.style.display='none';
					
					calShadow.style.width=Math.max((parseInt(n.offsetWidth)+2),122)+'px';
					calShadow.style.position='absolute';
					if (document.all){
						calShadow.style.top=parseInt(n.offsetHeight)+'px';
						calShadow.style.left='0px';
					} else {
						calShadow.style.top=(parseInt(n.offsetHeight)+4)+'px';
						calShadow.style.left='5px';
					}
					calShadow.style.backgroundColor='#000000';
					calShadow.style.filter='progid:DXImageTransform.Microsoft.Blur(PixelRadius="3", MakeShadow="true", ShadowOpacity="0.40")';
					calShadow.style.opacity='0.25';
					calShadow.style.display='none';
					
					calActivate.innerHTML='&#8230;';
					calActivate.style.border='1px solid #999999';
					calActivate.style.width='18px';//(parseInt(n.offsetHeight))+'px';
					calActivate.style.padding='0px';
					calActivate.style.textAlign='center';
					calActivate.style.height=(parseInt(n.offsetHeight)-2)+'px';
					calActivate.style.lineHeight=calActivate.style.fontSize;
					calActivate.style.overflow='hidden';
					calActivate.style.backgroundColor='#CCCCCC';
					calActivate.style.position='absolute';
					calActivate.style.top=document.all&&isLTIE8?'2px':'1px';
					calActivate.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="#AAAAAA")';
					calActivate.style.fontFamily='arial';
					calActivate.style.fontSize='10pt';
					calActivate.style.lineHeight='normal';
					//calActivate.style.left=parseInt(n.offsetWidth)-1+'px';
					calActivate.style.right='0px';
					calActivate.style.cursor='default';
					
					calActivate.onclick=function(ev){
						if (a) a.display='none';
						if (b) b.display='none';
						if (c) c.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="#AAAAAA")';
						(a=this.parentNode.getElementsByTagName('div')[2].style).display='block';
						(b=this.parentNode.getElementsByTagName('div')[1].style).display='block';
						(c=this.parentNode.getElementsByTagName('div')[0].style).filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#AAAAAA",endColorStr="#f3f3f3")';
						document.onclick=function(ev2){
							if (a) a.display='none';
							if (b) b.display='none';
							if (c) c.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="#AAAAAA")';
						};
						if (document.all) {
							window.event.cancelBubble=true;
						} else {
							ev.stopPropagation();
						}
						//makeCalendar(calBox,0,calShadow,n);
						makeCalendar(
							this.parentNode.getElementsByTagName('div')[2],
							0,
							this.parentNode.getElementsByTagName('div')[1],
							this.parentNode.getElementsByTagName('input')[0]
						)
					}
					
					n.parentNode.replaceChild(n2,n)
					n2.appendChild(n)
					n2.appendChild(calActivate);
					n2.appendChild(calShadow);
					n2.appendChild(calBox)
				}
			}
	   }	
	}
	
//-----------------------------COMBO BOX SCRIPTS---------------------------------------//

var selectedItem, itemNum=0, itemCount;

function activateComboBox(){
	var inputs=document.getElementsByTagName('input');
	createComboStyle();
	for (i=0;i<inputs.length;i++){
		if (inputs[i].getAttribute('type')=='combo'){
			z=z+1;
			var n=inputs[i];
			var n2=document.createElement('span');
			n2.style.position='relative';
			n2.style.lineHeight='normal';
			n2.style.zIndex=500-z;
			n.parentNode.replaceChild(n2,n)
			n2.appendChild(n);

			inputs[i].onfocus=function(){initComboBox(this)};
			inputs[i].onclick=function(e){showItems(e,this); hilite(e,this)}
			inputs[i].onkeyup=function(e){hilite(e,this)}
			inputs[i].onkeydown=function(e){processKeystroke(e,this)}
			
			inputs[i].style.width=(inputs[i].offsetWidth-26)+'px';

			var comboActivate=document.createElement('span');
					comboActivate.innerHTML='&#8230;';
					comboActivate.style.border='1px solid #999999';
					comboActivate.style.lineHeight='normal';
					comboActivate.style.overflow='hidden';
					//comboActivate.style.width='20px';
					comboActivate.style.width=(n2.offsetHeight)+'px'
					comboActivate.style.textAlign='center';
					comboActivate.style.height=(parseInt(inputs[i].offsetHeight)-2)+'px';
					comboActivate.style.backgroundColor='#CCCCCC';
					comboActivate.style.position='absolute';
					comboActivate.style.top=document.all?'1px':'-1px';
					comboActivate.style.filter='progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr="#f3f3f3",endColorStr="#AAAAAA")';
					comboActivate.style.fontFamily='arial';
					comboActivate.style.left=parseInt(inputs[i].offsetWidth-2)+'px';
					comboActivate.style.cursor='default';
					comboActivate.onclick=function(ev){
						var event='';
						if (document.all) {
							window.event.cancelBubble=true;
						} else {
							ev.stopPropagation();
						}
						initComboBox(this.previousSibling);
						showItems(event, this.previousSibling); 
						hilite(event,this.previousSibling);
					}
			
			inputs[i].parentNode.insertBefore(comboActivate,inputs[i].nextSibling);
			
			var dropWindow=document.createElement('div');
					dropWindow.className='drop';
					dropWindow.style.height='90px';
					dropWindow.style.width=(n2.offsetWidth+20)+'px';//'100%';
					dropWindow.style.marginLeft='1px';
					dropWindow.style.position='absolute'; 
					//dropWindow.style.top='21px'; 
					dropWindow.style.top=(n2.offsetHeight)+'px'; 
					dropWindow.style.left='-1px'; 
					dropWindow.style.overflow='auto'; 
					dropWindow.style.border='1px solid #AAAAAA'; 
					dropWindow.style.display='none';
					dropWindow.style.fontSize='10pt';
					dropWindow.style.backgroundColor='#EEEEEE';
					dropWindow.style.color='#000000';
					dropWindow.style.zIndex='10';
			
			inputs[i].parentNode.insertBefore(dropWindow,comboActivate.nextSibling); 

			var comboOptions=inputs[i].getAttribute('options').split('|');
				dropWindow.style.height=Math.min(90,comboOptions.length*18)+'px';
			for (j=0;j<comboOptions.length;j++){
				var newOption=document.createElement('div');
				newOption.style.padding='0px 4px';
				newOption.style.height='18px';
				newOption.style.textTransform='capitalize';
				eval('newOption.onclick=function(){selItem(this,'+(j+1)+')}');
				//var optionText=document.createTextNode(comboOptions[j]);
				//newOption.appendChild(optionText);
				newOption.innerHTML=comboOptions[j];
				dropWindow.appendChild(newOption);
			}
		}
	}
				
	arr=document.getElementsByTagName('div');
	for (i=0;i<arr.length;i++){
		if (arr[i].parentNode.className=='drop'){
			arr[i].onmouseover=function(){this.className='over'; selectedItem=this.innerHTML};
			arr[i].onmouseout=function(){this.className='off';};

		}
	}
}

function createComboStyle(){
	var pa= document.getElementsByTagName('head')[0] ;
	var el= document.createElement('style');
	var str='.drop .off{background-color: #EEEEEE;color: #000000;}.drop .over{	background-color: #000000;	color: #FFFFFF;}';

	el.type= 'text/css';
	el.media= 'screen';
	if(el.styleSheet) el.styleSheet.cssText= str;// IE method
	else el.appendChild(document.createTextNode(str));// others
	pa.appendChild(el);
	return el;
}

function initComboBox(obj){

	itemBox=obj.parentNode.getElementsByTagName('div')[0];
	items=itemBox.getElementsByTagName('div');
	itemCount=items.length;
	comboBox=obj;
	hilite(0,obj);
				
}

function showItems(e,obj){
		if (window.event){
			var e=window.event;
			var obj=e.srcElement;
		} else {
			obj=e.target;
		}
	if (e.keyCode!=13) {
		if (e.type=='click' && itemBox.style.display=='block') {
			itemBox.style.display='none';
		} else {
			itemBox.style.display='block';
		}
	}
	document.onclick=function(){itemBox.style.display='none';}
}

function scrollItems(x){
	y=itemBox.scrollTop;
	pos=-y+x*20;
	if (pos>80){
		itemBox.scrollTop=(x-4)*18;//itemBox.scrollTop+18;
	} else if (pos<0) {
		itemBox.scrollTop=(x)*18;//itemBox.scrollTop-18;
	}
}

function hilite(e,obj){
		if (window.event){
			var e=window.event;
		}
	if (e.keyCode!=38 && e.keyCode!=40){
	clearAllSelected(obj,itemCount);
		for (var j=0;j<=itemCount-1; j++){
			if (obj.value.length>0 && obj.value.toLowerCase()==items[j].innerHTML.substring(0,obj.value.length).toLowerCase()){
				items[j].className='over';
				scrollItems(j);
				selectedItem=items[j].innerHTML;
				itemNum=j;
				break;
			}
		}
	}
}

function clearAllSelected(obj, itemCount){
			for (var j=0;j<=itemCount-1; j++) items[j].className='off'
			selectedItem='';
}

function processKeystroke(e, obj){
		if (window.event){
			var e=window.event;
			var obj=e.srcElement;
		} else {
			obj=e.target;
		}
	if (e.keyCode==38 && itemNum>0){
			if (itemBox.style.display=='block') itemNum-=1;
			showItems(e, obj);
			clearAllSelected(obj,itemCount);
			items[itemNum].className='over';
			scrollItems(itemNum);
			selectedItem=items[itemNum].innerHTML;
	}
	if (e.keyCode==40 && itemNum<itemCount-1){
			if (itemBox.style.display=='block') itemNum+=1;
			showItems(e, obj);
			clearAllSelected(obj,itemCount);
			items[itemNum].className='over';
			scrollItems(itemNum);
			selectedItem=items[itemNum].innerHTML;
	}
	showItems(e, obj);
	if (e.keyCode==13 && itemBox.style.display=='block'){
		e.returnValue=false;
		obj.value=selectedItem!=''?selectedItem:obj.value;
		clearAllSelected(obj,itemCount);
		itemBox.style.display='none';
	}
	if (e.keyCode==9 || e.keyCode==27){
		obj.value=selectedItem!=''?selectedItem:obj.value;
		clearAllSelected(obj,itemCount);
		itemBox.style.display='none';
		itemNum=0;
	}
}
function selItem(obj,num){
		comboBox.value=selectedItem;
		itemNum=num;
		comboBox.focus();
		itemBox.style.display='none';
		if (document.all) EOT(comboBox);
}

function EOT(txt) {
  var range = txt.createTextRange();
  range.move("textedit");
  range.select();
}

//---------------------------- CONTACT MANAGER -----------------------//

	if (window.ActiveXObject) {
		var srvrConnect=new ActiveXObject('Microsoft.XMLHTTP');
	} else if (window.XMLHttpRequest) {
		var srvrConnect=new XMLHttpRequest();
	}

function getList(type){
	srvrConnect.open('post','_processAjax.cfm',0);
	srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	srvrConnect.send('act=19&type='+type);
	document.body.appendChild(document.getElementById('pot_'+type));
	document.getElementById('pot_'+type).innerHTML=srvrConnect.responseText;
	if (isLTIE7){
		with(document.getElementById('pot_'+type)){
		style.display='block';
		if (clientHeight>200){
			style.height='200px';
			style.overflow='auto';
		}
		style.display='none';
		}
	}
	var potMatches=document.getElementById('pot_'+type).getElementsByTagName('div');
	for (i=0;i<potMatches.length;i++){
		if (potMatches[i].className=='pot'){
			bckgrdclr=(i/2!=Math.floor(i/2))?'#F0F0F0':'#FFFFFF' ;
			potMatches[i].style.backgroundColor=bckgrdclr;
			potMatches[i].style.padding='2px 5px';
			potMatches[i].style.cursor='default';
		}
	}
	with (document.getElementById('pot_'+type)){
		setAttribute('corners','round,0,#CCCCFF,2,0.40');
		if (document.getElementById('pot_'+type).addEventListener) {
			addEventListener('DOMMouseScroll',function(event){stopScroll(event)},false);
			addEventListener('mousewheel',function(event){stopScroll(event)},false);
		} else if (attachEvent) {
			attachEvent('onmousewheel',function(event){stopScroll(event)},false);
		}
	}
	makeCorners(document.getElementById('pot_'+type));
	var potMatches=document.getElementById('pot_'+type).getElementsByTagName('div');
	for (i=0;i<potMatches.length;i++){
		if (potMatches[i].className=='pot'){
			potMatches[i].setAttribute('type',type);
			potMatches[i].onmouseover=function(){this.style.backgroundColor='#000000';this.style.color='#FFFFFF';}
			if (i/2!=Math.floor(i/2)){
				potMatches[i].onmouseout=function(){this.style.backgroundColor='#F0F0F0';this.style.color='#000000';}
			} else {
				potMatches[i].onmouseout=function(){this.style.backgroundColor='#FFFFFF';this.style.color='#000000';}
			}
			potMatches[i].onclick=function(){makeMatch(this)}
		}
	}
}

var objToDel, selRange;

function enableClickSel(type){
		if (document.getElementById('mentorTbl')){
			var spans=document.getElementById('mentorTbl').getElementsByTagName('span');
		} else if (document.getElementById('menteeTbl')){
			var spans=document.getElementById('menteeTbl').getElementsByTagName('span');
		} else if (document.getElementById('sponsorTbl')){
			var spans=document.getElementById('sponsorTbl').getElementsByTagName('span');
		}
		for (i=0;i<spans.length;i++){
			if (spans[i].getAttribute('teeID')!=null||spans[i].getAttribute('menteeID')!=null||spans[i].getAttribute('torID')!=null){
				spans[i].setAttribute('onmousedown',null);
				if (spans[i].addEventListener) {
					spans[i].addEventListener('click',function(event){clickSel(event)},false);
				} else if (spans[i].attachEvent) {
					spans[i].attachEvent('onclick',function(event){clickSel(event)},false);
				} else {
					spans[i].onclick=function (event){clickSel(event)}
				}
			}
		}
}
function clickSel(e){
	var e=e?e:window.event;
	var obj=e.srcElement?e.srcElement:e.target;
	if (!!window.getSelection) { // FF, Safari, Chrome, Opera
		 var sel = window.getSelection();
		 selRange = document.createRange();
		 selRange.selectNodeContents(obj);
		 sel.removeAllRanges();
		 sel.addRange(selRange);
	  } else if (!!document.selection) { // IE
		 document.selection.empty();
		 selRange = document.body.createTextRange();
		 selRange.moveToElementText(obj);
		 selRange.select();
	  }
}

function delTee(e){
	var e=e?e:window.event;
	if(e.keyCode==46){
		var delNode=selRange.parentElement?selRange.parentElement():selRange.commonAncestorContainer;
		var menteeID=delNode.getAttribute('teeID')?delNode.getAttribute('teeID'):delNode.getAttribute('menteeID');
		var mentorID=delNode.parentNode.getAttribute('recID');
		var td=delNode.parentNode;
		delNode.parentNode.removeChild(delNode);
		var newHTML=td.innerHTML;
		if (newHTML=='') document.getElementById('mentorMatched-'+mentorID).checked=false;

		var sendStr='menteeID='+menteeID+'&mentorID='+mentorID+'&names='+newHTML+'&act=4';
		var resp=getXML(sendStr,'_processAjax.cfm');
		//crawlXML(resp);
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) obj.focus();
		}

	}
}

function delTor(e){
	var e=e?e:window.event;
	if(e.keyCode==46){
		var delNode=selRange.parentElement?selRange.parentElement():selRange.commonAncestorContainer;
		var mentorID=delNode.parentNode.getAttribute('mentorID');
		var menteeID=delNode.parentNode.id.replace(/menteesMatch-/,'');
		var td=delNode.parentNode;
		delNode.parentNode.removeChild(delNode);
		document.getElementById('menteeMatched-'+menteeID).checked=false;
		var newHTML=td.innerHTML;

		var sendStr='menteeID='+menteeID+'&mentorID='+mentorID+'&names='+newHTML+'&act=4.1';
		var resp=getXML(sendStr,'_processAjax.cfm');
		//crawlXML(resp);
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) obj.focus();
		}

	}
}


var selMent;

function show(e){
	if(!e) e=window.event;
	if (e.srcElement) {
		var obj=e.srcElement
	} else {
		var obj=e.target
	}
	selMent=obj.id;
	mouseX=e.clientX;
	mouseY=e.clientY;
	var type=obj.id.indexOf('mentee')!=-1?'mentors':'mentees';
	var winH=document.documentElement.clientHeight;
	with (document.getElementById('pot_'+type)){
		style.display='block';
		style.top=mouseY+getScrollXY()[1]-mouseY/winH*offsetHeight+'px';
		style.left=mouseX+'px';
	}
	document.body.onclick=function(){document.getElementById('pot_'+type).style.display='none'; document.body.onclick=null;};
}

function stopScroll(e){
   e = e ? e : window.event;
	if(e.stopPropagation)
	 e.stopPropagation();
	if(e.preventDefault)
	 e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

function makeMatch(obj){
	if (selMent.indexOf('mentors')!=-1){
	
		selMentor=selMent.replace(/mentorsMatches-/,'');
		var selMentee=obj.id;
		document.getElementById('mentorMatched-'+selMentor).checked=true;
		var newMatch=document.createElement('span');
		newMatch.innerHTML=obj.innerHTML;
		newMatch.teeID=selMentee;
		document.getElementById('mentorsMatches-'+selMentor).appendChild(newMatch);
		enableClickSel('mentees');
		var newHTML=document.getElementById('mentorsMatches-'+selMentor).innerHTML;
		var sendStr='menteeID='+selMentee+'&mentorID='+selMentor+'&names='+newHTML+'&act=3';
		var resp=getXML(sendStr,'_processAjax.cfm');
		//crawlXML(resp);
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) obj.focus();
		}
	
	} else if (selMent.indexOf('mentees')!=-1) {
	
		selMentee=selMent.replace(/menteesMatch-/,'');
		var selMentor=obj.id;
		document.getElementById('menteeMatched-'+selMentee).checked=true;
		var newMatch=document.createElement('span');
		newMatch.innerHTML=obj.innerHTML;
		newMatch.torID=selMentor;
		document.getElementById('menteesMatch-'+selMentee).innerHTML='';
		document.getElementById('menteesMatch-'+selMentee).appendChild(newMatch);
		var newHTML=document.getElementById('menteesMatch-'+selMentee).innerHTML;
		var sendStr='menteeID='+selMentee+'&mentorID='+selMentor+'&name='+newHTML+'&act=3.1';
		var resp=getXML(sendStr,'_processAjax.cfm');
		//crawlXML(resp);
		var chk=resp.getElementsByTagName('success')[0].firstChild.data;
		if (chk!='true'){
			document.getElementById('response').innerHTML=resp.getElementsByTagName('message')[0].firstChild.data;
			if (confirm("An error occurred while attempting to save your data. To try again, click 'OK'. If this problem persists, please click 'Cancel' and  contact Christian Mentors for assistance.")) obj.focus();
		}

	}

}
function sort(col,type,obj,teeOrTor){
		var headers=obj.parentNode.getElementsByTagName('td');
		if (type=='mentors'){
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5&col='+col+'&type='+type);
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
			for (x=1;x<7;x++){
				headers[x].className='contactHeader';
			}
			obj.className='contactHeaderSelect';
		} else if (type=='mentees') {
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5&col='+col+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
			for (x=1;x<8;x++){
				headers[x].className='contactHeader';
			}
			obj.className='contactHeaderSelect';
		} else if (type=='matches'){
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=8&col='+col+'&type='+type+'&teeOrTor='+teeOrTor);
			document.getElementById('matchList').innerHTML=srvrConnect.responseText;
		}
}
function sort_v2(col,type){
	if (type=='mentors'){
		document.getElementById('mentorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('mentorTbl').style.opacity='0.50';
	} else if (type=='sponsors') {
		document.getElementById('sponsorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('sponsorTbl').style.opacity='0.50';
	} else {
		document.getElementById('menteeTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('menteeTbl').style.opacity='0.50';
	}
	setTimeout(function() {sort_v2b(col,type)},10)
}
function sort_v2b(col,type){
		if (type=='mentors'){
			document.body.removeChild(document.getElementById('pot_mentees'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2&col='+col+'&type='+type);
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			if (document.getElementById('pot_mentors')) document.body.removeChild(document.getElementById('pot_mentors'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2&col='+col+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='sponsors') {
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2&col='+col+'&type='+type);
			document.getElementById('sponsorList').innerHTML=srvrConnect.responseText;
		}
		var pots=(type=='mentors')?'mentees':'mentors';
		enableClickSel();
		getList(pots);
}

function sort_v3(col,type){
	if (type=='sponsors') {
		document.getElementById('sponsorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('sponsorTbl').style.opacity='0.50';
	} else {
		document.getElementById('menteeTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('menteeTbl').style.opacity='0.50';
	}
	setTimeout(function() {sort_v3b(col,type)},10)
}
 function sort_v3b(col,type){
		if (type=='children') {
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2&col='+col+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='sponsors') {
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2&col='+col+'&type='+type);
			document.getElementById('sponsorList').innerHTML=srvrConnect.responseText;
		}
}

function filter(col,type){
	if (type=='mentors'){
		document.getElementById('mentorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('mentorTbl').style.opacity='0.50';
	} else {
		document.getElementById('menteeTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('menteeTbl').style.opacity='0.50';
	}
	setTimeout(function() {filterb(col,type)},10)
}
function filterb(obj,type){
		var alph=obj.innerHTML;
		if (type=='mentors'){
			document.body.removeChild(document.getElementById('pot_mentees'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2.1&alph='+alph+'&type='+type);
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.body.removeChild(document.getElementById('pot_mentors'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2.1&alph='+alph+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		}
		var pots=(type=='mentors')?'mentees':'mentors';
		enableClickSel();
		getList(pots);
}

function groupFilter(col,type){
	if (type=='mentors'){
		document.getElementById('mentorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('mentorTbl').style.opacity='0.50';
	} else {
		document.getElementById('menteeTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('menteeTbl').style.opacity='0.50';
	}
	setTimeout(function() {groupFilter2(col,type)},10)
}
function groupFilter2(obj,type){
		var grp=obj.value;
		if (type=='mentors'){
			document.body.removeChild(document.getElementById('pot_mentees'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2.2&grp='+grp+'&type='+type);
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.body.removeChild(document.getElementById('pot_mentors'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.2.2&grp='+grp+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		}
		var pots=(type=='mentors')?'mentees':'mentors';
		enableClickSel();
		getList(pots);
}

function typeFilter(col,type){
	if (type=='mentors'){
		document.getElementById('mentorTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('mentorTbl').style.opacity='0.50';
	} else {
		document.getElementById('menteeTbl').style.filter='alpha(opacity=50)'; 
		document.getElementById('menteeTbl').style.opacity='0.50';
	}
	setTimeout(function() {typeFilter2(col,type)},10)
}
function typeFilter2(obj,type){
		var grp=obj.value;
		if (type=='mentors'){
			document.body.removeChild(document.getElementById('pot_mentees'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.3&grp='+grp+'&type='+type);
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.body.removeChild(document.getElementById('pot_mentors'));
			srvrConnect.open('post','_processAjax.cfm',0);
			srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			srvrConnect.send('act=5.3&grp='+grp+'&type='+type);
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		}
		var pots=(type=='mentors')?'mentees':'mentors';
		enableClickSel();
		getList(pots);
}

function delContact(type,id){
	if (type=='mentors' && document.getElementById('mentorMatched-'+id).checked==true){
		alert('You must disassociate this mentor from their mentee before deleting the record.')
		return false;
	}
	if (confirm('You have chosen to delete this contact. Are you sure you wish to continue?')){
		srvrConnect.open('post','_delContact.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('type='+type+'&id='+id);
		if (type=='mentors'){
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		}
	} else {
		return;
	}
}

function delContact2(type,id){
	if (type=='mentors' && document.getElementById('mentorMatched-'+id).checked==true){
		alert('You must disassociate this mentor from their mentee before deleting the record.')
		return false;
	}
	if (confirm('You have chosen to delete this contact. Are you sure you wish to continue?')){
		srvrConnect.open('post','_delContact2.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('type='+type+'&id='+id);
		if (type=='mentors'){
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='orphans') {
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='sponsors') {
			document.getElementById('sponsorList').innerHTML=srvrConnect.responseText;
		}
	} else {
		return;
	}
}

function selContact(type,id){
		srvrConnect.open('post','_selContact.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send('type='+type+'&id='+id);
}

function selAll(type){
		srvrConnect.open('post','_selAllContacts.cfm',0);
		var sendStr='type='+type;
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send(sendStr);
		//document.getElementById('response').innerHTML=srvrConnect.responseText;
		if (type=='mentors'){
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='sponsors') {
			document.getElementById('sponsorList').innerHTML=srvrConnect.responseText;
		}
}
function deselAll(type){
		srvrConnect.open('post','_deselAllContacts.cfm',0);
		var sendStr='type='+type;
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		srvrConnect.send(sendStr);
		if (type=='mentors'){
			document.getElementById('mentorList').innerHTML=srvrConnect.responseText;
		} else if (type=='mentees') {
			document.getElementById('menteeList').innerHTML=srvrConnect.responseText;
		} else if (type=='sponsors') {
			document.getElementById('sponsorList').innerHTML=srvrConnect.responseText;
		}
}

function sendEmail(type){
		msg=document.getElementById('content1').value;
		srvrConnect.open('post','_sendEmail.cfm',0);
		srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		msg=msg.replace(/&nbsp;/g,' ');
		srvrConnect.send('type='+type+'&msg='+msg);
		//document.getElementById('response').innerHTML=srvrConnect.responseText;
		if (srvrConnect.responseText.indexOf('Send OK') != -1){
			alert('Your email was sent successfully!');
			document.getElementById('content1').value='';
		} else {
			alert('There was a problem and your email was not sent.')
		}
}

/* ----------------- EMAIL Obfuscator -----------------------------------*/

function stumpIt(theName,theExtras,theLink,theDomain) {
	if (theDomain==''){
		var theDomain ="christianmentors.org";
	}
	var theEmail = theName+"@"+theDomain;
	if (theName == ""){
		theName = "ERROR";
		theLink = "ERROR";
		myEmail = theName;
		myLink = theLink;
	}else{
		if ((theExtras == "") && (theLink =="")){
			myEmail = theEmail;
			myLink = theEmail;
		}
		if ((theLink == "") && (theExtras != "")){
			myLink = theEmail;
			myEmail = theEmail+theExtras;
		}
		if 	((theLink != "") && (theExtras != "")){
			myLink = theLink;
			myEmail = theEmail+theExtras;
		}
		if 	((theLink != "") && (theExtras == "")){
			myLink = theLink;
			myEmail = theEmail;
		}
	}
	document.write('<a href=mailto:' + myEmail + '>' + myLink + '</a>');
}
