<!-- hiding script from incompatible browsers
// XxCavalierXx
// updated July 14, 2003
// Runscape PK lvl Calculation

var CR2003;
var runescape;

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(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);
	}
}

function clearerror()
{
	document.getElementById("errplace").innerHTML = "";
	document.getElementById("typechar").innerHTML = "";
	document.getElementById("tempsepbar").innerHTML = "<BR>";
	document.getElementById("tempsepbar2").innerHTML = "";
	document.getElementById("toshowfight").innerHTML = "";
	document.getElementById("toshowarch").innerHTML = "";
//	document.getElementById("toshowmage").innerHTML = "";
	document.getElementById("toshowmagpray").innerHTML = "";
	document.getElementById("lvl").innerHTML = "???";
	document.getElementById("showlvl").innerHTML = "?";
	document.getElementById("errorflag").innerHTML = "";
	document.getElementById("CR2003").innerHTML = "© 2003 by The Kuniva<br>Original Calc By XxCavalierXx";

}

function resetstats()
{
	clearerror();
	document.list.attack.value="1";
	document.list.defense.value="1";
	document.list.strength.value="1";
	document.list.hits.value="10";
	document.list.ranged.value="1";
	document.list.prayer.value="1";
	document.list.magic.value="1";
}

function calculate()
{
	var pray = 0;
	var error = 0;
	var defhit = 0;
	var attstr = 0;
	var mage = 0;
	var pklvl = 0;
	var arching = 0;
	var touparch = 0;
	var toupmagpray = 0;
	var toupfight = 0;
	var lastdecimal = 0;

	clearerror();


	if(!document.list.attack.value){
		document.list.attack.value = 1;
		attstr += parseInt(document.list.attack.value);
	} else {
		if(isValid("Attack", document.list.attack.value, 1, 99)){
			attstr += parseInt(document.list.attack.value);
		} else {
			error++;
		}
	}

	if(!document.list.defense.value){
		document.list.defense.value = 1;
		defhit += parseInt(document.list.defense.value);
	} else {
		if(isValid("Defense", document.list.defense.value, 1, 99)){
			defhit += parseInt(document.list.defense.value);
		} else {
			error++;
		}
	}

	if(!document.list.strength.value){
		document.list.strength.value = 1;
		attstr += parseInt(document.list.strength.value);
	} else {
		if(isValid("Strength", document.list.strength.value, 1, 99)){
			attstr += parseInt(document.list.strength.value);
		} else {
			error++;
		}
	}

	if(!document.list.hits.value && !error){
		calchits();
		defhit += parseInt(document.list.hits.value);
	} else {
		if(isValid("Hits", document.list.hits.value, 10, 99)){
			defhit += parseInt(document.list.hits.value);
		} else {
			error++;
		}
	}

	if(!document.list.ranged.value){
		document.list.ranged.value = 1;
		arching += parseInt(document.list.ranged.value);
	} else {
		if(isValid("Ranged", document.list.ranged.value, 1, 99)){
			arching += parseInt(document.list.ranged.value);
		} else {
			error++;
		}
	}

	if(!document.list.prayer.value){
		document.list.prayer.value = 1;
		pray += parseInt(document.list.prayer.value);
	} else {
		if(isValid("Prayer", document.list.prayer.value, 1, 99)){
			pray += parseInt(document.list.prayer.value);
		} else {
			error++;
		}
	}

	if(!document.list.magic.value){
		document.list.magic.value = 1;
		mage += parseInt(document.list.magic.value);
	} else {
		if(isValid("Magic", document.list.magic.value, 1, 99)){
			mage += parseInt(document.list.magic.value);
		} else {
			error++;
		}
	}

	if(!error && runescape){
//		defhit = defhit * 0.25;
//		magpray = magpray * 0.125;

		if( attstr < (mage * 1.5) && arching <= mage ){
			attstr = mage * 1.5;
//			arching = arching * 0.375;
			pklvl = (defhit / 4) + (mage * 0.4875) + (pray / 8);
			
			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupfight){	
				lastdecimal = lastdecimal - 0.25;
			}
			document.getElementById("toshowfight").innerHTML = "You need <B>" + toupfight + "</B> defense or Hits lvls<BR>";

			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++touparch){	
				lastdecimal = lastdecimal - 0.4875;
			}
			document.getElementById("toshowarch").innerHTML = "OR <B>" + touparch + "</B> Magic lvls,<BR>";

			document.getElementById("typechar").innerHTML = "You are a <B><U>Sorceror</U></B><BR>If your magic lvl does not change,<BR>your attack and strength will have<BR>NO effect on your combat lvl until<BR>after they add to " + parseInt(attstr) + "<BR><FONT color=#00ff00>And Your Range Wont Affect Until Lvl "+(mage+1)+"</font><br>";
		} 
		
		else if( attstr < (arching * 1.5) && mage < arching ){
			attstr = arching * 1.5;
//			arching = arching * 0.375;
			pklvl = (defhit / 4) + (arching * 0.4875) + (pray / 8);
			
			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupfight){	
				lastdecimal = lastdecimal - 0.25;
			}
			document.getElementById("toshowfight").innerHTML = "You need <B>" + toupfight + "</B> defense or Hits lvls<BR>";

			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++touparch){	
				lastdecimal = lastdecimal - 0.4875;
			}
			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<BR>after they add to " + parseInt(attstr) + "<BR><FONT color=#00ff00>And Your Magic Wont Affect Until Lvl "+(arching+1)+"</font><br>";
		} 
		else {
			arching = attstr / 1.5;
//			attstr = attstr / 4.0;
			pklvl = (0.325 * attstr) + (defhit / 4) + (pray / 8);

			for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupfight){	
				lastdecimal = lastdecimal - 0.2857;
			}
			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 or magic lvl will NEVER have<BR>any effect on your combat lvl<BR>";
			} 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 or magic lvl will have NO effect<BR>on your combat lvl until " + parseInt(arching + 1) + "<BR>";
			}
		}

		document.getElementById("tempsepbar").innerHTML = "--------------------<BR>";
		document.getElementById("tempsepbar2").innerHTML = "--------------------<BR>";

		for(lastdecimal=(parseInt(pklvl + 1) - pklvl); lastdecimal>0; ++toupmagpray){	
			lastdecimal = lastdecimal - 0.1429;
		}
		document.getElementById("toshowmagpray").innerHTML = "OR <B>" + toupmagpray + "</B> 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 if(!runescape){
		clearerror();
		document.write("<BR>");
	} else {
		document.getElementById("errorflag").innerHTML = "<BR>";
		document.getElementById("lvl").innerHTML = "0.0";
		document.getElementById("showlvl").innerHTML = "0";
		alert("Error Code: 03\n\nPlease notify XxCav.\nPlease include browser name and version!");
	}
}
// end hiding script -->