function ltrim(s)
	{
		return s.replace(/^\s*/,"")
	}

function rtrim(s)
	{
		return s.replace(/\s*$/,"");
	}

function trim(s)
	{
		return rtrim(ltrim(s));
	} 
function validate()
{
	var date1=new Date();
	var mon=date1.getMonth();
	var yr=date1.getFullYear();
	var expyr=document.frm.ExpirationYear.value;
	var expmon=document.frm.ExpirationMonth.value;
	var cardno=document.frm.CreditCard.value;
	if(trim(document.frm.DonorFirstName.value)=="")
		{
			alert("Please enter your Donor First Name");
			document.frm.DonorFirstName.focus();
			return false			   
		}
	if(trim(document.frm.DonorLastName.value)=="")
		{
			alert("Please enter your Donor Last Name");
			document.frm.DonorLastName.focus();
			return false			   
		}
	if(trim(document.frm.BillingAddress.value)=="")
		{
			alert("Please enter your Billing Address");
			document.frm.BillingAddress.focus();
			return false			   
		}
	if(trim(document.frm.BillingCity.value)=="")
		{
			alert("Please enter your Billing City");
			document.frm.BillingCity.focus();
			return false			   
		}
	if(trim(document.frm.BillingState.value)=="")
		{
			alert("Please enter your Billing State");
			document.frm.BillingState.focus();
			return false			   
		}
	if(trim(document.frm.BillingPostal.value)=="")
		{
			alert("Please enter your Billing Postal");
			document.frm.BillingPostal.focus();
			return false			   
		}
	if(trim(document.frm.BillingCountry.value)=="")
		{
			alert("Please enter your Billing Country");
			document.frm.BillingCountry.focus();
			return false			   
		}
	 if(document.frm.CreditCard.value=="")
		{
			alert("Please enter your Credit Card Number");
			document.frm.CreditCard.focus();
			return false
		}
		
	if(isNaN(document.frm.CreditCard.value))
		{
			alert("Please enter a Valid Credit Card Number");
			document.frm.CreditCard.focus();
			return false
		}
		
	if((cardno.length>16)||(cardno.length<16))
		{
			alert("Please enter a Valid Credit Card Number")
			document.frm.CreditCard.focus()
			return false
		}
	if(document.frm.ExpirationMonth.value=="")
		{
			alert("Please enter your Credit Card Expiry month");
			document.frm.ExpirationMonth.focus();
			return false
		}
	
	if(document.frm.ExpirationYear.value==0)
	{
		alert("Please enter your Credit Card Expiry year");
		document.frm.ExpirationYear.focus();
		return false
	}
	
	if((expyr==yr)&&(expmon<mon))
	{
		alert("Please enter a valid Credit Card Expiry month");
		document.frm.ExpirationMonth.focus();
		return false
	}
	if(document.frm.CardVerificationValue.value=="")
	{
		alert("Please enter your Credit Card security Code");
		document.frm.CardVerificationValue.focus();
		return false
	}
	
	if(isNaN(document.frm.CardVerificationValue.value))
	{
		alert("Please enter a Valid Credit Card security code");
		document.frm.CardVerificationValue.focus();
		return false
	}

	if(trim(document.frm.EmailAddress.value)=="")
	{
		alert("Please enter your Email Address");
		document.frm.EmailAddress.focus();
		return false
	}
	if (echeck(document.frm.EmailAddress.value)==false){
		 document.frm.EmailAddress.value=""
		 document.frm.EmailAddress.focus()
		return false
	}
	return true;
}
function tributeHandler()
{
	

	var val=document.frm.tribute_type.value;
	if(val==0)
		{
			document.getElementById("trib_type").style.display="none";
			document.getElementById("tribute_notification").style.display="none";
			document.getElementById("postal_notification").style.display="none";
			document.getElementById("email_notification").style.display="none";
		}
	else
		{
			document.getElementById("trib_type").style.display="block";
			document.getElementById("tribute_notification").style.display="block";
		}
}
function tributeNotificationHandler()
{
	var val=document.frm.tribute_notification_type.value;
	if(val==0)
		{
			document.getElementById("postal_notification").style.display="none";
			document.getElementById("email_notification").style.display="none";
		}
	if(val==1)
		{
			document.getElementById("postal_notification").style.display="none";
			document.getElementById("email_notification").style.display="block";
		}
	if(val==2)
		{
			document.getElementById("postal_notification").style.display="block";
			document.getElementById("email_notification").style.display="none";
		}
}
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("Please enter a valid Email Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid Email Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid Email Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid Email Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid Email Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid Email Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid Email Address")
		    return false
		 }

 		 return true					
	}