$(document).ready(function(){
	
	// Initialize Map
	$('#legend').data('state', 'closed');
	
	
	//Legend Switch
	$('#legend h3').click(function(){ $('#legend').trigger('toggle'); });
	
	// Legend Toggling
	$('#legend').bind('toggle', function(){
		if($(this).data('state') == 'closed'){
			$(this).animate({top: '-45px'});
			$(this).data('state', 'open');
		}else{
			$(this).animate({top: '-200px'});
			$(this).data('state', 'closed');
		}
	});
		
});

var popupwin=0;
function win_popup(v_path) {
popupwin = open(v_path, 'popupwin', 'height=600,width=800,toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=no,menubar=no');
}

var popupmls=0;
function mls_popup(v_path) {
popupmls = open(v_path, 'popupwin', 'height=600,width=800,toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=yes,menubar=no');
}

var popupemail=0;
function emailfriend_popup(v_path) {
popupemail = open(v_path, 'popupgloss', 'height=400,width=610,toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=no,menubar=no');
}

var popupagent=0;
function contactagent_popup(v_path) {
popupagent = open(v_path, 'popupgloss', 'height=400,width=610,toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=no,menubar=no');
}


function formCheck(formobj){
		// Enter name of mandatory fields
		var fieldRequired = Array("Name", "AreaCode", "Phone", "Phone2", "Email");
		// Enter field description to appear in the dialog box
		var fieldDescription = Array("Name", "AreaCode", "Phone", "Phone2", "Email");
		// dialog message
		var alertMsg = "Please complete the following fields:\n";
		
		var l_Msg = alertMsg.length;
		
		for (var i = 0; i < fieldRequired.length; i++){
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "text":
				case "textarea":
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				default:
				}
				if (obj.type == undefined){
					var blnchecked = false;
					for (var j = 0; j < obj.length; j++){
						if (obj[j].checked){
							blnchecked = true;
						}
					}
					if (!blnchecked){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
				}
			}
		}
	
		if (alertMsg.length == l_Msg){
			return true;
		}else{
			alert(alertMsg);
			return false;
		}
	}


