/******************************
*  MoviesAtWork Functions     *  
*******************************/

/**
* Process a click of the alphabar when looking for an item to rent
* @param string startLetter letter of the alphabet to find movies names starting with
* @return boolean
*/
function alphaBarClick(startLetter) {
  document.alphaBar.asset_name.value = startLetter;
  document.alphaBar.submit();
  return false;
}
/**
* highlight selected header tab 
*/
function highlight_tab(navItem) {
  if (navItem.length > 0) {
    myElement = document.getElementById(navItem);
    myElement.className = "nav1On";
  }                  
}
/**
* highlight selected left navigation item 
*/
function highlight_nav(navItem) {
  if (navItem.length > 0) {
    myElement = document.getElementById(navItem);
    myElement.className = "leftNavOn";
  }                  
}
/**
* submit a form 
* @param string formName name of form to be submitted
* @param string command optional parameter to modify the value of a hidden field called 'cmd', which represents the
* action to be taken
* @param string method GET or POST to submit the form
* @return boolean
*/
function submitForm(formName,command,method) {
  if(command){
    document.forms[formName].elements["cmd"].value = command;
  }
  if(method){
    document.forms[formName].method = method;
  }
  document.forms[formName].submit();
  return false;
}
/**
* submit the generic site search form 
* @return boolean
*/
function submitHdrSearch(siteRoot) {
  var formName = 'searchSite';
  var searchType = document.forms[formName].elements["searchType"].value;
  switch (searchType){
  case 'Books':
  case 'DVD':
  case 'Music':
  case 'VHS':
  case 'VideoGames':
    document.forms[formName].action = siteRoot + searchType + '/index.php';
    document.forms[formName].elements["cmd"].value = 'list';
    document.forms[formName].elements["searchText"].name = 'asset_name';
    break;
  case 'member_last_name':
    document.forms[formName].action = siteRoot + 'members/index.php';
    document.forms[formName].elements["cmd"].value = 'main';
    document.forms[formName].elements["searchText"].name = 'srch_last_name';
    break;  
  case 'member_login':
    document.forms[formName].action = siteRoot + 'members/index.php';
    document.forms[formName].elements["cmd"].value = 'main';
    document.forms[formName].elements["searchText"].name = 'srch_login';
    break;  
  }
  document.forms[formName].submit();
  return false;
}
/**
* check if the enter key has been pressed in an input field and submit form 
* @param string formName name of form to be submitted
* @param string command optional parameter to modify the value of a hidden field called 'cmd', which represents the
* action to be taken
*/
function checkForEnter(evt,formName,command) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13) {
    if(command){
      document.forms[formName].elements["cmd"].value = command;
    }    
    document.forms[formName].submit();
		return false;
	}
	return true;
}
/**
* only allows one checkbox to be selected at a time
* @param object form The form object
* @param int ref Checkbox sequence number
* @param string checkboxName Optional parameter to pass the name of the checkbox control
*/
function pickOneChkBox(myForm,ref,checkboxName) {
  //if checkboxName has not been passed set it to ticks[], which is used in 90% of cases
  if(!checkboxName) {
    checkboxName = "ticks[]";
  }
  //if required parameters have not been passed then return
  if(!myForm){
    return;
  } 
  var tickCount = myForm.elements[checkboxName].length;
  //tickCount is undefined when only one row in result set. No need to continue for one row so return
  if(!tickCount) {
    return;
  }
  //remember if the user is trying to tick or untick a checkbox
  var setToValue = myForm.elements[checkboxName][ref].checked;
  //loop through all checkboxes and reset checked property
  for (var i = 0; i < tickCount; i++) {
    myForm.elements[checkboxName][i].checked = false;
  }
  //set the value of the current checkbox as requested by the user
  myForm.elements[checkboxName][ref].checked = setToValue;
  return;
}

