﻿/*
	Common Scripts
	-----------------------
*/

//browser detection
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1 && strUserAgent.indexOf("msie 9") == -1;

/* Key Press */
function keypressmanager(objEvent, func) {

    var iKeyCode, strKey;

    if (isIE) {
        iKeyCode = objEvent.keyCode;
    }
    else {
        iKeyCode = objEvent.which; 
    }

    if (iKeyCode == 13) {
        eval(func);
        return false;
    }
    
    return true;
}

/* Perform property search */
function searchproperties() {
    var slet = 0;
    if (document.getElementById("cbxlet").checked) {
        slet = 1;
    }
    window.location.href = "/property-list.aspx?location=" + document.getElementById("ddlLocation").value + "&minprice=" + document.getElementById("ddlMinPrice").value + "&maxprice=" + document.getElementById("ddlMaxPrice").value + "&minbeds=" + document.getElementById("ddlMinBeds").value + "&order=" + document.getElementById("ddlOrder").value + "&let=" + slet;
    return false;
}


/*
Strings
*/

if (!String.prototype.endswith) {
    String.prototype.endswith = function(suffix) {
        var startPos = this.length - suffix.length;
        if (startPos < 0) {
            return false;
        }
        return (this.lastIndexOf(suffix, startPos) == startPos);
    };
}
// Starts With
if (!String.prototype.startswith) {
    String.prototype.startswith = function(prefix) {
        return (this.indexOf(prefix) == 0);
    };
}
// Contains
if (!String.prototype.contains) {
    String.prototype.contains = function(content) {
        return (this.indexOf(content) > -1);
    };
}

// TrimEnd
if (!String.prototype.trimend) {
    String.prototype.trimend = function(content) {
        if (this.endswith(content)) {
            return (this.substring(0, this.length - content.length));
        }
        else {
            return (this);
        }
    };
}


