﻿function showtext( games1 )
{
	
	var arrGames = games1.split('j');
	var strG1="";
	for( i= arrGames.length-2 ; i>=0;i--)
    strG1 += "מסי " + arrGames[i].substr(0, arrGames[i].indexOf('s')) + " סימן " + (arrGames[i].substr( arrGames[i].indexOf('s')+1 , 1)=='0' ? 'x' : arrGames[i].substr( arrGames[i].indexOf('s')+1 , 1)) + " יחס " + arrGames[i].substr( arrGames[i].indexOf('p')+1,4) + "<br />";
	
	 var src =  "בתאריך :" + arrGames[ arrGames.length-1] + "<br/>";
	 src+=  strG1;
      showtrail( src, "", 190, 90 );
}
function showTyr(xml, idTur , res)
{
	var divik = document.createElement("div");
	var picName;
	for(i=0; i< xml.length; i++)
	{
		var n = xml[i];
		if( parseInt( n.getAttribute("id")) ==  parseInt( idTur))
		{
		//	alert("ops");
			picName= n.getAttribute("pic");
			var oneBlock = document.createElement("div");
			oneBlock.className="catch clear";
			var spT = document.createElement("span");
			spT.className="game-num";
			spT.appendChild( document.createTextNode("משחק מספר :" + n.getAttribute("winner_id")));
			oneBlock.appendChild(spT);
			spText = document.createElement("span");
			spText.className="game-txt";
			spText.appendChild(  document.createTextNode("  " + n.getAttribute("descrip").substr(0,300) ));
			oneBlock.appendChild(spText);
			var spBot = document.createElement("span");
			spBot.className="game-bot";
			spBot.appendChild( document.createTextNode("ההימור " +  ( n.getAttribute("siman") == 0 ? "x" : n.getAttribute("siman")) +" ביחס " + n.getAttribute("persent")));
			oneBlock.appendChild( spBot);
			divik.appendChild(oneBlock);
		}
	}

	
		
	 document.getElementById("img-pic").src="asafPic/" + picName;
	var resault = 2;
	for(i=0; i< res.length; i++)
	{
		if(res[i].getAttribute("id") == idTur)
		{
			resault=res[i].getAttribute("res");
			break;
		}
	}
	//alert( resault);
	document.getElementById("block-res").className="res" + resault;
	return divik;
}

function showCerTyr( idTyr )
{
   var text = showTyr(xmlSelect, idTyr, xmlMain);
   document.getElementById("tip-txt").innerHTML="";
   document.getElementById("tip-txt").appendChild( text);
}

function fiilTyr( xml, count, start)
{
	if( start >= xml.length)
	{
		gStart=0;
		start=0;
		return;
	}
	var divik = document.getElementById("tyr-txt");
	var div= document.createElement("div");
	var str = "";
	for(i=start;  i < count +start; i++ )
	{		 
	 if( i >= xml.length)
	 {
	 	divik.innerHTML="";
	divik.appendChild( div);

	  return;
	 }

		var dd = document.createElement("div");
		dd.className="one-dd";
		dd.innerHTML="<a href=\"javascript:showCerTyr('"+xml[i].getAttribute("id")+"')\">" + xml[i].getAttribute("cdate_dm") + "</a>";
		//dd.innerHTML= xml[i].getAttribute("cdate_dm");
	//	dd.onclick = function(xml[i].getAttribute("id")){
		//	showTyr(xmlMain, xml[i].getAttribute("id"), xmlSelect);
	//	};
		div.appendChild( dd);

//	 str+="<div class=\"one-dd\" onclick=\"showTur(" +xmlMain + "," + xml[i].getAttribute("id") + ", " + xmlSelect+")\">" + xml[i].getAttribute("cdate_dm") + "</div>";
//	 divik.innerHTML+=str;
    }
	divik.innerHTML="";
	divik.appendChild( div);
}
function bildPrice( xml, countDays,  thisDay, price)
{
	var res =0;
       var pricePerWeek=0;
	for( ;countDays >=0; countDays--)
	{
		
		var date = new Date();
		date.setDate( thisDay.getDate() - countDays );
		for(j=0; j< xml.length;j++ )
		{
			var n = xml[j];
			var month= parseInt( date.getMonth())+1;
			//alert( date.getDate() +"/"+ date.getMonth()+1);
			if( n.getAttribute("cdate_dm") == date.getDate() +"/"+ month)
			{
				pricePerWeek+= price;
				if( n.getAttribute("res") == 2 )
				{
					continue;
				}
				if(n.getAttribute("res") == 0)
				{
					res+= -price;
				}
				else if(n.getAttribute("res") == 1 )
				{
					res+= ( n.getAttribute("persent_sum") * price) - price;
				}
			}
		}
	}
	 
	return  Math.round( res *10 )/10 +"|" +pricePerWeek;
}
function loadTable( xml, countDays, price ,idDiv)
{
	var divik= document.createElement("div");
	divik.className="div-hidden hidden";
	divik.id= idDiv;
	var table= document.createElement("table");
	table.className="mytable";
	var thead = document.createElement("thead");
	var tbody = document.createElement("tbody");
	
	var trh = document.createElement("tr");
    var tdh1 = document.createElement("th");
	tdh1.appendChild( document.createTextNode("תאריך"));
	trh.appendChild( tdh1);
	var tdh2 = document.createElement("th");
	tdh2.appendChild( document.createTextNode("השקעה"));
	trh.appendChild( tdh2);
    var tdh3 = document.createElement("th");
	tdh3.appendChild( document.createTextNode("רווח"));
	trh.appendChild( tdh3);
	tdh1.className="header";
	tdh2.className="header";
	tdh3.className="header";
	
    thead.appendChild( trh);
	 for( i= xml.length-1 ; i >= 0 && countDays >= 0; i--)
	 {
	 	var n = xml[i];
		if(n.getAttribute("res") == 2)
		{
			continue;
		}
		countDays--;
		var tr = document.createElement("tr");
		tr.className="mytr" + (i%2);
		var td1= document.createElement("td");
		td1.appendChild( document.createTextNode( n.getAttribute("cdate_dm")))
		tr.appendChild(td1);
		var td2= document.createElement("td");
		td2.appendChild( document.createTextNode( price ))
		tr.appendChild(td2);
		var td3= document.createElement("td");
		td3.appendChild( document.createTextNode( (n.getAttribute("res")== 1? Math.round( n.getAttribute("persent_sum") * price *10)/10 : 0) ))
		td1.className="center";
		td2.className="center";
		td3.className="center";		
		tr.appendChild(td3);
		
		tbody.appendChild( tr);
		
//
	 }
	table.appendChild(thead);
	table.appendChild(tbody);
	divik.appendChild(table);
	
	return divik;
	
}
function persentW(  w , c)
{
	
	var sum = parseInt( c);
   var temp = (w/sum)*100;
    var strTemp = temp.toString();
   if( strTemp.indexOf('.') > -1)
   {
   	strTemp = strTemp.substr(0, strTemp.indexOf('.'));
   }
   return strTemp  + "%";
}
function persentMany( winners, manym, count)
{
	var res = 1 * parseFloat(manym) *10 ;
	var strRes = res.toString();
	if( strRes.indexOf('.') > -1)
	{
		strRes= strRes.substr(0, strRes.indexOf('.'));
	}
    return strRes +"%";    
}
function loadTableNoAsaf( xml)
{
	var divik= document.createElement("div");
	divik.className="no-asaf";
	var table= document.createElement("table");
	table.className="mytable";
	var thead = document.createElement("thead");
	var tbody = document.createElement("tbody");
	
	var trh = document.createElement("tr");
    var tdh0 = document.createElement("th");
	tdh0.appendChild( document.createTextNode(" "));
	trh.appendChild( tdh0);	
    var tdh1 = document.createElement("th");
	tdh1.appendChild( document.createTextNode("שם"));
	trh.appendChild( tdh1);
	var tdh2 = document.createElement("th");
	tdh2.appendChild( document.createTextNode("ניחושים"));
	trh.appendChild( tdh2);
    var tdh3 = document.createElement("th");
	tdh3.appendChild( document.createTextNode("אחוזי הצלחה"));
	trh.appendChild( tdh3);
    var tdh4 = document.createElement("th");
	tdh4.appendChild( document.createTextNode("אחוזי רווח"));
	trh.appendChild( tdh4);	
	tdh0.className="header";
	tdh1.className="header";
	tdh2.className="header";
	tdh3.className="header";
	tdh4.className="header";
    thead.appendChild( trh);
	 for( i=0 ; i < xml.length; i++)
	 {
	 	var n = xml[i];
		var tr = document.createElement("tr");
		tr.className="mytr" + (i%2);
		var td0= document.createElement("td");
		td0.appendChild( document.createTextNode( i+1 ));
		tr.appendChild(td0);
		
		var td1= document.createElement("td");
		//td1.appendChild( document.createTextNode( n.getAttribute("name")));
		var spec = document.createElement("div");
		spec.innerHTML="<div style=\"cursor: pointer;\" onmouseout=\"hidetrail()\" onmouseover=\"showtext('" +n.getAttribute('g1') + "')\">" +n.getAttribute("name")+ "</div>"
		td1.appendChild( spec);
		tr.appendChild(td1);
		
		
		var td2= document.createElement("td");
		td2.appendChild( document.createTextNode(  n.getAttribute("count") + "/" + n.getAttribute("countw") ));
		tr.appendChild(td2);
		var td3= document.createElement("td");
		td3.appendChild( document.createTextNode(persentW(n.getAttribute("countw"), n.getAttribute("count"))) );
		tr.appendChild(td3);	
	    var td4= document.createElement("td");
		td4.appendChild( document.createTextNode(  persentMany(n.getAttribute("winers"), n.getAttribute("manym"),n.getAttribute("count"))));
		tr.appendChild(td4);			
        td0.className="center";	 
		td1.className="center";
		td2.className="center";
		td3.className="center";	
		td4.className="center";			
		tbody.appendChild( tr);
		
//
	 }
	table.appendChild(thead);
	table.appendChild(tbody);
	divik.appendChild(table);
	
	return divik;
	
}
var globalClic1=0;
function showtable( target ,divName)
{
	if (globalClic1 == 0) {
		target.className = "sum-fild-click2 right";
		showMyElem(divName);
		globalClic1=1;
	}
	else
	{
		target.className = "sum-fild-click right";
		hiddeMyElem(divName);
		globalClic1=0;
		
	}
}
var globalClick2=0;
function showtable2( target ,divName)
{
	if (globalClick2 == 0) {
		target.className = "sum-fild-click2 left";
		showMyElem(divName);
		globalClick2=1;
	}
	else
	{
		target.className = "sum-fild-click left";
		hiddeMyElem(divName);
		globalClick2=0;
		
	}
}
function openw()
{
 window.open("mmm.aspx", "telesport", "width=595, height=600,status=0,titlebar=0,toolbar=0,top=10");
}
function openw1()
{
 window.open("mmmlogin.aspx", "telesport", "width=595, height=600,status=0,titlebar=0,toolbar=0,top=10");
}
function openw2()
{
 window.open("mmmnew.aspx", "telesport", "width=595, height=600,status=0,titlebar=0,toolbar=0,top=10");
}

var countGames=0;
var sum=0;
function pushedTD( game_id, winner_id,p, status_p)
{
 if( document.getElementById("line" + winner_id).style.backgroundColor =="yellow")
   {
   return;
   }

	showMyElem("bat");
	var gm_id = document.getElementById("gm_id");
	var strGameId = gm_id.value;

	gm_id.value+= game_id + "i";	
	var win_id = document.getElementById("win_id");

	win_id.value+= winner_id + "i";
	var stat_id = document.getElementById("stat_id");
	stat_id.value+= status_p + "i";
	var p_val = document.getElementById("p_val");
	p_val.value+= p + "i";

	


    
	countGames++;
	if( countGames == 1)
	{
		showMyElem("send");
	}
	var stavka =1;//= document.getElementById("text_many").value;
	sum=sum+ (stavka * p);
	document.getElementById("line" + winner_id).style.backgroundColor="yellow";
	var div_total= document.getElementById("total-div");
	div_total.innerHTML= "יחס זכיה:" + sum.toString().substr(0,4);

	 var siman = ( status_p == 0 ? "x": status_p);
	var divik= document.getElementById("lines-3");
	var div = document.createElement("div");
	div.appendChild( document.createTextNode("מס'" + winner_id + " סימון" + " (" + siman + ") יחס" + " [" + p + "]" ));
	divik.appendChild( div);
	
}
function getBestTyr( countDays , xmlMenager, LorR)
{
var best=0; 
var points=0;
 for( i =0 ; i< xmlMenager.length; i++)
 {
    if(countDays == 0 )
     break;
     countDays--;
     if( xmlMenager[i].getAttribute("res") == "1")
     {
       if( best == 0 )
       {
        best = xmlMenager[i].getAttribute("id");
        points= xmlMenager[i].getAttribute("persent_sum");
       }
       else
       {
        if( parseFloat(xmlMenager[i].getAttribute("res")) > parseFloat( points) )
        {
        best = xmlMenager[i].getAttribute("id");
        points= xmlMenager[i].getAttribute("persent_sum");
          
        }
       }
     }
 }
 //alert( best);
 //return best;
  var strPic ="";
  for(i =0 ; i < xmlSelect.length; i++)
  {
    if( xmlSelect[i].getAttribute("id") ==  best )
    {
     strPic= "asafPic/" + xmlSelect[i].getAttribute("pic");
     break;
     }
  }
  if( strPic.length == 0)
  {
   alert("אין טופס זוכה");
   return;
  }
  var pic = document.createElement("img");
  pic.src= strPic;
  pic.alt="";
 if( LorR == "r")
 {
 
    var d = document.getElementById("mypic-r");
    d.innerHTML="";
    d.appendChild( pic );
    showMyElem("mypic-r");
 }
 else if( LorR == "l")
 {
 
    var d2 = document.getElementById("mypic-l");
    d2.innerHTML="";
    d2.appendChild( pic );
    showMyElem("mypic-l");
 }

}