// JavaScript Document
function onsub1()
{
	var mydate = new Date()
    var year = mydate.getYear()

    if (year < 1000)
        year += 1900

    var day = mydate.getDay()
    var month = mydate.getMonth()+1

    if (month < 10)
        month = "0" + month


	var AllQtyStr = '';

	//alert(AllQtyStr);

	if (document.pay_userfrm.First_Name.value=="")
	{
		alert("Enter the First name");
		document.pay_userfrm.First_Name.focus();
		return false;
	}
	 if(document.pay_userfrm.Last_Name.value=="")
	{
		alert("Enter the Last name");
		document.pay_userfrm.Last_Name.focus();	
		return false;
	}

	if (document.pay_userfrm.email.value=="")
	{
		alert("Enter the email id");
		document.pay_userfrm.email.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.pay_userfrm.email.value))){
		alert("Enter the valid email id");
		document.pay_userfrm.email.focus();
		return false;
	}
	if (document.pay_userfrm.Address.value=="")
	{
		alert("Enter the Address");
		document.pay_userfrm.Address.focus();
		return false;
	}

	if (document.pay_userfrm.Town.value=="")
	{
		alert("Enter the Town");
		document.pay_userfrm.Town.focus();
		return false;
	}

	if (document.pay_userfrm.State.value=="")
	{
		alert("Enter the State");
		document.pay_userfrm.State.focus();
		return false;
	}
	 if(document.pay_userfrm.Zip_Code.value=="")
	{
		alert("Enter the Zipcode");
		document.pay_userfrm.Zip_Code.focus();	
		return false;
	}
	if(isNaN(document.pay_userfrm.Zip_Code.value))
	{
		alert("Enter the valid Zipcode");
		document.pay_userfrm.Zip_Code.focus();	
		return false;
	}
	
	if(document.pay_userfrm.Pool_Shape.value=="")
	{
		alert("Enter the Pool Shape");
		document.pay_userfrm.Pool_Shape.focus();	
		return false;
	}

	if (document.pay_userfrm.Pool_Size.value=="")
	{
		alert("Enter the Pool Size");
		document.pay_userfrm.Pool_Size.focus();
		return false;
	}
	
	if((document.pay_userfrm.package[0].checked==false)&&(document.pay_userfrm.package[1].checked==false)&&(document.pay_userfrm.package[2].checked==false))
	{
		alert("Please select any one package");	
		return false;
	}
	if((document.pay_userfrm.package[0].checked==true))
	{
		if(document.pay_userfrm.open_month.value=="0")
		{
			alert("Select the month");	
			document.pay_userfrm.open_month.focus();			
			return false;
		}
		if(document.pay_userfrm.open_week.value=="N/A")
		{
			alert("Select the month");	
			document.pay_userfrm.open_week.focus();			
			return false;
		}
	}
	
	if((document.pay_userfrm.package[1].checked==true)||(document.pay_userfrm.package[2].checked==true))
	{
		if(document.pay_userfrm.open_month.value=="0")
		{
			alert("Select the month");	
			document.pay_userfrm.open_month.focus();			
			return false;
		}
		if(document.pay_userfrm.open_week.value=="N/A")
		{
			alert("Select the week");	
			document.pay_userfrm.open_week.focus();			
			return false;
		}
		if(document.pay_userfrm.close_month.value=="N/A")
		{
			alert("Select the month");	
			document.pay_userfrm.close_month.focus();
			return false;
		}
		if(document.pay_userfrm.close_week.value=="N/A")
		{
			alert("Select the week");	
			document.pay_userfrm.close_week.focus();			
			return false;
		}
		if(document.pay_userfrm.trm.checked==false)
		{
			alert("Please check the Terms and Conditions");
			document.pay_userfrm.trm.focus();
			return false;
		}
	}
	
	var i;
	var chking = "chk";
	var quantity = "qty";

	for(i=1;i<=36;i++)
	{
		
		if(i == 1)	{
			AllQtyStr = '';
		}

		checking = chking + i;
		qnty = quantity + i;

		if(isNaN(document.getElementById(qnty).value)){
			alert("Enter the valid quantity");	
			document.getElementById(qnty).focus();
			return false;
		}

	//collecting all entered qty in a single variable to get the quantity
		if(document.getElementById("qty" + i).value != "")
		{
			if(AllQtyStr == "")	{
				AllQtyStr = i;
			} else	{
				AllQtyStr += "," + i;
			}
		} else	{
			document.getElementById(checking).value = ""
		}
	//end of collecting quantity
	}
	document.pay_userfrm.hfAllQty.value = AllQtyStr;

	return true;
}



function isValidDate(dateStr)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}

	return true;  // date is valid
}
