
function redeemtickets(user, type)
{
	
	var answer = confirm ("Are you sure you want to use your ticket for this game?")
	if (answer)
	{
		$.post("freerollPass.php", { id:user, type: type},function(data) 
		{
			confirm(data)
		
		},'html');
	
	}
}


function loadGif()
{
	placeForm('#loadingGif')
	$('#loadingGif ').css('display','block')
}


function hideGif()

{
	$('#loadingGif ').css('display','none')
}



var cssDisplay
var oldText
function changeCenter()
{



if (cssDisplay != 'hidden')
	{
		loadGif()
		oldText=$('.navbar strong').text()
		$('.navbar strong').text('GAS Twitter - Main')
		
		$.post("centerTwitter.php", function(data) 
		
		{
				
				$('#centerColumn table').css('visibility','hidden')
				$('#centerColumn table').css('font-size','.1em')
				
				
	
				
				$('#centerColumn').prepend(data)
				hideGif()
				
			}, 'html')
			
		cssDisplay= 'hidden'

	}
	else if (cssDisplay == 'hidden')
	
	{
		
		$('#centerColumn table').css('visibility','visible')
		$('#centerTwitter').remove()
		$('#loadingGif ').css('display','none')
		cssDisplay= 'visible'
		$('.navbar strong').html(oldText)
	}


}


function removeStream(twittername,id)


{

	//$('#'+id).fadeTo("slow",0.33)
	
	
	$('#'+id ).attr( 'class',"removing");
	
	$('.removing').css('background-color',"#FFFDB2" );
	
	
	
	
	
	$('#'+id+' div .removeable ').html('<b>'+ twittername+' </b> has been removed from your twitter stream  ')
	$('#tinfo'+id).remove()
	
	$.post("Twitter/removeStream.php?",{ tweeter: twittername}, function(data) 
		{
		
			alert(data)	
		}, 'html')


}






function getUserIdForStakes(userid) {  }


















function transferToHorse(threadid)

{
		$.post("pvtTransfer.php?do=1",{ stakeid: threadid}, function(data) 
		{
		
			$('#report').html(data)	
		}, 'html')
	
}




function setRoomNames()
{
horse=$('#horse').val()
$.post(	"getRoomNames.php", { horse: horse}, function(data) {$('#PokerRooms').html(data)} )
}



function makeRail()
{
document.getElementById('infoText').innerHTML="Stakes Being Updated and user being Notified!"
$('#infoTD').css("background-color","yellow")
$('#infoTD').css("color","red")
$('#infoTD').css("border","2px solid red")
}

function placeForm(elementName)

{

    var docheight=$(document).height()    //gets  total height of document

    var windowheight=$(window).height()    // gets height of viewport

    var barHeight=$(elementName).height() // gets height of sidebar

    var barWidth=$(elementName).width()

    var windoWidth=$(window).width()

    var maxHeight=windowheight-60

    $(elementName).css("max-height",maxHeight)

    if (barHeight > maxHeight) {barHeight =maxHeight}

  

    var margin=(windowheight-barHeight)/2

    var sideMargin=(windoWidth-barWidth)/2

    var margin=margin-10

    var halfPanel=barHeight/2

    var place=(margin+halfPanel)

    $(elementName).css("top",margin)

    $(elementName).css("left",sideMargin)

    

}


function placeInfoBox(elementName)
{
    var windowheight=$(window).height()    // gets height of viewport

    var barHeight=$('#'+elementName).height() // gets height of sidebar
    var maxHeight=windowheight-60
	var margin=(windowheight-barHeight)/2
	var margin=margin-10
    $('#'+elementName).css("max-height",maxHeight)
	$('#'+elementName).css("top",margin)
	//console.log('window'+windowheight)
	//console.log('element'+barHeight)
	//console.log('margin'+margin)
}


var theuserid=""
function getUserIdForStakes(userid)
{

theuserid=userid

}

function getResults(horseid,stakerid)
{
	
	 if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="thisHorse.php?uid="+horseid+"&sid="+stakerid
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
          
	
	return xmlhttp.responseText;
}




function getStakes()
{
	
	 if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="myStakes.php?uid="+theuserid
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
          
	
	return xmlhttp.responseText;
}




function getRails()
{
	
	 if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="myRails.php?uid="+theuserid
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
          
	
	return xmlhttp.responseText;
}





var isVisible='false'

function showMyStakes() 
{
	if(isVisible!='true')
	{
	
		document.getElementById('popup').innerHTML=getStakes()
		placeForm('#popup')
	
		$('#popup').css("visibility","visible") 
		
		isVisible='true'
	}
	else if (isVisible =='true')
	{
		$('#popup').css("visibility","hidden")
		isVisible='false'
	}

}

function showMyRails() 
{
	if(isVisible!='true')
	{
	
		document.getElementById('popup').innerHTML=getRails()
		placeForm('#popup')
	
		$('#popup').css("visibility","visible") 
		
		isVisible='true'
	}
	else if (isVisible =='true')
	{
		$('#popup').css("visibility","hidden")
		isVisible='false'
	}

}



var oldhorse=""
function getHorseResults(horseid,stakerid) 
{
	if(isVisible!='true' || oldhorse != horseid )
	{
	
		document.getElementById('popup').innerHTML=getResults(horseid,stakerid)
		placeForm('#popup')
	
		$('#popup').css("visibility","visible") 
		
		isVisible='true'
	}
	else if (isVisible =='true')
	{
		$('#popup').css("visibility","hidden")
		isVisible='false'
	}
	oldhorse = horseid

}


function hideMyStakes() {$('#popup').css("visibility","hidden");isVisible='false'}



//uses tab s to show current stakes

var isCtrl = false; 
$(document).keyup(function (e)
{ 
	if(e.which == 9) isCtrl=false; 
}).keydown(function (e) 
		{ 
		if(e.which == 9) isCtrl=true; 
		if(e.which == 83 && isCtrl == true) { showMyStakes() ;addTweet()} 
		}); 
		
		
		
		
// uses r to show rails in progress
var isCtrl = false; 
$(document).keyup(function (e)
{ 
	if(e.which == 9) isCtrl=false; 
}).keydown(function (e) 
		{ 
		if(e.which == 9) isCtrl=true; 
		if(e.which == 82 && isCtrl == true) { showMyRails() } 
		}); 
		
		
		
		
// uses escape key to hide		

$(document).keyup(function (e)
{ 
	if(e.which == 27) {hideMyStakes()}
})



function GS(table,searchfield,criteria) {
    
     if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="GS.php?table="+table+"&searchfield="+searchfield+"&criteria="+criteria
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText   



return xmlhttp.responseText;

}

var aj=2


function moreinfo()
{

p=aj/2
if (p == Math.round(p)) {$('#moreInfo').css("visibility","visible")}
	if (p != Math.round(p)){ $('#moreInfo').css("visibility","hidden")}
   aj++                                 
}


function lessinfo()
{
$('#moreInfo').css("visibility","hidden")
	
   aj++                                 
}

function editGames(currentGame) 
{
	document.getElementById('gameButtton'+currentGame).value='Working'
	$('#gameButtton'+currentGame).css("color","yellow")
//	$('#gameButtton'+currentGame).css("font-weight","bold")
	
	date=document.getElementById('date'+currentGame).value
    time=document.getElementById('time'+currentGame).value
	pass=document.getElementById('pass'+currentGame).value
	room=document.getElementById('room'+currentGame).value
	tourney=document.getElementById('tourney'+currentGame).value
	currleague=document.getElementById('currleague').value

     if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="editLeagueGames.php?g="+currentGame+"&t="+time+"&p="+pass+"&r="+room+"&tn="+tourney+"&l="+currleague+"&d="+date
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText   
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='updated')
		{ 
			document.getElementById('gameButtton'+currentGame).value='Game '+currentGame+' Updated'
			$('#gameButtton'+currentGame).css("color","green")
		}
		if (result!='updated')
		{ 
			document.getElementById('gameButtton'+currentGame).value='Something Went Wrong'
			$('#gameButtton'+currentGame).css("color","red")
        	$('#gameButtton'+currentGame).css("font-weight","bold")

		}
	
return xmlhttp.responseText;

}




function getAppInfo(userid)
{


status=GS("vb_user","AppStatus","userid="+userid)


document.getElementById('GASNOTICES').innerHTML=status

}



function showRegistrants(currentLeague,currentGame)
{
	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='leageReg.php?do=list&leagueId='+currentLeague+'&game='+currentGame
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		document.getElementById('theinfo').innerHTML=result
		
		
}

function markPaid(currentLeague,currentGame,user)
{
	$('#'+user).css("color","yellow")
	$('#'+user).css("font-weight","bold")

	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='leageReg.php?do=markPaid&leagueId='+currentLeague+'&game='+currentGame+'&userId='+user
	  
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='paid')
		{ 
		
		$('#'+user).css("color","green")
		
		}
		if (result=='NOTpaid')
		{ 
		
		$('#'+user).css("color","red")
		
		}
}

function rrs(stakeid,eleId)
{
	document.getElementById('theButton'+eleId).innerHTML='Working'

	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='rolled.php?id='+stakeid
	  
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='updated')
		{ 
		document.getElementById('buttons'+eleId).innerHTML='Rolling Complete'
		
		}
}

function closedByAdmin(stakeid,eleId)
{
	document.getElementById('theButton'+eleId).innerHTML='Working'

	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='closedByAdmin.php?id='+stakeid
	  
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='updated')
		{ 
		document.getElementById('buttons'+eleId).innerHTML='STAKE CLOSED'
		
		}
}


function cancel(stakeid,eleId)
{
	document.getElementById('theButton'+eleId).innerHTML='Working'

	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='quickCancel.php?id='+stakeid
	  
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='updated')
		{ 
		document.getElementById('buttons'+eleId).innerHTML='STAKE CLOSED'
		
		}
}

function deleteStock(threadid)
				
{
	
 
	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='deleteStock.php?id='+threadid
	  
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		if (result=='updated')
		{ 
		
		
		}
}

function leagueReg(currentLeague,currentGame,UserSearched,gameTime1,gameTime2)
	{
			if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
  
		url='leageReg.php?userId='+UserSearched+'&leagueId='+currentLeague+'&game='+currentGame
		xmlhttp.open('POST',url,false);
		xmlhttp.send(null);
		result = xmlhttp.responseText   
	
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace

		

		if (result=='complete')
		{ 
			document.getElementById('leagueRegBox').innerHTML='<div id=theinfo></div><p> <b><a onmouseover=showRegistrants('+currentLeague+','+currentGame+') onmouseout=hideregistrants()><p><b>You are registered <br>for the next Game<br>'+gameTime1+' <br> '+gameTime2+' EST</p></a><input type=button onclick=leagueUnregister('+currentLeague+','+currentGame+','+UserSearched+',"'+gameTime1+'","'+gameTime2+'") value=Unregister />'}                                                          
		}
			




function hideregistrants(){document.getElementById('theinfo').innerHTML=''}


function leagueUnregister(currentLeague,currentGame,UserSearched,gameTime1,gameTime2)
{
	if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='leageReg.php?do=unreg&leagueId='+currentLeague+'&game='+currentGame+'&userId='+UserSearched
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		
		
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
	
					
			
		if (result=='deleted')
		{ 
		document.getElementById('leagueRegBox').innerHTML='<div id=theinfo></div><p> <b><a onmouseover=showRegistrants('+currentLeague+','+currentGame+') onmouseout=hideregistrants()><p><b>Click below to register for <br> League '+currentLeague+' Game '+currentGame+'<br> '+gameTime1+' <br> '+gameTime2+' EST</p></a><input type="button" onclick=leagueReg('+currentLeague+','+currentGame+','+UserSearched+',"'+gameTime1+'","'+gameTime2+'") value="Register" />'
		}

}


function forceInvestorToHaveReceived(investor,stakeid,eleId)
{
//console.log(eleId)
if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url='forceReceive.php?iid='+investor+'&sid='+stakeid
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
        result = xmlhttp.responseText  
		
		
		result = result.replace(/^\s+/g,'');//remove heading whitespace
		result = result.replace(/\s+$/g,'');//remove trailing whitespace
		
		document.getElementById('flake'+eleId).innerHTML=result


}

$(document).ready(function(){


$("a:contains('New Posts')").append('<span id="noOfNewPosts" > </span>')   //   adds span to new Posts so we can insert the number of new posts 

var parent = document.getElementById('server_status_table');

if(parent)
{
     var childCount = parent.getElementsByTagName('div').length;
         

	//parent.removeChild(parent.childNodes[9]);
	
	//document.getElementById('server_status_table').lastChild.nodeValue='bold bit of text';
	
	$("#server_status_table div").remove(":contains('Provided by Instant')");
	$("#server_status_table div").remove(":contains('ZIPS')");
	$("#server_status_table div").remove(":contains('Tracey's Therapy')");
	$("#server_status_table div").remove(":contains('GAS Chamber')");
	
	$("#server_status_table div").remove(":contains('No Sound')");
	$("#server_status_table div").remove(":contains('iCarly')"); 
	$("#server_status_table div").remove(":contains('Strategy')"); $("#server_status_table div").remove(":contains('Beats and variance')"); 
	
	//font:bold 12pt verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif;
	$("#server_status_table div:nth-child(1)").remove()
}

})






var myelement="closed"
var element3
function showStuff(element)
{

	
	$(".quickInfo").css("display","none")
		
	$(".quickView").css("display","none")
		
	$('#'+element).css("display","block")

}

function run()
{
	$(".quickView").css("display","none")
	$('#'+element3).css("display","block")
	placeForm("#"+element3)
}
	
function run2()
{
	$(".quickInfo").css("display","none")
			
	$(".quickView").css("display","none")
 
}	
	
	

function showStuff2(element2)
{


element3=element2	
		
	setTimeout("run()",50)
	

}

function hideStuff() 

{

setTimeout("run2()",50)
	
}
function hideSub(){$(".quickView").css("display","none")}



function getAllUserNames()
{
	
	 if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
    else
      {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      url="GASPrograms/autoNames.php"
        xmlhttp.open("POST",url,false);
        xmlhttp.send(null);
          
	
	return xmlhttp.responseText;
}



// private stake form *******************************************************************************************************************









// end placing private stake form        **************************************************************************************************


function getAmountToClear()
{



amountEntered=document.getElementById('clearamount').value

if (  parseInt(amountEntered)<0 || isNaN(amountEntered) ) {  document.getElementById('clearamount').value=""; amountEntered="0.00"}


document.getElementById('clearMakeupButton').value="Clear $"+amountEntered+" in makeup"

}



function removeMakeup(amount,staker,horse)
{
	alert("Clearing a horse's makeup is completely voluntarily and in most cases defeats the purpose of staking. Only do so if you have a good reason to.")
	$.post("getHorseName.php", { horse: horse}, function(data) 
	{
		buttonValue="Please Input an amount to clear First"
		rmhtml="<span class=specSpan onclick=clearThis() >X</span><center><b>"+data+"</b> Owes you $"+amount+" in Makeup. <br> How much of this would you like to clear? <br>$<input  type=text id=clearamount  onKeyUp=getAmountToClear() /> <br> <input type=button value='"+buttonValue+"' id='clearMakeupButton' onclick='finishclearing("+amount+","+staker+","+horse+")' /></center>"
		if (amount <=0) {rmhtml="<span class=specSpan onclick=clearThis() >X</span><center>There Is no Makeup to clear with <b>"+data+"</b></center>"}
		
		document.getElementById('specPop').innerHTML=rmhtml
		
		placeForm("#specPop")
		$("#specPop").css("display","block")
	})
}

function clearThis()
{
$("#specPop").css("display","none")
}


function clearThis2(divid)
{
$("#"+divid).css("display","none")
$('#overlayDiv').css("display","none");
}


function finishclearing(amount,staker,horse)
{
    enteredAmount=document.getElementById('clearamount').value
	
	if (enteredAmount > 0)
	{
		if (enteredAmount > amount) {enteredAmount = amount}
		remaining=amount-enteredAmount
		document.getElementById('specPop').innerHTML
		$.post("removeMakeup.php", { horse: horse, staker: staker, amount:enteredAmount  },
		
		function(data)
		{ 
		
			document.getElementById('specPop').innerHTML=data;
			document.getElementById('MO'+horse).innerHTML="$"+remaining.toFixed(2) 
			if (remaining==0) {document.getElementById('RM'+horse).innerHTML="  "}
		} );
		
		
		
	}
	else alert('You need to enter a value')
} 


function hideOldStake(horseid,stakerid)

{
	$.post("hideStakes.php?do=hide", { horse: horseid, staker:stakerid}, function(data) { $("#HTR"+horseid).css("color","red"); $("#HTR"+horseid).fadeTo("slow",0.33) } )
}

function showAll(stakerid)

{
	$.post("hideStakes.php?do=show", { staker:stakerid}, function(data) { alert('All history will be shown when you refresh or reload the page')})
}
