

var radio_selection1="";
var radio_selection="";
var x=true;
var y ;
var radio_selection1;
var select_box=0;
var other_value_conv="0";
var submitcount=0;
var amt_type="";

function submit_form()

{
	document.form1.refresh1.value = false;
	document.form1.submit();
}

function dateTime() {

var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var now = new Date();
var result = days[now.getDay()]+" ";
result += now.toLocaleString();
var tzOffset = -now.getTimezoneOffset()/60;
if(tzOffset<0) result += " (GMT "+tzOffset+" hours)"
else result += " (GMT + "+tzOffset+" hours)"
return result
}


function write_select() {

	if (document.form1.donation_contribute.checked == false)
		document.form1.donation_contribute.checked = true;
}



function tick()	
{
document.form1.client_clock.value=dateTime()

}

function receipt_check()	{

if (y==true) y=false
else y=true
}


function submit_check() {                      
if (x==true)	{
   if (submitcount == 0)
      {
      submitcount++;
		
      return true;
      }
   else 
      {
      alert("This form has already been submitted.  Thanks!");
      return false;
      }
	}
}


function formatCurrency(num, am_tp)
 {
num = num.toString().replace(/\$|\,/g,'');
var amt_tp = am_tp
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

if (amt_tp=="true"){
 	result = ('INR ' + num + '.' + cents);
	}
else {
    result = (num + '.' + cents);
}
return result
}

	
function number_check(field)	{
if (field.value!="0")	{ 

var valid = "0123456789., ";
var ok = "yes";
var temp;

for (var i=0; i <= field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") 
    ok = "no"
              }
if (ok == "no") {
alert("Invalid entry!  Enter Valid Number ! ");
field.focus();
field.select();
            	} 
}
if(ok=="yes")	{
	
	other_value_conv=field.value;
    amt_type ="false"
    var other_amount1 = field.value;
	//document.form1.other_amount_pass.value = other_amount1;			
	field.value=formatCurrency(other_amount1,amt_type);
	//show_conversion();

	}
	
 }

function number_check1(field)	{
if (field.value!="0")	{ 

var valid = "0123456789., ";
var ok = "yes";
var temp;

for (var i=0; i <= field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") 
    ok = "no"
              }
if (ok == "no") {
//alert("Invalid entry!  Enter Valid Number ! ");
field.focus();
field.select();
            	} 
}
if(ok=="yes")	{
	
	other_value_conv=field.value;
    amt_type ="false"
    var other_amount1 = field.value;
	//document.form1.other_amount_pass.value = other_amount1;			
	//field.value=formatCurrency(other_amount1,amt_type);
	//show_conversion();

	}
	
 }


function validate1()	{
x=true	

if (document.form1.refresh1.value=="false" && x==true && y)
{
x=false;
alert("You may have used the back button to come to this page, which is invalid.\n\n Please refresh this page to get a new Donation form.\n \nThank you & sorry for the inconvinience.") 
document.form1.action = "donation.asp"
document.form1.submit();
}
if(total_checkCount(document.form1.counter.value) == false && x )
{
x=false
document.form1.donation_contribute.focus();
// alert("Please Select atleast one of the donations");
}

if(greater101(document.form1.counter.value) == false && x )
{
x=false
document.form1.donation_contribute.focus();
// alert("Please Select atleast one of the donations");
}

if(document.form1.donation_contribute.checked == false && x )
{
x=false
 alert("Please Select atleast one of the donations");
 document.form1.donation_contribute.focus();
}

if(document.form1.donation_contribute.checked != false && radio_selection== "" && x )
{
 x=false
 alert("Please Enter the amount you wish to donate to Annamrita - Midday Meal Program");
 document.form1.donation_contribute.focus();
}

if(document.form1.f_name.value=="" && x && y)
{
 x=false
 alert("Please fill in your First Name");
 document.form1.f_name.focus();
}

if(document.form1.f_name.value.length<2 && x && y)
{
 x=false
 alert("Your IP has been recorded by us previously and you are trying to make a frivolous Transaction. \n\n Please note as per cyber laws, you liable to pay for transaction you commit");
 document.form1.f_name.focus();
}


 if(document.form1.l_name.value=="" && x && y)
{
 x=false
 alert("Please fill in your Last Name");
 document.form1.l_name.focus();
}
 
 if(document.form1.address_1.value=="" && x && y)
{
 x=false
 alert("Please fill in your Complete & Correct Address Details ");
 document.form1.address_1.focus();
}

// if(document.form1.address_2.value=="" && x && y)
//{
// x=false
// alert("Please fill in your Complete Address Details in Address1 & Address2 ");
// document.form1.address_2.focus();
//}

 if(document.form1.city.value=="" && x && y)
{
 x=false
 alert("Please fill in your City name ");
 document.form1.city.focus();
}

 if(document.form1.pincode.value=="" && x && y)
{
 x=false
 alert("Please fill in your Pincode ");
 document.form1.pincode.focus();
}

 if(document.form1.state.value=="" && x && y)
{
 x=false
 alert("Please fill in the State you stay in ");
 document.form1.state.focus();
}

if(document.form1.country.value=="" && x && y)
{
 x=false
 alert("Please select the country you stay in");
 document.form1.country.focus();
}

if(((document.form1.tel2.value=="") || (document.form1.tel2.value=="0") || (document.form1.tel3.value=="") || (document.form1.tel3.value=="0")) && x && y)
{
 x=false
 alert("Please fill in your telephone number, with country code, followed by the city code and then your telephone number.");
 document.form1.tel1.focus();
}
if(((document.form1.tel2.value.length < 2) || (document.form1.tel3.value.length < 5)) && x && y)
{
 x=false
 alert("Your Telephone number is invalid. Please fill a valid telephone number.");
 document.form1.tel1.focus();
}


if((number_check1(document.form1.tel2)==false || number_check1(document.form1.tel2)==false || number_check1(document.form1.tel3)==false) && x && y)
{
 x=false
 alert("Please enter a valid telephone number.");
 document.form1.tel1.focus();
}

if(document.form1.email.value=="" && x && y)
{
 x=false
 alert("Please fill in the Email Address");
 document.form1.email.focus();
}
if (x==true && y==true)
{
if (emailCheck(document.form1.email.value)==false)	{
x=false
document.form1.email.focus();
}
}

if(document.form1.IT_Exemption_Section.value=="" && x && y)
{
 x=false
 alert("Please Select an appropriate option for IT Exemption");
 document.form1.IT_Exemption_Section.focus();
}

if(document.form1.CCPay_type.value=="" && x && y)
{
 x=false
 alert("Please Select the mode of Payment");
 document.form1.CCPay_type.focus();
}


//if(document.form1.CCPay_type.value=="" && x && y)
//{
 //x=false
 //alert("Please Select the mode of Payment");
 //document.form1.CCPay_type.focus();
//}


//if(document.form1.amount.value!="" && x && y)
//{
//write_select()
//}


if (x==true)
{
	select_country()
	submit_form()
}

}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")



var matchArray=emailStr.match(emailPat)
if ((matchArray==null) && x==true) {
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]


if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid in the Email Address.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid in the Email Address!")
		return false
	    }
    }
    return true
}


var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid in the Email Address.")
    return false
}


var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("The Email address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This Email address is missing a hostname!"
   alert(errStr)
   return false
}


return true;
}
//  End -->


var radio_selection1="";
var radio_selection="";

function resetForm() {

document.form1.receipt.value="checked";
}


function changeCase(frmObj) 
{
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)
	{
	for (index = 0; index < strLen; index++)
		{
		if (index == 0) 
			{
			tmpChar = tmpStr.substring(0,1).toUpperCase();
			postString = tmpStr.substring(1,strLen);
			tmpStr = tmpChar + postString;
			}
		else 
			{
			tmpChar = tmpStr.substring(index, index+1);
			if (tmpChar == " " && index < (strLen-1)) 
				{
				tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
				preString = tmpStr.substring(0, index+1);
				postString = tmpStr.substring(index+2,strLen);
				tmpStr = preString + tmpChar + postString;
         		}
      		}
		}
	}

	frmObj.value = tmpStr;
}



function select_amount()
{
	if(radio_selection !="others")	
	{
		document.form1.other_amount.disabled=true;
		document.form1.other_amount.value="";
		
	}
    else {
		document.form1.other_amount.disabled=false;
		document.form1.other_amount.value=0;
	}
}

function select_country()
{
	//if(document.form1.country.options.[100].selected)	
	//if document.guideform.guidelinks.options[100].value == "IN" 
//     if document.form1.country.options[document.form1.country.selectedIndex].value == 100
	 
	 var selectedItemValue
	 selectedItemValue = document.form1.country.options[document.form1.country.selectedIndex].value 
	 if  (selectedItemValue == 'IN')
	{
		document.form1.location.selectedIndex = 0;
		
	}
	else 	
	{
		document.form1.location.selectedIndex = 1;
		
	}
  
}
function check_no(numb)
{
	
	var don_num = numb
			cbox = eval("document.form1.C" + don_num); 
			tbox = eval("document.form1.S" + don_num); 
			dnbox = eval("document.form1.DN" + don_num); 
//			cbox=don_num

				if (eval(cbox.checked) == true) 
				{
					 //alert (tbox) ;
					 (tbox.disabled) = false;
					 
//					 tbox.value="";
//					 document.form1.other_amount.value="";
				}
				else
				{
					 (tbox.disabled) = true;	
 					  tbox.value=0;
				}
}


function total_check(fields)
{
	var m_total =0;
	var Total_1 = 0;
	for (var i=1; i <= fields; i++) 
		
	{	
			var don_num = i	
//			cbox=eval("document.form1.C1"); 
//			tbox=eval("document.form1.S1"); 
			cbox = eval("document.form1.C" + don_num); 
			tbox = eval("document.form1.S" + don_num); 
	
			if (eval(cbox.checked) == true) 
			{
				Total_1==Total_1+(eval(tbox.value)); 
			}
	}	
	if (Total_1 == 0)
		{
		alert (Total_1)
		}
}
function total_checkCount(Counter)
{
	var m_total =0;
	var Total_1 = 0;
	var don_num = 0;
	cbox = 0;
	tbox = 0;
//	alert (Counter);
	for (var i=1; i <= Counter; i++) 
	{
			cbox = 0;
			tbox = 0;
			don_num = i;
			//alert (don_num + " Counter");
			cbox = eval("document.form1.C" + don_num); 
			tbox = eval("document.form1.S" + don_num); 
//			cbox=don_num
			//alert ((tbox.value)+ "tbox value");
			tboxvalue = tbox.value.toString().replace(/\$|\,/g,'')
			//alert ((tboxvalue)+ "tboxvalue");
			//alert (Number(Total_1));
			if (number_check(tbox) == false)
				{
				alert("Invalid entry!  \n\n Please Enter Number Value in Amount box");	
				}
			
			if (Number(tboxvalue != null) && Number(tboxvalue != 0)&& Number(cbox.checked == true))
			{
			Total_1=Number((Total_1)+ Number(tboxvalue)); 
			//alert ((Total_1));
		}
	}	
			if ((Total_1) < 501) 
			{
					alert("Invalid entry!  \n\n Please Enter Total Donation Amount More Than Rs 501");
					return false;
			}
			else return true
}

function greater101(Counter)
{
	var m_total =0;
	cbox = 0;
	tbox = 0;
	var don_num = 0;
//	alert (Counter);
	for (var i=1; i <= Counter; i++) 
	{
		don_num = i;
		cbox = eval("document.form1.C" + don_num); 
		tbox = eval("document.form1.S" + don_num); 	
		if (Number(tbox.value) < 501 && cbox.checked == true && i !=1)
		{
		alert("Invalid entry! \n\n Please Enter An Amount More Than Rs 501 for " + cbox.value + " ! ");
		tbox.focus();
		return false;
		}
	}
}

function check_no_mem(numb)
{
	
	var don_num = numb
			cbox = eval("document.form1.C" + don_num); 
			tbox = eval("document.form1.S" + don_num); 
//			cbox=don_num
			//alert(cbox.value)
				if ((eval(cbox.checked) == true) && (cbox.value == "Feed 1000 Children For One Year (approx.)"))
					 {
					 (tbox.disabled) = false;	
					 tbox.value="9,00,000.00";
//					 document.form1.other_amount.value="";
					 }
				else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 500 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="4,50,000.00";
//					 document.form1.other_amount.value="";
					 }
				else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 250 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="2,25,000.00";
//					 document.form1.other_amount.value="";
					 }
				else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 100 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="90,000.00";
//					 document.form1.other_amount.value="";
					 }

				else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 50 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="45,000.00";
//					 document.form1.other_amount.value="";
					 }
else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 25 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="22,500.00";
//					 document.form1.other_amount.value="";
					 }
else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 10 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="9,000.00";
//					 document.form1.other_amount.value="";
					 }
else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 5 Children For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="4,500.00";
//					 document.form1.other_amount.value="";
					 }
else if ((eval(cbox.checked) == true) && (cbox.value == "Feed 1 Child For One Year (approx.)"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="900.00";
//					 document.form1.other_amount.value="";
					 }

				else
					 (tbox.disabled) = true;	
					  //tbox.value=0;
	
}
