// JavaScript Document
var c_CCWebPage = 'http://www.lhmgift.org/neighbor/';

function ValidateLogin() {
	var reBlank = /^\s*$/;
	var strValue;
	
	strValue = document.frmLogin.Username.value
	if (reBlank.test(strValue)){
		alert('Please enter your username.') 
		document.frmLogin.Username.focus();
		return false;
	}	

	strValue = document.frmLogin.Password.value
	if (reBlank.test(strValue)){
		alert('Please enter your password.') 
		document.frmLogin.Password.focus();
		return false;
	}
}

function ValidateChangePassword() {
	var reBlank = /^\s*$/;
	var strValue;
	
	strValue = document.frmPassword.OldPassword.value
	if (reBlank.test(strValue)){
		alert('Please enter your old password.') 
		document.frmPassword.OldPassword.focus();
		return false;
	}	

	strValue = document.frmPassword.NewPassword.value
	if (reBlank.test(strValue)){
		alert('Please enter your new password.') 
		document.frmPassword.NewPassword.focus();
		return false;
	}	

	strValue = document.frmPassword.NewPassword2.value
	if (reBlank.test(strValue)){
		alert('Please re-enter your new password.') 
		document.frmPassword.NewPassword2.focus();
		return false;
	}	

	if (document.frmPassword.NewPassword2.value != document.frmPassword.NewPassword.value ){
		alert('New password does not match.') 
		document.frmPassword.NewPassword2.focus();
		return false;
	}			
	
	if (document.frmPassword.NewPassword.value == document.frmPassword.OldPassword.value ){
		alert('New password is the same as old password.') 
		document.frmPassword.NewPassword.focus();
		return false;
	}
}


function ValidateUpdateNeighbor() {
	var reBlank = /^\s*$/;
	var strValue;
	
	strValue = document.frmNeighbor.Firstname.value
	if (reBlank.test(strValue)){
		alert('Please enter the First Name.') 
		document.frmNeighbor.Firstname.focus();
		return false;
	}	

	strValue = document.frmNeighbor.Lastname.value
	if (reBlank.test(strValue)){
		alert('Please enter the Last Name.') 
		document.frmNeighbor.Lastname.focus();
		return false;
	}	

	strValue = document.frmNeighbor.Street.value
	if (reBlank.test(strValue)){
		alert('Please enter the street.') 
		document.frmNeighbor.Street.focus();
		return false;
	}	

	strValue = document.frmNeighbor.City.value
	if (reBlank.test(strValue)){
		alert('Please enter the city.') 
		document.frmNeighbor.City.focus();
		return false;
	}	

	if (document.frmNeighbor.State.selectedIndex == 0 ) {
		alert('Please select the state.') 
		document.frmNeighbor.State.focus();
		return false;
	}

	strValue = document.frmNeighbor.Zip.value
	if (reBlank.test(strValue)){
		alert('Please enter the zip code.') 
		document.frmNeighbor.Zip.focus();
		return false;
	}

}

function ValidateAddVol(sMode, sValue) {
	var reBlank = /^\s*$/;
	var strValue;


 	switch (sMode)	{
		case "1" :   // Search
			strValue = document.frmVol.Firstname.value;
			if (reBlank.test(strValue)){
				strValue = document.frmVol.Lastname.value;
				if (reBlank.test(strValue)){
					alert('Please enter first name, or last name, or both.') 
					document.frmVol.Firstname.focus();
					return false;
				}
			}
			break;

		case  "2" :   //Add new vol, edit vol
			strValue = document.frmVol.Firstname.value;
			if (reBlank.test(strValue)){
				alert('Please enter first name.') 
				document.frmVol.Firstname.focus();
				return false;
			}	
	
			if (strValue.indexOf("/") > 0 ) {
				alert('Please do not use "/" in first name.') 
				document.frmVol.Firstname.focus();
				return false;
			}
	
			strValue = document.frmVol.Lastname.value;
			if (reBlank.test(strValue)){
				alert('Please enter last name.') 
				document.frmVol.Lastname.focus();
				return false;
			}

			if (strValue.indexOf("/") > 0 ) {
				alert('Please do not use "/" in last name.') 
				document.frmVol.Lastname.focus();
				return false;
			}

			strValue = document.frmVol.Address1.value;
			if (reBlank.test(strValue)){
				alert('Please enter address line 1.') 
				document.frmVol.Address1.focus();
				return false;
			}

			strValue = document.frmVol.City.value;
			if (reBlank.test(strValue)){
				alert('Please enter city.') 
				document.frmVol.City.focus();
				return false;
			}

			if (document.frmVol.State.selectedIndex == 0 ) {
				alert('Please select the state.') 
				document.frmVol.State.focus();
				return false;
			}

			strValue = document.frmVol.Zip.value;
			if (reBlank.test(strValue)){
				alert('Please enter zip.') 
				document.frmVol.Zip.focus();
				return false;
			}
			
			//strEmail = document.frmVol.Email.value;
			//if (reBlank.test(strEmail)){
			//	alert('Please enter email address.') 
			//	document.frmVol.Email.focus();
			//	return false;
			//}	
			
			break;

		case "3":      //Add vol to program
			document.frmVol.vol.value = sValue;			
			break;
		default :
			break;
	}
	
	document.frmVol.mode.value = sMode;
	document.frmVol.submit();
}

function ValidateSearchVol() {
	var reBlank = /^\s*$/;
	var strValue;

	strValue = document.frmVol.Firstname.value;
	if (reBlank.test(strValue)){
		strValue = document.frmVol.Lastname.value;
		if (reBlank.test(strValue)){
			alert('Please enter first name, or last name, or both.') 
			document.frmVol.Firstname.focus();
			return false;
		}
	}
	
	document.frmVol.searchv.value = 'y';
	document.frmVol.submit();
}

function ValidateSearchNeighbor() {
	var reBlank = /^\s*$/;
	var strValue;

	strValue = document.frmNeighbor.Firstname.value;
	if (reBlank.test(strValue)){
		strValue = document.frmNeighbor.Lastname.value;
		if (reBlank.test(strValue)){
			alert('Please enter first name, or last name, or both.') 
			document.frmNeighbor.Firstname.focus();
			return false;
		}
	}	
}


function ShowPostcardType(DivID) { 
	var seldiv1 = document.getElementById('div1');
	var seldiv2 = document.getElementById('div2');
	var seldiv3 = document.getElementById('div3');
	
	switch (DivID){
 		case 1 : 
	  		seldiv1.style.display = "block";
			seldiv2.style.display = "none";
			seldiv3.style.display = "none";
			break;
 		case 2 :
			seldiv1.style.display = "none";
			seldiv3.style.display = "none"; 
 	 		seldiv2.style.display = "block";
			break;
 		case 3 : 
			seldiv1.style.display = "none";
			seldiv2.style.display = "none";
 	 		seldiv3.style.display = "block";
			break;
	   default : 
			seldiv1.style.display = "none";
			seldiv2.style.display = "none";
			seldiv3.style.display = "none";
	}
}


function EditVol(sVolID, sAdminVolID, sCongregID) 
{
	var windowSettings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,"+
								"resizable=yes,width=550,height=450,top=50,left=300";
	window.open(c_CCWebPage + 'editvolccweb.asp?vol=' + sVolID +'&VolID=' + sAdminVolID + '&CongregID=' + sCongregID,'',windowSettings);
}

function EditVolStatus(sVolID) 
{
	var windowSettings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,"+
								"resizable=yes,width=550,height=250,top=50,left=300";
	window.open('editvolstatus.asp?vol=' + sVolID,'',windowSettings);
}

function SubmitActivityForm(iActivityID, sAction){
	document.frmActivity.Activity.value = iActivityID;
	document.frmActivity.FormAction.value = sAction;
	document.frmActivity.submit();
}

function OpenHelp(HelpID){
	var windowSettings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes," +
			"resizable=no,width=500,height=300,top=300,left=300"; 
	window.open('activityhelp.htm#part' + HelpID, '', windowSettings);
}

function OpenCompanion(StyleCode){
	var windowSettings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes," +
			"resizable=yes,width=600,height=500,top=100,left=300"; 
	var PageName;

	switch (StyleCode){
 		case "beach" : 
			PageName = "c1_companion.htm";
			break;
		case "box" : 
			PageName = "c2_companion.htm";
			break;
		case "church" : 
			PageName = "a2_companion.htm";
			break;
		case "cookie" :
			PageName = "b2_companion.htm";
			break;
		case "plant" : 
			PageName = "b1_companion.htm";
			break;
		case "songbook" : 
			PageName = "a1_companion.htm";
			break;
	   default : 
			PageName = "a1_companion.htm";	
	}	
	
	window.open(PageName, '', windowSettings);
}

function OpenZoomIn(ProductCode, Side) {
	var windowSettings = 'height=550,width=500,top=50,left=380,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no';
	window.open('zoomin.asp?pcode=' + ProductCode + '&s=' + Side,'', windowSettings);
}

function OpenReport(sStatus, sSortBy) {
	var windowSettings = 'height=500,width=800,top=50,left=50,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=no';
	window.open('reportprt.asp?s=' + sStatus + '&o=' + sSortBy,'', windowSettings);
}

function PrintNeighbor(sType, sSortBy) {
	var windowSettings = 'height=500,width=800,top=50,left=50,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=no';
	window.open('neighborsprt.asp?t=' + sType + '&o=' + sSortBy,'', windowSettings);
}

function EditNeighbor(sID) {
	var windowSettings = 'height=500,width=450,top=50,left=380,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no';
	window.open('updateneighbor.asp?id=' + sID,'', windowSettings);
}

function AssignVol(sID) {
	var windowSettings = 'height=300,width=450,top=50,left=150,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no';
	window.open('assignvol.asp?id=' + sID,'', windowSettings);
}

function ChangeMenuColor(selID) {
	var selObj = document.getElementById(selID);
	selObj.style.color = '#FFFF66';
}

function SetMenuColorBack(selID) {
	var selObj = document.getElementById(selID);
	selObj.style.color = '#ffffff';
}


function URLHandler(pageURL,newWindow){
	var myPage
	var myNew 
		
	if (pageURL == 'broadcastinformation.htm') { 
		myPage = 'broadcastinformation.asp';
		myNew = 0;	
	}	
	else {
		myPage = pageURL;
		myNew = newWindow;
	}

	if (myPage.substr(0,4) !='http'){
		myPage = serverPath + myPage;
	}
		
	if (myNew != 1) {
		location.href = myPage;
	}
	else {
		window.open(myPage);
	}
}

function SelectAllNeighbors() {
	var AllStatus = document.frmNeighbors.SelectAll.checked; 
	
	if (document.frmNeighbors.SelNeighbor.length == null) {
		document.frmNeighbors.SelNeighbor.checked = AllStatus; 
	} 
	
	else {
		var CheckBoxCounts = document.frmNeighbors.SelNeighbor.length; 
		var i;  
	
		for (i=0;i<CheckBoxCounts;i++) {
			document.frmNeighbors.SelNeighbor[i].checked = AllStatus;
		}
	}
}

function UncheckSelectAllNeighbors(iIndex) {
	//var CheckBoxSelectedIndex = document.frmNeighbors.SelNeighbor.SelectedIndex();
	//alert(CheckBoxSelectedIndex);
	if (document.frmNeighbors.SelNeighbor.length == null) {
		if (!(document.frmNeighbors.SelNeighbor.checked)) {
			document.frmNeighbors.SelectAll.checked = false;
		}
	}
	
	else { 
		if (!(document.frmNeighbors.SelNeighbor[iIndex].checked)) {
			document.frmNeighbors.SelectAll.checked = false;
		}
	}
}

function GoPage(sPageName) {
	location.href = sPageName;
}

function ConfirmDelete() {
	return confirm('Are you sure you want to delete the selected neighbors?');
}

