var lapso = 90000;
var scoresTimer = setTimeout("",refresh);

var c = false;
var gt;
var gr;

var mystr = '';

function cargarleader(cref,idt,dbb,hadmin){
	gt=cref;
	gr=idt;
	gs=dbb;
	ha=hadmin;
	cargar_si('MainDIV','ContDiv', cref,idt,dbb,hadmin)
}

function cargar_si(PDiv,CDiv, cref,idt,dbb,hadmin){
	var URL= '/leader/leader.js.content.php?id='+idt+'&torneo='+ cref +'&dbb='+ dbb +'&hadmin='+ hadmin +'';
	refresh(URL)
}

function refresh(URL){
	if(bw.ns){
		document.layers['ScoresAqui'].load(URL,0);
	}
	if(bw.ie){
		document.frames['ScoresAqui'].location.href=URL;
	}
	if(bw.ns6){
		document.getElementById('ScoresAqui').src='about:blank';
		document.getElementById('ScoresAqui').src=URL;
	}
	else{
		document.frames['ScoresAqui'].location.href=URL;
	}
	scoresTimer = setTimeout("refresh('" + URL + "')",lapso);
} 

function player_scores(idtor,creft,ccodcli,startPos,currPos,Difer,Name,Country,CurrHole,scoreToPar,d1score,d2score,d3score,d4score,total,foto,todayscore){ //,oom_rank){

	this.idtor=idtor;
	this.creft=creft;
	this.ccodcli=ccodcli;
	this.startPos=startPos;
	this.currPos=currPos;
	this.Difer = Difer;
	this.Name=Name;
	this.Country=Country;
	this.CurrHole=CurrHole;
	this.scoreToPar=scoreToPar;
	this.d1score=d1score;
	this.d2score=d2score;
	this.d3score=d3score;
	this.d4score=d4score;
	this.dd1score=d1score;
	this.dd2score=d2score;
	this.dd3score=d3score;
	this.dd4score=d4score;
	this.total=total;
	this.foto=foto;
	this.todayscore=todayscore;

	this.get_player_row=getPlayerRow;

	this.get_player_row_my=getPlayerRowMy;
}

function getPlayerRow(){
	var strOom = '';
	
	if (this.oom_rank!=null){
		strOOM = this.oom_rank;
	}else{
		strOOM = '';
	}
	
	var str = '';
	var strRow = '<tr align="center" class="'+(c?'scoresRowBg">':'scoresRowBgAlternate">')

	if (this.idtor == 'thecut'){
		//if(screcho >= 1) {
			
			str += '<div class="THECUT">Projected Cut '+this.startPos+'</div>';
			//str += '<tr class="BODYSCORING" align="center"><td colspan="13"><a href="http://www.e-learningolf.com" target="_blank"><img border="0" src="http://www.mundogolfstar.com/images/banners/bann.elearn.corte.jpg"></a></td></tr>';
			//this.ccodcli = -this.ccodcli;
			
		//}
	}

	if (this.idtor == 'finalcut'){
		//if(screcho >= 1) {
			
		str += '<div class="THECUT">The Cut</div>';
			//str += '<tr class="BODYSCORING" align="center"><td colspan="13"><a href="http://scoring.golfmol.com" target="_blank"><img border="0" src="http://scoring.golfmol.com/images/banners/golfmol.tla.1.jpg"></a></td></tr>';
			//this.ccodcli = -this.ccodcli;
			
		//}

	}

	if (this.idtor == 'tenpos'){
		
		//if(screcho >= 1) {
			
			//str += '<tr class="BODYSCORECARD" align="center"><td colspan="11" bgcolor="#C0C0C0">Top 10</td></tr>';
			//str += '<tr class="BODYSCORING" align="center"><td colspan="11"><a href="http://scoring.golfmol.com" target="_blank"><img border="0" src="http://scoring.golfmol.com/images/banners/golfmol.tla.1.jpg"></a></td></tr>';
			//this.ccodcli = -this.ccodcli;
		//}
		
	}

	var strRow2 = '';
	var strRow33 = '';
	var strRow34 = '';

	if (this.idtor !== 'tenpos' && this.idtor !== 'thecut' && this.idtor !== 'nocut' && this.idtor !== 'finalcut' && this.idtor !== 'OUT') {

		if (this.d1score != '') {
		} else {
			this.d1score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d2score != '') {
		} else {
			this.d2score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d3score != '') {
		} else {
			this.d3score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d4score != '') {
		} else {
			this.d4score = '&nbsp;&nbsp;&nbsp;';
		}


		str += '<div style="float: left; width:100%; border-bottom:#e1e1e1 thin solid; min-height: 25px; padding: 3px 0px; '+strRow33+' " onmouseover="this.style.background=\'#e1e1e1\';" onmouseout="this.style.background=\''+ strRow34 +'\';">'
		str += '<a class="redsc" href="javascript:myLeader(\''+this.ccodcli+'\')" ><div class="BODYSCORINGi">&#9734;</div></a>'
			+'<div class="BODYSCORING7">'+this.currPos+'<img src="https://admin.plus.golf/img_com/'+this.Difer+'.gif"></div>'
			+'<div class="BODYSCORING7i">'+this.startPos+'</div>'
			+'<div class="BODYSCORINGy"><img id="flagy" src="https://admin.plus.golf/flag/'+this.Country+'.png" alt="'+this.Country+'"></div>'
			+'<a href="/plusgolf/scorecard.php?jugador='+this.ccodcli+'&tid='+this.creft+'" target="tarjetaframe" onclick="veroc(\'loadcard\')"><div align="left" class="BODYSCORINGname"><p style="text-align:left; margin:0px; padding:3px; line-height: 80%;"><b>'+this.Name+'</b></p></div></a>'
			+'<div class="BODYSCORINGt">'+this.CurrHole+'</div>'
			+'<div class="BODYSCORINGrdx">'+this.todayscore+'</div>'
			+'<div class="BODYSCORINGt">'+this.scoreToPar+'</div>'
			+'<div class="BODYSCORINGr">'+this.d1score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d2score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d3score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d4score+'</div>'
			+'<div class="BODYSCORING10">'+this.total+'</div>'
			+'</div><div style"clear:both;"></div>';
		str += strRow2
	
	}

	if (this.idtor == 'nocut') {
		
		if (this.d1score != '') {
		} else {
			this.d1score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d2score != '') {
		} else {
			this.d2score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d3score != '') {
		} else {
			this.d3score = '&nbsp;&nbsp;&nbsp;';
		}
		if (this.d4score != '') {
		} else {
			this.d4score = '&nbsp;&nbsp;&nbsp;';
		}

		str += '<div style="float: left; width:100%; border-bottom:#e1e1e1 thin solid; min-height: 25px; padding: 3px 0px;">'
		str += '<div class="BODYSCORINGi">-</div>'
			+'<div class="BODYSCORING7">'+this.currPos+'</div>'
			+'<div class="BODYSCORING7i">'+this.startPos+'</div>'
			+'<div class="BODYSCORINGy"><img id="flagy" src="https://admin.plus.golf/flag/'+this.Country+'.png" alt="'+this.Country+'"></div>'
			+'<a href="/plusgolf/scorecard.php?jugador='+this.ccodcli+'&tid='+this.creft+'" target="tarjetaframe" onclick="veroc(\'loadcard\')"><div align="left" class="BODYSCORINGname"><p style="text-align:left; margin:0px; padding:3px; line-height: 80%;"><b>'+this.Name+'</b></p></div></a>'
			+'<div class="BODYSCORINGt">'+this.CurrHole+'</div>'
			+'<div class="BODYSCORINGrdx">'+this.todayscore+'</div>'
			+'<div class="BODYSCORINGt">'+this.scoreToPar+'</div>'
			+'<div class="BODYSCORINGr">'+this.d1score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d2score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d3score+'</div>'
			+'<div class="BODYSCORINGr">'+this.d4score+'</div>'
			+'<div class="BODYSCORING10">'+this.total+'</div>'
			+'</div><div style"clear:both;"></div>';

		str += strRow2
		
	}

	if (this.idtor == 'OUT') {
		
		str += '<div style="float: left; width:100%; border-bottom:#e1e1e1 thin solid; min-height: 25px; padding: 3px 0px;">'

		str += '<div class="BODYSCORINGi">-</div>'
			+'<div class="BODYSCORING7">'+this.CurrHole+'</div>'
			+'<div class="BODYSCORING7i">&nbsp;</div>'
			+'<div class="BODYSCORINGy"><img id="flagy" src="https://admin.plus.golf/flag/'+this.Country+'.png" alt="'+this.Country+'"></div>'
			+'<div align="left" class="BODYSCORINGname"><p style="text-align:left; margin:0px; padding:3px; line-height: 80%;"><b>'+this.Name+'</b></p></div>'
			+'<div class="BODYSCORINGt">&nbsp;</div>'
			+'<div class="BODYSCORINGrdx">&nbsp;</div>'
			+'<div class="BODYSCORINGt">&nbsp;</div>'
			+'<div class="BODYSCORINGr">&nbsp;</div>'
			+'<div class="BODYSCORINGr">&nbsp;</div>'
			+'<div class="BODYSCORINGr">&nbsp;</div>'
			+'<div class="BODYSCORINGr">&nbsp;</div>'
			+'<div class="BODYSCORING10">&nbsp;</div>'
			+'</div><div style"clear:both;"></div>';
			
		str += strRow2
		
	}

	c=!c;
	return str;
}

function getPlayerRowMy(){
	var strOom = '';
	
	if (this.oom_rank!=null){
		strOOM = this.oom_rank;
	}else{
		strOOM = '';
	}
	
	var str = '';
	var strRow = '<tr align="center" class="'+(c?'scoresRowBg">':'scoresRowBgAlternate">')


	// LOOP DE MY LEADER
	if(Get_Cookie('myLeader')!=null){
		var strMyPlayers = Get_Cookie('myLeader')
		var arrMyPlayers=strMyPlayers.split(",") 
		
		for (i=0; i<arrMyPlayers.length; i++){
			if (arrMyPlayers[i] == this.ccodcli){

				if (this.idtor !== 'tenpos' && this.idtor !== 'thecut' && this.idtor !== 'nocut' && this.idtor !== 'finalcut' && this.idtor !== 'OUT') {
			
					if (this.dd1score != '') {
					} else {
						this.dd1score = '&nbsp;&nbsp;&nbsp;';
					}
					if (this.dd2score != '') {
					} else {
						this.dd2score = '&nbsp;&nbsp;&nbsp;';
					}
					if (this.dd3score != '') {
					} else {
						this.dd3score = '&nbsp;&nbsp;&nbsp;';
					}
					if (this.dd4score != '') {
					} else {
						this.dd4score = '&nbsp;&nbsp;&nbsp;';
					}
			
			
					str += '<div style="float: left; width:100%; border-bottom:#e1e1e1 thin solid; min-height: 25px; padding: 3px 0px;">'
					str += '<a href="javascript:myLeader(\''+this.ccodcli+'\')" ><div class="BODYSCORINGi"><font color="#ffcc00">&#9733;</font></div></a>'
						+'<div class="BODYSCORING7">'+this.currPos+'<img src="https://admin.plus.golf/img_com/'+this.Difer+'.gif"></div>'
						+'<div class="BODYSCORING7i">'+this.startPos+'</div>'
						+'<div class="BODYSCORINGy"><img id="flagy" src="https://admin.plus.golf/flag/'+this.Country+'.png" alt="'+this.Country+'"></div>'
						+'<a href="/plusgolf/scorecard.php?jugador='+this.ccodcli+'&tid='+this.creft+'" target="tarjetaframe" onclick="veroc(\'loadcard\')"><div align="left" class="BODYSCORINGname"><p style="text-align:left; margin:0px; padding:3px; line-height: 90%;"><b>'+this.Name+'</b></div></a>'
						+'<div class="BODYSCORINGt">'+this.CurrHole+'</div>'
						+'<div class="BODYSCORINGrdx">'+this.todayscore+'</div>'
						+'<div class="BODYSCORINGt">'+this.scoreToPar+'</div>'
						+'<div class="BODYSCORINGr">'+this.dd1score+'</div>'
						+'<div class="BODYSCORINGr">'+this.dd2score+'</div>'
						+'<div class="BODYSCORINGr">'+this.dd3score+'</div>'
						+'<div class="BODYSCORINGr">'+this.dd4score+'</div>'
						+'<div class="BODYSCORING10">'+this.total+'</div>'
						+'</div><div style"clear:both;"></div>';


				}
			
				break;
				
			}
		}
	
	}
	
	var strRow2 = '';
	var strRow33 = '';
	var strRow34 = '';

	c=!c;
	return str;
}

function concat_scores(scoringtime,scores,status,cancha){
	var cancha = new Array();
	var str = '';
	
		str += '<div style="margin: 0px auto; width: 99%;">'

		str +='<div style="float:left; width:100%; border-bottom: #666666 1px solid; border-top: #666666 1px solid; background-color: #f0f0f0;">'
			+'<div class="HEADSCORINGi"><p style="margin:1px 0px; text-align: center; padding: 0px;">My</p></div>'
			+'<div class="HEADSCORING7"><p style="margin:1px 0px; text-align: center; padding: 0px;">Pos</p></div>'
			+'<div class="HEADSCORING7i"><p style="margin:1px 0px; text-align: center; padding: 0px;">Ini</p></div>'
			+'<div class="HEADSCORINGy"><p style="margin:1px 0px; text-align: center; padding: 0px;">Flag</p></div>'
			+'<div class="HEADSCORING24"><p style="margin:1px 0px; text-align: center; padding: 0px;">P L A Y E R</p></div>'
			+'<div class="HEADSCORINGt"><p style="margin:1px 0px; text-align: center; padding: 0px;">Hole</p></div>'
			+'<div class="HEADSCORINGrdx"><p style="margin:1px 0px; text-align: center; padding: 0px;">Rd</p></div>'
			+'<div class="HEADSCORINGt"><p style="margin:1px 0px; text-align: center; padding: 0px;">Scr</p></div>'
			+'<div class="HEADSCORINGr"><p style="margin:1px 0px; text-align: center; padding: 0px;">R1</p></div>'
			+'<div class="HEADSCORINGr"><p style="margin:1px 0px; text-align: center; padding: 0px;">R2</p></div>'
			+'<div class="HEADSCORINGr"><p style="margin:1px 0px; text-align: center; padding: 0px;">R3</p></div>'
			+'<div class="HEADSCORINGr"><p style="margin:1px 0px; text-align: center; padding: 0px;">R4</p></div>'
			+'<div class="HEADSCORING10"><p style="margin:1px 0px; text-align: center; padding: 0px;">Tot</p></div>'
		+'</div>';
		

		var headerMy = '<div style="float: left; width:100%; min-height: 25px; padding: 3px 0px; background-color: #f9f9f9; border-bottom:#e1e1e1 thin solid; "><p style="margin:0px; padding: 5px 25px; font-size: 18px;">My+Leaderboard</p></div>';
		var headerFull = '<div style="float: left; width:100%; min-height: 25px; padding: 3px 0px; background-color: #f9f9f9; border-bottom:#e1e1e1 thin solid; "><p style="margin:0px; padding: 5px 25px; font-size: 18px;">Full+Leaderboard</p></div>';

		for(var i=0;i<scores.length;i++) {
			if(scores[i]) {
				if (scores[i].get_player_row_my().length > 100) {
					str += headerMy;
					break;
				}
			}
		}
		
		for(var i=0;i<scores.length;i++) {
			if(scores[i]) {
				str += scores[i].get_player_row_my();
			}
		}
		
		for(var i=0;i<scores.length;i++) {
			if(scores[i]) {
				if (scores[i].get_player_row_my().length > 100) {
					str += headerFull;
					break;
				}
			}
		}

		for(var i=0;i<scores.length;i++)if(scores[i])str += scores[i].get_player_row();
		
		str += '</div>'	
		str +='<div style="float:left; width:100%; text-align: center; border-top: #666666 1px solid;"><a href="https://plus.golf" target="_blank"><img src="/images/plusgolf_poweredby.png" style="height:64px;" /></a></div>'

	return str;
	
}