function MCTabs() {
  this.settings = new Array();
};

MCTabs.prototype.init = function(settings) {
  this.settings = settings;
};

MCTabs.prototype.getParam = function(name, default_value) {
  var value = null;

  value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];

  // Fix bool values
  if (value == "true" || value == "false")
    return (value == "true");
  return value;
};

MCTabs.prototype.displayTab = function(tab_id, panel_id) {
  var panelElm = document.getElementById(panel_id);
  var panelContainerElm = panelElm ? panelElm.parentNode : null;
  var tabElm = document.getElementById(tab_id);
  var tabContainerElm = tabElm ? tabElm.parentNode : null;
  var selectionClass = this.getParam('selection_class', 'current');

  if (tabElm && tabContainerElm) {
    var nodes = tabContainerElm.childNodes;
    // Hide all other tabs
    for (var i=0; i<nodes.length; i++) {
      if (nodes[i].nodeName == "LI")
        nodes[i].className = '';
    }
    // Show selected tab
    tabElm.className = 'current';
  }

  if (panelElm && panelContainerElm) {
    var nodes = panelContainerElm.childNodes;
    // Hide all other panels
    for (var i=0; i<nodes.length; i++) {
      if (nodes[i].nodeName == "DIV")
        nodes[i].className = 'panel';
    }
    // Show selected panel
    panelElm.className = 'current';
  }
};

MCTabs.prototype.getAnchor = function() {
  var pos, url = document.location.href;
  if ((pos = url.lastIndexOf('#')) != -1)
    return url.substring(pos + 1);
  return "";
};

// Global instance
var mcTabs = new MCTabs();

// Select and DeSelect all
function select_deselectAll (formname, elm, group) {
  var frm = document.forms[formname];
  
  // Loop through all elements
  for (i=0; i<frm.length; i++) {
    // Look for our Header Template's Checkbox
    if (elm.attributes['checkall'] != null && elm.attributes['checkall'].value == group) {
      if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
      frm.elements[i].checked = elm.checked;
    }
    // Work here with the Item Template's multiple checkboxes
    else if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group) {
      // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
      if(frm.elements[i].checked == false) {
        frm.elements[1].checked = false; //Uncheck main select all checkbox
      }
    }
  }
}

// Flash Detect
var requiredVersion = 8;

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var maxVersion = 9;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;


var isAOL = (navigator.appVersion.indexOf("AOL") != -1) ? true : false;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;


jsVersion = 1.1;

if(isIE && isWin && !isAOL){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('<\/SCR' + 'IPT\> \n');
}


function detectFlash() {
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
      var flashVersion = parseInt(flashDescription.substring(16));

      flash2Installed = flashVersion == 2;
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }

  for (var i = 2; i <= maxVersion; i++) {
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }

  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;

  if (actualVersion >= requiredVersion)
    hasRightVersion = true;
}

detectFlash();


// START TAB SCRIPT
var enabletabpersistence=1 // enable tab persistence via session only cookies, so selected tab is remembered?

var tabcontentIDs=new Object()

function expandcontent(linkobj){
  var ulid=linkobj.parentNode.parentNode.id //id of UL element
  var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents

  for (var i=0; i<ullist.length; i++){
    ullist[i].className=""  //deselect all tabs
    if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
    document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
  }
  linkobj.parentNode.className="selected"  //highlight currently clicked on tab
  document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
  saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function savetabcontentids(ulid, relattribute){ // save ids of tab content divs
  if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
    tabcontentIDs[ulid]=new Array()
    tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
  if (enabletabpersistence==1) //if persistence feature turned on
  setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
  var ullist=document.getElementById(ulid).getElementsByTagName("li")
  for (var i=0; i<ullist.length; i++){
    if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
      return ullist[i].getElementsByTagName("a")[0]
      break
    }
  }
}

function initializetabcontent(){
  for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
    if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
    setCookie(arguments[i], "")
    var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
    var ulobj=document.getElementById(arguments[i])
    var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL

    for (var x=0; x<ulist.length; x++){ //loop through each LI element
      var ulistlink=ulist[x].getElementsByTagName("a")[0]
      if (ulistlink.getAttribute("rel")){
        savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
        ulistlink.onclick=function(){
          expandcontent(this)
          return false
        }
        if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
        expandcontent(ulistlink) //auto load currenly selected tab content
      }
    } //end inner for loop

    if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
      var culistlink=getullistlinkbyId(arguments[i], clickedontab)
      if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
        expandcontent(culistlink) //auto load currenly selected tab content
      else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
        expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
    }
  } //end outer for loop
}

function getCookie(Name){
  var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
  if (document.cookie.match(re)) //if cookie found
  return document.cookie.match(re)[0].split("=")[1] //return its value
  return ""
}

function setCookie(name, value){
  document.cookie = name+"="+value //cookie value is domain wide (path=/)
}
// END TAB SCRIPT

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function openwin(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Open window
var newWin = null;
function popMeUp(strURL,strType,strWidth,strHeight) {
  if (newWin != null){
    if(!newWin.closed) newWin.close();
  }
  var left=((window.screen.width/2)-(strWidth/2))-12;
  var top=((window.screen.height/2)-(strHeight/2));
  var strOptions="";
  if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
  if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
  if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth+",left="+left+",top="+top;
  newWin = window.open(strURL, 'newWin', strOptions);
  newWin.focus();
  u = new String(strURL);
  l = new String(Window.location);
  if(u.indexOf("rostapopper") > -1){
    if(l.indexOf("?") > -1){
      Window.location=Window.location + "&voted=true";
    }else{
      Window.location=Window.location + "?voted=true";
    }  
  }
}

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
  newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
  newWindow.document.open();
  newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
  newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+alt+'>');
  newWindow.document.write('</body></html>');
  newWindow.document.close();
  newWindow.focus();
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function tab(obj,nextobj,mlength){
  if(!mlength) mlength = obj.size;
  if(obj.value.length>=mlength){
    obj.value = obj.value.substr(0,mlength);
    nextobj.focus();
  }
}
