google_ad_client = "pub-0327288835676005";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_channel ="8109295118";
google_ad_type = "text_image";
google_page_url = document.location;



var spacerImg = '<img src="http://hangman.shawnolson.net/media/hangman_clue_space.gif">';
var spacerImg2 = '<IMG src="http://hangman.shawnolson.net/media/hangman_clue_space.gif">';

 var wins=0;
 var losses=0;
 var emptyGallow;
 var gameList = new Array();
 gameList[1] = true;
 var inv = 'Invalid';
 var start = 1;
 var games = 1;
 
 var gamesArray = new Array();
 gamesArray[0] = 1;
   var spacerOutput = '__ ';
   var restrictWord = new Array('fuck', 'bitch', 'asshole', 'whore', ' slut', 'queer', 'rapist', ' shit ', 'blowjob', ' fag ', 'rogaine', 'viagra', 'levitra', 'vi@gra', 'viagr@', 'vi@gr@', ' penis', ' cialis');
   
   
function Hangman(phrase,clue,game){
     
	 this.head=false;
	 this.body=false;
	 this.leftArm=false;
	 this.rightArm=false;
	 this.rightLeg=false;
	 this.leftLeg=false;
	 
	 this.phrase = phrase;
     this.clue = clue;
	 this.game = game;

	 
	 this.phraseArray = new Array()

	 this.guesses = new Array();
	 
	 this.doesitexist = doesitexist;
	 this.setUnderscores = setUnderscores;
	 this.setVars = setVars;
     this.checkLetter = checkLetter;
	 this.badAnswer = badAnswer;
	 this.submitGuess = submitGuess;
	 this.showClues = showClues;
	 this.haveIGuessedThis = haveIGuessedThis;
	 this.GameForm = GameForm;
   }  
   
   

function GameForm(){

  form = "<div id=\"gameBox"+this.game+"\" style=\"display: block; margin-top: 15px\"><fieldset><legend>Phrase "+this.game+" Values</legend><label for=\"phrase"+this.game+"\">Winning Phrase </label><input type=\"text\" id=\"phrase"+this.game+"\" name=\"phrase"+this.game+"\" value=\""+this.phrase+"\" maxlength=\"96\" title=\"Enter a Winning Phrase for your Hangman Game.\" style=\"width:100%\"/><br/><label for=\"clue"+this.game+"\">Clue </label><input type=\"text\" id=\"clue"+this.game+"\" name=\"clue"+this.game+"\" value=\""+this.clue+"\" maxlength=\"96\" title=\"Enter a clue for your Hangman Game.\" style=\"width:100%\"/><br/><input type=\"button\" onclick=\"removeGame("+this.game+")\" value=\"Remove This Game\"/></fieldset></div>";

   document.getElementById("extraGames").innerHTML += form;
   document.getElementById("games").value +=','+this.game;
   gameList[this.game]=true;

}
   

   
   function checkLetter(){}   
   
   
   function setVars(){
     this.head=false;
	 this.body=false;
	 this.leftArm=false;
	 this.rightArm=false;
	 this.rightLeg=false;
	 this.leftLeg=false;
	 this.guesses = new Array();
      document.getElementById("yourClue").innerHTML = this.clue;
	  this.setUnderscores();
   }
   
   
   function setUnderscores(){
      theDisplay = '';

	  for(var x=0;x<this.phrase.length;x++){
	     if(this.phrase.substring(x,x+1)==' '){
		    theDisplay += spacerImg;
		 } else {theDisplay += spacerOutput;}
	  
	  }
	  document.getElementById("hangmanClues").innerHTML = theDisplay;

   }
   
   
   
   function replaceAll(thestring,thechop,replacement){
      
      while (thestring.search(thechop)!= -1){
	    thestring = thestring.replace(thechop,replacement);
		 
	  } 
   
     return thestring;
   }
   
    function checkForWin(){
      

	  var guessesstring = document.getElementById("hangmanClues").innerHTML;
		guessesstring = guessesstring.toLowerCase();
	    guessesstring= replaceAll(guessesstring,spacerImg,' ');
		guessesstring= replaceAll(guessesstring,spacerImg2,' ');
		guessesstring= replaceAll(guessesstring,spacerOutput,'');
	  if(guessesstring.length==hangman.phrase.length){
		return true;
	  } else {return false;}

      
   }
   
   
   function haveIGuessedThis(guess,change){
      
   	  for(var x=0;x<this.guesses.length;x++){
	    word = this.guesses[x];
        if(word.toLowerCase() == guess.toLowerCase()){
		 return true;
		 exit;
		}
	  
	  }
	  if(change==true){
	    this.guesses.push(guess);
	    document.getElementById("hangmanGuesses").innerHTML += guess;
	  }
      return false;
   }
   
   function submitGuess(guess){
      if(this.haveIGuessedThis(guess.toLowerCase(),true)==false){
         if(this.doesitexist(guess)){
		   document.getElementById("hangmanComments").innerHTML = 'You Found One!';
	       this.showClues(guess);
		   if(checkForWin()==true){
		     wongame();
		   }
	     } else {this.badAnswer();}
      } else {document.getElementById("hangmanComments").innerHTML='You have <i>already</i> guessed <b>'+guess+'</b>';}
   
   }
   
   
   
   function badAnswer(){
	 thephrase = 'Uh Oh! ';
	 if(this.head == false){
	    thephrase+= ' Do not be so quick to lose your head!';
	    document.getElementById("hangmanhead").src = 'http://hangman.shawnolson.net/media/headHung.gif';
		document.getElementById("hangmanhead").alt = 'Hung';
		this.head = true;
	 } else {
	   if(this.body == false){
	    thephrase+= ' You are about to have a broken heart!';
	    document.getElementById("body").src = 'http://hangman.shawnolson.net/media/bodyHung.gif';
		document.getElementById("body").alt = 'Broken Heart';
		this.body = true;
	   } else {
	     if(this.leftArm == false){
	       thephrase+= ' You better get a splint!';
	       document.getElementById("leftArm").src = 'http://hangman.shawnolson.net/media/leftArmHung.gif';
		   document.getElementById("leftArm").alt = 'Broken Arm';
		   this.leftArm = true;
	     } else {
	       if(this.rightArm == false){
	         thephrase+= ' You better get another splint!';
	         document.getElementById("rightArm").src = 'http://hangman.shawnolson.net/media/rightArmHung.gif';
		     document.getElementById("rightArm").alt = 'Broken Arm';
		     this.rightArm = true;
	       } else {
		 
		   if(this.leftLeg == false){
	         thephrase+= ' You have one leg in the grave, Pal!';
	         document.getElementById("leftLeg").src = 'http://hangman.shawnolson.net/media/leftLegHung.gif';
		     document.getElementById("leftLeg").alt = 'Broken Leg';
		     this.leftLeg = true;
	       } else {
		   
		     if(this.rightLeg == false){
	         thephrase= 'Looks like you got hung. Game Over.<br/><br/>Consider making <b>Your Own</b> hangman page at <a href="http://hangman.shawnolson.net/hangman.php">http://hangman.shawnolson.net/hangman.php</a>.';
	         document.getElementById("rightLeg").src = 'http://hangman.shawnolson.net/media/rightLegHung.gif';
		     document.getElementById("rightLeg").alt = 'Broken Leg';
		     this.rightLeg = true;
			 document.getElementById("gallows").innerHTML=emptyGallow;
			 losses++;
			 if(this.game != gameList.length-1){
			 startGame();} else {alert('Game Over.')}
	       }
		   
		   }
		 
		 }
		 
		 
		 }
	   }
	 }
	 
    document.getElementById("hangmanComments").innerHTML = thephrase;
   }
   
   function doesitexist(guess){
 
     for(var x=0;x<this.phrase.length;x++){
	     if(this.phrase.substring(x,x+1).toLowerCase()==guess.toLowerCase()){
		    return true;
		 } 
	  
	  }
      return false;
   
   }
   
   
   function showClues(clue){
      theDisplay = '';
	  for(var x=0;x<this.phrase.length;x++){
	     if(this.phrase.substring(x,x+1)==' '){
		    theDisplay += spacerImg;
		 } else {
		   if(this.phrase.substring(x,x+1).toLowerCase()==clue.toLowerCase()){
		    theDisplay+=clue;
		   } else {
		     if(this.haveIGuessedThis(this.phrase.substring(x,x+1).toLowerCase(), false)==true){
			    theDisplay+=this.phrase.substring(x,x+1);
			 } else {theDisplay+=spacerOutput;}
		   
		   }
		 }
	  
	  }
	  document.getElementById("hangmanClues").innerHTML = theDisplay;
   
   }
function removeGame(id){
 if(id!=''){
   string = 'document.getElementById("gameBox'+id+'").innerHTML = ""; document.getElementById("gameBox'+id+'").style.display="none";';
   eval(string);
 }
 gameList[id]=false;
 removerGameArrayId(id);
}

function removerGameArrayId(id){
 var tempArray = new Array();
 for (var i = 0; i<gameList.length; i++){
   if (gameList[i] == true){
     tempArray.push(gameList[i]);
   }

 }
 gamesList = tempArray;
 //games = gamesArray.length;
 formVars();
}

function formVars(){
 var sendIds = '1';
 for (var i = 2; i<gameList.length; i++){
   if (gameList[i]==true){
      sendIds+=','+i;

   }
 }
 document.getElementById("games").value = sendIds;

}
 
function startGame(){

  document.getElementById("hangmanGuesses").innerHTML = '';
  hangman.phrase = gameList[start][0];
  hangman.clue = gameList[start][1];
  hangman.game = gameList[start][2];

  if(hangman.game == ''){start++; startGame(); return;} else {
    hangman.setVars();
	start++;
  }
  if(emptyGallow != null){
    document.getElementById("gallows").innerHTML = emptyGallow;
  }
  
}

function wongame(){
  wins++;
  message = 'You Won!';
  if(wins+losses+1==gameList.length){
    message+=' You have completed all the games. You Won '+wins+' Times and Lost '+losses+' Times.';
    document.getElementById("hangmanComments").innerHTML = '<a href="javascript:document.location=document.location.href">Click Here</a> to play again. <br/><br/><h2>Or...</h2><p>Make your own <a href="http://hangman.shawnolson.net/hangman.php">Hangman Games</a>!</p>';
  } else {
    message+=' Next Round...';
  
     startGame();
  }
  	alert(message);
}

function keyguess(e) {
  if (e.keyCode) {keycode=e.keyCode;}
  else {keycode=e.which;}
   var thestring = String.fromCharCode(keycode);
   return thestring;
}

function makeForm(){}

function requiredFields(formObj){

 var bandMessage='';
 var errors = 0;


  for(x=0;x<gameList.length;x++){
     if (gameList[x]==true){
	 string = 'if(formObj.phrase'+x+'){errors = errors + changeVal(formObj.phrase'+x+',true,true);}';
     eval(string);
    }
  }

   if (errors==0){
      formObj.submit();
  }
  
  if (errors >0){
    alert("There are errors on your form... please verify the information. Fields with red text or the word 'Invalid' must be filled out."+bandMessage+'');
    return;
  }
}

function changeVal(formObj,need,bad){

 var FnameTest = true;
 var errors;
 errors = 0;
 
 if(need==true){
  if (formObj.value=='' || formObj.value == inv){ 
   FnameTest = false;
   formObj.value = inv;
  }
 }  
  
 if(bad==true){
   badword = badWords(formObj.value);
  if (badword == true){
   FnameTest = false;
  }
 }
 
 if (FnameTest == false){
   formObj.style.color = "red";
   errors = 1;
 }
 if (FnameTest == true){
   formObj.style.color = "black";
 }

return errors;
}



function badWords(word){
//this function keeps new members from choosing inappropriate names

var badword = false;
var word = new String(word);
word = word.toLowerCase();

 for (var i = 0; i<restrictWord.length; i++){
  if (word.match(restrictWord[i])){

  badword = true;
  alert("A label you chose is inappropriate for this site. Please be considerate and remember that this is a professional site.");
  }
 }
 return badword;
}

function createGameForm(){
  games++;
  
  //gamesArray.push(games);
  var string = 'hangman'+games+' = new Hangman("","","'+games+'");\r\nhangman'+games+'.game='+games+'; hangman'+games+'.GameForm();';

  eval(string);
  gamesArray.push(games);
  formVars();

}



function showGameVars(){

  message = 'Game Stats:\r\nGames='+gamesArray.length+'\r\nSendIDs='+document.getElementById("games").value+';\r\nGameListLength: '+gameList.length+'';

alert(message);

}

function setPageVars(){
  emptyGallow = document.getElementById("gallows").innerHTML;
  

}

var hangman = new Hangman("","","");