

if (!this['osrp']) {
	osrp = {};
}

if (!osrp.sbn) {
	osrp.sbn = {};
}

osrp.sbn = function() { 
	var _PROTOCOL = "http";
	var _HTTPPORT = "80";
	var _DOMAIN = "www.pcmallsbn.com";		
	var _APPHOME = "";
	var _JSHOME = _APPHOME + "/js";
	var _JS_SBN_HOME = _JSHOME + "/sbn";
	var _CONF = {};
	
	var _RID = "05C5973E9E2D02924CF2BBE792629815";
	
	jQAlertLoaded = false;
	jQConfirmLoaded = false;
	
	/***# common dialog message box start ***/
	jQuery(document).ready(function() {
		jQuery("BODY").append(
		  '<div id="jQAlert05C5973E9E2D02924CF2BBE792629815" title="SBN Alert Box" class="hidden">' +
		    '<span id="jQAlertMsg05C5973E9E2D02924CF2BBE792629815" class="farial fsize14"> </span>' +
		  '</div>')
		  .append(
		  '<div id="jQConfirm05C5973E9E2D02924CF2BBE792629815" title="SBN Confirmation Box" class="hidden">' +
		    '<span id="jQConfirmMsg05C5973E9E2D02924CF2BBE792629815" class="farial fsize14"> </span>' +
		  '</div>');		
		});
	/***# common dialog message box end ***/  
	  
	
	jQuery.ajax({
			type: "GET",
			contentType: "application/json; charset=utf-8",
			/** cache: false, **/
			url: _JS_SBN_HOME + "/config.json?r="+_RID,
			success: function(data) { 
				_CONF = data;
			},
			dataType: "json",			
			async: false			
		});
	
return {
	isHTTPS: function() {
		return (_PROTOCOL === "https");
	},
	redirect: function(url) {
		var _url = "";
		
		if (url === undefined || url === null || typeof(url) == 'undefined') {
			url = {};
		}
		
		if (url.protocol != undefined && url.protocol != null) {
			_url += url.protocol + "://";
		} else {
			_url += _PROTOCOL + "://";
		}
		
		if (url.domain != undefined && url.domain != null) {
			_url += url.domain;
		} else {
			_url += _DOMAIN;
		}
		
		if (url.port !== "80" && url.port != 80 && url.port !== "443" && url.port != 443) {
			if (url.port != undefined && url.port != null) {
				_url += ":" + url.port;
			} else if (_HTTPPORT !== "80" && _HTTPPORT != 80 && _PROTOCOL !== "https") {
				_url += ":" + _HTTPPORT;
			}
		}
		
		if (url.baseApp != undefined && url.baseApp != null) {
			_url += url.baseApp;
		} else {
			_url += _APPHOME;
		}
		
		if (url.pagePath != undefined && url.pagePath != null) {
			_url += url.pagePath;
		}		
		
		if (url.topWindow != undefined && url.topWindow != null && url.topWindow) {
			window.top.location.replace( _url );
		} else {
			window.location.replace( _url );
		}	
	},
	domainUrl:  _PROTOCOL + "://" + _DOMAIN + ":" + _HTTPPORT + _APPHOME
	,
	jsHome: _JS_SBN_HOME
	,
	getLibLoc: function(type, id) {
		var _id = _CONF[type][id];
		if (!_id || typeof(_id) == 'undefined') {
			alert("Please check if "+id+" is correctly configured in js registry.");
			return false;
		}
		var loc = _CONF[type][id].loc;
		return _APPHOME + "/" +loc; 
	},
	jQAlert: function(winTitle, winMessage) {
		jQuery(document).ready(function () {
			if (!jQAlertLoaded) {
				jQuery("#jQAlert05C5973E9E2D02924CF2BBE792629815").dialog({ autoOpen: false, modal: true, bgiframe: true, resizable: false});
				jQAlertLoaded = true;
			}
		});
		
		jQuery("#ui-dialog-title-jQAlert05C5973E9E2D02924CF2BBE792629815").addClass('fsize14');
		jQuery(".ui-dialog-buttonpane button").css({'font-size': '12px'});  		
		jQuery("#jQAlert05C5973E9E2D02924CF2BBE792629815").dialog('option', 'title', winTitle);
		jQuery("#jQAlert05C5973E9E2D02924CF2BBE792629815 #jQAlertMsg05C5973E9E2D02924CF2BBE792629815").html(winMessage);
		jQuery("#jQAlert05C5973E9E2D02924CF2BBE792629815").dialog("open");
	}
	,
	jQConfirm: function(winTitle, winMessage, btns) {
		jQuery(document).ready(function () {
			if (!jQConfirmLoaded) {
				jQuery("#jQConfirm05C5973E9E2D02924CF2BBE792629815").dialog({ autoOpen: false, modal: true, bgiframe: true, resizable: false});
				jQConfirmLoaded = true;
			}
		});
		
		jQuery("#ui-dialog-title-jQConfirm05C5973E9E2D02924CF2BBE792629815").addClass('fsize14');
		jQuery(".ui-dialog-buttonpane button").css({'font-size': '12px'});  		
		jQuery("#jQConfirm05C5973E9E2D02924CF2BBE792629815").dialog('option', {'title': winTitle, 'buttons': btns});
		jQuery("#jQConfirm05C5973E9E2D02924CF2BBE792629815 #jQConfirmMsg05C5973E9E2D02924CF2BBE792629815").html(winMessage);
		jQuery("#jQConfirm05C5973E9E2D02924CF2BBE792629815").dialog("open");
	}
	,
	onReady: function(module) {
		var csses = [];
		var jses = [];
		
		if (null === module || null === module.name 
			|| typeof(module.exec) !== 'function'
			|| typeof(module.name) == 'undefined'
			|| typeof(module.exec) == 'undefined') {
			alert("Invalid Module Arguments. Script module execution failed.");
			return false;
		}		
		
		if (!jQuery.isArray(module.js)) {
			alert("Invalid Javascript Module Argument. Script module execution failed.");
			return false;
		}
		
		if (!jQuery.isArray(module.css)) {
			alert("Invalid CSS Module Argument. Script module execution failed.");
			return false;
		}		
		
		var rid = new Date().getTime(); 
		var refreshr = "";
		
		/**
		// hack for safari script cache
		if (jQuery.browser.safari || jQuery.browser.msie) {
			//refreshr = "&r="+rid; 
		}		
		**/
		
		var i = module.js.length;
		var cntr = 0;   		
		while (i--) {	
			jses[cntr] = this.getLibLoc('jsLib', module.js[cntr]) + "?_=" + _RID;
			cntr++;
    	}
		
		i = module.css.length;
		cntr = 0;   		
		while (i--) {	
			csses[cntr] = this.getLibLoc('cssLib', module.css[cntr]) + "?_=" + _RID;
			cntr++;
    	}		
		
		var action = function() {
			var callback = module.exec;
			jQuery(document).ready(function () {
		 		callback();
		 	})
		};
		
		if (!osrp.sbn.modules) {
			osrp.sbn.modules = {};
		}

		if (module.name !== null && typeof(module.name) !== 'undefined') {
			var callback = module.exec;
			osrp.sbn.modules[module.name] = callback;
		}		
		
		if (module.css.length > 0 || module.js.length > 0) {
			var loaderOption = {
				js: jses, 
				css: csses,
				success: action
			};		
			
			jQuery.xLazyLoader( loaderOption );					
		} else {
			jQuery(document).ready(function () {
				var lonerMod = module.exec;
				lonerMod(); 
		 	});
		}		
	}
} // end of return
}();

// define shortcuts
jQAlert = osrp.sbn.jQAlert;
jQConfirm = osrp.sbn.jQConfirm;
jQLogout = function() {
		var url = path+"/ChatWidgetBox/"+"&decorator=blank&confirm=true";
		jQuery.post( url, {action: "chatLoginStatus"}, 
		function(data){
			if (data.chatStatus != 'O') {
				var str = '';
				for (var key in data.connList) {
					var str1 = data.connList[key].id+',';
					str += str1;
	  			}
	  			leaveChatRoom(str);
			}
			osrp.sbn.redirect({domain: window.location.hostname, pagePath: "/Logout?r=" + new Date().getTime() });
		}, "json");
		// logut call
}
// global WYSWYG var
path = "";


