jQuery(document).ready(function ($) {

    $("#s, #bs, #cname, #cemail, #ccontact, .ovinput, #sccontact").focus(function () {
        if (this.value == this.defaultValue) {
            this.value = ""
        }
    }).blur(function () {
        if (!this.value.length) {
            this.value = this.defaultValue
        }
    });

    $("#contform").submit(function () {
		$("#cname, #cemail, #ccontact").css("border", "1px solid #B7B7B8");
        $("#cname, #cemail, #ccontact").each(function () {
            if (this.value == this.defaultValue) {
                $(this).css("border", "1px solid red").focus();
                return false
            }
        });
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        var email = $("#cemail").val();
        if (!pattern.test(email)) {
            $("#cemail").css("border", "1px solid red").focus();
            return false
        }
		var sendcopy = "no";
		if ($("#sendcopy").is(':checked')){sendcopy = "yes"}
        $.post("http://icorr.com/wp-content/themes/icorr/ajax.contact.php", {
            "ctname": $("#cname").val(),
            "ctemail": $("#cemail").val(),
            "ctmsg": $("#ccontact").val(),
			"ccopy": sendcopy
        }, function (data) {
            if (data.response == "Thank You") {
                $("#cresponse").addClass('ctsuccess').html("Thank you for contacting us!").slideDown("slow");
                $("#cname, #cemail, #ccontact").each(function (i) {
                    this.value = this.defaultValue
                })
				$("#csendcopy").attr('checked', false);
            } else {
                alert(data.response)
            }
        }, "json");
        return false
    });

	$("#shareform").submit(function () {
		$("#scname, #scfromemail, #sctoemail, #sccontact").css("border", "1px solid #B7B7B8");
        $("#scname, #scfromemail, #sctoemail, #sccontact").each(function () {
            if (this.value == this.defaultValue) {
                $(this).css("border", "1px solid red").focus();
                return false
            }
        });
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        var email = $("#scfromemail").val();
        if (!pattern.test(email)) {
            $("#scfromemail").css("border", "1px solid red").focus();
            return false
        }
		var email = $("#sctoemail").val();
        if (!pattern.test(email)) {
            $("#sctoemail").css("border", "1px solid red").focus();
            return false
        }
		var sendcopy = "no";
		if ($("#sharecheck").is(':checked')){sendcopy = "yes"}
        $.post("http://icorr.com/wp-content/themes/icorr/ajax.share.php", {
            "scname": $("#scname").val(),
            "scfromemail": $("#scfromemail").val(),
            "sctoemail": $("#sctoemail").val(),
            "sccontact": $("#sccontact").val(),
            "scpropid": $("#scpropid").val(),
			"sccopy": sendcopy
        }, function (data) {
            if (data.response == "Thank You") {
                $("#scresponse").addClass('ctsuccess').html("Thank you for sharing this property!").slideDown("slow");
                $("#scname, #scfromemail, #sctoemail, #sccontact").each(function (i) {
                    this.value = this.defaultValue
                })
				$("#sccopy").attr('checked', false);
            } else {
                alert(data.response)
            }
        }, "json");
        return false
    });
	$(".deleter").click(function() {	
		var answer = confirm ("Are you sure you want to delete this item?");
		if (!answer)
			return false;
	});
	
});
