/* popup window */

var forcedRefresh = true;
var alreadyopen = new Array();
var newwin = new Array();

function openCenteredWindow(theURL, winName, features, w, h){
  var winl = parseInt((screen.width - w - 10) / 2);
  var wint = parseInt((screen.height - h - 29) / 2);
  var retval = openWindow(theURL, winName, features + ',height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl);
  if(!theURL) return retval;
}

function openWindow(theURL, winName, features){
  if(forcedRefresh == false && alreadyopen[winName] && !newwin[winName].closed){
    newwin[winName].focus();
  }
  else{
    alreadyopen[winName] = 1;	
    newwin[winName] = window.open(theURL, winName, features);
    newwin[winName].focus();
  }
  if(!theURL) return newwin[winName];
}

function openMediaBrowser(openName) {
	id = openName;
	openCenteredWindow('browse_media.php','browse','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no','300','500');
	
}

function setClassname(id, classname){ document.getElementById(id).className = classname; }
function getClassname(id){ return document.getElementById(id).className; }
function replaceClassname(id, find, replace){ setClassname(id, getClassname(id).replace(new RegExp(find), replace)); }

function showTab(newTab){
  if(currentTab != newTab) {
    replaceClassname(newTab, 'invisible', 'visible');
    replaceClassname(newTab + '_title', 'category_closed_link', 'category_open_link');
  }
  
  if (currentTab != null) {
    replaceClassname(currentTab, 'visible', 'invisible');
    replaceClassname(currentTab + '_title', 'category_open_link', 'category_closed_link');
  }
  
  if(currentTab != newTab) currentTab = newTab;
  else currentTab = null;
}

function confirmDelete(object) {
	return confirm("Are you sure you want to delete '" + object + "' from the database?");
}

function confirmDeletePrompt(type, object) {
	var confirmPrompt = prompt('Deletion of a ' + type + ' will delete all projects listed under that ' + type + '.\n\nIf you wish to delete \'' + object + '\' from the database please enter the word DELETE into the box below.', '');

	if(confirmPrompt == '' || confirmPrompt == null) return false;
	else if(confirmPrompt.toLowerCase() == 'delete') return true;
	else return false;
}