var doingNothing = false

function doNothing() {
  doingNothing = true
}

function sayHI(x) {
  alert(x)
}

function shoutOUT(x) {
  alert("Shout Out To " + x)
}

function getRandomWithRange(r) {
 if (isNumeric(r)) {
 if (r < 0) {
   r = r * -1
 }
 
 return Math.floor(Math.random() * r + 1)
 }
 else
 {
  alert(r + " is not numeric")
  return r + " is not numeric"
 }
}

function isNumeric(x) {
  var validCHARS = "0123456789.-+"
  var strChar
  var minusCount = 0
  var plusCount = 0
  var decimalCount = 0
  var bResult = true
  if (x.length == 0) return false
  
  for (i=0;i < x.length && bResult == true;i++) 
  {
    strChar = x.charAt(i)
    if (validCHARS.indexOf(strChar) == -1)
    {
     bResult = false
    }
    
    if (i > 0) {
      if (strChar == "-") {
        bResult = false
      }
    }
    
     if (i > 0) {
      if (strChar == "+") {
        bResult = false
      }
    }
        
    if (strChar == ".") {
      decimalCount = decimalCount + 1
    }
    if (strChar == "+") {
      plusCount = plusCount + 1
    }
    if (strChar == "-") {
      minusCount = minusCount + 1
    }
    if (decimalCount > 1) {
      bResult =  false
    }
    
    if (plusCount > 1) {
      bResult = false
    }
    if (minusCount > 1) {
      bResult =  false
    }
   }                         
     return bResult
     
  }       
  

function roll() {
 return getRandomWithRange(6) 
}

function GetXmlHttpObject(){
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function ajaxGetResponseText(u, xmlHttp) {
var ResponseText = ""
//var xmlHttp;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
  {
   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
  }
  catch (e)
  {
   try
  {
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    
  }
   catch (e)
  {
     //alert("Your browser does not support AJAX!"); 
     ResponseText = "Your browser does not support AJAX!"
     return false;
  }
  }
  }
  
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        ResponseText=xmlHttp.responseText;
      }
    else {
       ResponseText="...waiting try again"
    }
    }
 xmlHttp.open("GET",u,true);
 xmlHttp.send(null); 
 return ResponseText
 
 }

var bolRoll = true
var bolComeOut  = true 
var point = 0
var balance = 0
var bet = 0
var crapsTotal = 0

function doPoint() {
/*   alert("doPoint() balance = " + balance) */
   if (crapsTotal == point) {
     bolComeOut = true
     point = 0
     document.getElementById('crapsStatus').innerHTML = "You Made Your Point. You Win!"
     balance = balance + bet
     document.getElementById('crapsBalance').innerHTML = balance
   }
   if (crapsTotal == 7) {
     bolComeOut = true
     point = 0
    document.getElementById('crapsStatus').innerHTML = "Seven. You Lose!"   
     balance = balance - bet
     document.getElementById('crapsBalance').innerHTML = balance
   }
/*
   alert("crapsTotal = " + crapsTotal)
   alert("point = " + point)
   alert("balance = " + balance)
*/
}


function doComeOut() {
      
  if (crapsTotal == 7) {
       bolComeOut = true 
       point = 0
       document.getElementById('crapsStatus').innerHTML = "Natural - Win Next Roll Come Out"
        balance = balance + bet
       document.getElementById('crapsBalance').innerHTML = balance
    }

    if (crapsTotal == 11) {
       bolComeOut = true  
       point = 0
       document.getElementById('crapsStatus').innerHTML = "Natural - Win Next Roll Come Out"
       balance = balance + bet
      document.getElementById('crapsBalance').innerHTML = balance
   }

   if (crapsTotal == 2) {
       bolComeOut = true 
       point = 0
       document.getElementById('crapsStatus').innerHTML = "Craps - You Lose Next Roll Come Out" 
       balance = balance - bet
       document.getElementById('crapsBalance').innerHTML = balance
   }

   if (crapsTotal == 3) {
       bolComeOut = true 
       point = 0
        document.getElementById('crapsStatus').innerHTML = "Craps - You Lose Next Roll Come Out" 
        balance = balance - bet
        document.getElementById('crapsBalance').innerHTML = balance
   }

   if (crapsTotal == 12) {
       bolComeOut = true 
       point = 0
        document.getElementById('crapsStatus').innerHTML = "Craps - You Lose Next Roll Come Out" 
        balance = balance - bet
        document.getElementById('crapsBalance').innerHTML = balance
   }

   if (crapsTotal == 4) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }

   if (crapsTotal == 5) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }

   if (crapsTotal == 6) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }

     if (crapsTotal == 8) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }

   if (crapsTotal == 9) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }
      if (crapsTotal == 10) {
       bolComeOut = false 
       point = crapsTotal
       document.getElementById('crapsStatus').innerHTML = "Point: " + crapsTotal 
   }
}


function setBet(b) {
   bet = b
   document.getElementById('crapsWager').innerHTML = bet
}

function rollDicePlay() {
  var dicePics = new Array("images/Dice1.gif", "images/Dice2.gif", "images/Dice3.gif", "images/Dice4.gif", "images/Dice5.gif", "images/Dice6.gif")
  crapsTotal = 0    
  Roll1 = roll()
  Roll2 = roll()
  document.imgDice1.src = dicePics[Roll1 - 1]
  document.imgDice2.src = dicePics[Roll2 - 1]
  crapsTotal = Roll1 + Roll2
  
  if (bolComeOut) {
      doComeOut()
  }
  else {
     if (point != 0) {
        doPoint()
  }
}
}

function rollDice() {
  //spinDice()
  var dicePics = new Array("images/Dice1.gif", "images/Dice2.gif", "images/Dice3.gif", "images/Dice4.gif", "images/Dice5.gif", "images/Dice6.gif")
  Total = 0    
  Roll1 = roll()
  Roll2 = roll()
  document.imgDice1.src = dicePics[Roll1 - 1]
  document.imgDice2.src = dicePics[Roll2 - 1]
  Total = Roll1 + Roll2
}


var intMagicNo = 0
var maps = new Array("images/contraption0.gif",
"images/contraption1.gif",
"images/contraption2.gif",
"images/contraption3.gif",
"images/contraption4.gif",
"images/contraption5.gif",
"images/contraption6.gif",
"images/contraption7.gif",
"images/contraption8.gif",
"images/contraption9.gif",
"images/contraption10.gif",
"images/contraption11.gif",
"images/contraption12.gif")

function OuijaBoard(bolDo) {
  if (bolDo) {
    intMagicNo = getRandomWithRange(12)  
    document.getElementById('imgID').src = maps[intMagicNo]
  }
  else {
    document.getElementById('imgID').src = "images/contraption.gif"
  }
}