d=document;
processURL = '/process.inc';
msgsScrollBar = findStyleClass('#notesbodydiv').overflow;

function findStyleClass(n) {
	var mysheet=document.styleSheets[0]
	var myrules=mysheet.cssRules? mysheet.cssRules: mysheet.rules
	for (i=0; i<myrules.length; i++){
		if(myrules[i].selectorText.toLowerCase()==n){ //find target rule
			targetrule=myrules[i]
			break;
		}
	}
	return targetrule
}

function toggleView(objId,act) {
	obj = d.getElementById(objId);
	obj.style.visibility=act
}

function hideBios() {
	var bioDiv;
	bioDiv = document.getElementById('bioDiv');
	if(bioDiv) {
		for(i=2; i < bioDiv.childNodes.length ; i++) {
			if(bioDiv.childNodes[i].nodeName == "DIV") {bioDiv.childNodes[i].style.visibility = 'hidden';}
		}
	}
}
function showBio(bio) {
	hideBios();
	obj = d.getElementById(bio);
	act = 'hidden';
	if(obj) {
	if(obj.style.visibility=='hidden') {
		act = 'visible';
	} 
	
	obj.style.visibility = act;
	}
	
}
function infoDivStartTimer(topic,e,yoffset) {
	//InnerHTML into popup (title style) div
	obj = d.getElementById('infoDiv');

	switch(topic) {
		case 'header':
			obj.innerHTML = "The Sonoma Valley Fund is part of Community Foundation Sonoma County and shares its professional knowledge of financial and philanthropic services. With more than 20 yerars experience, Community Foundation Sonoma County oversees assets of more than $133 million and a cumulative grantmaking total of of more than $81 million. As part of the Community Foundation, the Fund is part of a 501(c)(3) charitable organization with a board of directors and full financial and legal accountability.";
			break;
		case '1':
			obj.innerHTML = "The Fund is flexible in responding to your interests. It offers many types of programs to support diverse charitable aims. For example, you can make an unrestricted donation to the Fund, endow a favorite nonprofit organization or cause, establish a scholarship fund, or set up a donor-advised fund. And the programs you support don't need to be exclusively local; your funds can affect charities anywhere around the globe. It's up to you. Moreover, when you give through the Fund, you work with Community Foundation staff, people with the know-how and experience to help you meet your philanthropic goals.";
			break;
		case '2':
			obj.innerHTML = "The Fund provides a resource for donors who wish to make charitable gifts in their estate plan to preserve the quality of life that they have enjoyed here in our Valley. The Directors of the Fund are residents of the Valley who, through a community-based process, will decide on the best use of the donated funds or will assure that your wishes for the use of your funds will be carried out after your lifetime.";
			break;
		case '3':
			obj.innerHTML = "You can become a Friend of the Sonoma Valley Fund by making a gift. You will receive a newsletter, be invited to contribute your ideas and attend our annual event, and join others to support a process that nurtures organizations that are vital to our community's well-being.";
			break;
		case '4':
			obj.innerHTML = "The Sonoma Valley Fund will be there in perpetuity, able to adapt to the changing needs of our community.";
			break;
		case '5':
			obj.innerHTML = "The Fund's annual grants to Sonoma Valley nonprofits will increase in number over the years through the growth of its endowment. Its endowment has been established with the Community Foundation, and through prudent investment, the endowment will grow and become a long-term community resource. All gifts are, of course, tax deductible to the extent allowed by law.";
			break;
		case '6':
			obj.innerHTML = "";
			break;

	}

	// Set div position vars
	var tempX = 0;
	var tempY = 0;
	// Set to mouse position
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}
	// Do not allow negative numbers
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}

	// Set top and left position
	
	switch (topic) {
		case '1':
			var xoffset = xoffset || 25;
			var yoffset = yoffset || -115;	
			break;
		case '2':
			var xoffset = xoffset || 25;
			var yoffset = yoffset || -75;	
			break;
		case '3':
			var xoffset = xoffset || 25;
			var yoffset = yoffset || -55;	
			break;
	}
	
	var xoffset = xoffset || 15;
	var yoffset = yoffset || -15;
	
	
	var objHolder = obj;
	obj.style.top  = (tempY + yoffset) + 'px';
	obj.style.left = (tempX + xoffset) + 'px';
	infoDivTimer = window.setTimeout("showInfo()",500);
}

function showInfo() {
	obj = d.getElementById('infoDiv');
	obj.style.visibility = 'visible';

}

function resetBoardMembers() {
	obj = d.getElementById('boardMembers');
	oParent = obj.parentNode;
	oParent.removeChild(obj);
	oParent.appendChild(obj);
	obj.style.left='45px';
	obj.style.top='130px';
	hideBios();
	toggleView('boardMembers','visible');
}

function openControlWindow() {
	o = controlWindow;
	oParent = o.parentNode;
	oParent.removeChild(o);
	oParent.appendChild(o);

	if(controlWindow.id == 'loginDiv') {
		o.style.left='20px';
		o.style.top='100px';
	} else {
		o.style.left='30px';
		o.style.top='150px';
	}
	o.style.visibility = 'visible';
	if (o.id=='loginDiv') {d.getElementById('loginName').focus()}
}

function bring2front(that,byId,focusTarget) {
	if(byId) that = d.getElementById(that);
	oParent = that.parentNode;
	if(oParent.lastChild != that) {
		oParent.removeChild(that);
		oParent.appendChild(that);
		if(focusTarget) {
			focusTarget.focus();
			focusTarget.select();
		}
	}
}
function sendLogin() {

	loginNameValue = d.getElementById('loginName').value;
	loginPasswordValue = d.getElementById('loginPassword').value;
	d.getElementById('loginName').value = '';
	d.getElementById('loginPassword').value = '';
	d.getElementById('loginName').blur();
	d.getElementById('loginPassword').blur();
	url = processURL+'?login='+loginNameValue+'&password='+loginPasswordValue
	//alert(url);
	loadXMLDoc(url, verifyLogin);
}

//core basic processing for ajax request. Called from loadXMLDoc
function verifyLogin() {
	// only if req shows "complete"

	if (req.readyState == 4) {
		// only if "OK"

		if (req.status == 200) {

			// ...processing statements go here...
			response  = req.responseText;
			if(response == 'Invalid name or password. Please try again') {
				alert(response)
			} else {
				userName = response;
				d.getElementById('welcomeMenuTitleText').innerHTML = 'Welcome '+userName;
				controlWindow.style.visibility = 'hidden';
				controlWindow = d.getElementById('welcomeMenuDiv');
				openControlWindow();
				url = processURL+'?loadNotes';
				loadXMLDoc(url, loadNotes);
			}
		} else {
			//alert("There was a problem retrieving the XML data:\n" + req.statusText);
			alert('There was a problem logging in. Please try again');
		}
	}
}

function showMessageCenter() {
	url = processURL+'?loadNotes';
	loadXMLDoc(url, loadNotes);
	toggleView('notesDiv','visible')
	bring2front('notesDiv',true)
}

function loadNotes()	{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			html = req.responseText
			notes = d.getElementById('notesBodyDiv');
			notes.innerHTML = html;
		} else {
			alert("There was a problem retrieving the data");
		}
	}
}

function toggleDisplay(noteId) {
	subjectId = 'subject_'+noteId;
	subjectBlock = d.getElementById(subjectId);
	bodyId = 'body_'+noteId;
	msgBlock = d.getElementById(bodyId);
	btnId = 'toggleBtn_'+noteId;
	toggleBtn = d.getElementById(btnId);

	if(msgBlock.style.display=='none') {
		toggleBtn.innerHTML = '[-]';
		msgBlock.style.display='block'
		if (subjectBlock.className == 'unReadNote') {
			url = processURL+'?markRead='+noteId;
			loadXMLDoc(url, showSaving);
			subjectBlock.className = 'readNote'
		}

	}
	else{
		toggleBtn.innerHTML = '[+]';
		msgBlock.style.display='none'
	}
}

function logout() {
	confirmed = confirm('Are you sure you want to log out?');
	if (confirmed) {
		url = processURL+'?logout';
		loadXMLDoc(url,alertResponse);
		d.getElementById('notesDiv').style.visibility = 'hidden';
		controlWindow.style.visibility = 'hidden';
		controlWindow = d.getElementById('loginDiv');
		if(d.getElementById('emailList_border')) emailListWindow.closeBox.closeContainer();
		if(d.getElementById('viewEmail_border')) viewEmailWindow.closeBox.closeContainer();
	}else{
		return false;
	}
}

function openPostAnote() {
	postAnote = d.getElementById('postAnoteDiv')
	bring2front(postAnote);
	postAnote.style.visibility = 'visible';
	subject = d.getElementById('postAnoteSubject').value=''
	message = d.getElementById('postAnoteMsg').value=''
	d.getElementById('postAnoteSubject').focus();
}

function submitPostAnote() {
	postAnote = d.getElementById('postAnoteDiv');

	subject = d.getElementById('postAnoteSubject').value;
	subject = subject.replace(/&/g,"*am*");
	subject = subject.replace(/=/g,"*eq*");
	subject = subject.replace(/\+/g,"*pl*");
	subject = subject.replace(/\n/g,"*lb*");
	//subject = subject.replace(/\'/g,"*quot*");

	message = d.getElementById('postAnoteMsg').value;
	message = message.replace(/&/g,"*am*");
	message = message.replace(/=/g,"*eq*");
	message = message.replace(/\+/g,"*pl*");
	message = message.replace(/\n/g,"*lb*");
	//message = message.replace(/\'/g,"*quot*");

	url = processURL+'?postAnote&subject='+subject+'&message='+message

	 //alert(url);
	loadXMLDoc(url,insertNewMessage);
	postAnote.style.visibility = 'hidden';
}

function insertNewMessage() {
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			response = req.responseText
			notes = d.getElementById('notesBodyDiv');
			notes.innerHTML = response+notes.innerHTML;
		} else {
			alert("There was a problem sending your data.\n Please try again");
		}
	}
}

function editNote(noteId,subject,msg) {
	d.getElementById('updateAnoteId').value = noteId;
	d.getElementById('updateAnoteSubject').value = subject;
	msg = msg.replace(/<br>/g,'\n');
	d.getElementById('updateAnoteMsg').value = msg;
	updateAnote = d.getElementById('updateAnoteDiv');
	bring2front(updateAnote);
	updateAnote.style.visibility = 'visible';
}

function submitUpdateAnote() {
	updateAnote = d.getElementById('updateAnoteDiv');
	noteId = d.getElementById('updateAnoteId').value

	subject = d.getElementById('updateAnoteSubject').value;
	subject = subject.replace(/&/g,"*am*");
	subject = subject.replace(/=/g,"*eq*");
	subject = subject.replace(/\+/g,"*pl*");
	subject = subject.replace(/\n/g,"*lb*");

	message = d.getElementById('updateAnoteMsg').value;
	message = message.replace(/&/g,"*am*");
	message = message.replace(/=/g,"*eq*");
	message = message.replace(/\+/g,"*pl*");
	message = message.replace(/\n/g,"*lb*");

	url = processURL+'?updateAnote&noteId='+noteId+'&subject='+subject+'&message='+message

	loadXMLDoc(url,processUpdateAnote);
	updateAnote.style.visibility = 'hidden';
}

function processUpdateAnote() {
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			$response = req.responseText
			// ...processing statements go here...
			if($response.indexOf('success') > 0) {
				$response = $response.split('|');
				$noteId = $response[0];
				$subject = $response[1];
				$message = $response[2];
				$subjectLine = "<table width='100%' border=0><tr><td>"
				$subjectLine += $subject
				$subjectLine += "</td><td><div style='float:right;'>";
				$subjectLine += "<img src='img/edit.gif' height='12px' margin-left='2px;' title='Edit' style='cursor:pointer;' onclick=\"event.cancelBubble=true;editNote('"+$noteId+"','"+$subject+"','"+$message+"')\"> ";
				$subjectLine += "<img src='img/trashcan.jpg' title='Delete' margin-left='2px;' height='12px' style='cursor:pointer;' onclick=\"event.cancelBubble=true;deleteNote('"+$noteId+"','"+$subject+"')\">"
				$subjectLine += "</div></td></tr></table>";
				$subjectId = "subject_"+$noteId;
				$messageId =  "body_"+$noteId;
				d.getElementById($subjectId).innerHTML = $subjectLine
				d.getElementById($messageId).innerHTML = $message

				/*$alertMsg = $response[3];
				$alertMsg = $alertMsg.replace(/<br>/g,'\n');
				alert($alertMsg);*/
			} else {
				alert($response);
			}
		} else {
			alert("There was a problem sending your data.\n Please try again");
		}
	}
}

function deleteNote(noteId,subject) {
	confirmDeleteNote = confirm('Are you sure you wish to delete the note "'+subject+'" ?')
	url = processURL+"?deleteAnote&noteId="+noteId;
	if (confirmDeleteNote) loadXMLDoc(url,removeDeletedMessage);
}
function removeDeletedMessage() {// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			response = req.responseText
			if(response.indexOf('success') > 0) {
				noteId = response.split('|')[0];
				noteDivId = "noteDiv_"+noteId
				noteDivNode = d.getElementById(noteDivId);
				oParent = noteDivNode.parentNode;
				oParent.removeChild(noteDivNode);
			} else {
				alert(response);
			}
		} else {
			alert("There was a problem sending your data.\n Please try again");
		}
	}
}

function sendContactRequest() {
	$nameTxt = convertGetVar(d.emailInfoFrm.nameTxt.value)
	$emailTxt = convertGetVar(d.emailInfoFrm.emailTxt.value)
	$phoneTxt = convertGetVar(d.emailInfoFrm.phoneTxt.value)
	$legacyChk = d.emailInfoFrm.legacyChk.checked
	$currentChk = d.emailInfoFrm.currentChk.checked
	$partnerChk = d.emailInfoFrm.partnerChk.checked
	$incomeChk = d.emailInfoFrm.incomeChk.checked
	$taxChk = d.emailInfoFrm.taxChk.checked
	$estateChk = d.emailInfoFrm.estateChk.checked
	$consultChk = d.emailInfoFrm.consultChk.checked
	$commentsTar = convertGetVar(d.emailInfoFrm.commentsTar.value)
	//$commentsTar = $commentsTar.replace(/\n/g, "<br />")
	$ccMeChk = d.emailInfoFrm.ccMeChk.checked
	url = processURL+'?emailInfo&nameTxt=' +$nameTxt+ '&\
emailTxt=' +$emailTxt+ '&\
phoneTxt=' +$phoneTxt+ '&\
legacyChk=' +$legacyChk+ '&\
currentChk=' +$currentChk+ '&\
partnerChk=' +$partnerChk+ '&\
incomeChk=' +$incomeChk+ '&\
taxChk=' +$taxChk+ '&\
estateChk=' +$estateChk+ '&\
consultChk=' +$consultChk+ '&\
commentsTar=' +$commentsTar+ '&\
ccMeChk=' +$ccMeChk
	loadXMLDoc(url)
	d.emailInfoFrm.reset()
	contactUsWindow.closeBox.closeContainer();
}

function contribute() {
	$nameTxt = convertGetVar(d.contributeFrm.nameTxt.value)
	$emailTxt = convertGetVar(d.contributeFrm.emailTxt.value)
	$phoneTxt = convertGetVar(d.contributeFrm.phoneTxt.value)
	$service = getCheckedValue(d.contributeFrm.service)
	$willChk = d.contributeFrm.willChk.checked
	$lifeInsuranceChk = d.contributeFrm.lifeInsuranceChk.checked
	$livingTrustChk = d.contributeFrm.livingTrustChk.checked
	$charitableRemainderChk = d.contributeFrm.charitableRemainderChk.checked
	$leadTrustChk = d.contributeFrm.leadTrustChk.checked
	$retirementChk = d.contributeFrm.retirementChk.checked
	$realEstateChk = d.contributeFrm.realEstateChk.checked
	$otherChk = d.contributeFrm.otherChk.checked
	$commentsTar = convertGetVar(d.contributeFrm.commentsTar.value)
	//$commentsTar = $commentsTar.replace(/\n/g, "<br />")
	$ccMeChk = d.contributeFrm.ccMeChk.checked
	url = processURL+'?contribute&nameTxt=' +$nameTxt+ '&\
emailTxt=' +$emailTxt+ '&\
phoneTxt=' +$phoneTxt+ '&\
willChk=' +$willChk+ '&\
service=' +$service+ '&\
lifeInsuranceChk=' +$lifeInsuranceChk+ '&\
livingTrustChk=' +$livingTrustChk+ '&\
charitableRemainderChk=' +$charitableRemainderChk+ '&\
leadTrustChk=' +$leadTrustChk+ '&\
retirementChk=' +$retirementChk+ '&\
realEstateChk=' +$realEstateChk+ '&\
otherChk=' +$otherChk+ '&\
commentsTar=' +$commentsTar+ '&\
ccMeChk=' +$ccMeChk
	//alert(url);
	loadXMLDoc(url)
	d.contributeFrm.reset()
	contributeWindow.closeBox.closeContainer();
	return false;
}
function submitGivingFrm() {
	$nameTxt = convertGetVar(d.givingFrm.nameTxt.value)
	$emailTxt = convertGetVar(d.givingFrm.emailTxt.value)
	$phoneTxt = convertGetVar(d.givingFrm.phoneTxt.value)
	$willChk = d.givingFrm.willChk.checked
	$nonProfitPartnerChk = d.givingFrm.nonProfitPartnerChk.checked
	$livingTrustChk = d.givingFrm.livingTrustChk.checked
	$charitableRemainderChk = d.givingFrm.charitableRemainderChk.checked
	$donorAdvisedChk = d.givingFrm.donorAdvisedChk.checked
	$fieldOfInterestChk = d.givingFrm.fieldOfInterestChk.checked
	$otherChk = d.givingFrm.otherChk.checked
	$otherTxt = convertGetVar(d.givingFrm.otherTxt.value)
	$talkToBoardMbrChk = d.givingFrm.talkToBoardMbrChk.checked
	$freeOneHourConsultChk = d.givingFrm.freeOneHourConsultChk.checked
	$ccMeChk = d.givingFrm.ccMeChk.checked
	url = processURL+'?give&nameTxt=' +$nameTxt+ '&\
emailTxt=' +$emailTxt+ '&\
phoneTxt=' +$phoneTxt+ '&\
willChk=' +$willChk+ '&\
nonProfitPartnerChk=' +$nonProfitPartnerChk+ '&\
livingTrustChk=' +$livingTrustChk+ '&\
charitableRemainderChk=' +$charitableRemainderChk+ '&\
donorAdvisedChk=' +$donorAdvisedChk+ '&\
fieldOfInterestChk=' +$fieldOfInterestChk+ '&\
otherChk=' +$otherChk+ '&\
otherTxt=' +$otherTxt+ '&\
talkToBoardMbrChk=' +$talkToBoardMbrChk+ '&\
freeOneHourConsultChk=' +$freeOneHourConsultChk+ '&\
ccMeChk=' +$ccMeChk+ '&\
noRedirect=true'
	//alert(url);
	loadXMLDoc(url)
	d.givingFrm.reset()
	contributeWindow.closeBox.closeContainer();
	return false;
}

function doNothing() {
	return;
}

addStyleToDOM('/etc/window.css');
function openWhatsNew() {
	whatsNewWindow = createWindow('whatsNew',"width=750px,height=600px,xPos=75px,yPos=15px,title=What's New,oParent=outerDiv,border=3px,contentURL=/modules/whatsNew.html");
	if(whatsNewWindow) whatsNewWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	
}

function openSupporters() {
	supportersWindow = createWindow('supporters',"width=730px,height=475px,xPos=80px,yPos=75px,title=Supporters,oParent=outerDiv,border=3px,contentURL=/modules/supporters.html");
	if(supportersWindow) supportersWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	
}

function openContactUs() {
	contactUsWindow = createWindow('contactUs',"width=525px,height=520px,xPos=100px,yPos=90px,title=Email Whitney Evans (info@sonomavalleyfund.org),oParent=outerDiv,border=3px,contentURL=/modules/email.html");
	if(contactUsWindow) contactUsWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	
}

function openBoardMembers() {
	boardMembersWindow = createWindow('boardMembers',"width=925px,height=400px,xPos=-15px,yPos=75px,title=Board Members,oParent=outerDiv,border=3px,contentURL=/modules/boardMembers.html");
	if(boardMembersWindow) boardMembersWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	if(boardMembersWindow) boardMembersWindow.body.style.overflow = 'hidden';
	hideBios();	
}
function openYouthInitiative() {
	youthInitiativeWindow = createWindow('youthInitiative',"width=650px,height=415px,xPos=50px,yPos=50px,title=Youth Initiative Report,oParent=outerDiv,border=3px,contentURL=/modules/youthInitiative.html");
	if(youthInitiativeWindow) youthInitiativeWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	if(youthInitiativeWindow) youthInitiativeWindow.body.style.overflow = 'hidden';	
}
function openNowHiring() {
	nowHiringWindow = createWindow('nowHiring',"width=550px,height=290px,xPos=175px,yPos=75px,title=Now Hiring,oParent=outerDiv,border=3px,contentURL=/modules/nowHiring.html");
	if(nowHiringWindow) nowHiringWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	if(nowHiringWindow) nowHiringWindow.body.style.overflow = 'hidden';	
}

function openContribute() {
	contributeWindow = createWindow('contribute',"width=520px,height=645px,xPos=90px,yPos=0px,title=Become A Supporter,border=3px,oParent=outerDiv,contentURL=/modules/contribute.html");
	if(contributeWindow) contributeWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
}
function openGiving() {
	contributeWindow = createWindow('giving',"width=570px,height=525px,xPos=155px,yPos=45px,title=Sonoma Valley Fund Legacy/Gift Worksheet,border=3px,oParent=outerDiv,contentURL=/modules/giving.html");
	if(contributeWindow) contributeWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
}

function openEmailList() {
	emailListWindow = createWindow('emailList',"width=600px,height=445px,title=Website Email,border=3px,contentURL=/modules/viewEmails.html");
	if(emailListWindow) emailListWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
}

function openViewEmail(emailIdstr) {
	emailId = emailIdstr
	if(d.getElementById('border_viewEmail')) {
		viewEmailWindow.grabContents("/modules/viewEmails.html?emailId="+emailId);
		bring2front(viewEmailWindow.container);
	} else {
		viewEmailWindow = createWindow('viewEmail',"width=450px,height=400px,title=View Email,border=3px");
		viewEmailWindow.grabContents("/modules/viewEmails.html?emailId="+emailId);
		if(viewEmailWindow) viewEmailWindow.closeBox.innerHTML = "<div class='dynamicWindowCloseBoxContents'>X</div>";
	}
}

function givingInfoTabSelect() {
	infoDiv = d.getElementById('givingInfo');
	formDiv = d.getElementById('givingForm');
	infoTab = d.getElementById('givingInfoTab');
	formTab = d.getElementById('givingFormTab');
	infoBtn = d.getElementById('givingInfoBtn');
	formBtn = d.getElementById('givingFormBtn');
		infoBtn.disabled = true;
		formBtn.disabled = false;
	
	if(infoDiv.style.display == 'none') {
		formDiv.style.display = 'none';
		infoDiv.style.display = 'block';
		infoTab.style.cursor = 'default';
		formTab.style.cursor = 'pointer';
		infoTab.style.background = '#FFF';
		formTab.style.background = '#d5b78f';
	}
	
}
function givingFormTabSelect() {
	infoDiv = d.getElementById('givingInfo');
	formDiv = d.getElementById('givingForm');
	infoTab = d.getElementById('givingInfoTab');
	formTab = d.getElementById('givingFormTab');
	infoBtn = d.getElementById('givingInfoBtn');
	formBtn = d.getElementById('givingFormBtn');
		formBtn.disabled = true;
		infoBtn.disabled = false;
	
	if(formDiv.style.display == 'none') {
		infoDiv.style.display = 'none';
		formDiv.style.display = 'block';
		formTab.style.cursor = 'default';
		infoTab.style.cursor = 'pointer';
		formTab.style.background = '#FFF';
		infoTab.style.background = '#d5b78f';
	}
}

var grantsInfoWin = null
function grantsInfo() {
	if(grantsInfoWin && !grantsInfoWin.closed) {
		grantsInfoWin.focus();
	} else {
		grantsInfoWin = window.open('http://www.sonomacf.org/sonoma_valley_fund/index.shtml','grantsInfo','scrollbars=1,width=850px,height=600px,resizable=1,menubar=1,toolbar=1,status=1,location=1');
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function convertGetVar (getVar) {
	output = getVar.toString()
	var regEx1 = /\#/g
	var regEx2 = /\&/g
	var regEx3 = /\n/g
	output = output.replace(regEx1,'%23');
	output = output.replace(regEx2,'%26');
	output = output.replace(regEx3,'<br />');
	return output;
}

function markEmailAsProcessed(emailId, processedValue) {
	if(processedValue == 1) {newProcessedValue = 0;}
	else {newProcessedValue = 1;}
	url = "/modules/viewEmails.html?markProcessed="+newProcessedValue+"&emailId="+emailId;
	loadXMLDoc(url,processMarkProcessed)
}

function processMarkProcessed() {
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			response = req.responseText
			if(response.indexOf('success') > 0) {
				emailId = response.split('|')[1];
				processedMark = response.split('|')[2];
				emailNode = d.getElementById('processed_'+emailId);
				emailNode.innerHTML = processedMark
			} else {
				alert(response);
			}
		} else {
			alert("There was a problem sending your data.\n Please try again");
		}
	}
	
}