/*	Function Name:	Option_Select_Set_Single
 *	Description:		Selects one option from an option list.
 *	Prototype:			Option_Select_Set_Single(OptionListID, Value);
 *	Arguments:			
 *		OptionListName:  Name of Option List.
 *		Item:  Name of Option List.
 *	ie: Option_Select_Set_Single('CountryList', 'USA'); *	  
 */
function Option_Select_Set_Single(OptionListID, Value) {
	SelectObject = document.getElementById(OptionListID);
	for(index = 0; index < SelectObject.length; index++) {
		if(SelectObject[index].value == Value){
			 SelectObject.selectedIndex = index;      
			 break;
	  }else{
			SelectObject.selectedIndex = 0;
		}
	} 
}

function Option_Select_Set_ClearAll(SelectName){
//This function is untested
	i = 0
	SelectObject = document.getElementById(SelectName);
	
	for(index = 0; index < SelectObject.length; index++) {
		if (selectlist.options[index].selected == 1){
			selectlist.options[index] = null;
		}
		else {
		}
	}
}

function isNull(val) { return (val == null); }

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

	
function DisplayStateField(sElement, sValue){
	if (sElement == 'shipcountry'){
		if(sValue == "USA" || sValue == "Canada"){
			document.getElementById('US_shipstate').style.display = '';
			document.getElementById('shipstate').style.display = 'none';
		}else{
			document.getElementById('US_shipstate').style.display = 'none';
			document.getElementById('shipstate').style.display = '';
		}
	} else if (sElement == 'country'){
		if(sValue == "USA" || sValue == "Canada"){
			document.getElementById('US_state').style.display = '';
			document.getElementById('state').style.display = 'none';
		}else{
			document.getElementById('US_state').style.display = 'none';
			document.getElementById('state').style.display = '';
		}
	} else if (sElement == 'B_Country'){
		if(sValue == "USA" || sValue == "Canada"){
			document.getElementById('US_B_State').style.display = '';
			document.getElementById('B_State').style.display = 'none';
		}else{
			document.getElementById('US_B_State').style.display = 'none';
			document.getElementById('B_State').style.display = '';
		}
	} else if (sElement == 'L_Country'){
		if(sValue == "USA" || sValue == "Canada"){
			document.getElementById('US_L_State').style.display = '';
			document.getElementById('L_State').style.display = 'none';
		}else{
			document.getElementById('US_L_State').style.display = 'none';
			document.getElementById('L_State').style.display = '';
		}
	} else{

	}
}	

function ShowHide(sElement, sValue){
	if (sValue == "Invoice Same Address" || sValue == "none" || sValue == "hide" ){
		document.getElementById(sElement).style.display = 'none';
	}else{
		document.getElementById(sElement).style.display = '';
	}
}
