// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//  	Submit Form
//		Used to submit the search results form using javascript 
//		Parameters
//		formID					String				The ID of the form to be submitted

function submitForm(formID) {
	if (formID == 'repselect') 
		document.getElementById('COMPLETE_THIS_ORDER').value = "true";
	document.getElementById(formID).submit() ;
}

// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Activate or deactivate all buttons for hard copies
// Parameters
// checkbox				Obj			The checkbox which will check or uncheck all the others
// formID					Str			The ID of the form whose checkboxes are to be checked or unchecked
// prefix						Str			The first three letters of the IDs of every checkbox to be checked or unchecked by this function
function allActive(checkbox, formID, prefix) {

	var objForm = document.getElementById(formID);
	var objCurrentBox;
	var strCurrentBoxName = new String();
		
    if (checkbox.checked == false) {
    	for (x = 0; x < objForm.length; x++) {
			objCurrentBox = objForm[x];
			strCurrentBoxName = objCurrentBox.name;
    		if (strCurrentBoxName.substring(0,3).toUpperCase() == prefix.toUpperCase())
    			objForm[strCurrentBoxName].checked = false;
    	}
    }
    else {
    	for (x = 0; x < objForm.length; x++) {
			objCurrentBox = objForm[x];
			strCurrentBoxName = objCurrentBox.name;
    		if (strCurrentBoxName.substring(0,3).toUpperCase() == prefix.toUpperCase())
    			objForm[strCurrentBoxName].checked = true;
		}
    }
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Calls the javascript functions which need to run when the page is loaded
function initJavascript() {
	setValue("COMPLETE_THIS_ORDER", "false");
	highlight();
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Sets the value of an input element
//		Parameters
//		inputID					String				The ID of the input to be set
//		inputValue			String				The string to be set as the value of the input
function setValue(inputID, inputValue) {
	document.getElementById(inputID).value = inputValue;
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Used to highlight the row in the sort table which coresponds to the user's search
function highlight() {
	
	var searchRows;
	var rowContent;
	var sorts
	var sortTableID;
	if(document.getElementById('general_header').childNodes[0]) 
	{
		var toMatch = document.getElementById('general_header').childNodes[0].nodeValue;

		for(sorts = 1; sorts <= 3; sorts++) {
			sortTableID = "sort" + sorts + "_search_table";
			if(document.getElementById(sortTableID) != null) {
				searchRows = document.getElementById(sortTableID).getElementsByTagName('tr');
				rowContent;
				toMatch = document.getElementById('general_header').childNodes[0].nodeValue;
				for(i=1; i<searchRows.length; i++) {
					rowContent = searchRows[i].getElementsByTagName('a')[0].childNodes[0].nodeValue;
						if(rowContent == toMatch)
							searchRows[i].className = "highlighted";
				}
			}
		}
	}
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}



function jsCheckForm(aForm) {
	internal = 'true';
	aForm.jsenabled.value = "true";
	return true;
}
function jsCheck() {
	document.repselect.jsenabled.value = "true";
	return true;
}
function AddRep(coyRef, someCheckBox) {
	testRef = ":" + coyRef + ":";
	coyRef = coyRef + "::";
	var refIdx = document.repselect.newcoys.value.indexOf(testRef);
	if ((someCheckBox.checked)&&(refIdx == -1)) {
		document.repselect.newcoys.value = document.repselect.newcoys.value + coyRef;
	} else if ((!someCheckBox.checked)&&(refIdx > -1)) {
		var newList = document.repselect.newcoys.value.substring(0, refIdx);
		if ((refIdx + coyRef.length) < document.repselect.newcoys.value.length) {
			newList = newList + document.repselect.newcoys.value.substring(refIdx + testRef.length, document.repselect.newcoys.value.length);
		}
		document.repselect.newcoys.value = newList;
	}
	return true;
}
function addPDF(coyRef, someCheckBox) {
	testRef = ":" + coyRef + ":";
	coyRef = coyRef + "::";
	var refIdx = document.repselect.newpdfs.value.indexOf(testRef);
	if ((someCheckBox.checked)&&(refIdx == -1)) {
		document.repselect.newpdfs.value = document.repselect.newpdfs.value + coyRef;
	} else if ((!someCheckBox.checked)&&(refIdx > -1)) {
		var newList = document.repselect.newpdfs.value.substring(0, refIdx);
		if ((refIdx + coyRef.length) < document.repselect.newpdfs.value.length) {
			newList = newList + document.repselect.newpdfs.value.substring(refIdx + testRef.length, document.repselect.newpdfs.value.length);
		}
		document.repselect.newpdfs.value = newList;
	}
	return true;
}


function check_for_nulls(message, input_1, input_2){

	var valid

	if ((input_1.value != "null" )||(input_2.value != "")){
		valid="true"
	}
	if (valid != "true"){
		alert(message)
		return false
	}else{
		return true
	}
}

function check_for_nulls_2(message, array){

	var valid

	for (i=0;i<=array.length;i++){

		if ((array[i].value != "null" )||(array[i].value != "")){
			valid="true"
		}
	}
	if (valid != "true"){
		alert(message)
		return false
	}else{
		return true
	}
}


function add_to_array(array,element){
	pushed = push(array, element)
}

function submitQuery(destination) {
	internal = 'true';
	startpt = destination.indexOf('userID=')
	stoppt = destination.indexOf('&', startpt) + 1
	sortval = destination.substring(startpt, stoppt)
	destination = destination.replace(sortval, '')
	startpt = destination.indexOf('sort=')
	stoppt = destination.indexOf('&', startpt) + 1
	sortval = destination.substring(startpt, stoppt)
	destination = destination.replace(sortval, '')
	sortval = sortval.replace('sort=', '')
	sortval = sortval.replace('&', '')
	document.repselect.sort.value = sortval
	document.repselect.jsenabled.value = 'true'
	document.repselect.action = destination
	document.repselect.submit()
	return false
}

function asp_submitQuery(destination) {	
	internal = 'true';
	startpt = destination.indexOf('session_ID=')
	stoppt = destination.indexOf('&', startpt) + 1
	sortval = destination.substring(startpt, stoppt)
	destination = destination.replace(sortval, '')
	document.repselect.jsenabled.value = 'true'
	document.repselect.action = destination
	document.repselect.submit()
	return false
}









function selectActivate(objSelect, key) {

// PARAMETERS:
//		objSelect	 -> Object Reference to the list box
//		key			 -> The value in the list box that should be selected
	for (x = 0; x < objSelect.length; x++) {
		if (objSelect[x].type == "radio") {
			if (objSelect[x].value == key) {
				objSelect[x].checked = true;
			}
		}
		else {
			if (objSelect.options[x].value == key) {
				objSelect.selectedIndex = x;
			}
		}
	}

} // selectActivate




