function checkCat(objstr){
var elmstr = ""
var checkfor = "notcat"
document.newlisting.catselected.value = "y";
for (var i=0; i < objstr.length; i++){
	if (objstr.options[i].selected){
		elmstr += objstr.options[i].value
	}
}
	if (elmstr.indexOf(checkfor) != -1){
		alert("You have selected a Category Heading\rPlease select only Categories from the list");
		document.newlisting.catselected.value = "n";
		return false;
	}
	return true
}

function validateForm(){
var vfields = "f110111111011111";
//var vfields = "f000000000000000";
var failed = 0;
var elmstr = "";
var digits = "0123456789"

if (vfields.charAt(1) == 1){
if (document.newlisting.name.value == "") {
alert("Please enter a Name!");
return false;
}
}
if (vfields.charAt(2) == 1){
if (document.newlisting.add1.value == "") {
alert("Please enter a Street Address!");
return false;
}
}
if (vfields.charAt(3) == 1){
if (document.newlisting.add2.value == "") {
alert("Please enter a Suite or PO Box!");
return false;
}
}
if (vfields.charAt(4) == 1){
if (document.newlisting.city.value == "") {
alert("Please enter a City!");
return false;
}
}
if (vfields.charAt(5) == 1){
if (document.newlisting.country.selectedIndex == 185 || document.newlisting.country.selectedIndex == 31){
if (document.newlisting.state.selectedIndex == 0 || document.newlisting.state.selectedIndex == 52) {
alert("Please choose a State or Canadian Province!");
return false;
}
}
}

if (vfields.charAt(5) == 1){
if (document.newlisting.country.selectedIndex == 185){
if (document.newlisting.state.selectedIndex > 52) {
alert("You have chosen a Canadian Province!\rPlease choose a US State from the pull-down menu!");
return false;
}
}
}

if (vfields.charAt(5) == 1){
if (document.newlisting.country.selectedIndex == 31){
if (document.newlisting.state.selectedIndex < 52) {
alert("You have chosen a US State!\rPlease choose a Canadian Province from the pull-down menu!\rProvinces are at the bottom of the pull-down list.");
return false;
}
}
}

if (vfields.charAt(6) == 1){		
	failed = 0
	elmstr = document.newlisting.zip.value + "";
	if (document.newlisting.country.selectedIndex == 185){
		for (var i = 0; i < elmstr.length; i++) {
			if (digits.indexOf(elmstr.charAt(i)) == -1  && i != 5) {
				failed = 1;
			}
		}
		if (elmstr == "" || elmstr.length < 5) {
			failed = 1
		} 	else if ((elmstr.length > 5 && elmstr.charAt(5) != "-") || (elmstr.length > 5 && elmstr.length < 10))	{
			failed = 1
		}
		if (failed == 1){
			alert("Please enter a US Zip Code in ##### -or- #####-#### format!");
			return false;
		}
	}
}

if (vfields.charAt(6) == 1){		
	failed = 0
	elmstr = document.newlisting.zip.value + "";
	if (document.newlisting.country.selectedIndex == 31){
		if (elmstr == "" || elmstr.length != 7 || elmstr.charAt(3) != " ") {
			failed = 1;
		}
		for (var i = 0; i < elmstr.length; i++) {
			if (digits.indexOf(elmstr.charAt(i)) != -1  && (i == 0 || i == 2 || i == 3 || i == 5)) {
				failed = 1;
			}
			if (digits.indexOf(elmstr.charAt(i)) == -1  && (i == 1 || i == 4 || i == 6)) {
				failed = 1;
			}
		}
		if (failed == 1){
			alert("Please enter a Canadian Zip Code in X#X #X# format!");
			return false;
		}
	}
}





if (vfields.charAt(7) == 1){
if (document.newlisting.country.value == "") {
alert("Please choose a Country!");
return false;
}
}
if (vfields.charAt(8) == 1){
if (document.newlisting.language.value == "") {
alert("Please select a Language!");
return false;
}
}
if (vfields.charAt(9) == 1){
failed = 0
elmstr = document.newlisting.telephone.value + "";
if (elmstr != ""){
if (document.newlisting.country.selectedIndex == 185 || document.newlisting.country.selectedIndex == 31){
if (elmstr.length != 12){
	failed = 1;
	}
    for (var i = 0; i < elmstr.length; i++) {
		if ((i < 3 && i > -1) || (i > 3 && i < 7) || (i > 7 && i < 12)) {
            if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9"){
			failed = 1;
			}
		}	else if (elmstr.charAt(i) != "-"){
			failed = 1;
		}
	}
if (failed == 1){
alert("Please enter your Phone Number in ###-###-#### format!");
return false;
}
}
}
}
if (vfields.charAt(10) == 1){
if (document.newlisting.addw.value == "") {
alert("Please enter a Web Site Address!");
return false;
}
}
if (vfields.charAt(11) == 1){
failed = 0
elmstr = document.newlisting.adde.value + "";
if (elmstr.indexOf("@") == "-1" || elmstr.indexOf(".") == "-1" || elmstr == "" || (elmstr.charAt((elmstr.length - 4)) != "." && elmstr.charAt((elmstr.length - 3)) != ".") || elmstr.length < 6 || elmstr.charAt(elmstr.indexOf("@") + 1) == ".") {
failed = 1
if (failed == 1){
alert("Please enter a valid Email Address!");
return false;
}
}
}
if (vfields.charAt(12) == 1){
if (document.newlisting.con1.value == "") {
alert("Please enter a Primary Contact Name!");
return false;
}
}
if (vfields.charAt(13) == 1){
if (document.newlisting.pos1.value == "") {
alert("Please enter a Primary Conatct Position/Title!");
return false;
}
}
if (vfields.charAt(14) == 1){
failed = 0
elmstr = document.newlisting.adde1.value + "";
if (elmstr.indexOf("@") == "-1" || elmstr.indexOf(".") == "-1" || elmstr == "" || (elmstr.charAt((elmstr.length - 4)) != "." && elmstr.charAt((elmstr.length - 3)) != ".") || elmstr.length < 6 || elmstr.charAt(elmstr.indexOf("@") + 1) == ".") {
failed = 1
if (failed == 1){
alert("Please enter a valid Primary Contact Email Address!");
return false;
}
}
}
if (vfields.charAt(15) == 1){
if (document.newlisting.catselected.value == "n"){
alert("Please select a Category!");
return false;
}
}

if (checkCat(document.newlisting.category) && checkCat(document.newlisting.categoryBP)){
return true;
} else	{ return false;}

return true;
}

	function tandc(){
		window.open ('privacy.asp', 'SitePolicy', 'scrollbars=yes,status=no,width=500,height=400')
	}

	function validateTerms(){
		if (document.newlisting.okterms.checked){
			return true;
		} else {
			alert("You must agree to the Terms and Conditions!");
			return false;
		}
		return true;
	}