﻿var N=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)<5);
var S=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)>4.9);
var M=(navigator.appName.indexOf('Microsoft')!=-1)

function strtrim() {
  return this.replace( /^\s+/g, "" ).replace(/\s+$/g, "" );
}

String.prototype.trim = strtrim;

//window.history.forward(1);

function clearHeader()
{
		document.all.header_lblError.innerHTML = '';
}

function qsvalue(param)
{
    var href = window.location.href;
    var firstindex = href.indexOf(param + '=');
    
    if(firstindex<0)
        return '';
        
    var secindex = href.indexOf('&', firstindex);
    
    if(secindex<0)
        secindex = href.length;
        
    firstindex += param.length+1;
    
    return href.substring(firstindex, secindex);
}

function openChildWindow(Page,Name,Width,Height, params)
{	
	var left = (screen.availWidth-Width)/2;
	var top = (screen.availHeight-Height)/2;
	var d = new Date();
	if ((Name == null) ||( Name.length == 0))	
		Name = d.getMilliseconds();
	
	if((params==null)||(params.length==0))
		params = 'toolbar=no,resizable=no,scrollbars=no,location=no,';
	
	if(M)
		theWindow = window.open(Page, Name, params + ',top=' + top + ',left=' + left + ',width='+Width+',height='+Height);	
	else
		theWindow = window.open(Page, Name, params + ',screenX=' + left + ',screenY=' + top + ',width='+Width+',height='+Height);
}

function refreshParentWindow(location)
{
	if(window.opener && !window.opener.closed)
	{
		window.opener.location.href = location;
		window.close();
	}
	return false;
}

function closeChildWindow()
{
	window.opener.focus();
	window.close();
	return false;
}

function SubmitParentWin(Url)
{
	var parentWin = window.opener;
	parentWin.document.open()
	parentWin.document.write(getFormHTML(Url));
	parentWin.document.close();
	window.close();
	return false;
}

function SubmitChildWin(Url,width, height, scroll)
{
	var left = (screen.availWidth-width)/2;
	var top = (screen.availHeight-height)/2;
	var d = new Date();
	
	if(M)
		var newwin = open('about:blank', d.getMilliseconds(), 'scrollbars='+ scroll + ',top=' + top + ',left=' + left + ',toolbar=no,location=no,resizeable=yes,width='+width+',height='+ height);
	else
		var newwin = open('about:blank', d.getMilliseconds(), 'scrollbars='+ scroll + ',screenX=' + left + ',screenY=' + top + ',toolbar=no,location=no,resizeable=yes,width='+width+',height='+ height);
		
	newwin.document.open();
	newwin.document.write(getFormHTML(Url));
	newwin.document.close();
	return false;
}

function openMail(from, to, subject, Company, Client)
{
	var url
	url = '/common/mailwindow.aspx?to=' + to + '&from=' + from + '&Subject=' + subject+ '&Company=' + Company + '&Client=' + Client;
	SubmitChildWin(url, 500, 430, 'no');
}


function getFormHTML(Url)
{
	var q = Url.indexOf("?");
	var PostUrl = Url.substring(0,q);
	var ParamString = Url.substring(q+1);
	var Params = ParamString.split('&');
	var i
	var namevalue;
	var formHTML = "<html><body onload='return document.frmPost.submit();'><form name='frmPost' method='post' action='" + PostUrl + "'>"
		for(i=0; i< Params.length; i++)
		{
			namevalue = Params[i].split('=');
			formHTML += "<input type='hidden' name='" + namevalue[0] + "' value='" + namevalue[1].replace("'", "&#039;") + "'>"
		}

	formHTML += "</form></body></html>";
	
	return formHTML;
}

function SubmitNewWin(Url)
{	
	var newwin = open('about:blank', 'submitnewwin', '');
			
	newwin.document.open();
	newwin.document.write(getFormHTML(Url));
	newwin.document.close();
	return false;
}

function submitUrl(Url)
{
	document.open();
	document.write(getFormHTML(Url));
	document.close();
}

function pageSubmit(form,page)
{
	form.page.value=page;
	form.submit();
}

function validate(obj)
{
	if (isNaN(obj.value))
	{
		alert("Please enter a number");
		obj.focus();
	}
	return;
}

function getCookie(key)
{
	var allcookies = document.cookie;
	key += "=";
	var pos = allcookies.indexOf(key);
	
	if(pos !=-1)
	{
		var start = pos + key.length;
		var end = allcookies.indexOf("&", start);
		if(end==-1)
			end = allcookies.length;
		var value = allcookies.substring(start, end);
		value = unescape(value);		
		return value;
	}	
	else
		return "";

}

function setCookie(key, newvalue)
{
	var curValue = getCookie(key);
	var allcookies = document.cookie;
	allcookies = allcookies.replace(key + "=" + curValue, key + "=" + newvalue);
	document.cookie = allcookies;
}

function delCookie(key)
{
	var curValue = getCookie(key);
	var allcookies = document.cookie;
	allcookies = allcookies.replace(key + "=" + curValue, "");	
	document.cookie = allcookies;
}

function swapImage(obj)
{
	var source = obj.src;
	var path = source.substring(0, source.length-7);
	var onoff = source.substring(source.length,source.length-7);

	if(onoff=='off.gif')
		obj.src = path + 'on.gif';
	else
		obj.src = path + '_off.gif';
}

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+
//	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}


/***********************************************************************
function FollowURL(sURL, bReturn, sWndName, sOptions)

Description:
	Shows the off-ramp language to the user before navigating to a third-
	party or global site. 
	
Parameters:
	sURL: string value identifying the URL the user is attempting to navigate to
	bReturn: optional boolean value identifying whether a return value is required by the caller
	sWndName: optional string identifying the name of the target window
	sOptions: optional string identifying window.open options
	
Example:
	FollowURL("http://www.cnn.com", false, "CNN", "top=10,left=10")

************************************************************************/
function FollowURL(sURL, bReturn, sWndName, sOptions)
{
	var sPrompt;
	
	sPrompt = "This link will take you to a site maintained by a third party who is solely responsible for its contents.\n\n AstraZeneca provides this link as a service to web site visitors. AstraZeneca is not responsible for the Privacy Policy of any third party web sites. We encourage you to read the privacy policy of every web site you visit.\n\n Click Cancel to return or OK to continue."
	
	if (bReturn == null)  bReturn = false;
	if (sWndName == null) sWndName = "";
	if (sOptions == null) sOptions = "";
	

	if (confirm(sPrompt))
  	{
		if (sURL != null) window.open(sURL, sWndName, sOptions);
		if (bReturn) return true;
	}
	else	
	{
		if (bReturn) return false;
	}
}

/***********************************************************************
The following three functions are for timeout warning
*  LoadPage: <body onLoad = "LoadPage();" >"
*  openTimeoutWin: open timeoutwin.aspx
*  updateTimeoutWin: refresh the minutes/seconds on timeoutWin.
************************************************************************/

var defaultIntervalMilliseconds = 1500000; // Popup warning message box after 25 minutes (1500 seconds)
var defaultWaitMilliseconds = 300000; // popup window wait 5 minutes (300 seconds)

var timeoutWin;
var intervalID;

function LoadPage() 
{
   var timerID = window.setTimeout('openTimeoutWin()', defaultIntervalMilliseconds);
}

function openTimeoutWin()
{
	var timeout_option;
	
    if (window.showModalDialog)
    {
		timeout_option = "dialogWidth:250px;dialogHeight:210px;help=no;status=no";
		timeoutWin = window.showModalDialog("/common/timeoutwin.aspx", this , timeout_option);
	}
	else
	{
		timeout_option = "toolbar=false" + ",location=false" + ",directories=false"
					 + ",status=false" + ",menubar=false" + ",scrollbars=false"
					 + ",resizable=false" + ",width=250" + ",height=210";

	    timeoutWin = window.open("/common/timeoutwin.aspx", "NewWindow", timeout_option, true );
	    timeoutWin.focus();
	}
}

function updateTimeoutWin()
{
	defaultWaitMilliseconds = defaultWaitMilliseconds - 1000; // refresh every 1 second
	var newDate = new Date(defaultWaitMilliseconds);   
	var second  = newDate.getSeconds();
	var minute  = newDate.getMinutes();

	if(minute < 10)
		minute = "0" + minute;
		
	if(second < 10)
		second= "0" + second;

	paraTime.innerHTML = minute + ":" + second;

	if(minute=="00" && second=="00") // Time Out
	{
		window.clearInterval(intervalID)
		document.all["btnSubmit"].disabled=true;
		var parWin;
		if ( window.opener != null && !window.opener.closed)
				parWin = window.opener;
		else
				parWin = window.dialogArguments;

		var Url = "/logon/logout.aspx?message=";
		Url += "We are sorry, but your session has expired. For security reasons, the information last submitted has not been saved.";
		parWin.document.open();
		parWin.document.write(getFormHTML(Url));
		parWin.document.close();
		self.close();
//		divMsg.innerHTML = "We are sorry but your session has expired. Information not submitted will be lost. You must logon again to resume using LBExpress.";
//		var form =  document.frmTimeout;
//		form.hdnTimeOut.value = 1;
//		document.all.btnCancel.style.display="none";
//		document.getElementById("btnSubmit").value = " OK ";
	}
}

/***********************************************************************
		End of Time Out
************************************************************************/

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_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

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 encodenotes(ctrlName, hdCtrlName)
{
	if (document.all[ctrlName] != null)
	{
		var plainNotes = document.all[ctrlName].innerText;
		if (plainNotes != null && plainNotes.trim() != "")
		{
			//document.all[ctrlName].innerText = encodeURI(plainNotes);
			if (hdCtrlName != null && document.all[hdCtrlName] != null)
			{
				document.all[hdCtrlName].innerText = encodeURI(plainNotes);
				document.all[ctrlName].disabled = true;
			}
			else
			{
				document.all[ctrlName].innerText = encodeURI(plainNotes);
			}
		}
	}
}

