function openSmallWindow(whichArray, width, height)
{
	var ScreenWidth=window.screen.width;
	var ScreenHeight=window.screen.height;
	placementx=(ScreenWidth/2)-((800)/2);
	placementy=(ScreenHeight/2)-((550+50)/2);
	thisWindow = window.open(whichArray,"theWin","width="+width+",height="+height+",toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,resizable=1,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
	window.setTimeout('thisWindow.focus()',100)
}

function releaseSeats(text)
{
	if(confirm(text))
		location.href='controllers/releaseSeat.php';
	else
		return false;
}

function validateMOD(radioObject, msg)
{
	valid = false;

	for(i = 0; i < radioObject.length; i++)
	{
		if(radioObject[i].checked)
			valid = true;
	}

	if(!valid)
		alert(msg);

	return valid;
}

function toggleObjectVisibility(obj, displayType, thisObj, textunit1, textunit2)
{
	if((displayType == undefined) || (navigator.appName == 'Microsoft Internet Explorer'))
		displayType='block'

	if(obj.style.visibility == 'hidden')
	{
		obj.style.visibility='visible';
		obj.style.display=displayType;
		if(thisObj && textunit1)
			thisObj.innerHTML=textunit1;
	}
	else
	{
		obj.style.visibility='hidden';
		obj.style.display='none';
		if(thisObj && textunit2)
			thisObj.innerHTML=textunit2;
	}
}

function preProcessBrowse() {
	if( $('major_cat').value == "NULL" ){
        $('major_cat').disable();
    }
	else {
		$('major_cat').enable();
	}	
    
    if( $('minor_cat').value == "NULL" ){
        $('minor_cat').disable();
    }
    else {
		$('minor_cat').enable();
	}	

    if( ($('rdc_select') && $('rdc_select').value == 'range') || $('type').value == 'range' ) {
            
        // Since we are ranged we have to set the type parameter
        $('type').value = 'RANGE';
        // We also have to disable of the rdc_select input
        if( $('rdc_select') ) {
            $('rdc_select').disable();
        }
        
    }
    else {
        // If the date is not range, change the hidden 'type' field to selected
        $('type').value = 'selected';
        $('calendar_from_input').disable();
        $('calendar_to_input').disable();
        if( !$('rdc_select') ) {
            $('rdc_select').enable();
        }
    }
}
// With this implementation, you don't have to set event handlers on the HTML level (no onclick, onmouseover, or onmouseout)
// This is DropMenu Class Constructor
var DropMenu = Class.create( {
    initialize: function(title, dropdown){
            var timer = null;
            $(title).observe('click', function(e) {
                    $(dropdown).toggle();
            });
            $(dropdown).observe('mouseover', function(e) {
                    clearTimeout(timer);
            });
            $(dropdown).observe('mouseout', function(e) {
                    timer = setTimeout( function(){$(dropdown).hide();},500);
            });
    } // end of initialize
});

function setHidden(field_name, field_value, field_select){

    if (field_name == 'major_cat'){
        $('minor_cat_dropdown').update();
    }
    $(field_name).value=field_value;

    // Do not try to reset the simulated input field for the range dates
    if ((field_name != 'rdc_smonth') &&
        (field_name != 'rdc_sday') &&
        (field_name != 'rdc_syear') &&
        (field_name != 'rdc_emonth') &&
        (field_name != 'rdc_eday') &&
        (field_name != 'rdc_eyear')){
            $(field_name + '_title').update(decodeURIComponent(field_select));
            $(field_name + '_dropdown').hide();
    }

   
}
//////////////////////////////////////////////////////////////////////////
// Build the Minor Category dropdown based on selecting a major cat
//////////////////////////////////////////////////////////////////////////
function build_minor_cat_dropdown(major_cat_id){
    title_span = eval('minor_cat_title_span_' + major_cat_id);

    $('minor_cat_title').update(title_span);
    $('minor_cat_title').removeClassName('off');
    $('minor_cat_dropdown').removeClassName('off');
    
    for( k in categories[major_cat_id] ) {
        var min_cat_anchor = new Element('a', { title: categories[major_cat_id][k].replace("&#39;","'"),
                                                href: ''
                                            }
                                        );
    $(min_cat_anchor).onclick = new Function("setHidden('minor_cat', '" + k + "', '" + categories[major_cat_id][k] + "'); return false;");
    $(min_cat_anchor).update( categories[major_cat_id][k] );
        $('minor_cat_dropdown').appendChild( min_cat_anchor );
    }
}
function restore_minor_cat(sub_cat_TU){
	 $('minor_cat_title').addClassName('off');
	 $('minor_cat_dropdown').addClassName('off');
	 setHidden('minor_cat', 'NULL', sub_cat_TU);
}


function venueLink(venueCode, venueSystem, language)
{
	return '/html/venue.htmI?venue=' + venueCode + '&amp;virt=' + venueSystem + '&amp;l=' + language;
}


function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


function checkPackageEventCheckbox(packCode, childQty, maxQty)
{
	var disabledObjs = new Array();

	if((childQty == 1 && childQty == maxQty) || (maxQty == 0))
	{
		return true;
	}

	cntCheck = 0;

	for(n = 1; n <= childQty; n++)
	{
		obj = document.getElementById(packCode+'_'+n);
		if (obj.disabled && obj.checked) 
			disabledObjs.push(obj);
		if(obj.checked)
			cntCheck++;
	}

	if(cntCheck == maxQty)
	{
		for(n = 1; n <= childQty; n++)
		{
			obj = document.getElementById(packCode+'_'+n);
			if(!obj.checked)
				obj.disabled=true;
		}
	}
	else
	{
		for(n = 1; n <= childQty; n++)
		{
			obj = document.getElementById(packCode+'_'+n);
				obj.disabled=false;
		}
	}
	for(n = 0; n < disabledObjs.length; n++) {
		disabledObjs[n].disabled = true;
	}
}
