// ----------------------------------------------------------------------------
//	alignPopup
//-----------------------------------------------------------------------------
//	Description:
//		positions a child window with its parent window.
//	Input:
//		object reference of popup window
//	Output:
//		n/a - (positions popup window)
//	Author:
//		Mitchell Wagner - 05/13/02
//  03/16/2006 - CR - made changes to fix the WebMD issue displaying multi frames
// ------------------------------------------------------------------------------
function alignPopup(objPopup){
		//align pop up window
		var leftpos = window.screenLeft + 100;
		var toppos = window.screenTop + 2;
		
//		if(window.parent){
//			// can not use parent.screenTop property due to cross frame security issue
//			// so just remove some pixels if parent exists
//			toppos = toppos - 100; // if parent move up x pixels 
//		}
		objPopup.moveTo(leftpos,toppos);
}
// ************ partnerExit  *************************
// use this function throughout the app when 
// returning to the partners desired page
// (Travels through logoff page to clear session and add touch point)
// ***************************************************
function partnerExit(returnPage, blnUseParent){

	var logoffPage = '/logoff.asp';
	if(returnPage.indexOf("edetailing.astrazeneca") != -1)
		{
			document.location.href = "https://edetailing.astrazeneca-us.com/edetail/custom/16_sample_iframe.aspx?close=yes";
			return;
		}

	if((returnPage.indexOf("staging.kingondemand") != -1) || (returnPage.indexOf("kingondemand") != -1))
		{
		    document.location.href = logoffPage; // first fire up logoff page (in this window) to clean session
	        return;
		}

	// if this is a pop up window
	if(window.opener){ 
		// and the main window is still open
		if(window.opener.closed==false){
			window.opener.focus(); // set focus to the main window (that opened this window)
		}
		document.location.href = logoffPage; // navigate to logoff page then close window
		window.close(); // close this window
	}
	else{	// not a pop up window
		// if this window is not the parent window
		if(self != parent){
			// and this partner is setup to go to return page using parents window
			if(blnUseParent=='True' || blnUseParent==true){
				// pdr docs travel through this branch
				document.location.href = logoffPage; // first fire up logoff page (in this window) to clean session
				parent.window.location.href = returnPage; // then navigate to returnPage using the parent window
			}else{
				// mdc docs travel through this branch
				document.location.href = logoffPage + '?red=' + returnPage; // go to logoff page (send it the page to use for redirect)
			}
		}
		else{	// this window is the parent
			// local login docs travel through this branch (lilly/pdi)
			document.location.href = logoffPage; // go to logoff page (it gets the redirect page from Session("Referrer")
		}
	}
}
// ************ clearHistAndLoad *********************
// use this function throughout the app when 
// needing to clear x history pages then load
// a page.
// ***************************************************
function clearHistAndLoad(historyStepsToClear, pageToLoad){
	// convert to negative number
	//var negSteps = (0 - historyStepsToClear)
	//window.history.go(negSteps);
	//window.location.replace(pageToLoad);
	document.location.href = pageToLoad;
}

// ************ closeRefresh *************************
// use this function throughout the app when 
// closing a pop up and then refresh its parent page
// we need to refresh the parent page to update its
// timeout value
// ***************************************************
function closeRefresh(page){
	// POP UP WINDOW FIX
	// if the top window does not have frames we are in a pop-up
	if(top.length==0){
		document.location.href = page;
		return;
	}

	if(window.opener && window.opener.closed==false){	// if this window has a parent (that is still around)
			// navigate the parent to page
			//window.opener.location.replace(page);
			window.opener.navigate(page);
			// and set focus to parent
			window.opener.focus();
			// now close this pop up window
			window.close();
	}
	else{	// no parent around - so just navigate this window
		//window.location.replace(page);
		document.location.href = page;
	}
}

// ************ closeWin *************************
// use this function throughout the app when 
// closing a pop up (it will bring focus to parent
// if a parent exists and hasnt been closed).
// NOTE: if a refresh of parent page is
// needed use closeRefresh function instead
// ***************************************************
function closeWin(page){
	if(window.opener){
		// make sure parent has not been closed
		if(window.opener.closed==false){
			window.opener.focus();
		}
	}
	window.close();
}

//*************** openEntrustUrl ***************//
function openEntrustUrl(){
    // The digitalid variable is the PROD eMedSample website certificate's 
    // Issuer Digest Serial Number from Verisign. It is updated annually.
	var digitalid='6c69b999b52c5fd1d201df8dee32dbab'
	var frm = document.forms["0"];
    	var EntrustPopup=window.open('/common/pleasewait.html','EntrustPopup','width=556 ,height=450,toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
	alignPopup(EntrustPopup);
	frm.target = 'EntrustPopup';
	frm.action='https://www.entrust.net/customer/profile.cfm?domain=www.emedsample.com';
	frm.submit();
}
function openTips(path){
	if(screen.availHeight>600&&screen.availWidth>800){
		var win=window.open(path,'win1','width=520, height=575, status=no,scrollbars=yes');
		alignPopup(win);
		win.focus();
	}
	if(screen.availHeight<=600&&screen.availWidth<=800){
		var win=window.open(path,'win1','width=520, height=500, status=no,scrollbars=yes');
		alignPopup(win);	
		win.focus();
	}
}
function openHelp(page){
	// Used on /home/help and prescriber/profile/help pages. Bill S. 12/13/02
	var helpWin1=window.open(page,'helpWin1',config='height=475,width=516,scrollbars=yes,resizable=yes');
	alignPopup(helpWin1);
}
function openInfo(page){
	// Used on /home/faq and any info-type pages requiring h=475 and w=667. Bill S. 12/14/02
	var helpWin2=window.open(page,'helpWin2',config='height=475,width=667,scrollbars=yes,resizable=yes');
	alignPopup(helpWin2);
}
function openContact(path){
	var win=window.open(path,'win1','width=350, height=220, status=no,scrollbars=no');
	alignPopup(win);
	//win.moveTo(0,0);	
	win.focus();
}

function openAbouteMedSample(path){
	var win=window.open(path,'win1','width=480, height=250, status=no,scrollbars=yes');
	alignPopup(win);	
	win.focus();
}

function openAboutus(path){
	var win=window.open(path,'win1','width=550, height=500, status=no,scrollbars=yes');
	alignPopup(win);	
	win.focus();
}

function logOff(){	
	var bOK = false;
	bOK = confirm("Are you sure you want to Log Off? \nYou may lose your data if you are currently in the middle of a process.");
	if (!bOK) {
		return;
				}
	else{window.location.href="/logoff.asp";
			}			

}

function MM_preloadImages() { //v3.1
  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_swapImgRestore() { //v3.1
  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_findObj(n, d) { //v3.1
  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;
}

function MM_swapImage() { //v3.1
  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 MM_setTextOfLayer(objName,x,newText) { //v3.1
	if ((obj=MM_findObj(objName))!=null) 
		with (obj)
   			if (navigator.appName=='Netscape') {document.write(unescape(newText)); document.close();}
   			else innerHTML = unescape(newText);
}

function SetColumnWidths()  {
    document.write("<img src='/images/1clearpx.gif' width='30' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='120' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='30' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='110' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='10' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='80' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='60' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='30' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='10' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='30' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='30' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='10' height='1'></td>");
    document.write("<td><img src='/images/1clearpx.gif' width='50' height='1'>");
}

//Preload items so that Netscape's annoying lack of ability to redraw select menus
//won't cause problems.
function loadOptions(leftList, rightList, itemsArray, valueArray) {
        leftList.length=itemsArray.length;
        for ( var i=0; i < itemsArray.length; i++ ) {
                leftList.options[i].value  = valueArray[i];
                leftList.options[i].text   = itemsArray[i];
        }
        rightList.length=0;
        rightList.options.value  = null;
        rightList.options.text   = null;
        leftList.selectedIndex = 0;
        rightList.selectedIndex = 0;
}


function MM_popupMsg(theMsg) { //v2.0
  alert(theMsg);
}

function chk1q(strIn) {
	// check for single and double quotes in the textstring so it doesn't break other javascript
	var strOut = new String("");
	if(strIn.indexOf("\'")!=-1 && strIn.indexOf("\\\'")==-1){
		strOut = strIn.replace(/\'/g,"\\'");
	} else { strOut = strIn; }
/*	if(strOut.indexOf('\"')!=-1 && strOut.indexOf('\\\"')==-1){
		strOut = strOut.replace(/\"/g,'\\"');
	} else { strOut = strOut; }  */
	return strOut;
}
function addToFavorites(bmTitle){ 
	if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
		if (bmTitle.length != 0) {
			window.external.AddFavorite(location.href,bmTitle);
		}
		else {
			window.external.AddFavorite(location.href,document.title); 
		}
	}
}
var oldColor;
function ChangeColor(color, control) 
{
	if(document.getElementById(control))
	{
		oldColor = document.getElementById(control).style.backgroundColor;
		document.getElementById(control).style.backgroundColor=color;
	}
}
			
function RestoreColor(control)
{
	if(document.getElementById(control))
	{
		document.getElementById(control).style.backgroundColor=oldColor;
	}				
}