// JavaScript Document
function checkCardSelected(card, hand) { //validate card played
	firstcard = playhand[(firstplayer-1)]; //set a temp var to the first card played
	if (currentplayer == firstplayer) { //check to see if its the first card played, if it is, anything goes
		//document.getElementById('topdialogbox').innerHTML = "first";
		return true;
	} else if (card == "12"+trumpalt) {
		if (firstcard.substr(2,1) == trump) {
			//document.getElementById('topdialogbox').innerHTML = "left";
			return true;
		} else {
			checksuit = checkHandforSuit(parseFloat(hand+1),firstcard);
			if (checksuit == true) {
				//document.getElementById('topdialogbox').innerHTML = "threw left but ok";
				return true;
			} else if (checksuit == false) {
				//document.getElementById('topdialogbox').innerHTML = "left no go";
				return false;
			}
		}
	} else if (firstcard == "12"+trumpalt) {
		if (card.substr(2,1) == trump) {
			//document.getElementById('topdialogbox').innerHTML = "follow";
			return true;
		} else {
			checksuit = checkHandforSuit(parseFloat(hand+1),("12"+trump));
			if (checksuit == true) {
				//document.getElementById('topdialogbox').innerHTML = "left started, but ok";
				return true;
			} else if (checksuit == false) {
				document.getElementById('topdialogbox').innerHTML = "must throw trump";
				return false;
			}	
		}	
	} else if (card.substr(2,1) == firstcard.substr(2,1)) {
		//document.getElementById('topdialogbox').innerHTML = "follow";
		return true;
	} else {
		checksuit = checkHandforSuit(parseFloat(hand+1),firstcard); //it doesnt match so search to see if the card played is valid
		
		if (checksuit == true) {
			//document.getElementById('topdialogbox').innerHTML = "no follow but ok";
			return true;
		} else if (checksuit == false) {
			document.getElementById('topdialogbox').innerHTML = "you must follow suit";
			return false;
		}
	}
}
function checkHandforSuit(hand, card) {
	if (card == "12"+trumpalt) {
		suit = trump;
	} else {
		suit = parseFloat(card.substr(2,1));
	}
	for (i=0; i<= 4; i++) {
		temp = window["hand"+hand][i];
		if (temp == "12"+trumpalt && suit == trump) {
			return false;
		}
		if (parseFloat(temp.substr(2,1)) == suit) {
			if (temp == "12"+trumpalt) {
				return true;
			} 
			return false;
		}
	}
	return true;	
}