
//////////////////////////////
// form handling

function setSelectedIndex(list, value){
   for(i=0; i<list.length; i++){
      if(list[ i].value == value){
         list.selectedIndex = i;
         break;
      }   
   }
}

function textCounter(textarea, counterID, maxLen) {
	cnt = document.getElementById(counterID);
	if (textarea.value.length > maxLen){
		textarea.value = textarea.value.substring(0,maxLen);
	}
	cnt.innerHTML = maxLen - textarea.value.length;
}


//////////////////////////////
// form specific

function checkJoinForm(){

	if(document.joinform.uname.value==''){
		alert('Please fill in your desired name, then submit the form.\\n\(Letters, numbers, and spaces ONLY\)');
		document.joinform.uname.focus();
		return false;
	}


	////////////////////////
	if(document.joinform.mail.value==''){
		alert('Please fill your email address.');
		document.joinform.mail.focus();
		return false;
	}

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.joinform.mail.value;
   if(reg.test(address) == false) {
      alert('This doesn\'t appear to be a valid email address.\nPlease correct it, then submit the form again.');
		document.joinform.mail.focus();
      return false;
   }


	if(document.joinform.cap_text.value==''){
		alert('Please fill anti-spam word, then submit the form.');
		document.joinform.cap_text.focus();
		return false;
	}
}

/////////////

function checkMoveForm(){
	if(document.getElementById('dest').value == ''){
		alert('Pick a city to move your crew to, fool.');
		return false;
	}

	if(document.getElementById('moveall').checked == false && document.getElementById('tmove').value== '' && document.getElementById('hmove').value== ''){
		alert('You got to move SOME hoes or SOME Thugs, fool.');
		return false;
	}
}

function moveAll(){
	if(document.getElementById('moveall').checked == true){
		document.getElementById('tmove').value = '$thugs';
		document.getElementById('hmove').value = '$hoes';
		document.getElementById('tmove').disabled = true;
		document.getElementById('hmove').disabled = true;
	}else{
		document.getElementById('tmove').disabled = false;
		document.getElementById('hmove').disabled = false;
	}
}

/////////////

function confirmClearArchive(){
var agree=confirm("Are you sure you want to clear the Previous Rounds archive?");
  if(agree){
       return true;
  }else{
       return false;
  }
}

/////////////

function confirmDelete(){
var agree=confirm("Are you sure you want to delete this message?");
  if(agree){
       return true;
  }else{
       return false;
  }
}

/////////////
function checkMailForm(){
	if(document.getElementById('recipient').value == ''){
		alert('You need to select a pimp to send a message to.');
		document.getElementById('recipient').style.backgroundColor='#ffff00';
		return false;
	}

	if(document.getElementById('msg_text').value == ''){
		alert('You can\'t send an empty message, fool.');
		document.getElementById('msg_text').focus();
		return false;
	}

}


/////////////
// gang mail
function checkGangMailForm(){
	if(document.getElementById('gangmailtxt').value == ''){
		alert('You can\'t send an empty message, fool.');
		document.getElementById('gangmailtxt').focus();
		return false;
	}
}


/////////////
function checkSalesForm(){
	if(document.getElementById('sellbeer').value=='' && document.getElementById('sellcondoms').value=='' && document.getElementById('sellcrack').value=='' && document.getElementById('sellweed').value=='' && document.getElementById('sellguns').value=='' && document.getElementById('sellthugs').value=='' && document.getElementById('selllowriders').value==''){
		alert('Enter something to sell, fool.');
		return false;
	}
}

function clearAll(){
	document.getElementById('buybeer').value='';
	document.getElementById('buycondoms').value='';
	document.getElementById('buycrack').value='';
	document.getElementById('buyweed').value='';
	document.getElementById('buyguns').value='';
	document.getElementById('buythugs').value='';
	document.getElementById('buylowriders').value='';
}


/////////////
function checkRemove(){
var agree=confirm("Are you sure you want to remove this pimp from the gang?");
  if(agree){
       return true;
  }else{
       return false;
  }
}
/////
function checkAddCoLeader(){
var agree=confirm("Assign this pimp as the Co-Leader of the gang?");
  if(agree){
       return true;
  }else{
       return false;
  }
}
/////
function checkDisband(){
var agree=confirm("Are you sure you want to disband the gang?");
  if(agree){
       return true;
  }else{
       return false;
  }
}

/////////////
function checkAttackType(){
	// require at least one radio button be selected
	var radioSelected = false;
	for (i = 0;  i < document.attackform.attacktype.length;  i++){
		if (document.attackform.attacktype[i].checked)
		radioSelected = true;
	}
	if (!radioSelected){
		alert("Please select an 'Attack Type' before attacking.");
		return false;
	}
}

/////////////
function checkCrackForm(cturns){
	if(cturns == '' || cturns < 1 || cturns > 100){
		alert('To make crack, enter a number between 1 and 100.');
		document.getElementById('crackturns').focus();
		document.getElementById('crackturns').style.backgroundColor='#ffffbb';
		return false;
	}
}

function checkMugForm(mturns){
	if(mturns == '' || mturns < 1 || mturns > 100){
		alert('To mug people, enter a number between 1 and 100.');
		document.getElementById('mugturns').focus();
		document.getElementById('mugturns').style.backgroundColor='#ffffbb';
		return false;
	}
}

function showChance(stype){
	if(stype == ''){
		document.getElementById('pctspan').innerHTML = '?????';
		//document.getElementById('pctspan').style.backgroundColor = '#$color1';
	}
	if(stype == 'mini'){
		document.getElementById('pctspan').innerHTML = '$rob_chances[0]&#37;';
		//document.getElementById('pctspan').style.backgroundColor = '#$color1';
	}
	if(stype == 'liquor'){
		document.getElementById('pctspan').innerHTML = '$rob_chances[1]&#37;';
		//document.getElementById('pctspan').style.backgroundColor = '#$color2';
	}
	if(stype == 'jewelry'){
		document.getElementById('pctspan').innerHTML = '$rob_chances[2]&#37;';
		//document.getElementById('pctspan').style.backgroundColor = '#$color3';
	}
	if(stype == 'bank'){
		document.getElementById('pctspan').innerHTML = '$rob_chances[3]&#37;';
		//document.getElementById('pctspan').style.backgroundColor = '#$color4';
	}
}

/////////////
