

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.radhagopinath.checked == false)
		document.form1.radhagopinath.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 = ('Rs ' + 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 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 Payment form.\n \nThank you & sorry for the inconvinience.") 
document.form1.action = "payments.asp"
document.form1.submit();
}
if(total_checkCount(document.form1.counter.value) == false && x )
{
x=false
document.form1.radhagopinath.focus();
// alert("Please Select atleast one of the Payments");
}

if(greater101(document.form1.counter.value) == false && x )
{
x=false
document.form1.radhagopinath.focus();
// alert("Please Select atleast one of the donations");
}

if(document.form1.radhagopinath.checked == false && x )
{
x=false
 alert("Please Select atleast one of the services for which payment is to be made");
 document.form1.radhagopinath.focus();
}

if(document.form1.radhagopinath.checked != false && radio_selection== "" && x )
{
 x=false
 alert("Please enter the amount you want to make a payment to ISKCON Juhu");
 document.form1.radhagopinath.focus();
}

//if(radio_selection == "others" && document.form1.amount.value == 0  && x )
//{
 //x=false
 //alert("Please Enter the amount you want to donate to ISKCON JUHU");
 //document.form1.radhagopinath.focus();
//}

//if (radio_selection == 'others' && document.form1.other_amount.value <= 500)
//{
 //x=false
 //alert("Please Enter an amount greater than Indian Rupees 501.");

// document.form1.other_amount.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 Address Details in Address 1 & Address 2 ");
 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 fill in the country you stay in");
 document.form1.country.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.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.")
    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!")
		return false
	    }
    }
    return true
}


var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    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 address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This 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); 
//			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 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 == "Life Patron Membership without Shrimad Bhagwatam Set"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="14,444.00";
//					 document.form1.other_amount.value="";
					 }
				else if ((eval(cbox.checked) == true) && (cbox.value == "Life Patron Membership with Shrimad Bhagwatam Set"))
					 
					 {
					 (tbox.disabled) = false;	
					 tbox.value="19,638.00";
//					 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(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 Payment Amount More Than Rs 501 \n\n(That is if the total of all services together at any one time should be greater than Rs 501 then only make payments through credit card!) ");
					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) < 101 && cbox.checked == true)
		{
		alert("Invalid entry! \n\n Please Enter An Amount More Than Rs 101 for " + cbox.value + " ! ");
		tbox.focus();
		return false;
		}
	}
}
