function trim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(" " + str + " ");
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
			j++;
		}
            s = s.substring(j, i);
	}

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
			i--;
		}
            s = s.substring(0, i+1);
	}
	return s;
}

function win(URL) { 
	swidth = (screen.width-700)/2;
	sheight = (screen.availHeight-550)/2
	var win = window.open(URL,'win','width=700,height=550,top=' + sheight + ',left=' + swidth + ',resizable=yes,scrollbars=yes,location=yes');
	win.focus();
}

function win_pic(URL, w, h) { 
	swidth = (screen.width-w)/2;
	sheight = (screen.availHeight-h)/2
	var win_pic = window.open(URL,'win_pic','width='+w+',height='+h+',top=' + sheight + ',left=' + swidth + ',resizable=yes,scrollbars=yes,menubar=yes');
	win_pic.focus();
}

String.prototype.capitalize = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

function change_states(c, st, mu) {
	if (c > 0) {
		$('state_select').innerHTML = "<font class=\"blue2\">&nbsp;&nbsp;Loading States...</font>";
		var url = 'http://www.ceoregistry.com/states.ajax.php';
		var pars = 'c=' + c + '&st=' + st + "&mu=" + mu;
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: showResponse
			}
		);
	} else {
		$('state_select').innerHTML = "<font class=\"blue2\">&nbsp;&nbsp;Please select a country...</font>";
	}
}
function showResponse(originalRequest) {
	$('state_select').innerHTML = originalRequest.responseText;
}
