DHL.JS.require('dhl.net.url');
DHL.JS.require('dhl.html.conversion');

String.prototype.ucwords = function() {
    return this.replace(/\w+/g, function(a) {
        return a.charAt(0).toUpperCase() + a.substr(1);
    });
};

var objRsModel = null; // the recordset containing all the connected models.
var objRsFeaturedModel = null; // the recordset containing the featured models.
var objArrTopModels = null;
var objRsNiche = null; // the recordset containing all the niches with at least one model.
var intMainNicheId = 6; // Latina nicheId
var blnStaticOutput = true; // true if the model data is already output statically at the beginning.
var blnDisplayPrice = false;
var fltCreditValue = 0;
var intSelectedNicheId = 0; // the niche currently selected.
var objSelectedModelRow = null; // the model currently selected.
var objModelBoxTemplate; // the box template to use when rebuilding the model box list.
var objNicheTabTemplate; // the tab template to use when rebuilding the niche tab list.
var objFeaturedModelBoxTemplate; // the box template to use when rebuilding the featured model box list.
var intCurrentVideoX; // the current video size.
var intSmallVideoX; // the initial video size.
var objHttpRequest; // to request the list of models from the server.
var intTimer; // the id of the timer that tells when to refresh the model list.
var blnBroadband; // broadband if true, lowband if false.
var blnIsFeature = false;
//var intTimeout = 3*60*1000; // the model list refresh rate (three minutes).
var intTimeout = 60*1000;

var blnDebug = false;
if (document.getElementById('debug')) {
	blnDebug = true;
}


DHL.JS.require('dhl.net.httprequest');
objHttpRequest = new DHL.NET.HTTPREQUEST();

function initVideoX(blnLoggedIn, blnDebug) {
	if (window.innerWidth) {
		var intWidth = window.innerWidth 
	} else {
		var intWidth = window.document.body.offsetWidth
	}
	if(parent.intVidSize == 2 && blnLoggedIn) {
		if (intWidth >= 1013) {
			self.intSmallVideoX = 4;
			parent.setVidSize(2);
		} else {
			self.intSmallVideoX = 2;
			parent.setVidSize(2);
		}
	} else {
		if( intWidth >= 1013 ) {
			self.intSmallVideoX = 2;
			parent.setVidSize(1);
		} else {
			self.intSmallVideoX = 1;
			parent.setVidSize(1);
		}
	}
	
	self.intCurrentVideoX = self.intSmallVideoX;
}

/**
 * Sets the style sheet for the page depending on intCurrentVideoX.
 */
function setCSS() {
	var objCss = document.getElementById('videocss');
	objCss.href = "/_live/template/css/video" + self.intCurrentVideoX + "x.css";
	var objCss = document.getElementById('modellistcss');
	objCss.href = "/_live/template/css/modellist" + ((self.intCurrentVideoX <= 1) ? 1 : 2) + "x.css";
}

/**
 * Sets the model data (connected models and niches available).
 * @param object objModelData the model data.
 */
function setModelData(objModelData) {
	self.objRsModel = objModelData['objRsModel'];
	self.objRsFeature = objModelData['objRsFeature'];
	self.objRsNiche = objModelData['objRsNiche'];
	if (getNicheRowById(self.intSelectedNicheId) == null) {
		self.intSelectedNicheId = 0;
	}
	if (objModelData['objArrTopModels']) {
		self.objArrTopModels = objModelData['objArrTopModels'];
	}
}

/**
 * Sets the selected niche.
 * @param integer intNicheId the id of the niche.
 */
function setSelectedNiche(intNicheId) {
	self.intSelectedNicheId = intNicheId;
}

/**
 * Sets the selected model.
 * @param integer intModelId the id of the model.
 */
function setSelectedModel(intModelId) {

	if(obj = document.getElementById('menu-signup-link')) {
		oUrl = new DHL.NET.URL(obj.href);
		oUrl.setAttribute('modelId',intModelId);
		obj.href = oUrl.toString();
	}
	if(obj = document.getElementById('header-link')) {
		oUrl = new DHL.NET.URL(obj.href);
		oUrl.setAttribute('modelId',intModelId);
		obj.href = oUrl.toString();
	}
	var i = 1;
	while(i <= 7) {
		if(obj = document.getElementById('menulink-' + i)) {
			oUrl = new DHL.NET.URL(obj.href);
			oUrl.setAttribute('modelId',intModelId);
			obj.href = oUrl.toString();
		}
		i = i + 1;
	}
	
	self.objSelectedModelRow = getModelRowById(self.objRsModel, intModelId);
	self.blnIsFeature = false;
	if(!self.objSelectedModelRow) {
		self.objSelectedModelRow = getModelRowById(self.objRsFeature, intModelId);
		self.blnIsFeature = true;
	}
}

function setBroadband(blnB) {
	self.blnBroadband = blnB;
}

/**
 * Call this with true as an argument if the model data is 
 * displayed statically at the beginning. 
 * @param boolean blnStatic true if the model data is displayed statically.
 */
function setStaticOutput(blnStatic) {
	self.blnStaticOutput = blnStatic;
}

function setDisplayPrice(blnDisplayPrice) {
	this.blnDisplayPrice = blnDisplayPrice;
}

function setCreditValue(fltCreditValue) {
	this.fltCreditValue = fltCreditValue;
}


/** 
 * Initializes the page.
 */
function start(blnHasPrivateAccess) {
	self.blnPrivateAccess = blnHasPrivateAccess;
	if(document.getElementById('model-box-template')) {
		self.objModelBoxTemplate = document.getElementById('model-box-template').cloneNode(true);
		self.objNicheTabTemplate = document.getElementById('niche-tab-template').cloneNode(true);
	}
	self.intTimer = setTimeout("requestModelData()", self.intTimeout);
	displayModelData();
	loadVideo();
	loadChat();
}

function selectRandomModel() {
	var intI = Math.floor(Math.random() * self.objRsModel.getRecordCount());
	self.objRsModel.seek(intI);
	var objModelRow = self.objRsModel.fetch();
	setSelectedModel(objModelRow['modelId']);
}

/**
 * Displays the model data on the page.
 */
function displayModelData() {
	displayAllModel();
	displayAllNiche();
	displayAllFeaturedModel();
}

function initStaticOutput() {
	self.objRsModel.applyFilter(getModelFilter(self.intSelectedNicheId));
	self.objRsModel.seek();
	var objModelRow;
	while(objModelRow = self.objRsModel.fetch()) {
		var objModelBox = document.getElementById("model-box-" + objModelRow['modelId']);
		var arrTag = objModelBox.getElementsByTagName('*');
		setModelBoxImage(arrTag['image'], objModelRow);
	}

	if(self.objRsFeature) {
		while(arrRow = self.objRsFeature.fetch()) {
			var objModelBox = document.getElementById("model-box-" + objModelRow['modelId']);
			var arrTag = objModelBox.getElementsByTagName('*');
			setModelBoxImage(arrTag['image'], arrRow);
		}
	}
}

/**
 * Sets the properties of the image tag according to the model's
 * attributes. The image chosen also depends on the window
 * size.
 * @param object objImage the image tag.
 * @param object objModelRow the row with the model's attributes.
 */
function setModelBoxImage(objImage, objModelRow) {
	if (objModelRow['imageFileName'] != null) {
		objImage.src = objModelRow['imagePath'] + ((self.intSmallVideoX <= 1) ? 'thumb/' : '') + objModelRow['imageFileName'];
	}
	else {
		objImage.src = ((self.intSmallVideoX <= 1) ? "/_live/template/images/default25x25.gif" : "/_live/template/images/default75x75.gif");
	}
	objImage.width = objImage.height = ((self.intSmallVideoX <= 1) ? 25 : 75);
	objImage.onmouseover = function(){ onModelBoxImageMouseover(objModelRow['modelId']) };
	objImage.onmouseout = function(){ onModelBoxImageMouseout() };
}

/**
 * Builds and displays the niche tabs in the niche menu. 
 */
function displayAllNiche() {
	var objListContainer = document.getElementById("nichelist");
	objListContainer.innerHTML = '';
	self.objRsNiche.applyFilter( function(oRow) { return true; } );
	var objNicheRow;
	while(objNicheRow = self.objRsNiche.fetch()) {
		if (objNicheRow['nicheId'] != self.intMainNicheId) {
			var objNicheTab = self.objNicheTabTemplate.cloneNode(true);
			setNicheTab(objNicheTab, objNicheRow);
			objNicheTab.style.display = 'inline';
			objListContainer.appendChild(objNicheTab);
		}
	}
	objNicheTab0 = document.getElementById("niche-tab-0");
	if (self.intSelectedNicheId == 0) {
		objNicheTab0.className = "selected-niche-tab";
	}
	else {
		objNicheTab0.className = "niche-tab";
	}
}

/**
 * Sets the fields of a niche tab according to the niche's
 * attributes.
 * @param object objNicheTab the niche tab.
 * @param object objNicheRow the niche's attributes.
 */
function setNicheTab(objNicheTab, objNicheRow) {
	objNicheTab.id = "niche-tab-" + objNicheRow['nicheId'];
	objNicheTab.className = (objNicheRow['nicheId'] == self.intSelectedNicheId)?"selected-niche-tab":"niche-tab";
	var arrTag = objNicheTab.getElementsByTagName('*');
	var objUrl = DHL.NET.URL.getCurrent();
	objUrl.setAttribute("nid", objNicheRow['nicheId']);
	arrTag['anchor'].href = objUrl.toString();
	arrTag['anchor'].onclick = function() { onSelectNiche(objNicheRow['nicheId']); return false; };
	arrTag['anchor'].innerHTML = DHL.HTML.CONVERSION.encode(objNicheRow['nicheTitle']);
}

/**
 * Displays the list of all the connected models who are in the
 * niche selected.
 */ 
function displayAllModel() {
	var objListContainer = document.getElementById("modellist-list");
	objListContainer.innerHTML = '';
	
	if (self.intSelectedNicheId == 'hd') {
		self.objRsModel.applyFilter(getHdFilter());
	} else {
		self.objRsModel.applyFilter(getModelFilter(self.intSelectedNicheId));
	}
	var objModelRow;
	while(objModelRow = self.objRsModel.fetch()) {
		var objModelBox = self.objModelBoxTemplate.cloneNode(true);
		setModelBox(objModelBox, objModelRow);
		objModelBox.style.display = 'block';
		objListContainer.appendChild(objModelBox);
	}
	var objClearer = document.createElement("div");
	objClearer.id = "clearer";
	objListContainer.appendChild(objClearer);
}

/**
 * Sets the fields of a model box according to the model's
 * attributes.
 * @param object objModelBox the model box.
 * @param object objModelRow the model's attributes.
 */
function setModelBox(objModelBox, objModelRow, strForceUrl) {
	objModelBox.id = "model-box-" + objModelRow['modelId'];
	var arrTag = objModelBox.getElementsByTagName('*');
	setModelBoxImage(arrTag['image'], objModelRow);
	arrTag['nickname'].innerHTML = DHL.HTML.CONVERSION.encode(objModelRow['nickName']);
	if(strForceUrl) {
		var objUrl = new DHL.NET.URL(strForceUrl);
	}
	else {
		var objUrl = DHL.NET.URL.getCurrent();
	}
	
	if(!strForceUrl || strForceUrl.indexOf('javascript:') == -1) {
		objUrl.setAttribute("modelId", objModelRow['modelId']);
		if (objModelRow['cnModelKey']) {
			objUrl.setAttribute('key', objModelRow['cnModelKey']);
		}
	}
	var strUrl = objUrl.toString();
	
	if (objModelRow['isTopModel'] == 1) {
		objModelBox.className = "model-box-top"
	} else if (self.objArrTopModels && self.objArrTopModels['i' + objModelRow['modelId']]) {
		objModelBox.className = "model-box-high"
	}
	
	if (objModelRow['isOnShow'] == 1) {
		if (self.intCurrentVideoX == 1) {arrTag['box-label'].innerHTML = 'P';} 
		else {arrTag['box-label'].innerHTML = 'Private';}
		arrTag['box-label'].style.display = '';
	} else if(objModelRow['isOnBreak'] == 1) {
		if (self.intCurrentVideoX == 1) {arrTag['box-label'].innerHTML = 'B';} 
		else {arrTag['box-label'].innerHTML = 'Break';}
		arrTag['box-label'].style.display = '';
	}
	
	if (arrTag["box-hd"]) {
		if(objModelRow['isHD'] == 1) {
			arrTag["box-hd"].style.display = "block";
		}
		else {
			arrTag["box-hd"].style.display = "none";
		}
	} else if (arrTag["box-hd-log"]) {
		if(objModelRow['isHD'] == 1) {
			arrTag["box-hd-log"].style.display = "block";
		}
		else {
			arrTag["box-hd-log"].style.display = "none";
		}
	}
	
	if (objModelRow['billingProfile'] && arrTag['model-price']) {
		arrTag["model-price"].style.display = "";
		arrTag["model-price"].className = 'model-price-icon-' + objModelRow['billingProfile'];
	}

	arrTag['nickname'].href = strUrl;
	arrTag['model-box-pic-a'].href = strUrl;
	var f = function() { switchToFeatured(LLFORCE_MODELLIST); onSelectModel(objModelRow['modelId']); return false; }
	if(strForceUrl) {
		arrTag['nickname'].onclick = function(){document.location=objUrl.toString();};
		arrTag['model-box-pic-a'].onclick = function(){document.location=objUrl.toString();};
	}
	else {
		arrTag['nickname'].onclick = f;
		arrTag['model-box-pic-a'].onclick = f;
	}
	
	// optional fields (age, nicheTitle, nationality)
	if (objModelRow['age'] != null) {
		arrTag['age'].innerHTML = DHL.HTML.CONVERSION.encode(objModelRow['age']);
	}
	else {
		arrTag['age-item'].style.display = 'none';
	}
	if (objModelRow['defaultNicheTitle'] != null) {
		arrTag['niche-title'].innerHTML = DHL.HTML.CONVERSION.encode(objModelRow['defaultNicheTitle']);
	}
	else {
		arrTag['niche-title-item'].style.display = 'none';
	}
	if (objModelRow['nationality'] != null) {
		strNationality = strNationalityShort = objModelRow['nationality'].toLowerCase().ucwords();
		if (strNationalityShort.length > 10) {
			strNationalityShort = strNationalityShort.substr(0, 10) + '...';
		}
		arrTag['nationality'].title = DHL.HTML.CONVERSION.encode(strNationality);	
		arrTag['nationality'].innerHTML = DHL.HTML.CONVERSION.encode(strNationalityShort);	
	}
	else {
		arrTag['nationality-item'].style.display = 'none';
	}
	var strPriceClass = "price-none";
	var fltShowPrice = 0;
	if (this.blnDisplayPrice) {
		//fltShowPrice = objModelRow['privateCreditRate'] * this.fltCreditValue;
	}
	if (fltShowPrice > 0) {
		var strDollar = Math.floor(fltShowPrice).toString();
		var strCent = Math.floor((fltShowPrice - Math.floor(fltShowPrice)) * 100).toString();
		if (strDollar == 7 && strCent == 48) {
			strCent = 49;
		}
		strPriceClass = "price-" + strDollar + strCent;
	}
	arrTag['price'].className = "model-box-price " + strPriceClass;
	
}

/**
 * Displays the list of featured models.
 */ 
function displayAllFeaturedModel() {
	var objListContainer = document.getElementById("feature-list");
	objListContainer.innerHTML = '';
	if(self.objRsFeature) {
		
		var objModelRow;
		if (self.intSelectedNicheId == 'hd') {
			self.objRsFeature.applyFilter(getHdFilter());
		} else {
			self.objRsFeature.applyFilter(getModelFilter(self.intSelectedNicheId));
		}
		var blnIsGroupChat = false;
		while(objModelRow = self.objRsFeature.fetch()) {
			blnIsGroupChat = true;
			var objModelBox = self.objModelBoxTemplate.cloneNode(true);
			var strForceUrl = "javascript:goPrivate(" + objModelRow["modelId"] + ", 'DHL_FMS_SHOW::FEATURED')";
			setModelBox(objModelBox, objModelRow, strForceUrl);
			objModelBox.style.display = 'block';
			objListContainer.appendChild(objModelBox);
		}
		var objClearer = document.createElement("div");
		objClearer.id = "clearer";
		objListContainer.appendChild(objClearer);
		
	}
	if (blnIsGroupChat) {
		document.getElementById('feature-title').style.display = 'block';
	} else {
		document.getElementById('feature-title').style.display = 'none';
	}
}

/**
 * Sets the fields of a featured model box according to the model's
 * attributes.
 * @param object objFeaturedModelBox the featured model box.
 * @param object objFeaturedModel the model's attributes.
 */ 
function setFeaturedModelBox(objFeaturedModelBox, objModelRow) {
	var arrTag = objFeaturedModelBox.getElementsByTagName('*');
	arrTag['nickname'].innerHTML = DHL.HTML.CONVERSION.encode(objModelRow['nickName']);
	if (objModelRow['imagePath'] && objModelRow['imageFileName']) {
		arrTag['image'].src = objModelRow['imagePath'] + 'thumb/' + objModelRow['imageFileName'];
	} else {
		arrTag['image'].src = "/_live/template/images/default25x25.gif";
	}
	arrTag['image'].onmouseover = function(){ onFeaturedModelBoxImageMouseover(objModelRow['modelId']); };
	arrTag['image'].onmouseout = function(){ onFeaturedModelBoxImageMouseout(); };
}

/**
 * Requests new model data from the server.
 */ 
function requestModelData() {
	var objUrl = DHL.NET.URL.getCurrent();
	objUrl.setAttribute("action", "getlist");
	objUrl.setAttribute("t", (new Date()).getTime());
	DHL.JS.require('dhl.net.httprequest');
	self.objHttpRequest.open('GET', objUrl, true);
	self.objHttpRequest.onreadystatechange(onReceiveModelData);
	self.objHttpRequest.send("");
	clearTimeout(self.intTimer);
	self.intTimer = setTimeout("requestModelData()", self.intTimeout);
}

/**
 * onreadystatechange event on the xml http request for the model data.
 * Receives the requested model data from the server and
 * displays it.
 */ 
function onReceiveModelData() {
	if(self.objHttpRequest.getReadyState() == 4) {
		var objModelData = eval("(" + self.objHttpRequest.getResponseText() + ")");
		setModelData(objModelData);
		displayModelData();
	}
}

/**
 * Returns the record of the model with the specified id.
 * @param integer intModelId the id of the model
 * @return object the row for the model.
 */ 
function getModelRowById(objRsToSearch, intModelId) {
	arrReturn = false;
	if(objRsToSearch) {
		objRsToSearch.applyFilter(
			function(oRow) {
				return oRow['modelId'] == intModelId;
			}
		);
		objRsToSearch.seek();
		arrReturn = objRsToSearch.fetch();
	}
	return arrReturn;
}

/**
 * Returns the record of the niche with the specified id.
 * @param integer intNicheId the id of the niche
 * @return object the row for the niche.
 */ 
function getNicheRowById(intNicheId) {
	self.objRsNiche.applyFilter(
		function(oRow) {
			return oRow['nicheId'] == intNicheId;
		}
	);
	self.objRsNiche.seek();
	return self.objRsNiche.fetch();
}

/**
 * onmouseover event on the image of a model box.
 * Displays the large version of a model's picture on mouseover.
 * @param integer intModelId the id of the model
 */ 
function onModelBoxImageMouseover(intModelId) {
	var objModelRow = getModelRowById(self.objRsModel, intModelId);
	if(!objModelRow) {
		objModelRow = getModelRowById(self.objRsFeature, intModelId);
	}
	
	objModelBox = document.getElementById("model-box-" + intModelId);
	if (
		self.intSmallVideoX <= 1 &&
		objModelRow &&
		objModelRow['imageFileName'] != null
	) {
		var sLabel = '';
		if (objModelRow['isOnShow'] == 1) {
			sLabel = 'Private';
		} else if (objModelRow['isOnBreak'] == 1) {
			sLabel = 'Break';
		}
		showModelImage(objModelBox, objModelRow['imagePath'] + objModelRow['imageFileName'], sLabel);
	} 
	else if( self.intSmallVideoX <= 1 ) {
		var sLabel = '';
		if (objModelRow['isOnShow'] == 1) {
			sLabel = 'Private';
		} else if (objModelRow['isOnBreak'] == 1) {
			sLabel = 'Break';
		}
		showModelImage(objModelBox, '/_live/template/images/default75x75.gif',sLabel);
	}
}

/**
 * onmouseover event on the image of a featured model box.
 * Displays the large version of a featured model's picture on mouseover.
 * @param integer intModelId the id of the model
 */
function onFeaturedModelBoxImageMouseover(intModelId) {
	var objModelRow = getModelRowById(self.objRsFeaturedModel, intModelId);
	objFeaturedModelBox = document.getElementById("featured-model-box-" + intModelId);
	if (objModelRow['imageFileName'] != null) {
		showModelImage(objFeaturedModelBox, objModelRow['imagePath'] + objModelRow['imageFileName']);
	} else {
		showModelImage(objFeaturedModelBox, '/_live/template/images/default75x75.gif');
	}
}

/**
 * Displays the large image of a model over the element.
 * object objElement the element over which the image is displayed.
 * string strImagePath the path of the image
 */
function showModelImage(objElement, strImagePath, sLabel) {
	ol_width = 79;
	ol_height = 79;
	ol_fixx = DOM_getX(objElement) - 50;
	if (ol_fixx < 0) ol_fixx = 0;
	ol_fixy = DOM_getY(objElement) + 40;
	var sAdd = '';
	if (sLabel) {
		sAdd = '<span class="floatingLabel">' + sLabel + '</span>';
	} 
	dcs(sAdd + '<img style="margin-left:2px; margin-top:2px;" src="' + strImagePath + '">');
}

/**
 * onmouseout event on the image of a model box.
 * Hides the large version of the picture on mouseout
 * (see onModelImageMouseover).
 */ 
function onModelBoxImageMouseout() {
	nd();
}

/**
 * onmouseout event on the image of a featured model box.
 * Hides the large version of the picture on mouseout
 * (see onFeaturedModelImageMouseover).
 */
function onFeaturedModelBoxImageMouseout() {
	nd();
}

/**
 * Returns a record filter that only accepts the models in
 * the given niche (intNicheId). If intNicheId == 0, returns a 
 * filter that accepts all models.
 * @param integer intNicheId the id of the niche
 * @return function the filter
 */ 
function getModelFilter(intNicheId) {
	var fnReturn = null;
	if (intNicheId === 0) { // all niches
		fnReturn = function(oRow) {
			return true;
		};
	}
	else { // one niche
		fnReturn = function(oRow) {
			var blnReturn = false;
			if (oRow['nicheList']) {
				var arrNiche = oRow['nicheList'].split(",");
				for (var i = 0; blnReturn == false && i < arrNiche.length; i++) {
					blnReturn = (arrNiche[i] == intNicheId);
				}
			}
			return blnReturn;
		};
	}
	return fnReturn;
}
 
function getHdFilter() {
	var fnReturn = null;
	fnReturn = function(oRow) {
		var blnReturn = false;
		if (oRow['isHD'] == 1) {
			blnReturn = true;
		}
		return blnReturn;
	};
	return fnReturn;
}


/**
 * onclick event on a niche tab.
 * Selects the niche and updates the list of model boxes displayed.
 * @param integer intNicheId the id of the niche
 */
function onSelectNiche(intNicheId) {
	objTab = document.getElementById("niche-tab-" + self.intSelectedNicheId);
	objTab.className = "niche-tab";
	setSelectedNiche(intNicheId);
	objTab = document.getElementById("niche-tab-" + self.intSelectedNicheId);
	objTab.className = "selected-niche-tab";
	displayAllModel();
	displayAllFeaturedModel();
}

function onSelectModel(intModelId) {
	disconnectall();
	setSelectedModel(intModelId);
	displaySelectedModel();
}

function displaySelectedModel() {
	loadVideo();
	loadChat();
	document.getElementById("selected-model-nickname").innerHTML = 
		DHL.HTML.CONVERSION.encode(self.objSelectedModelRow['nickName']);
	var objInfoUrl = new DHL.NET.URL.getCurrent();
	objInfoUrl.setPath('/_live/info.htm');
	objInfoUrl.setAttribute('opener', 1);
	objInfoUrl.setAttribute('modelId', self.objSelectedModelRow['modelId']);
	objLink = document.getElementById("selected-model-info");
	objLink.onclick = function () {
		loadProfile(self.objSelectedModelRow['modelId'], self.objSelectedModelRow['hasProfile']);
		//window.open(objInfoUrl.toString(),'LiveLatina','directories=0,toolbar=0,menubar=0,personalbar=0,location=0,scrollbars=1,status=0,resizable=0,height=510,width=806,screenX=0,screenY=0,left=0,top=0');
		return false;
	}
	objLink.href = objInfoUrl.toString();
	
	var strEmail = self.objSelectedModelRow['nickName'] + "@livelatina.com";
	document.getElementById("selected-model-email").href = "mailto:" + strEmail;

	if ( self.blnPrivateAccess ) {
		var objPrivateUrl = new DHL.NET.URL('javascript:goPrivate(' + self.objSelectedModelRow['modelId'] + ', \'DHL_FMS_SHOW::PRIVATE\')');
	} else {
		var objPrivateUrl = new DHL.NET.URL('javascript:goPrivate(' + self.objSelectedModelRow['modelId'] + ', \'DHL_FMS_SHOW::FEATURED\')');
	}
	
	var objPrivate = document.getElementById("private");
	if (objPrivate) objPrivate.href = objPrivateUrl.toString();

	var objSignupUrl = new DHL.NET.URL('signup.htm');
	objSignupUrl.setAttribute('modelId', self.objSelectedModelRow['modelId']);
	var objSignupPrivate = document.getElementById("signup-private");
	if (objSignupPrivate) objSignupPrivate.href = objSignupUrl.toString();
	var objSignupShort = document.getElementById("signup-short");
	if (objSignupShort) objSignupShort.href = objSignupUrl.toString();
	var objSignupVerbose = document.getElementById("signup-verbose");
	if (objSignupVerbose) objSignupVerbose.href = objSignupUrl.toString();

	var objAuth = document.getElementById("auth");
	if (objAuth) {
		var objAuthUrl = new DHL.NET.URL(objAuth.action);
		objAuthUrl.setAttribute('modelId', self.objSelectedModelRow['modelId']);
		objAuthUrl.setAttribute('key', self.objSelectedModelRow['cnModelKey']);
		objAuth.action = objAuthUrl.toString();
	}
}

function loadVideoFMS() {
	if(objVideo) {
		document.getElementById("bandwidth-bar").style.display = "none";
		document.getElementById("lowband-bar").style.display = "none";
		document.getElementById("fms-bar").style.display = "block";

		var objUrl = DHL.NET.URL.getCurrent();
		objUrl.setPath('/_live/video/registershow_fms.htm');
		objUrl.setAttribute('modelId', self.objSelectedModelRow['modelId']);
		objUrl.setAttribute('type', 'DHL_FMS_SHOW::FREE');
		objUrl.setAttribute('key', self.objSelectedModelRow['cnModelKey']);

		if (parent.intVidSize) {
			if (parent.intCurrentVideoX == 4) {
				objUrl.setAttribute('width', 640);
				objUrl.setAttribute('height', 480);
			} else if (parent.intCurrentVideoX == 2) {
				objUrl.setAttribute('width', 454);
				objUrl.setAttribute('height', 340);
			} else if (parent.intCurrentVideoX == 1) {
				objUrl.setAttribute('width', 320);
				objUrl.setAttribute('height', 240);
			}
		}

		document.getElementById("videoFMS").style.display = "block";
		document.getElementById("videoJV").style.display = "none";
		objVideo.changeVideo(objUrl);
	}
}

function loadFMSChat(blnResetNick) {
	if(objChat) {
		document.getElementById("chatFMS").style.display = "block";
		document.getElementById("chatJV").style.display = "none";

		if(blnResetNick) {
			objChat.reloadChat();
		}
	}
}

function loadVideo(blnSwitch) {
	if(self.objSelectedModelRow) {
		if(self.objSelectedModelRow['cnModelKey'].substring(0,2) == 'fm') {
			loadVideoFMS();
		}
		else {
			var objUrl = DHL.NET.URL.getCurrent();
			var objBlankUrl = new DHL.NET.URL("/_live/blank.htm");
			objUrl.setPath('/_live/video/registershow.htm');
			objUrl.setAttribute('modelId', self.objSelectedModelRow['modelId']);
			objUrl.setAttribute('type', 'DHL_FPSFREESHOW');
			objUrl.setAttribute('key', self.objSelectedModelRow['cnModelKey']);
			if ((typeof(blnSwitch) != 'undefined') && (blnSwitch == true)) {
				objUrl.setAttribute('sSwitch', 1);
				self.broadband = !self.broadband;
			}
			document.getElementById('video-frame').src = objUrl.toString();
			if (document.getElementById("videoFMS")) {
				document.getElementById("videoFMS").style.display = "none";
				document.getElementById("videoJV").style.display = "block";
			}
			document.getElementById("bandwidth-bar").style.display = "block";
			document.getElementById("lowband-bar").style.display = "block";
			document.getElementById("fms-bar").style.display = "none";
			
			
			if(typeof objVideo != 'undefined') {
				objVideo.changeVideo(objBlankUrl);
			}
		}
	}
}

function loadChat(blnResetNick) {
	if(self.objSelectedModelRow) {
		if(self.objSelectedModelRow['cnModelKey'].substring(0,2) == 'fm') {
			loadFMSChat(blnResetNick);
		}
		else {
			if (document.getElementById("chatFMS")) {
				document.getElementById("chatFMS").style.display = "none";
			}
			document.getElementById("chatJV").style.display = "block";
			
			var objUrl = DHL.NET.URL.getCurrent();
			objUrl.setPath('chat.htm');
			if( blnResetNick ) {
				objUrl.setAttribute('reset', 1);
			}
			objUrl.setAttribute('key', self.objSelectedModelRow['cnModelKey']);
			objUrl.setAttribute('videoX', self.intCurrentVideoX);
			if(document.getElementById("chat-frame")) {
				document.getElementById('chat-frame').src = objUrl.toString();
			}
		}
	}
}

function disconnectall() {
	var objBlankUrl = new DHL.NET.URL("/_live/blank.htm");
	
	if(typeof objChat != 'undefined') {
		objChat.disconnectChat();
	}
	
	if(typeof objVideo != 'undefined') {
		objVideo.changeVideo(objBlankUrl);
	}
	document.getElementById('chat-frame').src = objBlankUrl.toString();
	document.getElementById('video-frame').src = objBlankUrl.toString();
}

function switchSize(blnLoggedIn, strUrl) {

	if (window.innerWidth) {
		var intWidth = window.innerWidth 
	} else {
		var intWidth = window.document.body.offsetWidth
	}
	
	if ( blnLoggedIn ) {
		if( intWidth >= 1220 && parent.intVidSize == 1 ) {
			self.intCurrentVideoX = 4;
			parent.setVidSize(2);
			bln2x = 1;
		} else if ( intWidth < 1220 && parent.intVidSize == 1 ) {
			self.intCurrentVideoX = 2;
			parent.setVidSize(2);
			bln2x = 1;
		} else if (intWidth >= 1220 && parent.intVidSize == 2) {
			self.intCurrentVideoX = 2;
			parent.setVidSize(1);
			bln2x = 0;
		} else if (intWidth < 1220 && parent.intVidSize == 2) {
			self.intCurrentVideoX = 1;
			parent.setVidSize(1);
			bln2x = 0;
		}
		
		var objVideoCss = document.getElementById('videocss');
		objVideoCss.href = "/_live/template/css/video" + self.intCurrentVideoX + "x.css";
		
		loadVideo();
		loadChat();
		_httpSwitchSize(bln2x);
	} else {
		needAccess();
	}
}

function _httpSwitchSize(bln2x) {
	var objUrl = DHL.NET.URL.getCurrent();
	objUrl.setPath('/_live/script/setSession.htm');
	objUrl.setAttribute("bln2x", bln2x);
	self.objHttpRequest.open('GET', objUrl, true);
	self.objHttpRequest.send("");
}

function switchSpeed() {
	loadVideo(true);
}

function onBroadband() {
	loadVideo(true);
	document.getElementById("lowband-bar").style.display = "none";
	document.getElementById("broadband-bar").style.display = "block";
}

function onLowband() {
	loadVideo(true);
	document.getElementById("broadband-bar").style.display = "none";
	document.getElementById("lowband-bar").style.display = "block";
}

function onBroadbandHelp() {
	displayHighBandHelp('/shared/template/fps/fpsplayer.htm');
}

function dhlShowSetTime(attintTime) {
}

function dhlOnShowLoad() {
}

function dhlOnShowStop() {
} 

function dhlOnShowStart() {
}

function dhlOnSemiSwitch(intTimeOut) {
}

function dhlOnSwitchBack() {
}

function dhlKillShow() {
}

function dhlGoOffline() {
}

function dhlOnShowKill(){
	parent.document.getElementById('video-frame').location.href = "/shared/notready.htm?msg=2";
}