function n(a,b,c,d,e) { }

function wowui_expand_recent(id) {
  element = $('recentmod-' + id);
  element.style.display = "block";
}

function wowui_contract_recent(id) {
  element = $('recentmod-' + id);
  element.style.display = "none";
}

function wowui_expand_menu(id, positioner, offset_x, offset_y) {
  element = $(id);
  element.style.display = "block";
  if (positioner) {
    if (!offset_x) offset_x = 0;
    if (!offset_y) offset_y = 0;
    element.style.left = (findPos(positioner)[0] + offset_x) + 'px';
    element.style.top = (findPos(positioner)[1] + offset_y) + 'px';
  }
}

function wowui_contract_menu(id) {
  element = $(id);
  element.style.display = "none";
}

function wowui_change_class(sel) {
  $('classpic').src = 'static/images/class/' + sel.value + '.gif';
}

function wowui_ajax(frm, before, after) {
  el = frm.elements;
  vars = "";
  for (var obj in el) {
    try {
      if (el[obj].name == undefined || el[obj].value == undefined) {
        continue;
      }
      vars = vars + "&" + encodeURIComponent(el[obj].name) + "=" + encodeURIComponent(el[obj].value);
    }
    catch(e) {}
  }
  before();
  new Ajax.Request('?p=ajax', {
    method: 'post',
    parameters: vars,
    asynchronous: false,
    onSuccess: function(transport) {
      after(transport.responseText);
    },
    onFailure: function() {
      return true;
    }
  });
  return false;
}

function shoutbox_before() {
  $('shoutform').innerHTML = '<img src="static/images/indicator.gif" width="16" height="16" align="absmiddle" alt="" /> Please wait...';
}

function shoutbox_after(response) {
  if (response != 'error') {
    $('shoutform').innerHTML = '<span style="color: gray; font-style: italic">Thanks for your shout!</span>';
    $('shoutlist').innerHTML = response;
  }
  else {
    $('shoutform').innerHTML = '<span style="color: red; font-style: italic">Your shout was invalid (probably too long/short)</span>';
  }
}

var preview_a = 0;
var current_preview = 0;

function wowui_preview(a, modid, macro) {
  scrollTo(0,0);
  if (preview_a != 0) {
    preview_a.className = 'browsemod';
  }
  preview_a = a;
  preview_a.className = 'browsemod browseselected';
  if (current_preview == modid) {
    return true;
  }
  current_preview = modid;
  $('please-wait').style.display='block';
  macro = (macro) ? '&macro=1' : '&macro=0';
  new Ajax.Updater('mod-preview', '?p=ajax&ajax=preview&id=' + modid + macro, {asynchronous:true, onComplete:function(){
    $('lefthold').style.width = "59%";
    $('righthold').style.display = "block";
    initLightbox();
    $('please-wait').style.display='none';
  }});
  return false;
}

function wowui_vote(section, id, vote) {
  new Ajax.Request('?p=ajax&ajax=vote&section=' + section + '&item=' + id + '&direction=' + vote, {
    method: 'get',
    asynchronous: false,
    onSuccess: function(transport) {
      $('ratingbox').innerHTML = transport.responseText;
      return false;
    },
    onFailure: function() {
      return true;
    }
  });
}

function wowui_xcode(a) {
  a = a.replace(/<b>(.+)<\/b>/gi, "[b]$1[/b]");
  a = a.replace(/<u>(.+)<\/u>/gi, "[u]$1[/u]");
  a = a.replace(/<i>(.+)<\/i>/gi, "[i]$1[/i]");
  a = a.replace(/<font size=1>(.+)<\/font>/gi, "[small]$1[/small]");
  a = a.replace(/<font size=3>(.+)<\/font>/gi, "[big]$1[/big]");
  a = a.replace(/<font size=3>(.+)<\/font>/gi, "[big]$1[/big]");
  a = a.replace(/<blockquote><font color=#ffff33>(.+)<\/font><\/blockquote>/gi, "[code]$1[/code]");
  a = a.replace(/<a href="(.+)">(.+)<\/a>/gi, "$1");
  a = a.replace(/<br>/gi, "");
  return a;
}

var n_act;
var n_section;
var n_item;
var n_comment;

function wowui_ncomment(act, section, item, comment) {
  $('ncadd').style.display = "none";
  $('ncentry').style.display = "block";
  if (act == "edit") {
    $('nctext').value = wowui_xcode($('nc-' + comment).innerHTML);
  }
  n_act = act;
  n_section = section;
  n_item = item;
  n_comment = comment;
}

function wowui_nprocess() {
  if (n_act == "add") {
    turl = '?p=ajax&ajax=comment&a=add&s=' + n_section + '&i=' + n_item;	
  }
  else {
    turl = '?p=ajax&ajax=comment&a=edit&s=' + n_section + '&i=' + n_item + '&c=' + n_comment;
  }
  new Ajax.Request(turl, {
    method: 'post',
    postBody: 'comment=' + encodeURIComponent($('nctext').value),
    asynchronous: false,
    onSuccess: function(transport) {
      var response = transport.responseText;
      if (response == "0") {
        alert('There was a problem submitting your comment.');
      }
      else {
        $('ncajax').innerHTML = response;
        tabberAutomatic({});
      }
    },
    onFailure: function(){ alert('There was a problem submitting your comment.'); }
  });
  wowui_ncancel();
}

function wowui_ncancel() {
  $('ncadd').style.display = "block";
  $('ncentry').style.display = "none";
  $('nctext').value = "";
}


function wowui_ndelete(section, item, comment_id) {
  wowui_ncomment('edit', section, item, comment_id);
  $('nctext').value = "delete";
  wowui_nprocess();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function wowui_patch_notes() {
  $('patch-notes-1').style.display = "none";
  $('patch-notes-2').style.display = "block";
}

function wowui_open_report(section, id) {
  $('report-container').innerHTML = '<form action="#" method="post" onsubmit="wowui_report(' + section + ', ' + id + '); return false">' +
				    'Please give a reason for reporting: <input type="text" size="40" id="repreason"/> <input type="submit" value="Send Report"/></form>';
}

function wowui_report(section, id) {
  new Ajax.Request('?p=ajax&ajax=report&section=' + section + '&item=' + id + '&reason=' + encodeURIComponent($('repreason').value), {
    method: 'get',
    asynchronous: false,                                             
    onSuccess: function(transport) {}
  });
  $('report-container').innerHTML = '<span style="color:gray">Thanks for your report.</span>';
}

function wowui_hide_left() {
  $('lefthold').style.display = 'none';
  $('righthold').style.width = '100%';
}

function wowui_hide_right() {
  $('righthold').style.display = 'none';
  $('lefthold').style.width = '100%';
}

function wowui_sb_archive() {
  window.open("?p=archive","sbarchive","status=0,toolbar=0,width=500,height=350,scrollbars=1");	
}
