var cpnew = "";
var uty= "";
function getWinner(lid,ty){
	uty=ty;
	if(ty=='s'){
		target = cpnew+'/ajxc?a=spinw&id='+lid;
	}else{
		target = cpnew+'/ajxc?a=refw&id='+lid;
	}
	//alert(target);
	doCompletion(target)
}

function doCompletion(target){	
	initRequest();
	xhr.onreadystatechange = useHttpResponse;
	xhr.open("GET", target, true);
	xhr.send(null);
}

function initRequest(){	
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function useHttpResponse(){
	if (xhr.readyState == 4){
		if (xhr.status == 200){ 
			processSearch(xhr.responseText);
			}else{
    		failedTOConnect();
    	}
	}
}

function processSearch(result){
	var winnerArray = result.split("*");
	if(winnerArray !=null){
		if(uty=='s'){
			document.getElementById("swindiv").innerHTML=winnerArray[0]+'<br /><span class="fnt18  dbrw">Won $'+winnerArray[1]+' Cash</span>';
		}else{
			document.getElementById("refdiv").innerHTML=winnerArray[0]+'<br /><span class="fnt18  dbrw">Got $'+winnerArray[1]+' Cash</span>';
		}

	}
	//alert("innnn : ");
	
}

function failedTOConnect(){
	if(uty=='s'){
		document.getElementById("swindiv").innerHTML= 'Failed to send.';
	}else{
		document.getElementById("refdiv").innerHTML= 'Failed to send.';
	}
}

function setContextPathWinner(path){
	cpnew = path;
}

