﻿/********************************************/
/*             AJAX RESPONSES               */
/********************************************/
var RESPONSE_SUCCESS = "SUCCESS";
var RESPONSE_FAILURE = "FAILURE";
var RESPONSE_WARNING = "WARNING";
var RESPONSE_SUCCESS_W_MESSAGE = "SUCCESS_W_MESSAGE";
var RESPONSE_NO_AUTH = "NOAUTH";
var RESPONSE_MUST_REGISTER = "MUSTREGISTER";
var RESPONSE_NODATA = "NODATA";

/********************************************/
/*              ENTITY TYPES                */
/********************************************/
var SC_REGION = "SC_REGION";
var SC_CITY = "SC_CITY";
var SC_TOPIC = "SC_TOPIC";
var SC_ITINERARY = "SC_ITINERARY";
var SC_TRAVEL = "SC_TRAVEL";
var SC_OTHER = "SC_OTHER";
var SMI_LISTING = "SMI_LISTING";
var SMI_SEEANDDO = "SMI_SEEANDDO";
var SMI_EVENT = "SMI_EVENT";
var SMI_EAT = "SMI_EAT";
var SMI_STAY = "SMI_STAY";
var SMI_DEAL = "SMI_DEAL";
var SMI_OTHER = "SMI_OTHER";
var SMI_TRANSPORTATION = "SMI_TRANSPORTATION";
var SMI_LOCRESOURCES = "SMI_LOCRESOURCES";

/********************************************/
/*             LISTING TYPES                */
/********************************************/
var LT_EVENTS = "EVENTS";
var LT_FACILITIES = "FACILITIES";
var LT_DEALS = "DEALS";
var LT_CMS = "CMS";
var LT_OTHER = "OTHER";

/********************************************/
/*          PRICE FILTER PRICES             */
/********************************************/
var LISTINGPRICE=0;
var STAYPRICE = 0;
var EATPRICE = 0;

function SetProgressBar(divToChange) {

    // Get the animated loading image
    var progressHtml = $('#pageProgressBar').html();
    $('#' + divToChange).html(progressHtml);
}

function ResetResultHover() {

    $(".stayResults").hoverIntent({
        sensitivity: 7,
        interval: 100,
        over: featureOn,
        timeout: 0,
        out: featureOff
    }).each(function() {
        if ($(this).children('a.stayResultsImage').children('img').length) {
            $(this).children('a.stayResultsImage').css('display', 'block').css('float', 'left').css('margin-right', '10px');
            $(this).addClass("stayResultsWithImage");
            if ($(this).children('.bubble').length) {
                $(this).children('.stayResultsContainer').css('width', '245px');
                $(this).children('.stayResultsContainer').children('.stayResultsName').css('width', '245px');
            }
        }
    });
}

function IsNull(object) {

    return object == null
}

function IsNullOrEmpty(value) {
    var isNullOrEmpty = true;
    if (value) {
        if (typeof (value) == 'string') {
            if (value.length > 0)
                isNullOrEmpty = false;
        }
    }
    return isNullOrEmpty;
}

String.IsNullOrEmpty = function(value) {
    var isNullOrEmpty = true;
    if (value) {
        if (typeof (value) == 'string') {
            if (value.length > 0)
                isNullOrEmpty = false;
        }
    }
    return isNullOrEmpty;
}

function Trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function Ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/, "");
}
function Rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/, "");
}


/**
* Delay for a number of milliseconds
*/
function SleepScript(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

/********************************************/
/*            JQUERY EXTENSIONS             */
/********************************************/

/**
* YOU ARE FREE TO USE THIS CODE IF YOU HOLD THE REFERENCE TO THE AUTHOR
* Plugin for jQuery that delimites the maximum of characteres in inputs and textareas
* @author: Iván Guardado Castro
* @email: dev.ivangc@gmail.com
* @website: http://yensdesign.com/
*/
jQuery.fn.maxLength = function(max) {
    this.each(function() {
        //Get the type of the matched element
        var type = this.tagName.toLowerCase();
        //If the type property exists, save it in lower case
        var inputType = this.type ? this.type.toLowerCase() : null;
        //Check if is a input type=text OR type=password
        if (type == "input" && inputType == "text" || inputType == "password") {
            //Apply the standard maxLength
            this.maxLength = max;
        }
        //Check if the element is a textarea
        else if (type == "textarea") {
            //Add the key press event
            this.onkeypress = function(e) {
                //Get the event object (for IE)
                var ob = e || event;
                //Get the code of key pressed
                var keyCode = ob.keyCode;
                //Check if it has a selected text
                var hasSelection = document.selection ? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
                //return false if can't write more
                return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
            };
            //Add the key up event
            this.onkeyup = function() {
                //If the keypress fail and allow write more text that required, this event will remove it 
                if (this.value.length > max) {
                    this.value = this.value.substring(0, max);
                }
            };
        }
    });
};
