function doNothing() { }

function BGNew(obj, new_style, message) { 
  obj.className = new_style; 
  window.status = message; 
}

function BGNew2(obj, new_style) { 
  obj.className = new_style;   
}

function setLinkMouseOver(obj, newClass, label) {
  obj.className = newClass;
  obj.style.cursor='pointer';
  setLabel(label);
}

function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}


function search(field) {  
  if (field.value.length > 0 && field.value != 'Search Site') {           
     return true;  
  } else {   
     return false;
  }
}

function searchSite(form) {
  field = form.searchPhrase;
  if (field.value.length > 0 && field.value != 'Search Site') {
     form.submit();
  } 
}

function setLinkMouseOut(obj, newClass) {
  obj.className = newClass;  
  clearLabel();
}

function clearLabel() {
  window.status = "";
}

function setLabel(label) { 
  window.status = label;
}

function newWindowCustom(mypage, myname, scroll, w, h) {
        var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=1';
	win = window.open(mypage, myname, winprops);
        win.focus();
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function newWindowCloneReturn(mypage, myname, scroll) {
    win = window.open(mypage);
    win.focus();
    return win;
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function newWindowClone(mypage, myname, scroll) {
    win = window.open(mypage);
    win.focus();
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function newWindowLarge(mypage, myname, scroll) {
	var w = 490;
	var h = 770;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=1'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  //return win;
}

function newWindowSmall(mypage, myname, scroll) {
	var w = 400;
	var h = 320;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  //return win;
}

function eolaWindow(url) {
  var w = 1000;
  var h = 770;
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',status=0,resizable=1,scrollbars=1';
  win = window.open(url, 'eola', winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  return win;
}

function viewMap(lat, lon, zoom) {  
   var url = 'Display-Map.do'; 
   if (lat != undefined && lon != undefined && zoom != undefined) {
     url = 'Display-Map.do?lat='+lat+'&lon='+lon+'&zoom='+zoom;   
   }
   newWindow = window.open(url,'mapViewPopup','top=0,left=0,width=675,height=635,resizable=0,status=1');  
   newWindow.focus();   
}

function moan()
{   
    //document.getElementById("beep").innerHTML = ' <EMBED SRC="moan.wav" WIDTH=1 HEIGHT=1 HIDDEN="true" AUTOSTART="true" LOOP="false" volume="100">';  
}

function kiss()
{   
    document.getElementById("beep").innerHTML = ' <EMBED SRC="kiss.wav" WIDTH=1 HEIGHT=1 HIDDEN="true" AUTOSTART="true" LOOP="false" volume="100">';  
}

function ding()
{   
    document.getElementById("beep").innerHTML = ' <EMBED SRC="ding.wav" WIDTH=1 HEIGHT=1 HIDDEN="true" AUTOSTART="true" LOOP="false" volume="100">';  
}

function clearSearchBox(field) {
  if (field.value == "Search Site") {
    field.value = "";
  }  
}

function frameAdjust() {
  var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  if (document.getElementById("Calendar") != null) {
      myFrame = document.getElementById("Calendar");
      if (IE6) {
        myFrame.style.position = 'absolute';
        myFrame.style.top = '225';
        myFrame.style.right = '0';    
        myFrame.style.left = '-272';
        myFrame.style.bottom = '0';
      } 
  }
}
  
function CDownloadUrl(method, url, sendContent, func) {
   var httpObj;
   var browser = navigator.appName;
   if(browser.indexOf("Microsoft") > -1)
      httpObj = new ActiveXObject("Microsoft.XMLHTTP");
   else
      httpObj = new XMLHttpRequest();
   
   url += "&rnd="+new Date().getTime();   
   httpObj.open(method, url, true);
   if (sendContent) {
     httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     httpObj.setRequestHeader("Content-length", sendContent.length);
     httpObj.setRequestHeader("Connection", "close");
   }
   httpObj.onreadystatechange = function() {
      if(httpObj.readyState == 4){
         if (httpObj.status == 200) {          
            var contenttype = httpObj.getResponseHeader('Content-Type');
            if (contenttype.indexOf('xml')>-1) {                      
               func(httpObj.responseXML);
            } else {
               func(httpObj.responseText);
            }
         } else {
            func('Error: '+httpObj.status);
         }
      }
   };
   httpObj.send(sendContent);
}


function sendXMLHttpRequest(url) {
  req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    try {
       req = new XMLHttpRequest();
    } catch(e) {
      req = false;
    }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
        try {
           req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
               req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
               req = false;
            }
        }
    }
    
    if(req) {          
       req.onreadystatechange = processReqChange;                
       req.open("GET", url, true);
       req.send("");
    }
}

function processReqChange() { 
}


var sessionTimeoutTimerIntervalId;
var timeoutTimerCountdown;
 
function sessionTimeoutAlert() {  
    document.getElementById("timeoutTimerDisplay").innerHTML = " -:--";  
    window.focus();
    var sessionTimeoutPopUp = document.getElementById("sessionTimeoutWindow");  
    ding();
    sessionTimeoutPopUp.style.display = "block";     
    sessionTimeoutPopUp.scrollIntoView(true);
    addEvent(window, 'scroll', function(event) {
	document.getElementById("sessionTimeoutWindow").scrollIntoView(true);
    });
    timeoutTimerCountdown = 120000; // 2 minute countdown    
    sessionTimeoutTimerIntervalId = setInterval("updateTimeoutTimer()", 1000);
}

function keepSessionAlive() {
    // send a request to the server to keep session alive
    var sessionTimeoutPopUp = document.getElementById("sessionTimeoutWindow");
    sessionTimeoutPopUp.style.display = "none"; 
    sendXMLHttpRequest('Display-EolaMessage.do');
    clearInterval(sessionTimeoutTimerIntervalId);
    sessionTimeOutId = setTimeout("sessionTimeoutAlert()",  sessionTimoutWarning);       
    removeEvent(window, 'scroll', function(event) {
	document.getElementById("sessionTimeoutWindow").scrollIntoView(true);
    });
}

function updateTimeoutTimer() {  
    var timeoutTimerDisplay = document.getElementById("timeoutTimerDisplay");
    var seconds = timeoutTimerCountdown / 1000;
    var minutes = seconds / 60;
    seconds %= 60;   
    timeoutTimerDisplay.innerHTML = Math.floor(minutes) + ":" + Math.floor(seconds).numberFormat("00");   
    if (timeoutTimerCountdown <= 0) {
      // load expire page
      document.location.href = sessionExpireURL;
      //document.location.href = "NetforumLogin.do?method=logoff";
    }
    timeoutTimerCountdown = timeoutTimerCountdown - 1000;        
    if (timeoutTimerCountdown == 30000) {
        // 30 second warning
        ding();
    }
}

function addEvent(obj,type,fn){
    if(obj.addEventListener) obj.addEventListener(type,fn,false);
    else if(obj.attachEvent){
        obj["e"+type+fn]=fn;
        obj[type+fn]=function(){obj["e"+type+fn](window.event);}
        obj.attachEvent("on"+type,obj[type+fn]);
    }
}


function removeEvent(obj,type,fn){
  if(obj.removeEventListener) obj.removeEventListener(type,fn,false);
  else if(obj.detachEvent){
    obj.detachEvent("on"+type,obj[type+fn]);
    obj[type+fn]=null;
    obj["e"+type+fn]=null;
  }
}

function validateForm(form) {
  // required fields in stored in hidden field "requiredFields" as
  // fieldname1,fieldname2,fieldname3
  var errorMsg = "Please enter ALL *required fields.";
 
  var error = false;
  if (form.requiredFields != undefined) {
      var requiredFields = form.requiredFields.value.split(",");
      for (var i=0; i<requiredFields.length; i++) {
          var requiredFieldName = requiredFields[i];
          if (form[requiredFieldName] != undefined) {            
              if (form[requiredFieldName].value.length <= 0 ||
                  form[requiredFieldName].value == 'undefined') {
                  error = true;                  
              }
          }          
      }                
  }
  
  if (error) {
      alert(errorMsg);
      return false;
  } else {
    if (form['Submit'] != undefined) {
      form['Submit'].disabled = true;
    }
    if (document.getElementById('submitMsg') != undefined) {
      document.getElementById('submitMsg').innerHTML = "Please wait, uploading file...";
    }
    return true;
  }
  
}

function viewMediaLogin(domain) {
    if (window.opener != undefined) {
      window.opener.location.href= "http://"+domain+"/NetforumLogin.do?method=loginRequiredForm";
      window.close();
    } else {
      document.location.href= "http://"+domain+"/NetforumLogin.do?method=loginRequiredForm";
    }
}


var URL = {
	// public method for url encoding
	encode : function (string) {    
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {   
		return this._utf8_decode(unescape(string)).replace(/\+/g, " ");
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}
}

function toggleTab(name, currentTab) {
  tab = document.getElementById(currentTab);
  tab_button =  document.getElementById(currentTab+'_tab');
  tab.style.display = 'none';
  //tab.style.visibility = 'collapse';
  tab_button.onmouseover = function() {
     BGNew(this,'TabOn','Tab');
     this.style.cursor='pointer';
  }
  tab_button.onmouseout = function() {
     BGNew(this,'TabOff','')
     this.style.cursor='default'
  }
  tab_button.className = "TabOff";

  tab_button =  document.getElementById(name+'_tab');

  tab_button.onmouseover = "";
  tab_button.onmouseout = "";
  tab_button.className = "TabOn";
  document.getElementById(name).style.display = 'inline';
  //document.getElementById(name).style.visibility = 'visible';
}

function displayContentPage(pageNum) {
  currentPage = document.getElementById("contentPage"+currentContentPage);
  currentPage.style.display = 'none';
  newPage = document.getElementById("contentPage"+pageNum);
  newPage.style.display = 'inline';  
  document.getElementById("pageNav"+currentContentPage).className = 'APNbers';
  document.getElementById("pageNav"+pageNum).className = 'APNbersOn';
  currentContentPage = pageNum;
  if (currentContentPage > 1) {    
     document.getElementById("contentAuthor").style.display = 'none';
     document.getElementById("pageNum").style.display = 'inline';
     document.getElementById("pageNum").innerHTML = 'Page '+pageNum+" of "+totalContentPages;
  } else {     
     document.getElementById("contentAuthor").style.display = 'inline';
     document.getElementById("pageNum").style.display = 'none';
  }
  window.location.hash = 'contentTop';
  //scroll(0,250);
}

function nextContentPage() {
  if (currentContentPage < totalContentPages) {
    displayContentPage(currentContentPage+1);
  } 
}

function prevContentPage() {
  if (currentContentPage > 1) {
    displayContentPage(currentContentPage-1);
  }
}
