﻿// JScript File
var sessionSvc = {

    rootUrl: "",

    callService: function (url) {
        var head = document.getElementsByTagName("head")[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = this.rootUrl != "" ? (this.rootUrl + url) : url;
        head.appendChild(script);
    },

    getLead: function (userID, callback) {
        this.callService("/Services/SessionService.ashx/getLead?jsonp=" + callback + "&userID=" + userID);
    },

    getLeadByID: function (userID, leadID, callback) {
        this.callService("/Services/SessionService.ashx/getLeadByID?jsonp=" + callback + "&userID=" + userID +
			"&leadID=" + leadID);
    },

    login: function (userID, email, password, callback) {
        this.callService("/Services/SessionService.ashx/login?jsonp=" + callback + "&userID=" + userID +
			"&email=" + this.urlEncode(email) + "&password=" + this.urlEncode(password));
        popUp.loginIframe(userID, email, password);
    },

    logout: function (userID, callback) {
        this.callService("/Services/SessionService.ashx/logout?jsonp=" + callback + "&userID=" + userID);
        popUp.logoutIframe(userID);
    },

    forgotPassword: function (userID, email, callback) {
        this.callService("/Services/SessionService.ashx/forgotPassword?jsonp=" + callback + "&userID=" + userID +
			"&email=" + email);
    },

    signUp: function (sid, rid, segmentid, firstName, lastName, email, password, phone, citiesOfInterest,
		mlsTable, mlsNum, callback) {
        this.callService("/Services/SessionService.ashx/signUp?jsonp=" + callback + "&rid=" + rid + "&sid=" + sid +
			"&segmentid=" + segmentid + "&firstName=" + firstName + "&lastName=" + lastName + "&email=" + email +
			"&password=" + password + "&phone=" + phone + "&citiesOfInterest=" + citiesOfInterest + "&mlsTable=" +
			mlsTable + "&mlsNum=" + mlsNum);
    },

    urlEncode: function (str) {
        return escape(str).replace("/", "%2F").replace("+", "%2B").replace("#", "%23");
    }

}
