/////////////////////////////////////////////////
// Function to show or hide a block of HTML
// Example: <a href="javascript:void(0)" onclick="showHide('myElement');">Toggle me</a>
//   ...
//   <tbody id="myElement" style="display: none;">     would initially hide this element
//   <tr>
//     <td>
//       Content to hide
//     </td>
//   </tr>
//   </tbody>
//
function showHide(thisID) {
  var thisElement = document.getElementById(thisID);
  
  if( thisElement.style.display == "none")
    thisElement.style.display = "";
  else
    thisElement.style.display = "none"
}

function hideElement(thisID) {
  var thisElement = document.getElementById(thisID);

  thisElement.style.display = "none"
}

function showElement(thisID) {
  var thisElement = document.getElementById(thisID);
  
  thisElement.style.display = "";
}

function disableElement(thisID) {
  var thisElement = document.getElementById(thisID);
  
  thisElement.disabled = true;
}

function valueElement(thisID, newvalue) {
  var thisElement = document.getElementById(thisID);
  
  thisElement.value = newvalue;
}


/////////////////////////////////////////////////
// Function to Add rows to a textArea
// Example: <a href="##" onClick="addTextAreaRow('textarea1',2);">Add rows</a>
//
function addTextAreaRow(thisID,rowsToAdd) {
  var thisElement = document.getElementById(thisID);
  thisElement.rows = thisElement.rows + rowsToAdd;
}


/////////////////////////////////////////////////
// Function to clear a form element when user clicks on it if it matches the default text, erasing the default text
// Example: <input type="text" value="Required" onFocus="clearDefault(this,'Required');">
//
function clearDefault(el,defaultText) {
	if (el.defaultValue==el.value || el.value==defaultText) el.value = ""
}

/////////////////////////////////////////////////
// Function to add a new option in an HTML <select> form element
// Example: <a href="javascript:void(0)" onclick="addNewOption('howContacted_0_11','Add new Location',0)">add</a>
//  <cfset thisJSID = replace(createUUID(),'-','','all')>  then id="#thisJSID#" 
//
function addNewOption(thisID, promptText,position){

  var thisElement = document.getElementById(thisID);
  var tempvar = prompt(promptText,"");

  if (tempvar != null && tempvar != 'undefined') {
   myList = document.getElementById('prefix');
   thisElement.options.add(new Option(tempvar, tempvar), position);
   thisElement.selectedIndex = position;
   thisElement.value = tempvar;
  }  
}

var submitcount=0;

function checkFields() {            
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert("Please wait... This form has already been submitted and is being processed. Thanks You.");
      return false;
      }
}

function popUp(URL,w,h) {
    winl = (screen.width - w) / 2;
    wint = (screen.height - h) / 2;

    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",top="+wint+",left="+winl+"');");
}
    
//http://www.mediacollege.com/internet/javascript/form/limit-characters.html
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function limitTextNotEnfoced(limitField, limitCount, limitNum) {
  limitCount.value = limitNum - limitField.value.length;
  if (limitCount.value < 0) {
    limitCount.style.backgroundColor = 'red';
    limitCount.style.color = 'white';
    limitCount.style.fontWeight = 'bold';
  }
  else if (limitCount.value < 7) {
    limitCount.style.backgroundColor = 'yellow';
    limitCount.style.color = 'black';
    limitCount.style.fontWeight = 'normal';
  }
  else {
    limitCount.style.backgroundColor = 'white';
    limitCount.style.color = 'black';
    limitCount.style.fontWeight = 'normal';
  }
   
}
