// Return the selected value from a SELECT widget (dropbox)

function selectedValue(aSelect) {
   return aSelect.options[aSelect.selectedIndex].value;
}

// Extract the internal item ID used by the shopping cart from
// the size selection dropbox and insert it into the form fields

function setCartIDs(aForm) {
   var cartID = selectedValue(aForm.selectSize);
   aForm.objid.value = cartID;
}

// Display the RingCentral call window
function ringMe() {
	window.open("http://ringcentral.com/ringme/?uc=55879038,0,&s=no&v=2","ffRingMe","resizable=no,width=380,height=240");
	return false;
}

// Text field trim functions
function trimText(aTextField) {
	padded=aTextField.value
	aTextField.value=trim(aTextField.value)
}

// String trim functions
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// Extract document description from the 'description' meta tag
function getShareTitle(aDocument){
	var elementList=aDocument.getElementsByTagName('head')[0].getElementsByTagName('meta');
	for(var i=0;i<elementList.length;i++){
		if(elementList[i].getAttribute('name') !== null){
			if(elementList[i].getAttribute('name').toLowerCase() == 'description'){
				return elementList[i].getAttribute('content');
			}
		}
	}
	return aDocument.Title;
}

// Extract document description from the 'image_src' meta tag
function getShareImage(aDocument){
	var elementList=aDocument.getElementsByTagName('head')[0].getElementsByTagName('link');
	for(var i=0;i<elementList.length;i++){
		if(elementList[i].getAttribute('rel') !== null){
			if(elementList[i].getAttribute('rel').toLowerCase() == 'image_src'){
				return elementList[i].getAttribute('href');
			}
		}
	}
	return 'http://www.faeriesfinest.com/faerie.gif';
}