/* 
 * Copyright (c) 2003-2009 Y! Underground group
 *  www.2600.ir www.attacker.ir www.phreak.ir
 *                info@2600.ir
*/

/*
 * Global variables
 */

var web_windows_theme = "kamran";

/*
 * Window Management code and Dialogs
 */

var winIndex = 0;

/* Returns a unique Window identifier */
function obtainWindowId() {
	return (winIndex++);
}

/*
 * Show the About information dialog
 */
function openAboutDialog() {
    var aboutWindow = new Window("about-window"+obtainWindowId(),
        { className: web_windows_theme,
        width:450,
        height:160,
        zIndex: 100,
        resizable: true,
        title: "Contact",
        showEffect:Effect.BlindDown,
        hideEffect: Effect.SwitchOff,
        draggable:true
        })
        
    var about_content = "<div style='padding:5px'>Please read: we will not hack any yahoo" +
                     " hotmailmsn or other email account, we" +
                     " will not hack somebodiesICQ, MSN, whatever" +
                     " we will not crack the registration code of" +
                     " some software, we will not send you hacking" +
                     " softwarewe will not change your college or" +
                     " university grades and we will not teach you" +
                     " how to hack! Please don't bother.We get way" +
                     " too many crap mails, so we'll only reply to" +
                     " the serious ones info@2600.ir&info@attacker.ir</div>"
                        
    aboutWindow.getContent().innerHTML= about_content;
    aboutWindow.showCenter();
}


/*
 * Functions for opening modules lists and views
 */

function openProjectsWindow() {
    var console = create_window_ajax("/page/project", "projects-list", "Projects", 500, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openLanWindow() {
    var console = create_window_ajax("/page/lan", "projects-list", "language", 900, 550);
    console.setDestroyOnClose();
    console.showCenter();
}

function openMembersWindow() {
    var console = create_window_ajax("/page/members", "Members-list", "Members", 510, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function open0dayWindow() {
    var console = create_window_ajax("http://0day.attacker.ir", "0day-list", "0day", 600, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openscooWindow() {
    var console = create_window_ajax("/page/sco", "encoders-list", "YUG Program", 700, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function opendjxoWindow() {
    var console = create_window_ajax("/page/dj", "nops-list", "YUG Exploits", 700, 300);
    console.setDestroyOnClose();
    console.showCenter();
}
function openblogWindow() {
    var console = create_window_ajax("http://kamran.ir", "nops-list", "Blog", 720, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openLinksWindow() {
    var console = create_window_ajax("/page/links", "Links-list", "Links", 300, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openVideoWindow() {
    var console = create_window_ajax("/page/video", "Video-list", "Video", 500, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openToolsWindow() {
    var console = create_window_ajax("/page/tools", "Tools", "Tools", 550, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openConsoleWindowSession(sid) {
    var console = create_window_ajax("/console?sid="+sid, "console", "Underground Session", 760, 300);
    console.setDestroyOnClose();
    console.showCenter();
}

function openServicesWindow() {
    var console = create_window_ajax("/page/service", "service", "Service", 500, 300);
    console.setDestroyOnClose();
    console.showCenter();
}
function openBeetsWindow() {
    var console = create_window_ajax("/page/beet", "beed", "B33T", 644, 300);
    console.setDestroyOnClose();
    console.showCenter();

}

/*
 * Task and helper functions
 */

/*
 * Live search helper: sets an observer on text field with id (observer_id)
 * for (module_type) modules (ex. exploits) and the id of the spinner container
 * to show loading progress/indicator.
 * Last argument gives a clean list with no formatting. (ul-li)
 */
function generic_live_search(observer_id, module_type, load_spinner_id, clean_list) {
    new Form.Element.Observer(observer_id, 1, 
      function(element, value) {
        /* Set an AJAX updater for the observer of the text field */
        new Ajax.Updater(
            'search_results',
            '/msf/search',
            {
                asynchronous:true,
                evalScripts:true, 
                onComplete:function(request)
                {
                    Element.hide(load_spinner_id)
                }, 
                onLoading:function(request)
                {
                    Element.show(load_spinner_id)
                },
                method:'post',
                parameters:'module_type=' + module_type + '&clean_list=' + clean_list + '&terms=' + value
            })
      });
    /* Initializes the contents with all available modules by
     * doing a blank search 
     */
    $(observer_id).value = ' ';
}

/*
 * Create and AJAX based window from extenal content
 */
function create_window_ajax(target_url, wid, wtitle, wwidth, wheight) {
    var new_mwindow = new Window(wid+'-'+obtainWindowId(),
        { className: web_windows_theme,
          title: wtitle,
          top:70,
          left:100,
          width:wwidth,
          height:wheight,
          resizable: true,
          draggable: true,
          url: target_url,
          showEffect: Element.show,
          hideEffect: Element.hide
          });
    return new_mwindow;
}

/*
 * Open a window for the module of type (mtype) by id (refname) with tile (wtitle).
 * Height and width are fixed, should be working values in all cases.
 */
function openModuleWindow(mtype, refname, wtitle) {
    var mWin = create_window_ajax("/" + mtype + "/view?refname=" + refname, mtype + "-view-" + obtainWindowId(), wtitle, 700, 350);
    mWin.setDestroyOnClose();
    mWin.showCenter();
}

function run_tasks() {
    // ...
}
