//****************************************************
// 				DHTML  ANIMATIONS
//
//	Methods:
//	1.)submitFormFromEnter(e, submitButtonId) submits a form 
//	when the carriage return in the window is pressed. 
//		
// 	2.)proceedToNextField(field ,complete, nextFieldId) checks to see 
//  if the user has completed filling in the field, and if so, 
//  moves the cursor to the next logical field
//
//******************************************************





//--------------------------------------------------------
// Submit a certain form if the enter/carriage return 
// is pressed. 
//
//	e is event object passed from function invocation
// 	submitButton is the domId of the button to click to cause submission.
//---------------------------------------------------------
function submitFormFromEnter(e, submitButtonId){ 
	var charCode;
	// Gecko : 
	if(e && e.which) 
		charCode = e.which;
	// ie
	else
		charCode = e.keyCode;
	
	// The CR/Enter charCode (ascii 13)
	// Netscape tossing here
	if(charCode == 13){
		document.getElementById(submitButtonId).click();
	}
	return false;
}



//----------------------------------------------------------
// Given a field, if it has reached its capacity, move the
// cursor on to the next field. 
//----------------------------------------------------------
function proceedToNextField(fieldId ,capacity, nextFieldId){
	var f = document.getElementById(fieldId);
	if(f.value && f.value != "") {
		if(f.value.length == capacity)
			document.getElementById(nextFieldId).focus();
	}
}


//--------------------------------------------------------
// Restrict input to a phone field
//________________________________________________________

var digPat = /^\d*$/;
function restrictInput(fieldId ,capacity, nextFieldId){
	var f = document.getElementById(fieldId);
	if(f.value && f.value.length > 0 && !digPat.exec(f.value) ){
		f.value = f.value.substring(0,f.value.length-1)
	}
	if(capacity && nextFieldId)
		proceedToNextField(fieldId ,capacity, nextFieldId);
}

/*
	If masterBox is checked, check all checkboxes boxes in Array of subBoxes. 
	@param masterBox the controlling box object.
	@param subBoxes an Array of IDs of the boxes controlled by the master.
*/
function checkTheRestDyn(masterBox, subBoxes){
	var box;
	if(masterBox.checked){
		for(var i=0;i<subBoxes.length;i++){
			box = document.getElementById(subBoxes[i]);
			box.checked = true;			
		}
	}
}
//---------------------------------------------------------
// DEPRECATED!! Use checkTheRestDyn(string:masterBox, array:subBoxes) instead.
//
// Check boxes:  if one is checked, check all. 
//
// Changed to call checkTheRestDyn and pass the array of 
// IDs originally sent in. Only keeping this function for possible
// legacy code.
//---------------------------------------------------------
function checkTheRest(box1, cb1Id,cb2Id,cb3Id) {
	checkTheRestDyn(box1,[cb1Id,cb2Id,cb3Id]);
	/*
	if(box1.checked) {
		document.getElementById(cb1Id).checked = true;
		document.getElementById(cb2Id).checked = true;
		document.getElementById(cb3Id).checked = true;
	
	*/
}

//---------------------------------------------------------
// Check boxes:  if one is unchecked, uncheck another
//---------------------------------------------------------
function unCheckOne(box,cb1Id) {
	if(!box.checked) {
		document.getElementById(cb1Id).checked = false;
	}
}

//---------------------------------------------------------
// Determine the number of characters left for a text area field
// Restrict the field input if exceeded
// Set an optional Character remaining field
//---------------------------------------------------------
function determineRemaining(domId1, max, domIdToFill) {
	var str = document.getElementById(domId1).value;
	
	var l = str.length;
	if(max < l) {
		document.getElementById(domId1).value=str.substring(0,max);
		if(domIdToFill)
			document.getElementById(domIdToFill).innerHTML=0;
	}else{
		if(domIdToFill)
			document.getElementById(domIdToFill).innerHTML=max-l;
	}
}






