// JavaScript Document

function afocus()
{
	document.login_admin.userName.focus();
}

function contact_us_validate()
{
var contactForm=document.contactUsForm;
if(contactForm.cont_name.value=="")
	{
		alert ("Please enter a value for the \"Name\" field.");
		contactForm.cont_name.focus();
		return false;
	}
	if(!isValidName(contactForm.cont_name.value)) 
	 {
	  alert( "Value for the \"Name\" field must be valid Alpha numeric and should start with Alphabet." );
	  contactForm.cont_name.focus();
	   return false;		
	 }
	 
	if(contactForm.cont_address.value!=""){
	if(!isValidStreetAddress(contactForm.cont_address.value)) 
	 {
	  alert( "Value for the \"Address\" field must be a valid Alpha numeric and should start with Alphabet." );
	  contactForm.cont_address.focus();
	  return false;		
	 }
	}
	else if(contactForm.cont_address.value==""){
	  alert( "Please enter a value for the \"Address\" field." );
	  contactForm.cont_address.focus();
	  return false;		
	 }
	 
if(contactForm.cont_phone.value=="")
	{
		alert ("Please enter a value for the \"Phone Number\" field.");
		contactForm.cont_phone.focus();
		return false;
	}
	if(!isValidPhoneNumber(contactForm.cont_phone.value) && contactForm.cont_phone.value!="")
   {
    
	alert( "Value for the \"Phone\" field must be a valid Numeric." );
	 contactForm.cont_phone.focus();
	 return (false);
   } 
	 
	if(contactForm.cont_email.value=="")
	{
		alert ("Please enter a value for the \"Email\" field.");
		contactForm.cont_email.focus();
		return false;
	}
	if(!IsEmailAddress(contactForm.cont_email.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		contactForm.cont_email.focus();
		return false;
	}
	
	if(contactForm.cont_comments.value!=""){		
	if(!isValidStreetAddress(contactForm.cont_comments.value)) 
	 {
	  alert( "Value for the \"Comments\" field must be valid Alpha numeric and should start with Alphabet." );
	  contactForm.cont_comments.focus();
	  return false;		
	 }
	}
	else if(contactForm.cont_comments.value=="")
	{
		alert ("Please enter a value for the \"Comments\" field.");
		contactForm.cont_comments.focus();
		return false;
	}
	 
}


function user_validate()
{
	String.prototype.trim = function()
	 { return this.replace( /^\s+|\s+$/g, '' ); 
	 } 
	 var str = document.login_admin.userName.value;
	 if(document.login_admin.userName.value =="" || str.trim() == "")
	 {
		alert('Enter "User Name"');
		document.login_admin.userName.focus();
		document.login_admin.userName.select();
		return false;
	 }
	 var str1 =document.login_admin.password.value;
	 if(document.login_admin.userName.value =="" || str1.trim() == "")
	 {
		alert('Enter "Password"');
		document.login_admin.password.focus();
		document.login_admin.password.select();
		return false;
	 }
}


// Shared Vision Subscription Validation

function shared_vision_subscription(theForm)
{

var current = new Date();
var currentTime = new Date(current.getFullYear(),current.getMonth(),current.getDate());
var day = currentTime.getDate();
var month = currentTime.getMonth()+1;
var year = currentTime.getFullYear();
var date="0"+month+"/"+day+"/"+year;
var sub_date=theForm.subscription_end_date.value.split("/");
var subscription_end_date= new Date(sub_date[2],(sub_date[0]-1),sub_date[1]);

	 if(theForm.first_name.value== "")
	 {
	  alert("Please enter a value for the \"First Name\" field.");
	  theForm.first_name.focus();
	  return false;
	 }
	 if (!isValidName(theForm.first_name.value)) 
	 {
	  alert( "Value for the \"First Name\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.first_name.focus();
	  return false;		
	 }
	 if(theForm.last_name.value=="")
	 {
	  alert("Please enter a value for the \"Last Name\" field."); 
	  theForm.last_name.focus();
	  return false;
	 }	
	 if (!isValidName(theForm.last_name.value)) 
	 {
	  alert( "Value for the \"Last Name\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.last_name.focus();
	  return false;		
	 }
	 
	 if(theForm.street_address.value=="")
	 {
	  alert("Please enter a value for the \"Street Address\" field."); 
	  theForm.street_address.focus();
	  return false;
	 }

	  if (!isValidStreetAddress(theForm.street_address.value)) 
	 {
	  alert( "Enter a valid value for the \"Street Address\" field." );
	  theForm.street_address.focus();
	  return false;		
	 }
	 
	 if(theForm.address.value != "") 
	{

	 if (!isValidStreetAddress(theForm.address.value)) 
	 {
	  alert( "Value for the \"Address\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.address.focus();
	  return false;		
	 }	 
	}
	 
	 if(theForm.city.value=="")
	 {
	  alert("Please enter a value for the \"City\" field."); 
	  theForm.city.focus();
	  return false;
	 }

	 if (!isValidName(theForm.city.value)) 
	 {
	  alert( "Value for the \"City\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.city.focus();
	  return false;
	 }
	 
	 if(theForm.state_province.value=="")
	 {
	  alert("Please enter a value for the \"State/Province\" field."); 
	  theForm.state_province.focus();
	  return false;
	 }

	 if (!isValidName(theForm.state_province.value)) 
	 {
	  alert( "Value for the \"State\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.state_province.focus();
	  return false;
	 }

	 if(theForm.zip_postalcode.value=="")
	 {
	  alert("Please enter a value for the \"Zip/Postal Code\" field."); 
	  theForm.zip_postalcode.focus();
	  return false;
	 }	
	 
	 if (theForm.zip_postalcode.value != "")
	 {
			//var NumRegxp = /^([0-9]+)$/;
			var NumRegxp = /^([0-9])([0-9]+)$/;
			if (!NumRegxp.test(theForm.zip_postalcode.value)) 
			{
				alert("Please enter a valid \"Zip/Postal Code\".");
				theForm.zip_postalcode.value="";
				theForm.zip_postalcode.focus();
				
				return false;
				
			}
    }
	
	 //if(theForm.country.value=="0")
    if(theForm.country.options[theForm.country.selectedIndex].text=="Select the Country")
	 {
	  alert("Please select a value in the \"Country\" field."); 
	  theForm.country.focus();
	  return false;
	 }
	 
	 if(theForm.no_of_copies.value=="")
	 {
	  alert("Please enter a value for the \"Number of copies\" field."); 
	  theForm.no_of_copies.focus();
	  return false;
	 }	
	 
	 if (theForm.no_of_copies.value != "")
	 {
			//var NumRegxp = /^([0-9]+)$/;
			var NumRegxp = /^([0-9]+)$/;
			if (!NumRegxp.test(theForm.no_of_copies.value)) 
			{
				alert("Please enter a valid Numeric value for the \"Number of copies\" field.");
				theForm.no_of_copies.value="";
				theForm.no_of_copies.focus();
				return false;
				
			}
    }
	 
	 
 	 if(theForm.subscription_end_date.value=="")
	 {
	  alert("Please select a date for the \"Subscription End Date\" field."); 
	  theForm.subscription_end_date.focus();
	  return false;
	 }
	 
 	 if(subscription_end_date < currentTime)
	 {
	  alert("Subscription End Date should not be less than current date"); 
	  theForm.subscription_end_date.focus();
	  return false;		 
	 }

	if(theForm.volunteer_program.value != "") 
	{

	 if (!isValidName(theForm.volunteer_program.value)) 
	 {
	  alert( "Value for the \"Volunteer Program\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.volunteer_program.focus();
	  return false;		
	 }	 
	}

	 if(theForm.email_address.value=="")
	 {
	  alert("Please enter a value for the \"Email\" field."); 
	  theForm.email_address.focus();
	  return false;
	 }
	 

	
	if ( !IsEmailAddress(theForm.email_address.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		theForm.email_address.focus();
		return false;
	} 
	
	theForm.action="index.php?m=sv&action=insert";
	theForm.submit();
}
// Shared Vision End
function setFocus(objInput)
{
	objInput.focus();
}

function staying_connected_subscription(theForm)
{
	var NumRegxp = /^([0-9]+)$/;	 
	var current = new Date();
	var year = current.getFullYear();
	


	if(theForm.first_name.value== "")
	 {
	  alert("Please enter a value for the \"First Name\" field.");
	  theForm.first_name.focus();
	  return false;
	 }
	 if (!isValidName(theForm.first_name.value)) 
	 {
	  alert( "Value for the \"First Name\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.first_name.focus();
	  return false;		
	 }
	 if(theForm.last_name.value=="")
	 {
	   alert("Please enter a value for the \"Last Name\" field.");
	  theForm.last_name.focus();
	  return false;
	 }	
	 if (!isValidName(theForm.last_name.value)) 
	 {
	  alert( "Value for the \"Last Name\" field must be a valid Alpha numeric and should start with alphabet." );
	  theForm.last_name.focus();
	  return false;		
	 }	 
	 if(theForm.email_address.value=="")
	 {
	 alert("Please enter a value for the \"Email\" field."); 
	  theForm.email_address.focus();
	  return false;
	 }
	 
	/* if(theForm.email_address.value != "") 
	{
		var str = theForm.email_address.value;
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!(!reg1.test(str) && reg2.test(str))) { // if syntax is valid
			alert ("Please enter a valid email address for the \"Email\" field.");
			theForm.email_address.value="";			
			theForm.email_address.focus();
			return false;
		}
	}
	*/
	if ( !IsEmailAddress(theForm.email_address.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		theForm.email_address.focus();
		return false;
	} 
	 
 
	if(theForm.street_address.value=="")
	 {
	   alert("Please enter a value for the \"Street Address\" field."); 
	  theForm.street_address.focus();
	  return false;
	 }
	  if (!isValidStreetAddress(theForm.street_address.value)) 
	 {
	  alert( "Please enter a valid value for the \"Street Address\" field." );
	  theForm.street_address.focus();
	  return false;		
	 }
	 
	 if(theForm.address.value != "") 
	{

	 if (!isValidStreetAddress(theForm.address.value)) 
	 {
	  alert( "Value for the \"Address\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.address.focus();
	  return false;		
	 }	 
	}
	
	 if(theForm.city.value=="")
	 {
	  alert("Please enter City"); 
	  theForm.city.focus();
	  return false;
	 }
	 if (!isValidName(theForm.city.value)) 
	 {
	  alert( "Value for the \"City\" field must be a valid Alpha numeric." );
	  theForm.city.focus();
	  return false;
	 }	 
	 if(theForm.state_province.value=="")
	 {
	   alert("Please enter a value for the \"State/Province\" field."); 
	  theForm.state_province.focus();
	  return false;
	 }
	 if (!isValidName(theForm.state_province.value)) 
	 {
	  alert( "Value for the \"State\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.state_province.focus();
	  return false;
	 }
	 if(theForm.zip_postalcode.value=="")
	 {
	   alert("Please enter a value for the \"Zip/Postal Code\" field."); 
	  theForm.zip_postalcode.focus();
	  return false;
	 }	
	 
	 if (theForm.zip_postalcode.value != "")
	 {
			//var NumRegxp = /^([0-9]+)$/;
			var NumRegxp = /^([0-9])([0-9]+)$/;
			if (!NumRegxp.test(theForm.zip_postalcode.value)) 
			{
				alert("Please enter a valid \"Zip/Postal Code\" .");
				theForm.zip_postalcode.value="";
				theForm.zip_postalcode.focus();
				
				return false;
				
			}
    }
	
	 //if(theForm.country.value=="0")
	 if(theForm.country.options[theForm.country.selectedIndex].text=="Select the Country")
	 {
	   alert("Please select a value in the \"Country\" field.")
	  theForm.country.focus();
	  return false;
	 }
	 
	 
	// if(resourceArea.typeResource.options[resourceArea.typeResource.selectedIndex].text=="Select")
	 
	
	if(theForm.volunteer_program.value != "") 
	{

	 if (!isValidName(theForm.volunteer_program.value)) 
	 {
	  alert( "Value for the \"Volunteer Program\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.volunteer_program.focus();
	  return false;		
	 }	 
	}
	
	if(theForm.volunteer_program_place.value != "") 
	{

	 if (!isValidName(theForm.volunteer_program_place.value)) 
	 {
	  alert( "Value for the \"Volunteer Program Place\" field must be a valid Alpha numeric and should start with Alphabet." );
	  theForm.volunteer_program_place.focus();
	  return false;		
	 }	 
	}
	
	 if((!NumRegxp.test(theForm.volunteer_program_began.value))&&(theForm.volunteer_program_began.value!=""))
	 {
	  alert("Please enter a valid Volunteer program began year"); 
	  theForm.volunteer_program_began.value="";
	  theForm.volunteer_program_began.focus();
	  return false;
	 }
	
	 if((theForm.volunteer_program_began.value!="")&&(theForm.volunteer_program.value==""))
	 {
	  alert("You cannot enter Volunteer program began year without entering Volunteer Programs Name"); 		 
	  theForm.volunteer_program.value="";
	  theForm.volunteer_program.focus();
	  return false;
		 
	 }
	  if(parseInt(theForm.volunteer_program_began.value) < 1900 || parseInt(theForm.volunteer_program_began.value) > year)
	 {
	  alert("Please enter a Volunteer program began year between 1900 and "+year); 
	  theForm.volunteer_program_began.value="";
	  theForm.volunteer_program_began.focus();
	  return false;
		 
	 }
 	 
	 if((theForm.volunteer_program_finished.value!="")&&(theForm.volunteer_program.value==""))
	 {
	  alert("You cannot enter Volunteer program Finished year without entering Volunteer Programs Name"); 		 
	  theForm.volunteer_program.value="";
	  theForm.volunteer_program.focus();
	  return false;
		 
	 }

	 if((theForm.volunteer_program_finished.value!="")&&(theForm.volunteer_program_began.value==""))
	 {
	  alert("You cannot enter Volunteer program Finished year without entering Volunteer Programs began year"); 		 
	  theForm.volunteer_program_began.value="";
	  theForm.volunteer_program_began.focus();
	  return false;
		 
	 }
	 
	  if((!NumRegxp.test(theForm.volunteer_program_finished.value))&&(theForm.volunteer_program_finished.value!=""))
	 {
	  alert("Please enter a valid Volunteer program finished year"); 
	  theForm.volunteer_program_finished.value="";
	  theForm.volunteer_program_finished.focus();
	  return false;
	 }

	 if(parseInt(theForm.volunteer_program_finished.value) < 1900 || parseInt(theForm.volunteer_program_finished.value) > year)
	 {
	  alert("Please enter a Volunteer program finished year between 1900 and "+year); 
	  theForm.volunteer_program_finished.value="";
	  theForm.volunteer_program_finished.focus();
	  return false; 
	 }
	 
	 if(parseInt(theForm.volunteer_program_began.value) > parseInt(theForm.volunteer_program_finished.value) )
	 {
	  alert("Volunteer Program Began date should be less than Volunteer Program End date"); 
	  theForm.volunteer_program_began.value="";
	  theForm.volunteer_program_began.focus();
	  return false; 
	 }
	
	theForm.action="index.php?m=sc&action=insert";
	theForm.submit();
}
// Staying Connected End



function viewConnectionDetails() {
	var form = document.cdForm;
	
	
	var thissel=document.getElementById("connections");
	var selCount = 0;
	
	// do field validation
	//if (form.connections.value == "-1") {
	if(document.getElementById("connections").value == "-1" || document.getElementById("connections").value == ""){
		alert( "Please select a Program to view details." );
	} 
	else {
		//form.action.value = 'view';
		//form.id.value = form.connections.value;
		for (var i=0; i<thissel.length; i++) {
		  if (thissel[i].selected) {
				if(thissel[i] != -1){
					selCount += 1;
				}
		}
		}
		if(selCount>5){
		alert("Not allowed to select more than 5 Programs");	 
		}else{
		//return valList();
		form.submit();
		return true;
		}
	}
	return false;
}//function


function viewConnectionDetailsAll() {
	var form = document.cdForm;
	
	// do field validation
	if (form.connections.value == "-1") {
		//if(document.getElementById("connections").value == "-1"){
		alert( "Please select a Program to view details." );
	} else {
		form.action.value = 'viewSearch';
		form.id.value = form.connections.value;
		form.submit();
		return true;
	}
	
	return false;
}//function
function viewSubscriptionForm() {
	var form = document.cdForm;
		form.action.value = 'subscriptionForm';
		form.submit();
		return true;
	
}//function


//this  function  not requires now, in future it may be
function subscribeToPrograms() {
	var form = document.cdForm;
		// do field validation
	var connectionsList = document.getElementById('connectionsList');	
	
	if (connectionsList.selectedIndex == -1 || connectionsList.selectedIndex == 0 ) {
		alert( "Please select Program Name(s) to Subscribe." );
	} else if(form.firstname.value == "") {
		alert( "Please enter a value for the \"First Name\" field." );
	} else if(form.lastname.value == "") {
		alert( "Please enter a value for the \"Last Name\" field." );
	} else if(form.position.value == "") {
		alert( "Please enter a value for the \"Positon\" field." );
	} else if(form.email.value == "") {
		alert( "Please enter a value for the \"Email address\" field." );
	} else if(form.isUpdatedEmail[0].checked && form.prevemail.value == "") {
		alert( "Please enter a value for the \"Previous Email address\" field." );
	} else {
		form.action.value = 'subscribe';
		form.submit();
		return true;
	}
	
	return false;
}//function


//Volunteer Community Activities

function validateCAForm(action) {
	var form = document.caForm;
	//Cancel button
	if (action == 'cancel')	{
		form.action.value = '';
		form.submit();
		return;
	}
	
	//submit button
	// do field validation
	if (action == 'save')
	if (form.firstname.value == "") {
		alert( "Please enter a value for the \"First Name\" field." );
		form.firstname.focus();
	} else if ( !isValidName(form.firstname.value)) {
		alert( "Value for the \"First Name\" field must be a valid Alpha numeric and should start with Alphabet." );
		form.firstname.focus();
	} else if (form.lastname.value == "") {
		alert( "Please enter a value for the \"Last Name\" field." );
		form.lastname.focus();
	} else if ( !isValidName(form.lastname.value)) {
		alert( "Value for the \"Last Name\" field must be a valid Alpha numeric and should start with Alphabet." );
		form.lastname.focus();
	} else if (form.email.value == "") {
		alert( "Please enter a value for the \"Email\" field." );
		form.email.focus();
	} else if ( !IsEmailAddress(form.email.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		form.email.focus();
	}  else if (form.title.value == "") {
		alert( "Please enter a value for the \"Activity Title\" field." );
		form.title.focus();
	}  else if ( !isValidName(form.title.value)) {
		alert( "Value for the \"Activity Title\" field must be valid Alpha numeric and should start with Alphabet" );
		form.title.focus();
	} else if (form.activity.value == "") {
		alert( "Please enter a Activity for the \"Activity\" field." );
		form.activity.focus();
	} else {
		form.action.value = 'save';
		form.submit();
		return true;
	}
	
	return false;
}//function
function submitCAForm(action, id) {
	var form = document.caForm;
	//View button
	if (action == 'view')	{
		form.action.value = 'view';
		form.id.value = id;
		form.submit();
		return;
	}
	if (action == 'activitiesUnderCategory')	{
		form.action.value = 'activitiesUnderCategory';
		form.id.value = id;
		form.submit();
		return;
	}
	
	
	return false;
}//function
//Volunteer Community Activities End

function navigate(linkVal,pageId)
{
	document.location.href=linkVal+"&page="+pageId;
}
function IsEmailAddress(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)
	
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	
	var digitsCheck = /[0-9]/;
	str = Trim(str);
	
	if(digitsCheck.test(str.charAt(0)) ) //must start with alphabet
		return false;

	if (!reg1.test(str) && reg2.test(str))
	   return true;
	else
		return false;
}
function isValidStreetAddress(str)
{
	if(isEmpty(str)) //added by jaya//discuss with nakkeran
		return false; 
	var reg = /^([a-zA-Z0-9 \n\,\.\-\_\*\#\(\)\%\$\@]+)$/; // valid characters
	var regNum = /^([0-9 \n\,\.\-\_\*\#\(\)\%\$\@ ]+)$/; // valid characters	

	if(regNum.test(str))
		return false;
	if (reg.test(str))
	   return true;
	else
		return false;
	}
function isValidName(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)	
	
	var reg = /^([a-zA-Z]+)([a-zA-Z0-9 ]+)([a-zA-Z0-9 \.\-\_]*)$/; // valid characters
	if (reg.test(str))
	   return true;
	else
		return false;
	
}
function isAlphaNumeric(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)
	
	var reg = /^([a-zA-Z0-9 ]*)([a-zA-Z0-9]+)([a-zA-Z0-9 ]*)$/; // valid characters
	if (reg.test(str))
	   return true;
	else
		return false;
	
}
function isNumeric(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)
	
	var reg = /^([0-9]+)$/; // valid characters
	if (reg.test(str))
	   return true;
	else
		return false;
	
}	
function isCharacter(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)
	
	var reg = /^([a-zA-Z])$/;
	if (reg.test(str))
	   return true;
	else
		return false;
	
}
function isEmpty(str)//returns true if the value is empty (i.e all spaces)
{
	var reg = /^([\ ]*)$/;
	if (reg.test(str))
	   return true;
	else
		return false;
	
}
function validateResourceArea()
{
	var resourceArea=document.resourceArea;
	
	if(resourceArea.volunteerFirstName.value=="")
	{
		alert ("Please enter a value for the \"First Name\" field.");
		resourceArea.volunteerFirstName.focus();
		return false;
	}

	if (!isValidName(resourceArea.volunteerFirstName.value)) 
	 {
	  alert( "Value for the \"First Name\" field must be valid Alpha numeric and should start with Alphabet." );
	  resourceArea.volunteerFirstName.focus();
	   return false;		
	 }

	if(resourceArea.volunteerLastName.value=="")
	{
		alert ("Please enter a value for the \"Last Name\" field.");
		resourceArea.volunteerLastName.focus();
		return false;
	}
	if (!isValidName(resourceArea.volunteerLastName.value)) 
	 {
	  alert( "Value for the \"Last Name\" field must be valid Alpha numeric and should start with Alphabet." );
	  resourceArea.volunteerLastName.focus();
	   return false;		
	 }
	 
	if(resourceArea.volunteerEmail.value=="")
	{
		alert ("Please enter a value for the \"Email\" field.");
		resourceArea.volunteerEmail.focus();
		return false;
	}
	if ( !IsEmailAddress(resourceArea.volunteerEmail.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		resourceArea.volunteerEmail.focus();
		return false;
	}
	if(resourceArea.volunteerProgram.value!=""){		
	if (!isValidName(resourceArea.volunteerProgram.value)) 
	 {
	  alert( "Value for the \"Volunteer Program\" field must be valid Alpha numeric and should start with Alphabet." );
	  resourceArea.volunteerProgram.focus();
	  return false;		
	 }
	}
	 
	if(resourceArea.NameResource.value=="")
	{
		alert ("Please enter a value for the \"Name of the Resource\" field.");
		resourceArea.NameResource.focus();
		return false;
	}
	if (!isValidName(resourceArea.NameResource.value)) 
	 {
	  alert( "Value for the \"Name of the Resource\" field must be a valid Alpha numeric and should start with Alphabet." );
	  resourceArea.NameResource.focus();
	  return false;		
	 }
	if(resourceArea.typeResource.options[resourceArea.typeResource.selectedIndex].text=="Select")
	{
		alert ("Please select a value for the \"Type of Resource\" field.");
		resourceArea.typeResource.focus();
		return false;
	}
	if(resourceArea.resource_address.value!=""){
	if (!isValidStreetAddress(resourceArea.resource_address.value)) 
	 {
	  alert( "Value for the \"Resourece Address\" field must be a valid Alpha numeric and should start with Alphabet." );
	  resourceArea.resource_address.focus();
	  return false;		
	 }
	}
	if(resourceArea.resource_address1.value!=""){
	if (!isValidStreetAddress(resourceArea.resource_address1.value)) 
	 {
	  alert( "Value for the \"Address\" field must be a valid Alpha numeric and should start with Alphabet." );
	  resourceArea.resource_address1.focus();
	  return false;		
	 }
	}
	
	if(resourceArea.resource_city.value=="")
	{
		alert ("Please enter a value for the \"City\" field.");
		resourceArea.resource_city.focus();
		return false;
	}
	if (!isValidName(resourceArea.resource_city.value)) 
	 {
	  alert( "Value for the \"City\" field must be a valid Alpha numeric and should start with Alphabet." );
	  resourceArea.resource_city.focus();

	  return false;		
	 }

	if(resourceArea.resource_state.options[resourceArea.resource_state.selectedIndex].text=="Select")
	{
		alert ("Please Select value for the \"State\" field.");
		resourceArea.resource_state.focus();
		return false;
	}
	
	if(!isNumeric(resourceArea.resource_zip_code.value) && resourceArea.resource_zip_code.value!="")
   {
     alert( "Value for the \"Zip Code\" field must be a valid Numeric." );
	 resourceArea.resource_zip_code.focus();
	 return (false);
   }
  if(!isValidPhoneNumber(resourceArea.resource_phone_number.value) && resourceArea.resource_phone_number.value!="")
   {
    
	alert( "Value for the \"Phone\" field must be a valid Numeric." );
	 resourceArea.resource_phone_number.focus();
	 return (false);
   }
   /* if(resourceArea.resource_email.value!="")
	{
		var str = resourceArea.resource_email.value;
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!(!reg1.test(str) && reg2.test(str))) { // if syntax is valid
			alert ("Enter a valid Email Address for the \"Email\" field.");
			resourceArea.resource_email.focus();
			resourceArea.resource_email.value="";	
			return false;
		}

	}*/
	
	
	if(resourceArea.resource_website.value!=""){
	if (!IsWebsiteUrl(resourceArea.resource_website.value)) 
	 {
	  alert( "Invalid Website URL. For example: http://www.abc.com" );
	  resourceArea.resource_website.focus();
	  return false;		
	 }
	}
	
	if(resourceArea.resource_email.value!=""){
	if ( !IsEmailAddress(resourceArea.resource_email.value)) {//validate email
		alert( "Please enter a valid email addrress for the \"Email\" field and it should start with Alphabet." );
		resourceArea.resource_email.focus();
		return false;
	} 
	}

  if(resourceArea.description.value=="")
	{
		alert ("Please enter a value for the \"Description\" field.");
		resourceArea.description.focus();
		return false;
	}
		
if(resourceArea.description.value!=""){
 if (IsNumber(resourceArea.description.value) || isEmpty(resourceArea.description.value)) 
	 {
	 alert( "Value for the \"Description\" field must be a valid Alpha numeric and should start with Alphabet." );
	  resourceArea.description.focus();
	  return false;		
	 }
	}
	
	
}


/*
 *used to validate Network of Former Volunteer Form
*/

 /*
 *Function to get Ajax Object 
 */
function getXmlHttpObject()
{
	var objXMLHttp = null;
	if(window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest();
	}
	if(window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function validatenfvForm(action) {
	var form = document.nfvForm;
	var res;
	var regx = /^([0-9]{4})$/
	//Cancel button
	if (action == 'cancel')	{
		form.action.value = '';
		form.submit();
		return;
	}
	
	//submit button
	// do field validation
	if (action == 'save')
	if (form.firstname.value == "") {
		alert( "Please enter a value for the \"First Name\" field." );
		form.firstname.focus();
	} else if ( !isValidName(form.firstname.value)) {
		alert( "Value for the \"First Name\" field must be a valid Alpha numeric and should start witht Alphabet." );
		form.firstname.focus();
	} else if (form.lastname.value == "") {
		alert( "Please enter a value for the \"Last Name\" field." );
		form.lastname.focus();
	} else if ( !isValidName(form.lastname.value)) {
		alert( "Value for the \"Larst Name\" field must be a valid Alpha numeric and should start witht Alphabet." );
		form.lastname.focus();
	} else if (form.primaryemail.value == "") {
		alert( "Please enter a value for the \"Email address\" field." );
		form.primaryemail.focus();
	} else if (form.primaryemail.value != "" && !IsEmailAddress(form.primaryemail.value)) {//for valide email-address
			alert( "Please enter a valid email address for the \"Email address\" field and it should start with Alphabet." );
			form.primaryemail.focus();
	} else if (form.address1.value == "") {
		alert( "Please enter a value for the \"Street Address\" field." );
		form.address1.focus();
	} else if (form.city.value == "") {
		alert( "Please enter a value for the \"City\" field." );
		form.city.focus();
	} else if (form.programstarted.value != "" && !regx.test(form.programstarted.value)) {
		alert( "Value for the \"Year you began your program:\" field should be 4 digit year." );
		form.programstarted.focus();
	} else if (form.programended.value != "" && !regx.test(form.programended.value)) {
		alert( "Value for the \"Year you finished your program:\" field should be 4 digit year." );
		form.programended.focus();
	} else if (form.primaryemail.value != "") {//for duplication
		if(IsEmailAddress(form.primaryemail.value))
			validateEmailDuplication(form.primaryemail.value, form.status.checked, form, action, '');
		else {
			alert( "Please enter a valid email address for the \"Email address\" field and it should start with Alphabet." );
			form.primaryemail.focus();
			return false;
		}
			
	} else {
		form.action.value = 'save';
		form.submit();
		return true;
	}
	
	return false;
}//function

//function Using AJAX by Jaya
function validateEmailDuplication(email_value, checked_status, form, action, frm)
{
	
	email_value = Trim(email_value);
	var ajaxObj = getXmlHttpObject();
		var file_name = form.validateemail.value;
		var url=file_name+"?emailid="+email_value+"&frm="+frm;
		//var url="http://172.16.3.198/pallotti/validateemail.php?emailid="+email_value+"&frm="+frm;
		ajaxObj.onreadystatechange=function() {
			if(ajaxObj.readyState==4 || ajaxObj.readyState=='complete')	{
				response =  ajaxObj.responseText;
				
				if(response == 'Y'  && !checked_status) {
					
						alert("Email address already exists in database. Is this update? if so please check the checkbox\n\"This is an update. I am already in the Network.\"")
						return false;
					
				} else if(response == 'N'  && checked_status) {
					
					alert("your email address is not available in database to update your profile. Please uncheck the checkbox   \n\"This is an update. I am already in the Network.\" or provide previous email address")
						return false;
					
				} else { //submit form
					form.action.value = action;
					form.submit();
					return true;
					
				}
				
				
			}
		}//chatObj.onreadystatechange=function()
		ajaxObj.open("GET",url,true);
		ajaxObj.send(null);
		
		
	
}

function validateJBForm(action) {
	var form = document.JBForm;
	//Cancel button
	if (action == 'cancel')	{
		form.action.value = '';
		form.submit();
		return;
	}
	///^([0-9]+)$/
	reg = /^([0-9\-\,]*)$/;
	
	//submit buttonisAlphaNumeric(str)
	// do field validation
	if (action == 'subscribe')
	if (form.firstname.value == "") {
		alert( "Please enter a value for the \"First Name\" field." );
		form.firstname.focus();
	} else if ( !isValidName(form.firstname.value)) {
		alert( "Value for the \"First Name\" field must be a valid Alpha numeric and should start witht Alphabet." );
		form.firstname.focus();
	} else if (form.lastname.value == "") {
		alert( "Please enter a value for the \"Last Name\" field." );
		form.lastname.focus();
	} else if ( !isValidName(form.lastname.value)) {
		alert( "Value for the \"Last Name\" field must be a valid Alpha numeric and should start witht Alphabet." );
		form.lastname.focus();
	} else if (form.email.value == "") {
		alert( "Please enter a value for the \"Email\" field." );
		form.email.focus();
	} else if (form.email.value != "" && !IsEmailAddress(form.email.value)) {//for valide email-address
			alert( "Please enter a valid email address for the \"Email\" field and it should start with Alphabet." );
			form.email.focus();
	} else if (isEmpty(form.program.value)) {
		alert( "Please enter a value for the \"Volunteer program you were in\" field." );
		form.program.focus();
	} else if (form.yearsserved.value == "") {
		alert( "Please enter a value for the \"year(s) you were in the program\" field." );
		form.yearsserved.focus();
	} else if (form.yearsserved.value != "" && !reg.test(form.yearsserved.value)) {
		alert( "Please enter a valid value for the \"year(s) you were in the program\" field." );
		form.yearsserved.focus();
	} else if (form.email.value != "") {//for duplication
		if(IsEmailAddress(form.email.value))
			validateEmailDuplication(form.email.value, form.status.checked, form, action, 'JB');
		else {
			alert( "Please enter a valid email address for the \"Email address\" field and it should start with Alphabet." );
			form.email.focus();
			return false;
		}
			
	} else {
		form.action.value = 'subscribe';
		form.submit();
		return true;
	}
	
	return false;
}//function

function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space){
	}
	else
	{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
	}
	iTemp = iTemp-1;
	
	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


function noCharacters(e,oBj)
{
	var keynum
	var keychar
	var numcheck
	
	if(window.event) // IE
	{
	keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which
	}
	var keychar = String.fromCharCode(keynum);
	
	var digitsCheck = /[0-9 ]/;
	
	if(oBj.value.length <= 0)
	{		
		var key = window.event ? e.keyCode : e.which;
		var keychar = String.fromCharCode(key);
		if(digitsCheck.test(keychar)) {
			alert("First character should be alphabet");
			
		}
		return (!(digitsCheck.test(keychar)));
		
	}
		
}

function checkInitialChar(oBj)
{
	if(oBj.value.length > 1)
	{
		if(isNaN(oBj.value.substr(0,1)))
		{
			return true;
		}
		else
		{
			alert('First Character should be alphabet');
			oBj.focus();
			return false;
		}
	}
}



//back to searchresults
function backToSearchResults()
{
	form = document.cdForm;
	form.action.value = 'search';
	form.submit();
	return true;
}
function IsWebsiteUrl(str)
{
	
	if(isEmpty(str)) return false; //if the value is empty (i.e all spaces)
	
	var urlRegxp = "(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}[0-9A-Za-z\.\-]*\.[0-9A-Za-z\.\-]*$";
	
	var urlRegxp = new RegExp();
    urlRegxp.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!urlRegxp.test(str)) {
        return false;
    }
	else
		return true;

}
function IsNumber(source)
{
  var ValidChars = "0123456789";
  var Char;
  
  if(isEmpty(source)) return false; //if the value is empty (i.e all spaces)
  
  for (i = 0; i < source.length; i++) 
  { 
    Char = source.charAt(i); 
    if (ValidChars.indexOf(Char) == -1){
     return false;
    }
  }
  return true;
}
function isValidPhoneNumber(num)//valid phone number ex:415-422-2188
{
	
	num = Trim(num);
	reg = /^([0-9]+)([0-9\-\.]*)$/;	
    if (reg.test(num))
	   return true;
	else
		return false;
	
}



function getConnDirDetails(connid,id)
{		
		//document.getElementById(id).style.border='none';	
		var	cnt = document.getElementById("conn_count").value;
		var connid=connid.split("*");
	    var ajaxObj = getXmlHttpObject();
		var url="http://mahesha/pallotti/index.php?m=cd&action=view&connid="+connid[0];
		ajaxObj.onreadystatechange=function() {
			if(ajaxObj.readyState==4 || ajaxObj.readyState=='complete')	{
				response = ajaxObj.responseText;
				
				var finalResult = response.split("<!-- Test-->");
				
				for(i=1; i<=cnt; i++) {
					
					if(id == i) 
					{ 						
						document.getElementById("displayName"+i).style.display ="none";
						document.getElementById("conn_details_conn"+i).style.display ="";
//						document.getElementById("displayName"+i).style.display ="none";
						document.getElementById("conn_details_conn"+i).innerHTML = finalResult[1];
						
					}//if
					else
					{
						
						document.getElementById("conn_details_conn"+i).style.display ="none";
						document.getElementById("displayName"+i).style.display ="";
					}

				}//for

			}
		}
		ajaxObj.open("GET",url,true);
		ajaxObj.send(null);		
}


function valList() {
	
	var thissel=document.getElementById("connections");
	var selCount = 0;
	for (var i=0; i<thissel.length; i++) {
	  if (thissel[i].selected) {
	  		if(thissel[i] != -1){
				selCount += 1;
			}
	}
	}
	if(selCount>5){
	alert("not allowed to select more than 5 Program");	 
	return false;
	}
}

