var formName = "";
var paarungName = "";
var isHeimspiel = "true";

function showpopup(fName, pName, Satz) {


  formName = fName;
  paarungName = pName;
  if(document.getElementById){
    if(document.getElementById("popup").style.visibility == "visible"){
       document.getElementById("popup").style.visibility = "hidden";
    }else{
       document.getElementById("popup").style.visibility = "visible";
       document.getElementById("popup").innerHTML = Popup(Satz);
    }
  }
}

  var toreHInt = 0;
  var toreAInt = 0;

function Popup(Satz){

  var Woerter = Satz.split("|");

  var toreH = "";
  var toreA = "";

  toreH = document.forms[formName].elements[paarungName+'['+paarungName+'1]'].value;
  toreA = document.forms[formName].elements[paarungName+'['+paarungName+'2]'].value;
  toreHInt = parseInt(toreH);
  toreAInt = parseInt(toreA);

  teamStr1 = document.forms[formName].elements[paarungName+'[teamname1]'].value;
  teamStr2 = document.forms[formName].elements[paarungName+'[teamname2]'].value;

  isHeimspiel = "true";
  if(teamStr1 == "18")
    isHeimspiel = "true";
  else if(teamStr1 == "1")
    isHeimspiel = "true";
  else isHeimspiel = "false";

  var output = "";

  output += '<form name="statForm" id="statForm" action="#">';
  output += '<table class="popup" cellpadding="0" cellspacing="0">';
  output += '<tbody>';
  output += '<tr><td class="title" align="center"> Monatstitel </td><td> </td><td align="right"><a onclick="showpopup()">X </a></td></tr>';

  output += '<tr><td>';
  var Teil = "";

	for (var i = 0; i < toreHInt; i++){
  		output += ''+(i+1)+'. <select name="sel1'+i+'">';
  		output += '<option value="0"></option>';
  		if(isHeimspiel != "false"){
	  		for (var j = 0; j < Woerter.length; j++){
			  Teil = Woerter[j].split(":");
	  		  output += '<option value="'+Teil[0]+'">'+Teil[1]+'</option>';
	  		}
	  		//output += '<option value="-'+Woerter.length+'">-Eigentor</option>';
  		}//if
  		else{
  			output += '<option value="1">Eigentor</option>';
  		}
  		output += '</select><input type="text" id="minuteh'+i+'" name="minuteh'+i+'" value="" size="3" />';
  		if(isHeimspiel != "false"){
	  		output += '<select name="sel2'+i+'">';
	  		output += '<option value="0"></option>';
	  		output += '<option value="1">links</option>';
	  		output += '<option value="2">rechts</option>';
	  		output += '<option value="3">Kopfball</option>';
	  		output += '<option value="4">dir. Freistoss</option>';
	  		output += '<option value="5">Elfmeter</option>';
	  		output += '<option value="6">--Eigentor--</option>';
	  		output += '</select>';
  		}
  		output += '<br />\n';
  	}

  output += '</td><td> </td><td>';

	for (var i = 0; i < toreAInt; i++){
  		output += ''+(i+1)+'. <select name="sel3'+i+'">';
  		output += '<option value="0"></option>';
  		if(isHeimspiel != "true"){
	  		for (var j = 0; j < Woerter.length; j++){
			  Teil = Woerter[j].split(":");
	  		  output += '<option value="'+Teil[0]+'">'+Teil[1]+'</option>';
	  		}
	  		//output += '<option value="-'+Woerter.length+'">-Eigentor</option>';
  		}//if
  		else{
  			output += '<option value="1">Eigentor</option>';
  		}
  		output += '</select><input type="text" id="minutea'+i+'" name="minutea'+i+'" value="" size="3" />';
  		if(isHeimspiel != "true"){
	  		output += '<select name="sel4'+i+'">';
	  		output += '<option value="0"></option>';
	  		output += '<option value="1">links</option>';
	  		output += '<option value="2">rechts</option>';
	  		output += '<option value="3">Kopfball</option>';
	  		output += '<option value="4">dir. Freistoss</option>';
	  		output += '<option value="5">Elfmeter</option>';
	  		output += '<option value="6">--Eigentor--</option>';
	  		output += '</select>';
  		}
  		output += '<br />\n';
  	}
  output += '</td></tr><tr><td>';
  output += '<input type="button" name="button" value="Speichern" onclick="put2()" /><br />\n';
  output += '</td></tr>';
  output += '</tbody>';
  output += '</table>';
  output += '</form>';
  return(output);

}//function

function put2(foo) {

  var valT = "";
  if(isHeimspiel != "false")
    valT = valT + 'H';
  else
    valT = valT + 'A';
  for (var i = 0; i < toreHInt; i++){
	valT = valT + document.forms['statForm'].elements['sel1' + i].value;
	valT = valT +  ':' + document.forms['statForm'].elements['minuteh' + i].value;
	if(isHeimspiel != "false"){
	  valT = valT + '.' + document.forms['statForm'].elements['sel2' + i].value;
	}
	if( (i+1)< toreHInt ){
		valT = valT + '|';
	}
  }
  valT = valT + "-";
  for (var i = 0; i < toreAInt; i++){
	valT = valT + document.forms['statForm'].elements['sel3' + i].value;
	valT = valT + ':' + document.forms['statForm'].elements['minutea' + i].value;
	if(isHeimspiel != "true"){
	  valT = valT + '.' + document.forms['statForm'].elements['sel4' + i].value;
	}
	if( (i+1)< toreAInt ){
		valT = valT + '|';
	}
  }
  document.forms[formName].elements[paarungName+'['+paarungName+'tore]'].value = valT;
  showpopup();
}