// JavaScript Document
//------ form related functions -------

//get the selected choice's text, value, & index OR value for a text field
//used for xyz_general.js for reseting hidden fields and collect info for calcprintprice.
//make sure not trying to get the index or choice for a text field!!!  (using in quote page)
function get_choice(field_name, return_type)
{
	switch(return_type.toLowerCase())
	{
		case 'choice':
			var Current = document.Forminfo[field_name].selectedIndex;
			var choiceName = document.Forminfo[field_name].options[Current].text;
			return choiceName;
			break;
		
		case 'value':
			return document.Forminfo[field_name].value;
			break;

		case 'index':
			var Current = document.Forminfo[field_name].selectedIndex;
			return Current;
			break;
	}
}
//set focus to a text field	//using in quote page
//how to call: set_focus(this, 'username');
function set_focus(the_object, the_field_name)
{
	the_object.form[the_field_name].focus();
}

// enable the other field when you choose a, for example, pull down menu
// used for forms
//how to call: eg. onchange="enable_if_other('Outside US', this, 'outside_us')"
//enable_option: enable the field if the option is xyz. eg. "outside us", enable the other field to specific it.
//source_field: the pull down menu the onchange is at
//the_field: the field that we want to enable; the field should be disable to start with.

function enable_if_other(enable_option, source_field, the_field)
{
	if (source_field.value == enable_option) 
	{
		document.Forminfo[the_field].disabled = false;
		document.Forminfo[the_field].value = "specify here";
		//document.Forminfo[the_field].focus();
	} 
	else 
	{
		document.Forminfo[the_field].value = "N/A";
		document.Forminfo[the_field].disabled = true;
	}
}

function reset_onReload(formname)
{
	//if(document[formname].reset && detbrowser != "Safari")
	if(document[formname].reset)
	{
		document[formname].reset();	//for reseting the whole form when user reload the page
	}
}
//Function to limit text entered into textarea
//how to call: onkeyup="limitText(this,15,'char_left','characters left');"
//1. remember to initialize the counter field: <span id="char_left">15 characters left.</span>
//1a. can put them into the window.onload routine
function limitText(textID, maxlimit, counterID, counterMessage) 
{
    if (textID.value.length > maxlimit) 
	{
        textID.value = textID.value.substring(0,maxlimit);
    }
	else
	{
		var character_left = maxlimit - textID.value.length;
		//remember to put init value for the counter field
		document.getElementById(counterID).innerHTML = character_left+' '+counterMessage;
	}
}
