var ls_date2=null;
var date = new RegExp("^(((0[1-9]|[12][0-9]|3[01])([/])(0[13578]|10|12)([/])([1-2][0,9][0-9][0-9]))|(([0][1-9]|[12][0-9]|30)([/])(0[469]|11)([/])([1-2][0,9][0-9][0-9]))|((0[1-9]|1[0-9]|2[0-8])([/])(02)([/])([1-2][0,9][0-9][0-9]))|((29)(\.|-|\/)(02)([/])([02468][048]00))|((29)([/])(02)([/])([13579][26]00))|((29)([/])(02)([/])([0-9][0-9][0][48]))|((29)([/])(02)([/])([0-9][0-9][2468][048]))|((29)([/])(02)([/])([0-9][0-9][13579][26])))$");	

function validateForm()
{
	today = new Date() ;
	diff  = new Date();
	var Name = new RegExp("^[0-9a-zA-Z\\s\\.]{3,100}$");
   	var Add = new RegExp("^[A-Za-z0-9\\/\\#\\-\\_\\()\\s\\.\\,\\:\\&]{3,120}$");
	var amount = new RegExp("^([1-9]{1}[0-9]{0,7}|[1-9]{1}[0-9]{0,7}\\.[0-9]{2})$");
	if (checkName(document.form1.txtCustomerID.value))
	{
		alert("Please enter a valid Name of the Donor (eg Sachin Sharma)");
		document.form1.txtCustomerID.focus();
		return false;
	}
	else if (checkAddress1(document.form1.txtAdditionalInfo1.value))
	{
		alert("Please enter a valid Address (eg 7/7 I Flr, Old Rajinder Nagar,N D-60)");
		document.form1.txtAdditionalInfo1.focus();
		return false;
	}
 	else if (document.form1.txtAdditionalInfo2.value==0)
	{
		alert("Please Select the Name of the Donation Scheme (eg Amrut Manohi)");
		document.form1.txtAdditionalInfo2.focus();
		return false;
	}
 	else if (document.form1.txtAdditionalInfo3.value==0)
	{
		alert("Please Select the Name of the Bhog / Type of Donor (eg Amrut Manohi)");
		document.form1.txtAdditionalInfo3.focus();
		return false;
	}
 	else if (document.form1.txtTxnAmount.value==0)
	{
		alert("Please Select the Amount of Donation (eg 3000.00)");
		document.form1.txtTxnAmount.focus();
		return false;
	}
	else if (! document.form1.txtTxnAmount.value.match(amount))
	{
		alert("Please enter a valid Donation Amount (eg 3022.26)");
		document.form1.txtTxnAmount.focus();
		return false;
	}
    else if (checkDate())		
	{
		alert("Please enter a valid Date on which he/she intends to offer Bhog (eg 02/08/2006)");
		document.form1.bhog_date.focus();
		return false;
	}
	else if (document.form1.txtAdditionalInfo5.value==0)
	{
		alert("Please Select the Purpose of utilisation (eg Brahmin Bhojan)");
		document.form1.txtAdditionalInfo5.focus();
		return false;
	}
	else
	{
	ls_date2 = document.form1.bhog_date.value;
	sub_date12 = ls_date2.substring(0,2);
	sub_date22 = ls_date2.substring(3,5);
	sub_date32 = ls_date2.substring(6,10);
	if (! check_bhogdate())
	{
		return false;
	}
		var conv_Date2 = sub_date32 + sub_date22 + sub_date12;
		document.form1.txtAdditionalInfo4.value = conv_Date2;
		var str=document.form1.txtTxnAmount.value;
		if (str.indexOf(".")== -1)
		{
			str=str+".00";
		}
		document.form1.txtTxnAmount.value=str;
		//alert("Name of the donor = "+document.form1.txtCustomerID.value);
		//alert("Addess of the donor = "+document.form1.txtAdditionalInfo1.value);
		//alert("Name of the Donation Scheme = "+document.form1.txtAdditionalInfo2.value);
		//alert("Name of the Bhog / Type of Donor = "+document.form1.txtAdditionalInfo3.value);
		//alert("Bhog Date = "+document.form1.txtAdditionalInfo4.value);
		//alert("Amount of Donation (Rs. Ps.) = "+document.form1.txtTxnAmount.value);
		//alert("Purpose of utilisation = "+document.form1.txtAdditionalInfo5.value);
		document.all.item("form1").action="https://www.billdesk.com/pgidsk/servlet/com.pgidsk.controller.PGIBillerRequestHandler"
		document.form1.submit();
	}
}
function checkDate()
{
if (document.form1.bhog_date.value.length > 0)
{
	if (! document.form1.bhog_date.value.match(date))		
	{
		return true;
	}
	else
	{
		return false;
	}
}	
else
	{
	document.form1.bhog_date.value="00/00/2009";
	}		
}

function  check_bhogdate()
{
	var due_mmddyyyy =  new Date(sub_date22 +"/"+ sub_date12 +"/"+ sub_date32);
	diff.setTime(Math.abs(due_mmddyyyy.getTime() - today.getTime()));
	timediff = diff.getTime();
	var days = Math.floor(timediff / (1000 * 60 * 60 * 24));
	days = days + 2 ;
	//alert("days = "+days)
	if (due_mmddyyyy > today)
	{
		if(days >= 2000)
		{
			alert("Bhog Date:  should not be less than Today ");
			return false;
		}
		return true;
	}
	days = - days ;
	//alert("days ="+days);
	if(days <= -3)
	{
		alert("Bhog Date:  should not be less than Today ");
		return false;
	}
	return true;

}	
function checkName(str)
{
	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	else if(str.length>100 || str.length < 3)
	{
			return true;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ",str)))
    {
			return true;
    }
	else
	{
		return false;
	}
}
function checkAddress1(str)
{
	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	else if(str.length>120 || str.length < 3)
	{
			return true;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789., #&()/-_",str)))
    {
			return true;
    }
	else
	{
		return false;
	}
}
function checkAddress2(str)
{

	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	if(str.length>120 || str.length < 3)
	{
			return true;
	}
	else if(str=="")
	{
		
			return false;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ,#&()/-_",str)))
    {	
			
			return true;
    }
	
	else
	{
			return false;
	}
}
function checkForPraSpcChar(str, obj)
{
	var str1 = str;
    var str2 = obj;
	var str2Len = obj.length;
    var i,j;
    var ch;
    var check=false;
	for (i=0; i<str2.length; i++)
	{
       	check=false;
       	ch = str2.charAt(i);
		for (j=0; j<str1.length; j++)
		{

   			if (ch == str1.charAt(j))
			{
		     			check=true;
            	break;
            }
     	}
		if (!check)
			break;
     }
	    return check;
}
function trimSpaces (str)
{
    var len = str.length;
	var str1 = str;
    var loop=true;

	while(loop)
	{

		if (str1.charAt(0) == " ")
		{
			str1 = str1.substring(1);
			len = str1.length;
		}
		else if(str1.charAt((len-1)) == " ")
		{
			str1 = str1.substring(0,(len-2));
			len = str1.length;
		}
		else
		{
			loop = false;
		}
	}
	return (str1);
}
function checkTelephone()
{
	var str=document.form1.txtAdditionalInfo4.value;
	if(str=="")
		return true;
	else if(str.length > 30 || str.length < 3)
		return true;
	else if (!(checkForPraSpcChar("1234567890-",str)))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function checkEmailid()
{
	var str=document.form1.txtAdditionalInfo5.value;
	str = trimSpaces(str);
	var len = str.length;

	if(str=="")
	{
			return true;
	}
	else if(str.length>40)
	{
			return true;
	}
	else if(str.indexOf("@")==-1)
	{
		return true;
    }
	else if(str.indexOf(".")==-1)
	{
		return true;
    }
	else if(str.substring(str.indexOf(".")+1).length <2)
	{
		return true;
    }
    else if (!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._", str)))
    {
		return true;
    }
    else if(str.indexOf("@",(str.indexOf("@")+1)) != -1)
    {
		return true;
    }
    else if( (str.charAt((len -1 )) == ".") || (str.charAt((len -1 )) == "@") || (str.charAt((len -1 )) == "_"))
    {
		return true;
	}
    else if( (str.charAt(0) == ".") || (str.charAt(0) == "@"))
    {
		return true;
	}
	else
	{
		return false;
	}
}



// validation Service Tax Assessee Information

function setOptions(chosen) {
//Accounting Commissionerate =AccCom
var AccCom = document.form1.txtAdditionalInfo3;
var Purpose = document.form1.txtAdditionalInfo5;
var ComCodeNo = document.form1.txtTxnAmount;

AccCom.options.length = 0;
Purpose.options.length = 0;
//ComCodeNo.options.length = 0;
if (chosen == " ==Select Scheme==") {
//  for became a text box
//  id = 'init'
  
//  document.getElementById(id).style.visibility = "visible";
//  divs = document.getElementsByTagName('div')
//  for(i =0; i <divs.length; i++)
//  {
//  	if(divs[i].id != id)
//  	{
//   		divs[i].style.visibility = "hidden";
//	}
 // }
//end
  AccCom.options[AccCom.options.length] = new Option('==Select The Bhog==',' ');
  ComCodeNo.options[ComCodeNo.options.length] = new Option('==Amount Donated==',' ');
  Purpose.options[ComCodeNo.options.length] = new Option('==Select the Purpose of utilisation==',' ');
  
  }
if (chosen == "Amrut Manohi") {
  AccCom.options[AccCom.options.length] = new Option('==Select The Bhog==',' ');
  AccCom.options[AccCom.options.length] = new Option('Dress','Dress');
  AccCom.options[AccCom.options.length] = new Option('Mangla Arti Bhog','Mangla Arti Bhog');
  AccCom.options[AccCom.options.length] = new Option('Raj Bhog','Raj Bhog');
  AccCom.options[AccCom.options.length] = new Option('Madhyahna Bhog','Madhyahna Bhog');
  AccCom.options[AccCom.options.length] = new Option('Sandhya Arti','Sandhya Arti');
  AccCom.options[AccCom.options.length] = new Option('Combined Bhog/Arti for one whole day','Combined Bhog/Arti for one whole day');
  
  Purpose.options[Purpose.options.length] = new Option('==Select the Purpose of utilisation==',' ');
  Purpose.options[Purpose.options.length] = new Option('Brahmin Bhojan','Brahmin Bhojan');
  Purpose.options[Purpose.options.length] = new Option('Poor Feeding','Poor Feeding');
  Purpose.options[Purpose.options.length] = new Option('Bhojan for Lepers','Bhojan for Lepers');
  Purpose.options[Purpose.options.length] = new Option('Destitutes','Destitutes');
  Purpose.options[Purpose.options.length] = new Option('Other','Other');
  }
if (chosen == "Corpus Fund") {
  AccCom.options[AccCom.options.length] = new Option('==Select The Type of Donor==',' ');
  AccCom.options[AccCom.options.length] = new Option('Special Donor','Special Donor');
  AccCom.options[AccCom.options.length] = new Option('Patron Donor','Patron Donor');
  AccCom.options[AccCom.options.length] = new Option('Others','Others');

  Purpose.options[Purpose.options.length] = new Option('==Select the Purpose of utilisation==',' ');
  Purpose.options[Purpose.options.length] = new Option('Brahmin Bhojan','Brahmin Bhojan');
  Purpose.options[Purpose.options.length] = new Option('Poor Feeding','Poor Feeding');
  Purpose.options[Purpose.options.length] = new Option('Bhojan for Lepers','Bhojan for Lepers');
  Purpose.options[Purpose.options.length] = new Option('Destitutes','Destitutes');
  Purpose.options[Purpose.options.length] = new Option('Other','Other');
  }

}

function setOptions2(chosen) {
//Accounting Commissionerate =AccCom
var ComCodeNo = document.form1.txtTxnAmount;
//var ComCodeNoID = document.getElementById('txtTxnAmount');
//ComCodeNo.options.length = 0;

if (chosen == "Dress") {
//  ComCodeNo.disabled=true;
  ComCodeNo.readOnly=true;
  ComCodeNo.value='2100.00';
}
if (chosen == "Mangla Arti Bhog") {
  ComCodeNo.value='4000.00';
  ComCodeNo.readOnly=true;
}
if (chosen == "Raj Bhog") {
  ComCodeNo.value='5000.00';
  ComCodeNo.readOnly=true;
}
if (chosen == "Madhyahna Bhog") {
  ComCodeNo.value='3000.00';
  ComCodeNo.readOnly=true;
}
if (chosen == "Sandhya Arti") {
  ComCodeNo.value='5000.00';
  ComCodeNo.readOnly=true;
}
if (chosen == "Combined Bhog/Arti for one whole day") 
{
  ComCodeNo.value='15000.00';
  ComCodeNo.readOnly=true;
}
if (chosen == "Special Donor") 
{
  //ComCodeNo.value='100000.00';
  ComCodeNo.value='';
  ComCodeNo.focus();  
  ComCodeNo.readOnly=false;
}
if (chosen == "Patron Donor") 
{
 // ComCodeNo.value='1000000.00';
  ComCodeNo.value='';
  ComCodeNo.focus(); 
  ComCodeNo.readOnly=false;
}
if (chosen == "Others") 
{
  ComCodeNo.value='';
  ComCodeNo.focus();
  ComCodeNo.readOnly=false;
}

}
function setOptions3(chosen) {
//Accounting Commissionerate =AccCom
//var AccCom = document.form1.additional_info25;
//var ComCodeNo = document.form1.additional_info4;
//var Division = document.form1.additional_info5;
//var DivisionNo = document.form1.additional_info6;
var Addhead = document.form1.additional_info9;

//AccCom.options.length = 0;
//ComCodeNo.options.length = 0;
//Division.options.length = 0;
//DivisionNo.options.length = 0;

if (chosen == "I") {
  document.all.item("form1").action="servicetax_mumbai_division1.htm"
  document.form1.submit();
  }
if (chosen == "II") {
  document.all.item("form1").action="servicetax_mumbai_division2.htm"
  document.form1.submit();
}
}
