/*global $, document */var oDefaultLoadingImg;
var oWorldLoadingImg;
var oGearsLoadingImg;

function reg_process() {
	var sRegFirstName = $('#reg_user_fname').val();
	var sRegLastName = $('#reg_user_lname').val();
	var sRegEmail = $('#reg_user_email').val();
	var sRegPasswd = $('#reg_user_passwd').val();
	
	if (sRegFirstName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_fname);
		return;
	}
	
	if (sRegLastName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_lname);
		return;
	}
	
	if (sRegEmail === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email);
		return;
	}
	
	if (sRegPasswd === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_password);
		return;
	}	
	
	
	$.post('/join_ajax/get_reg_process', {}, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
		
		$.prompt(data.sContent, {
			prompt_height: 338,
			prompt_cont_height: '380',
			prompt_cont_padding: '70px 25px 5px 25px',
			prompt_background: 'url(/images/popups/tbn/blue_medium.gif)',
			prompt_buttons: {}
		});
		
	}, 'json');
}





function reg_process_join(oObj, sPath) {
	/*
	
	reg_user_fname
	reg_user_lname
	reg_user_email
	reg_user_passwd
	reg_user_email_reenter
	captcha_answer
	*/
	var sCaptchaString = $('#captcha_sum').attr('name').replace('captcha_', '');
	
	var sJoinEmail = $('#reg_user_email').val();
	
	var sJoinEmailRetype = $('#reg_user_email_reenter').val();
	
	var sJoinPassword = $('#reg_user_passwd').val();
	
	var sJoinFirstName = $('#reg_user_fname').val();
	
	var sJoinLastName = $('#reg_user_lname').val();
	
	var sJoinCaptcha = $('#captcha_answer').val();
	
	
	
	if (sJoinFirstName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_fname);
		return;
	}
	
	if (sJoinLastName === '') {
		$.prompt(oSiteMessages.tbn_alert_profile_enter_lname);
		return;
	}
	
	if (sJoinEmail === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email);
		return;
	}
	
	if (sJoinPassword === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_password);
		return;
	}
	
	if (validate_email(sJoinEmail) === false) {
		$.prompt(oSiteMessages.tbn_alert_invalid_email);
		return;
	}
	
	if (sJoinEmail !== sJoinEmailRetype) {
		$.prompt(oSiteMessages.tbn_alert_emails_differ);
		return;
	}
	
	if (sJoinPassword.length < oSiteVariables.min_password_length) {
		var sMessage = oSiteMessages.tbn_alert_password_length_short;
		sMessage = sMessage.replace(/__length__/g, oSiteVariables.min_password_length);
		$.prompt(sMessage);
		return;
	}
	
	
	var oPassthru = {
		sCaptchaString: sCaptchaString,
		sJoinEmail: sJoinEmail,
		sJoinEmailRetype: sJoinEmailRetype,
		sJoinPassword: sJoinPassword,
		sJoinFirstName: sJoinFirstName,
		sJoinLastName: sJoinLastName,
		sJoinCaptcha: sJoinCaptcha
	};
	
	
	$.post('/join_ajax/join_tbn_process', oPassthru, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
		
		
		if (data.sUserValid === 'Y') {
			$.prompt(oSiteMessages.tbn_alert_reg_complete, {
				prompt_callback : function() {
					location.href = sPath;	
				}
			});
			
		}
	}, 'json');
	
	
}



function captcha_help() {
	create_popup(450, 450, oSiteMessages.link_popup_help, function() {
		$.post('/join_ajax/captcha_popup', {  }, 
			function(data) {
				
				if (data.sError) {
					$.prompt(data.sError);
					return;
				}				
				
				$('.tbn_popup_container_content').html(data.sContent);
			}, 
			'json'
		);
	});
}





function user_forgot_passwd() {
	var oInput = document.createElement('input');
	
	$(oInput).attr({
		id: 'tbn_prompt_forgot_passwd'
	}).addClass('form_el').attr({
		size : '20',
		maxlength : '70',
		value : ''
	}).css({
		paddingLeft : '5px'
	});
	
	var oDiv = document.createElement('div');
	
	$(oDiv).css({
		padding : '5px'
	}).append(oInput);
	
	$.prompt(oSiteMessages.tbn_alert_forgot_passwd_enter_email, {
		prompt_buttons: {
			ok : true,
			cancel : false
		},
		prompt_cont_append : oDiv,
		prompt_remove_timeout : 2000,
		prompt_loaded: function() {
			$('#tbn_prompt_forgot_passwd').focus();
		},
		prompt_callback : function(bReturn) {
			if (bReturn) {
				var user_email = $('#tbn_prompt_forgot_passwd').val();
				
				$.post('/users_ajax/send_forgot_password', { user_email : user_email }, function(data) {

					if (data.sError) {
						$.prompt(data.sError);
						return;
					}							
					
					if (data.sUserValid === 'N') {
						$.prompt(oSiteMessages.tbn_alert_no_account_email);
						return;
					}
					
					if (data.sMessage) {
						$.prompt(data.sMessage);
					}
					
				}, 'json');
			}
		}
	});
}


function user_login()
{
	var user_email = $('#user_email').val();
	var user_passwd = $('#user_passwd').val();
	var user_logon = 'Y';
	
	if (user_email === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_email, {
			prompt_cont_css : {
				textAlign : 'center',
				paddingTop : '100px',
				height: '50px'
			}
		});
		return false;
	} else if (user_passwd === '') {
		$.prompt(oSiteMessages.tbn_alert_missing_password, {
			prompt_cont_css : {
				textAlign : 'center',
				paddingTop : '100px',
				height: '50px'
			}
		});
		return false;
	} else if (!validate_email(user_email)) {
		$.prompt(oSiteMessages.tbn_alert_invalid_email, {
			prompt_cont_css : {
				textAlign : 'center',
				paddingTop : '100px',
				height: '50px'
			}
		});
		return false;
	}
	
	var user_remember = $('#user_remember:checked').length === 1 ? 'Y' : 'N';
	
	$.post('/users_ajax/check_user_credentials', { user_email : user_email, user_passwd : user_passwd, user_logon : user_logon, user_remember : user_remember }, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
				
		if (data.sUserValid === 'Y') {
			if (data.sUserRegistered === 'N') {
				$.prompt(oSiteMessages.tbn_alert_registration_incomplete, {
					prompt_buttons : {
						resend_confirmation : true,
						cancel : false
					},
					prompt_callback : function(bReturn) {
						if (bReturn) {
							$.post('/users_ajax/resend_confirmation', { user_email : user_email}, function(data) {
								if (data.sError) {
									$.prompt(data.sError);
									return;
								}
								
								if (data.sMessage) {
									$.prompt(data.sMessage);
								}
							}, 'json');
						}
					}
				});
			} else {
				setTimeout('location.reload()', 500
				);
			}
		} else {
			$.prompt(oSiteMessages.tbn_alert_invalid_credentials, {
				prompt_buttons: { 
					forgot_password : true,
					cancel : false
				},
				prompt_callback : function(bReturn) {
					if (bReturn) {
						setTimeout(function() {
							user_forgot_passwd();
						}, 500);
					}
				}
			});
		}
			
	}, 'json');
}





function create_default_loading_image() {
	oDefaultLoadingImg = document.createElement('img');
	
	$(oDefaultLoadingImg).attr({
		src : '/images/ajax_loading/web/loading_bar.gif',
		alt : oSiteMessages.alt_ajax_loading
	}).css({
		margin : '0px auto'
	});
}


function create_world_loading_image() {
	oWorldLoadingImg = document.createElement('img');
	$(oWorldLoadingImg).attr({
		src : '/images/ajax_loading/web/loading_world.gif',
		alt : oSiteMessages.alt_ajax_loading
	}).css({
		margin : '0px auto'
	});
}


function create_gears_loading_image() {
	oGearsLoadingImg = document.createElement('img');
	$(oGearsLoadingImg).attr({
		src : '/images/ajax_loading/web/loading_gears.gif',
		alt : oSiteMessages.alt_ajax_loading
	}).css({
		margin : '0px auto'
	});
}

function input_default_value(oObj, sAction, bEmptyVal) {
	if (sAction === 'set') {
		if (!$(oObj).data('default_value')) {
			var sDefaultValue = $(oObj).val();
			$(oObj).data('default_value', sDefaultValue);
		}
		
		if (bEmptyVal) {
			if ($(oObj).val() === $(oObj).data('default_value')) {
				$(oObj).val('');
			}
		}
	} else {
		var sCurrentValue = $(oObj).val();
		
		if (sCurrentValue === '')
		{
			$(oObj).val($(oObj).data('default_value'));
		}
	}
	
}



function set_tag_line(sGroupAppClass, sText, sAction) {
	if (sGroupAppClass === 'top_menu_end') {
		if (sAction === 'over') {
			$('#top_menu_left').addClass('left_over');		
		} else {
			$('#top_menu_left').removeClass('left_over');
		}
	}
	
	$('#top_menu_tag_line').html(sText);
}



function forgot_password(oObj) {
	
}


function validate_email(sEmail) {
	var pattern = /^([a-zA-Z0-9'_.\-])+@([a-zA-Z0-9_.\-])+\.([a-zA-Z])+([a-zA-Z])+/;

    if (pattern.test(sEmail)){         
		return true;
    } else {   
		return false; 
    }

}



function accept_contact_request(oObj, iRequestId, iUserId, sId) {
	var bAnimSlide = true;
	
	$.post('/contacts_ajax/accept_contact_request', { iRequestId : iRequestId}, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
		if (data.sMessage === '') {
			
			if ($(sId).length === 1) {
				if (bAnimSlide) {
					$(sId).slideUp(1000, function() {
						$(sId).remove();
					});				
				} else {
					$(sId).remove();
				}
			}
			

			
		} else {
			$.prompt(data.sMessage);
		}
	}, 'json');
}



function reject_contact_request(oObj, iRequestId, iUserId, sId) {
	var bAnimSlide = true;
	
	$.post('/contacts_ajax/reject_contact_request', { iRequestId : iRequestId}, function(data) {

		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
		if (data.sMessage === '') {
			
			//var oEl = sIdPrefix + iUserIdFrom + '_' + iUserIdTo;
			
			if ($(sId).length === 1) {
				if (bAnimSlide) {
					$(sId).slideUp(1000, function() {
						$(sId).remove();
					});				
				} else {
					$(sId).remove();
				}
			}
			

			
		} else {
			$.prompt(data.sMessage);
		}
	}, 'json');
}



function remove_contact(oObj, iUserId) {
	$.prompt(oSiteMessages.tbn_alert_confirm_remove_contact, {
		prompt_buttons : {
			ok : true,
			cancel : false
		},
		prompt_callback : function(bReturn) {
			if (bReturn) {
				$.post('/contacts_ajax/remove_contact', {
					iUserId: iUserId
				});
				
				$('#main_content').children('.tbn_seperator').remove();
				$('#tbn_user_' + iUserId).fadeOut(500, function() {
					$(this).remove();
					var oDiv = document.createElement('div');
					$(oDiv).addClass('tbn_seperator');
					
					$('#main_content').children('.tbn_user:odd').after(oDiv);
				});
			}
		}
	});
}



function remove_contact_request(oObj, iRequestId, iUserId, sId) {
	var bAnimSlide = true;
	
	$.post('/contacts_ajax/remove_contact_request', { iRequestId : iRequestId}, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
				
		if (data.sMessage === '') {
			
			if ($(sId).length === 1) {
				if (bAnimSlide) {
					$(sId).slideUp(1000, function() {
						$(sId).remove();
					});				
				} else {
					$(sId).remove();
				}
				
				if($('#app_contacts_sent').length === 1) {
					$('#app_contacts_sent').click();
				}
			}
			

			
		} else {
			$.prompt(data.sMessage);
		}
	}, 'json');
}



function send_contact_reminder(oObj, iRequestId, iUserId) {
	$.post('/contacts_ajax/send_contact_reminder', { iRequestId : iRequestId, iUserId : iUserId }, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
		
		if (data.sSent == 'Y') {
			var oSpan = document.createElement('span');
			
			$(oSpan).html(oSiteMessages.label_invite_resent);
			$(oObj).replaceWith(oSpan);
		} else {
			$.prompt(oSiteMessages.tbn_alert_reminder_failed);
		}
		
		
		
	}, 'json');
}


function resend_external_invite(oObj, iInviteId) {
	var oObjParent = $(oObj).parent();
	
	$.post('/contacts_ajax/resend_external_invite', { iInviteId : iInviteId }, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
				
		if (data.sSent) {
			oObjParent.text(oSiteMessages.label_external_contact_resent);
			
			notify_fade_bg(oObjParent);
		}
	}, 'json');

}



function remove_external_invite(oObj, iInviteId) {
	$.post('/contacts_ajax/remove_external_invite', { iInviteId : iInviteId });
	
	$('#tbn_ext_user_' + iInviteId).slideUp(1000, function() {
		$(this).remove();
		
		$('.tbn_seperator').remove();
		
		var oDiv = document.createElement('div');
		
		$(oDiv).addClass('tbn_seperator');
		
		$('.tbn_ext_user_mini_contacts:odd').after($(oDiv).clone());
		
	});
}

function notify_fade_bg(oObj) {
	$(oObj).animate( { backgroundColor:"#F2F2FF" }, { queue:true, duration:700 } )
         .animate( { backgroundColor:"#FFFFFF" }, 700 );
}


function create_overlay() {
	var oDiv = document.createElement('div');
	
	$(oDiv).css({
		position : 'absolute',
		top : '0px',
		left : '0px',
		width : $(document).width() + 'px',
		height : $(document).height() + 'px'
	}).attr('id', 'tbn_screen_overlay').appendTo(document.body);
	
	return oDiv;
}


function remove_overlay() {
	$('#tbn_screen_overlay').remove();
}


function create_popup(width, height, title, callback) {
	//check if there is already a popup open
	if($('.tbn_popup_container').length > 0) {
		return;
	}
	
	var oOverlay = create_overlay();
	
	var divId = 'tbn_screen_popup';
	
	var windowHeight = $(window).height();
	var windowWidth = $(window).width();
	var iScrollTop = $(window).scrollTop();
	
	var iTop = iScrollTop;
	var iLeft = 0;
	
	if(windowWidth > width) {
		iLeft = (windowWidth - width) / 2;
	}
	
	if(windowHeight > height) {
		var iTopExtend = (windowHeight - height) / 2;
		
		iTopExtend = (iTopExtend > 150) ? 150 : iTopExtend;
		
		iTop += iTopExtend;
	}
	
	//create main container
	var oDiv = document.createElement('div');
	
	$(oDiv).css({
		top : iTop+'px',
		left : iLeft+'px',
		width : width + 'px',
		height : 'auto',
		zIndex : '1000'
	}).attr({'id' : divId, 'class' : 'tbn_popup_container'}).appendTo(oOverlay);
	
	//add clearing divs
	var oClearDiv1 = document.createElement('div');
	$(oClearDiv1).attr({'class' : 'tbn_clear'});
	
	var oClearDiv2 = document.createElement('div');
	$(oClearDiv2).attr({'class' : 'tbn_clear'});
	
	var oClearDiv3 = document.createElement('div');
	$(oClearDiv3).attr({'class' : 'tbn_clear'});
	
	//add the styled top bar
	var oTopStyledLeft = document.createElement('div');
	
	$(oTopStyledLeft).attr({'class' : 'tbn_popup_top_left'}).appendTo(oDiv);
	
	//add the top bar
	var oTopStyledCenter = document.createElement('div');
	
	$(oTopStyledCenter).css({
		width : (width - 22) + 'px'
	}).attr({'id' : divId+'_top', 'class' : 'tbn_popup_top_center'}).appendTo(oDiv).html(title);
	
	var oTopStyledRight = document.createElement('div');
	
	$(oTopStyledRight).attr({'class' : 'tbn_popup_top_right'}).appendTo(oDiv);
	
	//add close button
	var oTopCloseDiv = document.createElement('div');
	
	$(oTopCloseDiv).attr({'id' : divId+'_top_close', 'class' : 'tbn_popup_container_close'}).appendTo(oTopStyledCenter).click(
		function() {
			remove_popup();
		}
	);
	
	$(oClearDiv1).appendTo(oDiv);
	
	//add the main content
	var oContentDiv = document.createElement('div');
	
	$(oContentDiv).css({
		width : (width - 4) + 'px',
		height : 'auto'
	}).attr({'id' : divId+'_content', 'class' : 'tbn_popup_container_content'}).appendTo(oDiv);
	
	//add a loading image
	var oLoadingDiv = document.createElement('div');
	
	$(oLoadingDiv).attr('id', 'tbn_popup_loading_div').css({
		marginLeft : ((width/2)-110)+'px'
	});
	
	create_default_loading_image();
	
	$(oDefaultLoadingImg).appendTo(oLoadingDiv);
	
	$(oLoadingDiv).appendTo(oContentDiv);
	
	//add a clearing div
	$(oClearDiv2).appendTo(oDiv);
	
	//check for a callback function
	if(typeof(callback) != "undefined") {
		callback();
	}
	
	$("#"+divId).draggable();
	
	return oDiv;
}

function remove_popup() {
	$('#tbn_screen_overlay').remove();
	remove_overlay();
}


function reprocess_tbn_user(iUserId) {
	//get the container class
	var sClass = $('#tbn_user_' + iUserId).attr('class');
	
	$.post('/contacts_ajax/reprocess_tbn_user', { iUserId : iUserId}, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
		$('#tbn_user_' + iUserId).replaceWith(data.sContent);
		
		//make sure that the new container has the same class
		if(sClass != 'undefined' && sClass.length > 0) {
			$('#tbn_user_' + iUserId).attr('class', sClass);
		}
	}, 'json');
}



function make_contact_request(oObj, iUserId) {
	
	$.post('/contacts_ajax/make_contact_request', { iUserId : iUserId }, function(data) {
		
		if (data.sError && (data.sError.length > 0)) {
			$.prompt(data.sError);
		} else {
			create_popup(390, 450, oSiteMessages.label_popup_invite_contact, function() {
				$('.tbn_popup_container_content').html(data.sContent);
			});
		}
	}, 'json');
}

function confirm_contact_request(iUserId) {
	var sContactRequestIntro = $('#contact_request_intro').val();
	
	$.post('/contacts_ajax/confirm_contact_request', { iUserId: iUserId, sContactRequestIntro: sContactRequestIntro }, 
		function(data) {
			if (data.sError) {
				$.prompt(data.sError);
			} else {
				//$.prompt(data.sMessage);
				
				reprocess_tbn_user(iUserId);
				
			}
			remove_popup();
		}, 
		'json'
	);
}



function retrieve_element_props(oObj) {
	var oObjProps = $(oObj).offset();
	oObjProps.outerHeight = $(oObj).outerHeight();
	oObjProps.outerWidth = $(oObj).outerWidth();
	
	return oObjProps;
}




function create_loading_overlay(sText, oCssOverRide) {
	var oDiv = create_overlay();
	
	var oDivLoading = document.createElement('div');
	var oImg = document.createElement('img');
	var oDivText = document.createElement('div');
	
	$(oDivText).html(sText);
	
	$(oImg).attr({
		src: '/images/ajax_loading/web/loading_bar.gif',
		alt : oSiteMessages.alt_ajax_loading
	});
	
	
	
	$(oDivLoading).addClass('tbn_full_loading_overlay').css(oCssOverRide).append(oImg).append(oDivText).appendTo(oDiv).show();
}



function toggle_portlet_content(oObj) {
	var sImgSrc = $(oObj).attr('src');
	
	if (sImgSrc.indexOf('/right_arrow.gif') !== -1) {
		sImgSrc = sImgSrc.replace('/right_arrow.gif', '/down_arrow.gif');
	} else {
		sImgSrc = sImgSrc.replace('/down_arrow.gif', '/right_arrow.gif');
	}
	
	$(oObj).attr('src', sImgSrc).parent().next().slideToggle('slow');
}



function tbn_alert_loading(sText) {
	var oDiv = document.createElement('div');
	
	if (sText) {
		var oDivText = $(oDiv).clone(true);
		
		$(oDivText).html(sText).appendTo(oDiv);
	}
	
	$(oDiv).css('textAlign', 'center').append(oDefaultLoadingImg);
	
	
	$.prompt(oDiv, {
		prompt_buttons : {}
	});
}


function get_screen_center() {
	var iDocWidth = $(document).width();
	var iDocHeight = $(document).height();
	var iDocScrollTop = $(document).scrollTop();
	
	var oReturn = {};
	
	oReturn.left = Math.floor(iDocWidth / 2);
	oReturn.top = Math.floor((iDocHeight /2) + iDocScrollTop);
	
	return oReturn;
}


function slide_toggle_obj(oObj) {
	
}

function view_network(iAppId) {
	location.href = '/networks/view_network/network_id/' + iNetworkId + '.html';
}

function view_network_invite_contacts(iAppId) {
	location.href = '/networks/invite_contacts/network_id/' + iNetworkId + '.html';
}


function view_profile(iUserId) {
	location.href = '/profile/view/user_id/' + iUserId + '.html';
}

function user_logout() {
	$.post('/users_ajax/user_logout', {}, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
					
		if (data.sLoggedOut === 'Y') {
			setTimeout('location.reload()', 500);
		}
	}, 'json');
}


function network_request_membership(oObj, iNetworkId, sNetworkName, bRemoveTab) {
	$.post('/networks_ajax/request_membership', {iNetworkId : iNetworkId}, 
		function(data) {
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}
			
			if(bRemoveTab === true) {
				$(oObj).remove();
			} else {
				var oSpan = document.createElement('span');
				$(oSpan).css({color:'#666666', fontSize:'11px'}).html(oSiteMessages.label_network_request_sent_pending).replaceAll(oObj);
			}
			
			$.prompt(data.sMessage);
		}, 
		'json'
	);
}

function request_network_membership(iVal) {
	var oObj = $('#app_request_membership');
	
	if(oObj.length > 0) {
		network_request_membership(oObj, iNetworkId, '', true)
	}
}


function nudge_remove(iNudgeId, oCallback, oCallbackParam) {
	$.prompt(oSiteMessages.tbn_alert_confirm_remove_nudge, {
		prompt_buttons : {
			ok : true,
			cancel : false
		},
		prompt_callback : function(bReturn) {
			if (bReturn === true) {
				$.post('/nudge_ajax/nudge_remove', { iNudgeId : iNudgeId }, function(data) {
					if (data.sError) {
						$.prompt(data.sError);
						return;
					}
					
					if (data.sUpdated === 'N') {
						$.prompt(oSiteMessages.tbn_alert_nudge_remove_failed);
					} else {
						oCallback(oCallbackParam);
					}
				}, 'json');
				
			}
			
		}
	});
}



function email_user(oObj, iUserId) {
	location.href = '/inbox/email_user/' + iUserId;
}



function single_nudge_send(oObj, iUserId) {
	$('#nudge_data').data('data_obj', iUserId);
	nudges_send()
}



function nudges_send(){
	var sNudges = $('#nudge_data').data('data_obj');
	
	if (sNudges === '') {
		$.prompt(oSiteMessages.tbn_alert_nudge_none_selected);
		return;
	}
	
	
	tbn_alert_loading(oSiteMessages.alt_ajax_loading);
	
	$.post('/nudge_ajax/get_nudge_window', { sNudges : sNudges }, function(data) {
		$('#tbn_prompt_overlay').remove();
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}
		
		//remove_popup();
		
		//var oDivOverlay = create_overlay();
		
		create_popup(320, 320, oSiteMessages.label_popup_nudge, function() {
			$('.tbn_popup_container_content').html(data.sContent);
		});
		
		return;
		var oScreenCenter = get_screen_center();
		
		var oDiv = document.createElement('div');
		
		var iDivLeft = (oScreenCenter.left - Math.floor(data.iWidth/2));
		
		var iDocScrollTop = $(document).scrollTop();
		var iWindowHeight = $(window).height();
		
		// scolltop - ((window.height - nudge_height) / 2)
		var iPopupTop = iDocScrollTop + Math.floor((iWindowHeight - 480) / 2);
		
		//main_content
		$(oDiv).attr('id', 'nudge_window').css({
			position: 'absolute',
			top: iPopupTop + 'px',
			left: iDivLeft + 'px',
			height: 'auto'
		}).append(data.sContent).appendTo(oDivOverlay).parent().appendTo(document.body).show();
		
	}, 'json');
	
}



function select_contact_to_nudge(oObj, bAppend) {
	var prenudge_user_id = $(oObj).attr('id').replace('pre_nudge_', '');
	var sNudgeData = $('#nudge_data').data('data_obj');
	
	if ($(oObj).data('user_id') === undefined) {
		$(oObj).data('user_id', prenudge_user_id);//.fadeTo('slow', 0.33);
		if (bAppend === true) {
			sNudgeData += prenudge_user_id + ',';	
		}
		
	} else {
		$(oObj).removeData('user_id');//.fadeTo('slow', 1);
		sNudgeData = sNudgeData.replace(prenudge_user_id + ',', '');
	}
	
	$('#nudge_data').data('data_obj', sNudgeData);
}


function select_user_in_report(oObj, bAppend) {
	var report_user_id = $(oObj).attr('id').replace('report_select_', '');
	
	if($('#report_data').data('data_obj') === undefined) {
		$('#report_data').data('data_obj', '');
	}
	
	var sReportData = $('#report_data').data('data_obj');
	
	if ($(oObj).data('user_id') === undefined) {
		$(oObj).data('user_id', report_user_id);//.fadeTo('slow', 0.33);
		if (bAppend === true) {
			sReportData += report_user_id + ',';	
		}
		
	} else {
		$(oObj).removeData('user_id');//.fadeTo('slow', 1);
		sReportData = sReportData.replace(report_user_id + ',', '');
	}
	
	$('#report_data').data('data_obj', sReportData);
}

function select_ext_user_import(oObj, bAppend) {
	var ext_user_id = $(oObj).attr('id').replace('ext_import_select_', '');
	
	if($('#ext_import_data').data('data_obj') === undefined) {
		$('#ext_import_data').data('data_obj', '');
	}
	
	var sReportData = $('#ext_import_data').data('data_obj');
	
	if ($(oObj).data('user_id') === undefined) {
		$(oObj).data('user_id', ext_user_id);//.fadeTo('slow', 0.33);
		if (bAppend === true) {
			sReportData += ext_user_id + ',';	
		}
		
	} else {
		$(oObj).removeData('user_id');//.fadeTo('slow', 1);
		sReportData = sReportData.replace(ext_user_id + ',', '');
	}
	
	$('#ext_import_data').data('data_obj', sReportData);
}


function highlight_selected_contacts() {
	var sNudgeData = $('#nudge_data').data('data_obj');
	
	if (sNudgeData !== '') {
		var aNudgeData = sNudgeData.split(',');
		var iNudgeData = aNudgeData.length;
		
		var oTempObj;
		
		for (var i = 0; i < iNudgeData; i++) {
			oTempObj = $('#pre_nudge_' + aNudgeData[i]);
			
			if ($(oTempObj).length === 1) {
				select_contact_to_nudge(oTempObj, false);
			}
		}
	}
}



function nudges_send_confirm() {
	var oNudgeType = $('input:radio[name="nudge_type"]:checked');
	
	if ($(oNudgeType).length === 0) {
		$.prompt(oSiteMessages.tbn_alert_nudge_select_type);
		return;
	}
	
	var iNudgeType = $(oNudgeType).val();
	
	var sNudges = $('#confimed_nudges').val();
	
	var sNudgeMessage = $('#nudge_message').val();
	
	remove_popup();
	
	tbn_alert_loading(oSiteMessages.label_sending_nudge);
	
	$.post('/nudge_ajax/confirm_send_nudges', { sNudges : sNudges, iNudgeType : iNudgeType, sNudgeMessage : sNudgeMessage }, function(data) {
		
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
		
		$('#tbn_prompt_overlay').remove();
		//$.prompt(data.sMessage);
		$('#nudge_data').data('data_obj', '');
		//send_nudges(0);
		
		var oSpan;
		
		if (data.iNudgesSent === 1) {
			var iUserId = sNudges;
			
			oSpan = document.createElement('span');
			$(oSpan).css({
				cursor: 'default',
				color: '#666'
			}).html(oSiteMessages.label_user_nudged);
			
			$('#tbn_user_' + iUserId + '_nudge').replaceWith(oSpan);
		}
		else 
		{
			var aNudges = sNudges.split(',');
			var iNudges = aNudges.length;
			
			for (i = 0; i < iNudges; i++)
			{
				oSpan = document.createElement('span');
				$(oSpan).css({
					cursor: 'default',
					color: '#666'
				}).html(oSiteMessages.label_user_nudged);
				
				$('#tbn_user_' + aNudges[i] + '_nudge').replaceWith(oSpan);
			}
		}
		
		$.prompt(data.sMessage);
	}, 'json');
	
}




		
		

/*
| Generic Tag Helper Functions
*/
function clean_search_string(sString) {
	
	if(sString != '') {
		if(sString.indexOf(",") !== -1) {
			var iLastOcc = sString.lastIndexOf(",");
			sString = sString.substring(iLastOcc+1);
		}
	}
	
	return sString;
}

function get_current_tags(sString) {
	if(sString != '') {
		if(sString.indexOf(",") !== -1) {
			var iLastOcc = sString.lastIndexOf(",");
			sString = sString.substring(0, iLastOcc+1);
		} else {
			sString = '';
		}
	}
	
	return sString;
}

//sForce is used to force the helper to show or hide
//values can be show OR hide
function toggle_tag_helper(sForce) {
	if($('#tag_helper').length > 0) {
		
		if(sForce === 'show' || sForce === 'hide') {
			eval("$('#tag_helper')."+sForce+"()");
			
			return;
		}
		
		$('#tag_helper').toggle();
	}
}

function select_tag(oObj, sPlacmentElId) {
	var sTagText = $(oObj).html();
	sTagText = sTagText.replace("</strong>", "").replace("<strong>", "");
	
	var iTagId = $(oObj).attr('id');
	iTagId = iTagId.replace("tbn_tag_", "");
	
	var sCurrentTagsVal = $('#'+sPlacmentElId).val();
	
	sCurrentTagsVal = get_current_tags(sCurrentTagsVal);
	
	var sNewTags = sCurrentTagsVal+sTagText+",";
	
	toggle_tag_helper('hide');
	
	$('#'+sPlacmentElId).val(sNewTags);
}
/*
| END Generic Tag Helper Functions
*/

/*
| Improt Contacts 
*/

function import_contacts_select() {
	if($(".checkbox_checked[name='import_contacts_method']").length === 0) {
		$.prompt(oSiteMessages.tbn_alert_import_contacts_select_option);
		
		return;
	}
	
	var sMethod = $(".checkbox_checked[name='import_contacts_method']").attr('id');
	
	import_contacts_method(sMethod);
}

function import_contacts_method(sMethod) {
	$.post('/contacts_ajax/get_import_method_properties', { sMethod : sMethod },
		function(data) {

			if (data.sError) {
				$.prompt(data.sError);
				return;
			}			
			
			if(data.bUsername === true && data.bPassword === true) {
				import_contacts_prompt(sMethod, true, true, data.sPrompt);
			} else if(data.bUsername === true) {
				import_contacts_prompt(sMethod, true, false, data.sPrompt);
			} else {
				import_contacts_popup(sMethod, null, null)
			}
		}, 
		'json'
	);
}

function import_contacts_prompt(sMethod, bUser, bPass, sPrompt) {
	$.prompt(sPrompt, {
		prompt_buttons : {
			ok : 'ok',
			cancel : 'cancel'
		},
		prompt_loaded : function() {
			if($('#import_contacts_username').length == 0) {
				var oDiv = document.createElement('div');
				
				$(oDivSeparator).addClass('tbn_clear').css({ lineHeight : '20px' });
				
				var oDivSeparator = document.createElement('div');
				
				if(bUser === true) {
					var oUserDiv = document.createElement('div');
					
					$(oUserDiv).css({ padding : '5px', 'float' : 'left' });
					
					var oUserTitleDiv = document.createElement('div');
					
					$(oUserTitleDiv).css({ marginBottom : '5px' }).html(oSiteMessages.label_import_contacts_username);
					
					var oInputU = document.createElement('input');
					
					$(oInputU).attr({ type : 'text', name : 'import_contacts_username', id : 'import_contacts_username', size : '25', maxlength : '40' });
					
					$(oUserDiv).append(oUserTitleDiv).append(oInputU);
					
					$(oDiv).append(oUserDiv).append(oDivSeparator);
				}
				
				if(bPass === true) {
					var oPassDiv = document.createElement('div');
					
					$(oPassDiv).css({ padding : '5px', 'float' : 'left' });
					
					var oPassTitleDiv = document.createElement('div');
					
					$(oPassTitleDiv).css({ marginBottom : '5px' }).html(oSiteMessages.label_import_contacts_password);
					
					var oInputP = document.createElement('input');
					
					$(oInputP).attr({ type : 'password', name : 'import_contacts_password', id : 'import_contacts_password', size : '25', maxlength : '40' });
					
					$(oPassDiv).append(oPassTitleDiv).append(oInputP);
					
					$(oDiv).append(oPassDiv).append(oDivSeparator);
				}
				
				$(oDiv).appendTo($('#tbn_prompt_cont'));
			}
		},
		prompt_callback : function(sSubmit) {
			if (sSubmit === 'ok') {
				var sUsername = $('#import_contacts_username').length > 0 ? $('#import_contacts_username').val() : null;
				var sPassword = $('#import_contacts_password').length > 0 ? $('#import_contacts_password').val() : null;
				
				import_contacts_popup(sMethod, sUsername, sPassword);
			}
		}
	});
}

function import_contacts_popup(sMethod, sUsername, sPassword) {
	$.post('/contacts_ajax/get_import_destination', { sMethod : sMethod, sUsername : sUsername, sPassword : sPassword },
		function(data) {
			
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}			
			
			if(sMethod === 'csv') {
				create_popup(975, 600, oSiteMessages.label_popup_import_contacts, function() {
					$.post(data.sDestination, {}, 
						function(data) {
							$('.tbn_popup_container_content').html(data.sContent);
						}, 
						'json'
					);
					
					/*var oIframe = document.createElement('iframe');
					
					$(oIframe).css({
						width : '100%', 
						height : '610px',
						border: 'none'
					}).attr({'id' : 'advert_store_popup', 'src' : data.sDestination}).appendTo('.tbn_popup_container_content');*/
				});
			} else {
				$.prompt(data.sMessage, {
					prompt_callback : function() {
						location.href = data.sDestination;
					}
				});
			}
		}, 
		'json'
	);
}

/*
| END Improt Contacts 
*/

/* Discussions */
function open_discussion(iDiscussionId, sDiscussionTitle) {
	create_popup(800, 450, sDiscussionTitle, function() {
		$.post('/discussion_ajax/discussion_popup', { iDiscussionId : iDiscussionId }, 
			function(data) {
				
				if (data.sError) {
					$.prompt(data.sError);
					return;
				}				
				
				$('.tbn_popup_container_content').html(data.sContent);
			}, 
			'json'
		);
	});
}

function discussion_add_post(iDiscussionId, oObj) {
	
	$.post('/discussion_ajax/discussion_add_post', { iDiscussionId : iDiscussionId, iEntryId : null }, 
		function(data) {
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}
			
			$(oObj).parent('.discussion_entry_container').prev('.discussion_entry_placeholder').html(data.sContent).show();
		}, 
		'json'
	);
}

function discussion_reply_post(iDiscussionId, iEntryId, oObj) {
	var oParent = $(oObj).parent('.discussion_entry_container');
	var iMargin = oParent.css('margin-left');
	iMargin = iMargin.replace('px', '');
	iMargin = parseInt(iMargin);
	var oContainer = get_last_discussion_entry(oParent);
	
	$.post('/discussion_ajax/discussion_add_post', { iDiscussionId : iDiscussionId, iEntryId : iEntryId }, 
		function(data) {
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}
			
			oContainer.next('.discussion_entry_placeholder').css('margin-left', iMargin+15+'px').html(data.sContent).show();
		}, 
		'json'
	);
	
}

function get_last_discussion_entry(oObj) {
	var iMargin = $(oObj).css('margin-left');
	iMargin = iMargin.replace('px', '');
	iMargin = parseInt(iMargin);
	
	//get next discussion_entry_container
	var oNext = $(oObj).nextAll('.discussion_entry_container:first');
	
	var iNextMargin = oNext.css('margin-left');
	iNextMargin = iNextMargin.replace('px', '');
	iNextMargin = parseInt(iNextMargin);
	
	if(iNextMargin > iMargin) { 
		return get_last_discussion_entry(oNext);
	} else {
		return $(oObj);
	}
}

function discussion_add_entry(iDiscussionId, iEntryId, oObj) {
	var sPost = $(oObj).parent().siblings('textarea').val();
	var iMargin = $(oObj).parent().parent().css('margin-left');
	if(sPost === '') {
		return;
	}
	
	$.post('/discussion_ajax/discussion_add_post_add', { sPost : sPost, iDiscussionId : iDiscussionId, iEntryId : iEntryId, iMargin : iMargin }, 
		function(data) {
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}
			
			$(oObj).parent().parent().parent().replaceWith(data.sContent);
		}, 
		'json'
	);
}

function dyk_reject(oObj, iUserId, sView) {
	
	$(oObj).parent().parent().parent().slideUp(250, function(){
		$(this).remove();

		if ($('#main_content').length === 1) {
			$('#main_content').children('.tbn_seperator').remove();
			$('#main_content').children('.tbn_user:odd').after('<div class="tbn_seperator"></div>');
		}
	});
	
	
	$.post('/contacts_ajax/dyk_reject', { iUserId : iUserId });
	
	
}


function faq_close(oObj) {
	var sTopParentId = $(oObj).parent().parent().parent().attr('id');//mme_open_1
	if (sTopParentId === 'mme_cont') {
		$(oObj).parent().parent().prev().trigger('click');
	} else {
		var iOpenFaqId = $(oObj).parent().parent().attr('id').replace('mme_open_', '');
		
		remove_open_faq(oObj, iOpenFaqId);
	}
}


function remove_open_faq(oObj, iOpenFaqId) {
	$.post('/dash_ajax/close_open_faq', {
		iOpenFaqId: iOpenFaqId
	});
	
	$(oObj).parent().parent().remove();
}



/* Voice Conf */
function voice_conf_slide_up(iConfId) {
	if (!isNaN(iConfId)) {
		$('#tbn_voice_conf_' + iConfId).slideUp('2000', function() {
			$(this).remove();
		});
	}
}





function voice_conf_cancel(oObj, iConfId, fCallBack) {
	$.prompt(oSiteMessages.tbn_alert_confirm_cancel_voice_conf, {
		prompt_buttons : {
			ok : true,
			cancel : false
		},
		prompt_callback : function(bReturn) {
			if (bReturn) {
				tbn_alert_loading();
				
				
				$.post('/voice_conf_ajax/conf_cancel/conf_id/' + iConfId + '.html', {}, function(data) {
					$('#tbn_prompt_overlay').remove();
					
					if (data.sError) {
						$.prompt(data.sError);
						return;
					}
					
					if (data.sMessage) {
						$.prompt(data.sMessage, {
							prompt_callback : function() {
								if (data.sCancelled === 'Y') {
									fCallBack(iConfId);
								}
							}
						})
					}
				}, 'json');			
			}
		}
	})
}

function voice_conf_cancel_attend(oObj, iConfId, fCallBack) {
	$.prompt(oSiteMessages.tbn_alert_confirm_cancel_voice_conf, {
		prompt_buttons : {
			ok : true,
			cancel : false
		},
		prompt_callback : function(bReturn) {
			if (bReturn) {
				tbn_alert_loading();
				
				
				$.post('/voice_conf_ajax/conf_cancel_attend/conf_id/' + iConfId + '.html', {}, function(data) {
					$('#tbn_prompt_overlay').remove();
					
					if (data.sError) {
						$.prompt(data.sError);
						return;
					}
					
					if (data.sMessage) {
						$.prompt(data.sMessage, {
							prompt_callback : function() {
								if (data.sCancelled === 'Y') {
									fCallBack(iConfId);
								}
							}
						})
					}
				}, 'json');			
			}
		}
	})
}

function get_voice_conf_pricing(iCountryId) {
	$.post('/voice_conf_ajax/get_call_pricing', { iCountryId : iCountryId }, 
		function(data) {
			
			if (data.sError) {
				$.prompt(data.sError);
				return;
			}			
			
			$('#voice_conf_cpm').text(data.sCpm);
			$('#voice_conf_price_tax').text(data.sCpmTax);
			$('#voice_conf_price_mobile').text(data.sMobileCpm);
			$('#voice_conf_call_main_number').text(data.sNumber);
			$('#webinar_voice_conf_phone').text(data.sNumber);
			$('#voice_conf_notin_country').text(data.sCountryName);
		}, 
		'json'
	);
}






/** generic webinar functions **/

function webinar_slide_up(iWebinarId) {
	if (!isNaN(iWebinarId)) {
		$('#tbn_webinar_' + iWebinarId).slideUp('2000', function() {
			$(this).remove();
		});
	}
}



function webinar_cancel(oObj, iWebinarId, fCallBack) {
	$.prompt(oSiteMessages.tbn_alert_confirm_cancel_webinar, {
		prompt_buttons : {
			ok : true,
			cancel : false
		},
		prompt_callback : function(bReturn) {
			if (bReturn) {
				tbn_alert_loading();
				
				
				$.post('/webinars_ajax/webinar_cancel/webinar_id/' + iWebinarId + '.html', {}, function(data) {
					$('#tbn_prompt_overlay').remove();
					
					if (data.sError) {
						$.prompt(data.sError);
						return;
					}
					
					if (data.sMessage) {
						$.prompt(data.sMessage, {
							prompt_callback : function() {
								if (data.sCancelled === 'Y') {
									fCallBack(iWebinarId);
								}
							}
						})
					}
				}, 'json');			
			}
		}
	})
}



function webinar_view_delegates(oObj, iWebinarId, iOffset) {
	
	if ($(oObj).parent().next().hasClass('tbn_webinar_delegates')) {
		$(oObj).parent().next().slideUp(2000, function(){
			$(this).remove();
		});
	} else {
	
		tbn_alert_loading(oSiteMessages.tbn_alert_loading_delegates);
		
		$.post('/webinars_ajax/webinar_view_delegates/webinar_id/' + iWebinarId + '.html', {}, function(data) {
			
			$('#tbn_prompt_overlay').remove();

			if (data.sError) {
				$.prompt(data.sError);
				return;
			}
			
			
			if (data.iDelegates === 0) {
				$('#tbn_prompt_overlay').remove();
				$.prompt(oSiteMessages.tbn_alert_webinar_has_no_delegates);
				return;
			}
			
			var oDiv = document.createElement('div');
			
			//$(oDiv).addClass('tbn_webinar_delegates').html(data.sContent).insertAfter($(oObj).parent());
			
			$(oDiv).addClass('tbn_webinar_delegates').html(data.sContent).css({
				display: 'none'
			}).insertAfter($(oObj).parent()).slideDown(2000);
			
			
		}, 'json');
	}
}




function customise_your_experience() {
	$.post('/user_ajax/customise_your_experience', {}, function(data) {
		if (data.sError) {
			$.prompt(data.sError);
			return;
		}		
	}, 'json');
}



function popup_mme() {
	create_popup(450, 450, oSiteMessages.label_popup_what_can_i_do_next, function() {
		$.post('/user_ajax/popup_make_most_experience', {}, 
			function(data) {
				
				if (data.sError) {
					$.prompt(data.sError);
					return;
				}				
				
				$('.tbn_popup_container_content').html(data.sContent);
				
				$('.pmme_title').bind('click', function() {
					if ($(this).next().hasClass('pmme_content') === true) {
						
						$(this).next().slideToggle(1000, function() {
							if ($(this).css('display') === 'block') {
								var oPosition = $(this).position();
								var iHeight = $(this).height();
							
								var iParentHeight = $(this).parent().height();
								var iParentScrollTop = $(this).parent().scrollTop();
								
								if ((oPosition.top + iHeight) > iParentScrollTop) {
									iParentScrollTop = (oPosition.top + iHeight) - iParentHeight + iParentScrollTop;
									//console.log('setting iParentScrollTop: ' + iParentScrollTop);
									$(this).parent().animate({
										scrollTop: iParentScrollTop + 'px'
									}, 1000);
								}
								
							}
						});
					}
				});
				
				$('#pmme_cont').children('.pmme_content').draggable({
					helper: function() {
						var oEl = $(this).clone();
						
						$(oEl).appendTo(document.body);
						return oEl;
					}
				});
				
				$('#tbn_screen_popup').draggable( 'destroy' );
			}, 
			'json'
		);
	});
}


function addslashes(str) {
	str = str.replace(/\'/g, '\\\'');
	str = str.replace(/\"/g, '\\"');
	str = str.replace(/\\/g, '\\\\');
	str = str.replace(/\0/g, '\\0');
	return str;
}


$(document).ready(
	function() {

		_bTbnLoaded = true;
		
		setTimeout(function(){
			if($('#ws_home_cont').length == 1) {
				var sWsPortletId = $('#ws_home_cont').parent('.portlet_content').attr('id').replace('portlet_content_', '');
				
				//$('#tbn_dash_'+sWsPortletId).parent('.dash_col').width(770);
				
				//$('#tbn_dash_'+sWsPortletId).children('.tbn_portlet').children('.portlet_top').children('.dash_item_title').width(755);
				
				$('#ws_home_cont').flash({
					swf: '/flash/webstore/home_mini/webstore.swf',
					height: 402,
					width: 750, 
					params: {
						wmode: 'transparent'
					}
				});
				
				$('.dash_col').sortable('destroy');
			}
		}, 3000);

		var oDiv = document.createElement('div');
		$(oDiv).attr('id', 'nudge_data').data('data_obj', '').appendTo(document.body).hide();

		$('.pre_nudge').live('click', function() {
			select_contact_to_nudge(this, true);
		});
		
		$('.report_select').live('click', function() {
			select_user_in_report(this, true);
		});
		
		$('.report_update_select').live('click', function() {
			select_update_in_report(this, true);
		});
		
		$('.ext_import_select').live('click', function() {
			select_ext_user_import(this, true);
		});
		
		
		$('#language_select').children('select').bind('change', function() {
			$.post('/user_ajax/language_select', { iLangId : $(this).val() }, function() {
				location.reload();
			});
		});
		
		$('.checkbox_exclusive').live('click',
			function() {
				//handle unchecking
				var sClass = $(this).attr('class');
				
				if(sClass.search(/_checked/) > -1) {
					$(this).removeClass('checkbox_checked').addClass('checkbox_unchecked');
					return;
				}
				
				var sName = $(this).attr('name');
				
				$(".checkbox_exclusive[name='"+sName+"']").removeClass('checkbox_checked');
				$(this).addClass('checkbox_checked');
			}
		);
		
		$('.checkbox').live('click',
			function() {
				//handle unchecking
				var sClass = $(this).attr('class');
				
				if(sClass.search(/_checked/) > -1) {
					$(this).removeClass('checkbox_checked').addClass('checkbox_unchecked');
					return;
				}
				
				$(this).addClass('checkbox_checked');
			}
		);
		
		if(jQuery.livequery) {
			if ($('.click_blank').length > 0) {
				$('.click_blank').livequery('focus', function(){
					var sVal = $(this).val();
					
					if (typeof($(this).data('blank_value')) === 'undefined' || $(this).data('blank_value') === sVal) {
						$(this).data('blank_value', sVal);
						$(this).val('');
					}
				}).livequery('blur', function(){
					if ($(this).val() === '') {
						var sVal = $(this).data('blank_value');
						$(this).val(sVal);
					}
				});
			}
		}
		
		
		if($('.sub_menu_group').length > 0) {
			$('.sub_menu_group').hover(
				function() {
					$(this).css('text-decoration', 'underline');
				}, 
				function() {
					$(this).css('text-decoration', 'none');
				}
			);
		}
		
		
		
		$(document.body).droppable({
			accept: '.mme_content, .pmme_content',
			drop: function(event, ui) {
				
				if ($(ui.helper).hasClass('mme_content_exposed') === false) {
					var oEl = $(ui.helper).clone();
					
					/*					
					var oSpan = document.createElement('span');
					$(oSpan).addClass('tbn_link').html(oSiteMessages.alt_close).bind('click', function() {
						var iOpenFaqId = $(ui.helper).attr('id').replace('mme_open_', '');
						
						remove_open_faq(this, iOpenFaqId);
					});
					
					$(oEl).children('.mme_content_answer').append(oSpan)
					*/
					
					$(oEl).removeClass('ui-draggable').removeClass('ui-draggable_dragging').addClass('mme_content_exposed').draggable({
						helper: 'original'
					}).appendTo(document.body);
					
					var sFaqIdent = $(oEl).attr('id').replace('mme_', '');
					
					$(oEl).removeAttr('id');
		
					var oElOffset = $(oEl).offset();
					
					$.post('/dash_ajax/open_faq/', { sFaqIdent : sFaqIdent, iFaqTop : oElOffset.top, iFaqLeft : oElOffset.left }, function(data) {

						if (data.sError) {
							$.prompt(data.sError);
							return;
						}					
					
						if (data.sRemoveEl) {
							$(oEl).remove();
							return;
						}
						
						$(oEl).attr('id', 'mme_open_' + data.iOpenId);
					}, 'json');
					
				}
				else 
				{
					var iOpenFaqId = $(ui.helper).attr('id').replace('mme_open_', '');
					
					var oElOffset = $(ui.helper).offset();
					
					$.post('/dash_ajax/set_open_faq_pos', { iOpenFaqId : iOpenFaqId, iFaqTop : oElOffset.top, iFaqLeft : oElOffset.left });
						
				}
				
	
			}
	
		});
		
		
		
		$('.child_app').each(
			function(nr) {
				$(this).bind('click', { oObj : this }, function(e) {
					$('.child_app_selected').css({ color : '#FFFFFF', fontWeight : 'normal' }).removeClass('child_app_selected');
					$(e.data.oObj).children('.child_app_center').addClass('child_app_selected').css({ color : '#333333', fontWeight : 'bold' });
				}).hover(function() {
					if ($(this).children('.child_app_selected').length === 0) {
						$(this).children('.child_app_center').css({
							color: '#333'
						});
					}
				}, function() {
					if ($(this).children('.child_app_selected').length === 0) {
						$(this).children('.child_app_center').css({
							color: '#FFF'
						});
					}
					
				});
			}
		);
		
		
		//Form submission helper - for IE
		if($('.dynamic_button_submit_button').length > 0) {
			
			$('.dynamic_button_submit_button').each(
				function() {
					var oObj = $(this);
					oObj.parents('form:first').children().find('input').keyup(
						function(e) {
							if (e.keyCode == 13) {
								oObj.parents('form:first').children().find('input.dynamic_button_submit_button').click();
								
								return false;
							}
						}
					);
				}
			);		
		}

		
		$('.ws_create_info_btn, .ws_getting_started').live('click', function(){
			create_popup(1000, 650, 'Webstore Help', function() {
				
				$.post('/webstore/ajax/get_help', {}, function(data){
					$('.tbn_popup_container_content').html(data.sContent);
				}, 'json');
				
			});
		});

	}
);





