function setWelcomeHtml(smallText, fullText, title) {

	var showMain = !fullText;
	hasWelcome = true;

	if (showMain) {
		fullText = '<p style="padding-left: 5px;">...the first and only community-generated TV online featuring your idea of Luxury...<br/><br/>Enjoy what SQUA.RE has to offer immediately:</p><ul style="padding: 0px 0px 0px 5px; list-style-type: none;margin: 0px;"><li style="padding-bottom: 5px;">THE SQUA.RE CHANNEL <span style="color: #ccc; font-weight: normal;">The main channel on the home page bringing together the best and the latest from the SQUA.RE community.</span></li><li style="padding-bottom: 5px;">THE FOUR VERTICALS <span  style="color: #ccc; font-weight: normal;">Browse and find out daily the best of what has been uploaded by our community in High Living, Nightlife, Style and Escape.</span></li><li style="padding-bottom: 5px;">MEMBER CHANNELS <span style="color: #ccc; font-weight: normal;">Search and view any member\'s channel.</span></li><li style="padding-bottom: 5px;">JOIN SQUA.RE <span style="color: #ccc; font-weight: normal;">by receiving an invitation from an existing member or by applying <a href="javascript:writeToSquare_click();">here</a></span></li><li style="padding-bottom: 5px;">UPLOAD PHOTOS AND VIDEOS <span style="color: #ccc; font-weight: normal;">using the "MY SQUA.RE" section to edit your profile and build your channel</span></li><li style="padding-bottom: 5px;">BUILD YOUR CONTACTS <span  style="color: #ccc; font-weight: normal;">Through your own global network.  Simply, get started with messages and comments.</span></li><li style="padding-bottom: 5px;">SHOWCASE YOUR OWN CHANNEL <span style="color: #ccc; font-weight: normal;">Share it with your friends, your network and beyond through a direct link.</span></li></ul><p style="padding-bottom: 5px; text-align: center;"><a href="javascript:tour_click();">Click here</a> to see the Guided Tour</p>';
	}
	var html = '<h2 style="font-size: 18px; font-weight: normal;">' + title + '</h2>' +
			   '<h3 class="welcome hatched">' +
			   '<img class="hatcher" id="welcome_link" onclick="return welcome_show(this);" src="rsrc/button_sm_h3show-0.gif" width="9" height="9">' +
			   '<div id="scrollers" style="float: right; display:none;"><img id="scrollDown" src="rsrc/scroll2.gif" class="button" alt="" title="scroll down" width="13" height="13" onmousedown="return downScroll(\'txt_fullwelcome\');"" onmouseup="return stopScroll(this);" onmouseout="return stopScroll(this);" /><img id="scrollUp" src="rsrc/scroll8.gif" class="button" alt="" title="scroll up" width="13" height="13" onmousedown="return upScroll(\'txt_fullwelcome\');" onmouseup="return stopScroll(this);" onmouseout="return stopScroll(this);" /></div>' +
			   '<div class="ifunhatched" id="txt_fullwelcome" style="height: 347px; overflow-x:hidden;overflow-y:hidden; font-size: 11px;">'	 + fullText +  '</div>';



	html += '<div class="ifhatched" id="txt_smallwelcome" style="font-size: 11px;">' + smallText + '&nbsp;<a href="#" onclick="welcome_show(this);">Tell me more...</a>&nbsp;</div></h3>';
	selectedMember = ''; //Global Variable

	$('side_head').innerHTML = html;
}

function showHideDetails(node, mysquare) {
	if (!mysquare) {
		$("scrollUp").style.display = 'none';
		$("scrollDown").style.display = 'none';
	}

	if ($("member_details").className == 'dbody ifhatched') {
		$("member_details").className = 'dbody ifunhatched';

		if (node != null) {
			node.innerHTML = 'Hide full details';
		}

		// Ocultar la grilla
		oVLOG.setInvisible();

	} else {
		$("member_details").className = 'dbody ifhatched';
		if (node != null) {
			node.innerHTML = 'Show full details';
			// mostrar la grilla
			oVLOG.setVisible();
		}

	}
}

function setMemberProfile(service) {

	var html = '';
	var user_icon = '';
	var mysquare = 0;

	if (service.getResult().hasNext()) {
		var serviceRow = service.getResult().getCurrentRow().split("|!|");
		selectedMember = serviceRow[0];

		// Checks if the user is already on mysquare
		mysquare = parseInt('0' + serviceRow[30], 10);

		// Checks if the profile is public or not
		if (serviceRow[35].toLowerCase() == 'true' || parseInt('0' + serviceRow[35], 10) == 1) {
			mysquare = 1;
		}

		// Checks if the current user is equal to the profile user to display
		if (oEnviroment.getUser().getID() == serviceRow[0]) {
			mysquare = 1;
		}

		var image1 = 'localized/en/button_addmynetwork.gif';
		var image2 = 'localized/en/button_sm_sendmessage.gif';
		var buttonsHTML = '<p>&nbsp;</p>';
		var buttonDetails = '';

		// If the profile is not the profile of the current logged user
		if (serviceRow[0] != oEnviroment.getUser().getID()) {
			buttonsHTML = '';
			// If the members is not already on the current logged user square, the add button is shown.

			if (parseInt('0' + serviceRow[30], 10) == 0) {
				buttonsHTML += '<p style="margin:0 0 8px 0;padding:0;cursor:pointer;"><img id="entry_add_' + serviceRow[0] + '" onclick="grid_entry_add(this,\'3\',\''  + serviceRow[0] + '\',\'' + serviceRow[4] + '\')" src="' + image1 + '" \/></p>';
			} else {
				buttonsHTML += '<p></p>';
			}
			buttonsHTML += '<p style="margin:0 0 8px 0;padding:0;cursor:pointer;"><img id="send_msg_' + serviceRow[0] + '" src="' + image2 + '" onclick="send_message(this,\'' + serviceRow[0] + '\', \'' +  serviceRow[4] + '\')" \/></p>';

		}

		if (oStrategy.getCurrentPage() == 'index.php') {
			buttonDetails = '<a href="#" onclick="return showHideDetails(this,' + mysquare + ');" style="font-size: 11px">Show full details</a>';
		}

		var avatar = serviceRow[14];

		if (!avatar) {
			avatar = 'rsrc/noavatar.gif';
		}

		html = '';
		if (mysquare) {
			html = '<div class="userProfile">';
		}

		if (serviceRow[25]) {
			user_icon = '<img src="' + serviceRow[25] + '"  style="padding-left:10px;">';
		}

		html +=	'<div class="dhead">'+
				'<div style="float:left;">'+
				'<h1 style="font-size:22px;font-weight:normal;">' + serviceRow[4] + user_icon + '</h1></div><div class="item_status" style="float:right;"><img src="' + serviceRow[26] + '" width="30" height="7"></div><div class="cleaner"></div>'+
				'</div>'+
				'<div>'+
					'<div style="float:left;margin:0 10px 0 0">'+
						'<img src="' + avatar + '" style="width:80px;"/>'+
					'</div>'+
					'<div style="float:left;margin:0;padding:0;width:200px;">';


		if (serviceRow[5]) {
			html +=	'<font class="GoldText"><b><b>Link:</b></font> <a href="http://squa.re/' + serviceRow[5] + '">http://squa.re/' + serviceRow[5]  +'</a><br />';
		}

		if (serviceRow[7]) {
			//html +=	'<font class="GoldText"><b><b>Age:</b></font> ' + serviceRow[7] + '<br />';
		}

		if (serviceRow[11]) {
			html +=	'<font class="GoldText"><b><b>Sex:</b></font> ' + serviceRow[11]  +'<br />';
		}


		var website = ''
		if (serviceRow[23]) {
			website = serviceRow[23].toLowerCase().replace('http://', '');
		}



		html +=	'<font class="GoldText"><b>Location:</b></font> ' + serviceRow[13] + '<br />'+
						'<font class="GoldText"><b><b>Type:</b></font> ' + serviceRow[34] + '<br />'+
						'<font class="GoldText"><b><b>Vertical:</b></font> ' + serviceRow[21] + '<br />'+
						'<font class="GoldText"><b><b>Network:</b></font> ' + serviceRow[22] + ''+
					'</div>'+
					'<div style="float:left;text-align:right;">'+
						buttonsHTML +
						'<div style="padding:20px 0 0 0">' +
						buttonDetails +
						'</div>' +
					'</div>'+
				'<div class="cleaner"></div></div>'+
				'<div class="hatch">'+
  						'<div class="dbody ifhatched" id="member_details">'+
						'<table cellpadding="0" cellspacing="0" style="width:100%;" >'+
						'<tr><td style="text-align: center;"><img id="scrollUp" src="rsrc/scroll8.gif" class="button" alt="" title="scroll up" width="13" height="13" onmousedown="return upScroll(\'member_details_data\');" onmouseup="return stopScroll(this);" onmouseout="return stopScroll(this);" /></td></tr>'+
						'<tr><td>'+
						'<div style="height: 249px; overflow-x:hidden;overflow-y:hidden;" id="member_details_data"></div></td></tr>' +
						'<tr><td  style="text-align: center;"><img id="scrollDown" src="rsrc/scroll2.gif" class="button" alt="" title="scroll down" width="13" height="13" onmousedown="return downScroll(\'member_details_data\');"" onmouseup="return stopScroll(this);" onmouseout="return stopScroll(this);" /></td></tr>'+
						'</table>' +
						'</div>';


		if (mysquare) {
			html += '</div>';
		}
	}
	$('side_head').innerHTML = html;

	if (mysquare) {
		callMemberQuestionDetails(serviceRow[0], serviceRow[33], website);
	} else {
		//showHideDetails(null, mysquare);
		$("channel_name").innerHTML = serviceRow[4];
		//buildPrivateChannelMsg(serviceRow[4]);
	}

	return mysquare;

}



function callMemberQuestionDetails (user_id, network_id, website) {

	try {

		var connector = new AjaxConnector();
		var service = new Service("A1-005", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
		service.setMethod('GET');
		service.addParameter("language", oEnviroment.getLanguage().getID());
		service.addParameter("user", user_id);
		service.addParameter("network_type", network_id);
		service.addParameter("website", website);
		service.setOnServiceComplete(null, 'buildMemberQuestionDetails');
		connector.asyncRun(service);

	} catch (e) {
	}

}



function buildMemberQuestionDetails (service) {

	var html = '<table cellpadding="0" cellspacing="0" class="form">';
	var counter = 0;

	if (service !==null) {
		var website = service.getParameterByKey('website');
		if (!service.getResult().hasErrors()) {
			while (service.getResult().hasNext()) {
				var serviceRow = service.getResult().getCurrentRow().split("|!|");
				var answer = '' + serviceRow[3];
				counter++;
				if (answer.length > 0) {
					html += '<tr>' +
								'<td>' +
									'<p><font class="GoldText"><b>' + serviceRow[2] + '</b></font> ' + serviceRow[3] + '</p>' +
								'</td>' +
							'</tr>';
				}
				service.getResult().moveNext();
			}
		}

		if (website) {
			html += '<tr><td><font class="GoldText"><b>Website:</b></font>&nbsp;<a href="http://' + website + '" target="_blank">' + website + '</a></td></tr>';
		}
	}

	html += '</table>';
	$('member_details_data').innerHTML = html;

}



function showEntryReport(node, entry_type, entry_id) {

	html = '<form name="frmReport" id="frmReport">' +
			'<div style="overflow:auto;">' +
			'<h3 style="margin:0;padding:0;color:#A0917E;font-family:arial;font-size:14px;">REPORT THIS ENTRY</h3><br/>' +
			'<p><input type="hidden" id="errorMessage" class="text" size="0" value=""/><em class="ok"></em></p>' +
		   	'<table class="form long" cellspacing="0">'+
				'<tr>' +
					'<th><p>Reason</p></th>' +
					'<td>' +
						'<p><textarea cols="70" rows="12" id="field_report_msg"></textarea><em class="ok"></em></p>' +
					'</td>' +
				'</tr>' +
		   		'<tr>' +
					'<th>' +
					'</th>' +
					'<td width="240px" align="right">' +
						'<p><a href="javascript:report_entry_send(document.frmReport, \'' + entry_id + '\', \'' + entry_type + '\');"><img src="localized/en/button_submit_comment.gif" /></a>' +
						'&nbsp;<a href="javascript:oModalWindow.close();"><img src="localized/en/button_cancel_comment.gif" /></a>&nbsp;&nbsp;</p>' +
					'</td>' +
				'</tr>' +
			'</table>' +
			'</div></form>';

	oModalWindow = new Control.Modal(false, {
						containerClassName: 'modalWindowContainer',
						overlayClassName: 'modalWindowOverlay',
						overlayCloseOnClick: false,
						fade: false,
						contents: html
						});

	oModalWindow.open();
}



function showVideo(url){ //load SWF into DIV#videoSWF_holder
	var so = new SWFObject("rsrc/SquarePlayer.swf","my_ssp","514", "386", "7");
	so.addParam("wmode", "transparent");
	so.addParam('allowFullScreen','true');
	so.addVariable('xmlfile',url);
	so.addVariable('media','video');
	so.addVariable('quality','hight');
	so.addVariable('align','middle');
	so.addVariable('allowScriptAccess','sameDomain');
	so.addVariable('play','true');
	so.addVariable('loop','false');
	so.addVariable('scale','showall');
	so.addVariable('devicefont','false');
	so.write("videoSWF_holder");
	playerStatusEnded = false;

	return false;
}



function showSlideshow(url){ //load SWF into DIV#videoSWF_holder

	var so = new SWFObject("rsrc/SquarePlayer.swf","my_ssp","514", "386", "7");
	so.addParam("wmode", "transparent");
	so.addParam('allowFullScreen','true');
	so.addVariable("xmlfile",url);
	so.addVariable('media','slide');
	so.addVariable('quality','hight');
	so.addVariable('align','middle');
	so.addVariable('allowScriptAccess','sameDomain');
	so.addVariable('play','true');
	so.addVariable('loop','false');
	so.addVariable('scale','showall');
	so.addVariable('devicefont','false');
	so.write("videoSWF_holder");
	playerStatusEnded = false;

	return false;

}


function welcome_show() {
	if (oVLOG.isVisible()) {
		$('txt_fullwelcome').className = 'ifhatched';
		$('txt_smallwelcome').className = 'ifunhatched';
		$('scrollers').style.display = '';
		$('welcome_link').src = 'rsrc/button_sm_h3show-1.gif';
		oVLOG.setInvisible();

	} else {
		$('txt_fullwelcome').className = 'ifunhatched';
		$('txt_smallwelcome').className = 'ifhatched';
		$('scrollers').style.display = 'none';
		$('welcome_link').src = 'rsrc/button_sm_h3show-0.gif';
		oVLOG.setVisible();

	}

	return false;

}



/****************************************************

 * Main screen refresh events

 ****************************************************/

function welcome_refresh() {

	// Welcome loading service
	if (activeSection[PARAM_INDEX_SECTION].toUpperCase() != 'MAIN') {
		var today = new Date();
		var connector = new AjaxConnector();
		var service = new Service("A0-006", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
		service.setMethod('POST');
		service.addParameter("language", oEnviroment.getLanguage().getID());
		service.addParameter("section", activeSection[PARAM_INDEX_SECTION].toUpperCase());
		service.addParameter("date", today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate() );
		service.setOnServiceComplete(this, 'welcomeHandler');
		connector.asyncRun(service);

	} else {
		setWelcomeHtml("You're ON the Main Channel", "", "WELCOME TO SQUA.RE");
	}
}


function welcomeHandler(service) {
	if (service !==null) {
		if (!service.getResult().hasErrors()) {
			var serviceRow = null;
			hasWelcome = true;
			if (service.getResult().hasNext()) {
				serviceRow = service.getResult().getCurrentRow().split("|!|");
				oVLOG.setBigSize();

				setWelcomeHtml(serviceRow[2], serviceRow[3], serviceRow[1]);
			}
		}
	}
}

function search_click(section, filter, text, description) {

	if (!hasWelcome) { welcome_refresh(); }
	showSearchResultTab(description, text);
	document.getElementById('embedCode_div').style.display = 'none';
	oVLOG.clear();
	//oVLOG.lastServiceName = 'B0-004' + section + filter + text + oEnviroment.getUser().getID();
	oVLOG.runSearchService(section, filter, text, oEnviroment.getUser().getID(), 0, 100);

}


function grid_video_click(element, video, entry_id) {
	var showEmbed = ($('ixMenuSWF_holder').innerHTML != '');

	if (element) { hatchVideo(element, video); }

	document.getElementById('embedCode_div').style.display = 'none';
	if (document.getElementById('embed_code_' + entry_id) && showEmbed) {
		document.getElementById('embed_code').value = document.getElementById('embed_code_' + entry_id).value;
		document.getElementById('embedCode_div').style.display = 'none';
	}

	var connector = new AjaxConnector();
	var service = new Service("C0-003", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
	service.setMethod('POST');
	service.addParameter("language", oEnviroment.getLanguage().getID());
	service.addParameter("content_type", 1);
	service.addParameter("entry", entry_id);
	service.addParameter("section", activeSection[PARAM_INDEX_SECTION].toUpperCase());
	service.setOnServiceComplete(this, 'counterHandler');

	connector.asyncRun(service);
}



function grid_slide_click(element, slide ,entry_id) {
	var showEmbed = ($('ixMenuSWF_holder').innerHTML != '');
	if (element) { hatchSlideshow(element, slide); }

	document.getElementById('embedCode_div').style.display = 'none';
	if (document.getElementById('embed_code_' + entry_id) && showEmbed) {
		document.getElementById('embed_code').value = document.getElementById('embed_code_' + entry_id).value;
		document.getElementById('embedCode_div').style.display = 'none';
	}

	var connector = new AjaxConnector();
	var service = new Service("C0-003", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
	service.setMethod('POST');
	service.addParameter("language", oEnviroment.getLanguage().getID());
	service.addParameter("content_type", 2);
	service.addParameter("entry", entry_id);
	service.setOnServiceComplete(this, 'counterHandler');
	connector.asyncRun(service);
}

function counterHandler(service) {
	if (service !==null) {
		if (service.getResult().hasErrors()) {
			showErrorMessage('Error', 'Counter update error', '');
		}
	}
}

