
if (typeof(CM_WEBCOMPONENT_MODELLIST) == 'undefined') (function() { // #ifndef

CM_WEBCOMPONENT_MODELLIST = function (strName) {
	
	// Properties
	this.strName = strName;
	this.objRsModel = null;
	this.intSelectedNicheId = 0;
	this.intMaxModel = 7;
	this.intNicheId = 0;
	this.intPage = 1;
	this.intMaxPage = 1;
	this.intModelCount = 0;
	this.strSortFieldName = "";
	this.arrOnRegisterEvent = new Array();
	this.arrOnConfirmRegistration = new Array();
	this.arrOnLanguageClick = new Array();
	this.objModelContainer = null;
	this.objModelTemplate = null;
	this.intMinHeight = 0;
	this.intSeekIndex = 0;
	this.arrNicheList = new Array();
	this.objSendDataHttpRequest = new DHL.NET.HTTPREQUEST();
	this.ptCallbackFunction = "";
	this.cnt = 0;
	this.objSendToUrl = null;
	this.intLanguageId = 0;
	this.arrControllCacheEvent = new Array();
	this.arrControllShowEvent = new Array();
	this.arrShowMessageBoxListener = new Array();
	this.arrHideMessageBoxListener = new Array();
	this.objShowRegister = null;
	
	// Params
	this.blnPrivate = false;
	this.blnDisplayOnlineFlag = false;
	this.blnMatchmakerAnswered = false;
	this.blnCanRate = false;
	this.blnSending = false;
	this.blnTopModelOrder = false;
	this.blnForcePrivate = false;
	this.blnSendTo = false;
	this.blnOrderByMatchmaker = false;
	this.blnOrderByRating = false;
	
	// Constants
	this.MODELLIST_PAGESELECTOR_MAIN = 1;
	this.MODELLIST_PAGESELECTOR_TOP = 2;
	
	//this.objBaseRating = null;
	//this.arrRating = new Array();
}

var PUBLIC = CM_WEBCOMPONENT_MODELLIST.prototype;
var PRIVATE = CM_WEBCOMPONENT_MODELLIST.prototype;
var STATIC = CM_WEBCOMPONENT_MODELLIST; 
var SELF = CM_WEBCOMPONENT_MODELLIST; 

PUBLIC.initializePageSelector = function () {
	if (
		document.getElementById("pageNavigationTemplate" + this.strName) && 
		document.getElementById('pageNavigation' + this.strName)
	) {
		this.objPageNavigation = new DHL_PAGENAVIGATION(
			document.getElementById("pageNavigationTemplate" + this.strName),
			document.getElementById('pageNavigation' + this.strName)
		);
		this.objPageNavigation.setVisiblePage(1);
		this.objPageNavigation.setLoop(true);
		var me = this;
		if (
			document.getElementById("pageNavigationTemplate" + this.strName) && 
			document.getElementById('topPageNavigation' + this.strName)
		) {
			this.objTopPageNavigation = new DHL_PAGENAVIGATION(
				document.getElementById("pageNavigationTemplate" + this.strName),
				document.getElementById('topPageNavigation' + this.strName)
			);
			this.objTopPageNavigation.setVisiblePage(1);
			this.objTopPageNavigation.setLoop(true);
			this.objTopPageNavigation.setOnPageEvent(function(iPage) { me.changePage(iPage, me.MODELLIST_PAGESELECTOR_TOP); });
			this.objPageNavigation.setOnPageEvent(function(iPage) { me.changePage(iPage, me.MODELLIST_PAGESELECTOR_MAIN); });
		} else {
			this.objPageNavigation.setOnPageEvent(function(iPage) { me.renderPage(iPage); });
		}
	}
}

PUBLIC.setShowRegister = function(objShowRegister) {
	this.objShowRegister = objShowRegister;
	var me = this;
	if (this.objShowRegister) {
		this.objShowRegister.addShowListener(function() {
				me.onMessageBoxShowEvent();
		});
		this.objShowRegister.addHideListener(function() {
			me.onMessageBoxHideEvent();
		});
	}
}

PRIVATE._changeToTextStyle = function(obj) {
	obj.style.color = "black";
	obj.style.textDecoration = "none";
	obj.style.cursor = "default";
}

PUBLIC.isTopModelOrder = function (blnTopModel) {
	this.blnTopModelOrder = blnTopModel;
}

PUBLIC.isForcePrivate = function (blnForcePrivate) {
	this.blnForcePrivate = blnForcePrivate;
}

PUBLIC.isSendToPage = function (blnSendToPage) {
	this.blnSendTo = blnSendToPage;
	if (blnSendToPage) {
		if (this.objPageNavigation) {
			this.objPageNavigation.setOutOfBoundDisplay(false);
			this.objPageNavigation.setLoop(false);
			this.objPageNavigation.setReplace(true);
		}
		if (this.objTopPageNavigation) {
			this.objTopPageNavigation.setOutOfBoundDisplay(false);
			this.objTopPageNavigation.setLoop(false);
			this.objTopPageNavigation.setReplace(true);
		}
	}
}

PUBLIC.setSendToPageUrl = function (strUrl) {
	var oUrl = new CM_URL();
	oUrl.parseUrl(strUrl);
	this.objSendToUrl = oUrl;
}

PUBLIC.canRate = function canRate(blnCanRate) {
	
	this.blnCanRate = blnCanRate;
	
}

PRIVATE._changeToLinkStyle = function(obj) {
	if(obj) {
		obj.style.color = "#0000ff";
		obj.style.textDecoration = "underline";
		obj.style.cursor = "pointer";
	}
}

PUBLIC.registerMessageBoxShowListener = function (ptFunction) {
	this.arrShowMessageBoxListener.push(ptFunction);
}
PUBLIC.registerMessageBoxHideListener = function (ptFunction) {
	this.arrHideMessageBoxListener.push(ptFunction);
}

PUBLIC.onMessageBoxShowEvent = function() {
	for(var intI = 0; intI < this.arrShowMessageBoxListener.length; intI++) {
		this.arrShowMessageBoxListener[intI]();
	}
}

PUBLIC.onMessageBoxHideEvent = function() {
	for(var intI = 0; intI < this.arrHideMessageBoxListener.length; intI++) {
		this.arrHideMessageBoxListener[intI]();
	}
}

PUBLIC.onRegisterEvent = function(strFormName, strUrl, strAccess) {
	for(var intI = 0; intI < this.arrOnRegisterEvent.length; intI++) {
		this.arrOnRegisterEvent[intI](strFormName, strUrl, strAccess);
	}
}

PUBLIC.onConfirmRegistration = function(strFormName) {
	for(var intI = 0; intI < this.arrOnConfirmRegistration.length; intI++) {
		this.arrOnConfirmRegistration[intI](strFormName);
	}
}
PUBLIC.notifyLanguageClick = function(intLanguageId) {
	for(var intI = 0; intI < this.arrOnLanguageClick.length; intI++) {
		this.arrOnLanguageClick[intI](intLanguageId);
	}
}

PUBLIC.onControllCache = function() {
	for(var intI = 0; intI < this.arrControllCacheEvent.length; intI++) {
		if(this.arrControllCacheEvent[intI]) {
			this.arrControllCacheEvent[intI]();
		}
	}
}

PUBLIC.onControllShow = function() {
	for(var intI = 0; intI < this.arrControllShowEvent.length; intI++) {
		if(this.arrControllShowEvent) {
			this.arrControllShowEvent[intI]();
		}
	}
}

PUBLIC.onLanguageClick = function(intLanguageId) {
	this.reorderByLanguage(intLanguageId);	
}

PUBLIC.setMatchmakerAnswered = function(blnAnswered) {
	this.blnMatchmakerAnswered = blnAnswered;
}

PUBLIC.setSeekIndex = function(intSeekIndex) {
	this.intSeekIndex = intSeekIndex;
} 

PUBLIC.setMinHeight = function(intMinHeight) {
	this.intMinHeight = intMinHeight;
}

PUBLIC.setModelCount = function(intModelCount) {
	this.intModelCount = intModelCount;
}

PUBLIC.displayOnlineFlag = function(blnDisplay) {
	this.blnDisplayOnlineFlag = blnDisplay;
}

PUBLIC.allowPrivate = function(blnPrivate) {
	this.blnPrivate = blnPrivate; 
}

PUBLIC.registerOnRegisterEvent = function(ptFunction) {
	this.arrOnRegisterEvent.push(ptFunction);
}
PUBLIC.addOnConfirmRegistration = function(ptFunction) {
	this.arrOnConfirmRegistration.push(ptFunction);
}
PUBLIC.registerOnLanguageClick = function(ptFunction) {
	this.arrOnLanguageClick.push(ptFunction);
}
PUBLIC.registerControllCacheEvent = function(ptFunction) {
	this.arrControllCacheEvent.push(ptFunction);
}
PUBLIC.registerControllShowEvent = function(ptFunction) {
	this.arrControllShowEvent.push(ptFunction);
}

PUBLIC.filterByNiche = function(arrData) {
	blnFound = false;
	if(this.intNicheId == 0) {
		blnFound = true;
	} else {
		arrNiche = arrData["nicheList"].split(",");
		//alert(arrNiche);
		for(var intI = 0; intI <= arrNiche.length && !blnFound; intI++) {
			if(
				parseInt(arrNiche[intI]) == this.intNicheId
			) {
				//alert(parseInt(arrNiche[intI]) + " == " + me.intNicheId);
				blnFound = true;
			}
		} 
	}
	return blnFound;
}

PUBLIC.filterByPage = function(arrData, obj) {
	blnFound = false;
	if (obj.cnt >= (obj.intMaxModel * (obj.intPage -1)) && obj.cnt < (obj.intMaxModel * obj.intPage) ) {
		blnFound = true;
	}
	obj.cnt += 1;
	return blnFound;
}

PUBLIC.getModelRs = function () {
	// -------
	var objUrlToSend = new DHL.NET.URL.getCurrent();
	var strAttributes = 'Frm[' + this.strName + '][newModelRs][niche]='+this.intNicheId +
		(this.blnOrderByRating? '&Frm[' + this.strName + '][newModelRs][orderByRating]=1':'') +
		(this.blnOrderByMatchmaker? '&Frm[' + this.strName + '][newModelRs][orderByMatchmaker]=1':'') +
		(this.intLanguageId? '&Frm[' + this.strName + '][newModelRs][modelLanguageId]=' + this.intLanguageId:'') +
		''
	;
	this.objSendDataHttpRequest.open('POST', objUrlToSend, true);

	this.objSendDataHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	this.objSendDataHttpRequest.setRequestHeader('Content-length', strAttributes.length);
	this.objSendDataHttpRequest.setRequestHeader('Connection', 'close');

	var me = this;
	this.objSendDataHttpRequest.onreadystatechange(function() {
		me.onReceiveData();
	});
	this.objSendDataHttpRequest.send(strAttributes);
	this.ptCallbackFunction = this.setNewRs;
	// -------

	if(document.getElementById("searchbox" + this.strName)) {
		document.getElementById("searchbox" + this.strName).style.display="none";
		this.onControllCache();
	}
	if(document.getElementById("headerLoading" + this.strName)) {
		document.getElementById("headerLoading" + this.strName).style.display="block";
	}	
	
}

PUBLIC.setNewRs = function (strText) {
	var objNewRs = eval(strText);
	if(objNewRs) {
		objNewRs.seek(0);
		if (document.getElementById('pageModelCount' + this.strName)) {
			document.getElementById('pageModelCount' + this.strName).innerHTML = '(' + objNewRs.getRecordCount() + ')';
		}
		if (document.getElementById('pageModelCountMore' + this.strName)) {
			document.getElementById('pageModelCountMore' + this.strName).innerHTML = '(' + objNewRs.getRecordCount() + ')';
		}
		this.intModelCount = objNewRs.getRecordCount();
		this.intMaxPage = Math.ceil(this.intModelCount / this.intMaxModel);
		this.setModelRs(objNewRs);
		//this.updateWithNewRs();
		this.renderPage(1);
		if(this.objPageNavigation) {
			this.objPageNavigation.setTotalPage(this.intMaxPage);
			if (this.objTopPageNavigation) {
				this.objTopPageNavigation.setTotalPage(this.intMaxPage);
			}
			if ( this.intMaxPage > 1 ) {
				document.getElementById('pageNavigator' + this.strName).style.visibility = 'visible';
				if (this.objTopPageNavigation) {
					document.getElementById('topPageNavigation' + this.strName).style.visibility = 'visible';
				}
			} else {
				document.getElementById('pageNavigator' + this.strName).style.visibility = 'hidden';
				if (this.objTopPageNavigation) {
					document.getElementById('topPageNavigation' + this.strName).style.visibility = 'hidden';
				}
			}
			this.objPageNavigation.setCurrentPage(1);
			if (this.objTopPageNavigation) {
				this.objTopPageNavigation.setCurrentPage(1);
			}
		}
		if(document.getElementById("searchbox" + this.strName)) {
			document.getElementById("searchbox" + this.strName).style.display="block";
			this.onControllShow();
		}
		if(document.getElementById("headerLoading" + this.strName)) {
			document.getElementById("headerLoading" + this.strName).style.display="none";
		}
	}
}

PUBLIC.renderPage = function(iPage) {
	var me = this;
	me.cnt = 0;
	
	if (this.blnSendTo && iPage > 1 && iPage == this.intMaxPage && this.intPage == iPage - 1) {
		if (!this.objSendToUrl) {
			if(this.intNicheId != 0) { 
				this.setSendToPageUrl('/niche/' + this.arrNicheList[this.intNicheId]);
			} else {
				this.setSendToPageUrl('/modellist.htm');
			}
		}
		document.location.href = this.objSendToUrl.toString();
	} else {
		this.intPage = iPage;
		this.objRsModel.applyFilter(function(arr) { return me.filterByPage(arr, me); });
		this.render();
	}
}

PUBLIC.changePage = function (iPage, intId) {
	if (intId == this.MODELLIST_PAGESELECTOR_MAIN) {
		this.objTopPageNavigation.setCurrentPage(iPage, true);
	} else if (intId == this.MODELLIST_PAGESELECTOR_TOP) {
		this.objPageNavigation.setCurrentPage(iPage, true);
	}
	this.renderPage(iPage);
}

PUBLIC.setMaxModel = function(intMaxModel) {
	this.intMaxModel = intMaxModel;
	if (this.objRsModel) {
		this.objRsModel.seek(0);
		this.intMaxPage = Math.ceil(this.intModelCount / intMaxModel);
		if (
			this.objPageNavigation
		) {
			this.objPageNavigation.setTotalPage(this.intMaxPage);
			this.objPageNavigation.setCurrentPage(this.intPage);
			if (this.objTopPageNavigation) {
				this.objTopPageNavigation.setTotalPage(this.intMaxPage);
				this.objTopPageNavigation.setCurrentPage(this.intPage);
			}
			if ( this.intMaxPage > 1 ) {
				document.getElementById('pageNavigator' + this.strName).style.visibility = 'visible';
				if (this.objTopPageNavigation) {
					document.getElementById('topPageNavigation' + this.strName).style.visibility = 'visible';
				}
			} else {
				document.getElementById('pageNavigator' + this.strName).style.visibility = 'hidden';
				if (this.objTopPageNavigation) {
					document.getElementById('topPageNavigation' + this.strName).style.visibility = 'hidden';
				}
			}
		}
	}
}

PUBLIC.setArrNicheList = function (arrNicheList) {
	this.arrNicheList = arrNicheList;
}

PUBLIC.setNicheId = function (intNicheId) {
	this.intNicheId = parseInt(intNicheId);
}

PUBLIC.onNicheChange = function(intNicheId) {
	var me = this;
	if(parseInt(intNicheId) > 0 ) {
		this.intNicheId = parseInt(intNicheId);
	}
	else {
		this.intNicheId = 0;
	}
	if (
		this.objPageNavigation
	) {
		this.getModelRs();
	} else {
		this.objRsModel.applyFilter(function(arr) { return me.filterByNiche(arr); });
		
		if(this.blnTopModelOrder) {
			//sort
			this.objRsModel.sortData("isOnShow", this.sortDataAsc);
			this.objRsModel.sortData("isOnBreak", this.sortDataAsc);
			this.objRsModel.sortData("topModel", this.sortDataDesc);
			this.objRsModel.sortData("spokedLanguage", 
				function(strFirstField, strSecondField) { 
					return(strSecondField && strSecondField.search(me.intModelLanguageId) >= 0?1:-1); 
				}
			);
	
			//Generate the new column containing the isTopModel order
			this.objRsModel.addField("isTopModel");
			var intNbModel = 0;
			while(this.objRsModel.next()) {
				if(intNbModel < 4) {
					this.objRsModel.setField("isTopModel", 1);
				}
				else {
					this.objRsModel.setField("isTopModel", 0);
				}
				intNbModel++;
			}
	
			//sort
			this.objRsModel.sortData("isOnShow", this.sortDataAsc);
			this.objRsModel.sortData("isOnBreak", this.sortDataAsc);
			this.objRsModel.sortData("isTopModel", this.sortDataDesc);
			this.objRsModel.sortData("spokedLanguage", 
				function(strFirstField, strSecondField) { 
					return(strSecondField && strSecondField.search(me.intModelLanguageId) >= 0?1:-1); 
				}
			);
			this.objRsModel.sortData("rndField", this.sortDataDesc);
		}
		
		this.render();
	}
}
PUBLIC.updateWithNewRs = function () {
	var me = this;
	this.objRsModel.applyFilter(function(arr) { return me.filterByNiche(arr); });
	if(this.blnTopModelOrder) {
		//sort
		this.objRsModel.sortData("isOnShow", this.sortDataAsc);
		this.objRsModel.sortData("isOnBreak", this.sortDataAsc);
		this.objRsModel.sortData("topModel", this.sortDataDesc);
		this.objRsModel.sortData("spokedLanguage", 
			function(strFirstField, strSecondField) { 
				return(strSecondField && strSecondField.search(me.intModelLanguageId) >= 0?1:-1); 
			}
		);

		//Generate the new column containing the isTopModel order
		this.objRsModel.addField("isTopModel");
		var intNbModel = 0;
		while(this.objRsModel.next()) {
			if(intNbModel < 4) {
				this.objRsModel.setField("isTopModel", 1);
			}
			else {
				this.objRsModel.setField("isTopModel", 0);
			}
			intNbModel++;
		}

		//sort
		this.objRsModel.sortData("isOnShow", this.sortDataAsc);
		this.objRsModel.sortData("isOnBreak", this.sortDataAsc);
		this.objRsModel.sortData("isTopModel", this.sortDataDesc);
		this.objRsModel.sortData("spokedLanguage", 
			function(strFirstField, strSecondField) { 
				return(strSecondField && strSecondField.search(me.intModelLanguageId) >= 0?1:-1); 
			}
		);
		this.objRsModel.sortData("rndField", this.sortDataDesc);
	}
	
	this.render();
}

PUBLIC.setModelRs = function(objRsModel) {
	objRsModel.seek(0);
	this.intMaxPage = Math.ceil(this.intModelCount / this.intMaxModel);
	this.objRsModel = objRsModel;
	if (
		this.objPageNavigation
	) {
		this.objPageNavigation.setTotalPage(this.intMaxPage);
		this.objPageNavigation.setCurrentPage(this.intPage);
		if (this.objTopPageNavigation) {
			this.objTopPageNavigation.setTotalPage(this.intMaxPage);
			this.objTopPageNavigation.setCurrentPage(this.intPage);
		}
	}
}

PUBLIC.sortDataAsc = function(intFirstField, intSecondField) {
	intReturn = 1;
	
	if(
		intSecondField > intFirstField ||
		(
			intSecondField != null &&
			intFirstField == null
		)
	) {
		intReturn = -1;
	}
	
	return intReturn;
}

PUBLIC.sortDataDesc = function(intFirstField, intSecondField) {
	intReturn = -1;
	
	if(
		intSecondField > intFirstField ||
		(
			intSecondField != null &&
			intFirstField == null
		)
	) {
		intReturn = 1;
	}
	
	return intReturn;
}

PUBLIC.sortByPopular = function() {
	this._changeToLinkStyle(document.getElementById("lnkTop" + this.strName));
	this._changeToLinkStyle(document.getElementById("lnkMatchmaker" + this.strName));
	this._changeToTextStyle(document.getElementById("lnkPopular" + this.strName));
		
	this.objRsModel.sortData("mostPopularRank", this.sortDataDesc);
	this.objRsModel.seek(0);
	this.render();
}

PUBLIC.sortByTopRated = function() {
	this.blnOrderByRating = true;
	this.blnOrderByMatchmaker = false;	
	this._changeToLinkStyle(document.getElementById("lnkMatchmaker" + this.strName));
	this._changeToLinkStyle(document.getElementById("lnkPopular" + this.strName));
	this._changeToTextStyle(document.getElementById("lnkTop" + this.strName));
	this.getModelRs();
	//this.objRsModel.sortData("ratingResult", this.sortDataDesc);
	//this.objRsModel.seek(0);
	//this.render();
}

PUBLIC.sortByMatchmaker = function() {
	
	if(this.blnMatchmakerAnswered && this.blnPrivate) {
		this._changeToLinkStyle(document.getElementById("lnkTop" + this.strName));
		this._changeToLinkStyle(document.getElementById("lnkPopular" + this.strName));
		this._changeToTextStyle(document.getElementById("lnkMatchmaker" + this.strName));
		
		this.blnOrderByRating = false;
		this.blnOrderByMatchmaker = true;
		this.getModelRs();
		//this.objRsModel.sortData("matchmakerScore", this.sortDataDesc);
		//this.objRsModel.seek(0);
		//this.render();	
	}
	else if(this.blnPrivate) {
		if(this.blnCanRate) {
			objUrl = CM_URL.getCurrent();
			objUrl.setPath("/matchmaker_config.htm");
			document.location = objUrl.toString();
		}
		else {
			this.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_CONFIRM);
		}	
	}
	else {
		objUrl = CM_URL.getCurrent();
		objUrl.setPath((this.blnMatchmakerAnswered ? "/matchmaker.htm": "/matchmaker_config.htm"));
		this.onRegisterEvent(
			CM_WEBCOMPONENT_REGISTER.FORM_LOGIN, objUrl.toString(), 'matchmaker'
		);
	}
}

PUBLIC.setModelContainer = function(objModelContainer) {
	this.objModelContainer = objModelContainer
}

PUBLIC.setModelTemplate = function(objModelTemplate) {
	this.objModelTemplate= objModelTemplate
}

PUBLIC.render = function() {
	if(this.objRsModel) {
		//add the random Field
		this.objRsModel.addField("rndField");
		while(this.objRsModel.next()) {
			this.objRsModel.setField("rndField", Math.random());
		}
	
		if(this.intSeekIndex) {
			this.objRsModel.seek(this.intSeekIndex);
		}
		else {
			this.objRsModel.seek(0);
		}

		var arrRow = null;

		if(this.objModelTemplate) {
			var objModelTemplate = this.objModelTemplate;
		}
		else {
			var objModelTemplate = document.getElementById("modelTemplate" + this.strName);
		}

		if(this.objModelContainer) {
			var objContainer = this.objModelContainer;
		}
		else {
			var objContainer = document.getElementById("Container" + this.strName);
		}

		if(this.intMinHeight) {
			objContainer.style.minHeight = parseInt(this.intMinHeight) + 'px';
		}
		
		var intNbModel = 0;

		//Clear container
		while(objContainer.firstChild) {
			objContainer.removeChild(objContainer.firstChild);
		}
		
		//Display model list
		while(
			(arrRow = this.objRsModel.fetch()) && 
			intNbModel < this.intMaxModel
		) {
			
			var objNewModel = objModelTemplate.cloneNode(true);
			objContainer.appendChild(objNewModel);
			
			var objProfileUrl = CM_URL.getCurrent();
			objProfileUrl.setNickname(arrRow["nickName"]);
			objProfileUrl.setPath("");
			
			var objMatchmakerUrl = CM_URL.getCurrent();
			
			if(this.blnMatchmakerAnswered) {
				objMatchmakerUrl.setPath('/matchmaker');
			}
			else {
				objMatchmakerUrl.setPath('/matchmaker_config');
			}
			var me = this;
			arrTemplate = dom_getElementsByTagName(objNewModel, '*');
			if(this.blnForcePrivate && this.blnPrivate) {
				if(arrTemplate["lnkImgModel"]) {
					arrTemplate["lnkImgModel"].href = "#";
					arrTemplate["lnkImgModel"].modelId = arrRow['modelId'];
					arrTemplate["lnkImgModel"].showType = arrRow['showType'];
					arrTemplate["lnkImgModel"].onclick = function() {
						
						if(me.blnCanRate) {							
							me.objShowRegister.goPrivate(this.modelId, this.showType);							
						}else{
							
							me.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_CONFIRM);							
						}
						return false;
						
					}
				}
				if(arrTemplate["lnkModelNick"]) {
					arrTemplate["lnkModelNick"].href = "#";
					arrTemplate["lnkModelNick"].modelId = arrRow['modelId'];
					arrTemplate["lnkModelNick"].showType = arrRow['showType'];
					arrTemplate["lnkModelNick"].onclick = function() {
						if(me.blnCanRate) {
							me.objShowRegister.goPrivate(this.modelId, this.showType);							
						}else{
							me.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_CONFIRM);
						}
						return false;	
											
					}
				}
				if(arrTemplate["lnkMatchmaker"]) {
					arrTemplate["lnkMatchmaker"].href = "#";
					arrTemplate["lnkMatchmaker"].modelId = arrRow['modelId'];
					arrTemplate["lnkMatchmaker"].showType = arrRow['showType'];
					arrTemplate["lnkMatchmaker"].onclick = function() {
						if(me.blnCanRate) {
							me.objShowRegister.goPrivate(this.modelId, this.showType);							
						}else{
							me.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_CONFIRM);
						}
						return false;
					}
				}
				if(arrTemplate["profileUrl"]) {
					arrTemplate["profileUrl"].href = "#";
					arrTemplate["profileUrl"].modelId = arrRow['modelId'];
					arrTemplate["profileUrl"].showType = arrRow['showType'];
					arrTemplate["profileUrl"].onclick = function() {
						me.objShowRegister.goPrivate(this.modelId, this.showType);
						return false;
					}
				}
			}
			else {
				if(arrTemplate["lnkImgModel"]) {
					arrTemplate["lnkImgModel"].href = objProfileUrl.toString();
				}
				if(arrTemplate["lnkModelNick"]) {
					arrTemplate["lnkModelNick"].href = objProfileUrl.toString();
				}
				if(arrTemplate["lnkMatchmaker"]) {
					arrTemplate["lnkMatchmaker"].href = objProfileUrl.toString();
				}
				if(arrTemplate["profileUrl"]) {
					arrTemplate["profileUrl"].href = objProfileUrl.toString();
				}
			}

			if(arrTemplate["ratingContainer"]) {
				intCurrentScore = arrRow["ratingResult"]; 
				if (arrRow["modelPerformance"] != undefined) {
					objImage = document.createElement("img");
					arrTemplate["ratingContainer"].appendChild(objImage);
					var iScore = 1;
					if(arrRow["modelPerformance"] < 0.2){
						iScore = 1;
					}else if(arrRow["modelPerformance"] == 1){
						iScore = 5;
					}else{
						iScore = Math.floor(arrRow["modelPerformance"]/0.2)+1;
					}
					var oD = new Date();
					
					/*if (oD.getMonth() < 2 && oD.getDate() < 10 && iScore >= 2) {
						iScore = 1;
					} else if (oD.getMonth() < 2 && oD.getDate() < 11 && iScore >= 3) {
						iScore = 2;
					} else*/ 
						
					if (oD.getDate() < 25 && iScore >= 4) {
						iScore = 3;
					} else if (oD.getDate() < 29 && iScore >= 5) {
						iScore = 4;
					}
					
					objImage.width = 60;
					objImage.height = 10;
					objImage.src="/images/halloween/rank0" +iScore + ".gif";
				} else {
					for(var intISuffix =0; intISuffix < 5; intISuffix++) {
						fltSuffix = 0;
						if(intCurrentScore >= 1) {
							fltSuffix = '1';
						}
						else if(intCurrentScore < 1 && intCurrentScore >= 0.75) {
							fltSuffix = '0.75';
						}
						else if(intCurrentScore < 0.75 && intCurrentScore >= 0.50) {
							fltSuffix = '0.50';
						}
						else if(intCurrentScore < 0.50 && intCurrentScore >= 0.25) {
							fltSuffix = '0.25';
						}
						
						objImage = document.createElement("img");
						arrTemplate["ratingContainer"].appendChild(objImage);
						objImage.src="/images/star_modelbox_" + fltSuffix + ".gif";
						intCurrentScore--;
					}
				}
			}

			if(arrTemplate["language"] && arrRow["spokedLanguage"]) {
				arrLanguage = arrRow["spokedLanguage"].split(",");
				arrLanguage = DHL.SITE.PROFILEQUESTIONANSWER_LANGUAGE.sortByPriority(arrLanguage);
				
				for(var intI=0; intI < arrLanguage.length && intI < 4 ; intI++) {
					var strImage = "";
					if(strImage = DHL.SITE.PROFILEQUESTIONANSWER_LANGUAGE.getLanguageImage(arrLanguage[intI])) {
						var objImage = document.createElement("img");
						var objProfileQuestionAnswer = DHL.SITE.PROFILEQUESTIONANSWER.getInstance(arrLanguage[intI]);
						arrTemplate["language"].appendChild(objImage);
						objImage.src = "/shared/modelImage/56/200807/" + strImage + ".gif";
						objImage.style.paddingRight = "3px";
						objImage.style.width = "16px";
						objImage.style.height = "10px";
						objImage.style.cursor = "pointer";
						if(objProfileQuestionAnswer) {
							objImage.title = objProfileQuestionAnswer.getVariable("name");
						}
						var me = this;
						
						objImage.iLanguageId = arrLanguage[intI];
						objImage.onclick = function () {
							me.setLanguage(this.iLanguageId);
							return false;
						};
					}
				}
			}

			if(
				this.blnDisplayOnlineFlag && 
				arrRow["isOnline"] == 1 &&
				arrTemplate["onlineFlag"]
			) {
				arrTemplate["onlineFlag"].style.display = "block";
				arrTemplate["onlineFlag"].style.cursor = "pointer";
				arrTemplate["onlineFlag"].onclick = function() {
					document.location = objProfileUrl.toString();
				}
			}
			else if(arrTemplate["onlineFlag"]) {
				arrTemplate["onlineFlag"].style.display = "none";
			}

			if(arrTemplate["isPrivateAudio"]) {
				arrTemplate["isPrivateAudio"].style.visibility = "hidden";
			}
			
			if(arrTemplate["modelPriceBox"]) {
				arrTemplate["modelPriceBox"].style.visibility = (arrRow['billingProfile'] && arrRow['billingProfile'] > 0 ? "visible": "hidden");
				arrTemplate["modelPriceBox"].className = 'model-price-icon-' + arrRow['billingProfile'];
			}

			if(arrTemplate["isHD"]) {
				arrTemplate["isHD"].style.visibility = (arrRow['isHD'] == 1? "visible": "hidden");
				arrTemplate["isHD"].style.display = (arrRow['isHD'] == 1? "": "none");
			}
			
			if(this.blnPrivate) {
				
				if (arrRow['isOnline'] == 1) {
				
					if(arrTemplate["privateUrl"]) {
				
						if(this.blnCanRate) {
							arrTemplate["privateUrl"].href = "#";
							arrTemplate["privateUrl"].modelId = arrRow['modelId'];
							arrTemplate["privateUrl"].showType = arrRow['showType'];
							var me = this;
							arrTemplate["privateUrl"].onclick = function() {
								
								me.objShowRegister.goPrivate(this.modelId, this.showType);
								return false;
							}
						}
						else {
							arrTemplate["privateUrl"].href = "#";
							var me = this;
							arrTemplate["privateUrl"].onclick = function() {
								
								me.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_CONFIRM);
								return false;
							}
						}
					}

					if (
						arrRow['showType'] && 
						arrRow['showType'] == "DHL_FMS_SHOW::FEATURED" 
					) {
						if(arrTemplate["privateUrl"]) {
							arrTemplate["privateUrl"].innerHTML = 'Enter My Nude Chat';
						}
						if(arrTemplate["profileUrl"]) {
							arrTemplate["profileUrl"].style.display = "none";
						}
						if(arrTemplate["modelbox_split"]) {
							arrTemplate["modelbox_split"].style.display = "none";
						}
					}
					
					if(arrTemplate["isPrivateAudio"]) {
						arrTemplate["isPrivateAudio"].style.visibility = "hidden";
					}
					if(arrTemplate["isHD"]) {
						arrTemplate["isHD"].style.visibility = (arrRow['isHD'] == 1? "visible": "hidden");
					}
					if(arrTemplate["priceContainer"]) {
						arrTemplate["priceContainer"].style.display = "block";
					}
					if(arrTemplate["showPrice"]) {
						arrTemplate["showPrice"].innerHTML = Math.round(arrRow["privateCreditRate"] * 1.198 * 100) / 100;
					}
				} else {
					if(arrTemplate["privateUrl"]) {
						arrTemplate["privateUrl"].style.display = "none";
					}
					if(arrTemplate["profileUrl"]) {
						arrTemplate["profileUrl"].innerHTML = 'See my Homepage';
					}
					if(arrTemplate["modelbox_split"]) {
						arrTemplate["modelbox_split"].style.display = "none";
					}
					if(arrTemplate["priceContainer"]) {
						arrTemplate["priceContainer"].style.display = "none";
					}
				}
			}
			else {
				if(arrTemplate["lnkMatchmaker"]) {
					arrTemplate["lnkMatchmaker"].matchmakerScore = arrRow["matchmakerScore"];
					var me = this;
					arrTemplate["lnkMatchmaker"].onclick = function() {
							objUrl = CM_URL.getCurrent();
							objUrl.setPath((this.matchmakerScore ? "/matchmaker": "/matchmaker_config"));
							me.onRegisterEvent(
								CM_WEBCOMPONENT_REGISTER.FORM_LOGIN, objUrl.toString(), 'matchmaker'
							);
							return false;
					};
				}

				if (
					arrRow['isOnline'] == 1 && 
					arrTemplate["privateUrl"] &&
					arrRow['showType'] != "DHL_FMS_SHOW::FEATURED" 
				)  {
					arrTemplate["privateUrl"].href = "#";
					arrTemplate["privateUrl"].nickName = arrRow["nickName"];
					var me = this;
					arrTemplate["privateUrl"].onclick = function() {
						objUrl = CM_URL.getCurrent();
						objUrl.setNickname(this.nickName);
						objUrl.setPath("private/size.htm");
						objUrl.setAttribute('type', 'DHL_FPSPRIVATESHOW');
						me.onRegisterEvent(CM_WEBCOMPONENT_REGISTER.FORM_LOGIN, objUrl.toString(), 'privateshow');
						return false;
					};
				}
				else {
					if(arrTemplate["privateUrl"]) {
						arrTemplate["privateUrl"].style.display = "none";
					}
					if(arrTemplate["profileUrl"]) {
						arrTemplate["profileUrl"].innerHTML = 'See my Homepage';
					}
					if(arrTemplate["modelbox_split"]) {
						arrTemplate["modelbox_split"].style.display = "none";
					}
					if(arrTemplate["priceContainer"]) {
						arrTemplate["priceContainer"].style.display = "none";
					}
				}
			}

			if(arrTemplate["imgModel"]) {
				if(arrRow["imageFileName"]) {
					arrTemplate["imgModel"].src = arrRow["imagePath"] + arrRow["imageFileName"];
				}
				else {
					//arrTemplate["imgModel"].src = "/images/cs_102x75_default.gif";
				}
			}

			if(arrTemplate["modelAge"]) {
				arrTemplate["modelAge"].innerHTML = (arrRow["age"]? arrRow["age"]: "??");
			}
			if(arrTemplate["modelNiche"]) {
				arrTemplate["modelNiche"].innerHTML = arrRow["defaultNicheTitle"];
			}
			if(arrTemplate["modelNick"]) {
				arrTemplate["modelNick"].innerHTML = arrRow["nickName"];
			}
			
			if(arrTemplate["matchmakerResult"]) {
				arrTemplate["matchmakerResult"].innerHTML = (arrRow["matchmakerScore"] ? arrRow["matchmakerScore"] + '%': (this.blnMatchmakerAnswered?"0%":"??"));
			}
		
			objNewModel.style.display = "block";
			intNbModel++;
		}
		if (typeof strSearchValue != 'undefined' ) {
			return strSearchValue;
		}
	}
	else {
		alert("no rs");
	}
}
PUBLIC.sortNumber = function(objA, objB) {
	return objA - objB;
}

PUBLIC.setLanguage = function(intLanguageId) {
	this.notifyLanguageClick(intLanguageId);
	this.reorderByLanguage(intLanguageId);
}

PUBLIC.reorderByLanguage = function (intLanguageId) {
	this.intModelLanguageId = intLanguageId;
	this.intLanguageId = intLanguageId;
	this.getModelRs();
}

PUBLIC.onReceiveData = function() {
	
	if(this.objSendDataHttpRequest.getReadyState() == 4) {
		//response has been received
		this.blnSending = false;
		if(
			this.objSendDataHttpRequest.getStatus() == 200 && 
			this.ptCallbackFunction
		) {
			this.ptCallbackFunction(this.objSendDataHttpRequest.getResponseText());
		}
	}
}

PUBLIC.callbackChangeModelLanguageId = function(intNewModelLanguageId) {
	//alert('Done!');
}

})();