/**
 * Redirect
 */
function go(url) {
	if (url) window.location.assign(url);
}
/**
 * Open new window
 */
function wopen(url, w, h, res) {
	if (!url) {
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
	target = '_blank';
	if (!w) w = 500;
	if (!h) h = 400

	w = parseInt(w, 10);
	h = parseInt(h, 10);

	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if (w > aw) w = aw;
	if (h > ah) h = ah;

	if (res) r = 0; 
	else r = 1;
    
	var left = Math.round((aw - w)/2);
	var top = Math.round((ah - h)/ 2);

	var wd = window.open(url, target, 'channelmode=0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+r+', scrollbars=1, status=0, toolbar=0, top='+top+'px, left='+left+'px');
} 
/**
 * Close window with opener reload
 */
function wrclose() {
	if (window.opener) window.opener.location.reload();
	
	window.close();
}
/**
 * Replace double spaces and trailing spaces
 */
function replace( obj ) {
	var r1 = /^( )+/g;
	var r2 = /( )+$/g;
	var r3 = /( {2})+/;

	obj.value = obj.value.replace(r1, '');
	obj.value = obj.value.replace(r2, '');
	obj.value = obj.value.replace(r3, ' ');
} 
/**
 * Check email format
 */
function em_ch(obj) {
	if (!obj || !obj.value) return false;
	var CC = /^[._a-z0-9-]+@[._a-z0-9-]+\.[a-z]{2,4}$/i;
	if (!CC.test(obj.value)) return false;
	else return true;
} 