/**
* pop up a window
* @param string url
* @param string window name
* @param integer width
* @param integer height
**/
function popUp(url,windowName,width,height)
{
	var features = 'directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=' + width + ',height=' + height;
	window.open(url,windowName,features);
}

/**
* check/uncheck all boxes
**/
function checkAll(boxAll,boxName) {
    docForm = boxAll.form;
    for(var i = 0;i < docForm.elements.length;i ++) {
		elem = docForm.elements[i];
		if(elem.disabled)
			continue;
        if(elem.name == boxName) {
            elem.checked = boxAll.checked;
        }
    }
}

/**
* check all boxes
* @param docForm form
* @param boxName name of checkbox
**/
function checkAllBox(docForm,boxName) {
    for(var i = 0;i < docForm.elements.length;i ++) {
		elem = docForm.elements[i];
		if(elem.disabled)
			continue;
		if(!boxName) {			
			elem.checked = true;
			continue;
		}
        if(elem.name == boxName) {
            elem.checked = true;
        }
    }
}
/**
* uncheck all boxes
**/
function unCheckAllBox(docForm,boxName) {
	 for(var i = 0;i < docForm.elements.length;i ++) {
		 elem = docForm.elements[i];
		 if(elem.disabled) {
			 continue;
		 }
		 if(!boxName) {
			 elem.checked = false;
			 continue;
		 }
		 if(elem.name == boxName) {
			 elem.checked = false;
		 }
    }
}

function locateWindow() {
	window.focus();
	if(typeof window.outerWidth != "undefined") {
		w = window.outerWidth;
		h = window.outerHeight;
	} else {
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	}	
	var oX = (screen.width - w) / 2;
	var oY = (screen.height - h) / 3;
	window.moveTo(oX,oY);
}

function getRadioValue(elem) {
	for(var i = 0;i < elem.length;i ++) {
		if(elem[i].checked) {
			return elem[i].value;
		}
	}
	return null;
}

function disableForm(form) {
	for(var i = 0;i < form.elements.length;i ++) {
		form.elements[i].disabled = true;
	}
}

/**
* Check if the opener of the current window exists and is still open
* @return boolean
*/
function isOpenerAlive() {
	//detect browser	
	isIE = /msie/i.test(navigator.userAgent);
	isMozilla = /mozilla/i.test(navigator.userAgent);
	if(isIE) {
		//not opened by window.open()
		if(typeof window.opener == "undefined") {
			return false;
		}
		return window.opener.closed ? false : true;
	} else if(isMozilla) {		
		return window.opener == null ? false : true;
	} else {		
		//untested
		return window.opener == null ? false : true;
	}	
}

