// JavaScript Document
//alert('Loading all');
var xmlHttp=null;
var d = document;
var theTitle = document.title;

// Browser functions
function BrowserInfo(){
  this.name = navigator.appName;
  this.codename = navigator.appCodeName;
  this.version = navigator.appVersion.substring(0,4);
  this.platform = navigator.platform;
  this.javaEnabled = navigator.javaEnabled();
  this.screenWidth = screen.width;
  this.screenHeight = screen.height;
}
var browser = new BrowserInfo();

function getWinWidth() {
          if (browser.name == "Netscape") {
                    return(window.innerWidth);
		  }else if (browser.name == "Microsoft Internet Explorer") {
			  if (parseInt(browser.version) > 3){
                    return(document.documentElement.clientWidth);
			  }else{
				  return(document.body.clientWidth);
			  }
          }else {
                    return("no go!");
          }
}

function getWinHeight() {
          if (browser.name == "Netscape") {
               return(window.innerHeight);
		  }else if (browser.name == "Microsoft Internet Explorer") {
			  if (parseInt(browser.version) > 3){
				  return(document.documentElement.clientHeight);
			  }else{
				  return(document.body.clientHeight);
			  }
          }else {
               return("no go!");
          }
}

function findFldIndex(n){
	var i = 0;
	var done = false;
	while((i < p.memberIndex.length) && !done){
		if (p.memberIndex[i] == n){
			return i;
			done = true;
		}
		i++;
	}
	return false;
}

// Layer functions
function createLayer(name, inleft, intop, width, height, visible, content) {
          var layer;
          if (browser.name == "Netscape") {
            document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
            document.writeln(content);
            document.writeln('</layer>');
          } else {
            document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
            document.writeln(content);
            document.writeln('</div>');
          }
}

function replaceLayerContent(name, content) {
          var layer = findObj(name);
         layer.innerHTML = "'" + content + "'";
}

function showHideLayers(){ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-1); i+=2){
    if ((obj = findObj(args[i])) != null){
      visStr = args[i+1];
      if (obj.style){
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}

function getLayerWidth(name){
	var theLayer = findObj(name);
	alert(theLayer.style.width);
}

function resizeLayer(name, x, y) {
          var win = window;
		  var theLayer = findObj(name);
          if (browser.name == 'Netscape'){
                    theLayer.outerWidth=w;
                    theLayer.outerHeight=h;
          }else{
                    theLayer.resizeTo(w,h);
          }
}

function resetLayers(){
	var winHeight = getWinHeight();
	var menuFrame = findObj('theMenu');
	findObj('bgPageBottom').style.top = (winHeight - 100) + 'px';
	findObj('bgMenuBottom').style.top = (winHeight - 76) + 'px';
	findObj('bgMenu').style.height = (winHeight - 133) + 'px';
	findObj('bgPage').style.height = (winHeight - 163) + 'px';
	findObj('mainPage').style.height = (winHeight - 135) + 'px';
	findObj('theMenu').style.height = (winHeight - 173) + 'px';
}
function resetMenuLayers(){
	var winHeight = getWinHeight();
	findObj('aMenuList').style.height = (winHeight - 10) + 'px';
}

function findObj(theObj, theDoc){
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function preloadImages(){
  if(document.images){
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    for(i=0; i<args.length; i++){
      if (args[i].indexOf("#")!=0){
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}


// Mouse functions
function disableRightClick(e){
  var message = "Right click disabled";
  if(!document.rightClickDisabled){
    if(document.layers){
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }else{
	  document.oncontextmenu = disableRightClick;
	}
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all)){
    if (e.which==2||e.which==3){
      alert(message);
      return false;
    }
  }else{
    alert(message);
    return false;
  }
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e){
  	// Internet Explorer
  		try{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e){
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}
function trimAll (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i > 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

var Base64 = {
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = Base64._utf8_decode(output);
		return output;
	},

	// 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 refreshMenu(){
	var theUrl = "menu.php?userID=" + p.member[1];
	var tMenu = p.findObj('theMenu');
	if (tMenu.src){
		tMenu.src = theUrl;
	}else{
		tMenu.location = theUrl;
	}
}

//alert('All loaded');
