var CalcCode = document.getElementById("AirConCalcContainer").innerHTML;

if (CalcCode.indexOf("href=\"http://www.united-vision.ro/") == -1) {
	document.getElementById("AirConCalcContainer").innerHTML = "";
}
else {
	if (CalcCode.indexOf("nofollow") > -1) {
		document.getElementById("AirConCalcContainer").innerHTML = "";
	}
}

function IsNumeric(IntText) {
	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;
	
	for (LoopChar = 0; LoopChar < IntText.length && IsNumber == true; LoopChar++) { 
		Char = IntText.charAt(LoopChar); 
		
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	
	if (IntText.length == 0) {
		IsNumber = false;
	}
	
	return IsNumber;
}

function RoundInt(Int, DecPoints) {
	if (!DecPoints) return Math.round(Int);
	
	if (Int == 0) {
		var Decimals = "";
		for(var LoopDec = 0; LoopDec < DecPoints; LoopDec++) Decimals += "0";
		return "0."+Decimals;
	}

	var Exponent = Math.pow(10,DecPoints);
	var NewInt = Math.round((Int * Exponent)).toString();
	NewInt = NewInt.slice(0,-1 * DecPoints) + "." + NewInt.slice(-1 * DecPoints);
	
	if (NewInt.charAt(0) == ".") {
		NewInt = "0" + NewInt;
	}
	
	return NewInt;
}

function CalculateVolume (Length, Width, Total) {
	LengthCheck = IsNumeric(document.getElementById(Length).value);
	WidthCheck = IsNumeric(document.getElementById(Width).value);
	
	if (LengthCheck == true && WidthCheck == true) {
		document.getElementById(Total).value = (document.getElementById(Length).value * document.getElementById(Width).value * 2.5);
	}
	else {
		document.getElementById(Total).value = "";
	}
	
	CalculateArea('AirConCalcElectricItems','AirConCalcPersonnel','AirConCalcType','AirConCalcArea','AirConCalcDuty','AirConCalcVolume');
}

function CalculateArea (Electrical, Personnel, Type, Value, Duty, Volume) {
	ElectricalCheck = IsNumeric(document.getElementById(Electrical).value);
	PersonnelCheck = IsNumeric(document.getElementById(Personnel).value);
	TypeCheck = IsNumeric(document.getElementById(Type).value);
	VolumeCheck = IsNumeric(document.getElementById(Volume).value);
	
	if (ElectricalCheck == true && PersonnelCheck == true && TypeCheck == true && VolumeCheck == true) {
		document.getElementById(Duty).value = RoundInt((((document.getElementById(Volume).value * document.getElementById(Type).value) / 3412) + ((document.getElementById(Electrical).value * 250) + (document.getElementById(Personnel).value * 300)) / 3412), 2);
		
		var ACName = new Array("Gree ON/OFF 9000 BTU/h", "Gree ON/OFF 12000 BTU/h", "Gree ON/OFF 18000 BTU/h", "Gree ON/OFF 24000 BTU/h", "Gree Inverter 9000 BTU/h", "Gree Inverter 12000 BTU/h", "Gree Inverter 18000 BTU/h", "Daikin Inverter OKI 9000 BTU/h", "Daikin Inverter OKI 12000 BTU/h", "Gree Inverter OKI 18000 BTU/h", "Daikin Inverter OKI 24000 BTU/h");
		var ACValue = new Array(1, 2, 3, 4, 5, 6, 7, 8, 8, 10, 11);
		var Required = "";
		
		for (LoopAC = 0; LoopAC <= 10; LoopAC++) {
			if ((document.getElementById(Duty).value / ACValue[LoopAC]) > 1) {
				Required = "<p><span>Va recomandam:</span><br />" + Math.ceil((document.getElementById(Duty).value / ACValue[LoopAC])) + " x " + ACName[LoopAC] + " (" + ACValue[LoopAC] + "Rating in Kw per unitate) A/C unitate(ti)</p>";
			}
		}
		
		if (Required == "") {
			Required = "<p><span>Va recomandam:</span><br />1 x " + ACName[0] + " (" + ACValue[0] + "Rating in Kw per unitate) A/C unitate(ti)</p>";
		}
		
		document.getElementById("AirConCalcResults").innerHTML = Required;
	}
	else {
		document.getElementById(Duty).value = "";
	}
}
