function stripBlanks(fld) 
{
   var result = "";
   var c = 0;
   for (i=0; i<fld.length; i++) 
   {
		if (fld.charAt(i) != " " || c > 0) 
		{
			result += fld.charAt(i);
			if (fld.charAt(i) != " ") 
				c = result.length;
		}
   }
   return result.substr(0,c);
} 

function VerForm(myform)
{
 // This function veryfies the required fields
 // the variable myform get the form(rgstForm) as its value
 var alertStr="";  // hold names of missing fields
 var fname="";  // hold the string of FirstName after spaces striping
 var lname="";  // hold the string of LastName after spaces striping

 //Stripe the initial space of FirstName and LastName
 fname=stripBlanks(myform.firstname1.value);
 lname=stripBlanks(myform.lastname1.value);

 //Verify the required fields
 if (fname=="") 
	alertStr="First Name";
 if (lname=="")
 {
    if (alertStr=="") alertStr="Last Name";
    else alertStr=alertStr+", Last Name";
  }

 if(alertStr=="")
 {
    //alert(fname.length);
    //alert(fname.trim.length); 
    return true;
 }
 else
 {
	 alertStr=alertStr+" are required!";
	 alert(alertStr);
     return false;
 }  
}

function check( fromButton, toButton, maxChars)
{
	if ( fromButton.value.length == maxChars )
		toButton.focus();
}

function VerForm1(myform)
{
 // This function veryfies the required fields
 // the variable myform get the form(rgstForm) as its value
 var alertStr="";  // hold names of missing fields
 var projecttitle="";  // hold the string of project title after spaces striping

 //Stripe the initial space of project title
 projecttitle=stripBlanks(myform.projecttitle.value);

 //Verify the required fields
 if (projecttitle=="") 
	alertStr="Poject Title";

 if(alertStr=="")
 {
    //alert(fname.length);
    //alert(fname.trim.length); 
    return true;
 }
 else
 {
	 alertStr=alertStr+" is required!";
	 alert(alertStr);
     return false;
 }  
}

function VerForm2(myform)
{
	// This function veryfies the required fields
	// the variable myform get the form(rgstForm) as its value
	var alertStr="";  // hold names of missing fields
	var projecttitle="";  // hold the string of project title after spaces striping
	
    projecttitle=myform.projecttitle.value;
   
	//Verify the required fields
	if (projecttitle=="") alertStr="Project Title";

	if(alertStr=="")
	   return true;
	else
	{alertStr=alertStr+" is required!";
		alert(alertStr);
		return false;
	}  
}

//check max size of field
function maxString(myfield, max_size){
	if(myfield.value.length <= max_size)
		return true;
	else{
		return false;
	}
}

// require min and max characters size be entered.
function validateString(myfield, l_size, u_size) {
	if (notNull(myfield.value) && notBlank(myfield.value)) {
		if ((myfield.value.length >= l_size) && (myfield.value.length <= u_size))
			return true;
		else {
			myfield.focus();
			return false;
		}
	} else {
		myfield.focus();
		return false;
	}
	
}

//check null field
function notNull(str) 
{
  if (str.length == 0 )
     return false;
  else 
     return true;
}

//check empty field
function notBlank(str)
{
  for (i = 0; i < str.length; i++)
  {
       if (str.charAt(i) != " ")
	       return true;
  }
  return false;
}

// Initials allows ONLY alphanumeric keys and three "'", "-" and "!"
// this can be altered for any "checkOK" string you desire
function checkPersonName(myfield) {
	  var checkOK = "ÀÁÂÇÈÉÊÌÍÎÒÓÔÙÚÛÝàáâçèéêìíîòóôùúûABCDEFGHIJKLMNOPQRSTUVWXYZ!-' abcdefghijklmnopqrstuvwxyz";
	  var checkStr = myfield.value;
	  var allValid = true;

	  for (i = 0;  i < checkStr.length;  i++)
	  {
		var ch = checkStr.charAt(i);
		for (var j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j)){
			//alert("check number and letter");
			break;
		}
		if (j == checkOK.length)
		{
		  allValid = false;
		  //alert("number and letter not found! ");
		  break;
		}
	  }
	  if (!allValid)
	  {
		//alert("Please enter only letter and numeric characters in the \"personName\" field.");
		myfield.focus();
		return (false);
	  }
	  else{
		  return (true);
	  }
}

function checkForm1(form) 
{
		if ( !validateString(document.forms[0].firstname1, 1, 50) || !checkPersonName(document.forms[0].firstname1))
		{
			alert('The first name length is between 1 to 50 characters');
			form.firstname1.focus();
			return false;
		}
		else if ( !validateString(document.forms[0].lastname1, 1, 50) || !checkPersonName(document.forms[0].lastname1))
		{
			alert('The last name length is between 1 to 50 characters');
			form.lastname1.focus();
			return false;
		}
		else if ( !maxString(document.forms[0].area1, 3800) )
		{
			alert('Max characters for biographical field is 3800');
			form.area1.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area2, 1900))
		{
			alert('Max characters for applicant responsibilities field is 1800');
			document.forms[0].area2.focus();
			return false;
		}
		
		
		return true;
}

function checkForm2(form) 
{
		if ( !validateString(document.forms[0].projecttitle, 1, 255))
		{
			alert('The project title length is between 1 to 255 characters');
			form.projecttitle.focus();
			return false;
		}

		else if ( !maxString(document.forms[0].area3, 500) )
		{
			alert('Max characters for describe what project related activities have been carried out to date field is 500');
			form.area3.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area4, 500))
		{
			alert('Max characters for project summary field is 500');
			document.forms[0].area4.focus();
			return false;
		}
		else if ( !maxString(document.forms[0].area5, 500) )
		{
			alert('Max characters for short term goals field is 500');
			form.area5.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area6, 500))
		{
			alert('Max characters for long term goals field is 500');
			document.forms[0].area6.focus();
			return false;
		}
		else if ( !maxString(document.forms[0].area7, 500) )
		{
			alert('Max characters for target community field is 500');
			form.area7.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area8, 500))
		{
			alert('Max characters for why should fund field is 500');
			document.forms[0].area8.focus();
			return false;
		}
		else if ( !maxString(document.forms[0].area9, 500))
		{
			alert('Max characters for assess the achievement field is 500');
			document.forms[0].area9.focus();
			return false;
		}
		
		
		return true;
}


function checkForm3(form) 
{
		if ( !maxString(document.forms[0].area10, 1250) )
		{
			alert('Max characters for current community partners field is 1800');
			form.area10.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area11, 1250) )
		{
			alert('Max characters for organizations you plan to work field is 1800');
			form.area11.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area12, 1250))
		{
			alert('Max characters for project related activities field is 1800');
			document.forms[0].area12.focus();
			return false;
		}
		
		
		return true;
}

function checkForm4(form) 
{
		if ( !maxString(document.forms[0].area13, 1000) )
		{
			alert('Max characters for past, current and future funding source field is 1000');
			form.area13.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[0].area14, 2000) )
		{
			alert('Max characters for how do you plan to sustain this project field is 2000');
			form.area14.focus();
			return false;
		}		
		
		return true;
}

function checkForm(form)
{
		if ( !validateString(document.forms[1].firstname1, 1, 50) || !checkPersonName(document.forms[1].firstname1))
		{
			alert('The first name length is between 1 to 50 characters');
			form.firstname1.focus();
			return false;
		}
		else if ( !validateString(document.forms[1].lastname1, 1, 50) || !checkPersonName(document.forms[1].lastname1))
		{
			alert('The last name length is between 1 to 50 characters');
			form.lastname1.focus();
			return false;
		}
		else if ( !maxString(document.forms[1].area1, 3500) )
		{
			alert('Max characters for biographical field is 3500');
			form.area1.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area2, 1900))
		{
			alert('Max characters for applicant responsibilities field is 1900');
			document.forms[1].area2.focus();
			return false;
		}
		
		else if ( !validateString(document.forms[1].projecttitle, 1, 255))
		{
			alert('The project title length is between 1 to 255 characters');
			form.projecttitle.focus();
			return false;
		}

		else if ( !maxString(document.forms[1].area3, 380) )
		{
			alert('Max characters for describe what project related activities have been carried out to date field is 380');
			form.area3.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area4, 1500))
		{
			alert('Max characters for project summary field is 1500');
			document.forms[1].area4.focus();
			return false;
		}
		else if ( !maxString(document.forms[1].area5, 380) )
		{
			alert('Max characters for short term goals field is 380');
			form.area5.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area6, 380))
		{
			alert('Max characters for long term goals field is 380');
			document.forms[1].area6.focus();
			return false;
		}
		else if ( !maxString(document.forms[1].area7, 380) )
		{
			alert('Max characters for target community field is 380');
			form.area7.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area8, 380))
		{
			alert('Max characters for why should fund field is 380');
			document.forms[1].area8.focus();
			return false;
		}
		else if ( !maxString(document.forms[1].area9, 380))
		{
			alert('Max characters for assess the achievement field is 380');
			document.forms[1].area9.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area10, 1250) )
		{
			alert('Max characters for current community partners field is 1250');
			form.area10.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area11, 1250) )
		{
			alert('Max characters for organizations you plan to work field is 1250');
			form.area11.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area12, 1250))
		{
			alert('Max characters for project related activities field is 1250');
			document.forms[1].area12.focus();
			return false;
		}

		else if ( !maxString(document.forms[1].area13, 1000) )
		{
			alert('Max characters for past, current and future funding source field is 1000');
			form.area13.focus();
			return false;
		}
		
		else if ( !maxString(document.forms[1].area14, 2000) )
		{
			alert('Max characters for how do you plan to sustain this project field is 2000');
			form.area14.focus();
			return false;
		}	
		
		else if ( !validateString(document.forms[1].projectactivity, 1, 600))
		{
			alert('The project activity must be attached');
			form.projectactivity.focus();
			return false;
		}

		else if ( !validateString(document.forms[1].estimatedbudget, 1, 600))
		{
			alert('The project extimated budget must be attached');
			form.estimatedbudget.focus();
			return false;
		}
		
		return true;
}




