// rating
function submit_rating(type, member_id, content_id, score, url)
{
	$('#rating_'+type+'_progress'+content_id).show();

	$.post(virpath+'index.php?hp=1&m=rate', {'type':type,'score':score,'member_id':member_id,'content_id':content_id},
		function(response) {
			var response = response.split("\n");
			if ( response.length == 2 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					if ( typeof(url) != 'undefined' ) {
						window.location = url+'&ppid='+content_id+'&ps='+score;
					}
					else {
						var curr_score = parseFloat($('#rating_'+type+'_score'+content_id).html());
						var curr_votes = parseInt($('#rating_'+type+'_votes'+content_id).html());
						var new_score = curr_score*curr_votes+score;
						var new_votes = curr_votes+1;

						$('#rating_'+type+'_score'+content_id).html((new_score/new_votes).toFixed(2));
						$('#rating_'+type+'_votes'+content_id).html(new_votes);

						ratingstar_reset(type, content_id, 1);

						$('#rating_'+type+'_progress'+content_id).hide();
						return true;
					}
				}
			}

		}
	);
}

// reports
function submit_report(type, member_id, content_id, noreason)
{
	var reason = $('#report_'+type+'_reason'+content_id).val();
	if ( !reason ) { alert(noreason); return; }

	$('#report_'+type+'_progress'+content_id).show();

	$.post(virpath+'index.php?hp=1&m=report', {'type':type,'reason':reason,'member_id':member_id,'content_id':content_id},
		function(response) {
			var response = response.split("\n");
			if ( response.length == 2 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					$('#report_'+type+'_progress'+content_id).hide();
					$('#report_'+type+'_response'+content_id).html('<div class="response">' + response[1] + '</div>');
					setTimeout(function(){
						$('#report_'+type+'_response'+content_id).animate({ opacity: "hide" }, "slow");
					}, 2500);
					return true;
				}
			}

		}
	);
}

// send wink
function send_wink(member_id, message_id)
{
	window.location = virpath+'index.php?m=account_messages&p=quickmessage&id='+member_id+'&sid='+message_id;
}

// polls
function submit_poll(poll_id, answer_id, lang_votes)
{
	if ( answer_id == -1 ) {
		for ( var i = 0; document.getElementById('poll_' + poll_id + '_checkbox_' + i) != null; i++ ) {
			$('#poll_'+poll_id+'_bar_'+i).animate({opacity: "show"}, "fast");
			$('#poll_'+poll_id+'_checkbox_'+i).hide();
			$('#poll_'+poll_id+'_checkbox_'+i+'_obj').attr('disabled','disabled');
		}
		$('#poll_'+poll_id+'_results_view').hide();
		$('#poll_'+poll_id+'_results_wrap').show();
		return;
	}

	$('#poll_'+poll_id+'_progress').show();

	$.post(virpath+'index.php?hp=1&m=vote', {'poll_id':poll_id,'answer_id':answer_id},
		function(response) {
			var response = response.split("\n");
			if ( response.length == 3 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					$('#poll_'+poll_id+'_results').html(response[1]);
					$('#poll_'+poll_id+'_results_view').hide();
					$('#poll_'+poll_id+'_results_wrap').show();
					var votes = response[2].split(",");
					for ( var i = 0, totalvotes = votes.length; i < totalvotes; i++ ) {
						var counters = votes[i].split("=");
						if ( counters.length == 4 )
						{
							$('#poll_'+poll_id+'_results_'+counters[0]).html(counters[2]+'% ('+counters[1]+' '+lang_votes+')');
							//$('#poll_'+poll_id+'_results_'+counters[0]).html('('+counters[2]+'%)');
							$('#poll_'+poll_id+'_results_'+counters[0]).css('display', 'inline');
							$('#poll_'+poll_id+'_bar_'+counters[0]).css('width', counters[3]+'%');
							$('#poll_'+poll_id+'_bar_'+counters[0]).animate({opacity: "show"}, "fast");
							$('#poll_'+poll_id+'_checkbox_'+counters[0]).hide();
							$('#poll_'+poll_id+'_checkbox_'+counters[0]+'_obj').attr('disabled','disabled');
						}
					}
					$('#poll_'+poll_id+'_progress').hide();
					return true;
				}
			}
			else if ( response.length == 2 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					$('#poll_'+poll_id+'_results').html(response[1]);
					$('#poll_'+poll_id+'_results_wrap').show();
					for ( var i = 0; $('#poll_'+poll_id+'_checkbox_'+i) != null; i++ ) {
						$('#poll_'+poll_id+'_checkbox_'+counters[0]).hide();
						$('#poll_'+poll_id+'_checkbox_'+counters[0]+'_obj').attr('disabled','disabled');
					}
					$('#poll_'+poll_id+'_progress').hide();
					return true;
				}
			}
		}
	);
}

// vote icons
function ratingstar_toggle(type, content_id, score)
{
	for ( var i = 1; i <= 10; i++ ) {
		if ( i <= score ) {
			if ( $('#ratingstar'+content_id+'__'+i).hasClass("over") == false ) {
				$('#ratingstar'+content_id+'__'+i).addClass("over");
			}
		}
		else {
			$('#ratingstar'+content_id+'__'+i).removeClass("over");
		}
	}
}

function ratingstar_reset(type, content_id, lock)
{
	var score = Math.round($('#rating_'+type+'_score'+content_id).html());
	if ( score < 0 || score > 10 ) score = 0;
	for ( var i = 1; i <= 10; i++ ) {
		if ( i <= score ) {
			if ( $('#ratingstar'+content_id+'__'+i).hasClass("over") == false ) {
				$('#ratingstar'+content_id+'__'+i).addClass("over");
			}
		}
		else {
			$('#ratingstar'+content_id+'__'+i).removeClass("over");
		}
		if ( typeof(lock) != 'undefined' && lock ) {
			$('#ratingstar'+content_id+'__'+i).attr("onclick", "return false;");
			$('#ratingstar'+content_id+'__'+i).attr("onmouseover", "return false;");
			$('#ratingstar'+content_id+'__'+i).attr("disabled", "disabled");
		}
	}
}

function contacts_switchmail(type)
{
	emailtype = type;
	switch (type)
	{
		case 'custom':
			$('#field_email_custom').show();
			$('#field_email_public').hide();
			break;
		case 'aol':
			$('#field_email_public').show();
			$('#field_email_custom').hide();
			$('#emailext').html('');
			break;
		default:
			$('#field_email_public').show();
			$('#field_email_custom').hide();
			$('#emailext').html('@'+type+'.com');
			break;
	}
	$('#mem_username').val('')
	$('#mem_password').val('')
}

// check username

function checkusername(username,popup)
{
	if (username  != "") {
	$.post(virpath+'index.php?hp=1&m=checkusername', {'username':username},
		function(response) {
			var response = trim(response);
			response = response.split("\n");
			if ( response.length == 2 )
			{
				if (popup == 1) {
					if ( response[0] != 'ok') {
						$.facebox('<div class="info_modal" style="width:600px"><div class="inner">' + response[1] + '</div></div>');						
						//$('#field_username').focus();
					}
				} else {
					$('#field_username_status').html(response[1]);
					$('#field_username_status').removeClass('true');
					$('#field_username_status').removeClass('false');
					if ( response[0] == 'ok') {
						$('#field_username_status').addClass('true');
					}
					else {
						$('#field_username_status').addClass('false');
					}
					$('#field_username_status').show(300);
				}
			}

		}
	);
	}
}

// toggles
function row_toggle(name)
{
    for (var i = 0; document.getElementById(name+'_'+i) != null;  i++)
    {
        if (document.getElementById(name+'_'+i).style.display == "none")
            $('#'+name+'_'+i).show();
        else
            $('#'+name+'_'+i).hide();
    }
}

// switches
function row_switch(name)
{
    $('#'+active_tab).hide();
    $('#'+name).show();
    active_tab = name;
}

// tabs
var active_tab = 0;
var active_tab_first = 1;
function switch_tabs(prefix, new_tab, first, quick)
{
	if ( typeof(first) != 'undefined' && first == 1 ) {
		if ( active_tab_first == 1 ) {
			$('#'+prefix + '_' + new_tab + '_content').show();
			$('#'+prefix + '_' + new_tab + '_tab').addClass("active");
			active_tab = new_tab;
			active_tab_first = 0;
		}
	}
	else if ( active_tab != new_tab ) {
		$('#'+prefix + '_' + active_tab + '_content').hide(typeof(quick) == 'undefined' ? 0 : 0);
		$('#'+prefix + '_' + active_tab + '_tab').removeClass("active");

		$('#'+prefix + '_' + new_tab + '_content').show(typeof(quick) == 'undefined' ? 0 : 0);
		$('#'+prefix + '_' + new_tab + '_tab').addClass("active");
		active_tab = new_tab;
	}
}

function showhide_field(name, show, plain)
{
    if ( $('#'+name).css("display") == "none" && (show == undefined || show == '') || show == 1 )
    {
    	if ( plain == undefined ) {
        	$('#'+name).fadeIn("fast");
		}
		else {
    		$('#'+name).show();
		}
    }
    else
    {
    	if ( plain == undefined ) {
        	$('#'+name).fadeOut("fast");
		}
		else {
    		$('#'+name).hide();
		}
    }
}

var events_ids = [];
function eventScroll(day, total)
{
	if ( typeof(events_ids[day]) == 'undefined' ) {
		events_ids[day] = 0;
	}
	if ( total == 1 ) {
		return;
	}
	var id = (events_ids[day] == (total - 1)) ? 0 : events_ids[day] + 1;
	events_ids[day] = id;
    for (var i = 0; document.getElementById('event_' + day + '_' + i) != null;  i++)
    {
        if ( i != id ) {
            $('#event_' + day + '_' + i).hide();
		}
    }
    $('#event_' + day + '_' + id).show();
}

// misc
function confirmLink(question, url)
{
    var is_confirmed = confirm(question);

    if (is_confirmed && url != '')
        window.location = url;

    return is_confirmed;
}

function confirmForm(question, form)
{
    var is_confirmed = confirm(question);

    if (is_confirmed && form != '')
        eval('document.' + form + '.submit()');

    return is_confirmed;
}

function toggleItems(form, check)
{
    for (var i = 0; i < form.elements.length; i++)
    {
        if (form.elements[i].type == 'checkbox')
        {
            form.elements[i].checked = check;
        }
    }
}

function stylizeBooleanBox(prefix, boxid)
{
	var options = document.getElementById(prefix + boxid);
	for ( var i = 0, length = options.length; i < length; i++ )
	{
		options[i].style.background = ( options[i].value == 1 ) ? '#DEFAE0' : '#FBDDDD';
		if ( options[i].value == 1 && options[i].selected )
			document.getElementById(prefix + boxid).style.background = '#DEFAE0';
		else if ( options[i].value == 0 && options[i].selected )
			document.getElementById(prefix + boxid).style.background = '#FBDDDD';
	}
}

function removeFlashUploader()
{
	$('#regular_file_select').show();
	$('#regular_file_browse a').hide();
	$('#pending_file').show();
	$('#pending_fileUploader').hide();
	$('#regular_file_submit').show();
	$('#pending_file_submit').hide();
}

// toolpics
$.fn.ToolTip = function(customclass)
{
	this.mouseover(
		function(e)
		{	
			if((!this.title && !this.alt) && !this.tooltipset) return;
			
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 10;
			mouseY += 10;
			if(!this.tooltipdiv)
			{
				var div = document.createElement("div");
				this.tooltipdiv = div;
				$(div).addClass(customclass || 'tooltip');
				$(div).html((this.title || this.alt));
				this.title = "";
				this.alt = "";
				$("body").append(div);
				this.tooltipset = true;
			}
			$(this.tooltipdiv).fadeIn("fast").css({left: mouseX + "px", top: mouseY + 3 + "px"});
		}

	).mousemove(
		function(e)
		{
			if(!this.tooltipset) return;
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 10;
			mouseY += 10;
			$(this.tooltipdiv).css({left: mouseX + "px", top: mouseY + 3 + "px"});
		}
	).mouseout(
		function()
		{
			if(this.tooltipdiv)
			{
				$(this.tooltipdiv).fadeOut("fast");
			}
		}
	);
	return false;
}

function selectSmiley(smiley_id, textbox)
{	
	var val = nicEditors.findEditor(textbox).getContent();
	val = val + '' + smilies[smiley_id]['shortcut'];
	nicEditors.findEditor(textbox).setContent(val);
}

//------------------------------------------------
// Private messaging
//------------------------------------------------
var autocheck = 0;
var donotify = 0;
var current = 0;
var virpath = '';
var player = null;

function checkPM(path,check,delay)
{
    virpath = path;
    autocheck = check;
    autodelay = delay;
    checkMessage();
}

function checkMessage()
{
	$.post(virpath+'index.php?m=checkpm&hp=1', {},
            function(response) {
			response = response.split("|");
			if ( response.length == 3 )
			{
				if ( response[1] > 0 )
				{
					if ( $('#li_messages').hasClass("nav_messages") ) {							
						 $('#li_messages').removeClass("nav_messages");
						 $('#li_messages').addClass("nav_messages_new");						
					}
					
					$('.nm_wrap').html('(' + response[1] + ')'); // <img border="0" src="/media/new.gif" style="vertical-align:middle;width:22px;height:7px "/>
					if ( response[2] > 0 )
					{
						playNotification();
					} 						
				}
				else
				{
					if( $('.nm_wrap').html() != '' )
					{
						$('.nm_wrap').html('');	
					}
				}
				
				// smart polling (increase 10 seconds every round)
				if ( autocheck && (autodelay < 600) ) {
						autodelay = autodelay + 10;
	                    setTimeout('checkMessage()', (autodelay*1000));
				}
				else
				{
					return;	
				}
			}
		}
	);
}

function playerReady(thePlayer)
{
	player = window.document[thePlayer.id];
}

function playNotification()
{
	if ( donotify == true && $('#mpl').html() != '' ) {
		player.sendEvent("PLAY");
	}
}

//------------------------------------------------
// Chat
//------------------------------------------------
var chat_sessions = {};
var chat_check_auto = 0;
var chat_check_delay = 8;
var chat_alert_msg = '';
chatwins = new Array();

function checkChat(check,delay,msg)
{
    chat_check_auto = check;
    chat_check_delay = delay;
    chat_alert_msg = msg;
    checkChatText();
}

function checkChatText() {
	$.post(virpath+'chat.php?p=check', {},
		function(response) {
  			if ( response != '0' ) {
  				var response = response.split("\n");
  				if ( response.length == 2 && typeof(chat_sessions[response[0]]) == 'undefined' ) {
  					chat_sessions[response[0]] = 1;
  					var alert_msg = chat_alert_msg;
  					alert_msg = alert_msg.replace('%here%', '<a href="#" onclick="window.open(\''+virpath+'index.php?m=account_chat&p=request&id='+response[0]+'\', \'chat'+response[0]+'\', \'width=470,height=410,resizable=yes,scrollbars=no,toolbar=no,location=no,status=no,menubar=no\')">here</a>');
  					alert_msg = alert_msg.replace('%username%', '<a href="'+virpath+'index.php?m=member_profile&id='+response[1]+'">'+response[1]+'</a>');
		        	$.jGrowl(alert_msg, { sticky: true });
				}
			}
			if ( chat_check_auto ) {
			    setTimeout('checkChatText()', (chat_check_delay*1000));
			}
		}
	);
}

function openChatWindow(member_id) {
    if (member_id > 0 && (typeof(chatwins['chat' + member_id]) != "object"  ||  chatwins['chat' + member_id].closed)) {
        chatwins['chat' + member_id] = window.open(virpath + 'index.php?m=account_chat&p=request&id=' + member_id, 'chat' + member_id, 'width=470,height=410,resizable=yes,scrollbars=no,toolbar=no,location=no,status=no,menubar=no');
        if ( chatwins['chat' + member_id] && chatwins['chat' + member_id].open)
        	chatwins['chat' + member_id].focus();
		else
			alert('Could not open a chat window. Please disable your popup blocker.');
    }
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function save_search()
{
	var name = $('#field_search_save').val();
	var hash = $('#field_hash').val();

	if(name != '' && hash != '')
	{
		$('#save_search_progress').show();
		$('#save_search_submit').attr({disabled: "disabled"});

		$.post(virpath+'index.php?hp=1&m=searches&p=save', {'name':name,'s':hash},
			function(response) {
				var response = response.split("\n");
				if ( response.length > 0 )
				{
					if ( response[0] == 'ok' && response[1] )
					{
						$('#save_search_progress').hide();
						$('#save_search_response').html(response[1]);

						if ( response[2] )
						{
							setTimeout(function(){
								$('#div_save_search' ).animate({ opacity: "hide" }, "slow");
							}, 2000);
						}
						return true;
					}
				}
			}
		);
	}
}

// comments pagination
function get_comments_page(type, member_id, content_id, page)
{
	$('#get_comments_progress').show();

	$.post(virpath+'index.php?hp=1&m=comments', {'type':type,'member_id':member_id,'content_id':content_id,'page':page},
		function(response) {
			var response = response.split("|");
			if ( response.length == 2 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					$('#get_comments_progress').hide();
					$('#comments_page').html(response[1]);
					return true;
				}
			}

		}
	);
}

// comments deletion
function delete_comment(question, user_type, type, member_id, content_id, comment_id)
{
	var is_confirmed = confirm(question);

	if ( is_confirmed )
	{
		$.post(virpath+'index.php?hp=1&m=comments&a=delete', {'u_type':user_type, 'c_type':type, 'member_id':member_id, 'content_id':content_id, 'comment_id':comment_id},
			function(response) {
				var response = response.split("|");
				if ( response.length > 0 )
				{
					if ( response[0] == 'ok' && response[1] )
					{
						$('#object_comment_delete_link_' + comment_id).html(response[1]);
						setTimeout(function(){
							$('#object_comment_' + comment_id).animate({ opacity: "hide" }, "fast");
						}, 1000);
						return true;
					}
					else if ( response[0] == 'error' && response[1] )
					{
						$('#object_comment_delete_link_' + comment_id).html('<span style="color:red">' + response[1] + '</span>');
						return true;
					}
				}
			}
		);
	}
}

// display mood icon
function display_mood(url)
{
    var mood = $('select#field_mymood option:selected').text();
    $('#mood_div').attr('style', 'background: url(' + url + mood + '.gif) no-repeat; width:93px; height:30px;');
}

// play sound file
function play_sound(url)
{
    var soundfile = $('select#field_pmsound option:selected').text();
    if (soundfile != 'None')
    {
		player.sendEvent("LOAD", url + soundfile + '.mp3');
		player.sendEvent("PLAY");
	}
	else
	{
		alert('Select sound first!');	
	}
}
function isIE()
{

    if(navigator.userAgent.match(/MSIE \d\.\d+/))
        return true;
    return false;
}



function zIndexWorkaroundUserMenu(field_def)
{
	
    // If the browser is IE,
    if(isIE())
    {		
		$("div#usermenu").parents().each(function() {
			
            var p = $(this);
            var pos = p.css("position");
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {               
                p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
		
    }
}

function zIndexWorkaround(field_def)
{
	
    // If the browser is IE,
    if(isIE())
    {
		$("span.hint").parents().each(function() {
			
            var p = $(this);
            var pos = p.css("position");
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
				p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
		
		
    }
}

//tooltips
function generate_hints()
{
if(!isIE()) {
	$("input,select,textarea").focus( function(){
		//$(this).siblings("span").fadeIn();
		$('span.hint').css('display','none');
		$(this).siblings("span").css('display','inline');					
	}); 
	$("input,select,textarea").blur( function(){	
		$('span.hint').css('display','none');
	}); 
	$("ul.fielditems,.ui-dropdownchecklist-wrapper").mouseover( function(){	
		/*$('span.hint').css('display','none');																 
		var current = $(this).siblings("span");
		$(current).show(1).fadeTo(2000, 1).hide(1);
		zIndexWorkaround();	*/	
	});
}
} 

// character limit
function limitChars(textid, limit, infodiv)
{
        var text = $('#'+textid).val(); 
        var textlength = text.length;
        
        if(textlength > limit)
        {
                $('#' + infodiv).html('You cannot write more than '+limit+' characters!');
                $('#'+textid).val(text.substr(0,limit));
               return false;
        } 
        else
        {
                $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
                return true;
        }
}


//ajaxified message deletion
function delete_message(message_id, folder)
{
	var ajax_response = $('#delete_link_' + message_id);
	ajax_response.html('<img src="/media/spinner.gif" width="16" height="16" alt="thinking..." />');
	
	$.post(virpath+'index.php?hp=1&m=messages&a=delete', {'message_id':message_id, 'folder':folder},
		function(response) {
			var response = response.split("|");
			if ( response.length > 0 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					ajax_response.html(response[1]);
					setTimeout(function(){
					$('#message_' + message_id).animate({ opacity: "hide" }, "fast");
										}, 1000);
					
					return true;
				}
				else if ( response[0] == 'error' && response[1] )
				{
					ajax_response.html('<span style="color:red">' + response[1] + '</span>');
					return true;
				}
			
			}
		}
	);
}

//ajaxified reading
function mark_as_read(message_id)
{
	var ajax_response = $('#read_link_' + message_id);
	
	ajax_response.html('<img src="/media/spinner.gif" width="16" height="16" alt="thinking..." />');
	
	$.post(virpath+'index.php?hp=1&m=messages&a=markread', {'message_id':message_id},
		function(response) {
			var response = response.split("|");
			if ( response.length > 0 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					ajax_response.html(response[1]);
					setTimeout(function(){
					$('#message_' + message_id + ' blockquote').removeClass('new');
										}, 500);
					
					return true;
				}
				else if ( response[0] == 'error' && response[1] )
				{
					ajax_response.html('<span style="color:red">' + response[1] + '</span>');
					return true;
				}
			}
		}
	);
}

function confirmAction(question, action)
{
    var is_confirmed = confirm(question);

    if (is_confirmed && action != '')
        eval(action);

    return is_confirmed;
}


/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 *
 * Examples at http://famspam.com/facebox/
 *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 */

(function($) {
  $.facebox = function(data, klass) { 
    $.facebox.loading()
    if (data.ajax) fillFaceboxFromAjax(data.ajax)
    else if (data.image) fillFaceboxFromImage(data.image)
    else if (data.div) fillFaceboxFromHref(data.div)
    else if ($.isFunction(data)) data.call($)
    else $.facebox.reveal(data, klass)
  }
  /*
   * Public, $.facebox methods
   */
  $.extend($.facebox, {
    settings: {
      opacity      : .5,
      overlay      : false,
      loadingImage : mediapath + '/fbimages/loading.gif',
      closeImage   : mediapath + '/fbimages/closelabel.gif',
      imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxHtml  : '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div class="content"> \
                </div> \
                <div class="footer" style="position:relative"> \
                  <a href="#" class="close" id="close_label"> \
                    <img src="/facebox/closelabel.gif" title="close" class="close_image"  /> \
				  </a> \
				  <span class="hint" style="width:125px;right:-165px;top:7px;font-weight:bold;color:#000;">Click here to close<span class="hint-pointer">&nbsp;</span></span> \
				</div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    },
    loading: function() {
      init()
      if ($('#facebox .loading').length == 1) return true
      showOverlay()
      $('#facebox .content').empty()
      $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')
		
      $('#facebox').css({
							
        top:	getPageScroll()[1] + (getPageHeight() / 10),
        left:	385.5
      }).show()
      $(document).bind('keydown.facebox', function(e) {
        if (e.keyCode == 27) $.facebox.close()
        return true
      })
      $(document).trigger('loading.facebox')
    },
    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.facebox')
      if (klass) $('#facebox .content').addClass(klass)
      $('#facebox .content').append(data)
      $('#facebox .loading').remove()
      $('#facebox .body').children().fadeIn('normal')
      $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
      $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')	 
    },
    close: function() {
      $(document).trigger('close.facebox')
      return false
    }
  })
  /*
   * Public, $.fn methods
   */
  $.fn.facebox = function(settings) {
    init(settings)
    function clickHandler() {
      $.facebox.loading(true)
      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]
      fillFaceboxFromHref(this.href, klass)
      return false
    }
    return this.click(clickHandler)
  }
  /*
   * Private methods
   */
  // called one time to setup facebox on this page
  function init(settings) {
    if ($.facebox.settings.inited) return true
    else $.facebox.settings.inited = true
    $(document).trigger('init.facebox')
    makeCompatible()
    var imageTypes = $.facebox.settings.imageTypes.join('|')
    $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')
    if (settings) $.extend($.facebox.settings, settings)
    $('body').append($.facebox.settings.faceboxHtml)
    var preload = [ new Image(), new Image() ]
    preload[0].src = $.facebox.settings.closeImage
    preload[1].src = $.facebox.settings.loadingImage
    $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })
    $('#facebox .close').click($.facebox.close)
    $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
  }
  
  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }
  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
  }
  //MOD START
  function getPageWidth() {
    var windowWidth
    if (self.innerWidth) {	// all except Explorer
      windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
    } else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
    }	
    return windowWidth
  }
  //MOD END
  // Backwards compatibility
  function makeCompatible() {
    var $s = $.facebox.settings
    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  }
  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillFaceboxFromHref(href, klass) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
	   
	  var div_height = $(target).height();
	  var div_width = $(target).width();
	  
	  $('#facebox').css({top:	getPageScroll()[1] + (getPageHeight() / 2) - ( div_height / 2 ) - 40,
        				left:  (getPageWidth() / 2) - ( div_width / 2 ) - 20                          }); //Hack to vertical center div box
	   
      $.facebox.reveal($(target).clone().show(), klass)
    // image
    } else if (href.match($.facebox.settings.imageTypesRegexp)) {
      fillFaceboxFromImage(href, klass)
    // ajax
    } else {		
      fillFaceboxFromAjax(href, klass)
    }
  }
  function fillFaceboxFromImage(href, klass) {
    var image = new Image()
    image.onload = function() {
      $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
    }
    image.src = href
  }
  function fillFaceboxFromAjax(href, klass) {	
    $.get(href, function(data) { $.facebox.reveal(data, klass) })
  }
  function skipOverlay() {
    return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 
  }
  function showOverlay() {
	//if (skipOverlay()) return
    if ($('facebox_overlay').length == 0) 
      $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')
	
	if (skipOverlay()) {			
		$('#facebox_overlay').hide().addClass("facebox_overlayBG")
      	.css('opacity', 0)
      	.click(function() { $(document).trigger('close.facebox') })
      	.fadeIn(200)	
	} else {
		$('#facebox_overlay').hide().addClass("facebox_overlayBG")
		.css('opacity', $.facebox.settings.opacity)
      	.fadeIn(200)
	}
    return false
  }
  function hideOverlay() {
    //if (skipOverlay()) return
    $('#facebox_overlay').fadeOut(200, function(){
      $("#facebox_overlay").removeClass("facebox_overlayBG")
      $("#facebox_overlay").addClass("facebox_hide") 
      $("#facebox_overlay").remove()
    })
    
    return false
  }
  /*
   * Bindings
   */
  $(document).bind('close.facebox', function() {
    $(document).unbind('keydown.facebox')
    $('#facebox').fadeOut(function() {
      $('#facebox .content').removeClass().addClass('content')
      hideOverlay()
      $('#facebox .loading').remove()
    })
  })
})(jQuery);

//CA POPUP BLOCKER - FIX START
$('document').ready(function() {
  if(window._orig_windowSetTimeout !== undefined)
    window.setTimeout = _orig_windowSetTimeout;
  if(window._orig_windowSetInterval !== undefined)
    window.setInterval = _orig_windowSetInterval;
});
//CA POPUP BLOCKER - FIX END


function toggle_status(status)
{
	$.post(virpath+'index.php?hp=1&m=togglestatus','',
		function(response) {
			var response = response.split("|");
			if ( response.length == 2 )
			{
	
				if ( response[0] == 'ok' && response[1] != "" )
				{
					$('.member_staus_block').html(response[1]);
					
					
				}
				
				
			}
			
			return false;

		}
	);
}	







function get_lucky_spin(limit)
{
	$('#lucky_container').html('<img src="/media/lucky_spinner.gif" />');
	$('#spin_link').css({'display':'none'});
	$.post(virpath+'index.php?hp=1&m=luckyspin', {'limit':limit},
		function(response) {
			var response = response.split("|");
			if ( response.length == 2 )
			{
				if ( response[0] == 'ok' && response[1] )
				{
					
					setTimeout(function()
					{
						$('#lucky_container_wrap').html(response[1]);
						$('a.tooltip').ToolTip('nicetooltip');
					}, 1000);
					return true;
				}
				$('#spin_link').css({'display':'block'});
			}

		}
	);
}
