var firstLoad = true;
var boolReset = false;

function showCheck(chk,ctry,ctryDiv,zip) {
	if (document.getElementById(chk)){
  	  var checkBox = document.getElementById(chk);
  	  var inptZipVal = document.getElementById(zip);
      var otherText = document.getElementById(ctry); 
      var theCountryDiv = document.getElementById(ctryDiv); 

	  if (firstLoad == true) {
	  	if (checkBox.checked == true || inptZipVal.value == "00000") {
	  		checkBox.checked = true;
	  		otherText.disabled=false;
				otherText.value='';
				
				// toggle Right Now chat button position, if applicable
				if(document.getElementById('rightNow')){
					document.getElementById('rightNow').className = "rightNowShiftDown";
				}
	  		otherText.style.display = "block";
				theCountryDiv.style.display = "block";
			
			if(inptZipVal.value == "00000"){
				inptZipVal.value = ''
				boolReset = true;
			}
			otherText.focus();
			
		}
		firstLoad = false;
		}
		else {
		    firstLoad = false;
			if(otherText.disabled){
					otherText.disabled=false;
					otherText.value='';
					if(document.getElementById('rightNow')){
						document.getElementById('rightNow').className = "rightNowShiftDown";
					}
					otherText.style.display = "block";
					theCountryDiv.style.display = "block";
					checkBox.blur();
					otherText.focus();
				}
				else{
					otherText.disabled=true;
					if(document.getElementById('rightNow')){
						document.getElementById('rightNow').className = "rightNowStd";
					}
					otherText.style.display = "none";
					otherText.value=null;
					theCountryDiv.style.display = "none";
					checkBox.blur();
					}
		}
		doCheck(chk,zip);
  }
}

function doCheck(chk,zip) {
	if (document.getElementById(chk)){
		var billZip = document.getElementById(zip);
		var checkBox = document.getElementById(chk);
		if (checkBox.checked) {
			billZip.value="";
			billZip.disabled = true;
			billZip.style.background = "#D4D0C8";
		  }
		else {
			billZip.disabled = false;
			billZip.style.background = "#FFFFFF";			
			}
	}
}

function validateSubmit(zip) {
	if(document.getElementById(zip).disabled || boolReset){
		document.getElementById(zip).disabled = false;
		document.getElementById(zip).value = "00000";
		}
		return true;
}

var zipBox = null;
function evalCheck(objCheck, objZip){
	zipBox = document.getElementById(objZip);
	if(objCheck.checked){
		zipBox.disabled = true;
		zipBox.value = "00000";
	}else {
	zipBox.value = "";
	zipBox.disabled = false;
	zipBox.focus();
	}
}
function enableState(zip){
	document.getElementById(zip).disabled = false;
	return true;
}