//bookmark this page
function bookmarkPage(siteName, bookmarkName) {
	//if (bookmarkName != "") {bookmarkName = ' - ' + bookmarkName;}
 	if (navigator.userAgent.indexOf("MSIE") != -1) {
		alert('Press Control+D to bookmark this site.');
		//window.external.AddFavorite(window.location.href, siteName + bookmarkName);
 	} else {
		alert('Press Control+D to bookmark this site.');
	}
}


//variables used to center pop-up windows
var width = screen.width;
var height = screen.height;
var popUpWidth = 0;
var popUpHeight = 0;
var positionTop = 0;
var positionLeft = 0;

function openWindow(pageURL,windowName,pWidth,pHeight,pResize,pScrollbars,pStatus)
{
 	positionTop = ((height/2) - (pHeight/2));
 	positionLeft = ((width/2) - (pWidth/2));
 	popup=window.open(pageURL,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=0,location=0,directories=0,toolbar=0,scrollbars=' + pScrollbars + ',status=' + pStatus);
}

function closePopup(pageURL) {
	opener.location = pageURL;
	self.close();
}

function registerUser(from) {
	pWidth = 409;
	pHeight = 251;
	positionTop = ((height/2) - (pHeight/2));
	positionLeft = ((width/2) - (pWidth/2));
	popup=window.open('/registerUser.cfm?frPg='+from,'Registration', config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=0,menubar=0,location=0,directories=0,toolbar=0,scrollbars=0,status=0');
	popup.focus();
}

function openLogOffWindow() {
	pWidth = 409;
	pHeight = 195;
	positionTop = ((height/2) - (pHeight/2));
	positionLeft = ((width/2) - (pWidth/2));
	popup=window.open('/site_tools/popup/logoff.cfm','LogOff', config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=0,menubar=0,location=0,directories=0,toolbar=0,scrollbars=0,status=0');
	popup.focus();
}

function executeLogOff() {
	window.close();
	opener.location.href = '/index.cfm';
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i < a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkEMail()
{

  //for email validation
  var emailaddress=document.registerform.DoctorEMail.value;
  //alert(emailaddress);
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  //alert(filter.test(emailaddress))
  if (filter.test(emailaddress))
  {
	document.registerform.submit();
    return true;

  }
  else
  {
     alert("Please input a valid email address!")
	 document.registerform.DoctorEMail.focus();
     return false;
	 
  }
}


/*library slide popup*/
function queryString(val) {
	var q  = unescape(location.search.substr(1)).split('&');

	for(var i=0; i<q.length; i++) {
		var t=q[i].split('=');
		if (t[0].toLowerCase()==val.toLowerCase()) return t[1];
	}
	return '';
}

function slideNavigation(direction) {
	if (direction == 'previous') {slide--;}
	if (direction == 'next') {slide++;}
	//slideImg.src = "/coe/images/library/"+ topic + "/slides/" + slide + ".JPG";	
		
	if (speakerSpecific == 1)
		slideImg.src = "/coe/images/library/" + topic + "/" + coe_doctorwebsite  + "/slides/" + slide + ".jpg";
	else
		slideImg.src = "/coe/images/library/" + topic + "/slides/" + slide + ".jpg";
		
	document.getElementById("slide-counter").innerHTML = "Slide " +slide;
	if (slide == 1) {document.getElementById('btn-previous').style.display = "none";} else {document.getElementById('btn-previous').style.display = "inline";}
	if (slide == maxSlide) {document.getElementById('btn-next').style.display = "none";document.getElementById('btn-next_placeholder').style.display = "inline";} else {document.getElementById('btn-next').style.display = "inline";document.getElementById('btn-next_placeholder').style.display = "none";}
}


/* AJAX */

var xmlhttp ;

function getDynamicInfo(str)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url= "getinfo.cfm?qstr="+ str;
	xmlhttp.onreadystatechange=state_Change;	
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	document.getElementById('show_dynamic').innerHTML=xmlhttp.responseText;
}



function state_Change()
{
	if(xmlhttp.readyState==4)
  		{document.getElementById('show_dynamic').innerHTML=xmlhttp.responseText}
}	

/* Navigation check (COE to CLDF) */
	
	function confirmation() {
	
		var answer = confirm("Are you sure to navigate away from Hepatology \nCenters of Educational Expertise website?");
	
		if (answer){
			window.location.href = "/coe/clearSession.cfm";
		}
	
	}
