function pageInit(){
	var oDetail = document.getElementById("pldetail");
	var iTopLevel = document.getElementById("totallevel").value;
	var oForm = document.postform;
	oForm.esbtn.onclick=function(){
		if (oForm.slvl.value.length==0||isNaN(oForm.slvl.value)){alert('Please enter the Starting level!');oForm.slvl.focus();return false;}
		if (oForm.elvl.value.length==0||isNaN(oForm.elvl.value)){alert('Please enter the Desired level!');oForm.elvl.focus();return false;}
		var startingLevel = parseInt(oForm.slvl.value);
		var desiredLevel = parseInt(oForm.elvl.value);
		if (startingLevel >= desiredLevel){alert('The Desired level can\'t less than the Starting level!');oForm.slvl.focus();return false;}
		if (desiredLevel > iTopLevel){alert('The Desired level must less than '+iTopLevel+'!');oForm.elvl.focus();return false;}
		var s = oForm.servers.selectedIndex;
		var c = oForm.cclass.selectedIndex;
		var sVar = parseFloat(serverVar[s]),cVar = parseFloat(charsVar[c]);
		var timeCount=0;
		
		for (i=startingLevel;i<desiredLevel ;i++ ){
			timeCount=timeCount+parseFloat(lvltime[i]);
		}

		timeCount=timeCount*cVar;

		var h = parseInt(timeCount%24);
		var d = parseInt((timeCount-h)/24);
		if(d>0){
			var t = d + ' Day';
			if(d>1) t += 's ';
		} else {
			var t = '';
		}
		t += h+' Hour';
		if(h>1) t += 's';
		
		oForm.price.value = (parseFloat(timeCount*sVar)).toFixed(2)+' $';
		oForm.timecost.value = t;
		showdetail();
	}

	oForm.onsubmit=function(){
		if (oForm.acc.value.length < 2){alert('Please enter your account!');oForm.acc.focus();return false;}
		if (oForm.pwd.value.length < 2){alert('Please enter your password!');oForm.pwd.focus();return false;}
		if (oForm.charname.value.length <2){alert('Please enter your character name!');oForm.charname.focus();return false;}
		if (oForm.yourname.value.length <2){alert('Please enter your full name!');oForm.yourname.focus();return false;}
		if (oForm.country.value.length <2){alert('Please enter your country!');oForm.country.focus();return false;}
		if (oForm.address.value.length <2){alert('Please enter your street address!');oForm.address.focus();return false;}
		if (oForm.email.value==''||!oForm.email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){alert('Please enter your email address!');oForm.email.focus();return false;}
		if (oForm.telephone.value.length <5||isNaN(oForm.telephone.value)){alert('Please enter your phone number!');oForm.telephone.focus();return false;}
		var c = oForm.currency;
		if(c[0].checked){oForm.currency_code.value="usd";}
		if(c[1].checked){oForm.currency_code.value="eur";}
		if(c[2].checked){oForm.currency_code.value="gbp";}
		var ndate = new Date();
		var tzone=0-ndate.getTimezoneOffset()/60;
		oForm.usertimezone.value=tzone;
		return true;
	}

	var c = oForm.currency;
	c[0].checked=true;
	for (var i=0;i<c.length ;i++ ){
		c[i].onclick=function(){
			var s = oForm.servers.selectedIndex;
			var c = oForm.cclass.selectedIndex;
			var sVar = parseFloat(serverVar[s]),cVar = parseFloat(charsVar[c]);
			var timeCount=0;
			var startingLevel = parseInt(oForm.slvl.value);
			var desiredLevel = parseInt(oForm.elvl.value);
			for (i=startingLevel;i<desiredLevel ;i++ ){
				timeCount=timeCount+parseFloat(lvltime[i]);
			}
			var currentValue = parseFloat(timeCount*sVar*cVar);
			if (this.value==1){cp=1;ccode='$';}
			else if (this.value==2){cp=rate_eur;ccode='€';}
			else if (this.value==3){cp=rate_gbp;ccode='£';}
			oForm.price.value = (parseFloat(currentValue)/cp).toFixed(2)+' '+ccode;
		}
	}
}
function showdetail(){
	var oDetail = document.getElementById("pldetail");
	oDetail.style.display='block';
}
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
addLoadEvent(pageInit);