// -----------UTILITY------------------------
// version= .8


function clearList(obj){
	
	
	if(obj)	obj.innerHTML ='';
}
function selectListItem(li, active){

	var ul = li.parentNode;
	var lis = li.parentNode.getElementsByTagName('li');
	for(var x=0; x<lis.length; x++) {
	
		if(active>=0) {
		
			if(active==x) lis[x].className = 'active';
			else lis[x].className = '';
		
		} else {
			lis[x].className = '';
		}
	}
	li.className = 'active';
}





// XML ----------------------

function getText(node){
	
	if(isIE) return node.text;
	else if(node.firstChild) return node.firstChild.nodeValue;
	else return node.textContent;
}

function getNodeText(node, tag){
	
	return getText(node.getElementsByTagName(tag)[0]);
	
}

function getChildNode(element, index){
	if(isIE) return element.childNodes[index-1];
	else {
		
		return element.childNodes[index];
	}
}
function parseDOM(str){
	return (new DOMParser()).parseFromString(str, "text/xml");
}
function getXMXHTTPRequest() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
	try { return new XMLHttpRequest(); } catch(e) {};
}

var TRange=null

function findString (str, txt) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (navigator.appName=="Netscape") {

  // NAVIGATOR-SPECIFIC CODE

  strFound=self.find(str);
  if (!strFound) {
   strFound=self.find(str,0,1)
   while (self.find(str,0,1)) continue
  }
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {

  // EXPLORER-SPECIFIC CODE

  if (TRange!=null) {
   TRange.collapse(false)
   strFound=TRange.findText(str)
   if (strFound) TRange.select()
  }
  if (TRange==null || strFound==0) {
   TRange=self.document.body.createTextRange()
   strFound=TRange.findText(str)
   if (strFound) TRange.select()
  }
 }
 return strFound;
}
//-->


function getGetValue(key){
	
	var str = new String(window.location);
	if ((str.indexOf("?") != -1)) { // jump ref
		value = str.substr((str.indexOf(key)));
		return value;
	} else {
		return false;
	}
}
function getQueryString(){
	
	var str = new String(window.location);
	if ((str.indexOf("?") != -1)) { // jump ref
		value = str.substr((str.indexOf("?")+1));
		return value;
	} else {
		return false;
	}
}


// some array prototypes
Array.prototype.removeElement =  function() { 
    for (var i=0; i<this.length; i++) { 
      if (this[i] == arguments[0]) {
        for (var j=i;j<this.length-1;j++)
          this[j] = this[j+1];
        this.pop();
        break;
      }
    }
  };
  
/**
  * array_search
  * 
  * Searches the array for a given value and returns the (highest) corresponding key if successful, -1 if not found.
  *
  * @param val The value to search for.
  * @param arr The array to search in.
  */
function array_search(val, arr)
{
	var i = arr.length;

	while (i--)
		if (arr[i] && arr[i] === val) break;

	return i;
}

function randomNumber(low, high){
	
	Math.floor(high*Math.random());
	return Math.floor(high*Math.random());
}

function getRandomNumbers(number, low, high){

	var nums = Array();
	for(var n=0; n<number; n++){
		nums.push(randomNumber(low, high));
	}
	return nums;
}
function loadJSFiles(JSdocs) {
	var head = document.getElementsByTagName("head")[0];
	for (var i=0; i<JSdocs.length; i++) {
		var script = document.createElement("script");
		script.setAttribute("type","text/javascript");
		script.setAttribute("src",JSdocs[i]);
		head.appendChild(script);
	}
}
function loadCSSFiles() {
	var head = document.getElementsByTagName("head")[0];
	for (var i=0; i<CSSdocs.length; i++) {
		var sheet = document.createElement("link");
		sheet.setAttribute("type","text/css");
		sheet.setAttribute("href",CSSdocs[i]);
		sheet.setAttribute("rel",'stylesheet');
		head.appendChild(sheet);
	}
}

function modalWin(url, height, width) {
	
	
	if (window.showModalDialog) {
		
		//var args = Array();
		
		//return window.open(url,'name','height=' + height + ',width=' + width + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
		
		return window.showModalDialog(url,window,"dialogWidth:" + (width+5) + "px;dialogHeight:" + (height+40) + "px;scroll:no");
	

	
	} else {
		return window.open(url,'name','height=' + height + ',width=' + width + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}




//
// JSHttpRequest v1.12. (C) Dmitry Koterov, 2005-01-27.
// http://forum.dklab.ru/users/DmitryKoterov/
//
//
//
function JSHttpRequest() {}
(function() {
  var count       = 0;
  var pending     = {};
  var cache       = {};
  var spanReuse   = null;

  // Uncomment if you want to switch on <SCRIPT> reusing.
  // But be carefull: seems FireFox does not work with reusing correctly
  // (long delay on fast data reloading via existed <SCRIPT>).
  //spanReuse   = [];

  // Called by server script on data load.
  JSHttpRequest.dataReady = function(id, text, js) {
    var undef;
    var th = pending[id];
    if (th) {
      if (th.caching) cache[th.hash] = [text, js];
      th._dataReady(text, js);
    } else if (typeof(th) != typeof(undef)) {
      alert("ScriptLoader: unknown pending id: "+id);
    }
  }

  JSHttpRequest.prototype = {
    // Standard properties.
    onreadystatechange: null,
    readyState: 0,
    responseText: null,
    responseXML: null,
    status: 200,
    statusText: "OK",
    // Additional properties.
    responseJS: null,
    caching: false,
    SID: null,
    // Internals.
    _span: null,
    _id: null,

    abort: function() { with (this) {
      readyState = 0;
      if (onreadystatechange) onreadystatechange();
      _cleanupScript();
      delete pending[_id];
    }},

    open: function(method, url, asyncFlag, username, password) {
      if ((""+method).toLowerCase() != 'get') {
        alert('Only GET method is supported!');
        return false;
      }
      this.url = url;
      return true;
    },

    send: function(content) {
      var id = count++;
      var query = [];
      if (content instanceof Object) {
        for (var k in content) {
          query[query.length] = escape(k) + "=" + escape(content[k]);
        }
      } else {
        query = [content];
      }
      var qs = query.join('&');
      query = id + ':' + (this.SID || '') + ':' + qs;
      var href = this.url + (this.url.indexOf('?')>=0? '&' : '?') + query;
      var hash = this.url + '?' + qs;
      this.hash = hash;
      if (this.caching && cache[hash]) {
        var c = cache[hash];
        this._dataReady(c[0], c[1]);
        return false;
      }
      this._obtainScript(id, href);
      return true;
    },

    getAllResponseHeaders: function() {
      return '';
    },

    getResponseHeader: function(label) {
      return '';
    },

    setRequestHeader: function(label, value) {
    },

    //
    // Internal functions.
    //

    _dataReady: function(text, js) { with (this) {
      if (text !== null || js !== null) {
        readyState = 4;
        responseText = responseXML = text;
        responseJS = js;
      } else {
        readyState = 0;
        responseText = responseXML = responseJS = null;
      }
      if (onreadystatechange) onreadystatechange();
      _cleanupScript();
    }},

    _obtainScript: function(id, href) { with (document) {
      var span = null;
      if (spanReuse == null || !spanReuse.length) {
        span = body.appendChild(createElement("SPAN"));
        span.style.display = 'none';
        span.innerHTML = 'Text for stupid IE.<s'+'cript></' + 'script>';
        //span.innerHTML = 'Text for stupid IE.<s'+'cript language="JavaScript" src="'+href+'"></' + 'script>';
      } else {
        span = spanReuse[spanReuse.length-1];
        spanReuse[spanReuse.length-1] = null;
        spanReuse.length--;
      }
      pending[id] = this;
      setTimeout(function() {
        var s = span.getElementsByTagName("script")[0];
        s.language = "JavaScript";
        if (s.setAttribute) s.setAttribute('src', href); else s.src = href;
      }, 10);
      this._id = id;
      this._span = span;
    }},

    _cleanupScript: function() {
      var span = this._span;
      if (span) {
        this._span = null;
        setTimeout(function() {
          if (spanReuse != null) {
            spanReuse[spanReuse.length] = span;
          } else {
            // without setTimeout - crash in IE 5.0!
            span.parentNode.removeChild(span);
          }
        }, 50);
      }
      //window.status = document.body.childNodes.length + " - " + (spanReuse? spanReuse.length : 'no span reusing')
      return false;
    }
  }
})();



function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	if (theWidth > 800)
	{
		setStylesheet("1024");
	}
	else
	{
		setStylesheet("800");
	}
	return true;
}


function getBrowserWidth()
{
if(navigator.appName == "Netscape"){

var windowwidth = window.innerWidth;
var windowheight = window.innerHeight;

}else if(navigator.appName == "Microsoft Internet Explorer"){

//alert('IE');
var windowwidth = document.body.clientWidth;
var windowheight = document.body.clientHeight;

}else{

//alert('dunno dude');
var windowwidth = "can't tell you";

} 
return windowwidth;
}


function setStylesheet(styleTitle)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	return true;
}

















var noticeFader= false;
var Feedback = {
	
	msg: "",
	title: "ALERT",
	color: "black",
	backgroundOpacity: 65,
	timer: false,
	active: false,
	OldStyle: {},
	videoPlaying: false,
	buttons: {
		
		
		
	},
	show: function(){
		
		Feedback.display(Feedback.msg, Feedback.title);
		
		
	},
	customDisplay: function(msg, title, color, opacity, style){
							
			
			//Feedback.oldStyle = document.getElementById('notice-text').style.closeNode();
			Feedback.OldStyle = {};
			var obj = document.getElementById('notice-text')
			for(x in obj.style){
				Feedback.OldStyle[x] = obj.style[x];
				//alert('preserving: ' + x +': ' + obj.style[x]);
			}
			
			
			//alert(Feedback.oldStyle);
			
			for(x in style){
				
				//alert('setting: ' + x + ': ' + style[x]);
				document.getElementById('notice-text').style[x] = style[x];
			}
			
			Feedback.display(msg, title, color, opacity);
			
	},
	darkenScreen: function(opacity, color){
		
		Feedback.hideSelects();
		
		var div = document.getElementById('notice');
	
		div.style.width = '1024px';
		div.style.height = '768px';
		div.style.display = 'block';
		div.style.position = 'absolute';
		div.style.top = 0;
		div.style.left = 0;
		div.style.zIndex = 500;
		div.style.display = 'block';
		
		if(color)div.style.backgroundColor = color;
		else div.style.backgroundColor = 'black';
		
		if(opacity) noticeFadedOpacity = opacity;
		else noticeFadedOpacity = 45;
		
		setOpacity(document.getElementById('notice'),  noticeFadedOpacity);
		
		div.onclick = function(){
			
			//Feedback.dismiss();
		}
	},
	hideSelects: function(){
		
		var s = document.getElementsByTagName('select');
		for(var x=0; x<s.length; x++){
			
			s[x].style.visibility = 'hidden';	
		}
	},
	showSelects: function(){
		
		var s = document.getElementsByTagName('select');
		for(var x=0; x<s.length; x++){
			
			s[x].style.visibility = 'visible';	
		}
	},
	showTrace: false,
	trace: function(msg, title){
		
		if(Feedback.showTrace) return Feedback.display(msg, title, 'green', 80);
			
	},
	display: function(msg, title, color, opacity){
	
		/*
		if(title) YAHOO.example.container.generalDialog.setHeader(title);
		else 	YAHOO.example.container.generalDialog.setHeader('Alert!');
		
		
		YAHOO.example.container.generalDialog.setBody(msg);
		YAHOO.example.container.generalDialog.show();

		return;
	*/
		
		
		Feedback.active = true;
		var div = document.getElementById('notice');
	
		div.style.width = '1024px';
		div.style.height = '768px';
		div.style.display = 'block';
		div.style.position = 'absolute';
		div.style.top = 0;
		div.style.left = 0;
		div.style.zIndex = 1000;
		div.style.display = 'block';
		
		var content = document.getElementById('notice-content');
		content.innerHTML = msg;
		
		if(color)div.style.backgroundColor = color;
		else div.style.backgroundColor = 'black';
			
		if(title) document.getElementById('notice-title').innerHTML = title;
		else 	document.getElementById('notice-title').innerHTML = 'Alert!';
			
		if(opacity) noticeFadedOpacity = opacity;
		else noticeFadedOpacity = 45;
		
		setOpacity(document.getElementById('notice-text'), 100);
		document.getElementById('notice-text').style.zIndex = 1000;
		
		setOpacity(document.getElementById('notice'),  noticeFadedOpacity);
		setOpacity(document.getElementById('notice-text'), 100);
		
	},
	dismiss: function(){
		
		Feedback.showSelects();
		
		if(Feedback.videoPlaying){
			//alert(document.getElementById('video-player').childNodes.length);
			document.getElementById('video-player').removeChild(document.getElementById('video-player').firstChild);
			Feedback.videoPlaying = false;
			document.getElementById('video-player').style.zIndex = -900;
		
			if(document.getElementById('video-player-title')){
				document.getElementById('video-player-title').style.zIndex = -900;
			}
			if(document.getElementById('video-title')){
				document.getElementById('video-title').innerHTML = '';
			}
					}
		
		
		if(Feedback.onclose){
			
			
			Feedback.onclose();
			Feedback.onclose = false;
		}
		
		setOpacity(document.getElementById('notice-text'), 0);
		setOpacity(document.getElementById('notice'), 0);
	
	
		
	
		var obj = document.getElementById('notice-text')
		for(x in Feedback.OldStyle){
		
			try {
				obj.style[x] = Feedback.OldStyle[x];
				//alert('preserving: ' + x +': ' + obj.style[x]);
			} catch(e){
				
			}
		}
		Feedback.OldStyle = {};
	
	
	
		document.getElementById('notice-text').style.zIndex = -900;
		document.getElementById('notice').style.zIndex = -900;
		document.getElementById('notice-text').style.zIndex = -900;
		document.getElementById('notice').style.zIndex = -900;
		
		document.getElementById('notice-text').style.left = '100px';
		
		document.getElementById('notice-content').innerHTML = '';
	
		document.getElementById('noticer-text').style.display = 'none';
		
		Feedback.active = false;
	},
	
	timedNotice: function(msg, delay) {
		
		Feedback.title = 'timedNotice';
		Feedback.msg = msg;
		Feedback.timer = setTimeout("Feedback.show()", 100);
	},
	
	loading: function(){
		
		Feedback.title = '<img src="images/loading.gif" /> Loading...';
		Feedback.msg = '<img src="images/loading.gif" width="100" height="100" />';
		
		Feedback.timer = setTimeout("Feedback.show()", 800);
		
		//alert('ok');
		
		
	},
	loaded: function(){
		
		clearTimeout(Feedback.timer);
		if(Feedback.active){
			Feedback.display('loaded');
			Feedback.dismiss();
		}
		
	},
	onclose: false,
	dialog: function(text, title, options){
		
		var bottom = "";
		if(options){
			//alert('we have dialog options');
			bottom += "<hr />";
			for(x in options){
				
				switch(x){
					case("buttons"):
						bottom += '<div class="buttons">';	
						for(b in options[x]){
							bottom += '<input type="button" value="' + options[x][b].text
										+ '" onclick="' + options[x][b].onclick + '()" />';
						}
						bottom += '</div>';
					break;
					default:
				}
			}
		}
		Feedback.show(text + bottom, title, "black", 90);
	}
};


