/*
 * Javascript utilities.
 *
 */
function validate(_form) {
    if (_form.name === 'signupform') {
	var re = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$");
	var email = document.getElementById('SignupEmail');	
	if (!email) {
	    return false;
	}

	if (!re.test(email.value)) {
	    alert("Please enter a valid email address.");
	}
	else {
	    _form.submit();
	}
    }
    else {
	_form.submit();
    }
}

function confirm_deletion(baseurl, id, type, plural, page) {
    if (!id || !type || type.length == 0) {
	return false;
    }

    if (confirm('Are you sure you wish to delete ' + type + ' #' + id + '?')) {
	if (!plural) {
	    plural = type + 's';
	}
	var url = baseurl + '/' + plural + '/delete/' + id;
	if (page) {
	    url += '/' + page;
	}
	window.location = url;
	return true;
    }

    return false;
}

function g_openWindow(page, height, width, win, scrollbars, resizable, toolbar, menubar)
{
    if (!height)
	height = 260;
    if (!width)
	width = 500;
    if (!win)
	win = "_new"

	    height += 25; // hack for safari popups		    

    var h, w, scrol, siz;
    w = "WIDTH=" + width.toString();
    h = "HEIGHT=" + height.toString();
    scrol = ",scrollbars=" + ( (scrollbars) ? "yes" : "no" );
    siz = ",resizable=" + ( (resizable) ? "yes" : "no" );
    tool = ",toolbar=" + ( (toolbar) ? "yes" : "no" );
    menu = ",menubar=" + ( (menubar) ? "yes" : "no" );
    attr = w + "," + h + scrol + siz + tool + menu;
    popupWin = window.open(page,win,attr);
    popupWin.focus();
}

