﻿function popUp(u) {

    var winScroll = $(document).scrollTop();
    var winHeight = $(window).height();
    var winWidth = $(window).width();
    var docHeight = $(document).height();
    var docWidth = $(document).width();
    var popWidth = $("#popUp").width();
    
    $("#popUp").css("position", "absolute");
    $("#popUp").css("display", "block");
    $("#popUp").css("top", winScroll + 50);
    $("#popUp").css("left", docWidth/2 - popWidth/2);
    $("#popUp").html(u);

    $.get(u, function(data) {
        $("#popUp").html(data);
    });

}

function closePopup() {
    $("#popUp").css("display", "none");
}

function ltrim(str) {
    for (var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
    return str.substring(k, str.length);
}
function rtrim(str) {
    for (var j = str.length - 1; j >= 0 && isWhitespace(str.charAt(j)); j--);
    return str.substring(0, j + 1);
}
function trim(str) {
    return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
    var whitespaceChars = " \t\n\r\f";
    return (whitespaceChars.indexOf(charToCheck) != -1);
}

function regForm(frm) {
    if (trim(frm.firstname.value) == '') {
        alert("You must enter your first name");
        frm.firstname.focus();
        return false;
    } else if (trim(frm.lastname.value) == '') {
        alert("You must enter your last name");
        frm.lastname.focus();
        return false;
    } else if (trim(frm.email.value) == '') {
        alert("You must enter a valid email address so \n interested parties can contact \n you about your property");
        frm.email.focus();
        return false;
    } else if (trim(frm.password.value) == '') {
        alert("You must enter a password");
        frm.password.focus();
        return false;
    } else if (trim(frm.city.value) == '') {
        alert("You must enter your city");
        frm.city.focus();
        return false;
    } else if (trim(frm.state.value) == '') {
        alert("You must enter your state");
        frm.state.focus();
        return false;
    } else if ((frm.userType.selectedIndex == 1) && (trim(frm.company.value) == '')) {
        alert("You must enter your company name");
        frm.company.focus();
        return false;
    } else {
        return true;
    }
}

function inputForm(frm) {
    if (isNaN(frm.price.value)) {
        alert("Price must be integer format only. ie: 255000");
        frm.price.focus();
        return false
    } else if (isNaN(frm.sqft.value)) {
        alert("SqFt must be integer format only. ie: 1500");
        frm.sqft.focus();
        return false
    } else if (isNaN(frm.sqft.value)) {
        alert("Lot Size must be Number format only. ie: 2.5");
        frm.lotsize.focus();
        return false
    } else if (isNaN(frm.yearbuilt.value)) {
        alert("Year Built must be Integer format only. ie: 1998");
        frm.yearbuilt.focus();
        return false
    } else if (trim(frm.address.value) == '') {
        alert("You must enter the property street address.");
        frm.address.focus();
        return false;
    } else if (trim(frm.city.value) == '') {
        alert("You must select a city using the 'Get List' feature.");
        return false;
    } else if (trim(frm.zip.value) == '') {
        alert("You must enter the property's Zip Code.");
        frm.zip.focus();
        return false;
    } else if (trim(frm.remarks.value) == '') {
        alert("Please supply descriptive remarks for this property.");
        frm.remarks.focus();
        return false;
    } else {
        return true;
    }
}


