function open_popupimg(page) {
alert("window open");
window.open(page,'popupimg','width=550,height=400,scrollbars=yes,resizable=yes,screenX=100,screenY=100');
alert("111111window open");
//    window_handle.focus();
	//return false;
}
function checkFields(errEmail, errPassword)
{
	document.forms['signinform'].Email.value = trimstr(document.forms['signinform'].Email.value);
	document.forms['signinform'].Password.value = trimstr(document.forms['signinform'].Password.value);
	
	if (document.forms['signinform'].Email.value == "" && document.forms['signinform'].Password.value == "")
	{
		alert(errEmail + '\n' + errPassword);
		document.forms['signinform'].Email.focus();
		return false;
	}
	if (document.forms['signinform'].Email.value == "")
	{
		alert(errEmail);
		document.forms['signinform'].Email.focus();
		return false;
	}
	if (document.forms['signinform'].Password.value == "")
	{
		alert(errPassword);
		document.forms['signinform'].Password.focus();
		return false;
	}
	
	return true;
}

function checkSearch(formName)
{
	strSearch = trimstr(document.forms[formName].searchterm.value);

	if (strSearch == "")
	{
		alert("Please enter search criteria");
		document.forms[formName].searchterm.focus();
		return false;
	}
	
	len1 = strSearch.length;
	strSearch = strSearch.replace(/[^a-zA-Z 0-9]+/g,'');
	len2 = strSearch.length;

	if (len1 != len2)
	{
		alert("Special characters are not allowed in search criteria");
		document.forms[formName].searchterm.focus();
		return false;
	}
	
	return true;
}
	
function RoundTo2dp(X)
{
	return Math.round(X * 100) / 100;
}

function open_help(page)
{
	window_handle = window.open (page, 'popuphelp', 'width=740, height=400, scrollbars=yes, resizable=yes, screenX=200, screenY=350');
	window_handle.moveTo((screen.width-740)/2,(screen.height-400)/2);
    window_handle.focus();
	return false;
}

function blankimagepopup(url)
{
	if (typeof(imgpop) != "undefined") {
			imgpop.close();
	}
	// open popup window
	imgpop = window.open('about:blank','imgpop2','location=no,menubar=no,scrollbars=yes,status=no,toolbar=no');
	//imgpop.document.open();
	imgpop.document.location.href = url;
	//imgpop.document.close();
}

function checkemail(email)
{
	email = String(email);
	var at = "@";
	var dot = ".";
	var lstr = email.length;
	var lat = email.indexOf(at);
	var ldot = email.indexOf(dot);
	
	if (trimstr(email) == '')
		return false;
	
	if (email.indexOf(at)==-1)
		return false;
	
	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr)
	   return false;
	
	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr)
	    return false;

	if (email.indexOf(at,(lat+1))!=-1)
	    return false;

	if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot)
	    return false;

	if (email.indexOf(dot,(lat+2))==-1)
	    return false;
		
	if (email.indexOf(" ")!=-1)
	    return false;

	return true;
}

function trimstr(str)
{
	while (str.substring(0,1) == ' ')
	    str = str.substring(1,str.length);

 	while (str.substring(str.length-1,str.length) == ' ')
	    str = str.substring(0,str.length-1);
	
	return str;
}

function blankscwindow(url)
{
	if (typeof(imgpop) != "undefined") {
			imgpop.close();
	}
	// open popup window
	imgpop = window.open('about:blank','imgpop2','location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes');
	//imgpop.document.open();
	imgpop.document.location.href = url;
	//imgpop.document.close();
}

function validateFields()
{
	if (document.forms[0].Name.value == "")
	{
		alert("Please enter your name");
		document.forms[0].Name.focus();
		return false;
	}
	if (!checkemail(document.forms[0].Email.value))
	{
		alert('Please enter a valid email address.');
		document.forms[0].Email.focus();
		return false;
	}
	if (document.forms[0].Topic.value == "")
	{
		alert("Please select a topic");
		document.forms[0].Topic.focus();
		return false;
	}
	if (document.forms[0].Message.value == "")
	{
		alert("Please enter message");
		document.forms[0].Message.focus();
		return false;
	}
	return true;
}
	
function open_ilink(page)
{
    window_handle = window.open(page,'ilink','width=725,height=400,scrollbars=yes,resizable=yes,screenX=200,screenY=350');
	window_handle.moveTo((screen.width-725)/2,(screen.height-400)/2);
    window_handle.focus();
    return false;
}

function open_iha(page,section)
{
	window_handle = window.open ('/common/showfiletype.cfm?type=h&section=' + section + '&dirFileName=' + page, 'popupiha', 'width=900, height=585, scrollbars=no, resizable=yes, screenX=200, screenY=350');
	window_handle.moveTo((screen.width-900)/2,(screen.height-585)/2);
	window_handle.focus();
	return false;
}

function openNetterWindow(fileName,type)
{
	imgpop = window.open('about:blank','imgpop2','location=no,menubar=no,scrollbars=yes,status=no,toolbar=no');
	imgpop.document.open();
	imgpop.document.location = '/common/showimage.cfm?bFlag=1&type=' + type + '&imgFile=' + fileName;
	imgpop.document.close();
}

// Videos html file functions
function MM_findObj(n, d) { //v3.0
	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); return x;
	}
	
/* Functions that swaps images. */
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='/common/showimage.cfm?type=n&imgFile=' + a[i+2];}
	}
	
/* Functions that handle preload. */
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];}}
	}

// MCQ Functions
function fillEndTime()
{
	var endTime = new Date();
	var calEndTime = endTime.getTime();
	var calStartTime = document.forms[0].startTime.value;
	var diff = ((calEndTime - calStartTime) / 1000) / 60;
	var tmpTime = document.forms[0].elapsedTime.value;
	document.forms[0].elapsedTime.value = RoundTo2dp(parseFloat(tmpTime) + parseFloat(diff));
}

function clearRadioButtons()
{
	for (cnt=0; cnt<=document.forms[0].optionsMCQ.length-1; cnt++)
		document.forms[0].optionsMCQ[cnt].checked = 0;
	
	return false;
}

// Case Study Functions
function fillCasePageIndexVal(casepageIndex, flag)
{	
	if (flag)
		document.forms[0].casepageIndex.value = casepageIndex - 1;
	else
		document.forms[0].casepageIndex.value = casepageIndex + 1;
}

function showhideAns()
{
	if ($(casestudyAns).className == "casestudyAnsHide")
	{
		document.forms[0].imgShowhideAns.src = "/images/button_anshide.gif";
		document.forms[0].imgShowhideAns.alt = "Hide Answer";
		$(casestudyAns).className = "casestudyAnsShow";
	}
	else
	{
		document.forms[0].imgShowhideAns.src = "/images/button_ansshow.gif";
		document.forms[0].imgShowhideAns.alt = "Show Answer";
		$(casestudyAns).className = "casestudyAnsHide";
	}
}

function disableLinks()
{
	var a = document.anchors;
	for(var i=a.length-1;i>=0;i--)
	{
		if(a[i].href)
		{
			while(a[i].hasChildNodes())
			{
				a[i].parentNode.insertBefore(a[i].childNodes[0],a[i]);
			}
			a[i].parentNode.removeChild(a[i]);
		}
	}
}

function printthispage()
{
	var printpage = window.open('about:blank','printthispage','location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,width=693,height=573');
	
	var pagecontent = '<html><head><title>Netter Anatomy</title><link rel="stylesheet" type="text/css" href="/css/common.css" /><link rel="stylesheet" type="text/css" href="/css/book.css" /><script type="text/javascript" src="/js/common.js"></script></head><body onload="disableLinks();"><div align="center" style="margin-top:5px;"><input type="button" onclick="window.print();" value="Print">&nbsp;&nbsp;<input type="button" onclick="window.close();" value="Close"><br/><br/><hr/></div><style type="text/css">.noprint{display:none;}.back2top{display:none;}</style> <div id="printcontent" style="width:665px;">' + document.getElementById("pagecontent").innerHTML + '</div></body></html>';
	
   printpage.document.open();
   printpage.document.write(pagecontent);
	printpage.document.close();
	
	printpage.moveTo((screen.width-693)/2,(screen.height-573)/2);
	printpage.focus();
}

function openSpotTest()
{
	left = (screen.width-910)/2;
	top2 = (screen.height-600)/2;
	myWindow = window.open("/reviewcenter/spotmaterial/index.html", "tinyWindow", 'toolbar=0,status=0,width=910,height=600,left='+left+',top='+top2); 
	myWindow.focus();
}

// spot test stuff - added by Rob Lowe 14th Novemeber 2006 

var nwin=null
var bclr="##CCCCCC"

function newWindow()
{
	TheNewWin =window.open("/reviewcenter/spotmaterial/main.html","TheNewpop","left=0,top=0,width=800,height=537,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function fchangeclass2(lparam)
{
   lparam.className = 'btnStyle_mo'
}

function fchangeclassl2(lparam)
{
   lparam.className = 'btnStyle'
}
