    function uncheckAny(formname,field) {

        var CheckBox = formname.elements[field];

            CheckBox[CheckBox.length-1].checked = false;

    }

    function uncheckAll(formname,field) {

        var CheckBox = formname.elements[field];

            for (i = 0; i < (CheckBox.length - 1); i++) {

                if (CheckBox[i].checked)

                    CheckBox[i].checked = false ;

            }

    }

    function setCheckboxes(formname, check) {

        var CheckBox = document.forms[formname].elements;

        for (i = 0; i < CheckBox.length; i++) {

            CheckBox[i].checked = check ;

        }

    }

	$(document).ready(function() {

		$("select#select_state").change(function () {

			var state = $("select#select_state").val();

			if ( state == 'any' ) {

				document.getElementById('select_city').disabled = "disabled";

			} else {

				$('span.cities_loading').show();
				document.getElementById('select_city').disabled = "disabled";

				var dataString = 'state='+state;

				$.ajax({
				
					type: "POST",
					url: "http://www.listingvista.com/includes/update_cities.php",
					data: dataString,
					success: function(data) {

						$('select#select_city').html(data);
						$('span.cities_loading').hide();
						document.getElementById('select_city').disabled = false;
		
					}
		
				});

				return false;

			}

		});

		$("input#submitOrder").click(function () {

			var select_package = $("select#select_package").val();
			var tour_title = $("input#tour_title").val();
			var tour_desc = $("textarea#tour_desc").val();
			var select_state = $("select#select_state").val();
			var select_city = $("select#select_city").val();
			var tour_mls_number = $("input#tour_mls_number").val();
			var tour_house_number = $("input#tour_house_number").val();
			var tour_street = $("input#tour_street").val();
			var tour_zipcode = $("input#tour_zipcode").val();
			var tour_price = $("input#tour_price").val();
			var tour_square_footage = $("input#tour_square_footage").val();
			var tour_bedrooms = $("select#tour_bedrooms").val();
			var tour_bathrooms = $("select#tour_bathrooms").val();
			var tour_property_type = $("select#tour_property_type").val();
			var tour_listing_terms = $("select#tour_listing_terms").val();
			var tour_pool = $("input[@name='tour_pool']").is(":checked");
			var tour_view = $("input[@name='tour_view']").is(":checked");
			var tour_garage = $("input[@name='tour_garage']").is(":checked");
			var tour_association = $("input[@name='tour_association']").is(":checked");

			var appointment_best_phone = $("input#appointment_best_phone").val();
			var appointment_contact_name = $("input#appointment_contact_name").val();
			var appointment_best_time = $("input#appointment_best_time").val();
			var appointment_comments = $("textarea#appointment_comments").val();

			if (select_package == "any") {
	
				alert('Please Select Tour Package');
				$("input#select_package").focus();
		
				return false;
	
			} else {

				if ( select_package == 1 ) {

					$("input#amount").val('150.00');
					$("input#item_name").val('1 to 1500 sqft - 360 Virtual Tour');

				} else if ( select_package == 2 ) {

					$("input#amount").val('250.00');
					$("input#item_name").val('1,500 to 3,500 sqft - 360 Virtual Tour');

				} else if ( select_package == 3 ) {

					$("input#amount").val('375.00');
					$("input#item_name").val('3,500 to 7,000 sqft - 360 Virtual Tour');

				}

			}

			if (tour_title == "") {
	
				alert('Please Enter a Title');
				$("input#tour_title").focus();
		
				return false;
	
			}
	
			if (tour_desc == "") {
	
				alert('Please Enter a Description');
				$("textarea#tour_desc").focus();
		
				return false;
	
			}

			if (tour_mls_number == "") {
	
				alert('Please Enter a MLS #');
				$("input#tour_mls_number").focus();
		
				return false;
	
			}

			if (tour_mls_number != "") {

				var dataString = 'mls='+tour_mls_number;
		
				$.ajax({
				
					type: "POST",
					url: "http://www.listingvista.com/includes/admin/check_mls_number.php",
					data: dataString,
					success: function(data) {
		
						if ( data == 1 ) {

							alert('This MLS # is Already Listed');
							$("input#tour_mls_number").focus();
							$("input#tour_mls_number").select();

							return false;

						} else {

							if (tour_house_number == "") {
					
								alert('Please Enter a House #');
								$("input#tour_house_number").focus();
						
								return false;
					
							}
				
							if (tour_street == "") {
					
								alert('Please Enter a Street Name');
								$("input#tour_street").focus();
						
								return false;
					
							}
				
							if (select_state == "any") {
					
								alert('Please Select a State');
								$("select#select_state").focus();
						
								return false;
					
							}
				
							if (select_city == "any") {
					
								alert('Please Select a City');
								$("select#select_city").focus();
						
								return false;
					
							}
				
							if (tour_zipcode == "") {
					
								alert('Please Enter a Zip Code');
								$("input#tour_zipcode").focus();
						
								return false;
					
							}
				
							if (tour_price == "") {
					
								alert('Please Enter a Price');
								$("input#tour_price").focus();
						
								return false;
					
							}
				
							if (tour_square_footage == "") {
					
								alert('Please Enter the Sqaure Footage');
								$("input#tour_square_footage").focus();
						
								return false;
					
							}
				
							if (tour_bedrooms == "any") {
					
								alert('Please Select the number of bedrooms');
								$("select#tour_bedrooms").focus();
						
								return false;
					
							}
				
							if (tour_bathrooms == "any") {
					
								alert('Please Select the number of bathrooms');
								$("select#tour_bathrooms").focus();
						
								return false;
					
							}
				
							if (tour_property_type == "any") {
					
								alert('Please Select the Property Type');
								$("select#tour_property_type").focus();
						
								return false;
					
							}

							if (tour_listing_terms == "any") {
					
								alert('Please Select the Listing Terms');
								$("select#tour_listing_terms").focus();
						
								return false;
					
							}

							if (!tour_pool) {
					
								alert('Does Property have a Pool?');
						
								return false;
					
							} else {

								if ( tour_pool == true ) {

									tour_pool = '1';

								} else {

									tour_pool = '0';

								}

							}
				
							if (!tour_view) {
					
								alert('Does Property have a View?');
						
								return false;
					
							} else {

								if ( tour_view == true ) {

									tour_view = '1';

								} else {

									tour_view = '0';

								}

							}
				
							if (!tour_garage) {
					
								alert('Does Property have a Garage?');
						
								return false;
					
							} else {

								if ( tour_garage == true ) {

									tour_garage = '1';

								} else {

									tour_garage = '0';

								}

							}
				
							if (!tour_association) {
					
								alert('Please Select Association');
						
								return false;
					
							} else {

								if ( tour_association == true ) {

									tour_association = '1';

								} else {

									tour_association = '0';

								}

							}

							if (appointment_best_phone == "") {
					
								alert('Please Enter the Best Phone Number to Contact You.');
								$("input#appointment_best_phone").focus();
						
								return false;
					
							}
				
							if (appointment_contact_name == "") {
					
								alert('Please Enter a Contact Name');
								$("input#appointment_contact_name").focus();
						
								return false;
					
							}
				
							if (appointment_best_time == "") {
					
								alert('Please Enter the Best Time to Contact You.');
								$("input#appointment_best_time").focus();
						
								return false;
					
							}

							var dataString = 'tour_mls_number='+tour_mls_number+'&tour_house_number='+tour_house_number+'&tour_title='+tour_title+'&tour_desc='+tour_desc+'&tour_street='+tour_street+'&select_state='+select_state+'&select_city='+select_city+'&tour_zipcode='+tour_zipcode+'&tour_price='+tour_price+'&tour_square_footage='+tour_square_footage+'&tour_bedrooms='+tour_bedrooms+'&tour_bathrooms='+tour_bathrooms+'&tour_property_type='+tour_property_type+'&tour_listing_terms='+tour_listing_terms+'&tour_pool='+tour_pool+'&tour_view='+tour_view+'&tour_garage='+tour_garage+'&tour_association='+tour_association+'&appointment_best_phone='+appointment_best_phone+'&appointment_contact_name='+appointment_contact_name+'&appointment_best_time='+appointment_best_time+'&appointment_comments='+appointment_comments;

							$(document).ready(function() {
					
								$.ajax({
								
									type: "POST",
									url: "http://www.listingvista.com/includes/order_virtual_tour.php",
									data: dataString,
									success: function(data) {

										document.order_form.submit();
					
									}
						
								});
					
							});

						}

					}
		
				});

			}

			return false;
	
		});

	});

	function remove_virtual_tour_thumb(thumb_id) {

		var answer = confirm("Are you sure you want to delete this thumbnail?");

		if (answer) {

			var dataString = 'thumb_id='+thumb_id;

			$.ajax({
			
				type: "POST",
				url: "http://www.listingvista.com/includes/admin/remove_virtual_tour_thumb.php",
				data: dataString,
				success: function(data) {

					if ( data == 1 ) {
	
						$('td#thumb_data').html('<input name="tour_thumb" id="tour_thumb" class="normal_field" type="file"></input>');
	
					}

				}

			});

		}

		return false;

	}

	function remove_virtual_tour(flash_id) {

		var answer = confirm("Are you sure you want to delete this virtual tour?");

		if (answer) {

			var dataString = 'flash_id='+flash_id;

			$.ajax({
			
				type: "POST",
				url: "http://www.listingvista.com/includes/admin/remove_virtual_tour.php",
				data: dataString,
				success: function(data) {

					if ( data == 1 ) {
	
						$('td#flash_data').html('<input name="tour_360flash" id="tour_360flash" class="normal_field" type="file" />');
	
					}

				}

			});

		}

		return false;

	}

	function remove_realtor_photo(photo_id) {

		var answer = confirm("Are you sure you want to delete this photo?");

		if (answer) {

			var dataString = 'photo_id='+photo_id;

			$.ajax({
			
				type: "POST",
				url: "http://www.listingvista.com/includes/admin/remove_realtor_photo.php",
				data: dataString,
				success: function(data) {

					if ( data == 1 ) {
	
						$('div#picture_data').html('<input name="realtor_picture" id="realtor_picture" class="normal_field" type="file"></input>');
	
					}

				}

			});

		}

		return false;

	}

	function delete_administrator(EditID) {

		var answer = confirm("Are you sure you want to delete this administrator?");

		if (answer) {

			var dataString = 'EditID='+EditID;

			$.ajax({
			
				type: "POST",
				url: "http://www.listingvista.com/includes/admin/delete_administrator.php",
				data: dataString,
				success: function(data) {

					if ( data == 1 ) {
	
						window.location.href = 'http://www.listingvista.com/admin/admin_manager.php?action=3';
	
					}

				}

			});

		}

		return false;

	}

	function delete_realtor(EditID) {

		var answer = confirm("Are you sure you want to delete this realtor?");

		if (answer) {

			var dataString = 'EditID='+EditID;

			$.ajax({
			
				type: "POST",
				url: "http://www.listingvista.com/includes/admin/delete_realtor.php",
				data: dataString,
				success: function(data) {

					if ( data == 1 ) {
	
						window.location.href = 'http://www.listingvista.com/admin/realtor_manager.php?action=3';
	
					}

				}

			});

		}

		return false;

	}
