<!-- hiding script from incompatible browsers
// XxCavalierXx
// updated May 24, 2002
// Runscape PK lvl Calculation

function isaNumber(input){
	if(!input.length){
		return false;
	}

	for (var i = 0; i < input.length; i++) {
		var ch = input.charAt(i);

		if (ch < "0" || ch > "9"){
			return false;
		}
	}

	return true;
}

function isValid(skill, lvlvalue, min, max){
	if(lvlvalue){
		if(isaNumber(lvlvalue)){
			if(lvlvalue >= min){
				if(lvlvalue > max){
					document.getElementById("errplace").innerHTML += skill + " cannot be higher than " + max + ".<BR>";
					return(false);
				} else {
					return(true);
				}
			} else {
				document.getElementById("errplace").innerHTML += skill + " must be at least " + min + ".<BR>";
				return(false);
			}
		} else {
			document.getElementById("errplace").innerHTML += skill + " is not a valid positive integer.<BR>";
			return(false);
		}
	} else {
		document.getElementById("errplace").innerHTML += skill + " was not entered.<BR>";
		return(false);
	}
}

function clearerror()
{
	document.getElementById("errplace").innerHTML = "";
	document.getElementById("typechar").innerHTML = "";
	document.getElementById("tempsepbar").innerHTML = "";
	document.getElementById("toshowfight").innerHTML = "";
	document.getElementById("toshowarch").innerHTML = "";
	document.getElementById("toshowmagpray").innerHTML = "";
	document.getElementById("lvl").innerHTML = "0.0";
	document.getElementById("showlvl").innerHTML = "0";
	document.getElementById("errorflag").innerHTML = "";
}

function calculate()
{
	var error = 0;
	var defhit = 0;
	var attstr = 0;
	var magpray = 0;
	var pklvl = 0;
	var arching = 0;
	var touparch = 0;
	var toupmagpray = 0;
	var toupfight = 0;
	var lastdecimal = 0;

	clearerror();


	if(isValid("Attack", document.list.attack.value, 1, 99)){
		attstr += parseInt(document.list.attack.value);
	} else {
		error++;
	}

	if(isValid("Defense", document.list.defence.value, 1, 99)){
		defhit += parseInt(document.list.defence.value);
	} else {
		error++;
	}

	if(isValid("Strength", document.list.strength.value, 1, 99)){
		attstr += parseInt(document.list.strength.value);
	} else {
		error++;
	}

	if(isValid("Hits", document.list.hits.value, 10, 99)){
		defhit += parseInt(document.list.hits.value);
	} else {
		error++;
	}

	if(isValid("Ranged", document.list.ranged.value, 1, 99)){
		arching += parseInt(document.list.ranged.value);
	} else {
		error++;
	}

	if(isValid("Prayer", document.list.prayer.value, 1, 99)){
		magpray += parseInt(document.list.prayer.value);
	} else {
		error++;
	}

	if(isValid("Magic", document.list.magic.value, 1, 99)){
		magpray += parseInt(document.list.magic.value);
	} else {
		error++;
	}


	if(!error){
		defhit = defhit * 0.25;
		magpray = magpray * 0.125;

		if( attstr < (arching * 1.5) ){
			attstr = arching * 1.5;
			arching = arching * 0.375;
			pklvl = defhit + arching + magpray;
			
			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupfight){	
				lastdecimal = lastdecimal - 0.25;
			}
			document.getElementById("toshowfight").innerHTML = "You need <B>" + toupfight + "</B> Defence or Hits lvls<BR>";

			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++touparch){	
				lastdecimal = lastdecimal - 0.375;
			}
			document.getElementById("toshowarch").innerHTML = "OR <B>" + touparch + "</B> Ranged lvls,<BR>";

			document.getElementById("typechar").innerHTML = "You are an <B><U>Archer</U></B><BR>If your ranged lvl does not change,<BR>your attack and strength will have<BR>NO effect on your combat lvl until after<BR>they add to " + parseInt(attstr);
		} else {
			arching = attstr / 1.5;
			attstr = attstr / 4.0;
			pklvl = attstr + defhit + magpray;

			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupfight){	
				lastdecimal = lastdecimal - 0.25;
			}
			document.getElementById("toshowfight").innerHTML = "You need <B>" + toupfight + "</B> Att, Def, Str or Hits lvls<BR>";

			if( parseInt(arching + 1) > 99){
				document.getElementById("typechar").innerHTML = "You are a <B><U>Fighter</U></B><BR>Based on your Strength and Attack lvls<BR>your ranged lvl will NEVER have<BR>any effect on your combat lvl";
			} else {
				document.getElementById("typechar").innerHTML = "You are a <B><U>Fighter</U></B><BR>If you do not raise your attack and strength,<BR>your ranged lvl will have NO effect<BR>on your combat lvl until " + parseInt(arching + 1) + " ranged";
			}
		}

		document.getElementById("tempsepbar").innerHTML = "--------------------";

		for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupmagpray){	
			lastdecimal = lastdecimal - 0.125;
		}
		document.getElementById("toshowmagpray").innerHTML = "OR <B>" + toupmagpray + "</B> Magic or Prayer lvls<BR>to advance to your next combat lvl.<BR>";
		
		document.getElementById("lvl").innerHTML = pklvl;
		document.getElementById("showlvl").innerHTML = parseInt(pklvl);
		if( pklvl == parseInt(pklvl) ){
			document.getElementById("lvl").innerHTML += ".0";
		}

	} else {
		document.getElementById("errorflag").innerHTML = "<BR>";
		document.getElementById("lvl").innerHTML = "0.0";
		document.getElementById("showlvl").innerHTML = "0";
	}
}
// end hiding script -->