var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var n = navigator.appName;
var ie = (n=="Microsoft Internet Explorer");
var temp=0;
var cj = {
	gradient: function(id,level)
	{
		var Obj = d.getElementById(id);
		with(Obj.style){
			opacity = level; MozOpacity = level; KhtmlOpacity = level;
			filter = "alpha(opacity=" + level * 100 + ")"; 
			display="block";
		}
		return;
	},
	gradientfadeout: function(id,level)
	{
		var Obj = d.getElementById(id);
		with(Obj.style){
			opacity = level; MozOpacity = level; KhtmlOpacity = level;
			filter = "alpha(opacity=" + level * 100 + ")";
			if (level <= 0.15) {
				display="block";
			}
			else {
				display="none";
			}
		}
		return;
	},
	fadein: function(id) 
	{
		var level = 0;
		while(level <= 1) {
			setTimeout( "cj.gradient('" + id + "'," + level + ")", (level* 1000) + 10);
			level += 0.01;
		}
	},
	fadeout: function(id) 
	{
		var level = 1;
		do { 
			setTimeout( "cj.gradientfadeout('" + id + "'," + level + ")", (level* 1000) + 10);
			level -= 0.09;
		} while (0 <= level);
	},
	openbox: function(lbid,w,h,fid,fadin)// Open the lightbox
	{
	  if(fadin)
	  {
		 if (ie) {this.hideParentSelectBoxes();} 
		 this.showlb(lbid,w,h);
		 this.lbshadow(fid,0.5);
		 this.gradient(lbid, 0);
		 this.fadein(lbid);
	  }
	  else {d.getElementById(lbid).style.display='block';}	
	},
	hideParentSelectBoxes: function()
	{
		selects = document.getElementsByTagName('select');
		 for(i = 0; i < selects.length; i++) {
			if (selects[i].rel == 'lb')
				selects[i].style.visibility = 'visible';
			else
				selects[i].style.visibility = 'hidden';
		 }
	},
	showParentSelectBoxes: function()
	{
		selects = document.getElementsByTagName('select');
		 for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = 'visible';
		 }
	},
	closebox: function(lbid,fid)// Close the lightbox
	{
		selects = document.getElementsByTagName('select');
		 for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = 'visible';
		 }
		d.getElementById(lbid).style.display='none';
		d.getElementById(fid).style.display='none';
	},
	closeboxwithfade: function(lbid,fid)// Close the lightbox
	{
		if (ie) {this.hideParentSelectBoxes();}
		this.fadeout(lbid);
		setTimeout("cj.closebox('" + lbid + "','" + fid + "')",500);
		this.showParentSelectBoxes();		
	},
	lbshadow: function(fid,level) {
		var wh = this.getPageSize();		
		var Obj = d.getElementById(fid);
		with(Obj.style){
			top = 0 + 'px';
			left = 0 + 'px';
			width = wh[0] + 'px';
			height = wh[1] + 'px';
			opacity = level; MozOpacity = level; KhtmlOpacity = level;
			filter = "alpha(opacity=" + level * 100 + ")";
			display="block";
		}
	},
	showlb: function(lbid,w,h) {
		Obj = d.getElementById(lbid);
		this.makeCenter(Obj,w,h);
	},
	getScrollWidth : function(){
		var w = window.pageXOffset || d.body.scrollLeft || d.documentElement.scrollLeft;
		return w ? w : 0;
	},
	getScrollHeight : function (){
		var h = window.pageYOffset || d.body.scrollTop || d.documentElement.scrollTop;
		return h ? h : 0;
	},
	getPageScroll : function(){
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( d.body && ( d.body.scrollLeft || d.body.scrollTop ) ) {
			scrOfY = d.body.scrollTop;
			scrOfX = d.body.scrollLeft;
		} else if( d.documentElement && ( d.documentElement.scrollLeft || d.documentElement.scrollTop ) ) {
			scrOfY = d.documentElement.scrollTop;
			scrOfX = d.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	},
	getCenterXY : function(w,h){
		var x=0, y=0, xy = this.getPageSize();
		x = (xy[2] - w) / 2;
		y = (this.getPageScroll()[1] + ((xy[3] - h) / 2));
		return [x,y];
	},
	makeCenter : function(Obj,w,h){
		var xy = this.getCenterXY(w,h);
		with(Obj.style){
			left = (xy[0]) + "px";
			top= (xy[1]) + "px";
			zIndex = "101";
			width = w + "px";
			/*if (ie)
				height = (h + 30) + "px";
			else
				height = h + "px";*/
		}
	},
	getPos: function(inputElement) {
		var coords =  new Object();
		coords.x = 0;
		coords.y = 0;
		try {
			targetElement = inputElement;
			if(targetElement.x && targetElement.y) {
				coords.x = targetElement.x;
				coords.y = targetElement.y;
			} else {
				if(targetElement.offsetParent) {
					coords.x += targetElement.offsetLeft;
					coords.y += targetElement.offsetTop;
					while(targetElement = targetElement.offsetParent) {
						coords.x += targetElement.offsetLeft;
						coords.y += targetElement.offsetTop;
					}
				} else {
					/*/alert("Could not find any reference for coordinate positioning.");*/
				}
			}
			return coords;
		} catch(e){
			return coords;
		}
	},
	getPageSize : function(){
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = d.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (d.body.scrollHeight > d.body.offsetHeight){ /* all but Explorer Mac*/
			xScroll = d.body.scrollWidth;
			yScroll = d.body.scrollHeight;
		} else { /* Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari*/
			xScroll = d.body.offsetWidth;
			yScroll = d.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	/* all except Explorer*/
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (d.documentElement && d.documentElement.clientHeight) { /* Explorer 6 Strict Mode*/
			windowWidth = d.documentElement.clientWidth;
			windowHeight = d.documentElement.clientHeight;
		} else if (d.body) {
			windowWidth = d.body.clientWidth;
			windowHeight = d.body.clientHeight;
		}
		/* for small pages with total height less then height of the viewport*/
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		/* for small pages with total width less then width of the viewport*/
		if(xScroll < windowWidth){
			if (ns=="true") { pageWidth = xScroll; } else {	pageWidth = (windowWidth-18); }
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	},
	showDiv: function(id) {
		if (temp==0) {
			d.getElementById(id).style.display = "block";
			temp=1;
		} else {
			d.getElementById(id).style.display = "none";
			temp=0;
		}
	}
};