var currentpid;	
var isAllFieldsOk = true;

function doPlay(pid){
	calculatePopupMargins();
	getEl("confirmpopup").style.display="block";
	getEl("confirmpopup").style.margin= popupMargin;
	if(getEl("div_alert"))getEl("div_alert").style.height="0px";
	getEl("val_group_name").innerHTML =   getEl("fld_group_name").value;
	getEl("val_selected_prediction").innerHTML =   getEl("fld_prediction_title_"+ pid).value;
	//getEl("val_points_placed").innerHTML = getEl("fld_points_"+ pid).value;
	getEl("val_current_odds").innerHTML =   getEl("fld_display_odds_"+ pid).value;
	getEl("fld_prediction_dtls").value =   getEl("fld_prediction_dtls_"+ pid).value;
	//alert( getEl("fld_prediction_dtls").value+" "+getEl("fld_prediction_dtls_"+ pid).value+" Vikas");	
	getEl("fld_group_info").value=getEl("fld_group_in").value;
	getEl("fld_pid").value = pid;	
	currentpid = pid;
	getEl("fld_points").focus();
	getEl("fld_points").value="";
	getEl("val_to_win").innerHTML ="0";
	
}
function populatePoints(p){
	p = p.trim();
	if(!isNaN(p) && p.length>1 ){
		validatePoints();	
	 }
}
function doVal(){
	validatePoints();
	if(getEl("username") && isLoggedIn=='N'){		
		var tempStr = getEl("username").value;	
		tempStr = tempStr.trim();
		if (tempStr.length == 0 && isAllFieldsOk){	
			getEl("div_alert").style.height="auto";	
			getEl("div_alert").innerHTML =p2winMessage.enterusername;		
			isAllFieldsOk = false;	
			getEl("username").className= "formerrorfield";			
		}	
	}
	if(getEl("password") && isLoggedIn=='N'){
		var tempStr = getEl("password").value;	
		tempStr = tempStr.trim();
		if (tempStr.length == 0 && isAllFieldsOk){	
		getEl("div_alert").style.height="auto";		
			getEl("div_alert").innerHTML =p2winMessage.enterpwd;		
			isAllFieldsOk = false;
			getEl("password").className= "formerrorfield";			
		}	
	}
	if (isAllFieldsOk){	
		getEl("div_alert").innerHTML =="";
	}else{
		getEl("div_alert").style.height = "";
	}
}

function validatePoints(){
	
	var tempNum = getEl("fld_points").value;
	tempNum = tempNum.trim();
	if (isBlank(tempNum) ){		
	getEl("div_alert").style.height="auto";	
		getEl("div_alert").innerHTML =p2winMessage.placepoints;		
		isAllFieldsOk = false;	
		getEl("fld_points").className= "formerrorfield";			
	}	
	if (isNaN(tempNum) && isAllFieldsOk){
	getEl("div_alert").style.height="auto";			
		getEl("div_alert").innerHTML =p2winMessage.pointsNaN;		
		isAllFieldsOk = false;	
		getEl("fld_points").className= "formerrorfield";			
	}

	if (parseInt(tempNum) < 10 && isAllFieldsOk){	
	getEl("div_alert").style.height="auto";		
		getEl("div_alert").innerHTML =p2winMessage.mimPoints;		
		isAllFieldsOk = false;	
		getEl("fld_points").className= "formerrorfield";	
	}else{
		var tempPoints =  getEl("fld_points").value;
		tempPoints = tempPoints.trim();
		if(tempPoints.length >0 && !isNaN(tempPoints)) {
			tempPoints =  parseInt(getEl("fld_points").value)* parseFloat(getEl("fld_odds_"+ currentpid).value); 
			getEl("val_to_win").innerHTML = getRoundPoints(tempPoints);
		}
	}
	
}
function doPopupContinue(){
	doVal();
	if(isAllFieldsOk){
		//alert("Submiting ... ");	
		getEl("form_place_prediction").submit();
	}else{
		isAllFieldsOk = true;
	}

}
function doPopupCancel(){
	getEl("div_alert").innerHTML ="";
	getEl("confirmpopup").style.display="none";
}
function doErrorPopupClose(){
	getEl("errorpopup").style.display="none";
}
/* Also Play */
function showPrediction(eid,gid,aid){
	//var url="wcpredictions.php?eventid="+eid+"&grpid="+gid+"&aid="+aid;
	//alert(url);
	var x =  new RemoteProcedure("wcpredictions.php?eventid="+eid+"&grpid="+gid+"&aid="+aid,displayResults,showWaitFetchResults);

}
function showWaitFetchResults(){
		var tempStr = 'divprediction_body';
		getEl(tempStr).innerHTML = loadingHTML;
		
}

function displayResults(xhrObj){
		var tempStr = 'divprediction_body';
		getEl(tempStr).className="slider";
		//alert(xhrObj.responseText);
		getEl(tempStr).innerHTML = xhrObj.responseText;
		currentgid = "";
		return;
}
function hideDiv(gid,groupname,eid,aid) {
	 var tempStr = 'divprediction_body';
	getEl(tempStr).className="";
	 getEl(tempStr).innerHTML = "<a href=\"javascript:showPrediction("+eid+","+gid+","+aid+")\">+"+groupname+"</a>";
}

