﻿//Init

var con = new XHConn();
var fullImagesPath = "../images/deckOfCards/2";
var ImagesType = ".gif";
var playersName = new Array();
    playersName[0] = "Alex";
    playersName[1] = "Bob";
    playersName[2] = "Carol";
    playersName[3] = "David";

var rightAnswerImageSrc = "../images/general/greenV1.jpg";
var wrongAnswerImageSrc = "../images/general/redX1.jpg";

var qNum = 0 ;
var cGameName = "Texas Hold'em";
var badPoints = 0 ;
var goodPoints = 0 ;

document.getElementById('quizBox').innerHTML ="<div id='tabBox'></div><div id='qaBox'></div>";

var deckOfCardsInfo = new Array();

deckOfCardsInfo["Ac"] = new Array();
deckOfCardsInfo["2c"] = new Array();
deckOfCardsInfo["3c"] = new Array();
deckOfCardsInfo["4c"] = new Array();
deckOfCardsInfo["5c"] = new Array();
deckOfCardsInfo["6c"] = new Array();
deckOfCardsInfo["7c"] = new Array();
deckOfCardsInfo["8c"] = new Array();
deckOfCardsInfo["9c"] = new Array();
deckOfCardsInfo["Tc"] = new Array();
deckOfCardsInfo["Jc"] = new Array();
deckOfCardsInfo["Qc"] = new Array();
deckOfCardsInfo["Kc"] = new Array();

deckOfCardsInfo["Ah"] = new Array();
deckOfCardsInfo["2h"] = new Array();
deckOfCardsInfo["3h"] = new Array();
deckOfCardsInfo["4h"] = new Array();
deckOfCardsInfo["5h"] = new Array();
deckOfCardsInfo["6h"] = new Array();
deckOfCardsInfo["7h"] = new Array();
deckOfCardsInfo["8h"] = new Array();
deckOfCardsInfo["9h"] = new Array();
deckOfCardsInfo["Th"] = new Array();
deckOfCardsInfo["Jh"] = new Array();
deckOfCardsInfo["Qh"] = new Array();
deckOfCardsInfo["Kh"] = new Array();

deckOfCardsInfo["As"] = new Array();
deckOfCardsInfo["2s"] = new Array();
deckOfCardsInfo["3s"] = new Array();
deckOfCardsInfo["4s"] = new Array();
deckOfCardsInfo["5s"] = new Array();
deckOfCardsInfo["6s"] = new Array();
deckOfCardsInfo["7s"] = new Array();
deckOfCardsInfo["8s"] = new Array();
deckOfCardsInfo["9s"] = new Array();
deckOfCardsInfo["Ts"] = new Array();
deckOfCardsInfo["Js"] = new Array();
deckOfCardsInfo["Qs"] = new Array();
deckOfCardsInfo["Ks"] = new Array();

deckOfCardsInfo["Ad"] = new Array();
deckOfCardsInfo["2d"] = new Array();
deckOfCardsInfo["3d"] = new Array();
deckOfCardsInfo["4d"] = new Array();
deckOfCardsInfo["5d"] = new Array();
deckOfCardsInfo["6d"] = new Array();
deckOfCardsInfo["7d"] = new Array();
deckOfCardsInfo["8d"] = new Array();
deckOfCardsInfo["9d"] = new Array();
deckOfCardsInfo["Td"] = new Array();
deckOfCardsInfo["Jd"] = new Array();
deckOfCardsInfo["Qd"] = new Array();
deckOfCardsInfo["Kd"] = new Array();

//Clubs

deckOfCardsInfo["Ac"]["alt"] = "Ace of Clubs";
deckOfCardsInfo["Ac"]["path"] = "clubs/Ac"+ImagesType;

deckOfCardsInfo["2c"]["alt"] = "Deuce of Clubs";
deckOfCardsInfo["2c"]["path"] = "clubs/2c"+ImagesType;

deckOfCardsInfo["3c"]["alt"] = "Three of Clubs";
deckOfCardsInfo["3c"]["path"] = "clubs/3c"+ImagesType;

deckOfCardsInfo["4c"]["alt"] = "Four of Clubs";
deckOfCardsInfo["4c"]["path"] = "clubs/4c"+ImagesType;

deckOfCardsInfo["5c"]["alt"] = "Five of Clubs";
deckOfCardsInfo["5c"]["path"] = "clubs/5c"+ImagesType;

deckOfCardsInfo["6c"]["alt"] = "Six of Clubs";
deckOfCardsInfo["6c"]["path"] = "clubs/6c"+ImagesType;

deckOfCardsInfo["7c"]["alt"] = "Seven of Clubs";
deckOfCardsInfo["7c"]["path"] = "clubs/7c"+ImagesType;

deckOfCardsInfo["8c"]["alt"] = "Eight of Clubs";
deckOfCardsInfo["8c"]["path"] = "clubs/8c"+ImagesType;

deckOfCardsInfo["9c"]["alt"] = "Nine of Clubs";
deckOfCardsInfo["9c"]["path"] = "clubs/9c"+ImagesType;

deckOfCardsInfo["Tc"]["alt"] = "Ten of Clubs";
deckOfCardsInfo["Tc"]["path"] = "clubs/Tc"+ImagesType;

deckOfCardsInfo["Jc"]["alt"] = "Jack of Clubs";
deckOfCardsInfo["Jc"]["path"] = "clubs/Jc"+ImagesType;

deckOfCardsInfo["Qc"]["alt"] = "Queen of Clubs";
deckOfCardsInfo["Qc"]["path"] = "clubs/Qc"+ImagesType;

deckOfCardsInfo["Kc"]["alt"] = "King of Clubs";
deckOfCardsInfo["Kc"]["path"] = "clubs/Kc"+ImagesType;

//Hearts

deckOfCardsInfo["Ah"]["alt"] = "Ace of Hearts";
deckOfCardsInfo["Ah"]["path"] = "hearts/Ah"+ImagesType;

deckOfCardsInfo["2h"]["alt"] = "Deuce of Hearts";
deckOfCardsInfo["2h"]["path"] = "hearts/2h"+ImagesType;

deckOfCardsInfo["3h"]["alt"] = "Three of Hearts";
deckOfCardsInfo["3h"]["path"] = "hearts/3h"+ImagesType;

deckOfCardsInfo["4h"]["alt"] = "Four of Hearts";
deckOfCardsInfo["4h"]["path"] = "hearts/4h"+ImagesType;

deckOfCardsInfo["5h"]["alt"] = "Five of Hearts";
deckOfCardsInfo["5h"]["path"] = "hearts/5h"+ImagesType;

deckOfCardsInfo["6h"]["alt"] = "Six of Hearts";
deckOfCardsInfo["6h"]["path"] = "hearts/6h"+ImagesType;

deckOfCardsInfo["7h"]["alt"] = "Seven of Hearts";
deckOfCardsInfo["7h"]["path"] = "hearts/7h"+ImagesType;

deckOfCardsInfo["8h"]["alt"] = "Eight of Hearts";
deckOfCardsInfo["8h"]["path"] = "hearts/8h"+ImagesType;

deckOfCardsInfo["9h"]["alt"] = "Nine of Hearts";
deckOfCardsInfo["9h"]["path"] = "hearts/9h"+ImagesType;

deckOfCardsInfo["Th"]["alt"] = "Ten of Hearts";
deckOfCardsInfo["Th"]["path"] = "hearts/Th"+ImagesType;

deckOfCardsInfo["Jh"]["alt"] = "Jack of Hearts";
deckOfCardsInfo["Jh"]["path"] = "hearts/Jh"+ImagesType;

deckOfCardsInfo["Qh"]["alt"] = "Queen of Hearts";
deckOfCardsInfo["Qh"]["path"] = "hearts/Qh"+ImagesType;

deckOfCardsInfo["Kh"]["alt"] = "King of Hearts";
deckOfCardsInfo["Kh"]["path"] = "hearts/Kh"+ImagesType;

//Spades

deckOfCardsInfo["As"]["alt"] = "Ace of Spades";
deckOfCardsInfo["As"]["path"] = "spades/As"+ImagesType;

deckOfCardsInfo["2s"]["alt"] = "Deuce of Spades";
deckOfCardsInfo["2s"]["path"] = "spades/2s"+ImagesType;

deckOfCardsInfo["3s"]["alt"] = "Three of Spades";
deckOfCardsInfo["3s"]["path"] = "spades/3s"+ImagesType;

deckOfCardsInfo["4s"]["alt"] = "Four of Spades";
deckOfCardsInfo["4s"]["path"] = "spades/4s"+ImagesType;

deckOfCardsInfo["5s"]["alt"] = "Five of Spades";
deckOfCardsInfo["5s"]["path"] = "spades/5s"+ImagesType;

deckOfCardsInfo["6s"]["alt"] = "Six of Spades";
deckOfCardsInfo["6s"]["path"] = "spades/6s"+ImagesType;

deckOfCardsInfo["7s"]["alt"] = "Seven of Spades";
deckOfCardsInfo["7s"]["path"] = "spades/7s"+ImagesType;

deckOfCardsInfo["8s"]["alt"] = "Eight of Spades";
deckOfCardsInfo["8s"]["path"] = "spades/8s"+ImagesType;

deckOfCardsInfo["9s"]["alt"] = "Nine of Spades";
deckOfCardsInfo["9s"]["path"] = "spades/9s"+ImagesType;

deckOfCardsInfo["Ts"]["alt"] = "Ten of Spades";
deckOfCardsInfo["Ts"]["path"] = "spades/Ts"+ImagesType;

deckOfCardsInfo["Js"]["alt"] = "Jack of Spades";
deckOfCardsInfo["Js"]["path"] = "spades/Js"+ImagesType;

deckOfCardsInfo["Qs"]["alt"] = "Queen of Spades";
deckOfCardsInfo["Qs"]["path"] = "spades/Qs"+ImagesType;

deckOfCardsInfo["Ks"]["alt"] = "King of Spades";
deckOfCardsInfo["Ks"]["path"] = "spades/Ks"+ImagesType;

//Diamonds

deckOfCardsInfo["Ad"]["alt"] = "Ace of Diamonds";
deckOfCardsInfo["Ad"]["path"] = "diamonds/Ad"+ImagesType;

deckOfCardsInfo["2d"]["alt"] = "Deuce of Diamonds";
deckOfCardsInfo["2d"]["path"] = "diamonds/2d"+ImagesType;

deckOfCardsInfo["3d"]["alt"] = "Three of Diamonds";
deckOfCardsInfo["3d"]["path"] = "diamonds/3d"+ImagesType;

deckOfCardsInfo["4d"]["alt"] = "Four of Diamonds";
deckOfCardsInfo["4d"]["path"] = "diamonds/4d"+ImagesType;

deckOfCardsInfo["5d"]["alt"] = "Five of Diamonds";
deckOfCardsInfo["5d"]["path"] = "diamonds/5d"+ImagesType;

deckOfCardsInfo["6d"]["alt"] = "Six of Diamonds";
deckOfCardsInfo["6d"]["path"] = "diamonds/6d"+ImagesType;

deckOfCardsInfo["7d"]["alt"] = "Seven of Diamonds";
deckOfCardsInfo["7d"]["path"] = "diamonds/7d"+ImagesType;

deckOfCardsInfo["8d"]["alt"] = "Eight of Diamonds";
deckOfCardsInfo["8d"]["path"] = "diamonds/8d"+ImagesType;

deckOfCardsInfo["9d"]["alt"] = "Nine of Diamonds";
deckOfCardsInfo["9d"]["path"] = "diamonds/9d"+ImagesType;

deckOfCardsInfo["Td"]["alt"] = "Ten of Diamonds";
deckOfCardsInfo["Td"]["path"] = "diamonds/Td"+ImagesType;

deckOfCardsInfo["Jd"]["alt"] = "Jack of Diamonds";
deckOfCardsInfo["Jd"]["path"] = "diamonds/Jd"+ImagesType;

deckOfCardsInfo["Qd"]["alt"] = "Queen of Diamonds";
deckOfCardsInfo["Qd"]["path"] = "diamonds/Qd"+ImagesType;

deckOfCardsInfo["Kd"]["alt"] = "King of Diamonds";
deckOfCardsInfo["Kd"]["path"] = "diamonds/Kd"+ImagesType;


    function CreateQuestion(handNum)
    {
        con.connect("../tools/ajax/horsetool2.aspx","POST","&n="+handNum,CreateQuestionResponse);
    }
    
    function CreateQuestionResponse(txt) 
    {
    
       var str = txt.responseText;
               
       if(str == "n")
       {
        alert("You can't use this tool please contact me : contactus@horsepokerguide.com");
                        document.getElementById('qaBox').innerHTML = "";

            return; 
       }
       else if(str == "x")
       {
        alert("Server has some problem, please contact me : contactus@horsepokerguide.com");
                        document.getElementById('qaBox').innerHTML = "";

            return; 
       }
       
       var spliter = str.split('@');
       
       var okQ = spliter[0];
       var hands = new Array();
       var highLowQ = spliter[2];
       var answers = spliter[3];
                  
            var handsSpliter = spliter[1].split('^');
            
            var numOfHands = 0;
                       
            for(var i = 0 ; i < handsSpliter.length ; i++)
            {
                lastHandsSplit = handsSpliter[i].split(':');
                hands[lastHandsSplit[0]] = lastHandsSplit[1];
                numOfHands++;
            }
            
            //background-image:url(../images/general/horsequizzBG.jpg)
                
            var tableStr = "" +        
            "<table width='550px' border='0' style='font-size:12;overflow:hidden;border:solid 1px #999999;background-repeat:no-repeat;background-image:url(../images/general/bg772.jpg);background-color:#ffffff;text-align:center'>" +
            "<tr>" +
            "<td style='width:20%;height:5px'></td>"+
            "<td style='width:30%'></td>"+
            "<td style='width:30%'></td>"+
            "<td style='width:20%'></td>"+
            "</tr>" +
            "<tr>"+
            "<td style='text-align:center;font-size:16;' colspan='2'>Game : "+cGameName+"</td>"+
            "<td style='text-align:center;font-size:18;' colspan='2'>Score : <span style='color:#008800'><b>"+goodPoints+"</b></span> | <span style='color:#cc0000'><b>"+badPoints+"</b></span></td>"+
            "<tr>"+
            "<td style='text-align:center' colspan='4'>&nbsp;</td>"+
            "</tr>"+
            "</tr>"+
            "<tr>"+
                "<td colspan='2' style='height:30px'>"+
                   "( "+playersName[0]+" )<br /> ";
                  tableStr += DrawHands(hands["H1"]);
                  tableStr += "</td>"+
                "<td colspan='2'>"+
                    "( "+playersName[1]+" )<br />";
                  tableStr += DrawHands(hands["H2"]);
                  tableStr += "</td>"+
                "</td>"+
                "<td colspan='2'></td>"+ //&nbsp;
            "</tr>"+
            "<tr>"+
                "<td></td>"+
                "<td colspan='2' style='height:100px'>"+
                       "( Board )<br />";
                       if(hands["B"] != null)
                       {
                          tableStr += DrawTheBoard(hands["B"]);
                       }
                       
                   tableStr +=  "<br />"+
                "</td>"+
                "<td>&nbsp;</td>"+
            "</tr>"+
            DrawAnswersBlock(highLowQ,numOfHands-1);
            
           tableStr += "<tr>"+
            "<td colspan='4' style='height:40px'>"+
            "<input id='btnCheck' type='button' value='Check' style='width:100px' onclick=CheckAnswer('"+highLowQ+"','"+answers+"') /> <input id='btnNext' type='button' value='Next >>' style='display:none' onclick=javascript:ClickNext() />"+
            "</td>"+
            "</tr>"+
        //    "<tr><td colspan='4'><marquee scrollamount='3'><a target='_blank' href='http://www.horsepokerguide.com/play-horse-poker'>Best Online H.O.R.S.E Poker Room's review</a></marquee></td></tr>"+
            "</table>";
            
                    
            document.getElementById('qaBox').innerHTML = tableStr;
    }
    
    function CheckAnswer(hlq,answers)
    {
        document.getElementById('btnNext').style.display = "inline";
        document.getElementById('btnCheck').disabled="disabled";
        highAns = "";
        lowAns = "";
        
        HighRight = false;
        lowRight = false; 
        
        if(hlq == "y")
        {
            answersArr = answers.split(':');
            highAns = answersArr[0];
            lowAns = answersArr[1];
            
            CheckHighAns(highAns);
            CheckLowAns(lowAns);
            
        }
        else if(hlq == "n")
        {
            highAns = answers;
            CheckHighAns(highAns);
        }
        
        function CheckHighAns(num)
        {
            var blnSomething = false;
        
            var radioArr = document.getElementsByName('HighHandRadios');
            
            for(var i = 0 ; (i < radioArr.length) && (blnSomething==false); i++)
            {
                if(document.getElementsByName('HighHandRadios')[i].checked)
                {
                    blnSomething = true;
                    if( (i+1) == num )
                    {
                          document.getElementById('tdHighAnswerCheck').innerHTML = "<img src='"+rightAnswerImageSrc+"' />";                
                          goodPoints += 1;
                    }
                    else
                    {
                          document.getElementById('tdHighAnswerCheck').innerHTML =  "<img src='"+wrongAnswerImageSrc+"' />";
                          badPoints += 1;
                    }
                }    
            }
            
        }
        
        function CheckLowAns(num)
        {
            var blnSomething = false;
        
            var radioArr = document.getElementsByName('LowHandRadios');
            
            for(var i = 0 ; (i < radioArr.length) && (blnSomething==false); i++)
            {
                if(document.getElementsByName('LowHandRadios')[i].checked)
                {
                    blnSomething = true;
                    if( (i+1) == num )
                    {
                          document.getElementById('tdLowAnswerCheck').innerHTML = "<img src='"+rightAnswerImageSrc+"' />";                
                          goodPoints += 1;

                    }
                    else
                    {
                          document.getElementById('tdLowAnswerCheck').innerHTML =  "<img src='"+wrongAnswerImageSrc+"' />";
                          badPoints += 1;
                    }
                }    
            }
        }
    }    

   function DrawAnswersBlock(lowQ,numberOfHands)
   {
        retStr = "<tr>"+             
        "<td colspan='2' style='text-align:left;padding-left:50px;height:120px'>"+
        "Who has the winning hand ? <br />"+
        "<table>"+
            "<tr>"+
                "<td style='width:50%'>";
                
                for (var i = 0 ; i < numberOfHands ; i++)
                {
                  retStr += "<input id='highRadio"+(i+1)+"' type='radio' name='HighHandRadios' /><span style='font-size:12'> "+playersName[i]+"</span> .<br />";
                }
                retStr += "<input id='highRadioTie' type='radio' name='HighHandRadios' /><span style='font-size:12'> Tie .</span><br />"+
               "<div>&nbsp;</div>" +
               "</td>" +
                "<td id='tdHighAnswerCheck' style='width:50%;text-align:center;vertical-align:middle'>" +
                "</td>"+
           "</tr>"+
        "</table>"+
        "</td>";
        
        if(lowQ == "y")
        {
             retStr += "<td colspan='2' style='text-align:left;padding-left:50px'>" +
            "Who has the best low hand ? <br />"+
            "<table>"+
                "<tr>"+
                    "<td style='width:50%'>";
                for (var i = 0 ; i < numberOfHands ; i++)
                {
                  retStr += "<input id='lowRadio"+(i+1)+"' type='radio' name='LowHandRadios' /><span style='font-size:12'> "+playersName[i]+" .</span><br />";
                }
              
               retStr += "<input id='lowRadioTie' type='radio' name='LowHandRadios' /><span style='font-size:12'> Tie .</span><br />"  +
               "<input id='lowRadioNoLow' type='radio' name='LowHandRadios' /><span style='font-size:12'> No one.</span><br />" +
               "</td>" +
                    "<td id='tdLowAnswerCheck' style='width:50%;text-align:center;vertical-align:middle'>"+
                    "</td>"+
                "</tr>"+
            "</table>";
        }

           return "</td></tr>"+retStr;
   }
   
   function DrawHands(txt)
   {
      var strRet = "";  
   
      var spliter = txt.split('-');
      
      for(var i = 0 ; i < spliter.length ; i++)
      {
        strRet += "<img style='height:35px;width:25px' alt='"+deckOfCardsInfo[spliter[i]]["alt"]+"' src='"+fullImagesPath+"/"+deckOfCardsInfo[spliter[i]]["path"]+"' />";      
      }
    
       return strRet;            
    }
    
   function DrawTheBoard(txt)
   {
      var strRet = "";  
   
      var spliter = txt.split('-');
      
      for(var i = 0 ; i < spliter.length ; i++)
      {
        if(spliter[i] != "x")
            strRet += "<img style='height:35px;width:25px' alt='"+deckOfCardsInfo[spliter[i]]["alt"]+"' src='"+fullImagesPath+"/"+deckOfCardsInfo[spliter[i]]["path"]+"' />"; 
      }
    
       return strRet;            
    }
    
    function ClickNext()
    {     
      if(qNum < 20)
        qNum += 1 ;
      else
      {
         if(qNum == 20)
            alert("You just finished the quizz \r\n \r\n Result : \r\n Good Answers : "+goodPoints+" \r\n Wrong Answers : "+badPoints+"  ");
            qNum = 1;
            badPoints = 0;
            goodPoints = 0;
         
      }
         
      var hand = (qNum % 5);
      
      if(hand == 1)
      {
          cGameName = "Texas Hold'em";
          
          if(qNum != 1)
          {
            alert("You just finished a full round. Going back to Texas Hold'em");
          }
      }
      else if(hand == 2)
          cGameName = "Omaha High Low";
      else if(hand == 3)
          cGameName = "Razz";
      else if(hand == 4)
          cGameName = "Seven Card";
      else if(hand == 0)
          cGameName = "Seven Card High Low";
                CreateQuestion(qNum);

    }
   
   ClickNext();
