function validatePostBasic() {
    var myName = 			$("#postyourownform input#invoice_name").val();
    var myEmailAddress =	$("#postyourownform input#invoice_email").val();
    var myContactName = 	$("#postyourownform input#contact_name").val();
    var myContactPhone = 	$("#postyourownform input#contact_phone").val();
    var myContactEmail = 	$("#postyourownform input#contact_email").val();
    //var myLocation       =	$("#location option:selected").val();
    var myLocation       =  $('[name=location] option:selected').text();
    var myLocalarea = 	    $("#locationDetailPost option:selected").val();
    var myStreet = 		    $("#postyourownform input#street").val();
    var myPostcode = 		$("#postyourownform input#postcode").val();
    var myType = 		    $("#type option:selected").val();
    var myBedrooms = 		$("#bedrooms option:selected").val(); 
    //var myPrice = 		    $("#price option:selected").val();
    var myPriceDrop =       $('[name=price_modifier] option:selected').text();  
    var myPrice =           $("#postyourownform input#price").val();  
    var myDescription = 	$("#postyourownform textarea#property_description").val();

    if ( (myName == "") || (myEmailAddress == "") || ( myContactName == "") ||  (myLocation == "Any" || myLocalarea==""  ) || (myStreet == "") || (myPostcode == "") || (myType == "") || (myBedrooms == "") || (myBedrooms == "") ||  (myPrice == "") ||  (myDescription == "") ) {

        if (myName == "") {
            $("#post_premier_ul .invoice_name").show();
            $("#post_premier_ul .invoice_name span").show();
        } else{
            $("#post_premier_ul .invoice_name").hide();
            $("#post_premier_ul .invoice_name span").hide();
        }

        if (myEmailAddress == "") {
            $("#post_premier_ul .invoice_email").show();
            $("#post_premier_ul .invoice_email span").show();
        } else {
            $("#post_premier_ul .invoice_email").hide();
            $("#post_premier_ul .invoice_email span").hide();
        }

        if (myContactName == "") {
            $("#post_premier_ul .contact_name").show();
            $("#post_premier_ul .contact_name span").show();
        } else {
            $("#post_premier_ul .contact_name").hide();
            $("#post_premier_ul .contact_name span").hide();
        }

        if ((myContactPhone == "") && (myContactEmail == "")) {
            $("#post_premier_ul .contact_phone").show();
            $("#post_premier_ul .contact_phone span").show();
            //$("#post_premier_ul .contact_phone span").text("Phone or email required");

            $("#post_premier_ul .contact_email").show();
            $("#post_premier_ul .contact_email span").show();
            //$("#post_premier_ul .contact_email span").text("Phone or email required");
        } else {
            $("#post_premier_ul .contact_phone").hide();
            $("#post_premier_ul .contact_phone span").hide();
            $("#post_premier_ul .contact_email").hide();
            $("#post_premier_ul .contact_email span").hide();
        }

        if (myLocation == "Any") {
            $(".location").show();
            $(".location span").show();
            $('#post_premier_ul .location span').css('font-weight','bold');
            returnVal = 'false';
        } else {
            $("#post_premier_ul .location").hide();
            $("#post_premier_ul .location span").hide();
        }

        if (myLocalarea == "") {
            $("#post_premier_ul .location").show();
            $("#post_premier_ul .location span").show();
            $('#post_premier_ul .location span').css('font-weight','bold');
            returnVal = 'false';
        } else {
            if (myLocation != "Any") {
                $("#post_premier_ul .location").hide();
                $("#post_premier_ul .location span").hide();
            } 
        }

        if (myStreet == "") {
            $("#post_premier_ul .street").show();
            $("#post_premier_ul .street span").show();
        } else {
            $("#post_premier_ul .street").hide();
            $("#post_premier_ul .street span").hide();
        }

        if (myPostcode == "") {
            $("#post_premier_ul .postcode").show();
            $("#post_premier_ul .postcode span").show();
        } else {
            $("#post_premier_ul .postcode").hide();
            $("#post_premier_ul .postcode span").hide();
        }

        if (myType == "") {
            $("#post_premier_ul .type").show();
            $("#post_premier_ul .type span").show();
        } else {
            $("#post_premier_ul .type").hide();
            $("#post_premier_ul .type span").hide();
        }

        if (myBedrooms == "") {
            $("#post_premier_ul .bedrooms").show();
            $("#post_premier_ul .bedrooms span").show();
        } else {
            $("#post_premier_ul .bedrooms").hide();
            $("#post_premier_ul .bedrooms span").hide();
        }

        if (myPrice == "") {
            $("#post_premier_ul .price").show();
            $("#post_premier_ul .price span").show();
        } else {
            $("#post_premier_ul .price").hide();
            $("#post_premier_ul .price span").hide();
        }

        if (myDescription == "") {
            $("#post_premier_ul .property_description").show();
            $("#post_premier_ul .property_description span").show();
        } else {
            $("#post_premier_ul .property_description").hide();
            $("#post_premier_ul .property_description span").hide();
        }
       
        $("#postahome_errors").show();
        $('html, body').animate({ scrollTop: $('#postahome_errors').offset().top }, 'slow');
        return false;
    } else {
        $("#loading-images").fadeIn();
        return true;
    }
}

function status_change() {
    if ($("#select_status")) {
        var orig_status         = $("#prop_status");
        var select_status       = $("#select_status");
        var property_status     = $("#property-status");
        var closing_date        = $("#closing-date");
        var closing_date_inputs = $("#closing-date-inputs");
        var under_offer         = $("#under-offer");
        var for_sale            = $("#for-sale");
    }

    if (select_status) {
        if (select_status.val() == orig_status.val()) {
            closing_date.css("display", "none");
            closing_date_inputs.css("display", "none");
            under_offer.css("display", "none");
            for_sale.css("display", "none");
            property_status.css("display", "none");
        } else {
            if (select_status.val() == "closing_date_set") {
                property_status.css("display", "block");
                closing_date.css("display", "block");
                closing_date_inputs.css("display", "block");
                under_offer.css("display", "none");
                for_sale.css("display", "none");
            } else if (select_status.val() == "for_sale") {
                property_status.css("display", "block");
                closing_date.css("display", "none");
                closing_date_inputs.css("display", "none");
                under_offer.css("display", "none");
                for_sale.css("display", "block");
            } else {
                property_status.css("display", "block");
                closing_date.css("display", "none");
                closing_date_inputs.css("display", "none");
                under_offer.css("display", "block");
                for_sale.css("display", "none");
            }
        }
    }
}

function validatePostPremier() {
    var isLoggedIn =        $("#postyourownform input#login").val();
    var myName =            $("#postyourownform input#invoice_name").val();
    var myEmailAddress =    $("#postyourownform input#invoice_email").val();
    var myContactName =     $("#postyourownform input#contact_name").val();
    var myContactPhone =    $("#postyourownform input#contact_phone").val();
    var myContactEmail =    $("#postyourownform input#contact_email").val();
    //  var myLocation       =  $("#postyourownform #location").val() || $("#location option:selected").val();
    var myLocation       =  $('[name=location] option:selected').text();
    var myLocalarea =       $("#postyourownform input#locationDetailPost").val() || $("#locationDetailPost option:selected").val();
    var myStreet =          $("#postyourownform input#street").val();
    var myPostcode =        $("#postyourownform input#postcode").val();
    var myType =            $("#type option:selected").val(); 
    var myBedrooms =        $("#bedrooms option:selected").val(); 
    //var myPrice =           $("#price option:selected").val();
    var myPriceDrop =       $('[name=price_modifier] option:selected').text();  
    var myPrice =           $("#postyourownform input#price").val();   
    var myDescription =     $("#postyourownform textarea#property_description").val();

    if ( (isLoggedIn == 0) || (myName == "") || (myEmailAddress == "") || ( myContactName == "") || (myContactPhone == "" && myContactEmail == "") || (myLocation == "Any" || myLocalarea==""  ) || (myStreet == "") || (myPostcode == "") || (myType == "") || (myBedrooms == "") || (myBedrooms == "") ||  (myPrice == "") ||  (myDescription == "") )
    {
        returnVal = 1;
        if(isLoggedIn == 0) {
            myPassword1 = $("#postyourownformpassword input#password").val();
            myPassword2 = $("#postyourownformpassword input#password2").val();
            if (myPassword1 == "" || myPassword2 =="") {
                var pMessesage = "";
                if (myPassword1 == ""){ pMessage = "Password one is empty"; }
                if (myPassword2 == "" ){ pMessage = "Password two is empty"; }
                if (myPassword1 == "" && myPassword2 == ""  ){ pMessage = "Both passwords are empty"; }
                $("#post_premier_ul .password_fail").show();
                $("#post_premier_ul .password_fail span").text(pMessage);
                $("#post_premier_ul .password_fail span").show();
                $("#postahome_errors").show();
                returnVal = 'false';
            } else {
                $("#post_premier_ul .password_fail").hide();
                $("#post_premier_ul .password_fail span").hide();
            }

            if (myPassword1 !== myPassword2) {
                $("#post_premier_ul .password_mismatch").show();
                $("#post_premier_ul .password_mismatch span").show();
                $("#postahome_errors").show();
                returnVal = 'false';
            } else {
                $("#post_premier_ul .password_mismatch").show();
                $("#post_premier_ul .password_mismatch span").show();
            }
        }

        if (myName == "") {
            $("#post_premier_ul .invoice_name").show();
            $("#post_premier_ul .invoice_name span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .invoice_name").hide();
            $("#post_premier_ul .invoice_name span").hide();
        }
        if (myEmailAddress == "")
        {
            $("#post_premier_ul .invoice_email").show();
            $("#post_premier_ul .invoice_email span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .invoice_email").hide();
            $("#post_premier_ul .invoice_email span").hide();
        }
        if (myContactName == "" )
        {
            $("#post_premier_ul .contact_name").show();
            $("#post_premier_ul .contact_name span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .contact_name").hide();
            $("#post_premier_ul .contact_name span").hide();
        }
        if (myContactPhone == "" && myContactEmail == "")
        {
            $("#post_premier_ul .contact_phone").show();
            $("#post_premier_ul .contact_phone span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .contact_phone").hide();
            $("#post_premier_ul .contact_phone span").hide();
        }
        if (myLocation == "Any")
        {
            $("#post_premier_ul .location").show();
            $("#post_premier_ul .location span").show();
            $('#post_premier_ul .location span').css('font-weight','bold');
            returnVal = 'false';
        }else{
            $("#post_premier_ul .location").hide();
            $("#post_premier_ul .location span").hide();
        }
        if (myLocalarea == "")
        {
            $("#post_premier_ul .location").show();
            $("#post_premier_ul .location span").show();
            $('#post_premier_ul .location span').css('font-weight','bold');
            returnVal = 'false';
        }else{
            if (myLocation != "Any") {
                $("#post_premier_ul .location").hide();
                $("#post_premier_ul .location span").hide();
            } 
        }
        if (myStreet == "")
        {
            $("#post_premier_ul .street").show();
            $("#post_premier_ul .street span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .street").hide();
            $("#post_premier_ul .street span").hide();
        }
        if (myPostcode == "")
        {
            $("#post_premier_ul .postcode").show();
            $("#post_premier_ul .postcode span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .postcode").hide();
            $("#post_premier_ul .postcode span").hide();
        }
        if (myType == "")
        {
            $("#post_premier_ul .type").show();
            $("#post_premier_ul .type span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .type").hide();
            $("#post_premier_ul .type span").hide();
        }
        if (myBedrooms == "")
        {
            $("#post_premier_ul .bedrooms").show();
            $("#post_premier_ul .bedrooms span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .bedrooms").hide();
            $("#post_premier_ul .bedrooms span").hide();
        }
        if (myPrice == "")
        {
            $("#post_premier_ul .price").show();
            $("#post_premier_ul .price span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .price").hide();
            $("#post_premier_ul .price span").hide();
        }
        if (myDescription == "")
        {
            $("#post_premier_ul .property_description").show();
            $("#post_premier_ul .property_description span").show();
            returnVal = 'false';
        }else{
            $("#post_premier_ul .property_description").hide();
            $("#post_premier_ul .property_description span").hide();
        } 

        if (returnVal =='false'){
            $("#postahome_errors").show();
            $('html, body').animate({ scrollTop: $('#postahome_errors').offset().top }, 'slow');
            return false;
        }
    } else {
        $("#loading-images").fadeIn();
        return true;
    }
}

function modifyProperty (misc) {

    if (misc == 'extend') {
        if (document.form1.chose_duration) {
            document.location.href = "post-your-own.html?extend=1&prop_id=" + document.form1.prop_id.value + "&chose_duration=" + document.form1.chose_duration.value;
        } else {
            document.location.href = "post-your-own.html?extend=1&prop_id=" + document.form1.prop_id.value;
        }
    } else {
        document.location.href = "post-your-own.html?prop_id=" + document.form1.prop_id.value;
    }
}

function sendEmail (cphone, cemail, iemail, iname) {
    if ( window.ActiveXObject ) // if it's ie
    {
        xmlObjPostahome = new ActiveXObject("Microsoft.XMLHTTP"); // xmlObjPostahome is global
        xmlObjPostahome.onreadystatechange = function ()
        {
            if(xmlObjPostahome.readyState == 4) process(xmlObjPostahome.responseText);
        };
    }
    else
    {
        if (window.XMLHttpRequest) // if it's firefox etc.
        {
            xmlObjPostahome        = new XMLHttpRequest() // xmlObjPostahome is global
                xmlObjPostahome.onload = function () { process(xmlObjPostahome.responseText) };
        }
        else return; //
    }


    //var url = "http://" + document.location.hostname + "/post/send_premium_number_alert.cgi";
    var url = "/post/send_premium_number_alert.cgi";
    var params = "cphone=" + cphone + '&cemail=' + cemail + '&iemail=' + iemail + '&iname=' + iname;
    xmlObjPostahome.open("POST", url, true);
    //Send the proper header information along with the request
    xmlObjPostahome.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlObjPostahome.setRequestHeader("Content-length", params.length);
    xmlObjPostahome.setRequestHeader("Connection", "close");
    xmlObjPostahome.send(params);
}

function process() {
    //dont need to do anything here
}


function getOtherLocationAreas () {
    if ( window.ActiveXObject ) // if it's ie
    {
        xmlObjPostahome = new ActiveXObject("Microsoft.XMLHTTP"); // xmlObjPostahome is global
        xmlObjPostahome.onreadystatechange = function ()
        {
            if(xmlObjPostahome.readyState == 4) writecontentPostOwn(xmlObjPostahome.responseText, 'locationSelect');
        };
    } else {
        if (window.XMLHttpRequest) // if it's firefox etc.
        {
            xmlObjPostahome        = new XMLHttpRequest() // xmlObjPostahome is global
                xmlObjPostahome.onload = function () { writecontentPostOwn(xmlObjPostahome.responseText, 'locationSelect') };
        }
        else return; //
    }

    if (document.postyourownform && (document.postyourownform.loggedin || document.postyourownform.password)) {
        if (!document.postyourownform.password) {
            alert('Please enter your password');
        }
    }

    var locationid="";
    if(document.postyourownform && document.postyourownform.location && document.postyourownform.location.options) {
        var locationid = document.postyourownform.location.options[document.postyourownform.location.selectedIndex].value;
        var localareaid = document.postyourownform.localareaid.value;
    }

    var targ = document.getElementById('locationHeader').style.display = 'block';
    //	var targ = $("#locationHeader").text("Local area");

    if (locationid.match(/[0-9]/)) {
        //var url = "http://" + document.location.hostname + "/post/get_local_locations.cgi?locationid=" + locationid + '&localarea=' + localareaid;
        var url = "/post/get_local_locations.cgi?locationid=" + locationid + '&localarea=' + localareaid;
        xmlObjPostahome.open("GET", url , true);
        xmlObjPostahome.send(null);
    } else {   
        //document.getElementById('locationHeader').style.display = 'none';
        //$("#locationHeader").text("Local area");
    }
}

function writecontentPostOwn (contentPostOwn, targetDiv) {
    var targDivId = document.getElementById(targetDiv);
    if (targDivId) {
        targDivId.innerHTML = contentPostOwn;
    }
}

