var serverPath = "http://mon.itor.us";
var windowHref = window.location.href;
function encode(str)
{
	var tokens = str.split("/");
	var result = encodeURIComponent(tokens[0]);
	for(var i=1; i< tokens.length; ++i)
	{
		result += "/" + encodeURIComponent(tokens[i]) ;
	}
	return result;
}

var IndexListPopUp = {

	Container: null,
	inited: false,

	show: function(attr, value){
		if(!IndexListPopUp.inited){
			WizardBox.init();
			IndexListPopUp.inited = true;
		}
		IndexListPopUp.container = document.createElement("div");
		IndexListPopUp.container.className = "indexListContainer";
		
		var title = "";
		switch(attr){
			case "tagname": title = "Performance Benchmarks Tagged<br/>"+value+"";break;
			case "industry": title = "Industry Performance Benchmarks<br/>"+value+"";break;
			case "country": title = "Country Performance Benchmarks<br/>"+value+"";break;
		}
		WizardBox.removeContent();
		WizardBox.showDialog(IndexListPopUp.container, title, 500, 428);
		IndexListPopUp.container.innerHTML="<iframe allowTransparency='-1' frameBorder=0 width='425px' height='280px'"+
		" src='"+serverPath+"/more.jsp?attr="+attr+"&value="+encode(value)+"' ></iframe>";	

	}
} 	

var WizardBox = function(){
		var wizardBoxDialog;
		var wizardBoxTitle;
		var wizardBoxBody;
		var wizardBoxClose;
		var title;
		
		return {
		init:function(){
			wizardBoxDialog = document.getElementById("wizardBox-dlg");
			wizardBoxTitle = document.getElementById("wizardBoxTitle");
			wizardBoxBody = document.getElementById("wizardBoxBody");
			wizardBoxLine = document.getElementById("wizardBox-dlg-title-line");
			wizardBoxClose = document.createElement("div");
			wizardBoxClose.className = "close";
			
			wizardBoxClose.innerHTML = "<img src='"+serverPath+"/img/closeMod.gif'  style='cursor:pointer;'/>";
			wizardBoxDialog.appendChild(wizardBoxClose);
			wizardBoxClose.onclick = WizardBox.hide;
			
		},
		showTitle:function(){
			document.getElementById("wizardBox-dlg-title").style.display = "";
			document.getElementById("wizardBox-dlg-title-line").style.display = "";
		},
		
		addContent:function(objOrstr){
			if(objOrstr && typeof objOrstr == "string" ) {
				if(wizardBoxBody.innerHTML) wizardBoxBody.innerHTML += objOrstr;
				else wizardBoxBody.innerHTML = objOrstr;
			
			}
			else if(objOrstr && typeof objOrstr == "object");
				wizardBoxBody.appendChild(objOrstr);
		
		},
		showDialog:function(node,newTitle,width,height){
			WizardBox.setTitle(newTitle);
			WizardBox.addContent(node);
			WizardBox.resizeTo(width,height);
			WizardBox.show();
		},
		show:function(){
			document.getElementById("body-mask").style.display  = "block";
			document.getElementById("body-mask").onclick = function(ev){
				if (window.event) ev = window.event;
				ev.cancelBubble = true;
				return false;
			}
			wizardBoxDialog.style.display = "block";
			wizardBoxClose.style.left = (wizardBoxDialog.offsetWidth - 13 )+"px";
		},
		setTitle:function(newTitle){
			if(newTitle){
				title = newTitle;
				wizardBoxTitle.innerHTML = title;
			}
		},
		removeContent: function(){
			wizardBoxBody.innerHTML = "";
		},
		
		resizeTo: function(w, h){
			if(w)wizardBoxDialog.style.width = w+"px";
			if(h)WizardBox.resizeHeight(h);
			var scrolltop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
			var height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight; 
			if (h) height = (height+parseInt(scrolltop)-h)/2 - 50;
			else height = 80+scrolltop;
			if(height<0) height = 80+scrolltop;
			wizardBoxDialog.style.top = height+"px";		
			wizardBoxDialog.style.left = (document.body.clientWidth-w)/2+"px";
		},
		
		resizeHeight: function(h){
			offsetH = wizardBoxDialog.getElementsByTagName("div")[0].offsetHeight; 
			if(offsetH && offsetH != 'undefined' && offsetH != 0) height=offsetH;
			else height = (h) ? h : 330;
			wizardBoxDialog.style.height = height+"px";
		},
		
		hide:function(ev){
			document.getElementById("body-mask").style.display  = "none";
			WizardBox.showTitle();
			wizardBoxDialog.style.display = "none";
			col = document.getElementById("colorPicker");
			if (col) col.outerHTML = "";
			if(ev)ev.cancelBubble = true;
			return false;
		}
	
		};
}();


Date.prototype.getWeek=function(){
	var Hq=this.getFullYear();var H5T=new Date(Hq,0,1);var H0I=H5T.getDay();
	var H5U=((Date.UTC(Hq,this.getMonth(),this.getDate())-Date.UTC(Hq,0,1))/(1000*60*60*24));if(H0I==0){H0I=6;}else{H0I--;}
	var H5V=H5U-(7-H0I);var H4z=Math.floor(H5V/7)+1;if(0<=H0I&&H0I<=3){H4z+=1;}
	H3i=H4z;if(H3i==53){if(H0I==3||((H0I==2||H0I==3)&&((Hq%4==0&&Hq%100!=0)||Hq%400==0))){}else{H3i=1;}}
	return H3i;
}

var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isIE6 = ( Browser.isIE && /msie 6\.0/i.test(navigator.userAgent) );
Browser.isIE7 = ( Browser.isIE && /msie 7\.0/i.test(navigator.userAgent) );

var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentWeek = currentDate.getWeek(); 
var currentMonth = currentDate.getMonth();
if (currentWeek == 1){
	currentWeek = 52;
	if (currentMonth == 0) currentYear--;
}else{
	currentWeek--;
}
if (typeof creationYear == 'undefined'){
	creationYear = 2007;
}
if (typeof year == 'undefined'){
	year = 2007;
}

function initPage(){
	var cont = document.getElementById("tags");
	var spans = cont.getElementsByTagName("span");
	cont.removeChild(spans[spans.length-1]);
	if (Browser.isIE) document.getElementById("middle").style.paddingLeft="20px";
	
	var weekDivs=[];
	var slider = document.getElementById("slider");
	
	var arrowLeft=document.createElement("img");
	arrowLeft.src=serverPath+"/img/sliderLeft.gif";
	arrowLeft.className="sliderArrow";
	arrowLeft.style.display="none";
	slider.appendChild(arrowLeft);
	var selectedIndex;
	if (creationWeek == 0){
		creationWeek = 1;
	}
	for (var y = creationYear; y <= currentYear; y++){
		var yearStartWeek = (y==creationYear) ? creationWeek : 1;
		var yearEndWeek = (y==currentYear) ? currentWeek : 52;
		for (var w = yearStartWeek; w <= yearEndWeek; w++){
			var div=document.createElement("span");
			div.style.display = "none";
			var style = (w==week && y==year) ? "style='color:#C15527 !important; text-decoration:none;'" : "";
			div.innerHTML+= "<a class=week "+style+" href='../"+y+"/"+w+".html'>"+w+"</a>";
			weekDivs[weekDivs.length]=div;
			slider.appendChild(div);
			if (y == year && w == week) selectedIndex = weekDivs.length-1;
		}
	}
	var arrowRight=document.createElement("img");
	arrowRight.src=serverPath+"/img/sliderRight.gif";
	arrowRight.className="sliderArrow";
	arrowRight.style.display="none";
	slider.appendChild(arrowRight);
	
	var weeksLength = weekDivs.length;
	var next=null, prev=null;
	for (var i = 0; i < weeksLength; i++){
		if (i>=selectedIndex-7 && i<=selectedIndex+7) {
			if (!prev) prev = i-1; 
			next = i+1;
			weekDivs[i].style.display="";
		}
	}
	if (prev && prev >= 0){
		arrowLeft.onclick = function(){window.location.href = weekDivs[prev].firstChild.href;};
		arrowLeft.style.display="";
	}
	if (next && next < weeksLength){
		arrowRight.onclick = function(){window.location.href = weekDivs[next].firstChild.href;};
		arrowRight.style.display="";
	}
}


