var tmp=0;
var res=0;
var i=0;

var selected="";
var selectText="";

var srcEl;

var urls = new Array("null","frontpage.html","presentation.html","calculator.html","questionnaire.html","customercase.html","technicaldata.html","website.html","contact.html");

//*** DETECTS WHETHER OR NOT FLASH VERSION 6+ IS INSTALLED **//
function flashDetect() {
	
	for(var i=7; i>0; i--){
		var flashVersion = 0;
		try {
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
			flashVersion = i;
			break;
		}
		catch(e){
		}
	}

	if (flashVersion<6) {
		document.getElementById('instFlash').style.visibility='visible';
	}
	//window.alert(flashVersion);
}

//*** MENU -> MOUSEOVER ***//
function mOver(ev) {

	if (window.event) ev = window.event;  srcEl = ev.srcElement? ev.srcElement : ev.target; 

	srcEl.style.cursor='pointer';	
	srcEl.style.background='#FF9517';
	if (srcEl.id!=selected) {
		document.getElementById(srcEl.id+'a').src='images/menu/border_over.gif';
		document.getElementById(srcEl.id+'b').src='images/menu/border_over.gif';
	}	
}

//*** MENU -> MOUSEOUT ***//
function mOut(ev) {

	if (window.event) ev = window.event;  srcEl = ev.srcElement? ev.srcElement : ev.target; 

	if (srcEl.id!=selected) {
		srcEl.style.background='#E87B1E';
		document.getElementById(srcEl.id+'a').src='images/menu/border.gif';
		document.getElementById(srcEl.id+'b').src='images/menu/border.gif';		
	}
}

//*** MENU -> MOUSECLICK ***//
function mClick(ev) {

	if (window.event) ev = window.event;  srcEl = ev.srcElement? ev.srcElement : ev.target; 

	if (selected.length>0) {
		document.getElementById(selected).style.background='#E87B1E';
		document.getElementById(selected+'a').src='images/menu/border.gif';
		document.getElementById(selected+'b').src='images/menu/border.gif';
	}
	selected=srcEl.id;
	srcEl.style.background='#FF9517';
	document.getElementById(selected+'a').src='images/menu/border_selected.gif';
	document.getElementById(selected+'b').src='images/menu/border_selected.gif';

	window.open(urls[srcEl.id.substring(1,2)], "main");
}

//*** SET A MENU-ITEM SELECTED WITHOUT CLICKING IT ***//
function setMenu(id) {

	if (selected.length>0) {
		document.getElementById(selected).style.background='#E87B1E';
		document.getElementById(selected+'a').src='images/menu/border.gif';
		document.getElementById(selected+'b').src='images/menu/border.gif';
	}

	srcEl = document.getElementById('m'+id);
	
	selected = srcEl.id;
	srcEl.style.background='#FF9517';
	document.getElementById(selected+'a').src='images/menu/border_selected.gif';
	document.getElementById(selected+'b').src='images/menu/border_selected.gif';
}


//*** CHECK INPUT FOR NUMERIC VALUE ***//
function keyCheck(e) {

	var kc = e.keyCode;
	if (kc == 0)
	kc = e.which;

	/* 
	48-57: 0-9 KEYS ON REGULAR/NUMERIC KEYBOARD
	13: RETURN KEY
	44: ,-KEY ON REGULAR/NUMERIC KEYBOARD
	46: .-KEY
	*/

	if (!((kc>47 && kc<58) || kc==13 || kc==8 || kc==44 || kc==46))
		e.returnValue = false;
	else if (kc==44) {
		var caretPos = document.selection.createRange().duplicate();
		caretPos.text = "."+caretPos.text;
		e.returnValue = false;
	}

}

//*** SHOW THE CHART (GRAPH) ***//
function showChart() {
	document.getElementById('hotSelect').style.visibility='hidden';
	document.getElementById('excessSelect').style.visibility='hidden';
	document.getElementById('coolSelect').style.visibility='hidden';
	
	if (airKilnResult<0.5 || airKilnResult>1.3 || coolLossResult<50 || coolLossResult>170 || showCalc==false) {
		document.getElementById('yourCalc').style.visibility='hidden';	
		res = 0;
	}
	else {
		document.getElementById('yourCalc').style.visibility='visible';
		
		for (i=70; i<=150; i++) {
			tmp = Math.round(i*Math.exp((1.15-(airKilnResult*1.285))*(1.887-0.00667*i)));
			if (tmp == Math.round(coolLossResult))
				{
					res = i;
					break;
				}	
		}
		
	var queryString = '';
	queryString += 'HotAirNm=' + hotSelect;
	queryString += '&HotAirDegree=' + hotAir;
	queryString += '&ExcessAirNm=' + excessSelect;
	queryString += '&ExcessAirDegree=' + excAir;
	queryString += '&CoolingAirNm=' + coolSelect;
	queryString += '&CoolingAirDegree=' + coolAir;
	queryString += '&Clinker=' + clink;
	queryString += '&CoolerLoss=' + coolerlossRes;
	queryString += '&TotalAirTilKiln=' + totalAirKiln;
	queryString += '&Efficiency=' + efficiencyRes;
	
	top.frames["logCalc"].location.href = 'logCalc.aspx?' + queryString;
	
	}

	
	if (res>125) {
		document.getElementById('text1').style.visibility='visible';
		selectText='text1';
	}
	else if (res>105) {
		document.getElementById('text2').style.visibility='visible';
		selectText='text2';
	}
	else if (res>90) {
		document.getElementById('text3').style.visibility='visible';
		selectText='text3';
	}
	else {
		document.getElementById('textErr').style.visibility='visible';
		selectText='textErr';
	}
	
	document.getElementById('calcTopIntro').style.visibility='hidden';
	document.getElementById('calcTopChart').style.visibility='visible';
	
	document.getElementById('graf').style.visibility='visible';
	document.getElementById('rightTable').style.filter='alpha(opacity=60)';
}

//*** HIDE THE CHART (GRAPH) ***//
function hideChart() {
	document.getElementById('hotSelect').style.visibility='visible';
	document.getElementById('excessSelect').style.visibility='visible';
	document.getElementById('coolSelect').style.visibility='visible';
	document.getElementById(selectText).style.visibility='hidden';
	
	document.getElementById('yourCalc').style.visibility='hidden';
	document.getElementById('graf').style.visibility='hidden';
	document.getElementById('rightTable').style.filter='alpha(opacity=100)';
	
	document.getElementById('calcTopIntro').style.visibility='visible';
	document.getElementById('calcTopChart').style.visibility='hidden';
}