$(function(){
	$('#contactus_submit,#meeting_submit,#wedding_submit').click(function(){
		var html = '';
		$('#message').empty();
		//check is_required
		if ("" == $("#proposal").val()) {
			html += "<li>Date proposal must be received:Please enter proposal.</li>"; 
		} else {}
		if("" == $("#firstname").val()) {
			html += "<li>First Name: Input required.</li>"; 
		}
		if ("" == $("#lastname").val()) {
			html += "<li>Last Name: Input required.</li>"; 
		}
		if ("" == $("#street").val()) {
			html += "<li>Street: Input required.</li>"; 
		}
		if ("" == $("#meeting_country").val()) {
			html += "<li>Country: Input required.</li>"; 
		}
		//email
		var myreg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if("" == $("#email input").val()){
			html += "<li>E-mail: The email address is empty.</li>"; 
		} else if (!myreg.test($("#email input").val())){
			html += "<li>E-mail:Please enter a valid Email.</li>"; 
		} else {}
		var patrn = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
		if ("" == $("#telphone").val()) {
			html += "<li>Telephone number: Input required.</li>"; 
		} else if (!patrn.test($("#telphone").val())) {
			html += "<li>Telephone number:Please enter a valid telphone.</li>"; 
		}
		//Guest  /[^\d]/
		var patrn1 = /^[0-9]*[1-9][0-9]*$/;
		var guests = $.trim( $('#guests input').val());
		if ("" != guests) {
			if (!patrn1.test(guests)) {
				html += "<li>Number of guests:Please enter a valid Guests.</li>"; 
			} else {}
		} else {}
		//GuestRooms  /[^\d]/
		var patrn2 = /^[0-9]*[1-9][0-9]*$/;
		var GuestRoom = $.trim( $('#GuestRoom input').val());
		if ("" != GuestRoom) {
			if (!patrn2.test(GuestRoom)) {
				html += "<li>Number of guest rooms:Please enter a valid GuestRoom.</li>"; 
			} else {}
		} else {}
		//NightPerRoom  /[^\d]/
		var patrn3 = /^[0-9]*[1-9][0-9]*$/;
		var NightPerRoom = $.trim( $('#NightPerRoom input').val());
		if ("" != NightPerRoom) {
			if (!patrn3.test(NightPerRoom)) {
				html += "<li>Number of nights per room: Please enter a valid NightPerRoom.</li>"; 
			} else {}
		} else {}
		//comment /
		if("" == $('#comment textarea').val()){
			html += "<li>Comments or Questions: Input required.</li>"; 
		} else {} 
		// send_infomation_to
		var check_obj = $("input[name='ContentObjectAttribute_ezselect_selected_array_12264[]']");
		if (check_obj.length > 0) {
			var length=0;
			for(var i=0; i<check_obj.length;i++){
				if(true == check_obj.get(i).checked){
					length++;
				} else {};
			}
			if (0 == length) {
				html += "<li>Send Information to: Input required.</li>";
			} else {}
		} else {}
		// message_topic
		$("#message_topic").find().each(function(){});
		var check1_obj = $("input[name='ContentObjectAttribute_ezselect_selected_array_12265[]']");
		if (check1_obj.length > 0) {
			var length=0;
			for(var i=0; i<check1_obj.length;i++){
				if(true == check1_obj.get(i).checked){
					length++;
				} else {};
			}
			if (0 == length) {
				html += "<li>Message Topic: Input required.</li>";
			} else {}
		} else {}
		if (html != '') {
			$('#message').append(html);
		} else {
			_key_ = $(this).attr('id');
			$('#'+_key_.replace('_submit', '')).trigger('submit');
			return false;
		}
	});
	
	$('#contactus_reset, #meeting_reset,#wedding_reset').click(function(){
		_key_ = $(this).attr('id');
		$("input[type=text]").each(function(){
			this.value="";
		} );
		$("#meeting_country_select").find('option').each(function() {  
        if ($(this).text() == "Select a Country") {  
                $(this).attr("selected", "selected");  
            }  
        });
		$("#meeting_state_select").find('option').each(function() {  
        if ($(this).text() == "Select a State" || $(this).text() == "Select a Province" || $(this).text() == "") {  
                $(this).text("Select a State");
				$(this).attr("selected", "selected");  
            }  
        });
		var check_obj = $("input[type=checkbox]");
		for(var i=0; i<check_obj.length;i++){
			check_obj.get(i).checked = false;
		}
		
		var check_obj = $("input[type=radio]");
		for(var i=0; i<check_obj.length;i++){
			check_obj.get(i).checked = false;
		}
		$('#comment textarea').val("");
		//$('#'+_key_.replace('_reset', '')).trigger('reset');	
		return false;
	});
	
	$('#contactus_country_select').change(function(){
		val = '';
		$(this).find('option').each(function(){
			if ($(this).attr('selected')) {
				val = $(this).text();
			}
		});
		if (val =='Select a Country' || val == '') {
			$('#contactus_country').val("");
		} else {
			$('#contactus_country').val(val);
		}
	});

	$('#meeting_country_select').change(function(){
		val = '';
		$(this).find('option').each(function(){
			if ($(this).attr('selected')) {
				val = $(this).text();
			}
		});
		if (val =='Select a Country' || val == '') {
			$('#meeting_country').val("");
		} else {
			$('#meeting_country').val(val);
		}
	});
});

