/************************************************************************/
/* 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 elems = document.forms[0].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.                                                */
/************************************************************************/

if ( self != top ) 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);
}


