
$(function()
	{
	
	//make sure send_enquiry is enabled
	$('#send_enquiry_basic').removeAttr('disabled');
	$('#send_enquiry_property').removeAttr('disabled');
	$('#send_enquiry_featured').removeAttr('disabled');
	
	/*
	//to colorize input fields - maybe use later-----------------------------------
	function focused()
		{
		//reset inputs, textareas, tds color
		$("input").css({'border-color' : ''});
		$("textarea").css({'border-color' : ''});
		$("form").find("td").css({'color' : ''});
		//set this border colour and text colour
		$(this).css({'border-color' : '#555555'});
		$(this).parent().parent().find('td').css({'color' : '#333333'});
		};
	
	$("input").focus(focused);
	$("textarea").focus(focused);
	$("select").focus(focused);
	
	//end to colorize input fields - maybe use later--------------------------------
	*/
	
	});


//to highlight the textarea
$(function()
	{
	
	});//end function


//to validate the email address (called below)
function echeck(elementValue)
	{
 		var emailPattern = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
   		return emailPattern.test(elementValue);  
	}


//-------- if they click send_enquiry on rightside-contact or rightside-search --------------//
$(function()
	{
	$(".send_enquiry_basic").click(function()
		{
		//start by hiding error msgs, so we never see two error msgs at once
	  	$('.error').hide();

		//get values
		var imie = $("input#imie").val(),
			email = $("input#email").val(),
			telefon = $("input#telefon").val(),
			telefon2 = $("input#telefon2").val(),
			tresc = $("textarea#tresc").val(),
			frompage = $("input#frompage").val(),
			type = $("input#type").val();

	
		//if name is blank
		if(imie == "" || imie == "Full Name")
			{
			$("label#problem").show();
			$("label#imie_error").show();
			return false;
			}
		
		//if email and phone are blank
		if( (email == "" || email == "Email Address")
		    && (telefon == "" || telefon == "Daytime Phone")
			&& (telefon2 == "" || telefon2 == "Evening Phone") )
			{
			$("label#problem").show();
			$("label#email_error").show();
			return false;
			}
		
		//if email is not blank, make sure it's valid
		if(email != "" && email != "Email Address")
			{
			if(echeck(email)!=true)
				{
				$("label#problem").show();
				$("label#email_error2").show();
				$("input#email").focus();
				return false;
				}
			}

		
		var dataString = 'imie=' + imie + '&email=' + email + '&telefon=' + telefon + '&telefon2=' + telefon2+ '&tresc=' + tresc + '&frompage=' + frompage + '&type=' + type;
		
		//alert (dataString); return false;

		$('#send_enquiry_basic').css('background','url(/images/buttons/sendingAndSent.png) top no-repeat');
		$.ajax(
			{
			type: "POST",
			url: "/msg.php", // don't add http here, otherwise problems appear when on http://www vs just http://
			data: dataString,
			success: function()
				{
				$('#messageHolder').html("<div id='message'></div>");
				$('#message').html("Your enquiry has been sent").append("");
				} //end success
			}); //end .ajax
			//$(this).fadeOut("slow");
			//$(".send_enquiry").fadeOut(1500);
			$("#send_enquiry_basic").attr("disabled","disabled"); //this is countered above in this js file with $('.send_enquiry').removeAttr('disabled');
			$('#send_enquiry_basic').css('background','url(/images/buttons/sendingAndSent.png) bottom no-repeat');
			$('#send_enquiry_basic').css('cursor','default');
			return false; //so page doesn't reload


		}); //end button.click function
	}); //end function
	
//------ end if they click send_enquiry on rightside-contact or rightside-search ------------//



//---------------------- if they click send_enquiry on property.tpl ------------------------------//
$(function()
	{
	$("input[type=checkbox][name=agree]").hide();
	
	$(".send_enquiry_property").click(function()
		{
		//this is different than the others -- it uses visibility instead of display to hide/show errors
		//start by hiding error msgs and resetting border colors, so we never see two error msgs at once
		$('.error').css({ visibility : 'hidden' });
		$("#contactOwnerTab input").css({ borderColor : '#999999' });
	  	
		//get values
		var imie = $("input#imie").val(),
			email = $("input#emailEnq").val(),
			telefon = $("input#telefon").val(),
			checkfrom = $("input#checkfrom").val(),
			checkto = $("input#checkto").val(),
			adults = $("input#adults").val(),
			kids = $("input#kids").val(),
			tresc = $("textarea#tresc").val(),
			id = $("input#id").val(),
			property = $("input#property").val(),
			frompage = $("input#frompage").val(),
			type = $("input#type").val(),
                        pid = $("input#pid").val(),
                        pname = $("input#pname").val(),
                        uid = $("input#uid").val();
						
			question_id = $("input[name=question_id]").val();
			answer = $("input[name=answer]").val();
			
			$.ajax({
				type: "POST",
				url: "/check_question.php",
				data: 'question_id=' + question_id + '&answer=' + answer,
				success: function(data)
					{
					if(data == 'success')
					{
						
						
						
						//if name is blank
						if(imie == "" || imie == "Full Name")
							{
							$("label#problem").css({ visibility : 'visible' });
							$("label#imie_error").css({ visibility : 'visible' });
							$("#imie").css({ borderColor : 'red' });
							return false;
							}
						
						//if email and phone are blank
						if( (email == "" || email == "Email Address") && (telefon == "" || telefon == "Phone Number") )
							{
							$("label#problem").css({ visibility : 'visible' });
							$("label#email_error").css({ visibility : 'visible' }).html('Email required...');
							$("label#telefon_error").css({ visibility : 'visible' });
							$("#emailEnq, #telefon").css({ borderColor : 'red' });
							return false;
							}
						
						//if email is not blank, make sure it's valid
						if(email != "" && email != "Email Address")
							{
							if(echeck(email)!=true)
								{
								$("label#problem").css({ visibility : 'visible' });
								$("label#email_error").css({ visibility : 'visible' }).html('Invalid email');
								$("input#emailEnq").focus();
								return false;
								}
							}

						
						var dataString = 'imie=' + imie + '&email=' + email + '&telefon=' + telefon + '&checkfrom=' + checkfrom + '&checkto=' + checkto + '&adults=' + adults + '&kids=' + kids + '&tresc=' + tresc + '&pid=' + pid + '&pname=' + pname + '&frompage=' + frompage + '&type=' + type +'&uid=' + uid;
						
						//alert (dataString); return false;

						$('#send_enquiry_property').css('background','url(/images/buttons/sendingAndSent.png) top no-repeat');
						$.ajax(
							{
							type: "POST",
							url: "/msg.php", // don't add http here, otherwise problems appear when on http://www vs just http://
							data: dataString,
							success: function()
								{
								//$('#messageHolder').html("<div id='message'></div>");
								$('#problem').css({ visibility : 'visible', color : '#666666' }).html('Your enquiry has been sent');
								} //end success
							}); //end .ajax
							//$(this).fadeOut("slow");
							//$(".send_enquiry_property").fadeOut(1500);
							$("#send_enquiry_property").attr("disabled","disabled"); //this is countered above in this js file with $('.send_enquiry_property').removeAttr('disabled');
							$('#send_enquiry_property').css('background','url(/images/buttons/sendingAndSent.png) bottom no-repeat');
							$('#send_enquiry_property').css('cursor','default');
							return false; //so page doesn't reload
						
						
						
						
					}
					else
					{
						$("label.error[for=answer], label#problem").css({ visibility : 'visible' });
						return false;
					}
					}
			});
		
		


		}); //end button.click function
		
		
		
	$(".send_enquiry_property_hs").click(function()
		{
		//this is different than the others -- it uses visibility instead of display to hide/show errors
		//start by hiding error msgs and resetting border colors, so we never see two error msgs at once
		$('.error').css({ visibility : 'hidden' });
		$("#contactOwnerTab input").css({ borderColor : '#999999' });
	  	
		//get values
		var imie = $("input#imie").val(),
			email = $("input#email2").val(),
			telefon = $("input#telefon").val(),
			checkfrom = $("input#checkfrom").val(),
			checkto = $("input#checkto").val(),
			adults = $("input#adults").val(),
			kids = $("input#kids").val(),
			tresc = $("textarea#tresc").val(), // Msg
			myHouse = $("textarea#myhouse").val(), // Msg
			id = $("input#id").val(),
			property = $("input#property").val(),
			frompage = $("input#frompage").val(),
			type = $("input#type").val(),
                        pid = $("input#pid").val(),
                        pname = $("input#pname").val(),
                        uid = $("input#uid").val();
						
			question_id = $("input[name=question_id]").val();
			answer = $("input[name=answer]").val();
			
			$.ajax({
				type: "POST",
				url: "/check_question.php",
				data: 'question_id=' + question_id + '&answer=' + answer,
				success: function(data)
					{
					if(data == 'success')
					{
						
						
						
						//if name is blank
						if(imie == "" || imie == "Full Name")
							{
							$("label#problem").css({ visibility : 'visible' });
							$("label#imie_error").css({ visibility : 'visible' });
							$("#imie").css({ borderColor : 'red' });
							return false;
							}
						
						//if email and phone are blank
						if( (email == "" || email == "Email Address") && (telefon == "" || telefon == "Phone Number") )
							{
							$("label#problem").css({ visibility : 'visible' });
							$("label#email_error").css({ visibility : 'visible' }).html('Email required...');
							$("label#telefon_error").css({ visibility : 'visible' });
							$("#emailEnq, #telefon").css({ borderColor : 'red' });
							return false;
							}
						
						//if email is not blank, make sure it's valid
						if(email != "" && email != "Email Address")
							{
							if(echeck(email)!=true)
								{
								$("label#problem").css({ visibility : 'visible' });
								$("label#email_error").css({ visibility : 'visible' }).html('Invalid email');
								$("input#emailEnq").focus();
								return false;
								}
							}

						
						var dataString = 'imie=' + imie + '&email=' + email + '&telefon=' + telefon + '&checkfrom=' + checkfrom + '&checkto=' + checkto + '&adults=' + adults + '&kids=' + kids + '&tresc=' + tresc + '&myHouse=' + myHouse + '&pid=' + pid + '&pname=' + pname + '&frompage=' + frompage + '&type=' + type +'&uid=' + uid;
						
						//alert (dataString); return false;

						$('#send_enquiry_property_hs').css('background','url(/images/buttons/sendingAndSent.png) top no-repeat');
						$.ajax(
							{
							type: "POST",
							url: "/msg.php", // don't add http here, otherwise problems appear when on http://www vs just http://
							data: dataString,
							success: function()
								{
								//$('#messageHolder').html("<div id='message'></div>");
								$('#problem').css({ visibility : 'visible', color : '#666666' }).html('Your enquiry has been sent');
								} //end success
							}); //end .ajax
							//$(this).fadeOut("slow");
							//$(".send_enquiry_property").fadeOut(1500);
							$("#send_enquiry_property_hs").attr("disabled","disabled"); //this is countered above in this js file with $('.send_enquiry_property').removeAttr('disabled');
							$('#send_enquiry_property_hs').css('background','url(/images/buttons/sendingAndSent.png) bottom no-repeat');
							$('#send_enquiry_property_hs').css('cursor','default');
							return false; //so page doesn't reload
						
						
						
						
					}
					else
					{
						$("label.error[for=answer], label#problem").css({ visibility : 'visible' });
						return false;
					}
					}
			});
		
		


		}); //end button.click function
		
	
	}); //end function

//----------------- end if they click send_enquiry on property.tpl -------------------------//



//----------------- if they click send_enquiry on rightside-owners.tpl -------------------------//
$(function()
	{
	$(".send_enquiry_featured").click(function()
		{
		//start by hiding error msgs, so we never see two error msgs at once
	  	$('.error').hide();
	  	
		//get values
		//the id's are appended because this appears along with _basic form, so these ids muse be unique
		var placement = $("select#placement").val(),
			imie = $("input#imie_featured").val(),
			email = $("input#email_featured").val(),
			telefon = $("input#telefon_featured").val(),
			telefon2 = $("input#telefon2_featured").val(),
			location = $("input#location_featured").val(),
			tresc = $("textarea#tresc_featured").val(),
			frompage = $("input#frompage_featured").val(),
			type = $("input#type_featured").val();
		
		//if name is blank
		if(imie == "" || imie == "Full Name")
			{
			$("label#problem_featured").show();
			$("label#imie_error_featured").show();
			return false;
			}
		
		//if email and phone are blank
		if( (email == "" || email == "Email Address")
		    && (telefon == "" || telefon == "Daytime Phone")
			&& (telefon2 == "" || telefon2 == "Evening Phone") )
			{
			$("label#problem_featured").show();
			$("label#email_error_featured").show();
			return false;
			}
		
		//if email is not blank, make sure it's valid
		if(email != "" && email != "Email Address")
			{
			if(echeck(email)!=true)
				{
				$("label#problem_featured").show();
				$("label#email_error2_featured").show();
				$("input#email_featured").focus();
				return false;
				}
			}

		
		var dataString = 'placement=' + placement + '&imie=' + imie + '&email=' + email + '&telefon=' + telefon + '&telefon2=' + telefon2 +  '&location=' + location + '&tresc=' + tresc + '&frompage=' + frompage + '&type=' + type;
		
		//alert (dataString); return false;

		$('#send_enquiry_featured').css('background','url(/images/buttons/sendingAndSent.png) top no-repeat');
		$.ajax(
			{
			type: "POST",
			url: "/msg.php", // don't add http here, otherwise problems appear when on http://www vs just http://
			data: dataString,
			success: function()
				{
				$('#messageHolder_featured').html("<div id='message_featured'></div>");
				$('#message_featured').html("Your enquiry has been sent").append("");
				} //end success
			}); //end .ajax
			//$(this).fadeOut("slow");
			//$(".send_enquiry_featured").fadeOut(1500);
			$("#send_enquiry_featured").attr("disabled","disabled"); //this is countered above in this js file with $('.send_enquiry_featured').removeAttr('disabled');
			$('#send_enquiry_featured').css('background','url(/images/buttons/sendingAndSent.png) bottom no-repeat');
			$('#send_enquiry_featured').css('cursor','default');
			return false; //so page doesn't reload


		}); //end button.click function
	
	}); //end function

//--------------- end if they click send_enquiry on rightside-owners.tpl ------------------------//




