// $Id: scps.js,v 1.10 2004/09/09 16:30:08 spencern Exp $

var base = jsBase;
var weePopUp = null;
var includeExternalJSFile = false;

function onloadFunctions(){
	if(includeExternalJSFile){
		doInit();
	}
}

function doInit(){

}

function openWin( url , width , height, featureSwapList ){
	var fWidth = 810;
	if( width && width != "" ){
		fWidth = width;
	}
	var fHeight = 610;
	if( height && height != "" ){
		fHeight = height;
	}
	if(weePopUp){
		weePopUp = window.open('', 'weePopUp' , 'width=100,height=100,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,left=1700,top=1700' );
		weePopUp.close();
		weePopUp = null;
	}
	var fToolbar = 'no';
	var fScrollbars = 'yes';
	var fStatus = 'yes';
	var fLocation = 'no';
	var fResizable = 'yes';
	if(featureSwapList){
		featureSwapArray = featureSwapList.split(',');
		for(var i=0; i < featureSwapArray.length; i++){
			if(featureSwapArray[i] == "scrollbars"){fScrollbars = 'no';}
			if(featureSwapArray[i] == "toolbar"){fToolbar = 'yes';}
			if(featureSwapArray[i] == "status"){fStatus = 'no';}
			if(featureSwapArray[i] == "location"){fLocation = 'yes';}
			if(featureSwapArray[i] == "resizable"){fResizable = 'no';}
		}
	}
	weePopUp = window.open( jsBase + url , 'weePopUp' , 'width=' + fWidth + ',height=' + fHeight + ',toolbar='+ fToolbar +',location='+ fLocation +',directories=no,status='+ fStatus +',scrollbars='+ fScrollbars +',resizable='+ fResizable +',menubar=no,left=180,top=20' );
}

var navElement = null;
function navLink(elementId){
	if(!elementId){
		if(navElement){
			navElement.className = 'formatLinkNav';
			navElement = null;
		}
	} else{
		navElement = document.getElementById(elementId);
		if(navElement){
			navElement.className = 'formatLinkNav-over';
		}
	}
}


function submitLevel( searchId, level ) {
  document.getElementById(searchId).value = level;
  document.searchform.submit();
}

function highSearchLevel( searchId ) {
    document.getElementById(searchId).value = '1';
    document.searchform.submit();
}

function lowSearchLevel( searchId ) {
    document.getElementById(searchId).value = '0';
    document.searchform.submit();
}

function submitID( groupId, timeId, groupnum ) {
    document.getElementById(groupId).value = groupnum;
    document.getElementById(timeId).value = 0;
    document.searchform.submit();
}

function submitTime( timeId, time ) {
    document.getElementById(timeId).value = time;
    document.searchform.submit();
}

function submitSort( sortId, sort ) {
    var val = new String(sort);
    document.getElementById(sortId).value = val;
    document.searchform.submit();
}

function submitCart(groupId, groupByCart, statusId, inCart, oldGroupBy, oldProfileItemId, profileId, searchGroupID) {
    document.getElementById(groupId).value = groupByCart;
    document.getElementById(statusId).value = inCart;
    updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupID);
    document.searchform.submit();
}

function submitProfile(groupId, byProfile, statusId, inProfile, oldGroupBy, oldProfileItemId, profileId, searchGroupID) {
    document.getElementById(groupId).value = byProfile;
    document.getElementById(statusId).value = inProfile;
    updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupID);
    document.searchform.submit();
}

function changeFilter(filterId) {
    var filter = document.searchform.statusSelect.options[document.searchform.statusSelect.selectedIndex].value;
    document.getElementbyId(filterId).value = filter;
}

function updateShoppingCart(sessionid, remove, add) {
	var imageElement = document.getElementById("img"+ sessionid);
	var txtElement = document.getElementById("txt"+ sessionid);
	if(imageElement.className == "imageDelete") {
		if(window.document.applets.ShoppingCart) {
			var jsp = window.document.applets.ShoppingCart.doPostAction(sessionid, remove);
			if( jsp.indexOf("blank") != -1 ) {
				imageElement.className = "imageAdd";
				imageElement.alt = "Add session to My Interests";
				if(txtElement){
					txtElement.innerHTML = "Add to My Interests";
				}
			} else {
				doAppletPopup();
			}
		}
	} else {
		if(window.document.applets.ShoppingCart) {
			var jsp = window.document.applets.ShoppingCart.doPostAction(sessionid, add);
			if( jsp.indexOf("blank") != -1 ) {
				imageElement.className = "imageDelete";
				imageElement.alt = "Remove session from My Interests";
				if(txtElement){
					txtElement.innerHTML = "Remove";
				}
			} else if( jsp.indexOf("maxExceeded") != -1 ) {
				doMaxExceededPopup();
			} else {
				doAppletPopup();
			}
		}
	}
}

function helpwindow(url) {
    var helpwin = window.open("", "helpwindow", "width=550,height=575,scrollbars=yes")
    helpwin.focus()
    helpwin.location=url
}

function download(url) {
    var download = window.open(base+url, "download", "width=550,height=400,scrollbars=yes")
    download.focus()
}

function doAppletPopup() {
	var url = "jsp/appletWarning.jsp";
	openWin(url);
}

function doMaxExceededPopup() {
    var url = "jsp/cartMaxExceeded.jsp";
    openWin(url);
}

function verify(URL,statement) {
    if (confirm(statement))
      document.location = URL;
}

function updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId) {
    var newGroupBy = document.getElementById(groupId).value;
    var newProfileItemID = document.getElementById(profileId).value;
    if( oldGroupBy != newGroupBy || oldProfileItemId != newProfileItemID ) {
      document.getElementById(searchGroupId).value = 1;
    }
}
function go(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId) {
    updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId);
    document.searchform.submit();
}
  
function submitGroup( group, firstIf, filterId, showAll, secondIf, profileId, oldGroupBy, groupId, oldProfileItemId, searchGroupId ) {
    if( firstIf) {
      if(document.getElementById(filterId))
        document.getElementById(filterId).value = showAll;
    } else if( secondIf ) {
      document.getElementById(profileId).value = 0;
    }
    document.getElementById(groupId).value = group;
    updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId);
    document.searchform.submit(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId);
}
    
function submitProfileID( group, profileItemId, firstIf, filterId, showAll, profileId, groupId, oldGroupBy, oldProfileItemId, searchGroupId ) {
    if( firstIf ) {
      if(document.getElementById(filterId))
        document.getElementById(filterId).value = showAll;
    }
    document.getElementById(profileId).value = profileItemId;
    document.getElementById(groupId).value = group;
    updateGroupID(oldGroupBy, groupId, oldProfileItemId, profileId, searchGroupId);
    document.searchform.submit();
}

var popupWin;
function openWin(popupURL) {
    if ((popupWin != null) && !popupWin.closed)
      popupWin.close();
    popupWin = window.open(base + popupURL,"popup",'height=500,width=785,scrollbars=1');
    popupWin.focus();
}
  
function openWin2(popupURL) {
    popupWin = window.open(base + popupURL,"popup",'height=250,width=550,scrollbars=1');
    popupWin.focus();
}

function closePopup() {
    if (popupWin != null) {
      if (!popupWin.closed) {
        popupWin.close();
      }
      popupWin = null;
    }
}

function doSchedulePrintView(baseURL, personID) {
    var printWin;
	var URL = baseURL + "schedule/printView.jsp";
    printWin = window.open(URL,personID,'height=600,width=600,resizable=1,scrollbars=1,menubar=1');
    printWin.focus();
}

function doScheduleBadgePrintView(baseURL, personID, small) {
    var printWin;
	var URL = baseURL + "schedule/printView.jsp?" + small + "=1";
    printWin = window.open(URL,personID,'height=600,width=600,resizable=1,scrollbars=1,menubar=1');
    printWin.focus();
}

var PopWin = null;
function winopen(url) {
    PopWin = window.open(url,"PopWin","height=300,width=590,scrollbars,resizable");
}

function openSurveyWin(popupURL) {
    surveyWin = window.open(popupURL,"popup",'height=550,width=750,scrollbars=1');
    surveyWin.focus();
}
  