// JavaScript Document

var bodytext=""; 
function submitForm() {
	var i;
	var tflag=0;
 	bodytext="";
	var tflagZero=0;
	var Total=0;
	// Need to enable controls whose values are needed server side
	for (i = 1; i <= 6; i++) 
	{
		if(document.getElementById('Fund' + i).value != -1)
		{
			if(document.getElementById('Amount' + i).value < 1)
			{
				tflagZero=1;
			}
			tflag=1;
			bodytext=bodytext+" "+document.getElementById('Fund' + i).value+" : ";
			bodytext=bodytext+" $"+document.getElementById('Amount' + i).value+"";
			Total = Total + parseInt(document.getElementById('Amount' + i).value);
			bodytext=bodytext+"\n";
		}
	}
	
	bodytext=bodytext+" Total : ";
	bodytext=bodytext+" $"+Total+"";
	bodytext=bodytext+"\n";
	
	bodytext=bodytext+"\n";
	bodytext=bodytext+"Start Date: " + document.getElementById('start_month').value + "/" + document.getElementById('start_year').value+"\n";
	bodytext=bodytext+"End Date: " + document.getElementById('end_month').value + "/" + document.getElementById('end_year').value;
	bodytext=bodytext+"\n";
	
	if(tflag==0)
	{
		alert("Select your donation");
	}
	else
	{
		if(tflagZero==1)
		{
			tflagZero=0;
			alert("Donation should be greater than ZERO");
		}
		else if(document.getElementById("txtTotalDonationAmount").value != "0" && document.getElementById("txtTotalDonationAmount").value != "")
		{
			document.getElementById('hdnBody1').value=bodytext;
			document.Form1.submit();
		}
		else
		{
			alert("Enter your donation");
		}
	}
}

function submitForm1() {
	var i;
	var tflag=0;
 	bodytext="";
	var Total=0
	// Need to enable controls whose values are needed server side
	for (i = 1; i <= 6; i++) 
	{
		if(document.getElementById('Fund' + i).value != -1)
		{
			tflag=1;
			bodytext=bodytext+" "+document.getElementById('Fund' + i).value+" : ";
			bodytext=bodytext+" $"+document.getElementById('Amount' + i).value+"";
			Total = Total + parseInt(document.getElementById('Amount' + i).value);
			bodytext=bodytext+"\n";
		}
	}
	
	bodytext=bodytext+" Total : ";
	bodytext=bodytext+" $"+Total+"";
	bodytext=bodytext+"\n";
	
	if(tflag==0)
	{
		alert("Select your donation");
	}
	else
	{
		if(document.getElementById("txtTotalDonationAmount").value != "0" && document.getElementById("txtTotalDonationAmount").value != "")
		{
			document.getElementById('hdnBody1').value=bodytext;
			document.Form1.action="donation-bank.php";
			document.Form1.submit();
		}
		else
		{
			alert("Enter your donation");
		}
	}
}
 
function SetTotal() 
{
	var Total=0;
	for(i=1;i<=6;i++)
	{
		if(document.getElementById('Amount'+i).value=="")
			document.getElementById('Amount'+i).value=0;
		Total=Total+parseInt(document.getElementById('Amount'+i).value);
	}
	document.getElementById('txtTotalDonationAmount').value=Total;
}
 

function loadProgram(id) 
{
	if(document.getElementById("Fund"+id).value != "-1")
	{
		document.getElementById("Amount"+id).disabled=false;
		document.getElementById("Amount"+id).value=0;
		document.getElementById("Amount"+id).focus();
	}
	else
	{
		document.getElementById("Amount"+id).value=0;
		document.getElementById("Amount"+id).disabled=true;
	}
}

var type;
function validate(t){

	type=t;
	if (navigator.appName.indexOf("Microsoft") == -1){

	
		window.captureEvents(Event.KEYPRESS);
		window.onkeypress = validate2;

	}else{
	
		validate2(window.event);
	}


}
//this function used for checking character validation on given text field
function validate2(e){

	var validString;
	var code;
	
	if (navigator.appName.indexOf("Microsoft")!= -1){

			code = e.keyCode;

	}else{
		
		code = e.which;
	}
	
	if(type == "")
		return;

	var ch = String.fromCharCode(code);
	if(type == "ALPHA_NUMERIC"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 ";
	
	}else if(type == "EMAIL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@._-";

	}else if(type == "ALPHA_NUMERIC_COMMA"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@. _,-";

	}else if(type == "NUMBER"){

		validString="0123456789 .";

	}else if(type == "ONLYNUMBER"){

		validString="1234567890";

	}else if(type == "ALPHA"){

		validString="abcdefghijklmnopqrstuvwxyz ";

	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'-\"";

	}else if(type == "URL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789.:";

	}else if(type == "PHONE"){
	
		validString="1234567890() -abcdefghijklmnopqrstuvwxyz";
	
	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR_WITH_QUOTES"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'\"";

	}else if(type == "TIME"){
		
		validString="1234567890:";
	}else if(type == "BIRTH_DATE"){
		
		validString="1234567890/";

		
	}else if(type == "COMPANYNAME")
		validString="abcdefghijklmnopqrstuvwxyz0123456789 '";
	
	type = "";

	
	//code of ENTER key
		if( code != 13){

				if( validString.indexOf( ch.toLowerCase() ) == -1 ){



				if(e.keyCode){

					e.keyCode=0;

					}else{				
						return false;

				}

			
		}
	}
}

function resetall()
{
	for(i=1;i<=11;i++)
	{
		document.getElementById("txt"+i).value="0";
	}
}

function calculateTotal()
{
	var total=0;
	
	for(i=1;i<=9;i++)
	{
		total=total+parseInt(document.getElementById("txt"+i).value);
	}
	document.getElementById("txt10").value=total;
	document.getElementById("txt11").value=(total*2.5)/100;
}

function viewPage(page){

window.open(page,'_blank',config='left='+(screen.width - 760)/2+',top='+(screen.height - 600)/2+',screenX='+(screen.width - 760)/2+',screenY='+(screen.height - 600)/2+',height=600,width=760,titlebar=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');

}

function checkblank()
	{
		if(document.getElementById("name").value=="")
		{
			alert("Please enter your name")
			document.getElementById("name").focus();
			return false;
		}
		if(document.getElementById("hphone").value=="")
		{
			alert("Please enter home phone number")
			document.getElementById("hphone").focus();
			return false;
		}
		if(document.getElementById("grandtotal").value=="" || document.getElementById("grandtotal").value=="0")
		{
			alert("Please donate here")
			document.getElementById("hphone").focus();
			return false;
		}
		
	}
 


var testresults;
function checkEmail(txt){
	
	trim(txt);
	var str=txt.value;
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
	testresults=true
	}else{
		
		testresults=false
	}
	return (testresults)

}
//...........................function that trim any control value......................
function trim(text){

	var chr=false;
	var len;

	for(i=0;i<text.value.length;i++){
		
		if(text.value.substr(i,1) != " "){
			chr=true;
			len = i;
			break;

		}

	}
	
	if(chr == false){

		text.value="";
	
	}else{

		text.value = text.value.substr(len,text.value.length);
	
	}


	for(i = text.value.length ; i>0 ; i--){
		
		if(text.value.substr(i-1,1) != " "){
			len = i;
			break;

		}

	}
	
	text.value = text.value.substr(0,len);

}

function sendmail()
{
	document.getElementById("Inputform").submit();
}

function doblank()
	{
		if(document.getElementById('strLicense').value == "License Number")
		{
			document.getElementById('strLicense').value = "";
		}
		
	}
function checkblankVolunteer()
	{
		if(document.getElementById('strLicense').value == "")
		{
			document.getElementById('strLicense').value = "License Number";
		}
	}
	
	