/************************************************************************/
/* Try to give the first relevant field the focus.                      */
/************************************************************************/

function TrySetFocus()
{
  if ( ! document.forms                ) return;
  if ( ! document.forms[0]             ) return;
  if ( ! document.forms[0].elements    ) return;

	var pos = document.forms[0].name == 'searchForm' ? 1 : 0;
  var elems = document.forms[pos].elements;

  for ( var i = 0 ; i < elems.length ; i++ )
    {
//	if ( elems[i].type == 'text' || elems[i].type == 'password' ) {
	if ( elems[i].type != 'hidden' && elems[i].type != 'select-one' ) 
    {
//	    alert(elems[i].type);
//        alert(elems[i].name);
        elems[i].focus();
	    return;
	}
 }
//  if ( document.all && document.all.enter ) {
//      document.all.enter.focus();
//  }
}

function TrySubmitForm()
{
  if ( ! window.event ) return;
  if ( window.event.keyCode != 13 ) return;

  if ( ! document.forms ) return;
  if ( ! document.forms[0] ) return;

  if ( ! window.hasSave ) {
    // Do not submit if we already have our own handler.
    document.forms[0].submit();
  }
}

/************************************************************************/

function byebye()
{
    alert("Je kunt altijd terugkomen naar deze site om je assessment af te maken.");
}

/************************************************************************/
/* Prevent being framed.                                                */
/************************************************************************/
/* uitgezet omdat we dit toestaan voor arbounie.nl
if ( self && top && self.location.href != top.location.href ) {
	top.location.href = self.location.href;
}
*/
/************************************************************************/
/* Define the roll over functions.                                      */
/************************************************************************/

function mouse_over(label, count, body1, body2) 
{
    if ( document.images ) {
	if ( count ) {
	    name = 'button_' + count;
	} else {
	    name = label;
	}
	document.images[name].src = over[label].src;
	if ( body1 ) {
	    document.images[body1].src = over[body1].src;
	}
	if ( body2 ) {
	    document.images[body2].src = over[body2].src;
	}
    }
}

function mouse_out(label, count, body1, body2) {
    if ( document.images ) {
	if ( count ) {
	    name = 'button_' + count;
	} else {
	    name = label;
	}
	document.images[name].src = out[label].src;
	if ( body1 ) {
	    document.images[body1].src = out[body1].src;
	}
	if ( body2 ) {
	    document.images[body2].src = out[body2].src;
	}
    }
}

function text_color(label, color)
{
    if ( document.anchors ) {
	for ( var i = 0 ; i < document.anchors.length ; i++ ) {
	    var anch = document.anchors[i];
	    if ( anch.name == label && anch.style ) {
		anch.style.color = color;
	    }
	}
    }
}

function popupPrint(id)
{
  msg = window.open('../home/popup_feedback.php',
		    'feedback',
		    'toolbar=yes,width=770,height=500,directories=no,resizable=yes,status=no,scrollbars=yes,menubar=yes,location=no');
  msg.focus();
}

function storeCaret (textEl) 
{
           if (textEl.createTextRange) 
           textEl.caretPos = document.selection.createRange().duplicate();
        }
        
        function insertAtCaret (textEl, text) 
        {
           if (textEl.createTextRange && textEl.caretPos) 
           {
             var caretPos = textEl.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' 
                          ? text + ' ' 
                          : text;
         }
         textEl.focus();
 }
 
function mySubmit() {
	document.DataForm.onsubmit();
	document.DataForm.submit();
}
 
function launchCenter(url, name, height, width) {
  var str = "scrollbars=yes, height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  return window.open(url, name, str);
}

function SliderValue(id, val)
{
  var form = document.forms[0]

  // Vertaal val naar een waarde tussen de 1 en 5.
	val = Math.floor(val / 101 * 5) + 1;

  var ids = id.split('_');
	if ( ids.length == 3 ) 
    {
			// Nu komt een COMP+ vraag
      form.elements[ids[0]].value = val;

			// Nu komt een NJ vraag
      form.elements[ids[1]].value = (val == 1 || val == 5) ? 1 : 2;

			// Nu komt een COMP- vraag
      form.elements[ids[2]].value = val; // Niet inverteren.
    }
   else	if ( ids.length == 2 ) 
    {
			// Nu komt een COMP- vraag
      form.elements[ids[1]].value = 6 - val; // Wel inverteren.
    }
   else
    {
			// Nu komt een COMP+ vraag
      form.elements[ids[0]].value = val;
    }

}

