/****************************************************
 *Grid tabs change events
 ****************************************************/
function content_change(value) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	activeSection[PARAM_INDEX_CATEGORY] = value;
	showContent(selectedMember);
}

function members_change(value) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = value;
	showContent(selectedMember);
}

function events_change(value) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = value;
	showContent(selectedMember);
}

function tags_change(value) {
	activeSection[PARAM_INDEX_TAG] = value;
	showContent(selectedMember);
}

/****************************************************
 * General Grid change events
 ****************************************************/
function submenu_channel_click(key) {
	activeSection[PARAM_INDEX_TAG] = '';
	activeSection[PARAM_INDEX_CATEGORY] = 'content';
	updateMenus(PARAM_INDEX_AREA);
	showContent(selectedMember);
}

function submenu_mostpopular_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	activeSection[PARAM_INDEX_TAG] = '';
	updateMenus(PARAM_INDEX_AREA);
	showContent(selectedMember);
}

function submenu_members_click(key) {
	activeSection[PARAM_INDEX_TAG] = '';
	updateMenus(PARAM_INDEX_AREA);
	showContent(selectedMember);
}

function submenu_comments_click(key) {
	activeSection[PARAM_INDEX_TAG] = '';
	updateMenus(PARAM_INDEX_AREA);
	showContent(selectedMember);
}

function submenu_events_click(key) {
	activeSection[PARAM_INDEX_TAG] = '';
	updateMenus(PARAM_INDEX_AREA);
	showContent(selectedMember);
}

function submenu_messages_click(key) {
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
	showErrorMessage('Notice', 'Available on Phase 2', '');
}

function edit_event(entry_id) {
	showErrorMessage('Notice', 'Available on Phase 2', '');
}

function add_comment() {
	oVLOG.setStoped(true);
	$('loadingIndicator').style.display = 'none';
	showAddComment("side_ctntBody_ul", selectedMember);
}

function filter_uploads_click(key) {
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_added_click(key) {
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_content_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_members_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_events_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_contacts_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function filter_requests_click(key) {
	activeSection[PARAM_INDEX_ENTRY_TYPE] = 0;
	updateMenus(PARAM_INDEX_CATEGORY);
	showContent(selectedMember);
}

function grid_entry_report(node, entry_type, entry_id) {
	if (oEnviroment.isUserLogged()) {
		showEntryReport(node, entry_type, entry_id);
	} else {
		showErrorMessage('Login Error', 'You must be logged in to view this section', '');
	}
}

function report_entry_send(frm, entry_id, content_type) {
	if (validate_report(frm)) {
		var connector = new AjaxConnector();
		var service = new Service("C1-002", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
		service.addParameter("language", oEnviroment.getLanguage().getID());
		service.addParameter("entry", entry_id);
		service.addParameter("content_type", content_type);
		service.addParameter("nickname", oEnviroment.getUser().getNickname());
		service.addParameter("mail", oEnviroment.getUser().getMail());
		service.addParameter("reason", frm.field_report_msg.value);
		service.setOnServiceComplete(null, 'entryReportHandler');
		connector.asyncRun(service);
	}
}

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

function grid_entry_share(node, entry_type, entry_id) {
	var section = activeSection[PARAM_INDEX_SECTION];
	var area = activeSection[PARAM_INDEX_AREA];
	var currentEmail = '';
	var currentUser = '';

	if (oEnviroment.isUserLogged()) {
		currentUser = oEnviroment.getUser().getNickname();
		currentEmail = oEnviroment.getUser().getMail();
	}

	showShareEntry(section, area, entry_id, entry_type, currentUser, currentEmail);
}

function grid_entry_add(node, entry_type, entry_id, name) {
	if (!oEnviroment.isUserLogged()) {
		showErrorMessage('Login Error', 'You must be logged in to add contacts to your network', '');
	} else {
		if (entry_type == '3') {
			var msg = 'Are you sure you want to add' + name + ' to your network?';
			showConfirmWindow(msg, "entry_send('" + node.id + "','" + entry_type + "','" + entry_id +"')", "");
		} else {
			entry_send(node, entry_type, entry_id);
		}
	}
}



function entry_send(node_id, entry_type, entry_id) {
	var connector = new AjaxConnector();
	var service = new Service("C0-002", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
	service.addParameter("language", oEnviroment.getLanguage().getID());
	service.addParameter("entry", entry_id);
	service.addParameter("content_type", entry_type);
	service.addParameter('operation', 0);
	service.addParameter("container", node_id);

	service.setOnServiceComplete(null, 'gridEntryAddHandler');
	connector.asyncRun(service);
}



function grid_entry_join(node, entry_type, entry_id) {
	if (!oEnviroment.isUserLogged()) {
		showErrorMessage('Login Error', 'You must be logged in to join event', '');
	} else {
		var connector = new AjaxConnector();
		var service = new Service("C0-002", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
		service.addParameter("language", oEnviroment.getLanguage().getID());
		service.addParameter("entry", entry_id);
		service.addParameter("content_type", entry_type);
		service.addParameter('operation', 0);
		service.addParameter("container", node.id);

		service.setOnServiceComplete(null, 'gridEntryAddHandler');
		connector.asyncRun(service);
	}
}

function gridEntryAddHandler(service) {
	var msgText = '';
	if (service !==null) {

		if (!service.getResult().hasErrors()) {
			var serviceRow = service.getResult().getCurrentRow().split("|!|");
			var entry_id = service.getParameterByKey('entry');
			var type = service.getParameterByKey('content_type');
			if (type == 1 || type==2) {
	 			if (serviceRow[1] == 'added') {
					$('entry_add_' + entry_id).src = 'localized/en/icon_addedtonynet.gif';
				} else {
					$('entry_add_' + entry_id).src = 'localized/en/button_sm_add.gif';
				}
			} else if (type == 3) {
				if (serviceRow[1] == 'added') {
					msgText = 'Invitation has been sent';
					$('entry_add_' + entry_id).style.display='none';
				} else if (serviceRow[1] == 'exists') {
					msgText = 'You already have a pending request sent to this contact.';
					$('entry_add_' + entry_id).style.display='none';
				} else {
					$('entry_add_' + entry_id).src = 'localized/en/button_addmynetwork.gif';
				}

			} else {
				if (serviceRow[1] == 'added') {
					$('entry_add_' + entry_id).src = 'localized/en/icon_addedtonynet.gif';
				} else {
					$('entry_add_' + entry_id).src = 'localized/en/button_sm_join.gif';
				}
			}

			if (msgText) {
				showErrorMessage('Success', msgText, '');
			}

		} else {
			showErrorMessage('Service Error', 'Error adding entry to my square', '');
		}
	}
}

function send_comment(member_id) {
	var value = "" + document.frmComment.field_comment.value;
	if (member_id !==null ) {
		if (value.length) {
			showConfirmWindow('Post the comment?', "comment_doSave('" + member_id + "')", "");
		}
	}
}

function comment_doSave (member_id, value) {
	// Sending a comment to square
	var connector = new AjaxConnector();
	var service = new Service("C1-003", oEnviroment.getServicePath() + oEnviroment.getServletName(), oEnviroment.getUser().getSID());
	service.addParameter("language", oEnviroment.getLanguage().getID());
	service.addParameter("user", member_id);
	service.addParameter("comment", "");
	service.addParameter("text", "" + document.frmComment.field_comment.value);

	service.setOnServiceComplete(this, 'sendCommentHandler');
	connector.asyncRun(service);
}

function sendCommentHandler(service) {
	oVLOG.setStoped(false);
	submenu_comments_click('comments');
}


function goto_PrevPage() {

	var pageCounter = 0;
	if (oVLOG.getStart() > 0) {
		while (pageCounter * oVLOG.getNumber() < oVLOG.getTotal()) {
		    if($('page_' + pageCounter)) $('page_' + pageCounter).className= 'link';
			pageCounter++;
		}
		pageCounter = ((oVLOG.getStart() / oVLOG.getNumber()) -1);
		if($('page_' + pageCounter)) $('page_' + pageCounter).className='linkSelected';

		showContent(selectedMember, true, pageCounter * oVLOG.getNumber());
	} else {
		//$('page_' + ((start / oVLOG.getNumber()) + 1)).className='link';
		if($('page_' + pageCounter)) $('page_' + (pageCounter)).className='linkSelected';
	}
}

function goto_NextPage() {
	var start = oVLOG.getStart() + oVLOG.getNumber();
	if (start < oVLOG.getTotal()) {
		var pageCounter = 0;
		while (pageCounter * oVLOG.getNumber() < oVLOG.getTotal()) {
			$('page_' + pageCounter).className= 'link';
			pageCounter++;
		}
		$('page_' + (start / oVLOG.getNumber())).className='linkSelected';
		showContent(selectedMember, true, start);
	}
}

function goto_Page(start) {
	var pageCounter = 0;
	while (pageCounter * oVLOG.getNumber() < oVLOG.getTotal()) {
		$('page_' + pageCounter).className= 'link';
		pageCounter++;
	}
	$('page_' + (start / oVLOG.getNumber())).className='linkSelected';

	showContent(selectedMember, true, start);
}

function onVideoPlaybackEnd() {
	//oVLOG.playNextMedia();
}

function onSlidePlaybackEnd() {
	oVLOG.playNextMedia();
}

function mysquare_view_entry(type, media, title) {
	if (type==1) {
		showMediaPlayerWindow('video', media, title);
	} else {
		showMediaPlayerWindow('slideshow', media, title);
	}

}

function showMediaPlayerWindow(type, media, title) {
	 html = '<div style="overflow:auto;">' +
			'<h3 style="margin:0;padding:0;color:#A0917E;font-family:arial;font-size:14px;">' + title + '</h3>' +
		   	'<table class="form long" cellspacing="0" width="460px">'+
				'<tr>' +
					'<td>' +
						'<embed type="application/x-shockwave-flash" src="rsrc/SquarePlayer.swf" id="my_ssp" name="my_ssp" quality="high" wmode="transparent" allowfullscreen="true" flashvars="xmlfile=' + media + '&amp;media='+ type + '&amp;quality=hight&amp;align=middle&amp;allowScriptAccess=sameDomain&amp;play=true&amp;loop=false&amp;scale=showall&amp;devicefont=false" height="386" width="514">' +
					'</td>' +
				'</tr>' +
		   		'<tr>' +
					'<td align="right">' +
						'<a href="javascript:oModalWindow.close();"><img src="localized/en/button_cancel_comment.gif" /></a>&nbsp;&nbsp;</p>' +
					'</td>' +
				'</tr>' +
			'</table>' +
			'</div>';


	oModalWindow = new Control.Modal(false, {

						containerClassName: 'modalWindowContainer',
						overlayClassName: 'modalWindowOverlay',
						overlayCloseOnClick: false,
						fade: false,
						contents: html
						});

	oModalWindow.open();
}
