
// fetch geo
function fetch_geo(country, state, city, curpath, inner)
{
	if ( ! country ) return;

	$('#ajax_geo_loading').show();

	if ( typeof(inner) == 'undefined' ) {
		$.post(( typeof(curpath) != 'undefined' && curpath != '' ? curpath : virpath) + 'index.php?m=geo', {'country':country,'state':''},
			function(response) {
				var itemsbox = '';
				if ( response != "" ) {
					var items = response.split("\n");
					for ( var i = 0, count = items.length; i < count; i++ ) {
						itemsbox = itemsbox + '<option value="' + items[i] + '">' + items[i] + '</option>';
					}
				}
				if ( itemsbox ) {
					itemsbox = '<select id="field_state" name="state" onchange="fetch_geo($(\'#field_country\').val(),this.value,\'\',\'\',1)" class="select"><option value="">Any</option>' + itemsbox + '</select>';
					$('#data_state').html(itemsbox);
					itemsbox = '<select id="field_city" name="city" class="select"><option value="">Select state</option></select>';
					$('#data_city').html(itemsbox);
				}
				else {
					$('#data_state').html('<input id="field_state" name="state" class="text" value="" style="width:150px" />');
					$('#data_city').html('<input id="field_city" name="city" class="text" value="" style="width:150px" />');
				}
				$('#field_country').val(country);
				$('#ajax_geo_loading').hide();
				if ( state ) {
					fetch_geo(country, state, city, curpath, 1);
				}
			}
		);
	}
	else {
		$.post(( typeof(curpath) != 'undefined' && curpath != '' ? curpath : virpath) + 'index.php?m=geo', {'country':country,'state':state},
			function(response) {
				var itemsbox = '';
				if ( response != "" ) {
					var items = response.split("\n");
					for ( var i = 0, count = items.length; i < count; i++ ) {
						itemsbox = itemsbox + '<option value="' + items[i] + '">' + items[i] + '</option>';
					}
				}
				if ( itemsbox ) {
					itemsbox = '<select id="field_city" name="city" class="select"><option value="">Any</option>' + itemsbox + '</select>';
					$('#data_city').html(itemsbox);
				}
				else {
					$('#data_city').html('<input id="field_city" name="city" class="text" value="" style="width:150px" />');
				}
				$('#field_state').val(state);
				$('#field_city').val(city);
				$('#ajax_geo_loading').hide();
			}
		);
	}
}

function submit_rating(f, g, h, i, j) {
    $('#rating_' + f + '_progress' + h).show();
    $.post(virpath + 'index.php?hp=1&m=rate', {
        'type': f,
        'score': i,
        'member_id': g,
        'content_id': h
    }, function (a) {
        var a = a.split("\n");
        if (a.length == 2) {
            if (a[0] == 'ok' && a[1]) {
                if (typeof (j) != 'undefined') {
                    window.location = j
                } else {
                    var b = parseFloat($('#rating_' + f + '_score' + h).html());
                    var c = parseInt($('#rating_' + f + '_votes' + h).html());
                    var d = b * c + i;
                    var e = c + 1;
                    $('#rating_' + f + '_score' + h).html((d / e).toFixed(2));
                    $('#rating_' + f + '_votes' + h).html(e);
                    ratingstar_reset(f, h, 1);
                    $('#rating_' + f + '_progress' + h).hide();
                    return true
                }
            }
        }
    })
}
function submit_report(b, c, d, e) {
    var f = $('#report_' + b + '_reason' + d).val();
    if (!f) {
        alert(e);
        return
    }
    $('#report_' + b + '_progress' + d).show();
    $.post(virpath + 'index.php?hp=1&m=report', {
        'type': b,
        'reason': f,
        'member_id': c,
        'content_id': d
    }, function (a) {
        var a = a.split("\n");
        if (a.length == 2) {
            if (a[0] == 'ok' && a[1]) {
                $('#report_' + b + '_progress' + d).hide();
                $('#report_' + b + '_response' + d).html('<div class="response">' + a[1] + '</div>');
                setTimeout(function () {
                    $('#report_' + b + '_response' + d).animate({
                        opacity: "hide"
                    }, "slow")
                }, 2500);
                return true
            }
        }
    })
}
function toggle_url(b, c, d) {
    $('#' + d).show();
    $.post(virpath + b, {
        'dynamic_request': 1
    }, function (a) {
        $('#' + d).hide();
        $('#' + c).html(a)
    })
}
function send_wink(a, b) {
    window.location = virpath + 'index.php?m=account_messages&p=quickmessage&id=' + a + '&sid=' + b
}
function submit_poll(d, e, f) {
    if (e == -1) {
        for (var i = 0; document.getElementById('poll_' + d + '_checkbox_' + i) != null; i++) {
            $('#poll_' + d + '_bar_' + i).animate({
                opacity: "show"
            }, "fast");
            $('#poll_' + d + '_checkbox_' + i).hide();
            $('#poll_' + d + '_checkbox_' + i + '_obj').attr('disabled', 'disabled')
        }
        $('#poll_' + d + '_results_view').hide();
        $('#poll_' + d + '_results_wrap').show();
        return
    }
    $('#poll_' + d + '_progress').show();
    $.post(virpath + 'index.php?hp=1&m=vote', {
        'poll_id': d,
        'answer_id': e
    }, function (a) {
        var a = a.split("\n");
        if (a.length == 3) {
            if (a[0] == 'ok' && a[1]) {
                $('#poll_' + d + '_results').html(a[1]);
                $('#poll_' + d + '_results_view').hide();
                $('#poll_' + d + '_results_wrap').show();
                var b = a[2].split(",");
                for (var i = 0, totalvotes = b.length; i < totalvotes; i++) {
                    var c = b[i].split("=");
                    if (c.length == 4) {
                        $('#poll_' + d + '_results_' + c[0]).html(c[2] + '% (' + c[1] + ' ' + f + ')');
                        $('#poll_' + d + '_results_' + c[0]).css('display', 'inline');
                        $('#poll_' + d + '_bar_' + c[0]).css('width', c[3] + '%');
                        $('#poll_' + d + '_bar_' + c[0]).animate({
                            opacity: "show"
                        }, "fast");
                        $('#poll_' + d + '_checkbox_' + c[0]).hide();
                        $('#poll_' + d + '_checkbox_' + c[0] + '_obj').attr('disabled', 'disabled')
                    }
                }
                $('#poll_' + d + '_progress').hide();
                return true
            }
        } else if (a.length == 2) {
            if (a[0] == 'ok' && a[1]) {
                $('#poll_' + d + '_results').html(a[1]);
                $('#poll_' + d + '_results_wrap').show();
                for (var i = 0; $('#poll_' + d + '_checkbox_' + i) != null; i++) {
                    $('#poll_' + d + '_checkbox_' + c[0]).hide();
                    $('#poll_' + d + '_checkbox_' + c[0] + '_obj').attr('disabled', 'disabled')
                }
                $('#poll_' + d + '_progress').hide();
                return true
            }
        }
    })
}
function ratingstar_toggle(a, b, c) {
    for (var i = 1; i <= 5; i++) {
        if (i <= c) {
            if ($('#ratingstar' + b + '__' + i).hasClass("over") == false) {
                $('#ratingstar' + b + '__' + i).addClass("over")
            }
        } else {
            $('#ratingstar' + b + '__' + i).removeClass("over")
        }
    }
}
function ratingstar_reset(a, b, c) {
    var d = Math.round($('#rating_' + a + '_score' + b).html());
    if (d < 0 || d > 5) d = 0;
    for (var i = 1; i <= 5; i++) {
        if (i <= d) {
            if ($('#ratingstar' + b + '__' + i).hasClass("over") == false) {
                $('#ratingstar' + b + '__' + i).addClass("over")
            }
        } else {
            $('#ratingstar' + b + '__' + i).removeClass("over")
        }
        if (typeof (c) != 'undefined' && c) {
            $('#ratingstar' + b + '__' + i).attr("onclick", "return false;");
            $('#ratingstar' + b + '__' + i).attr("onmouseover", "return false;");
            $('#ratingstar' + b + '__' + i).attr("disabled", "disabled")
        }
    }
}
function contacts_switchmail(a) {
    emailtype = a;
    switch (a) {
    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('@' + a + '.com');
        break
    }
    $('#mem_username').val('');
    $('#mem_password').val('')
}
function checkusername(b) {
    $.post(virpath + 'index.php?hp=1&m=checkusername', {
        'username': b
    }, function (a) {
        var a = trim(a);
        a = a.split("\n");
        if (a.length == 2) {
            $('#field_username_status').html(a[1]);
            $('#field_username_status').removeClass('true');
            $('#field_username_status').removeClass('false');
            if (a[0] == 'ok') {
                $('#field_username_status').addClass('true')
            } else {
                $('#field_username_status').addClass('false')
            }
            $('#field_username_status').show(300)
        }
    })
}
function row_toggle(a) {
    for (var i = 0; document.getElementById(a + '_' + i) != null; i++) {
        if (document.getElementById(a + '_' + i).style.display == "none") $('#' + a + '_' + i).show();
        else $('#' + a + '_' + i).hide()
    }
}
function row_switch(a) {
    $('#' + active_tab).hide();
    $('#' + a).show();
    active_tab = a
}
var active_tab = 0;
var active_tab_first = 1;

function switch_tabs(a, b, c, d) {
    if (typeof (c) != 'undefined' && c == 1) {
        if (active_tab_first == 1) {
            $('#' + a + '_' + b + '_content').show();
            $('#' + a + '_' + b + '_tab').addClass("active");
            active_tab = b;
            active_tab_first = 0
        }
    } else if (active_tab != b) {
        $('#' + a + '_' + active_tab + '_content').hide(typeof (d) == 'undefined' ? 300 : 0);
        $('#' + a + '_' + active_tab + '_tab').removeClass("active");
        $('#' + a + '_' + b + '_content').show(typeof (d) == 'undefined' ? 300 : 0);
        $('#' + a + '_' + b + '_tab').addClass("active");
        active_tab = b
    }
}
function switch_boxes(a, b, c) {
    $('.' + a).hide();
    $('.' + b).show();
    if (typeof (c) != 'undefined' && c == 1) {
        $('.' + a + '_tabs > a').removeClass('active');
        $('.' + b + '_tab').addClass('active')
    }
}
function showhide_field(a, b, c) {
    if ($('#' + a).css("display") == "none" && (b == undefined || b == '') || b == 1) {
        if (c == undefined) {
            $('#' + a).fadeIn("fast")
        } else {
            $('#' + a).show()
        }
    } else {
        if (c == undefined) {
            $('#' + a).fadeOut("fast")
        } else {
            $('#' + a).hide()
        }
    }
}
var events_ids = [];

function eventScroll(a, b) {
    if (typeof (events_ids[a]) == 'undefined') {
        events_ids[a] = 0
    }
    if (b == 1) {
        return
    }
    var c = (events_ids[a] == (b - 1)) ? 0 : events_ids[a] + 1;
    events_ids[a] = c;
    for (var i = 0; document.getElementById('event_' + a + '_' + i) != null; i++) {
        if (i != c) {
            $('#event_' + a + '_' + i).hide()
        }
    }
    $('#event_' + a + '_' + c).show()
}
function confirmLink(a, b) {
    var c = confirm(a);
    if (c && b != '') window.location = b;
    return c
}
function confirmForm(a, b) {
    var c = confirm(a);
    if (c && b != '') eval('document.' + b + '.submit()');
    return c
}
function toggleItems(a, b) {
    for (var i = 0; i < a.elements.length; i++) {
        if (a.elements[i].type == 'checkbox') {
            a.elements[i].checked = b
        }
    }
}
function stylizeBooleanBox(a, b) {
    var c = document.getElementById(a + b);
    for (var i = 0, length = c.length; i < length; i++) {
        c[i].style.background = (c[i].value == 1) ? '#DEFAE0' : '#FBDDDD';
        if (c[i].value == 1 && c[i].selected) document.getElementById(a + b).style.background = '#DEFAE0';
        else if (c[i].value == 0 && c[i].selected) document.getElementById(a + b).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()
}
$.fn.ToolTip = function (d) {
    this.mouseover(function (e) {
        if ((!this.title && !this.alt) && !this.tooltipset) return;
        var a = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
        var b = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
        a += 10;
        b += 10;
        if (!this.tooltipdiv) {
            var c = document.createElement("div");
            this.tooltipdiv = c;
            $(c).addClass(d || 'tooltip');
            $(c).html((this.title || this.alt));
            this.title = "";
            this.alt = "";
            $("body").append(c);
            this.tooltipset = true
        }
        $(this.tooltipdiv).fadeIn("fast").css({
            left: a + "px",
            top: b + 3 + "px"
        })
    }).mousemove(function (e) {
        if (!this.tooltipset) return;
        var a = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
        var b = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
        a += 10;
        b += 10;
        $(this.tooltipdiv).css({
            left: a + "px",
            top: b + 3 + "px"
        })
    }).mouseout(function () {
        if (this.tooltipdiv) {
            $(this.tooltipdiv).fadeOut("fast")
        }
    });
    return this
};

function selectSmiley(a, b) {
    var c = $('#' + b).val();
    c = c + '' + smilies[a]['shortcut'];
    $('#' + b).val(c)
}
var chat_sessions = {};
var chat_check_auto = 0;
var chat_check_delay = 8;
var chat_alert_msg = '';
chatwins = new Array();

function checkChat(a, b, c) {
    chat_check_auto = a;
    chat_check_delay = b;
    chat_alert_msg = c;
    checkChatText()
}
function checkChatText() {
    $.post(virpath + 'chat.php?p=check', {}, function (a) {
        if (a != '0') {
            var a = a.split("\n");
            if (a.length == 2 && typeof (chat_sessions[a[0]]) == 'undefined') {
                chat_sessions[a[0]] = 1;
                var b = chat_alert_msg;
                b = b.replace('%here%', '<a href="#" onclick="window.open(\'' + virpath + 'index.php?m=account_chat&p=request&id=' + a[0] + '\', \'chat' + a[0] + '\', \'width=470,height=410,resizable=yes,scrollbars=no,toolbar=no,location=no,status=no,menubar=no\')">here</a>');
                b = b.replace('%username%', '<a href="' + virpath + 'index.php?m=member_profile&id=' + a[1] + '">' + a[1] + '</a>');
                $.jGrowl(b, {
                    sticky: true
                })
            }
        }
        if (chat_check_auto) {
            setTimeout('checkChatText()', (chat_check_delay * 1000))
        }
    })
}
function openChatWindow(a) {
    if (a > 0 && (typeof (chatwins['chat' + a]) != "object" || chatwins['chat' + a].closed)) {
        chatwins['chat' + a] = window.open(virpath + 'index.php?m=account_chat&p=request&id=' + a, 'chat' + a, 'width=470,height=410,resizable=yes,scrollbars=no,toolbar=no,location=no,status=no,menubar=no');
        if (chatwins['chat' + a] && chatwins['chat' + a].open) chatwins['chat' + a].focus();
        else alert('Could not open a chat window. Please disable your popup blocker.')
    }
}
function trim(a) {
    return a.replace(/^\s+|\s+$/g, "")
}
function nicetrim(a, b) {
    if (a.length > b) {
        try {
            a = a.substr(0, b) + '&hellip;'
        } catch (e) {}
    }
    return a
}
function save_search() {
    var b = $('#field_search_save').val();
    var c = $('#field_hash').val();
    if (b != '' && c != '') {
        $('#save_search_progress').show();
        $('#save_search_submit').attr({
            disabled: "disabled"
        });
        $.post(virpath + 'index.php?hp=1&m=searches&p=save', {
            'name': b,
            's': c
        }, function (a) {
            var a = a.split("\n");
            if (a.length > 0) {
                if (a[0] == 'ok' && a[1]) {
                    $('#save_search_progress').hide();
                    $('#save_search_response').html(a[1]);
                    if (a[2]) {
                        setTimeout(function () {
                            $('#div_save_search').animate({
                                opacity: "hide"
                            }, "slow")
                        }, 2000)
                    }
                    return true
                }
            }
        })
    }
}
function get_comments_page(b, c, d, e) {
    $('#get_comments_progress').show();
    $.post(virpath + 'index.php?hp=1&m=comments', {
        'type': b,
        'member_id': c,
        'content_id': d,
        'page': e
    }, function (a) {
        var a = a.split("|");
        if (a.length == 2) {
            if (a[0] == 'ok' && a[1]) {
                $('#get_comments_progress').hide();
                $('#comments_page').html(a[1]);
                return true
            }
        }
    })
}
function strcounter(a, b, c, d) {
    var e = c.length;
    if (e > d) {
        $('#' + a).val(c.substr(0, d))
    } else {
        $('#' + b).html(e)
    }
}
function delete_comment(b, c, d, e, f, g) {
    var h = confirm(b);
    if (h) {
        $.post(virpath + 'index.php?hp=1&m=comments&a=delete', {
            'u_type': c,
            'c_type': d,
            'member_id': e,
            'content_id': f,
            'comment_id': g
        }, function (a) {
            var a = a.split("|");
            if (a.length > 0) {
                if (a[0] == 'ok' && a[1]) {
                    $('#object_comment_delete_link_' + g).html(a[1]);
                    setTimeout(function () {
                        $('#object_comment_' + g).animate({
                            opacity: "hide"
                        }, "fast")
                    }, 1000);
                    return true
                } else if (a[0] == 'error' && a[1]) {
                    $('#object_comment_delete_link_' + g).html('<span style="color:red">' + a[1] + '</span>');
                    return true
                }
            }
        })
    }
}
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (a, b) {
        var c = this.length;
        if (b == null) b = 0;
        else if (b < 0) {
            b += c;
            if (b < 0) b = 0
        }
        for (var i = b; i < c; i++) {
            var d = this[i] || this.charAt && this.charAt(i);
            if (d == a) return i
        }
        return -1
    }
}
