
function switch_realms(region) {

 if (region == 'na') {
  q.loadXML('/inc/northamerica_realms.xml');
  q.setComboText('');
 } else {
  q.loadXML('/inc/eu_realms.xml');
  q.setComboText(''); 
 }


}



function validate_reply ( )
{
    valid = true;

    if ( document.reply.message.value == "" ) {
        alert ( "Please type a message!" );
        valid = false;
    } else {
      if (document.reply.message.value.length < 10) {
       alert ( "Your message is too short. Remember, \"bumping\" or irrelevant content of any kind is not allowed." );
       valid = false;
      }
    }

    return valid;
}



function validate_thread ( )
{
    valid = true;
    
    if ( document.reply.topic.value == "" || document.reply.topic.value == "Enter the topic of your thread here... 130 characters max." ) {
        alert ( "Please type a topic!" );
        valid = false;
    } else {
      if (document.reply.topic.value.length < 5) {
       alert ( "Your topic is too short. It must be at least 5 characters." );
       valid = false;
      }
    }
    
    
    if ( document.reply.message.value == "" ) {
        alert ( "Please type a message!" );
        valid = false;
    } else {
      if (document.reply.message.length < 10) {
       alert ( "Your message is too short. Remember, \"bumping\" or irrelevant content of any kind is not allowed." );
       valid = false;
      }
    }

    return valid;
}


function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue.split("{br}").join("\r\n");
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}

function load_sheet(version, sheet, profile, snapshot) {
 
 // Change Button Classes
 document.getElementById('character_tab').className="profile_tabs_inactive";
 document.getElementById('reputation_tab').className="profile_tabs_inactive";
 document.getElementById('skills_tab').className="profile_tabs_inactive";
 if (document.getElementById('achievements_tab')){ document.getElementById('achievements_tab').className="profile_tabs_inactive"; }
 if (document.getElementById('tools_tab')){ document.getElementById('tools_tab').className="profile_tabs_inactive"; }
 document.getElementById(sheet+'_tab').className="profile_tabs_active";
     
 if (snapshot != '0') {
  snapshotstring = '&snapshot='+snapshot;
 } else {
  snapshotstring = '';
 }
    
$.ajax({
  type: "GET",
  url: "/profilepages/"+version+"/"+sheet+".php",
  data: "id="+profile+snapshotstring,
  cache: false,
  success: function(html){
    $("#tube").html(html);
  }
}); 
    
}


function switch_stats ( switchto ) {

 // Change Button Classes
 document.getElementById('base_stat_button').className="jumplink";
 document.getElementById('melee_stat_button').className="jumplink";
 document.getElementById('spell_stat_button').className="jumplink";
 document.getElementById('defense_stat_button').className="jumplink";
 document.getElementById('ranged_stat_button').className="jumplink";
 document.getElementById(switchto+'_stat_button').className="activejumplink";
 
 // Change Display Area
 document.getElementById('base_stats').style.display='none';
 document.getElementById('melee_stats').style.display='none';
 document.getElementById('spell_stats').style.display='none';
 document.getElementById('defense_stats').style.display='none';
 document.getElementById('ranged_stats').style.display='none';
 document.getElementById(switchto+'_stats').style.display='inline'; 

}

function popUp(page,PWidth,PHeight,id) {
 eval("popupwindow"+id+"=window.open('"+page+"','popupwindow1','toolbar=0,scrollbars=0,location=0,status=0,menubars=0,resizable=0,width="+PWidth+",height="+PHeight+"')")
 eval;("wiz"+id+".window.moveTo((screen.width/2)-(PWidth/2),(screen.height/2)-(PHeight/2))")
}

/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
    if (window.innerHeight!=window.undefined) return window.innerHeight;
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
    if (document.body) return document.body.clientHeight; 

    return window.undefined; 
}
function getViewportWidth() {
    var offset = 17;
    var width = null;
    if (window.innerWidth!=window.undefined) return window.innerWidth; 
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
    if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
    if (self.pageYOffset) // all except Explorer
    {
        return self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
        // Explorer 6 Strict
    {
        return document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        return document.body.scrollTop;
    }
}
function getScrollLeft() {
    if (self.pageXOffset) // all except Explorer
    {
        return self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollLeft)
        // Explorer 6 Strict
    {
        return document.documentElement.scrollLeft;
    }
    else if (document.body) // all other Explorers
    {
        return document.body.scrollLeft;
    }
}
  