var isMinNS4 = document.layers ? 1 : 0;
var isMinIE4 = document.all ? 1 : 0;
var flag = 0;
var remail=/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+\.+[a-zA-Z0-9-]+|[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+\.+[a-zA-Z0-9-]+\.+[a-zA-Z0-9-]+)$/;


function dynamicOption(frmDonation){
	var puja = new Array(" ","Pushpanjali: Rs.5/-","Mangalarathi: Rs.5/-","Thrimadhuram: Rs.11/-","Neyyvilakku: Rs.15/-","Anna Prasam: Rs.5/-","Panineer Abhishekam: Rs.20/-","Elaneer Abhishekam: Rs.5/-","Kedavilakku (One day): Rs.11/- (Things Extra.)","Kedavilakku (One month): Rs.301/-  Things Extra","Chuttuvilakkum Nirmalayum: Rs.1001/-","Pooja: Rs.51/-","Bal Bhojan Payasam: Rs.250/-","Ganapathi Homam: Rs.151/-","Mrithynjaya Homam: Rs.101/-","Vahana pooja: Rs.15/- (things extra)","Thulabharam: Rs.11/-");
	//var others = new Array(" ","Balbhojan","Sadhubhojan","School","College","No specific reason");
	var others = new Array(" ","Gurupurnima Fund","Datta Jayanti Fund","Mahashivratri Fund","Pranprathistha Fund","Jananand Swami Edu Fund (School)","Builing Const. & Maintenance Fund","English Medium Fund","Medical Aim Fund","Bal Bhojan (Rs.251/-)","Sadhu Bhojan","College Fund","Guruvan Fund","Tree Plantation Fund (Rs. 501/-)","other");
	var obj = new Array();
	if(frmDonation.optPuja[0].checked == true)	{
		frmDonation.mnuPuja.length = puja.length;
		for(var counter=1;counter<puja.length;counter++)	{
			obj[counter] = new Option(puja[counter],puja[counter]);
			frmDonation.mnuPuja[counter] = obj[counter];
		}
	}
	if(frmDonation.optPuja[1].checked == true)	{
		frmDonation.mnuPuja.length = others.length;
		for(var counter=1;counter<others.length;counter++)	{
			obj[counter] = new Option(others[counter],others[counter]);
			frmDonation.mnuPuja[counter] = obj[counter];
		}
	}
			
}

function setFocus(fieldname)	{
	if(document.forms[0].optMode[0].checked == true)	{
		flag = 1;
	}
	else {
		flag = 0;
	}
	if(flag == 1)
		document.forms[0].txtContactPerson.focus();
	else if(flag == 0)	{
		fieldname.focus();
	}
}

function amountChecker(frm){

	var amtArr = new Array(" ","5","5","11","15","5","20","5","11","301","1001","51","250","151","101","15","11");
	var amtArr1 = new Array(" "," "," "," "," "," "," "," "," ","251"," "," "," "," "," "," "," ");
	
	
	// this is puja
	if(frm.optPuja[0].checked == true ){
		if(frm.cmbCurrency.options[frm.cmbCurrency.selectedIndex].value == "INR"){
			if((frm.mnuPuja.selectedIndex == 1) || (frm.mnuPuja.selectedIndex == 2) || (frm.mnuPuja.selectedIndex == 3) || (frm.mnuPuja.selectedIndex == 4) || (frm.mnuPuja.selectedIndex == 5) || (frm.mnuPuja.selectedIndex == 6) || (frm.mnuPuja.selectedIndex == 7) || (frm.mnuPuja.selectedIndex == 8) || (frm.mnuPuja.selectedIndex == 11) || (frm.mnuPuja.selectedIndex == 15) ||	(frm.mnuPuja.selectedIndex == 16)){
				return "101";
			} else if((frm.mnuPuja.selectedIndex == 13) ||(frm.mnuPuja.selectedIndex == 14)){
				return "201";
			} else if((frm.mnuPuja.selectedIndex == 9) ||(frm.mnuPuja.selectedIndex == 11)){
				return "501";
			} else if((frm.mnuPuja.selectedIndex == 10)){
				return "1111";
			}
		} else {
			if((frm.mnuPuja.selectedIndex == 1) || (frm.mnuPuja.selectedIndex == 2) || (frm.mnuPuja.selectedIndex == 3) || (frm.mnuPuja.selectedIndex == 4) || (frm.mnuPuja.selectedIndex == 5) || (frm.mnuPuja.selectedIndex == 6) || (frm.mnuPuja.selectedIndex == 7) || (frm.mnuPuja.selectedIndex == 8) || (frm.mnuPuja.selectedIndex == 11) || (frm.mnuPuja.selectedIndex == 14) || (frm.mnuPuja.selectedIndex == 15) || (frm.mnuPuja.selectedIndex == 16)){
				return "5";
			} else if((frm.mnuPuja.selectedIndex == 9) ||(frm.mnuPuja.selectedIndex == 12) ||(frm.mnuPuja.selectedIndex == 13)){
				return "10";
			} else if((frm.mnuPuja.selectedIndex == 10)){
				return "30";
			}	
		} 
	}

	// this is other
		if(frm.optPuja[1].checked == true ){
		if(frm.cmbCurrency.options[frm.cmbCurrency.selectedIndex].value == "INR"){
			if((frm.mnuPuja.selectedIndex == 9)){
				return "251";
			} else if((frm.mnuPuja.selectedIndex == 13)){
				return "501";
			} else {
				return "101";
			} 
		} else {
			if((frm.mnuPuja.selectedIndex == 9)){
				return "10";
			} else if((frm.mnuPuja.selectedIndex == 13)){
				return "30";
			} else {
				return "10";
			} 
		} 
	}

}
function checkBlank(fieldvalue){
//	alert(fieldvalue);
	if(fieldvalue.length == 0)
		return true;
	else
		return false;	
		
}

function checkSpace(fieldvalue){
	if(fieldvalue.charAt(0) == " ")
		return true;
	else
		return false;		
}

function checkEmail(fieldvalue){
	if(remail.test(fieldvalue))
		return false;
	else
		return true;		
}
function checkNum(fieldvalue){
	
	if(isNaN(fieldvalue))
		return true;
	else 
		return false;
}


function submitForm(frmFeedBack){
	var err = new String();
	var focus;
	if(checkBlank(frmFeedBack.txtContactPerson.value) || checkSpace(frmFeedBack.txtContactPerson.value) ||  checkBlank(frmFeedBack.txtAddress.value) || checkSpace(frmFeedBack.txtAddress.value) || checkBlank(frmFeedBack.txtCity.value) || checkSpace(frmFeedBack.txtCity.value) || checkBlank(frmFeedBack.txtState.value) || checkSpace(frmFeedBack.txtState.value) || checkBlank(frmFeedBack.txtPin.value) || checkSpace(frmFeedBack.txtPin.value)|| checkNum(frmFeedBack.txtPin.value) || frmFeedBack.mnuCountry.selectedIndex == 0 || checkBlank(frmFeedBack.txtTelephone.value) || checkSpace(frmFeedBack.txtTelephone.value) || checkBlank(frmFeedBack.txtEmail.value) || checkSpace(frmFeedBack.txtEmail.value) || checkEmail(frmFeedBack.txtEmail.value) || checkBlank(frmFeedBack.txtNameOfPerson.value) || checkSpace(frmFeedBack.txtNameOfPerson.value) || (frmFeedBack.optPuja[0].checked == false && frmFeedBack.optPuja[1].checked == false) || frmFeedBack.mnuPuja.selectedIndex == 0 || frmFeedBack.cmbCurrency.selectedIndex == 0 ||  (frmFeedBack.optMode[0].checked == false && frmFeedBack.optMode[1].checked == false && frmFeedBack.optMode[2].checked == false && frmFeedBack.optMode[3].checked == false) || ((frmFeedBack.optMode[1].checked == true || frmFeedBack.optMode[2].checked == true) && (checkBlank(frmFeedBack.txtDD.value) || checkSpace(frmFeedBack.txtDD.value) || checkNum(frmFeedBack.txtDD.value) || checkBlank(frmFeedBack.txtDate.value) || checkSpace(frmFeedBack.txtDate.value) || checkBlank(frmFeedBack.txtBankName.value) || checkSpace(frmFeedBack.txtBankName.value)))){
		if(checkBlank(frmFeedBack.txtContactPerson.value)){
			err = "Please Enter Contact Persons Name\n";
			focus=1;
		}
		else if(checkSpace(frmFeedBack.txtContactPerson.value)){
			err +="Blank Spaces are not allowed\n";
			focus=1;
		}
		if(checkBlank(frmFeedBack.txtAddress.value)){
			err +="Please Enter Your Address\n";
			if(focus!=1){
				focus=2;
			}
		}
		else if(checkSpace(frmFeedBack.txtAddress.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1){
				focus=2;
			}
		}
		if(checkBlank(frmFeedBack.txtCity.value)){
			err +="Please Enter Your City Name\n";
			if(focus!=1 && focus!=2){
				focus=3;
			}
		}
		else if(checkSpace(frmFeedBack.txtCity.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2){
				focus=3;
			}
		}
		if(checkBlank(frmFeedBack.txtState.value)){
			err +="Please Enter Your State\n";
			if(focus!=1 && focus!=2 && focus!=3){
				focus=4;
			}
		}
		else if(checkSpace(frmFeedBack.txtState.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2 && focus!=3){
				focus=4;
			}
		}
		if(checkBlank(frmFeedBack.txtPin.value)){
			err +="Please Enter Your Pin/Zip\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4){
				focus=5;
			}
		}
		else if(checkSpace(frmFeedBack.txtPin.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4){
				focus=5;
			}
		}
		else if(checkNum(frmFeedBack.txtPin.value)){
			err +="Please Enter a Integer Number\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4){
				focus=5;
			}
		}
		if(frmFeedBack.mnuCountry.selectedIndex == 0){
			err +="Please Select Country from drop down menu\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5){
				focus=6;
			}
		}
		if(checkBlank(frmFeedBack.txtTelephone.value)){
			err +="Please Enter Your Telephone Number\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6){
				focus=7;
			}
		}
		else if(checkSpace(frmFeedBack.txtTelephone.value)){
		err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6){
				focus=7;
			}
		}
		if(checkBlank(frmFeedBack.txtEmail.value)){
			err +="Please Enter Your Email-Id\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7){
				focus=8;
			}
		}
		else if(checkSpace(frmFeedBack.txtEmail.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7){
				focus=8;
			}
		}
		else if(checkEmail(frmFeedBack.txtEmail.value)){
			err+="Invalid Email Address\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7){
				focus=8;
			}
		}
		if(checkBlank(frmFeedBack.txtNameOfPerson.value)){
			err +="Please Enter Name Of Person\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8){
				focus=9;
			}
		}
		else if(checkSpace(frmFeedBack.txtNameOfPerson.value)){
			err +="Blank Spaces are not allowed\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8){
				focus=9;
			}
		}
		if(frmFeedBack.optPuja[0].checked == false && frmFeedBack.optPuja[1].checked == false)	{
			err+="Please Select the purpose of donation\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9){
				focus=10;
			}		
		}
		if(frmFeedBack.optPuja[0].checked == true || frmFeedBack.optPuja[1].checked == true){
			if(frmFeedBack.mnuPuja.selectedIndex == 0)	{
				err+="Please Select Puja from the dropdown List\n"
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10){
					focus=11;
				}
			}		
		}

		
		if(frmFeedBack.cmbCurrency.selectedIndex == 0)	{
			err+="Please Select Currency Type\n"
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11){
				focus=21;
			}
		}		
		if(frmFeedBack.optMode[0].checked == false && frmFeedBack.optMode[1].checked == false && frmFeedBack.optMode[2].checked == false && frmFeedBack.optMode[3].checked == false)	{
			err+="Please Select the Mode of Payment\n";
			if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=21){
				focus=14;
			}
		}
		//else if(frmFeedBack.optMode[1].checked == true || frmFeedBack.optMode[2].checked == true)	{
		else if(frmFeedBack.optMode[1].checked == true || frmFeedBack.optMode[2].checked == true)	{
			if(checkBlank(frmFeedBack.txtDD.value))	{
				err+="Please Enter DD Number\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=21){
					focus=15;
				}
			}
			else if(checkSpace(frmFeedBack.txtDD.value))	{
				err+="Blank Spaces are not allowed\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=21){
					focus=15;
				}
			}
			else if(checkNum(frmFeedBack.txtDD.value))	{
				err+="Please a Number\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=21){
					focus=15;
				}
			}
			if(checkBlank(frmFeedBack.txtDate.value))	{
				err+="Please Enter Date\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=15 && focus!=21){
					focus=16;
				}
			}
			
			else if(checkSpace(frmFeedBack.txtDate.value))	{
				err+="Blank Spaces are not allowed\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=15 && focus!=21){
					focus=16;
				}
			}
			if(checkBlank(frmFeedBack.txtBankName.value))	{
				err+="Please Enter the name of the bank\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=15 && focus!=16 && focus!=21){
					focus=17;
				}
			}
			else if(checkSpace(frmFeedBack.txtBankName.value))	{
				err+="Blank Spaces are not allowed\n";
				if(focus!=1 && focus!=2 && focus!=3 && focus!=4 && focus!=5 && focus!=6 && focus!=7 && focus!=8 && focus!=9 && focus!=10 && focus!=11 && focus!=12 && focus!=14 && focus!=15 && focus!=16 && focus!=21){
					focus=17;
				}
			}
		}

		alert(err);
		if(focus == 1){
			frmFeedBack.txtContactPerson.focus();
		}
		if(focus == 2){
			frmFeedBack.txtAddress.focus();
		}
		if(focus == 3){
			frmFeedBack.txtCity.focus();
		}
		if(focus == 4){
			frmFeedBack.txtState.focus();
		}
		if(focus == 5){
			frmFeedBack.txtPin.focus();
		}
		if(focus == 6){
			frmFeedBack.mnuCountry.focus();
		}
		if(focus == 7){
			frmFeedBack.txtTelephone.focus();
		}
		if(focus == 8){
			frmFeedBack.txtEmail.focus();
		}
		if(focus == 9){
			frmFeedBack.txtNameOfPerson.focus();
		}
		if(focus == 10){
			frmFeedBack.optPuja[0].focus();
		}
		if(focus == 11){
			frmFeedBack.mnuPuja.focus();
		}
		if(focus == 21)	{
			frmFeedBack.cmbCurrency.focus();
		}		
		if(focus == 12){
			frmFeedBack.optMandir[0].focus();
		}
		if(focus == 14){
			frmFeedBack.optMode[0].focus();
		}
		if(focus == 15)	{
			frmFeedBack.txtDD.focus();
		}
		if(focus == 16)	{
			frmFeedBack.txtDate.focus();
		}
		if(focus == 17)	{
			frmFeedBack.txtBankName.focus();
		}
}
	else{
			frmFeedBack.amount.value = amountChecker(frmFeedBack); 
			document.forms[0].submit();

	}
}
