




var dtCh= "/";

var cuDate = new Date();

var dYear = cuDate.getYear();



var minYear=dYear;

var maxYear=2100;





function isInteger(s){

	var i;

    for (i = 0; i < s.length; i++){   

        // Check that current character is number.

        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;

    }

    // All characters are numbers.

    return true;

}



function stripCharsInBag(s, bag){

	var i;

    var returnString = "";

    // Search through string's characters one by one.

    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++){   

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}



function daysInFebruary (year){

	// February has 29 days in any year evenly divisible by four,

    // EXCEPT for centurial years which are not also divisible by 400.

    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

}

function DaysArray(n) {

	for (var i = 1; i <= n; i++) {

		this[i] = 31

		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}

		if (i==2) {this[i] = 29}

   } 

   return this

}



function isDate(dtStr){

	var daysInMonth = DaysArray(12)

	var pos1=dtStr.indexOf(dtCh)

	var pos2=dtStr.indexOf(dtCh,pos1+1)

	var strMonth=dtStr.substring(0,pos1)

	var strDay=dtStr.substring(pos1+1,pos2)

	var strYear=dtStr.substring(pos2+1)

	strYr=strYear

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

	for (var i = 1; i <= 3; i++) {

		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)

	}

	month=parseInt(strMonth)

	day=parseInt(strDay)

	year=parseInt(strYr)

	if (pos1==-1 || pos2==-1){

		alert("The date format should be : mm/dd/yyyy")

		return false

	}

	if (strMonth.length<1 || month<1 || month>12){

		alert("Please enter a valid month")

		return false

	}

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){

		alert("Please enter a valid day")

		return false

	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)

		return false

	}

	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){

		alert("Please enter a valid date")

	return false

	}

return true

}

function ValidateForm1(){

	

	var dt=document.form1.sdate

		if(document.form1.sdate.value != "") 

		{

			if (isDate(dt.value)==false)

			{

			dt.focus()

			return false

			}

		}

    return true

 }



/* -------------------------------------------------------------*/



function checkBalance()

{

	var isdigit= /^[0-9\.]+$/;

	if(document.myform.amountpaid.value.length <= 0)

		{

			alert("Please enter the amount you want to pay ");

			document.myform.amountpaid.focus();

			return false;

		}

		

			if(document.myform.amountpaid.value != "")

				{

					chf= isdigit.test(document.myform.amountpaid.value);

					if(!chf)

						{

						alert(" 'Amount Paid' contains invalid character(s).");

						document.myform.amountpaid.focus();

						return false;

						}

				}

				var amtval =parseInt(document.myform.amountdue.value);

					if(document.myform.amountpaid.value > amtval)

						{

						alert("The amount you paid is more than the Total amount");

						document.myform.amountpaid.focus();

						return false;

						}

					else

						{

							document.myform.bal.value = document.myform.amountdue.value - document.myform.amountpaid.value;

						}

}



/* ----------------------------- */

function checksumclassi(){

var iscardno =/^[0-9]+$/;

	if(document.form1.runx.value != "")

			{

			chf= iscardno.test(document.form1.runx.value);

			if(!chf)

				{

				alert(" RunX (No. of week(s) ) contains invalid character.");

				document.form1.runx.focus();

				return false;

				}

			}

}





/*</-- ----------------------------------------------------------------------- -->

################  adinsertViewCheck()    */



function adinsertViewcheck(){

	var isamount= /^[0-9\.]+$/;

	var isdigit= /^[0-9\s\-]+$/;

	var iscardno =/\d{4}/;

var ischar= /^[a-zA-Z\s][^\d\#\!\@\$\%\^\&\*\(\)\|\-\+\=\"\?\<\>\~\/]+$/;

	if(document.myform.amountpaid.value.length <= 0)

		{

			alert("Please enter the amount you want to pay ");

			document.myform.amountpaid.focus();

			return false;

		}

		if(document.myform.amountpaid.value != "")

		{

			chf= isamount.test(document.myform.amountpaid.value);

			if(!chf)

				{

				alert(" 'Amount Paid' contains invalid character(s).");

				document.myform.amountpaid.focus();

				return false;

				}

		}

		

		if(document.forms[0].pmode.selectedIndex == 0){

			alert ("Please select payment node");

			document.forms[0].pmode.focus();

			return false;

		}

		if(document.forms[0].pmode.selectedIndex <= 4){

		if(document.forms[0].cno1.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno1.focus();

			return false;

		}

		if(document.forms[0].cno1.value != "")

					{

					chf= iscardno.test(document.forms[0].cno1.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cno1.focus();

						return false;

						}

					}

		if(document.forms[0].cno2.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno2.focus();

			return false;

		}

		if(document.forms[0].cno2.value != "")

					{

					chf= iscardno.test(document.forms[0].cno2.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cno2.focus();

						return false;

						}

					}

		

		if(document.forms[0].cno3.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno3.focus();

			return false;

		}

		if(document.forms[0].cno3.value != "")

					{

					chf= iscardno.test(document.forms[0].cno3.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cno3.focus();

						return false;

						}

					}

		

		if(document.forms[0].cno4.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno4.focus();

			return false;

		}

		if(document.forms[0].cno4.value != "")

			{

			chf= iscardno.test(document.forms[0].cno4.value);

			if(!chf)

				{

				alert(" Card number contains invalid character.");

				document.forms[0].cno4.focus();

				return false;

				}

			}

			if(document.forms[0].exmonth.selectedIndex <= 0){

			alert(" Please select month");

			document.forms[0].exmonth.focus();

			return false;

			}

			if(document.forms[0].exyear.selectedIndex <= 0){

			alert(" Please select Year");

			document.forms[0].exyear.focus();

			return false;

			}

			if(document.forms[0].cardname.value.length <= 0)

			{

			alert("Please enter the name on the card");

			document.forms[0].cardname.focus();

			return false;

			}

			if(document.forms[0].cardname.value != "")

			{

			chf= ischar.test(document.forms[0].cardname.value);

			if(!chf)

				{

				alert(" Name contains invalid character.");

				document.forms[0].cardname.focus();

				return false;

				}

			}

		

		}

	

}









/* --------------------------------------------------------------------------------

*/





function adForm2check()

{

	var iscardno =/^[0-9]+$/;



	if(document.form1.sdate.value.length <= 0)

		{

			alert("Please enter the date");

			document.form1.sdate.focus();

			return false;

		}

	if(document.form1.runx.value.length <= 0)

		{

			alert("Please enter RunX (no.of weeks)");

			document.form1.runx.focus();

			return false;

		}

	if(document.form1.runx.value != "")

		{

			chf= iscardno.test(document.form1.runx.value);

			if(!chf)

				{

				alert(" RunX(no. of weeks contains invalid character.");

				document.form1.runx.focus();

				return false;

				}

		}

}









/* ###################### Classifieds Form validation  ###################### */



function adForm3check()

{

	var iscardno =/\d{4}/;

	var isamt= /^[0-9\.]+$/;

	if(document.form1.content.value.length <= 0)

		{

			alert("Please enter the Classified contents");

			document.form1.content.focus();

			return false;

		}

	if(document.form1.sdate.value.length <= 0)

		{

			alert("Please enter the date");

			document.form1.sdate.focus();

			return false;

		}

	if(document.form1.runx.value.length <= 0)

		{

			alert("Please enter RunX (no.of weeks)");

			document.form1.runx.focus();

			return false;

		}

	if(document.form1.total.value.length <= 0)

		{

			alert("Please enter the total amount");

			document.form1.total.focus();

			return false;

		}

	if(document.form1.total.value != "")

		{

			chf= isamt.test(document.form1.total.value);

			if(!chf)

				{

				alert(" Total amount contains invalid character(s).");

				document.form1.total.focus();

				return false;

				}

		}

}











/* #######################  END Classifieds Form validation   #################################*/

function checkSum(){

	var iscardno =/^[0-9]+$/;

	chf= iscardno.test(document.form1.runx.value);

	if(!chf)

	{

		alert(" RunX (No.of weeks contains invalid character.");

		document.form1.runx.focus();

		return false;

	}

	else

	{

	var sum;

	var s= 1

	//if(s ==1 )sum = 909 *  parseInt(document.form1.runx.value);

	//alert(document.form1.adtype.value);

	if(document.form1.adtype.selectedIndex == 0) sum = 909 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 1) sum = 779 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 2) sum = 419 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 3) sum = 309 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 4) sum = 209 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 5) sum = 139 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 6) sum = 69 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 7) sum = 40 *  parseInt(document.form1.runx.value);

	if(document.form1.adtype.selectedIndex == 8) sum = 900 *  parseInt(document.form1.runx.value);

	document.form1.total.value = sum;

	}

	return true;

}













/* ########################################################################           */



// JavaScript Document

function adFormcheck(){

var isdigit= /^[0-9\s\-]+$/;

var iszip= /^[0-9]+$/;

var validEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

var iscardno =/\d{4}/;

var ischar= /^[a-zA-Z\s][^\d\#\!\@\$\%\^\&\*\(\)\|\-\+\=\"\?\<\>\~\/]+$/;

if(document.form1.startdate.value.length <= 0)

		{

			alert("Please enter Date");

			document.form1.startdate.focus();

			return false;

		}

	if(document.form1.name.value.length <= 0)

		{

			alert("Please enter the name");

			document.form1.name.focus();

			return false;

		}



		if(document.form1.name.value != "")

		{

			chf= ischar.test(document.form1.name.value);

			if(!chf)

				{

				alert(" Name contains invalid character.");

				document.form1.name.focus();

				return false;

				}

		}

		if(document.form1.address.value.length <= 0)

		{

			alert("Please enter the Address");

			document.form1.address.focus();

			return false;

		}

		if(document.form1.city.value.length <= 0)

		{

			alert("Please enter the City");

			document.form1.city.focus();

			return false;

		}

		if(document.form1.city.value != "")

		{

			chf= ischar.test(document.form1.city.value);

			if(!chf)

				{

				alert(" City name contains invalid character.");

				document.form1.city.focus();

				return false;

				}

		}

		if(document.form1.zip.value.length <= 0)

		{

			alert("Please enter the Zipcode");

			document.form1.zip.focus();

			return false;

		}



		if(document.form1.zip.value != "")

		{

			chf= iszip.test(document.form1.zip.value);

			if(!chf)

				{

				alert(" Zipcode contains invalid character.");

				document.form1.zip.focus();

				return false;

				}

		}

		if(document.form1.phone.value.length <= 0)

		{

			alert("Please enter the Phone Number");

			document.form1.phone.focus();

			return false;

		}



		if(document.form1.phone.value != "")

		{

			chf= isdigit.test(document.form1.phone.value);

			if(!chf)

				{

				alert(" Phone number contains invalid character.");

				document.form1.phone.focus();

				return false;

				}

		}

		if(document.form1.fax.value != "")

		{

			chf= isdigit.test(document.form1.fax.value);

			if(!chf)

				{

				alert(" Fax number contains invalid character.");

				document.form1.fax.focus();

				return false;

				}

		}

		if(document.form1.email.value.length <= 0)

		{

			alert("Please enter the Email");

			document.form1.email.focus();

			return false;

		}

		if(document.form1.email.value != "")

					{

					chf= validEmail.test(document.form1.email.value);

					if(!chf)

						{

						alert(" A valid e-mail address is required.");

						document.form1.email.focus();

						return false;

				}

		}

		if(document.form1.rep.value != "")

		{

			chf= ischar.test(document.form1.rep.value);

			if(!chf)

				{

				alert(" Rep. name contains invalid character(s).");

				document.form1.rep.focus();

				return false;

				}

		}

		if(document.form1.auth.value != "")

		{

			chf= ischar.test(document.form1.auth.value);

			if(!chf)

				{

				alert(" Authorised name contains invalid character(s).");

				document.form1.auth.focus();

				return false;

				}

		}
		if(!document.form1.agree.checked)
		{
			alert("You have to agree the policy");
			document.form1.agree.focus();
			return false;
		}
		if(confirm('You are electronically signing that you have read our policies and agree to all payment arrangements'))
		{
			return true;
		}
		else
		{
			return false;
		}


}







function doCheckform(){

var isdigit= /^[0-9\s\-]+$/;

var iszip= /^[0-9]+$/;

var validEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

//var iscardno =/\d{4}/;
var iscardno =/^[0-9\s\-]+$/;


var ischar= /^[a-zA-Z\s][^\d\#\!\@\$\%\^\&\*\(\)\|\-\+\=\"\?\<\>\~\/]+$/;

	

		/*if(document.forms[0].pmode.selectedIndex > 4 && document.forms[0].pmode.selectedIndex <=7){

			alert (document.forms[0].pmode.options[document.forms[0].pmode.selectedIndex].value);

			document.forms[0].pmode.focus();

			return false;

			}*/


		if(document.forms[0].name.value.length <= 0)

		{

			alert("Please enter the name");

			document.forms[0].name.focus();

			return false;

		}



		if(document.forms[0].name.value != "")

		{

			chf= ischar.test(document.forms[0].name.value);

			if(!chf)

				{

				alert(" Name contains invalid character.");

				document.forms[0].name.focus();

				return false;

				}

		}



		if(document.forms[0].address.value.length <= 0)

		{

			alert("Please enter the Address");

			document.forms[0].address.focus();

			return false;

		}



		if(document.forms[0].city.value.length <= 0)

		{

			alert("Please enter the City");

			document.forms[0].city.focus();

			return false;

		}

		if(document.forms[0].city.value != "")

		{

			chf= ischar.test(document.forms[0].city.value);

			if(!chf)

				{

				alert(" City name contains invalid character.");

				document.forms[0].city.focus();

				return false;

				}

		}



		if(document.forms[0].zip.value.length <= 0)

		{

			alert("Please enter the Zipcode");

			document.forms[0].zip.focus();

			return false;

		}



		if(document.forms[0].zip.value != "")

		{

			chf= iszip.test(document.forms[0].zip.value);

			if(!chf)

				{

				alert(" Zipcode contains invalid character.");

				document.forms[0].zip.focus();

				return false;

				}

		}



		if(document.forms[0].phone.value.length <= 0)

		{

			alert("Please enter the Phone Number");

			document.forms[0].phone.focus();

			return false;

		}



		if(document.forms[0].phone.value != "")

		{

			chf= isdigit.test(document.forms[0].phone.value);

			if(!chf)

				{

				alert(" Phone number contains invalid character.");

				document.forms[0].phone.focus();

				return false;

				}

		}



		if(document.forms[0].fax.value != "")

		{

			chf= isdigit.test(document.forms[0].fax.value);

			if(!chf)

				{

				alert(" Fax number contains invalid character.");

				document.forms[0].fax.focus();

				return false;

				}

		}



		if(document.forms[0].email.value.length <= 0)

		{

			alert("Please enter the Email Address");

			document.forms[0].email.focus();

			return false;

		}

		if(document.forms[0].email.value != "")

					{

					chf= validEmail.test(document.forms[0].email.value);

					if(!chf)

						{

						alert(" A valid e-mail address is required.");

						document.forms[0].email.focus();

						return false;

				}

			}

			

			if(document.forms[0].bname.value.length <= 0)

		{

			alert("Please enter the Fictitious Business Name");

			document.forms[0].bname.focus();

			return false;

		}

			if(document.forms[0].baddress.value.length <= 0)

		{

			alert("Please enter the Buniness Address");

			document.forms[0].baddress.focus();

			return false;

		}

		if(document.forms[0].bdate.value.length <= 0)

		{

			alert("Please enter date the Business Name was filed on");

			document.forms[0].bdate.focus();

			return false;

		}

		

		if(document.forms[0].county.value.length <= 0)

		{

			alert("Please enter the County name");

			document.forms[0].county.focus();

			return false;

		}



		if(document.forms[0].county.value != "")

		{

			chf= ischar.test(document.forms[0].county.value);

			if(!chf)

				{

				alert(" County Name contains invalid character(s).");

				document.forms[0].county.focus();

				return false;

				}

		}

		

		

		

		

		

		if(document.forms[0].name1.value.length <= 0)

		{

			alert("Please enter the  Name");

			document.forms[0].name1.focus();

			return false;

		}

		if(document.forms[0].name1.value != "")

		{

			chf= ischar.test(document.forms[0].name1.value);

			if(!chf)

				{

				alert(" Name contains invalid character.");

				document.forms[0].name1.focus();

				return false;

				}

		}



		if(document.forms[0].address1.value.length <= 0)

		{

			alert("Please enter the Address");

			document.forms[0].address1.focus();

			return false;

		}

		if(document.forms[0].city1.value.length <= 0)

		{

			alert("Please enter the City");

			document.forms[0].city1.focus();

			return false;

		}

		if(document.forms[0].city1.value != "")

		{

			chf= ischar.test(document.forms[0].city1.value);

			if(!chf)

				{

				alert(" City name contains invalid character.");

				document.forms[0].city1.focus();

				return false;

				}

		}

		

			

		

		

		/*     payment check  */

			

			

			

			if(document.forms[0].pmode.selectedIndex == 0){

			alert ("Please select payment node");

			document.forms[0].pmode.focus();

			return false;

		}

		if(document.forms[0].pmode.selectedIndex <= 5){

		if(document.forms[0].cardno.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cardno.focus();

			return false;

		}

		if(document.forms[0].cardno.value != "")

					{

					chf= iscardno.test(document.forms[0].cardno.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cardno.focus();

						return false;

						}

					}
					if(document.forms[0].cvv.value.length <= 0)
			{
				alert("Please enter the CVV Code");
				document.forms[0].cvv.focus();
				return false;
			}
			if(document.forms[0].cvv.value != "")
			{
			chf= iscardno.test(document.forms[0].cvv.value);
			if(!chf)
				{
				alert(" CVV Code contains invalid character.");
				document.forms[0].cvv.focus();
				return false;
				}
				
			}

		/*if(document.forms[0].cno2.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno2.focus();

			return false;

		}

		if(document.forms[0].cno2.value != "")

					{

					chf= iscardno.test(document.forms[0].cno2.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cno2.focus();

						return false;

						}

					}

		

		if(document.forms[0].cno3.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno3.focus();

			return false;

		}

		if(document.forms[0].cno3.value != "")

					{

					chf= iscardno.test(document.forms[0].cno3.value);

					if(!chf)

						{

						alert(" Card number contains invalid character.");

						document.forms[0].cno3.focus();

						return false;

						}

					}

		

		if(document.forms[0].cno4.value.length <= 0)

		{

			alert("Please enter the Card Number");

			document.forms[0].cno4.focus();

			return false;

		}

		if(document.forms[0].cno4.value != "")

			{

			chf= iscardno.test(document.forms[0].cno4.value);

			if(!chf)

				{

				alert(" Card number contains invalid character.");

				document.forms[0].cno4.focus();

				return false;

				}

			}*/

			if(document.forms[0].exmonth.selectedIndex <= 0){

			alert(" Please select month");

			document.forms[0].exmonth.focus();

			return false;

			}
			else
			{
				var my_month=new Date()
				var month_name=new Array(12);
				month_name[0]="January"
				month_name[1]="February"
				month_name[2]="March"
				month_name[3]="April"
				month_name[4]="May"
				month_name[5]="June"
				month_name[6]="July"
				month_name[7]="August"
				month_name[8]="September"
				month_name[9]="October"
				month_name[10]="November"
				month_name[11]="December"
				var d=my_month.getMonth()+1;
				var y=my_month.getFullYear();
				if(document.forms[0].exmonth.selectedIndex >= d)
					{
				
						if( document.forms[0].exyear.options[document.forms[0].exyear.selectedIndex].value < y ) 
						{
							alert("Invalid Expiration Date");
							return false;
						}
					}
					else
					{
						if( document.forms[0].exyear.options[document.forms[0].exyear.selectedIndex].value <= y )
						{
							alert("Invalid Expiration Date");
							return false;
						}
					}

			}

			if(document.forms[0].exyear.selectedIndex <= 0){

			alert(" Please select Year");

			document.forms[0].exyear.focus();

			return false;

			}

			if(document.forms[0].cardname.value.length <= 0)

			{

			alert("Please enter the name on the card");

			document.forms[0].cardname.focus();

			return false;

			}

			if(document.forms[0].cardname.value != "")

			{

			chf= ischar.test(document.forms[0].cardname.value);

			if(!chf)

				{

				alert(" Name contains invalid character.");

				document.forms[0].cardname.focus();

				return false;

				}

			}

		

		}
		
		if(!document.forms[0].agree.checked)
		{
			alert("You have to agree the policy");
			document.forms[0].agree.focus();
			return false;
		}
		if(confirm('You are electronically signing that you have read our policies and agree to all payment arrangements'))
		{
			return true;
		}
		else
		{
			return false;
		}

  

}