var poolId = 3;
var expertsTeamId = 28290;

function antipoolLogin ()
{
	// LOADING MSG
	$('login').innerHTML = "<img src='http://www.rds.ca/images/ajax-loader-antipool.gif'><br/><b>Chargement ...</b>";
	
	// GRAB COOKIE
	GetRDSCookieValue (GetCookie ("sessionkey"));
	
	// AUTHENTICATE
	if (oCurrentCookie.sessionkey == 'na' || oCurrentCookie.sessionkey == 'deleted' ){
		//NOT LOGGED
		$('login').innerHTML = '<div align="left" class="log"><img src="/antipool/img/warning.gif" align="absmiddle" height="20"/>&nbsp;<span style=\'font-size:10px;\'><strong>Veuillez vous identifier pour vous inscrire !</strong></span><br/>'+
		'<form method="post" action="/cgi-bin/Identification">'+
			'<input type="hidden" value="email" name="Commande"/>'+
			'<input type="hidden" value="realtime" name="deg"/>'+
			'<input type="hidden" value="http://www.rds.ca/antipool/" name="pageloc"/>'+
			'<input style="width: 230px;color:#777777;font-weight:bold;" type="text" name="email" value="Votre courriel" onclick="if (this.value == \'Votre courriel\'){this.value = \'\'}" onblur="if (this.value == \'\'){this.value=\'Votre courriel\'}">&nbsp;'+
			'<input class="bouton" type="submit" value="GO" name="submit"/>'+
		'</form></div>';	
		
	} else {
		var id = oCurrentCookie.pkprofil;
		var sid = oCurrentCookie.sessionkey;
		antipoolAjaxRequest('login', '/pooltotal/registration/registrationstatus?id='+id+'&sid='+sid+'&pool=' + poolId);
	}
}

function antipoolAjaxRequest(id, params)
{
	var rand_no = Math.ceil(Math.random()*10000);

	// LOADING MSG
	document.getElementById(id).innerHTML = '<div style="text-align:center;"><img src="http://www.rds.ca/images/ajax-loader-antipool.gif" / > <br/> <b>Chargement ... Ceci peut prendre un certain.  Veuillez patienter.</b></div>';
	
	var httpRequest;
	
	if (window.XMLHttpRequest)  {
		// Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType){httpRequest.overrideMimeType('text/xml');}
	}else if (window.ActiveXObject) {
		// IE
		try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {}}
	}
	if (!httpRequest){return false;}
	
	httpRequest.onreadystatechange = function() {	if (httpRequest.readyState == 4)
													{
														if (httpRequest.status == 200) 
														{
															document.getElementById(id).innerHTML = httpRequest.responseText;
															
														}
													}
												};
	httpRequest.open('GET', 'http://www.rds.ca/app'+params, true);
	/*params = params.replace('?','&');
	httpRequest.open('GET', 'http://www.rds.ca/proxy/apps.php?action='+params+"&rand="+rand_no, true);*/
	httpRequest.send('');
}

function antipoolAjaxRandRequest(id, params)
{
	var rand_no = Math.ceil(Math.random()*10000);

	// LOADING MSG
	document.getElementById(id).innerHTML = '<div style="text-align:center;"><img src="http://www.rds.ca/images/ajax-loader-antipool.gif" / > <br/> <b>Chargement ...</b></div>';
	
	var httpRequest;
	
	if (window.XMLHttpRequest)  {
		// Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType){httpRequest.overrideMimeType('text/xml');}
	}else if (window.ActiveXObject) {
		// IE
		try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {}}
	}
	if (!httpRequest){return false;}
	
	httpRequest.onreadystatechange = function() {	if (httpRequest.readyState == 4)
													{
														if (httpRequest.status == 200) 
														{
															document.getElementById(id).innerHTML = httpRequest.responseText;
														}
													}
												};
	httpRequest.open('GET', 'http://www.rds.ca/app'+params+"&rand="+rand_no, true);
	/*params = params.replace('?','&');
	httpRequest.open('GET', 'http://www.rds.ca/proxy/apps.php?action='+params+"&rand="+rand_no, true);*/
	httpRequest.send('');
}



function antipoolAjaxBGRequest(id, params)
{
	var rand_no = Math.ceil(Math.random()*10000);
	
	// LOADING MSG
	document.getElementById(id).innerHTML = '<div style="text-align:center;"><img src="http://www.rds.ca/images/ajax-loader-antipool.gif" / > <br/> <b>Chargement ...</b></div>';
	
	var httpRequest;
	
	if (window.XMLHttpRequest)  {
		// Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType){httpRequest.overrideMimeType('text/xml');}
	}else if (window.ActiveXObject) {
		// IE
		try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {}}
	}
	if (!httpRequest){return false;}
	
	httpRequest.onreadystatechange = function() {	if (httpRequest.readyState == 4)
													{
														if (httpRequest.status == 200) 
														{
															document.getElementById(id).innerHTML = httpRequest.responseText;
															var idExpert = parseInt(document.getElementById("idExpert").innerHTML);
															document.body.style.backgroundImage = "url(http://www.rds.ca/antipool/img/bg/experts/bg_"+idExpert+".jpg)";
														}
													}
												};
	httpRequest.open('GET', 'http://www.rds.ca/app'+params, true);
	/*params = params.replace('?','&');
	httpRequest.open('GET', 'http://www.rds.ca/proxy/apps.php?action='+params+"&rand="+rand_no, true);*/
	httpRequest.send('');
}

function antipoolAjaxErrRequest(id, params)
{
	var rand_no = Math.ceil(Math.random()*10000);
	
	// LOADING MSG
	document.getElementById(id).innerHTML = '<div style="text-align:center;"><img src="http://www.rds.ca/images/ajax-loader-antipool.gif" / > <br/> <b>Chargement ...</b></div>';
	
	var httpRequest;
	
	if (window.XMLHttpRequest)  {
		// Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType){httpRequest.overrideMimeType('text/xml');}
	}else if (window.ActiveXObject) {
		// IE
		try{httpRequest = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");}catch (e) {}}
	}
	if (!httpRequest){return false;}
	
	httpRequest.onreadystatechange = function() {
													if (httpRequest.readyState == 4)
													{
														if (httpRequest.status == 200) 
														{
															document.getElementById(id).innerHTML = httpRequest.responseText;
															var errCode = parseInt(document.getElementById("errCode").innerHTML);
															if(errCode == 1){window.location = "http://www.rds.ca/antipool/confirmation.html";};
														}
													}
												};
	httpRequest.open('GET', 'http://www.rds.ca/app'+params+"&rand="+rand_no, true);
	/*params = params.replace('?','&');
	httpRequest.open('GET', 'http://www.rds.ca/proxy/apps.php?action='+params+"&rand="+rand_no, true);*/
	httpRequest.send('');
}

// ON ERROR IMAGE
function RescueImage(img){
	img.src="http://legrandclub.rds.ca/images/design/shared/avatar_default_medium.gif";
}

function antipoolLoadLineup( id){
	var url = '/app/pooltotal/roster/url?pool=' + poolId + '&id='+id;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		var lineup = $('alignement');
		lineup.src = transport.responseText;
		//setTimeout('loadLeaderboard()', 3000);
		
		
	  }
	});

}

function loadLeaderboard(){
	//alert ('Bienvenue sur votre alignement');
	try{
		if( $('alignement').contentDocument ) {
			
			var lineup = $('alignement').contentDocument;
			
		} else if( $('alignement').contentWindow.document )  {
			
			var lineup = $('alignement').contentWindow.document;
			
		} else {
			
			return;
			
		}
		//var id = $('idExpert').innerHtml;
		var id = lineup.getElementById('idExpert').innerHTML;
		document.body.style.backgroundImage = "url(http://www.rds.ca/antipool/img/bg/experts/bg_" + id + ".jpg)";
		//alert($('leaderboard').style.backgroundImage);
		//alert( "url(http://www.rds.ca/antipool/images/bg/experts/bg_" + id + ".jpg)");
	} catch(e){
		//alert(e.message);	
	}
	
}
