
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 

var mydate=new Date();
var date_day=mydate.getDay();         //0=sun; 1=mon; 2=tue ...
var date_dd=mydate.getDate();        //1 to 31
var date_mm=mydate.getMonth()+1; //0=jan; 1=feb; 2=mar... to 11=dec
var date_yyyy=mydate.getYear();

var date_hh=lZ(mydate.getHours());
var date_ms=lZ(mydate.getMinutes());
var date_ss=lZ(mydate.getSeconds());

function calculate1(){

total = 0;

}



function calculate2(){

  valid = true; // assume valid

	if (document.giving2.amount_a3.value < 1  ||
		  document.giving2.amount_a3.value > 1000000 ||
		  isNaN(document.giving2.amount_a3.value))
		{ valid = false; alert('GIFT AMOUNT is zero or is an invalid value!');
	    document.giving2.amount_a3.value = 0.00;
			document.giving2.amount_a3.focus();return false; }

	var how_many = document.giving2.how_many_srt.value;

	if (document.giving2.billing_cycle_t3.value == "M"  &&
	     how_many > 12)
		{ valid = false; alert('(For:) INSTALLMENTS must be a number between 1 to 12, if payments are based on "Monthly" terms.');  
	    //document.giving2.how_many_srt.value = 1;
	    document.giving2.how_many_srt.focus();return false; 
			}


	total_a3=0;

	gt = document.giving2.gift_type.value;
	a3 = document.giving2.amount_a3.value*1;
	p3 = document.giving2.billing_cycle_p3.value*1;
	t3 = document.giving2.billing_cycle_t3.value;
	srt = document.giving2.how_many_srt.value*1;

	document.giving2.p3.value = document.giving2.billing_cycle_p3.value;

	if (document.giving2.billing_cycle_t3.value == "W"){document.giving2.t3.value = "WEEK(S)";}
	if (document.giving2.billing_cycle_t3.value == "M"){document.giving2.t3.value = "MONTH(S)";}
	//if (document.giving2.billing_cycle_t3.value == "W"){document.giving2.t3x.value = "WEEK(S)";}
	//if (document.giving2.billing_cycle_t3.value == "M"){document.giving2.t3x.value = "MONTH(S)";}
	document.giving2.t3x.value = "INSTALLMENTS";

	total_a3 = a3*srt;
	document.giving2.total_a3.value = total_a3;

	 document.giving2.amount_a3.focus();
   return true;

}

function submit2(){
  valid = true; // assume valid

	valid=calculate2();

if (valid)
{
      alert("Please be patient while your application is processed. \n" +
				"Processing can take up to few minutes depending on network traffic.\n\n" + 
				"DO NOT CLICK SUBMIT AGAIN, it can result in a duplicate information." +
				"\n\n Click OK to Continue.");

			// Building paypal form data for AUTOMATIC RECURRING GIFT: (Regular Billing Cycle)
			//==================================================================
			//document.paypal2.item_number.value= document.giving2.item_number.value;
			document.paypal2.item_name.value= document.giving2.gift_type.value;
			document.paypal2.a3.value= document.giving2.amount_a3.value;
			document.paypal2.p3.value= document.giving2.billing_cycle_p3.value;
			document.paypal2.t3.value= document.giving2.billing_cycle_t3.value;
			document.paypal2.srt.value= document.giving2.how_many_srt.value;

			document.paypal2.submit();
}

return true;

}