function encodeNameAndValue(sName, sValue) {
    var sParam = encodeURIComponent(sName);
    sParam += "=";
    sParam += encodeURIComponent(sValue);
    return sParam;				
}

function getRequestBody(oForm) {
	//array to hold the params
	var aParams = new Array();
	            
	//iterate over each element in the form
	for (var i=0 ; i < oForm.elements.length; i++) {
	//get reference to the field
		var oField = oForm.elements[i];
	    //different behavior based on the type of field
	    switch (oField.type) {
	    	//buttons - we don't care
	        case "button":
	        case "submit":
	        case "reset":
	        break;
	      	
	      	//checkboxes/radio buttons - only return the value if the control is checked.
	        case "radio":
	        case "checkbox":
	        if (!oField.checked) {
	        	break;
	        } //End: if
	        
	        //text/hidden/password all return the value
	        case "text":
	        case "hidden":
	        case "password":
	        aParams.push(encodeNameAndValue(oField.name, oField.value));			
	        break;
	                    
	        //everything else
	        default:
	                    
	        switch(oField.tagName.toLowerCase()) {
	        	case "select":
	            aParams.push(encodeNameAndValue(oField.name, oField.options[oField.selectedIndex].value));
	            break;
	            
	            default:	
	            aParams.push(encodeNameAndValue(oField.name, oField.value));
	        }
	    }							
	            
	}
	return aParams.join("&");
}

function openWin(urlToOpen, windowName, width, height){
	var useTop = 0;
	var useLeft = 0;
	var screenHeight = screen.height;
	var screenWidth = screen.width;		
	var useWidth = 1000;
	var useHeight = 800;
	
	if(width){
		useWidth = width;
	}
	if(height){
		useHeight = height;
	}
	
	if(screenHeight > useHeight && screenWidth > useWidth){
		useTop = (screenHeight - useHeight)/2;
		useLeft = (screenWidth - useWidth)/2;
	}
	if(!windowName) windowName = '_blank';
	var varFeatures = 'scrollbars=yes,menubar=no,left=' + useLeft + ',top=' + useTop + ',height='+useHeight+',width='+useWidth+',resizable=yes,toolbar=no,location=no,status=no';
	openNewWindow(urlToOpen,windowName,varFeatures);
}

function refreshPage(){
	window.location.href = refreshUrl;
}

function lTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function rTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim( value ) {
	return lTrim(rTrim(value));
}

function beginsWith(inString, what){
	var useString = "" + inString;
	return useString.indexOf(what) == 0;
}

function endsWith(inString, what){
	var useString = "" + inString;
	return useString.lastIndexOf(what) == useString.length - what.length;
}

