function returnObjById(id) {
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}
function emd_item_validate() {
	var answer;
	var title = document.forms[0].listing_title.value;
	var category = document.forms[0].listing_category.value;
	var address1 = document.forms[0].listing_address1.value;
	var address2 = document.forms[0].listing_address2.value;
	var city = document.forms[0].listing_city.value;
	var country = document.forms[0].listing_country.value;
	var tags = document.forms[0].listing_tags.value;
	var specials = document.forms[0].listing_specials.value;
	if (title.length > 30) {
		alert('The title you have entered is too long.  Please shorten it to no more than 30 characters.');
		return false;	
	}
	if (title==null||title=='') {
		alert('You have not entered a title for this listing.');
		return false;
	}
	if (category=='') {
		alert("Please select a category for this listing.");
		return false;
	}
	if (document.forms[0].listing_phone.disabled == false) {
		var phone = document.forms[0].listing_phone.value;
		if (phone==null||phone=='') {
			answer = confirm('You have not entered a phone number for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (phone.length > 25) {
			alert('The phone number you have entered is too long.  Please shorten it to no more than 25 characters.');
			return false;
		}
	}
	if (document.forms[0].listing_fax.disabled == false) {
		var fax = document.forms[0].listing_fax.value;
		if (fax==null||fax=='') {
			answer = confirm('You have not entered a fax number for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (fax.length > 25) {
			alert('The fax number you have entered is too long.  Please shorten it to no more than 25 characters.');
			return false;
		}
	}
	if (document.forms[0].listing_email.disabled == false) {
		var email = document.forms[0].listing_email.value;
		if (email==null||email=='') {
			answer = confirm('You have not entered an email address for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (email.length > 127) {
			alert('The email address you have entered is too long.  Please shorten it to no more than 127 characters.');
			return false;
		}
	}
	if (document.forms[0].listing_url.disabled == false) {
		var url = document.forms[0].listing_url.value;
		if (url==null||url==''||url=='http://') {
			answer = confirm('You have not entered a URL for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (url.length > 127) {
			alert('The URL you have entered is too long.  Please shorten it to no more than 127 characters.');
			return false;
		}
	}
	if (address1==null||address1=='') {
		alert('You have not entered the first line of an address for this listing.');
		return false;
	}
	if (address1.length > 127) {
		alert('The first line of the address you have entered is too long.  Please shorten it to no more than 127 characters');
		return false;
	}
	if (address2.length > 127) {
		alert('The second line of the address you have entered is too long.  Please shorten it to no more than 127 characters');
		return false;
	}
	if (city==null||city=='') {
		alert('You have not entered a city for this listing.');
		return false;
	}
	if (city.length > 40) {
		alert('The city you have entered is too long.  Please shorten it to no more than 40 characters');
		return false;
	}
	if (document.forms[0].listing_state.disabled == false) {
		var state = document.forms[0].listing_state.value;
		if (state==null||state=='') {
			alert('You have not selected a state for this listing.  This field is only required if \'United States\' is selected as the country.');
			return false;
		}
		if (state.length > 20) {
			alert('The state you have chosen is too long.  Please shorten it to no more than 20 characters.');
			return false;
		}
	}
	if (document.forms[0].listing_zip.disabled == false) {
		var zip = document.forms[0].listing_zip.value;
		if (zip==null||zip=='') {
			alert('You have not entered a ZIP code for this listing.  This field is only required if \'United States\' is selected as the country.');
			return false;
		} else if (zip.length > 5) {
			alert('The ZIP code you have entered is too long.  Please shorten it to 5 digits.');
			return false;
		} else if (zip.length > 1 && zip.length < 5) {
			alert('The ZIP code you have entered is too short.  Please shorten it to 5 digits.');
			return false;
		} else if (zip.length == 5) {
			if (isNaN(parseInt(zip))) {
				alert('The ZIP code you have entered is not numeric.  Please ensure that it is composed of 5 numbers.');
				return false;
			}
		}
	}
	if (country==null||country=='') {
		alert('You have not selected a country for this listing.');
		return false;
	}
	if (document.forms[0].listing_description.disabled == false) {
		var description = document.forms[0].listing_description.value;
		if (description==null||description=='') {
			alert('You have not entered a description for this listing.');
			return false;
		}
		if (description.length > 16777215) {
			alert('The description you have entered is too long.  Please shorten it to no more than 16,777,215 characters.');
			return false;
		}
	}
	if (tags==null||tags=='') {
		alert('You have not entered any tags for this listing.');
		return false;
	} else if (tags.length > 127) {
		var aMsg = 'The tag list you have entered is too long.  Please shorten it to no more than 127 characters - you are currently using: ' + tags.length;
		alert(aMsg);
		return false;
	}
	if (document.forms[0].listing_hours.disabled == false) {
		var hours = document.forms[0].listing_hours.value;
		if (hours==null||hours=='') {
			answer = confirm('You have not entered any hours for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (hours.length > 65535) {
			alert('The hours you have entered are too long.  Please shorten them to no more than 16,777,215 characters');
			return false;
		}
	}
	if (specials.length > 65535) {
		alert('The specials you have entered are too long.  Please shorten them to no more than 16,777,215 characters');
		return false;
	}
	if (document.forms[0].listing_menu.disabled == false) {
		var menu = document.forms[0].listing_menu.value;
		if (menu==null||menu=='') {
			answer = confirm('You have not entered any menu information for this listing. Do you still wish to proceed?');
			if (!answer) {
				return false;
			}
		}
		if (menu.length > 65535) {
			alert('The menu information you have entered is too long.  Please shorten it to no more than 16,777,215 characters');
			return false;
		}
	}
	return true;
}
function emd_item_comment_validate() {
	var commentTitle = document.emd_item_comment.listing_comment_title.value;
	var rating = document.emd_item_comment.listing_comment_rating.value;
	var comment = document.emd_item_comment.listing_comment.value;
	if (commentTitle==''||commentTitle==null) {
		alert('You have not entered a title for your comment.');
		return false;	
	}
	if (rating==''||rating==null) {
		alert('You have not rated this listing.');
		return false;	
	}
	if (comment=='Enter your comment here.'||comment==''||comment==null) {
		alert('You have not entered a comment.');
		return false;	
	}
	if (comment.length > 16777215) {
		alert('The comment you have entered is too long.  Please shorten it to no more than 16,777,215 characters');
		return false;
	}
	return true;
}
function emd_item_image_validate() {
	var image = document.emd_item_upload_img.listing_uploaded_image.value;
	if (image==''||image==null) {
		alert("You haven't chosen an image to upload.");
		return false;
	} else {
		if (!/(\.(gif|jpg|jpeg|png))$/i.test(image)){
			alert("Sorry, only .jpg, .jpeg, or .gif images are allowed.");
			return false;
		}
	}
	return true;
}
function emd_item_video_validate() {
	var video = document.emd_item_upload_vid.listing_uploaded_video.value;
	var stream = document.emd_item_upload_vid.listing_streaming_video.value;
	var title = document.emd_item_upload_vid.listing_video_title.value;
	if ((video=='') && (stream==''||stream=='http://')) {
		alert("You haven't chosen a video to upload.");
		return false;
	} else if ((video!='') && ((stream!=''&&stream!='http://') || (title!=''))) {
		answer = confirm("You have entered details for both an uploaded video and a streaming video.  Only the upload will be used, any URL or title you have entered will be disregarded.  Do you still want to proceed?");
		if (!answer) {
			return false;
		}
	} else {
		if (video!='') {
			if (!/(\.(mpg|swf|mpeg|wmv))$/i.test(video)){
				alert("Sorry, only .mpg, .mpeg or .swf videos are allowed.");
				return false;
			}
		} else if (stream!=''&&stream!='http://') {
			if (title==''||title==null) {
				alert("You haven't entered a title for this video.");
				return false;
			}
		}
	}
	return true;
}
function emd_img_approval_validate() {
	var answer;
	var imgCheckboxes = document.getElementsByName('img_approval[]');
	var howManyCheckboxes = imgCheckboxes.length;
	var howManyImgToApprove = 0;
	for (i=0;i<howManyCheckboxes;i++) {
		if (imgCheckboxes[i].checked == true) {
			howManyImgToApprove++;
		}
	}
	if (howManyImgToApprove > 0) {
		if (howManyImgToApprove == 1) {
			confirmMsg = "This action will affect 1 image.  Are you sure you want to proceed?";
		} else if (howManyImgToApprove > 1) {
			confirmMsg = "This action will affect "+howManyImgToApprove+" images.  Are you sure you want to proceed?";
		}
		answer = confirm(confirmMsg);
		if (answer) {
			return true;
		} else {
			return false;
		}
	} else {
		alert('You have not selected any images.');
		return false;
	}
	return true;
}
function emd_vid_approval_validate() {
	var answer;
	var vidCheckboxes = document.getElementsByName('vid_approval[]');
	var howManyCheckboxes = vidCheckboxes.length;
	var howManyVidToApprove = 0;
	for (i=0;i<howManyCheckboxes;i++) {
		if (vidCheckboxes[i].checked == true) {
			howManyVidToApprove++;
		}
	}
	if (howManyVidToApprove > 0) {
		if (howManyVidToApprove == 1) {
			confirmMsg = "This action will affect 1 video.  Are you sure you want to proceed?";
		} else if (howManyVidToApprove > 1) {
			confirmMsg = "This action will affect "+howManyVidToApprove+" videos.  Are you sure you want to proceed?";
		}
		answer = confirm(confirmMsg);
		if (answer) {
			return true;
		} else {
			return false;
		}
	} else {
		alert('You have not selected any videos.');
		return false;
	}
	return true;
}
function emd_doINeedStateAndZip() {
	var country = document.forms[0].listing_country.value;
	var state = document.forms[0].listing_state;
	var zip = document.forms[0].listing_zip;
	if (country != '212') {
		state.disabled = true;
		state.style.backgroundColor = '#999';
		zip.disabled = true;
		zip.style.backgroundColor = '#999';
	} else {
		state.disabled = false;
		state.style.backgroundColor = '#fff';
		zip.disabled = false;
		zip.style.backgroundColor = '#fff';
	}
}
function emd_doINeedToFindStateAndZip() {
	var country = document.emd_find.findACountry.value;
	var state = returnObjById('emd_find_f3');
	var city = returnObjById('emd_find_f4');
	var zip = returnObjById('emd_find_f5');
	if (country != '212') {
		state.style.display = 'none';
		zip.style.display = 'none';
	} else {
		state.style.display = '';
		zip.style.display = '';
	}
}
function emd_find_validate() {
	var zip = document.emd_find.find_zip.value;
	if (zip.length > 5) {
		alert('The ZIP code you have entered is too long.  Please shorten it to 5 digits.');
		return false;
	} else if (zip.length > 1 && zip.length < 5) {
		alert('The ZIP code you have entered is too short.  Please shorten it to 5 digits.');
		return false;
	} else if (zip.length == 5) {
		if (isNaN(parseInt(zip))) {
			alert('The ZIP code you have entered is not numeric.  Please ensure that it is composed of 5 numbers.');
			return false;
		} else {
			return true;
		}
	}
}
function emd_adminDel_validate(url) {
	answer = confirm("If you continue this listing will be deleted forever.  Do you still want to proceed?");
	if (!answer) {
		return false;
	} else {
		location.href=url;
		return true;
	}
}
function emd_imgDel_validate(url) {
	answer = confirm("You have chosen to delete this image.  Do you still want to proceed?");
	if (!answer) {
		return false;
	} else {
		location.href=url;
		return true;
	}
}
function emd_vidDel_validate(url) {
	answer = confirm("You have chosen to delete this video.  Do you still want to proceed?");
	if (!answer) {
		return false;
	} else {
		location.href=url;
		return true;
	}
}