var _toolTip, a, b, r = /^[0-9]*$/;
var bindToolTip = function(){
	var _div = document.getElementById('advancedBlock');
	_div.onmouseover = bindOnMouseMove;
	_div.onmouseout = function(){document.onmousemove = null;};
	var _anchors = _div.getElementsByTagName('img');
	var _body = document.getElementsByTagName('body')[0];
	var _standardBlock = document.getElementById('standardBlock');
	var _advancedBlock = document.getElementById('advancedBlock');
	var _h1 = _standardBlock.scrollHeight;
	_standardBlock.className = "tabVisible";	
	var _h2 = _advancedBlock.scrollHeight;
	_advancedBlock.className = "tabHidden";
	if(_h1 + 80 > _h2){
		_advancedBlock.style.height = _h1 + 80 + 'px';
		_standardBlock.style.height = _h1 + 80 + 'px';
	}else{
			_standardBlock.style.height = _h2 + 'px';
	}
	document.getElementById("_submit").onclick=___submit;
	for(var i=0; i < _anchors.length; i++){
		_anchors[i].onmouseover = new Function('showToolTip(' + i + ')');
		_anchors[i].onmouseout = new Function('hideToolTip(' + i + ')');
		var __span = document.createElement('span');
		var _span = _body.appendChild(__span);
		_span.className = 'toolTip';
		_span.id = 'toolTip' + i;
		_span.innerHTML = _toolTip[i];
	}
}

var showToolTip = function(i){
	var _divToolTip = document.getElementById('toolTip' + i);
	_divToolTip.style.left = mousePos.x -120 + 'px';
	_divToolTip.style.top = mousePos.y + 15 + 'px';
	_divToolTip.style.display = 'block';
}

var hideToolTip = function(i){
	document.getElementById('toolTip' + i).style.display = 'none';
}

var showTab = function (tabid){
	document.getElementById(tabid).className = "tab show";
	document.getElementById(tabid+"Block").className = "tabVisible";
}
var hideTab = function (tabid){
	document.getElementById(tabid).className = "tab";
	document.getElementById(tabid+"Block").className = "tabHidden";
}

var valid = function (value, count){
    if(value == "")return false;
	if(!r.test(value) || value < b[i])return false;
	return true;
}
var formatNum = function (num){
	var re = new RegExp().compile( "(\\d)(\\d{3})(,|\\.|$) ");
    num += " ";  
    while(re.test(num))
        num = num.replace(re, "$1,$2$3 ")
    return num;
} 

var toStandard = function (){
	hideTab('advanced');
	showTab('standard');
}
var toAdvanced = function (){
	hideTab('standard');
	showTab('advanced');
}
var ___submit = function (){
	if(cs())
	document.getElementById("form").submit();
}
function cs(){
	var flag = true;
	for(i =0; i <a.length; i++){
		var error = document.getElementById(a[i]+"_error");		
		if(!valid(document.getElementById(a[i]).value, i)){
			flag = false;
			if(error.innerHTML.indexOf('This value must be') == -1){
				error.innerHTML += "<br/>This value must be greater than or equal to <b>" + b[i] + "</b>";
				error.style.color = "red";
			}	
		}else{
			error.innerHTML = error.innerHTML.split(")")[0] + ")";
			error.style.color = "black";
		}
	}
	if(!flag){
		document.getElementById('errorDiv').style.visibility = 'visible';
	}else{
		document.getElementById('errorDiv').style.visibility = 'hidden';
	}
	return flag;
}
if(window.location.href.indexOf("roic") != -1){
	AddToOnload(bindToolTip);
}
if(window.location.href.indexOf("sharepoint-data-protection-roic") != -1){
	a = new Array("num_employees", "num_admin", "num_wfe", "num_servers", "num_hosts", "num_dbs", "ave_dbsize", "recovery_time");
	b = new Array(1, 1, 0, 0, 0, 1, 1, 1);
//	a = new Array("num_employees", "num_admin", "num_wfe", "web_app", "site_coll", "site", "list");
//	b = new Array(1, 1, 0, 1, 1, 1, 1);
	_toolTip = new Array("Total Cost of Ownership and Return on Investment calculations’ horizon.  Default value is a standard analysis horizon. ","Default value obtained from industry research.  Includes wages, overtime, benefits, switching costs from regular responsibilities to DR, etc… ","Default value was obtained from Gartner.  Further breakdowns according to industry and type of solution are available in various industry research performed by IDC, Alinean, and Nucleus Research. ","Default value is a very conservative estimate based on customer field data. ","Default value is based on Microsoft data. ","Probability that a certain portion of the user community will require granular content recovery. Default value based on customer field data. ","This includes scenarios where users cannot recover from the recycling bin, or require full document libraries/sites to be restored. Percentage of total instances of granular recovery. Default value based on customer field data. ");
}
if(window.location.href.indexOf("sharepoint-administration-roic") != -1){
	a = new Array("num_employees", "num_admin", "num_wfe", "web_app", "site_coll", "site", "list");
	b = new Array(1, 1, 0, 1, 1, 1, 1);
//	a = new Array("num_employees", "num_admin", "num_wfe", "cost_tier1", "cost_tier2");
//	b = new Array(1, 1, 1, 1, 1);
	_toolTip = new Array("Total Cost of Ownership and Return on Investment calculations’ horizon.  Default value is a standard analysis horizon. ","Default value obtained from industry research.  Includes wages, overtime, benefits, switching costs from regular responsibilities to DR, etc… ","Default value based on customer field data.","A ‘restructuring task’ involves changing the topology of your environment, such as promoting a site, or moving a site collection to a new content database.","Examples include: moving a list from one library to another, or moving a site to a different site collection.");
}
if(window.location.href.indexOf("sharepoint-archiving-roic") != -1){
	a = new Array("num_employees", "num_admin", "num_wfe", "cost_tier1", "cost_tier2");
	b = new Array(1, 1, 1, 1, 1);
//	a = new Array("num_employees", "num_admin", "num_wfe", "num_servers", "num_hosts", "num_dbs", "ave_dbsize", "recovery_time");
//	b = new Array(1, 1, 0, 0, 0, 1, 1, 1);
	_toolTip = new Array("Total Cost of Ownership and Return on Investment calculations’ horizon.  Default value is a standard analysis horizon.","Default value based on customer field data.");
}