function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

// Clears a text field only if the value matches what is passed in
function clearField(fId, sMatch, sChange){
	if(sChange == null) sChange = '';
	if(trim(fId.value) == sMatch) {
		fId.value = sChange;
	}
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function SwitchOfferTabs(id, on) {
	if(SelectedOfferTab!=id) {
		sExtra = '';
		if(on==1){
			if(document.getElementById(id).className.indexOf('Over')<0){
				document.getElementById(id).className = document.getElementById(id).className + 'Over'
			}else{
				SelectedSearchTab = id;
			}
		}else{
			if(document.getElementById(id).className.indexOf('Over') > -1) {
				document.getElementById(id).className = Left(document.getElementById(id).className,document.getElementById(id).className.length-4);
			}
		}
	}
}
var SelectedOfferTab = 'offer_tab1';
function SwitchOfferSearch(id) {
	for(x=1;x<8;x++) {
		if(document.getElementById('offer_tab'+x)) {
			document.getElementById('offer_tab'+x).className = 'offertab';
		}
		if(document.getElementById('offer'+x)) {
			document.getElementById('offer'+x).style.display = 'none';
		}
	}
	SelectedOfferTab = id;
	if(document.getElementById(id)) {
		document.getElementById(id).className = 'offertabOver';
	}
	if(document.getElementById('offer'+Right(id,1))) {
		document.getElementById('offer'+Right(id,1)).style.display = '';
	}
}
