// JavaScript Document

	function toggleVis(name,state) {
		if (state == "" || state == undefined) { state = "toggle"; }
		//alert(state);
		if (state == "revert") {
			document.getElementById(name).style.display = "";
		} else {
			if (state == "toggle") {
				v = document.getElementById(name).style.display;								
				if (v == "" || v == "none" || v == false) {
					document.getElementById(name).style.display = "block";
				}  else {
					document.getElementById(name).style.display = "none";
				}								
			} else {
				if (state == "true") {
					document.getElementById(name).style.display = "block";										
				}
				if (state == "false") {
					document.getElementById(name).style.display = "none";									
				}
			}
		}
	}
	
	function openUrl(url, name) {
		window.open("http://"+url,name);
	}

/* -------------------- ACCORDION.JS ----------------------------------------- */
var accordion=function(){
	var tm=sp=2;
	function slider(n){this.nm=n; this.arr=[]}
	slider.prototype.init=function(t,c,k){		
		var a,h,s,l,i; 
		a=document.getElementById(t); 
		//a=$('#t');
		this.sl=k?k:'';
		h=a.getElementsByTagName('dt'); 
		s=a.getElementsByTagName('dd'); 
		this.l=h.length;
		for(i=0;i<this.l;i++){
				var d=h[i]; 
				this.arr[i]=d; 
				d.onclick=new Function(this.nm+'.pro(this)'); 
				if(c==i){
					d.className=this.sl;
				}
		}
		l=s.length;
		for(i=0;i<l;i++){
				var d=s[i]; 
				d.mh=d.offsetHeight; 
				//if(c!=i && c != ""){
				if (c == "") {
					d.style.height=0; d.style.display='none';
				} else {
					if (c != i) {
						d.style.height=0; d.style.display='none';						
					}
				}
		}
	}
	slider.prototype.pro=function(d){
		for(var i=0;i<this.l;i++){
			var h=this.arr[i], s=h.nextSibling; s=s.nodeType!=1?s.nextSibling:s; clearInterval(s.tm);
			if(h==d&&s.style.display=='none') {
				s.style.display=''; 
				su(s,1); 
				h.className=this.sl;
			} else if(s.style.display=='') {
				su(s,-1); h.className='';
			}
		}
	}
	function su(c,f){c.tm=setInterval(function(){sl(c,f)},tm)}
	function sl(c,f){
		var h=c.offsetHeight, m=c.mh, d=f==1?m-h:h; c.style.height=h+(Math.ceil(d/sp)*f)+'px';
		c.style.opacity=h/m; 
		//c.style.filter='alpha(opacity='+h*100/m+')';
		if(f==1&&h>=m){ clearInterval(c.tm); c.style.filter='alpha(opacity=100)'; } else if(f!=1&&h==1){c.style.display='none'; c.style.opacity='0'; clearInterval(c.tm); c.style.filter='alpha(opacity=0)';}
	}
	return{slider:slider}
}();
/*--------------------- ############ ------------------------------------------ */


/* -------------------- VALIDATION.JS ----------------------------------------- */
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 0;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
	
  if ($("#"+target).attr("disabled") != true)  { targetdiv.focus(); }
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
	if (topposition < window.pageYOffset) {
		window.scroll(0,topposition - 200);		
		//alert(topposition + " : " + window.pageYOffset);
	} else {
		//alert("no scrolling required!");
	}
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/validation/msg_arrow.gif"; 
}
/* -------------------- ############# ----------------------------------------- */

/* -------------------- bsn.Crossfader.js ------------------------------------- */
var useBSNns;

if (useBSNns){
	if (typeof(bsn) == "undefined")
		bsn = {}
	var _bsn = bsn;
}else{
	var _bsn = this;
}

_bsn.Crossfader = function (divs, fadetime, delay ){	
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var i=0;i<divs.length;i++)	{
		if (i != 0) {
			document.getElementById(divs[i]).style.opacity = 0;
			document.getElementById(divs[i]).style.filter = "alpha(opacity=0)";
			document.getElementById(divs[i]).style.visibility = "hidden";
			document.getElementById(divs[i]).style.display = "none";			
		}
		document.getElementById(divs[i]).style.position = "absolute";
	}
	
	this.nDur = fadetime;
	this.nDelay = delay;		
	this._newfade();
}

_bsn.Crossfader.prototype._newfade = function(){
	if (this.nID1)
		clearInterval(this.nID1);
	
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct])	this.nAct = 0;
	
	if (this.nAct == this.nOldAct)
		return false;
	
	document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
	document.getElementById( this.aDivs[this.nAct] ).style.display = "";	
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}

_bsn.Crossfader.prototype._fade = function(){
	this.nTime += this.nInt;	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	document.getElementById( this.aDivs[this.nAct] ).style.opacity = op;
	document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.nOldAct > -1)	{
		document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	if (this.nTime == this.nDur)	{
		clearInterval( this.nID2 );		
		if (this.nOldAct > -1) {
			document.getElementById( this.aDivs[this.nOldAct] ).style.display = "none";	
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";				
		}		
		var p=this;
		this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	}
}

_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d){
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}
/*--------------------- ############ ------------------------------------------ */

/* -------------------- TOOLTIP.JS ---------------------------------------------- */
var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();
/*--------------------- ############ ------------------------------------------ */
/* -------------------- VALIDATION.JS ----------------------------------------- */
/*--------------------- ############ ------------------------------------------ */
