
/**
Common add Event listener function
*/
function addListener(element, type, expression, bubbling) {
	bubbling = bubbling || false;
	if(window.addEventListener)	{ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

/**
Opens a standard pop-up window
*/
function openPopup(url, name, width, height) {
	var newwin = window.open(url, name, "scrollbars=no,resizable,top=50,left=100,width=" + 
		width + ",height=" + height);
}

/**
Prompts the user to confirm before proceeding with an action
*/
function interfaceConfirm(confirmText, targetURL) {
	if(confirm(confirmText)) {
		document.location.href = targetURL;
	}
}

/**
Sets a form field with the focus
*/
function setFieldFocus(field) {
	window.focus();
	if(field) {
		try {
			field.focus();	
		} catch(e) {
			
		}		
	}
}

/**
Sets the first field with focus
*/
function setFirstFieldWithFocus(form, skipFilled) {
	if(form.elements[0] != null) {
		var i;
		var max = form.length;
		for( i = 0; i < max; i++ ) {
			if( form.elements[i].type != "hidden" &&
				!form.elements[i].disabled &&
				!form.elements[i].readOnly && 
				(!skipFilled || (skipFilled && form.elements[i].value == '' ) )) {
				setFieldFocus(form.elements[i]);
				break;
			}
		}
	}
}



function valid_int(value) {
	return (parseInt(value) == value - 0);
}

function valid_float(value) {
	return (parseFloat(value) == value - 0);
}

function valid_currency(value) {
	return RegExp(/^-?\$?[0-9\,]+(\.\d{2})?$/).test(String(value).replace(/^\s+|\s+$/g, ""));
}


function CheckEmail(str) {
	return (str.indexOf(".") >= 1) && (str.indexOf("@") > 0);
}

