if (DHL == undefined) var DHL = {};
if (DHL.SITE == undefined) DHL.SITE = {};
DHL.SITE.FMS_SHOWREGISTRATION = function (intModelId, strShowType) {
	this.intModelId = intModelId;
	this.strShowType = strShowType;
	this.objHttpRequest = new DHL.NET.HTTPREQUEST();
	this.blnSending = false;
	this.ptGoPrivateCallBack = null;
	this.intLastException = 0;
	this.blnSendPrivate = false;
	this.blnShowMessage = true;
	this.strMessage = "";
	this.intRandomCheck = 0;
	this.strMessage = "";
	this.strTitle = "";
	this.strRegisterUrl = "";
}

var PUBLIC = DHL.SITE.FMS_SHOWREGISTRATION.prototype;
var PRIVATE = DHL.SITE.FMS_SHOWREGISTRATION.prototype;

DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_NOEXCEPTION = 0;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_ALREADYINPRIVATE = 1;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_INFEATURE = 2;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_REQUIREAPRIVATE = 3;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_NOTENOUGHFUND = 4;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_INBREAK = 5;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_CNMODEL_OFFLINE = 6;
DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_REQUIRE_USER = 7;

PUBLIC.setPrivateUrl = function(strUrl) {
	this.strRegisterUrl = strUrl;
}

PUBLIC.setPrivateCallback = function(ptFunction) {
	this.ptGoPrivateCallBack = ptFunction;
}

PUBLIC.registerShow = function() {
	if(!this.blnSending && 
		this.intModelId > 0 && 
		this.strShowType != ""
	) {
		if(this.strRegisterUrl) {
			var objUrl = new DHL.NET.URL(this.strRegisterUrl);
		}
		else {
			var objUrl = new DHL.NET.URL.getCurrent();
		}
		objUrl.setPath('/shared/template/private/register_show.htm');
		var strAttributes = "modelId=" + this.intModelId + "&type=" + this.strShowType;
		this.objHttpRequest.open('POST', objUrl, true);
		this.objHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.objHttpRequest.setRequestHeader('Content-length', strAttributes.length);
		this.objHttpRequest.setRequestHeader('Connection', 'close');
		
		var me = this;
		this.objHttpRequest.onreadystatechange(function(){
			me.registerShowResponse();
		});

		this.objHttpRequest.send(strAttributes);
		this.blnSending = true;
	}
}

PUBLIC.getShowType = function() {
	return this.strShowType;
}
PUBLIC.setShowType = function(strShowType) {
	this.strShowType = strShowType; 
}

PUBLIC.getLastException = function() {
	return this.intLastException;
}

PUBLIC.isSendPrivate = function() {
	return this.blnSendPrivate;
}
PUBLIC.isShowMessage = function() {
	return this.blnShowMessage;
}
PUBLIC.getMessage = function() {
	return this.strMessage;
}

PUBLIC.getTitle = function() {
	return this.strTitle;
}

PUBLIC.getRandomCheck = function() {
	return this.intRandomCheck;
}

PUBLIC.getModelId = function() {
	return this.intModelId;
}

PRIVATE.registerShowResponse = function() {
	if(this.objHttpRequest.getReadyState() == 4) {
		//response has been received
		this.blnSending = false;
		if(
			this.objHttpRequest.getStatus() == 200
		) {
			eval("var arrReturn = " + this.objHttpRequest.getResponseText());
			this.blnSendPrivate = arrReturn['blnSendPrivate'];
			this.blnShowMessage = arrReturn['blnShowMessage'];
			this.intRandomCheck = arrReturn["intRandomCheck"];
			if(this.blnSendPrivate) {
				this.strTitle = "You are entering a <span id=\"registerShowShowType\">" + arrReturn["strShowType"] + " show</span>";
				this.strMessage = " with <span id=\"registerShowNickname\">" + arrReturn["strNickname"] + "</span> " + arrReturn["strPrice"];
			}
			//normalize exception
			switch(arrReturn['strExceptionClassName']) {
				case 'DHL_EXP_FMS_FPS_SHOW_PRIVATE_ALREADY_EXISTS':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_ALREADYINPRIVATE;
				break;
				case 'DHL_EXP_FMS_FPS_SHOW_MODEL_IN_FEATURED':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_INFEATURE;
				break;
				case 'SHD_EXP_SHOWCONTEXT_REQUIREPRIVATESHOW':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_REQUIREAPRIVATE;
				break;
				case 'DHL_EXP_FMS_FPS_SHOW_NOT_ENOUGH_CREDIT':
					this.strTitle = "Sorry, <span id=\"messageEmphaz\">more funds</span> are required.";
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_NOTENOUGHFUND;
				break;
				case 'DHL_EXP_FMS_FPS_SHOW_SESSION_INBREAK':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_INBREAK;
					this.strTitle = "Sorry, this model is currently on break.";
				break;
				case 'DHL_EXP_FMS_FPS_SHOW_MODEL_IN_FPS':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_REQUIREAPRIVATE;
				break;
				case 'DHL_FMS_CNMODEL_OFFLINE':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_CNMODEL_OFFLINE;
					this.strTitle = "Sorry, this model is currently offline.";
				break;
				case 'DHL_FMS_FMS_SHOW_REQUIREUSER':
					this.intLastException = DHL.SITE.FMS_SHOWREGISTRATION.EXCEPTION_REQUIRE_USER;
					this.strTitle = "<span id=\"messageEmphaz\">Login or Signup</span> to access the show.";
				break;
			}
			this.ptGoPrivateCallBack(this);
		}
	}
}