﻿<!--
/*
* copyright: Petr Koci
* email: p.koci@txtester.com
* web: http://www.txtester.com
* destination: Czech Republic 
* version: 1.3
* date: 14/12/2009 (DD/MM/YYYY)
*
* 01 - Main
* 02 - Execute
* 03 - MsgResult
* 04 - myAlert
* 05 - SetLanguage
* 06 - LoadResString
*/


/*
* 1
*/
function Main(){
gstrLn=AppsGetLang(location.href);
SetLanguage(gstrLn);
webInitOptLang();

//document.getElementById(gstrLn).selected="selected";

}


/*
* 2
*/
function Execute(){

var Quantity=document.getElementById("quantity").value
var Percent=document.getElementById("percent").value
var Mass=document.getElementById("mass").value
var Gender=document.getElementById("gender").value

var Promile;
var Hours;

txtester.promile.calculate(Quantity,Percent,Mass,Gender,function(result){
	if(!result.error){
		Promile=result.promile;
		Hours=result.hours;
		MsgResult(Promile,Hours);		
	}
	else{
		switch (result.error.code){
			case 1: 
				myAlert(1);
				document.getElementById("quantity").focus();
  				return;
			case 2:
  				myAlert(2);
				document.getElementById("percent").focus();
				return;
			case 3:
  				myAlert(3);
				document.getElementById("mass").focus();
  				return;
		}
	}
	
});//txtester.promile.calculate

}//Execute


/*
* 3
*/
function MsgResult(i,j){
	if(i>4){myAlert(15,i,j);}
	else if(i>3 && i<=4){myAlert(14,i,j);}
	else if(i>2 && i<=3){myAlert(13,i,j);}
	else if(i>1 && i<=2){myAlert(12,i,j);}
	else{myAlert(11,i,j);}
}


/*
* 4
*/
function myAlert(id, param1, param2){
var t="myAlert";
if(id>10 && id<16)t= LoadResString(40) + param1.toString() + "<br />" +  LoadResString(41) + param2.toString() + "<br /><br />";

switch(id){
	//error messages
	case 1:t=LoadResString(11) + ":<br />" + LoadResString(20);break;
	case 2:t=LoadResString(12) + ":<br />" + LoadResString(20);break;
	case 3:t=LoadResString(13) + ":<br />" + LoadResString(20);break;

	//result messages
	case 11:t+=LoadResString(42);break;
	case 12:t+=LoadResString(43);break;
	case 13:t+=LoadResString(44);break;
	case 14:t+=LoadResString(45);break;
	case 15:t+=LoadResString(46);break;
	default:
		t="myAlert: undefined id=" + id;
}
document.getElementById("msgbox").innerHTML=t;
}


/*
* 5
*/
function SetLanguage(lng){

gstrLn=lng;
AppsSaveCookie("lng",gstrLn);
AppsRefreshUrl();

document.title=LoadResString(1);
document.getElementsByTagName("h1")[0].innerHTML=LoadResString(1);

var lrs=new Array();
lrs[0]=new Array("ln-chordtrans",2);
lrs[1]=new Array("intro",10);
lrs[2]=new Array("lblquantity",11);
lrs[3]=new Array("lblpercent",12);
lrs[4]=new Array("lblmass",13);
lrs[5]=new Array("optmale",14);
lrs[6]=new Array("optfemale",15);
lrs[7]=new Array("lblgender",16);

for(var i=0;i<lrs.length;i++)document.getElementById(lrs[i][0]).innerHTML=LoadResString(lrs[i][1]);

document.getElementById("cmdexecute").value = LoadResString(17);

}


/*
* 6
*/
function LoadResString(id,lng){

if(lng==undefined)lng=gstrLn;

//CZECH
if(lng=="cs"){
	switch(id){

		case 1:return("Promile");
		case 2:return("Transponer akordů");

		case 10:return("Za jak dlouho můžu po požití alkoholu za volant? ... vyplň následující kolonky a hned se to dozvíš.");
		case 11:return("množství vypitého alkoholu");
		case 12:return("koncentrace alkoholu");
		case 13:return("hmotnost osoby");
		case 14:return("muž");
		case 15:return("žena");
		case 16:return("zvol pohlaví");
		case 17:return("vypočti");

		//errors
		case 20:return("Neplatná hodnota.");

		//results
		case 40:return("Promile alkoholu v krvi: ");
		case 41:return("Počet hodin na vystřízlivění: ");
		case 42:return("Moc dobře víš, že alkohol může být dobrý sluha, ale zlý pán. Tvoje řidičské schopnosti nejsou ohroženy požíváním alkoholu. Zřejmě nesedáš za volant pod vlivem a chodci můžou být na přechodech v pohodě.");
		case 43:return("Když to není často, tak to ještě ujde. Šakalí dech po ránu ale taky neni žádná výhra. Příště si místo chlastu radši zajeď k pumpě, a pak navštiv naše hrady a zámky.");
		case 44:return("Nechtěj, aby se z tvého mozku stal časem scvrklý vlašský ořech. Doufám, že je ti blbě, a že znáš lepší věci než alkohol. (Třeba taková horká polívka...)");
		case 45:return("Pokud se nacházíš v tomto stavu víckrát za měsíc, poohlížej se po vhodném dárci jater. Nesnaž se ho ale získat svojí jízdou za volantem - řidičák před sebou radši schovávej.");
		case 46:return("Začni si hledat nejbližší pohřební ústav, najdi si nějakou pěknou parcelku a rozluč se s příbuznými. Nedožiješ totiž rána. (Jestli je ti zrovna zima, nech se pohřbít žehem.)");

		//SYSTEM ERROR: UNDEFINED ID
		default:return("LoadResString: nedefinované id=" + id);

	}//end-of-switch
}//end-of-if

//NOT ENGLISH
if(lng!="en"){
	var strEn=LoadResString(id,"en");
	try{
		google.language.translate(strEn,"en",lng,function(result){
			if(!result.error)return(result.translation);
		});
		return(strEn);
	}
	catch(err){
		return(strEn);
	}
}

//ENGLISH = ENGLISH + SOURCE LANGUAGE FOR TRANSLATING
if(lng=="en"){
	switch(id){

		case 1:return("Promile");
		case 2:return("Chord Transposer");

		case 10:return("How long can I drive after drinking alcohol? ... fill in the following form and immediately to learn.");
		case 11:return("quantity of drinking alcohol");
		case 12:return("alcohol concentration");
		case 13:return("mass person");
		case 14:return("male");
		case 15:return("female");
		case 16:return("choose gender");
		case 17:return("calculate");

		//errors
		case 20:return("Invalid value.");

		//results
		case 40:return("Per mille of alcohol in blood: ");
		case 41:return("Number of hours sobering: ");
		case 42:return("You know very well that alcohol can be a good servant but a bad master. Your driving skills are not at risk of alcohol. Apparently not the car you drive drunk, and pedestrians are crossing safe.");
		case 43:return("If it is not often, that's not bad. Big Beat breath in the morning - this is no a victory. Next time, instead of booze rather ride it up to the filling station, and then visit our castles and chateaus.");
		case 44:return("I hope that you're feeling sick and you know are better things than alcohol. (Hot soup would come to taste...)");
		case 45:return("If you are in this situation several times a month, you start looking for a suitable donor liver. But do not try to get him driving a car.");
		case 46:return("Start your search for the nearest funeral parlor and say good-bye to the relatives. By morning, you die. (If you're just cold, leave to cremate.)");

		//SYSTEM ERROR: UNDEFINED ID
		default:return("LoadResString: undefined id=" + id);

	}//switch

}//if

}//LoadResString

--> 