
function $(objid)
{
	return document.getElementById(objid);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(eid){
	var emailID=$(eid);
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		$('eerr').style.visibility = 'visible';
		return false
	}
	if (echeck(emailID.value)==false){

		$('eerr').style.visibility = 'visible';
		return false
	}
	$('eerr').style.visibility = 'hidden';
	return true
 }

function ValidatePhone(pid)
{
	var phoneObj = $(pid);
   if(phoneObj.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
      $('perr').style.visibility = 'visible';
      return false;
   }
   
   $('perr').style.visibility = 'hidden';
   return true;
}

	function checkForm( called )
	{
		if (called == 'talk')
		{
			var emailok = ValidateEmail('email');
 			var phoneok = ValidatePhone('phone');
 			var commok = ($('comments').value.length > 0) ? true : false;
 			var fnok = ($('fname').value.length > 0) ? true : false;
 			var lnok = ($('lname').value.length > 0) ? true : false;
 			
 			if (commok == false )
			{
				$('cerr').style.visibility = 'visible';
				alert(' Comments must not be left empty');
			}
			else
			{
				$('cerr').style.visibility = 'hidden';
			}
			
 			if (fnok == false )
			{
				$('fnerr').style.visibility = 'visible';
				alert('First name is required');
			}
			else
			{
				$('fnerr').style.visibility = 'hidden';
			}
			
			if (lnok == false )
			{
				$('lnerr').style.visibility = 'visible';
				alert ('Last Name is required');
			}
			else
			{
				$('lnerr').style.visibility = 'hidden';
			} 
			
			if ( lnok == true &&  fnok == true && commok == true && phoneok == true && emailok == true )
			{
				return true;
			}
		}
		else if ( 'help' == called )
		{
			var emailok = ValidateEmail('email');
 			var phoneok = ValidatePhone('phone');
 			var fnok = ($('fname').value.length > 0) ? true : false;
 			var lnok = ($('lname').value.length > 0) ? true : false;
 			//var ager = $('age').checked;
			
 			if (fnok == false )
			{
				$('fnerr').style.visibility = 'visible';
				alert('First name is required');
			}
			else
			{
				$('fnerr').style.visibility = 'hidden';
			}
			
			if (lnok == false )
			{
				$('lnerr').style.visibility = 'visible';
				alert ('Last Name is required');
			}
			else
			{
				$('lnerr').style.visibility = 'hidden';
			}
			//if (ager == false)
			//{
			//	$('aerr').style.visibility = 'visible';
			//	alert ('You must be over 18 Years of age.');
			//}
			//else
			//{
			//	$('aerr').style.visibility = 'hidden';
			//} 
			
			if (	lnok == true    &&  
						fnok == true    && 
						phoneok == true && 
						emailok == true )
			{
				return true;
			}
		}
		else if ( 'pray' == called )
		{
 			var fnok = ($('fname').value.length > 0) ? true : false;
 			var reqok = ($('request').value.length > 0) ? true : false;
			
			if (	fnok == true &&	reqok == true )
			{
				return true;
			}
		}
		else if ( 'sign' == called )
		{
 			var phoneok = ValidatePhone('phone');
 			var fnok = ($('fname').value.length > 0) ? true : false;
 			var lnok = ($('lname').value.length > 0) ? true : false;
			var ciok = ($('city').value.length > 0) ? true : false;
			var aook = ($('addrone').value.length > 0) ? true : false;
			var zok = ($('zip').value.length > 0) ? true : false;
			var sok = ($('state').value.length > 0) ? true : false;
			
 			if (fnok == false )
			{
				$('fnerr').style.visibility = 'visible';
				alert('First name is required');
			}
			else
			{
				$('fnerr').style.visibility = 'hidden';
			}
			
			if (lnok == false )
			{
				$('lnerr').style.visibility = 'visible';
				alert ('Last Name is required');
			}
			else
			{
				$('lnerr').style.visibility = 'hidden';
			}

			if (ciok == false )
			{
				$('cierr').style.visibility = 'visible';
				alert ('City is required');
			}
			else
			{
				$('cierr').style.visibility = 'hidden';
			}

			if (aook == false )
			{
				$('aoerr').style.visibility = 'visible';
				alert ('Address One is required');
			}
			else
			{
				$('aoerr').style.visibility = 'hidden';
			}
 
			if (zok == false )
			{
				$('zerr').style.visibility = 'visible';
				alert ('Postal Code is required');
			}
			else
			{
				$('zerr').style.visibility = 'hidden';
			}
 
			if (sok == false )
			{
				$('serr').style.visibility = 'visible';
				alert ('State is required');
			}
			else
			{
				$('serr').style.visibility = 'hidden';
			}

			
			if (	lnok == true    &&  
				 		fnok == true    &&
						ciok == true    && 
						sok == true     && 
						zok == true     &&
						aook == true    && 
						phoneok == true    )
			{
				return true;
			}
		}
		
		return false;
	}

 	function subtalk()
 	{
 		var cmd = '';
 		cmd += "<xml>";
 		cmd += "<fname>"+$('fname').value+"</fname>"; //req
 		cmd += "<lname>"+$('lname').value+"</lname>"; //req
		cmd += "<aone>"+$('addrone').value+"</aone>";
		cmd += "<atwo>"+$('addrtwo').value+"</atwo>";
		cmd += "<city>"+$('city').value+"</city>";
		cmd += "<state>"+$('state').value+"</state>";
		cmd += "<zip>"+$('zip').value+"</zip>";
		cmd += "<email>"+$('email').value+"</email>"; //req
		cmd += "<phone>"+$('phone').value+"</phone>"; //req
		cmd += "<comment>"+$('comments').value+"</comment>"; //req
		cmd += "</xml>";

		if ( checkForm('talk') == true )
		{		
			pushXML('./BackCode/talkBack.php', cmd, 'talkthanks', 'talk');
		}
 
 	}
 	
 	function subhelp()
 	{
 		
 		var selObj = document.getElementById('shirt');
 		var selIndex = selObj.selectedIndex;

 		var cmd = '';
 		cmd += "<xml>";
 		cmd += "<fname>"+$('fname').value+"</fname>"; //req
 		cmd += "<lname>"+$('lname').value+"</lname>"; //req
		cmd += "<aone>"+$('addrone').value+"</aone>";
		cmd += "<atwo>"+$('addrtwo').value+"</atwo>";
		cmd += "<city>"+$('city').value+"</city>";
		cmd += "<state>"+$('state').value+"</state>";
		cmd += "<zip>"+$('zip').value+"</zip>";
		cmd += "<email>"+$('email').value+"</email>"; //req
		cmd += "<phone>"+$('phone').value+"</phone>"; //req
		cmd += "<shirt>" +selObj.options[selIndex].value +"</shirt>";
		if ($('age').checked == true)                            //req
		{
			cmd += "<age>Y</age>";
		}
		else
		{
			cmd += "<age>N</age>";
		}
		cmd += "</xml>";
		
		if ( checkForm('help') == true )
		{		
			pushXML('./BackCode/helperBack.php', cmd, 'helpthanks', 'help');
		}
 
 	}
 	
 	function subsign()
 	{

 		var cmd = '';
 		cmd += "<xml>";
 		cmd += "<fname>"+$('fname').value+"</fname>"; //req
 		cmd += "<lname>"+$('lname').value+"</lname>"; //req
		cmd += "<aone>"+$('addrone').value+"</aone>"; //req
		cmd += "<atwo>"+$('addrtwo').value+"</atwo>"; //req
		cmd += "<city>"+$('city').value+"</city>";    //req
		cmd += "<state>"+$('state').value+"</state>"; //req
		cmd += "<zip>"+$('zip').value+"</zip>";       //req
		cmd += "<phone>"+$('phone').value+"</phone>"; //req
		cmd += "</xml>";
		
		if ( checkForm('sign') == true )
		{		
			pushXML('./BackCode/signBack.php', cmd, 'signthanks', 'signform');
		}
 
 	}
 	function subpray()
 	{
 		var cmd = '';
 		cmd += "<xml>";
 		cmd += "<fname>"+$('fname').value+"</fname>"; //req
		cmd += "<email>"+$('email').value+"</email>"; 
		cmd += "<request>"+$('request').value+"</request>"; //req
		cmd += "<ipaddr>"+$('ipaddr').value+"</ipaddr>"; //req
		cmd += "</xml>";

		if ( checkForm('pray') == true )
		{		
			pushXML('./BackCode/prayBack.php', cmd, 'praythanks', 'prayform');
		}
 
 	}
 	
 	