//COMPLETED REMINDER
function fCompleted(what)
{
	var msg = "Are you sure this reminder is completed?"
	if (confirm(msg))
	{
		window.location = document.location.href + "&completed=" + what;
	}
	
	return false;
}


//VALIDATE ADD REMINDER
function validateReminder(formName)
{
	createStartDate(formName,'Rem');
	rem_type_id =(eval("document." + formName + ".rem_type_id"));
	if(rem_type_id.value.length == 0)
	{
		alert("Plese choose Reminder Type.");
		rem_type_id.focus();
		return false;
	}
	else
	{
		rem_text =(eval("document." + formName + ".rem_text"));
		//b = rem_text.value.replace(/\r\n|\r|\n/g, ' ');
		var a = rem_text.value.split(/\s+/g); // split the sentence into an array of words
		//var a = b.split(/\s+/g); // split the sentence into an array of words
		//alert(a.length == 0)
		
		if ((a.length == 0) || (rem_text.value.length == 0))
					{
						alert("Please provide Reminder Text.");
						rem_text.focus();
					return false;
					}
		return true;
	}
	return false;
}



//VALIDATE REPORT FORM
function validateCreateReport(formName)
{
report_name = hasText(formName,"report_name","Report Name field");
	if(report_name)
	{
		return true;
	}
	return false;
}


//DISPLAY PRINT PREVIEW
function printWindow()
{	
    printPreview = window.open('printPreview.asp', 'newPrint');
    if (printPreview && printPreview.open && !printPreview.closed) printPreview.focus();
}

function f_selectAll(formName)
	{
		objForm = eval("document." + formName)
	if (objForm.elements[0].checked==true)
	{
		for(i=0;i< objForm.length;i++)
		{
			e = objForm.elements[i];
			if (e.type=='checkbox')
			{
					e.checked=true;	
				
			}
		}
	}
	
	else
	{
		for(i=0;i< objForm.length;i++)
		{
			e = objForm.elements[i];
			if (e.type=='checkbox')
			{
					e.checked=false;	
				
			}
		}
	}
	
	}
	
	
//IS NUMBER
function checkNum(elementID,message)
{
	z = document.getElementById([elementID])
		//alert(z)
		//return false;
	
	if (z.value != "")
	{
		 if (isNaN(z.value)== true)
		{
			alert(message);
			z.value = "";
			z.focus();
			return false;
		}
		return true;
	}
	return true;
}

//VALIDATE ADD CONFERENCE
function validateAddConf(formName)
{
	conference_name = hasText(formName,"conference_name","Conference Name field");
	if(conference_name)
	{
		return true;
	}
	return false;
}

//VALIDATE EDIT USER
function validateUser(formName)
{
	pas = eval("document." + formName + ".upassword")
	pasC = eval("document." + formName + ".upasswordConf")
	user_type_id =(eval("document." + formName + ".user_type_id"));
	affiliate_id =(eval("document." + formName + ".affiliate_id"));
	if(user_type_id.value.length == 0)
	{
		alert("Please choose User Type.")
		user_type_id.focus();
		return false;
	}
	else if (user_type_id.value == 3)
	{
		if(affiliate_id.value.length == 0)
		{
			alert("Please choose Affiliate.")
			affiliate_id.focus();
			return false;
		}
	}
		
		a = hasText(formName,"uname","User Name field");
		if(a)
		{
			b = hasText(formName,"upassword","Password field");
			if(b)
			{
				if(pas.value.length < 8)
				{
					alert("Password must be at least eight characters in length.")
					pas.focus();
					return false;
				}
				ph = hasText(formName,"upasswordConf","Confirm Password field");
				if (ph)
				{
					if(pas.value == pasC.value)
					{
						return checkEmail('email');
						//return true;
					}
					else
					{
						alert("Please confirm password.")
						pasC.value = "";
						pasC.focus();
						return false;
					}
				}
			}
		}

	
	return false;
}

// VALIDATE EDIT ORGANIZATION MEMBER
function editCompanyMember(formName)
{
	//alert(formName)
	org_id =(eval("document." + formName + ".org_id.value"));
	//contact_id =(eval("document." + formName + ".contact_id.value"));
	cont = document.getElementById("contact_id")
	contact_id = cont.value
	//alert(org_id)
	//alert(contact_id)
	//return false
	org_name = hasText(formName,"company_name","Organization Name field");
	if(org_name)
	{
		if(contact_id.length == 0)
		{
			alert("Please choose Contact Name.");
			//contact_id.focus();
			return false;
		}
		else
		{
			if(contact_id == 0)
			{
				a = hasText(formName,"fname","First Name field");
				if(a)
				{
					b = hasText(formName,"lname","Last Name field");
					if(b)
					{
						ph = hasText(formName,"phone","Phone field");
						if (ph)
						{
							e = hasText(formName,"email","Email field");
							if(e)
							{
								return checkEmail('email');
								//return true;
							}
						}
					}
				}
			}
			else
			{
				ph = hasText(formName,"phone","Phone field");
				if (ph)
				{
					e = hasText(formName,"email","Email field");
					if(e)
					{
						return checkEmail('email');
						
								//return true;
					}
				}
			}
		}
	}
	return false;
}

// VALIDATE ADD ORGANIZATION MEMBER
function addCompanyMember(formName)
{
	org_id =(eval("document." + formName + ".org_id.value"));
	contact_id =(eval("document." + formName + ".contact_id"));
	
	//return false;
	if(org_id == 0)
	{
		org_name = hasText(formName,"company_name","Organization Name field");
		if(org_name){
			if(contact_id.value.length == 0)
			{
				alert("Please choose Contact Name.");
				contact_id.focus();
				return false;
			}
			else
			{
				if(contact_id.value == 0)
				{
					// is fname, lname empty?
					a = hasText(formName,"fname","First Name field");
					if(a)
					{
						b = hasText(formName,"lname","Last Name field");
						if(b){
							ph = hasText(formName,"phone","Phone field");
							if (ph){
							e = hasText(formName,"email","Email field");
								if(e){
									return checkEmail('email');
									
								//return true;
								}
							}
						}
					}
					return false;
				}
				//else
				//{
				//alert("next")
					ph = hasText(formName,"phone","Phone field");
					if(ph)
					{
						e = hasText(formName,"email","Email field");
						if(e){
							return checkEmail('email');
							
								//return true;
						}
					}
					
				//}
			}
		}
		return false;
	}
	else
	{
	if(contact_id.value.length == 0)
			{
				alert("Please choose Contact Name.");
				contact_id.focus();
				return false;
			}
			else
			{
				if(contact_id.value == 0)
				{
					// is fname, lname empty?
					a = hasText(formName,"fname","First Name field");
					if(a)
					{
						b = hasText(formName,"lname","Last Name field");
						if(b){
							ph = hasText(formName,"phone","Phone field");
							if (ph){
							e = hasText(formName,"email","Email field");
								if(e){
									return checkEmail('email');
									
								//return true;
								}
							}
						}
					}
					return false;
				}
				//else
				//{
				//alert("next")
					ph = hasText(formName,"phone","Phone field");
					if(ph)
					{
						e = hasText(formName,"email","Email field");
						if(e){
							return  checkEmail('email');
							//return true;
						}
					}
					
				//}
			}
			return false
	}
	//alert(org_id)
	
}

//VALIDATE LEGISLATOR
function validateLegislator(formName)
{
	objState =(eval("document." + formName + ".state"));
	a = hasText(formName,"chamber","Chamber field");
	if(a)
	{
		b = hasText(formName,"lname","Last Name field");
		if(b)
		{
			if(objState.value.length == 0)
			{
				alert("The State field cannot be blank.");
				objState.focus();
				return false;
			}
			else
			{
				return checkEmail('email');
				//return true;		
			}
		}
	}
	return false;
}

//VALIDATE ADD COUNSELOR
function validateAddCounselor(formName)
{
	{
	//alert(formName)
	//return false
	contact_id =(eval("document." + formName + ".contact_id.value"))
	if(contact_id == 0)
	{
		org_id =(eval("document." + formName + ".org_id.value"))
		a = hasText(formName,"fname","First Name field");
		if(a){
			b = hasText(formName,"lname","Last Name field");
			if(b){
				e = hasText(formName,"email","Email field");
				if(e){
					if(checkEmail('email'))
					{
					ph = hasText(formName,"phone","Phone field");
					if(ph)
					{
						if(org_id.length == 0)
						{
							return true;
						}
						else
						{
							if(org_id == 0)
							{
								org_name = hasText(formName,"company_name","Organization Name field");
								if(org_name)
								{
									return true;
								}
							}
							else
							{
								return true;
							}
						}
					}
					}
				}
			}
		}
		return false;
	}
	else
	{
		org_id =(eval("document." + formName + ".org_id.value"))
		a = hasText(formName,"fname","First Name field");
		if(a){
			b = hasText(formName,"lname","Last Name field");
			if(b){
				e = hasText(formName,"email","Email field");
				if(e){
					if(checkEmail('email'))
					{
					ph = hasText(formName,"phone","Phone field");
					if(ph){
						if(org_id.length == 0){
							return true;
						}
						else{
							if(org_id == 0){
								org_name = hasText(formName,"company_name","Organization Name field");
								if(org_name)
								{
									return true;
								}
							}
							else{
								return true;
							}
						}
							
					}
					}
				}
			}
		}
		return false;
	}
	
	return true;
}
}




// VALIDATE EDIT INDIVIDUAL CONTACT
function validateEditIndividual(formName)
{
	contact_id =(eval("document." + formName + ".contact_id.value"))
		org_id =(eval("document." + formName + ".org_id.value"))
		a = hasText(formName,"fname","First Name field");
		if(a){
			b = hasText(formName,"lname","Last Name field");
			if(b){
				e = hasText(formName,"email","Email field");
				if(e){
					if(checkEmail('email'))
					{
					ph = hasText(formName,"phone","Phone field");
					if(ph){
						if(org_id.length == 0){
							return true;
						}
						else{
							if(org_id == 0)
							{
								org_name = hasText(formName,"company_name","Organization Name field");
								if(org_name)
								{
									return true;
								}
							}
							else{
								return true;
							}
						}
							
					}
					}
				}
			}
		}
		return false;
}


// VALIDATE ADD INDIVIDUAL CONTACT
function validateAddIndividual(formName)
{
	//alert(formName)
	//return false
	contact_id =(eval("document." + formName + ".contact_id.value"))
	if(contact_id == 0)
	{
		org_id =(eval("document." + formName + ".org_id.value"))
		a = hasText(formName,"fname","First Name field");
		if(a){
			b = hasText(formName,"lname","Last Name field");
			if(b){
				e = hasText(formName,"email","Email field");
				if(e){
					if(checkEmail('email'))
					{
					ph = hasText(formName,"phone","Phone field");
					if(ph){
						if(org_id.length == 0){
							return true;
						}
						else{
							if(org_id == 0){
								org_name = hasText(formName,"company_name","Organization Name field");
								if(org_name){
									return true;
								}
							}
							else{
								return true;
							}
						}
							
					}
					}
				}
			}
		}
		return false;
	}
	else
	{
		org_id =(eval("document." + formName + ".org_id.value"))
		a = hasText(formName,"fname","First Name field");
		if(a){
			b = hasText(formName,"lname","Last Name field");
			if(b){
				e = hasText(formName,"email","Email field");
				if(e){
					if(checkEmail('email'))
					{
					ph = hasText(formName,"phone","Phone field");
					if(ph){
						if(org_id.length == 0){
							return true;
						}
						else{
							if(org_id == 0){
								org_name = hasText(formName,"company_name","Organization Name field");
								if(org_name)
								{
									return true;
								}
							}
							else{
								return true;
							}
						}
							
					}
					}
				}
			}
		}
		return false;
	}
	
	return true;
}


//VALIDATE ADD CONTACT
//function validateAddContact(formName){
//	viewBy = document.getElementById("viewBy")
//	//alert(viewBy.value)
//	if (viewBy){
//		if(viewBy.value == 1){
//			return validateAddIndividual(formName);
//		}
//	}
//	return false;
	
//}



//VALIDATE DOES FIELD HAS TEXT
function hasText(strFormName,strFormField,strMessage)
{
var iAt=0, strValue="", strFiltered="";
strValue = eval('document.' + strFormName + '.' + strFormField + ".value") ;

for(iAt=0;iAt<strValue.length+1;iAt++)
    {
    if (strValue.substring(iAt,iAt+1) != " ")
         {
         strFiltered = strFiltered + strValue.substring(iAt,iAt+1) ;
         }
    }

	if (strFiltered == "")
   	 {
  	  alert("The " + strMessage + " cannot be blank.");
   	 eval('document.' + strFormName + '.' + strFormField + ".focus()") ;
    	return false ;
    	}
	return true;
}

//VALIDATE EMAIL ADDRESS
function checkEmail(elementID)
{
	formElement = document.getElementById([elementID])
	if (formElement.value.length != 0)
	{
		em = formElement.value.indexOf(" ")
		ema = formElement.value.indexOf("@")
		emai = formElement.value.indexOf(".")
  		//alert("em is: " + em + "\nema is: " + ema + "\nemai is: " + emai);
		
		if (em != -1 || ema == -1 || emai == -1)
		{
			alert("You must enter a valid email address")
			//formElement.value = "";
			formElement.focus();
			return false;
		}
	}

return true;
}


//CONFIRM DELETE MESSAGE 
function ConfirmDeleteMessage(what)
{
	var deleteFile = confirm("Are you sure you wish to delete " + what + "?");
	return deleteFile;
}

//CONFIRM MESSAGE 
function ConfirmMessage(message)
{
	var yesOrNo = confirm(message);
	return yesOrNo;
}


//VALIDATE ADD AFFILIATE
function validateAddAff(formName)
{
	af_id =(eval("document." + formName + ".af_id.value"));
	contact_id =(eval("document." + formName + ".contact_id"));
	
	//return false;
	if(af_id == 0)
	{
		org_name = hasText(formName,"af_name","Affiliate Name field");
		if(org_name){
			if(contact_id.value.length == 0)
			{
				alert("Please choose Executive Director.");
				contact_id.focus();
				return false;
			}
			else
			{
				if(contact_id.value == 0)
				{
					// is fname, lname empty?
					a = hasText(formName,"fname","First Name field");
					if(a)
					{
						b = hasText(formName,"lname","Last Name field");
						if(b){
							ph = hasText(formName,"phone","Phone field");
							if (ph){
							e = hasText(formName,"email","Email field");
								if(e){
									return checkEmail('email');
									//return true;
								}
							}
						}
					}
					return false;
				}
				//else
				//{
				//alert("next")
					ph = hasText(formName,"phone","Phone field");
					if(ph)
					{
						e = hasText(formName,"email","Email field");
						if(e){
							return checkEmail('email');
							//return true;
						}
					}
					
				//}
			}
		}
		return false;
	}
	else
	{
	if(contact_id.value.length == 0)
			{
				alert("Please choose Executive Director.");
				contact_id.focus();
				return false;
			}
			else
			{
				if(contact_id.value == 0)
				{
					// is fname, lname empty?
					a = hasText(formName,"fname","First Name field");
					if(a)
					{
						b = hasText(formName,"lname","Last Name field");
						if(b){
							ph = hasText(formName,"phone","Phone field");
							if (ph){
							e = hasText(formName,"email","Email field");
								if(e){
									return checkEmail('email');
									//return true;
								}
							}
						}
					}
					return false;
				}
				//else
				//{
				//alert("next")
					ph = hasText(formName,"phone","Phone field");
					if(ph)
					{
						e = hasText(formName,"email","Email field");
						if(e){
							return checkEmail('email');
							//return true;
						}
					}
					
				//}
			}
			return false
	}
	//alert(af_id)
	
}

//VALIDATE EDIT AFFILIATE
function validateEditAff(formName)
{
	//alert(formName)
	af_id =(eval("document." + formName + ".af_id.value"));
	//contact_id =(eval("document." + formName + ".contact_id.value"));
	cont = document.getElementById("contact_id")
	contact_id = cont.value
	//alert(org_id)
	//alert(contact_id)
	//return false
	org_name = hasText(formName,"af_name","Affiliate Name field");
	if(org_name)
	{
		if(contact_id.length == 0)
		{
			alert("Please choose Executive Director.");
			//contact_id.focus();
			return false;
		}
		else
		{
			if(contact_id == 0)
			{
				a = hasText(formName,"fname","First Name field");
				if(a)
				{
					b = hasText(formName,"lname","Last Name field");
					if(b)
					{
						ph = hasText(formName,"phone","Phone field");
						if (ph)
						{
							e = hasText(formName,"email","Email field");
							if(e)
							{
								return checkEmail('email');
								//return true;
							}
						}
					}
				}
			}
			else
			{
				ph = hasText(formName,"phone","Phone field");
				if (ph)
				{
					e = hasText(formName,"email","Email field");
					if(e)
					{
						return checkEmail('email');
						//return true;
					}
				}
			}
		}
	}
	return false;
}


function validatePayment(formName)
{
	amount = hasText(formName,"amount","Amount field");
	if(amount)
	{
		return true;
	}
	return false;
}