﻿var EnableNext = false;
function FormatText(Text)
{
    while(Text.indexOf('&') > -1)
        Text = Text.replace("&", "%26");
    return Text;
}

function PrepareToUpload()
{
    $(document).ready(function(){	    var button = $('#ImageLoader'), interval;	    new Ajax_upload(button,{		    action: "/Community/User.aspx?UploadImage=1&rnd=" + Math.random(), 		    name: 'UploadedFile',		    onSubmit : function(file, ext){		            this.disable();
		    },
		    onComplete: function(file, response){
		        this.enable();
		        $('#ProfileImage').html("<img src='/Data/User/Images/Size1/" + response + "' border=0>");
		    }
	    });
    });
}

function Request(Href, Data, OnSuccess, OnError)
{
    if(Href.indexOf('?') == -1)
        Href = Href + "?";
    if(Href.indexOf('Ajax=1') == -1)
        Href = Href + "&Ajax=1";
    $.ajax({
      cache: false,
      type: "POST",
      url: Href + "&rnd=" + Math.random(),
      data: Data,
      success: OnSuccess,
      error: OnError
     });
    return false;
}

function Login()
{
    $("#LoginMessage").html("");
    Request("/Community/Login.aspx?Ajax=1&rnd=" + Math.random(), "Email=" + $("#Email").val() + "&PWD=" + $("#Password").val(), (function(response) { if(response.length <= 3) { location.reload(true) } else { $("#LoginMessage").html(response); }} ), "");
    return false;
}

function HandleTabs()
{
    var Counter;
    Counter = 1;
    var $$ = $("#TabControl");
    var Index = 1;
    $$.find("a").each(
        function() 
        {
            $(this).attr("class", "Tab");
            if(document.location.href.indexOf("Tab=" + Counter) > -1)
            {
                Index = Counter;
            }        
            Counter++;
       }
    );
    Counter = 1;
    $$ = $("#TabControl");
    $$.find("a").each(
        function() 
        {
            if(Counter == Index)
                $(this).attr("class", "SelectedTab");
            Counter++;
       }
    );
}

jQuery(document).ready
(
    function($) 
    {
     
      HandleTabs();
      UpdateCommonBindings();
      $('.ClickablePanel').each(
        function (){
            $(this).unbind("click");
            $(this).click(function(){ 
                if(this.title != "")
                {
                    if(this.title.indexOf("Target=Blank")>-1)
                    {
                        Popup = window.open(this.title, 'MapWindow', 'width=' + screen.availWidth + ',height=' + screen.availHeight); 
                        Popup.moveTo(0,0);
                    }
                    else
                        document.location.href = this.title; 
                }
            });
        }
      );
      $(".ToolTip[title]").tooltip('#ToolTipBox'); 
    }
);

function UpdateCommonBindings()
{
    $(".AutoComplete").each(function(){$(this).autocomplete(this.title, {width: 400, multiple: this.title.indexOf("Multiple=true") > -1, matchContains: true });});
    $('a[rel*=facebox]').each(function (){$(this).unbind("click");$(this).click(function(){ $.facebox({ajax:this.href}, 'my-groovy-style'); $.facebox.hideFooter(); return false;}); });
}

function PerformTopPanelLayout()
{
    $('.SandBox a').click(
        function(e) {
        if($(this).attr("rel") != "" && $(this).attr("rel") != null && $(this).attr("rel") != undefined)
        {
            $('.SandBox a').each(function() {if($(this).attr("rel") != "" && $(this).attr("rel") != null && $(this).attr("rel") != undefined) { $('#' + $(this).attr("rel")).hide(); $(this).removeClass("SelectedUserOp"); }});
            $('#' + $(this).attr("rel")).show();
            $(this).addClass("SelectedUserOp");
        }
      })
}

function CheckUpperSector(Sector)
{
    var ParentSector = $('#Sector_' + Sector).attr("rel");
    if(ParentSector == "" || ParentSector == null || ParentSector == undefined)
        ParentSector = 0;
    if(ParentSector * 1 > 0)
    {
        if(document.getElementById("Sector_" + Sector).checked && document.getElementById("Sector_" + ParentSector))
        {
            document.getElementById("Sector_" + ParentSector).checked = true;
            CheckUpperSector(ParentSector);
        }
    }
}
