<!-- Javascript Aware bib -->
function popup(url,features) {
	window.open(url,'newwin','status=yes,scrollbars=yes,'+features);
}

var viewerPostion 		= 0;

function viewerNext(viewerImageId)
{	
	var vi 					= document.getElementById(viewerImageId);

	if(vi != null)
	{
		viewerPostion 	= (viewerPostion == viewerImages.length-1 ? 0 : viewerPostion + 1);
		vi.src 			= imagesFolder + viewerImages[viewerPostion];
	}
}

function viewerPrevious(viewerImageId)
{
	var vi 					= document.getElementById(viewerImageId);
	
	if(vi != null)
	{
		viewerPostion 	= (viewerPostion == 0 ? viewerImages.length-1 : viewerPostion - 1);
		vi.src 			= imagesFolder + viewerImages[viewerPostion];
	}
}

//function for setting height of div wrapper, otherwise we have a grey area
function adaptWrapperHeight()
{
	var wrapper = document.getElementById('wrapper');
	var extra = document.getElementById('extra');
	
	if(extra && (wrapper.offsetHeight < extra.offsetHeight))
	{
		wrapper.style.height = extra.offsetHeight + "px";
	}
}

function KeyValue( key, value )
{
    this.key = key;
    this.value = value;
}

//Map functionality
function Map()
{
    this.array = new Array();
}

Map.prototype.put = function( key, value )
{
    if( ( typeof key != "undefined" ) && ( typeof value != "undefined" ) )
    {
        this.array[this.array.length] = new KeyValue( key, value );
    }
}

Map.prototype.get = function( key )
{
    for( var k = 0 ; k < this.array.length ; k++ )
    {
        if( this.array[k].key == key ) {
            return this.array[k].value;
        }
    }
    return "";
}

Map.prototype.getKey = function( index )
{
	if(index < this.array.length)
	{
		return this.array[index].key;
	}
    
  return "";
}

Map.prototype.getValue = function( index )
{
	if(index < this.array.length)
	{
		return this.array[index].value;
	}
    
  return "";
}

Map.prototype.length = function()
{
    return this.array.length;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function enableTxtGroup()
{
  var txtGroup = document.settings.txtGroup;
  var trOtherGroup = document.getElementById('trOtherGroup');
  
  for(var i = 0; i < document.settings.selGroup.options.length; i++)
  {
    var option =  document.settings.selGroup.options[i];
    if(option.selected && option.text == 'Other')
    { 
      trOtherGroup.style['visibility']="visible";
      txtGroup.focus();
      return 1;
    }
  }

  txtGroup.blur();
  trOtherGroup.style['visibility']="hidden";
  return 1;
}

function GoToStep(fn)
{ 
  var elFn = document.getElementById('fn');
  elFn.value = fn;
  
  document.form.submit();
}

function MakeVisible()
{
  var selType = document.getElementById('question_type');
  
  var tblText = document.getElementById('text');
  var tblTextarea = document.getElementById('textarea');
  var tblCheckbox = document.getElementById('checkbox');
  var tblRadio = document.getElementById('radio');
  var tblSelect = document.getElementById('select');
  
  tblText.style['display'] = "none";
  tblTextarea.style['display'] = "none";
  tblCheckbox.style['display'] = "none";
  tblRadio.style['display'] = "none";
  tblSelect.style['display'] = "none";
  
  for(var i = 0; i < document.form.question_type.options.length; i++)
  {
    var option =  document.form.question_type.options[i];
    if(option.selected)
    {
      var tblTable = document.getElementById(option.value);
      tblTable.style['display'] = "block";
      return 1;
    }
  }
  
}