function openURL(strURL) {
	//alert(strURL);
	//alert(document.all.server_name.value);
	window.location.href=strURL;	
}
function openWindow(url) {
	var newwindow;
	newwindow=window.open(url,'name','height=200,width=300,status=yes,scrollbars=yes,resizable=1');
	if (window.focus) {newwindow.focus()}
}
function addToList(listField, newText, newValue) {
   if ( ( newValue == "" ) || ( newText == "" ) ) {
      alert("You cannot add blank values!");
   } else {
      var len = listField.length++; // Increase the size of list and return the size
      listField.options[len].value = newValue;
      listField.options[len].text = newText;
      listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered)
   } // Ends the check to see if the value entered on the form is empty
}

function getQueryString(strURL, strQSName) {
/*
	This function searches a URL for the query string specified by the parameter strQSName
	and returns it's value
*/
	var intStartPos = strURL.indexOf(strQSName) ;
	if (intStartPos != -1) {
		var intEndPos = (strURL.lastIndexOf("&") == intStartPos-1) ? strURL.length  : 
			 intStartPos + strQSName.length + strURL.substring(intStartPos + strQSName.length,  strURL.length - 1).indexOf("&");
		intStartPos = intStartPos + strQSName.length + 1;	
		//alert(strURL + "\nlooking for:" + strQSName + "\nintStartPos:" + intStartPos + "\nintEndPos:"+intEndPos)
		return strURL.substring(intStartPos, intEndPos);
	}
	return '';
}
function displayErrorMsg(strFuncName, strMsg){
	alert("JavaScript Error in general.js Function \"" + strFuncName + "\"\r\r" + strMsg);
}
function getArgs(strURL) {
	var args = new Object();
	// Get Query String
	var query =strURL;
	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 
		// if not found, skip to next
		if (pos == -1) continue; 
		// Extract the name
		var argname = pairs[i].substring(0,pos); 
		
		// Extract the value
		var value = pairs[i].substring(pos+1); 
		// Store as a property
		args[argname] = unescape(value); 
	}
	return args; // Return the Object
}
function getDropDownSelected(objField, strValue) {
	for (var k=0; k < objField.options.length; k++){
		if(objField.options[k].value == strValue) {
			return k;
		}
	} 
	return -1;
}

String.prototype.trim = function()  {
	// use this by just calling it as a function
	// for example:  var s = document.all.UserRoles.value.trim();
	//
	return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function getNumeric(val) {
	if(!isNaN(val)) return (val/1);
  	return false;
}

function currency(anynum) {
//-- Returns passed number as string in $xxx,xxx.xx format.
	anynum=eval(anynum)
	if (anynum=="" || anynum==NaN || anynum==null || anynum==0) {return "$0.00"}
   	workNum=Math.abs((Math.round(anynum*100)/100));
	workStr=""+workNum
   	if (workStr.indexOf(".")==-1){workStr+=".00"}
   	dStr=workStr.substr(0,workStr.indexOf("."));
	dNum=dStr-0
   	pStr=workStr.substr(workStr.indexOf("."))
   	while (pStr.length<3){pStr+="0"}

//--- Adds comma in thousands place.
//	if (dNum>=1000) {
//		dLen=dStr.length
//		dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
//	 }

//-- Adds comma in millions place.
//	if (dNum>=1000000) {
//		dLen=dStr.length
//		dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
//	}
retval = dStr + pStr 
//-- Put numbers in parentheses if negative.
	if (anynum<0) {retval="("+retval+")"}
	return "$"+retval
}

function insertFieldMsg (fldName, message, alertMsg) {
	removeFieldMsg(fldName+'msg');
	var html = '';
	var newPara = document.createElement("<span id='"+fldName+"msg'></span>");
	var newBR = document.createElement("<br>");
	newPara.appendChild(newBR);
	newPara.appendChild(document.createTextNode(message));
	newPara.style.color = "#FF0000";
	newPara.style.fontWeight = "normal";
	var form = document.forms[0];
	for (i = 0; i < form.elements.length; i++) {
         if (form.elements[i].name == fldName) { 
			if (alertMsg) alert(message)
         		var el = form.elements[i];
         		var parent = el.parentNode;
			parent.appendChild(newPara);
			break;
		}
	}
}

function removeFieldMsg(idName) {
	var msg = document.getElementById(idName+'msg');
	if (msg) msg.removeNode(true);
}
function getRadioValue(objFld) {
	for (var i=0; i < objFld.length; i++) {
		if ( objFld[i].checked) {
     			return objFld[i].value;
     		}
	}
}
function setRadioValue(objFld, newVal) {
	for (var i=0; i < objFld.length; i++) {
		if ( objFld[i].value==newVal) {
     			objFld[i].checked = true
     		} else {
     			objFld[i].checked = false     		
     		}
	}
}