function ClearField(TextBox) {
	TextBox.value = '';
}

function openWindow(theURL,winName,features) { //v2.0
  var newWindow = window.open(theURL,winName,features);
  newWindow.focus();
}

function openWindow_w(myform, theURL, winName, webcastid) { //v2.0
 var str = theURL + '?webcastid=' + webcastid
 var features = 'scrollbars=yes,resizable=yes,status=yes,titlebar=yes,toolbar=yes,menubar=yes,toolbar=yes'
  
  if (myform.review[0].checked == true) {
	if (myform.approval.checked == true) {
		var newWindow = window.open(str,winName,features);
		newWindow.focus();
		}
	else {
	alert('Verify that you have read and accept the CE Information and Terms above.')
	}
  }
  else {
		alert('You must complete the CE Activity before you take the test.');
	}
}

function openWindow_ic(myform, theURL, winName, webcastid) { //v2.0
 var str = theURL + '?webcastid=' + webcastid
 var features = 'scrollbars=yes,resizable=yes,status=yes,titlebar=yes,toolbar=yes,menubar=yes,toolbar=yes'
  
	if (myform.approval.checked == true) 
	{
		var newWindow = window.open(str,winName,features);
		newWindow.focus();
	}
	else 
	{
		alert('Verify that you have read and accept the CE Information terms above.')
	}

}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*Style sheet switching code*/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function leaveSite(site) {
	if (confirm('You are now leaving the CVspectrum.org Web Site and moving to an external website independently operated and not managed by ISIS 1. Because ISIS 1 does not control the content of the website you are about to visit, and due to its constantly changing nature, we cannot be responsible for the content, accuracy, practices or standards of any non-ISIS 1 site.\n\nIf you do not wish to leave this site, click Cancel or, click OK to continue.') == 1) {
		window.open(site, 'site','toolbar=yes,width=600,height=400,scrollbars=yes,resizable=yes,menubar=yes')
	}
}
                
function handleEnter (event, buttonReference) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		buttonReference.click();
		return false;
	} 
	else
		return true;
}      

function checkApproval(myform,url, newWin) {
	if (myform.approval.checked == true) {
		if (newWin) {
			window.open(url);
		} else {
			document.location = url;
		}
	} else {
		alert('Verify that you have read and accept the CE Information and Terms above.');
	}
}

function checkApproval_global(url, newWin) {
	var element = document.getElementById('approval');
	if (element.checked == true) {
		if (newWin) {
			window.open(url);
		} else {
			document.location = url;
		}
	} else {
		alert('Verify that you have read and accept the Terms of Use above.');
	}
}

window.onload = initRollovers;

