$(document).ready(function() {
	$('<input name="checkForm" value="1" type="hidden">').appendTo('#contact-frm');
	$('<input name="checkForm" value="1" type="hidden">').appendTo('#enewsletter-frm');
	$('<input name="checkForm" value="1" type="hidden">').appendTo('#claim-frm');
	$('<input name="checkForm" value="1" type="hidden">').appendTo('#cv-frm');
	$('#gallery a').lightBox();
    if ($('#banner a').size()>1) {
        $('#banner').slideshow({
            timeout: 5000,
            type: 'random'
        });
    }
    $('#more-info-link').click(function() {
        $(this).hide('slow');
        $('#more-info-content').show('slow');
        return false;
    })
     $("input[name=area[]]").change(function() {
        if ($(this).val()) {
            $("#ps-district").html('<option>Loading...</option>');
            var get_arr = [];
            $("input[name=area[]]:checked").each(function() {
                get_arr.push($(this).val())
            });
            $("#ps-district").load('/ajax/property-districts/?area[]='+get_arr.join('&area[]='));
        } else {
            $("#ps-district").html('<option value="all">All Districts</option>');
        }
    });
    $("#contact-frm").submit(function() {
        var validates = true;
        if ($('#name').val().length == 0) {
            validates = false;
        }
        if ($('#telephone').val().length == 0) {
            validates = false;
        }
        if ($('#privacy:checked')===null) {
             validates = false;
        }
        if (!valid_email($('#email').val())) {
            validates = false;
        }
        if (validates===false) {
            alert('Please enter all the required fields marked with a (*) and accept the privacy policy.');
            return false;
        }
    })
    $("#cv-frm").submit(function() {
        var validates = true;
        if ($('#name').val().length == 0) {
            validates = false;
        }
        if ($('#cv').val().length == 0) {            
            validates = false;
        }
        if ($('#privacy:checked')===null) {
             validates = false;
        }
        if (!valid_email($('#email').val())) {
            validates = false;
        }
        if (validates===false) {
            alert('Please enter all the required fields marked with a (*) and accept the privacy policy.');
            return false;
        }
    })
    $("#claim-frm").submit(function() {
        var validates = true;
        if ($('#name').val().length == 0) {
            validates = false;
        }
        if ($('#telephone').val().length == 0) {
            validates = false;
        }
        if ($('#privacy:checked')===null) {
             validates = false;
        }
        if (!valid_email($('#email').val())) {
            validates = false;
        }
        if (validates===false) {
            alert('Please enter all the required fields marked with a (*) and accept the privacy policy.');
            return false;
        }
    })
    $("#enewsletter-frm").submit(function() {
        var validates = true;
        if (!valid_email($('#email').val())) {
            validates = false;
        }
        if (validates===false) {
            alert('Please enter all the required fields marked with a (*) and accept the privacy policy.');
            return false;
        }
    })
});

function valid_email(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(email) == false) {
      return false;
   } else {
       return true;
   }
}
