function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function png_init() {

	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 

	{
	   for(var i=0; i<document.images.length; i++)
	   {
			  var img = document.images[i]
			  var imgName = img.src.toUpperCase()
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
					 var imgID = (img.id) ? "id='" + img.id + "' " : ""
					 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
					 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
					 var imgStyle = "display:inline-block" + img.style.cssText 
					 if (img.align == "left") imgStyle = "float:left;" + imgStyle
					 if (img.align == "right") imgStyle = "float:right;" + imgStyle
					 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
					 var strNewHTML = "<span " + imgID + imgClass + imgTitle
					 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
					 img.outerHTML = strNewHTML
					 i = i-1
			  }
	   }
	}
}
function expand(divIdClosed, divIdExpanded) {
	document.getElementById(divIdExpanded).style.display = 'block';
	document.getElementById(divIdClosed).style.display = 'none';
}

function collapse(divIdClosed, divIdExpanded) {
	document.getElementById(divIdExpanded).style.display = 'none';
	document.getElementById(divIdClosed).style.display = 'block';
}

/* --------------------------------------------------------------- 
//Tooltips code
------------------------------------------------------------------- */
(function() {
	var VZ_Tooltip = new Class({
		ishim:false,
		cur_launcher:null,
		cur_index:null,
		hide_timer:50,
		show_timer:500,
		cur_dir:'top',
		options:{
			launchers:'tooltip',
			tips:'tip',
			blank_iframe:gn_iframe,
			mode:'linear',
			holder_width:250
		},
		initialize:function(o) {
			this.setProperties(o);
			this.initLaunchersTips('launchers');
			this.initLaunchersTips('tips');
			this.initHolder();
			this.cacheHolder();
			this.initTransitions();
			this.initEvents();
		},
		cacheHolder:function() {
			var d = new Element('div',{
				'styles':{
					'position':'absolute',
					'left':'-1000em',
					'width':'1px',
					'height':'1px'
				}
			});
			d.adopt(this.holder);
			this.body.adopt(d);
			this.body.adopt(this.holder);
			d.remove();
		},
		initLaunchersTips:function(what) {
			if ($type(this[what]) === 'string') {
				this[what+'_class'] = this[what];
				this[what] = $$('.'+this[what+'_class']); 
			} else if ($type(this[what]) === 'array') {
				return;
			} else {
				throw new Error(what + " must either be a string or array");
			}
		},
		initHolder:function() {
			var me = this;
			var th = $('tip-holder');
			this.body = $$('body')[0];

			if ($chk(th)) {
				this.holder = th;
				this.carat = th.getElement('#tip-carat');
				this.content_pad = th.getElement('#tip-content-pad');
				if (this.needsIShim()) {this.initIShim();}
				return;
			}
			if (this.needsIShim()) {this.initIShim();}
			this.holder = new Element('div',
				{'id':'tip-holder',
				'styles':{
					'visibility':'hidden',
					'position':'absolute'
				}
			});
			this.top = new Element('div',{'id':'tip-top'});
			this.bottom = new Element('div',{'id':'tip-bottom'});
			this.left = new Element('div',{'id':'tip-left'});
			this.right = new Element('div',{'id':'tip-right'});
			this.content = new Element('div',{'id':'tip-content'});
			this.content_pad = new Element('div',{'id':'tip-content-pad'});
			this.carat = new Element('div',{'id':'tip-carat','class':'carat-'+me.cur_dir});
			this.tl = new Element('div',{'id':'tip-tl'});
			this.tr = new Element('div',{'id':'tip-tr'});
			this.bl = new Element('div',{'id':'tip-bl'});
			this.br = new Element('div',{'id':'tip-br'});
			
			this.holder.adopt([this.top,this.left,this.bottom,this.carat]);
			this.top.adopt([this.tl,this.tr]);
			this.left.adopt(this.right);
			this.right.adopt(this.content);
			this.content.adopt(this.content_pad);
			this.bottom.adopt([this.bl,this.br]);
			this.body.adopt(this.holder);
		},
		initIShim:function() {
			var me = this;
			var ishim = $('tip-ishim');
			if ($chk(ishim)) {
				this.ishim = ishim;
				return;
			}
			this.ishim = new Element('iframe',{
				'src':me.blank_iframe,
				'id':'tip-ishim',
				'frameborder':'0',
				'scrolling':'0',
				'styles':{
					'position':'absolute',
					'top':'0',
					'left':'0',
					'width':'0',
					'height':'0',
					'display':'none',
					'z-index':'99',
					'filter':'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'	
				}
			});
			this.body.adopt(this.ishim);
		},
		initEvents:function() {
			var me = this;
			this.launchers.each(function(l,i) {
				l.addEvents({
					'mouseenter':function(e) {
						me.cur_launcher = l;
						if (me.isRelated(e)) {return;}
						me.initHolderEvent();
						me.timer = (function() {
							me.cur_index = i;
							me.enter(i);
						}).delay(me.show_timer);
					}.bindWithEvent(),
					'mouseleave':function(e) {
						me.clearTimer();
						if (me.isRelated(e)) {return;}
						me.timer = (function() {
							me.leave();
						}).delay(me.hide_timer);
					}.bindWithEvent()
				});
			});
		},
		initHolderEvent:function() {
			var me = this;
			this.holder.addEvent('mouseleave',function(e) {
					me.clearTimer();
					if (me.isRelated(e)) {return;}
					me.timer = (function() {
						me.leave();
					}).delay(me.hide_timer);
				}.bindWithEvent()
			);
		},
		isRelated:function(e) {
			var relTarg = e.relatedTarget;
			while (relTarg && 
				relTarg !== this.cur_launcher && 
				relTarg !== this.holder && 
				relTarg.tagName.toLowerCase() !== "body" && 
				relTarg.tagName.toLowerCase() !== "html" && relTarg !== document) {
					relTarg = relTarg.parentNode;
				}
			if (relTarg === this.cur_launcher || relTarg === this.holder) {return true;}
			return false;
		},
		clearTimer:function() {
			$clear(this.timer);
		},
		initTransitions:function() {
			var me = this;
			this.toggle_effect = new Fx.Styles(me.holder, {
				duration: 200,
				transition: Fx.Transitions.Quad.easeIn,
				wait: true,
				fps: 24
			});
			
			this.toggle_effect.addEvent('onStart',function(){
					if (me.ishim) {me.toggleIShim();}
					if (me.visible) {
						me.positionHolder();
					}
			});
			this.toggle_effect.addEvent('onComplete',function() {
					if (me.ishim) {me.toggleIShim();}
					if (!me.visible) {
						me.holder.setStyle('left','-1000em');
					}
			});
		},
		validateTip:function() {
			return $chk(this.cur_tip)?true:false;
		},
		findCurTip:function() {
			var me = this;
			var id = '';
			if (this.mode === 'linear') {
				this.cur_tip = this.tips[this.cur_index];
			} else {
				var rel = this.cur_launcher.getProperty('rel');
				var href = this.cur_launcher.getProperty('href');
				var klass = this.cur_launcher.getProperty('class');
				
				if (this.cur_launcher.getTag() === 'a') {
					if (rel && rel.match('#')) {
						id = this.parseRelTip(this.cur_launcher,'rel');
					} else if (href && href.match('#')) {
						id = this.parseRelTip(this.cur_launcher,'href');
					} else if (klass && klass.match('#')) {
						id = this.parseRelTip(this.cur_launcher,'class');	
					}
				} else if(klass && klass.match('#')){
					id = this.parseRelTip(this.cur_launcher,'class');	
				}
				this.tips.each(function(t) {
					if (t.getProperty('id') === id) {
						me.cur_tip = t;
					}
				});
				if (this.validateTip()) {
					this.cur_tip = $(id);
				}
			}
		},
		parseRelTip:function(el,prop) {
			var re = /#(.[^\s]+)/;
			return re.exec(el.getProperty(prop))[1];
		},
		needsIShim:function() {
			if (window.ie6) {
				try	{
					document.execCommand("BackgroundImageCache", false, true); 
				}	catch(err){}
				return true;
			}
			return false;
		},
		enter:function() {
			this.findCurTip();
			if (this.validateTip()) {
				this.setCurDir();
				this.swapContent();
				this.visible = true;
				this.toggle();
			}
		},
		leave:function() {
			this.visible = false;
			this.cur_tip = null;
			this.toggle();
			this.holder.removeEvents();
		},
		toggle:function() {
			var o = this.visible === true?[0,1]:[1,0];
			var vis = this.visible === true?'visible':'hidden';
			this.toggle_effect.stop();
			if (window.ie7 || this.isChrome()) {
				this.holder.setStyle('visibility',vis);
				this.toggle_effect.start();	
			} else {
				this.toggle_effect.start({
					'opacity':o
				});	
			}
			
		},
		toggleIShim:function() {
			if(this.visible){	
				var coords = this.holder.getCoordinates();
				this.ishim.setStyles({
					'width':coords.width,
					'height':coords.height,
					'top':coords.top,
					'left':coords.left,
					'display':'block'
				});
			} else {this.ishim.setStyle('display','none');}
		},
		swapContent:function() {
			var c = this.cur_tip.clone().setStyle('margin','0px');
			if ($chk(this.tips_class)) {c.removeClass(this.tips_class);}
			var w = parseInt(c.getStyle('width'),10);
			if ($chk(w) && w > 0) {
				this.setHolderWidth(w+12);
			} else {
				this.setHolderWidth(this.holder_width);
			}
			c.setStyle('width','auto');
			this.content_pad.empty().adopt(c);
		},
		setCurDir:function() {
			var me = this;
			var dirs = ['top','bottom','left','right'];
			var new_dir = null;
			var bool = false;
			dirs.each(function(dir) {
				new_dir = me.cur_launcher.hasClass(dir)?
					(function() {
						bool = true;
						return dir;
					})():new_dir;
				if (bool !== true) {
					new_dir = me.cur_tip.hasClass(dir)?dir:new_dir;
				}
			});
			this.cur_dir = new_dir !== null?new_dir:this.cur_dir;
			return this.cur_dir;
		},
		setHolderWidth:function(w) {
			this.holder.setStyle('width',w+'px');
		},
		positionCarat:function(dir) {
			var pos;
			switch(dir) {
				case "left":
					pos = "right";
					break;
				case "right":
					pos = "left";
					break;
				case "top":
					pos = "bottom";
					break;
				case "bottom":
					pos = "top";
					break;	
			}
			this.carat.setProperty('class','carat-'+pos);
		},
		positionHolder:function() {
			this.setCoords();
			this.setAvailableSpace();
			this.dirCompensation();
			this.setHolderPositionCoords();				
			this.setHolderPosition(this.holder_left,this.holder_top);
		},
		dirCompensation:function() {
			var tas = this.tas, 
					bas = this.bas, 
					las = this.las,
					ras = this.ras,
					hc = this.h_cds,
					dir = this.cur_dir;
			this.cur_dir = dir === 'bottom'?
					hc.height<bas?'bottom':
					hc.height<tas?'top':
					hc.width<ras?'right':
					hc.width<las?'left':
					dir
				:	dir === 'right'?
					hc.width<ras?'right':
					hc.width<las?'left':
					hc.height<tas?'top':
					hc.height<bas?'bottom':
					dir
				:	dir === 'left'?
					hc.width<las?'left':
					hc.width<ras?'right':
					hc.height<tas?'top':
					hc.height<bas?'bottom':
					dir
				:	dir === 'top'?
					hc.height<tas?'top':
					hc.height<bas?'bottom':
					hc.width<ras?'right':
					hc.width<las?'left':
					dir
				:	dir;
			this.positionCarat(this.cur_dir);
		},
		setHolderPositionCoords:function() {			
			var hc = this.h_cds,
					lc = this.l_cds,
					dir = this.cur_dir,
					pad = 11,
					l_center = (lc.left+(lc.width/2)-37), 
					t_center = (lc.top+(lc.height/2)-37),
					marker = 50,
					l,t;			
			
			switch(dir) {
				case 'top':
					l = lc.width<marker?l_center:lc.left;
					t = lc.top-hc.height-pad;
					break;
				case 'bottom':
					l = lc.width<marker?l_center:lc.left;
					t = lc.bottom+pad;
					break;
				case 'left':
					t = lc.height<marker?t_center:lc.top;
					l = lc.left-hc.width-pad;
					break;
				case 'right':
					t = lc.height<marker?t_center:lc.top;
					l = lc.right+pad;
					break;
			}
			this.holder_left = l;
			this.holder_top = t;
		},
		setHolderPosition:function(left,top) {
			this.holder.setStyles({
				'left':left+'px',
				'top':top+'px'
			});
		},
		setCoords:function() {
			this.w_cds = {'width': window.getWidth(), 'height': window.getHeight()};
			this.s_cds = {'left': window.getScrollLeft(), 'top': window.getScrollTop()};
			this.l_cds = this.cur_launcher.getCoordinates();
			this.h_cds = this.holder.getCoordinates();
		},
		setAvailableSpace:function() {
			//top,bottom,right,left
			this.tas = this.l_cds.top - this.s_cds.top;			
			this.bas = this.w_cds.height-this.l_cds.bottom+this.s_cds.top;
			this.ras = this.w_cds.width+this.s_cds.left-this.l_cds.right;
			this.las = this.l_cds.left-this.s_cds.left;
		},
		setProperties:function(o) {
			this.setOptions(o);
			if (this.options) {
				for (var op in this.options) {
					this[op] = this.options[op];
				}
			}
		},
		isChrome:function() {
			return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		}
	});
	VZ_Tooltip.implement(new Options);
		
	var VZ = {
		Tooltip:VZ_Tooltip
	};
	if (!window.VZ) {window.VZ = VZ;}
	else {window._VZ = VZ;}
	
	
})();

var tooltips_Init = function() {
		var tooltip = new VZ.Tooltip();
		png_init();
};

/* --------------------------------------------------------------- 
//popup code
------------------------------------------------------------------- */
//set target to new window using XHTML 1.0 strict compatible attribute
function popupLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "popup")
		anchor.target = "_blank";
	}
}
addLoadEvent(popupLinks);

//set popup window options 
function popUp(strURL,strType,strHeight,strWidth) {
var strOptions="";
	if (strType=="flashPopup") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="popup") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fullScreen") strOptions="scrollbars,location,directories,status,menubar,toolbar,resizable";
window.open(strURL, 'newWin', strOptions);
}

/* --------------------------------------------------------------- 
//Buttons code
------------------------------------------------------------------- */
function setButtons()
{
	var buttons = document.getElementsByTagName('button');
	var buttonsLen = buttons.length;
	if (window.ie)
	{
		for(var i=0; i<buttonsLen; i++)
		{
			if ((buttons[i].className == 'red') || (buttons[i].className == 'gray')) {
				buttons[i].style.width = (buttons[i].getElementsByTagName('span').item(0).offsetWidth+12 ) + 'px';
			}
			else 
			{
				buttons[i].style.width = (buttons[i].getElementsByTagName('span').item(0).offsetWidth) + 'px';
			}
		}
	}
	var inputs = document.getElementsByTagName('input');
	var inputsLen = inputs.length;
	for(i=0; i<inputsLen; i++)
	{
		if((inputs[i].type=='button') || (inputs[i].type=='submit') || (inputs[i].type=='reset'))
		{
			inputs[i].value=inputs[i].value.toUpperCase();
			var nspace=0;
			var l=inputs[i].value.length;
			var str=inputs[i].value;
			for(var j=0;j<l;j++)
			{
				if (str.charAt(j)==' ')
				{
					nspace++;
				}
			}
			if(window.webkit!=true)
			{
				inputs[i].style.width = ((inputs[i].value.length*0.73 )- (nspace* 0.31))+'em';
				inputs[i].style.width=(inputs[i].offsetWidth+12)+ 'px';
			}
		}
	}
}

