/**
 * @author Constantin Polozin
 */
function loadBest(xml, type)
{
	var divik = document.createElement("div");
	if( xml == null || xml.length == 0)
	{
		return divik;
	}
	var title = document.createElement("div");
	title.className="best-" +type+"-title";
	divik.appendChild(title);
	var block = document.createElement("div");
	block.className="best-block";
	divik.appendChild(block);
	
	for(var i=1; i< xml.length-1; i++)
	{
		var n = xml[i-1];
		if(n.getAttribute(type) == "0")
		break;
		var row = document.createElement("div");
		row.className="best-row" + (i%2 ?"-off": "") + " clear catch";
		
		var num =document.createElement("div");
		num.className="best-num";
		num.appendChild( document.createTextNode(i));
		row.appendChild(num);
		
		var name = document.createElement("div");
		name.className="best-name";
		name.appendChild( document.createTextNode(n.getAttribute("name")));
		row.appendChild(name);
		var res = document.createElement("div");
		res.appendChild( document.createTextNode(n.getAttribute(type)));
		row.appendChild(res);
		block.appendChild(row);
	}
	
	return divik;
}
function findAndSetAverage( team_id , xmlik , attribute)
{
	for(var ind=0; ind < xmlik.length; ind++)
	{
		nod = xmlik[ind];
		if( nod.getAttribute("team_id") == team_id )
		{
			return setAverage(nod.getAttribute(attribute), nod.getAttribute("count"));
		}
	}
	return "0";
}
function setAverage( goals, games)
{

	if( parseInt(games) == 0 )
	return "0";
	
	var gol = parseFloat(goals);
	var gam = parseFloat(games);
	var original= gol/gam;
	
	return Math.round(original*10)/10;
}
function bildTableGoals(xml,xmlInside, xmlOutside)
{
	var divik = document.createElement("div");
    divik.className="block-goals";
	var g_title= document.createElement("div");
	g_title.className="g-title";
	divik.appendChild(g_title);
	
	var g_name = document.createElement("div");
	g_name.className="g-name-title";
	g_name.appendChild( document.createTextNode("קבוצה"));
	g_title.appendChild(g_name);
	
	var g_elem1 = document.createElement("div");
	g_elem1.className="g-elem-title";
	g_elem1.appendChild( document.createTextNode("מספר משחקים שערכה"));
	g_title.appendChild(g_elem1);
	var g_elem2 = document.createElement("div");
	g_elem2.className="g-elem-title";
	g_elem2.appendChild( document.createTextNode("מספר משחקים שכבשה"));
	g_title.appendChild(g_elem2);	
	var g_elem3 = document.createElement("div");
	g_elem3.className="g-elem-title";
	g_elem3.appendChild( document.createTextNode("מספר משחקים שספגה"));
	g_title.appendChild(g_elem3);	
	var g_elem4 = document.createElement("div");
	g_elem4.className="g-elem-title";
	g_elem4.appendChild( document.createTextNode("מספר משחקים שלא כבשה"));
	g_title.appendChild(g_elem4);	
	var g_elem5 = document.createElement("div");
	g_elem5.className="g-elem-title";
	g_elem5.appendChild( document.createTextNode("מספר משחקים שלא ספגה"));
	g_title.appendChild(g_elem5);			
	var g_elem6 = document.createElement("div");
	g_elem6.className="g-elem-title g-elem-padd";
	g_elem6.appendChild( document.createTextNode("ממוצע שערי זכות"));
	g_title.appendChild(g_elem6);	
	var g_elem7 = document.createElement("div");
	g_elem7.className="g-elem-title g-elem-padd";
	g_elem7.appendChild( document.createTextNode("ממוצע שערי חובה"));
	g_title.appendChild(g_elem7);		
	var g_elem8 = document.createElement("div");
	g_elem8.className="g-elem-title g-elem-padd";
	g_elem8.appendChild( document.createTextNode("ממוצע שערי זכות"));
	g_title.appendChild(g_elem8);	
	var g_elem9 = document.createElement("div");
	g_elem9.className="g-elem-title g-elem-padd";
	g_elem9.appendChild( document.createTextNode("ממוצע שערי חובה"));
	g_title.appendChild(g_elem9);	
	
	var g_pos = document.createElement("div");
	g_pos.className="g-t2";
	divik.appendChild(g_pos);	
	var t2_n = document.createElement("div");
	t2_n.className="g-name";
	t2_n.appendChild( document.createTextNode(""));
	g_pos.appendChild(t2_n);
	
	var t2_elem = document.createElement("div");
	t2_elem.className="g-elem";
	var g_small = document.createElement("div");
	g_small.className="g-small";
	g_small.appendChild( document.createTextNode("ב"))
	t2_elem.appendChild( g_small);
	var g_small2 = document.createElement("div");
	g_small2.className="g-small";
	g_small2.appendChild( document.createTextNode("ח"))
	t2_elem.appendChild( g_small2);
	g_pos.appendChild(t2_elem);		
	var t2_elem2 = document.createElement("div");
	t2_elem2.className="g-elem";
	var g_small2 = document.createElement("div");
	g_small2.className="g-small";
	g_small2.appendChild( document.createTextNode("ב"))
	t2_elem2.appendChild( g_small2);
	var g_small22 = document.createElement("div");
	g_small22.className="g-small";
	g_small22.appendChild( document.createTextNode("ח"))
	t2_elem2.appendChild( g_small22);
	g_pos.appendChild(t2_elem2);	
	var t2_elem3 = document.createElement("div");
	t2_elem3.className="g-elem";
	var g_small3 = document.createElement("div");
	g_small3.className="g-small";
	g_small3.appendChild( document.createTextNode("ב"))
	t2_elem3.appendChild( g_small3);
	var g_small23 = document.createElement("div");
	g_small23.className="g-small";
	g_small23.appendChild( document.createTextNode("ח"))
	t2_elem3.appendChild( g_small23);
	g_pos.appendChild(t2_elem3);				

	var t2_elem4 = document.createElement("div");
	t2_elem4.className="g-elem";
	var g_small4 = document.createElement("div");
	g_small4.className="g-small";
	g_small4.appendChild( document.createTextNode("ב"))
	t2_elem4.appendChild( g_small4);
	var g_small24 = document.createElement("div");
	g_small24.className="g-small";
	g_small24.appendChild( document.createTextNode("ח"))
	t2_elem4.appendChild( g_small24);
	g_pos.appendChild(t2_elem4);	
	
	var t2_elem5 = document.createElement("div");
	t2_elem5.className="g-elem";
	var g_small5 = document.createElement("div");
	g_small5.className="g-small";
	g_small5.appendChild( document.createTextNode("ב"))
	t2_elem5.appendChild( g_small5);
	var g_small25 = document.createElement("div");
	g_small25.className="g-small";
	g_small25.appendChild( document.createTextNode("ח"))
	t2_elem5.appendChild( g_small25);
	g_pos.appendChild(t2_elem5);	
	
	var t2_elem6 = document.createElement("div");
	t2_elem6.className="g-elem center";
	t2_elem6.appendChild( document.createTextNode("כללי"));
	g_pos.appendChild(t2_elem6);
	
	var t2_elem7 = document.createElement("div");
	t2_elem7.className="g-elem center";
	t2_elem7.appendChild( document.createTextNode("כללי"));
	g_pos.appendChild(t2_elem7);	

	var t2_elem8 = document.createElement("div");
	t2_elem8.className="g-elem";
	var g_small8 = document.createElement("div");
	g_small8.className="g-small";
	g_small8.appendChild( document.createTextNode("ב"))
	t2_elem8.appendChild( g_small8);
	var g_small28 = document.createElement("div");
	g_small28.className="g-small";
	g_small28.appendChild( document.createTextNode("ח"))
	t2_elem8.appendChild( g_small28);
	g_pos.appendChild(t2_elem8);	
	
	var t2_elem9 = document.createElement("div");
	t2_elem9.className="g-elem";
	var g_small9 = document.createElement("div");
	g_small9.className="g-small";
	g_small9.appendChild( document.createTextNode("ב"))
	t2_elem9.appendChild( g_small9);
	var g_small29 = document.createElement("div");
	g_small29.className="g-small";
	g_small29.appendChild( document.createTextNode("ח"))
	t2_elem9.appendChild( g_small29);
	g_pos.appendChild(t2_elem9);	
	
	for(var i=0; i< xml.length; i++)
	{
		n = xml[i];
		var row = document.createElement("div");
		row.className="g-row" + (i%2?"-off" : "") + " catch clear";
		
		
		var _n = document.createElement("div");
		_n.className="g-name";
		_n.appendChild( document.createTextNode(n.getAttribute("name")));
		row.appendChild(_n);
		
		var all = document.createElement("div");
		all.className="g-elem";
		var all_i=document.createElement("div");
		all_i.className="g-small";
		all_i.appendChild( document.createTextNode(n.getAttribute("all_i")));
		all.appendChild(all_i);
		var all_o = document.createElement("div");
		all_o.className="g-small";
		all_o.appendChild( document.createTextNode(n.getAttribute("all_o")));
		all.appendChild(all_o);
		row.appendChild(all);
		
	    var gol = document.createElement("div");
		gol.className="g-elem";
		var gol_i=document.createElement("div");
		gol_i.className="g-small";
		gol_i.appendChild( document.createTextNode(n.getAttribute("gol_i")));
		gol.appendChild(gol_i);
		var gol_o = document.createElement("div");
		gol_o.className="g-small";
		gol_o.appendChild( document.createTextNode(n.getAttribute("gol_o")));
		gol.appendChild(gol_o);
		row.appendChild(gol);
		
	    var gol2 = document.createElement("div");
		gol2.className="g-elem";
		var gol2_i=document.createElement("div");
		gol2_i.className="g-small";
		gol2_i.appendChild( document.createTextNode(n.getAttribute("gol2_i")));
		gol2.appendChild(gol2_i);
		var gol2_o = document.createElement("div");
		gol2_o.className="g-small";
		gol2_o.appendChild( document.createTextNode(n.getAttribute("gol2_o")));
		gol2.appendChild(gol2_o);
		row.appendChild(gol2);
		
	    var _null = document.createElement("div");
		_null.className="g-elem";
		var _null_i=document.createElement("div");
		_null_i.className="g-small";
		_null_i.appendChild( document.createTextNode(n.getAttribute("null_i")));
		_null.appendChild(_null_i);
		var _null_o = document.createElement("div");
		_null_o.className="g-small";
		_null_o.appendChild( document.createTextNode(n.getAttribute("null_o")));
		_null.appendChild(_null_o);
		row.appendChild(_null);		
		
	    var _null2 = document.createElement("div");
		_null2.className="g-elem";
		var _null2_i=document.createElement("div");
		_null2_i.className="g-small";
		_null2_i.appendChild( document.createTextNode(n.getAttribute("null2_i")));
		_null2.appendChild(_null2_i);
		var _null2_o = document.createElement("div");
		_null2_o.className="g-small";
		_null2_o.appendChild( document.createTextNode(n.getAttribute("null2_o")));
		_null2.appendChild(_null2_o);
		row.appendChild(_null2);				
		
		var av1 = document.createElement("div");
		av1.className="g-elem center";
		av1.appendChild( document.createTextNode( setAverage( n.getAttribute("scopeplus"), n.getAttribute("count"))));
		row.appendChild(av1);
		
		var av2 = document.createElement("div");
		av2.className="g-elem center";
		av2.appendChild( document.createTextNode( setAverage( n.getAttribute("scopeminus"), n.getAttribute("count"))));
		row.appendChild(av2);
		
		var av3 = document.createElement("div");
		av3.className="g-elem";
		var av3_1 = document.createElement("div");
		av3_1.className="g-small";
		av3_1.appendChild( document.createTextNode( findAndSetAverage( n.getAttribute("team_id"), xmlInside, "scopeplus") ));
		av3.appendChild( av3_1);
		var av3_2 = document.createElement("div");
		av3_2.className="g-small";
		av3_2.appendChild( document.createTextNode( findAndSetAverage( n.getAttribute("team_id"),xmlOutside, "scopeplus") ));
		av3.appendChild(av3_2);
		row.appendChild(av3);
		
		var av4 = document.createElement("div");
		av4.className="g-elem";
		var av4_1 = document.createElement("div");
		av4_1.className="g-small";
		av4_1.appendChild( document.createTextNode( findAndSetAverage( n.getAttribute("team_id"), xmlInside, "scopeminus") ));
		av4.appendChild( av4_1);
		var av4_2 = document.createElement("div");
		av4_2.className="g-small";
		av4_2.appendChild( document.createTextNode( findAndSetAverage( n.getAttribute("team_id"),xmlOutside, "scopeminus") ));
		av4.appendChild(av4_2);
		row.appendChild(av4);
		
		divik.appendChild(row);
	}
								
	return divik;
}
function bildTableHalf(xml)
{
	var divik = document.createElement("div");
	var tabs = document.createElement("div");
	tabs.className="h-tabs";
	var t1=document.createElement("div");
	t1.className="h-tab";
	t1.appendChild( document.createTextNode("פיגרה מחצית"));
	tabs.appendChild(t1);
	
	var t2=document.createElement("div");
	t2.className="h-tab";
	t2.appendChild( document.createTextNode("תיקו מחצית"));
	tabs.appendChild(t2);

	var t3=document.createElement("div");
	t3.className="h-tab";
	t3.appendChild( document.createTextNode("הובילה מחצית"));
	tabs.appendChild(t3);
	
	divik.appendChild(tabs);
	
	var head = document.createElement("div");
	head.className="half-head";
	divik.appendChild(head);
	
	var n = document.createElement("div");
	n.className="h-name h-title";
	n.appendChild( document.createTextNode("קבוצה"));
	head.appendChild(n);
	var carY = document.createElement("div");
	carY.className="h-card h-title";
	carY.appendChild( document.createTextNode("כרטיסים צהובים"));
	head.appendChild(carY);
	var carR = document.createElement("div");
	carR.className="h-card h-title";
	carR.appendChild( document.createTextNode("כרטיסים אדומים"));
	head.appendChild(carR);
    var w1 = document.createElement("div");
	w1.className="h-val h-title";
	w1.appendChild( document.createTextNode("נצחון"));
	head.appendChild(w1);
	var w2 = document.createElement("div");
	w2.className="h-val h-title";
	w2.appendChild( document.createTextNode("תיקו"));
	head.appendChild(w2);
	var w3 = document.createElement("div");
	w3.className="h-val h-title";
	w3.appendChild( document.createTextNode("הפסד"));
	head.appendChild(w3);
    var z1 = document.createElement("div");
	z1.className="h-val h-title";
	z1.appendChild( document.createTextNode("נצחון"));
	head.appendChild(z1);
	var z2 = document.createElement("div");
	z2.className="h-val h-title";
	z2.appendChild( document.createTextNode("תיקו"));
	head.appendChild(z2);
	var z3 = document.createElement("div");
	z3.className="h-val h-title";
	z3.appendChild( document.createTextNode("הפסד"));
	head.appendChild(z3);	
    var f1 = document.createElement("div");
	f1.className="h-val h-title";
	f1.appendChild( document.createTextNode("נצחון"));
	head.appendChild(f1);
	var f2 = document.createElement("div");
	f2.className="h-val h-title";
	f2.appendChild( document.createTextNode("תיקו"));
	head.appendChild(f2);
	var f3 = document.createElement("div");
	f3.className="h-val h-title";
	f3.appendChild( document.createTextNode("הפסד"));
	head.appendChild(f3);	
	for(var i=0; i< xml.length;i++)
	{
		 nd = xml[i];
		var row = document.createElement("div");
		row.className="h-row" + (i%2?"-off" : "") + " catch clear";
		divik.appendChild(row);
		
		var _n = document.createElement("div");
		_n.className="h-name bold";
		_n.appendChild( document.createTextNode(nd.getAttribute("name")));
		row.appendChild(_n);
		divik.appendChild(row);
		
		var cardY = document.createElement("div");
		cardY.className="h-card center";
		cardY.appendChild( document.createTextNode(nd.getAttribute("yellow")));
		row.appendChild(cardY);
		var cardR = document.createElement("div");
		cardR.className="h-card center";
		cardR.appendChild( document.createTextNode(nd.getAttribute("red")));
		row.appendChild(cardR);
		
		var _w1 = document.createElement("div");
		_w1.className="h-val";
		_w1.appendChild( document.createTextNode(nd.getAttribute("w1")));
		row.appendChild(_w1);
	    var _w2 = document.createElement("div");
		_w2.className="h-val";
		_w2.appendChild( document.createTextNode(nd.getAttribute("w2")));
		row.appendChild(_w2);
	    var _w3 = document.createElement("div");
		_w3.className="h-val";
		_w3.appendChild( document.createTextNode(nd.getAttribute("w3")));
		row.appendChild(_w3);		
		
		var _z1 = document.createElement("div");
		_z1.className="h-val";
		_z1.appendChild( document.createTextNode(nd.getAttribute("z1")));
		row.appendChild(_z1);
	    var _z2 = document.createElement("div");
		_z2.className="h-val";
		_z2.appendChild( document.createTextNode(nd.getAttribute("z2")));
		row.appendChild(_z2);
	    var _z3 = document.createElement("div");
		_z3.className="h-val";
		_z3.appendChild( document.createTextNode(nd.getAttribute("z3")));
		row.appendChild(_z3);		
		var _f1 = document.createElement("div");
		_f1.className="h-val";
		_f1.appendChild( document.createTextNode(nd.getAttribute("f1")));
		row.appendChild(_f1);
	    var _f2 = document.createElement("div");
		_f2.className="h-val";
		_f2.appendChild( document.createTextNode(nd.getAttribute("f2")));
		row.appendChild(_f2);
	    var _f3 = document.createElement("div");
		_f3.className="h-val";
		_f3.appendChild( document.createTextNode(nd.getAttribute("f3")));
		row.appendChild(_f3);								
	}
	return divik;
}

function bildTableGames( xml, div_name, title, arrColors )
{
	    //xml = sortArr(xml);
		//xml = sortArr(xml);
		//xml = sortArr(xml);
		//xml = sortArr(xml);
	    var div_allgames  = document.createElement( "div");
		div_allgames.className="div-allgames";
		var panel = createPanelForTable(title, "");
		div_allgames.appendChild( panel);
		var table = document.createElement("table");
		table.className="mytable";
		//table.className="red";
		var thead = document.createElement("thead");
		table.appendChild( thead );
		var tr = document.createElement("tr");
		var th0=document.createElement("td");
		
		th0.appendChild(document.createTextNode(""));
		tr.appendChild(th0 );
		var th1=document.createElement("td");
		
		th1.appendChild(document.createTextNode(""));
		tr.appendChild(th1 );
		var th2=document.createElement("td");
		th2.appendChild(document.createTextNode("מש'"));
		tr.appendChild( th2);
		var th3=document.createElement("td");
		th3.appendChild(document.createTextNode("נצ'"));
		tr.appendChild( th3);
		var th4=document.createElement("td");
		th4.appendChild(document.createTextNode("תיקו"));
		tr.appendChild( th4);
        var th5=document.createElement("td");
		th5.appendChild(document.createTextNode("הפ'"));
		tr.appendChild( th5);
		var th8=document.createElement("td");
		th8.appendChild(document.createTextNode("הפרש"));
		tr.appendChild( th8);		
		var th6=document.createElement("td");
		th6.appendChild(document.createTextNode("יחס"));
		tr.appendChild( th6);
		var th7=document.createElement("td");
		th7.appendChild(document.createTextNode("נק'"));
		tr.appendChild( th7);
		thead.appendChild( tr );
		//table.appendChild( tr );
		th1.className="table-text";
		th2.className="table-text center";
		th3.className="table-text center";
		th4.className="table-text center";
		th5.className="table-text center";
		th6.className="table-text center";	
		th8.className="table-text center";					
		th7.className="table-text center";				
		//alert("kyky");
		var tbody = document.createElement( "tbody");
		table.appendChild( tbody);
        
	for (var i = 0; i < xml.length; i++)
	 {
	 	var trRow = document.createElement("tr");
		trRow.className="mytr" + ( arrColors == "" ? (i%2): arrColors[i+1]);
		var td0 = document.createElement( "td");
		td0.appendChild(document.createTextNode(i+1));
		td0.className="table-text";
		trRow.appendChild( td0);
		var td1 = document.createElement( "td");
		td1.appendChild(document.createTextNode(xml[i].getAttribute("name")));
		td1.className="table-text";
		trRow.appendChild( td1);
		var td2 = document.createElement( "td");
		td2.className="center";
		td2.appendChild(document.createTextNode(xml[i].getAttribute("count")));
		trRow.appendChild( td2);
		var td3 = document.createElement( "td");
		td3.className="center";
		td3.appendChild(document.createTextNode(xml[i].getAttribute("winers")));
		trRow.appendChild( td3);	
		var td4 = document.createElement( "td");
		td4.className="center";
		td4.appendChild(document.createTextNode(xml[i].getAttribute("zero")));
		trRow.appendChild( td4);	
		var td5 = document.createElement( "td");
		td5.className="center";
		td5.appendChild(document.createTextNode(xml[i].getAttribute("faild")));
		trRow.appendChild( td5);	
		var td6 = document.createElement( "td");
		td6.className="center";
		td6.appendChild(document.createTextNode(xml[i].getAttribute("scopeminus") + "-" +xml[i].getAttribute("scopeplus")));
		trRow.appendChild( td6);	
		var td8 = document.createElement( "td");
		td8.className="center";
		var efresh =  xml[i].getAttribute("scopeplus") - xml[i].getAttribute("scopeminus");
		td8.appendChild(document.createTextNode(( efresh > 0 ? "+" + efresh: efresh)));
		trRow.appendChild( td8);							
		var td7 = document.createElement( "td");
		td7.className="center2";
		td7.appendChild(document.createTextNode(xml[i].getAttribute("points")));
		trRow.appendChild( td7);
		tbody.appendChild( trRow );								

	 }
	 //table.appendChild(tbody);
	 div_allgames.appendChild( table );
	 document.getElementById(div_name).appendChild( div_allgames);
}
var globCountPreiods=0;
function getcountPeriods( xml )
{
 return   xml[xml.length-1].getAttribute("period");	
}
function bildTablePeriod(xml, intPeriod)
{
	var divik = document.createElement("div");
	divik.className="tbl-scroll";
	var divTitlePeriod = document.createElement("div");
	divTitlePeriod.className="table-period-title";
	var table = document.createElement("table");
	table.className="mytable-period";
	var tbody=document.createElement("tbody");
	var flag=0;
	for(var i=0; i < xml.length; i++)
	{
	var cerPriod = xml[i].getAttribute("period");
		
		

		 var tr = document.createElement("tr");
		 tr.className="tr-period" + ( i% 2 ? "-off" : "" );
		 var td5 = document.createElement("td");
		 td5.className="td-date";
		 td5.appendChild( document.createTextNode(  xml[i].getAttribute("cdate")));
		 var td1 = document.createElement("td");		 		 
		 td1.appendChild( document.createTextNode( xml[i].getAttribute("name1")));
		 
		 var td2 = document.createElement("td");
	     var td3 = document.createElement("td");
		 var td= document.createElement("td");		 
		 if (xml[i].getAttribute("scope1") == "-1") {
	    	td2.appendChild(document.createTextNode("ט"));
			td.appendChild(document.createTextNode("."));
			td3.appendChild(document.createTextNode("נ"));
		    td.className="td-digit-red";
		
		 td2.className="td-digit-red";
		 td3.className="td-digit-red";
		
		
		 }
		 else {
		 td2.appendChild(document.createTextNode(xml[i].getAttribute("scope1")));

		 td.appendChild( document.createTextNode("-"));
		 td.className="center";
		 td3.appendChild( document.createTextNode( xml[i].getAttribute("scope2")));
		 td.className="td-digit";
		 td2.className="td-digit";
		 td3.className="td-digit";
		 }

		 var td4 = document.createElement("td");
		 td4.appendChild( document.createTextNode( xml[i].getAttribute("name2")));	
		 td1.className="td-name2";
		 td4.className="td-name2";
         tr.appendChild(td5);
		 tr.appendChild(td1);
		 tr.appendChild(td2);
		 tr.appendChild(td);
		 tr.appendChild(td3);
		 tr.appendChild(td4);	 		 		 
		 tbody.appendChild( tr );
		
		
	}
	table.appendChild( tbody);
	divik.appendChild( divTitlePeriod);
	divik.appendChild( table);
	return divik;
}
function reloadPeriods(intPeriod, xml)
{
 var divik = $("tables-period");
 divik.innerHTML="";
 var table1 = bildTablePeriod( xml, intPeriod );
 var table2 = bildTablePeriod( xml, parseInt( intPeriod) +1 );
 var tit1= createPanelForTableGreey("המחזור שהיה" , "");
 var tit2= createPanelForTableGreey("המחזור הבא" , "");
 divik.appendChild(tit1);
 divik.appendChild( table1 );
 divik.appendChild(tit2);
 divik.appendChild( table2 );
}

function bildPanelPeriods( xml) 
{
	var divik = document.createElement("div");
	divik.className="catch clear periods-cange-div";//numbers_bg_cntr.jpg
	var table= document.createElement("table");
	table.className="periods-change"
	var tbody= document.createElement("tbody");
	var tr= document.createElement("tr");
	tr.className="panel-periods";
	for(var i=1; i<= globCountPreiods; i++ )
	{
		var td= document.createElement("td");
		td.className="td-panel-periods";
		td.appendChild( document.createTextNode(i));
	    td.onclick=function(){ reloadPeriods(this.innerHTML, xml)};
		tr.appendChild( td);
	}
	tbody.appendChild( tr);
	table.appendChild( tbody);
	var pan = createPanelForTable("מחזורי ליגה", "");
	divik.appendChild( pan );
	divik.appendChild( table);
	
	return divik;
	
}
function getLastPeriod( xml )
{
	for(var i=1; i< xml.length; i++)
	{
		if( xml[i].getAttribute("game_id") == "")
		 return xml[i-1].getAttribute("period");
	}
	return getcountPeriods( xml);
}
function bildPeriodGames( xml, divName) 
{
	var divik = document.createElement("div");
	divik.className="tables-period right";

	//alert( lastPeriod);
var table1 = bildTablePeriod( xml, 1 );
var tit1= createPanelForTableGreey("משחקים" , "");

 $(divName).appendChild(tit1);
 $(divName).appendChild( table1 );
	
}

