// window popups...
window.referencePopup = null;

function openPopup(name, url, url2, x, y, width, height) {

	if (width <= 0) {
	  width = screen.width;
	}
	if (height <= 0) {
	  height = screen.height;
	}
	if (x <= 0) {
	  x = (screen.width - width) / 2;
	}
	if (y <= 0) {
	  y = (screen.height - height) / 2 - 40;
	}

  window.referencePopup = window.open(url, name, 'location=false,toolbar=false,menu=false,resizable=yes,scrollbars,height='+height +',width='+width+',top='+y+',left='+x); 
  
	if (!window.referencePopup.opener) {
		window.referencePopup.opener = window;
	}
	if (window.focus) {
		window.referencePopup.focus();
		return false;
	}
}

function openSearchPopup(name, url, url2, x, y, width, height) {

	if (width <= 0) {
	  width = screen.width;
	}
	if (height <= 0) {
	  height = screen.height;
	}
	if (x <= 0) {
	  x = (screen.width - width) / 2;
	}
	if (y <= 0) {
	  y = (screen.height - height) / 2 - 40;
	}

  window.referencePopup = window.open(url, name, 'location=false,toolbar=false,menu=false,resizable=yes,scrollbars,height='+height +',width='+width+',top='+y+',left='+x); 
  
	if (!window.referencePopup.opener) {
		window.referencePopup.opener = window;
	}
	if (window.focus) {
		window.referencePopup.focus();
		return false;
	}
}


function openPopup2(url, url2) {
  return openPopup(url, url2, 800, 600, 0, 0);
}

function closeRefresh(url) {
	if (window.opener) {
	  window.opener.location = url;
	  window.close();
	  window.opener.focus();
	}
}
function onlyClose() {
	if (window.opener) {
	  window.close();
	  window.opener.focus();
	}
}
function onlyRefresh(url) {
  location = url;
}


function copyOptions(x, x1) {
	while (x.length > 0) {
	  x.remove(x.length - 1);
	}
	var i = 0;
	for (i = 0; i < x1.options.length; i++) {
		var optionName = new Option(x1.options[i].text, x1.options[i].value, false, false)
 		x.add(optionName, null);
	}
}

function enableInput(checkboxname, inputname) {
	if(document.getElementById(checkboxname).checked) {
    document.getElementById(inputname).disabled=true;
	} else {
    document.getElementById(inputname).disabled=false;
  }
}

function selector(idname, textname, id, text) {
	if (window.opener) {
		window.opener.document.getElementById(idname).value = id;	  
		window.opener.document.getElementById(textname).value = text;	  
	  window.close();
	  window.opener.focus();
	  return false;
	}
}

function deselector(idname, textname) {
	document.getElementById(idname).value = null;	  
	document.getElementById(textname).value = "";	  
}

function showError() {
    document.getElementById("error").style.display = "block";
    return true;
}

function changeVisibility(name) {
	var style = document.getElementById(name).style.display ;
	if (style == 'none') {
    document.getElementById(name).style.display = 'block';
	} else {
    document.getElementById(name).style.display = 'none';
  }  
}