//
// General window pop up
//
function popWin(url, wname, w, h) {
	var hWin = window.open(url, wname, 'width=' + w + ',height=' + h + ',scrollbars=yes');
	hWin.focus();
}

function popFixWin(url, wname, w, h) {
	var hWin = window.open(url, wname, 'width=' + w + ',height=' + h + ',scrollbars=no');
	hWin.focus();
}

function popResizWin(url, wname, w, h) {
	var hWin = window.open(url, wname, 'width=' + w + ',height=' + h + ',scrollbars=no,resizable=yes');
	hWin.focus();
}

function popPrintInvoice(url) {
	var w = 600;
	var h = 400;
	var wname = 'invoice';
	var hWin = window.open(url, wname, 'width=' + w + ',height=' + h + ',scrollbars=yes,resizable=yes');
	hWin.focus();
}

function popEditPDetails(url) {
	// pop personal details window
	var w = 500;
	var h = 400;
	var wname = 'edtPDetails';
	var hWin = window.open(url, wname, 'width=' + w + ',height=' + h + ',scrollbars=yes,resizable=yes');
	hWin.focus();
}

//
// pop up windows for footer
//
function popPrivacyWin(url) {
	var hWin = window.open(url,'privacy','width=590,height=600,scrollbars=yes');
	hWin.focus();
}

function popContactWin(url) {
	var hWin = window.open(url,'contact','width=720,height=400,scrollbars=yes');
	hWin.focus();
}

//
// Common functions
//
var focusFormObj = false;

// set focus to object
function giveFocus(frmObj) {
	var isIE4 = (document.all) ? 1 : 0;
	var isDisabled = false;
	if (isIE4) {
		isDisabled = frmObj.disabled;
	}
	if ((!focusFormObj) && (!isDisabled)) {
		frmObj.focus();
		focusFormObj = true;
	}
}

function confirmLogout() {
	return confirm('Are you sure you want to logout?');
}

// function trim(inputString) {
// 	// Removes leading and trailing spaces from the passed string. Also removes
// 	// consecutive spaces and replaces it with one space. If something besides
// 	// a string is passed in (null, custom object, etc.) then return the input.
// 	if (typeof inputString != "string") { return inputString; }
// 	var retValue = inputString;
// 	var ch = retValue.substring(0, 1);
// 	while (ch == " ") { // Check for spaces at the beginning of the string
// 		retValue = retValue.substring(1, retValue.length);
// 		ch = retValue.substring(0, 1);
// 	}
// 	ch = retValue.substring(retValue.length-1, retValue.length);
// 	while (ch == " ") { // Check for spaces at the end of the string
// 		retValue = retValue.substring(0, retValue.length-1);
// 		ch = retValue.substring(retValue.length-1, retValue.length);
// 	}
// 	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
// 		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
// 	}
// 	return retValue; // Return the trimmed string back to the user
// } // Ends the "trim" function

function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}
