// ------------------------------------------------
//
// REVISION HISTORY:
//
// Oct 12 2006 changed from staging URL of https://www.webmdhealth.com/apwu/connect.aspx
// to live URL of https://staging.webmdhealth.com/apwu/connect.aspx\
//
// 2006-10-13 YmL:
// . added opening of new window.
//
// 2006-10-14 YmL:
//	.	now uses relative link for XMLHttp callback to get around
//		https: problem.

function UTC_Cost() 
{ 

// collect data and create authentication string
// generate UTC 

var today = new Date(); 
var utc = today.getUTCFullYear() + "-" + (today.getUTCMonth() + 1) + "-" + today.getUTCDate() + "+" + today.getUTCHours() + ":" + today.getUTCMinutes() + ":" + today.getUTCSeconds();

// <STEP 1> pull these fields from database (order is not important) 

var data = new Array();

data["StartID" ] = "587";
data["UTC" ] = utc;

// call encrypt function which will encrypt and sign data 

var encryptedQueryString = encrypt(data);

// alert( encryptedQueryString );

// send encrypted information to WebMD Health Services 
// <STEP 2> the following line transmits the encrypted authentication data to WebMD Health Services TestEncryption page. 

var newwin = window.open();

newwin.document.write("<body>" + "<form name =\"mainform\" method=\"Post\" action=\"https://www.webmdhealth.com/apwu/connect.aspx\">" + "<input type=\"hidden\" name=\"login\" value=\"" + encryptedQueryString +"\">"+ "</form>"+ "<script language=\"javascript\">" + "document.mainform.submit();" + "</script></body>"); 

}

// ------------------------------------------------

function UTC_Hospital() 
{ 
// collect data and create authentication string
// generate UTC 

var today = new Date(); 
var utc = today.getUTCFullYear() + "-" + (today.getUTCMonth() + 1) + "-" + today.getUTCDate() + "+" + today.getUTCHours() + ":" + today.getUTCMinutes() + ":" + today.getUTCSeconds();

// <STEP 1> pull these fields from database (order is not important) 

var data = new Array();

data["StartID"]="550";
data["UTC"] = utc;

// call encrypt function which will encrypt and sign data 

var encryptedQueryString = encrypt(data);

// alert( encryptedQueryString );

// send encrypted information to WebMD Health Services 
// <STEP 2> the following line transmits the encrypted authentication data to WebMD Health Services TestEncryption page. 

var newwin = window.open();

newwin.document.write("<body>" + "<form name =\"mainform\" method=\"Post\" action=\"https://www.webmdhealth.com/apwu/connect.aspx\">" + "<input type=\"hidden\" name=\"login\" value=\"" + encryptedQueryString +"\">"+ "</form>"+ "<script language=\"javascript\">" + "document.mainform.submit();" + "</script></body>"); 
}

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_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_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];}
}

// ------------------------------------------------

/** 
* _postback()
*
* pulled from AreaEdit. See http://www.areaedit.com for more info.
*
* Use XML HTTPRequest to post some data back to the server and do something
* with the response (asyncronously!) 
*/

var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

function _postback(url, data, handler)
  {

  // alert( "htmlarea.js","1539", "_postback() : top with url '" + url + "'" );

  var req = null;
  if(is_ie)
    {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    }
  else
    {
    req = new XMLHttpRequest();
    }

  var content = '';
  for(var i in data)
    {
    content += (content.length ? '&' : '') + i + '=' + encodeURIComponent(data[i]);
    }

  // req.onreadystatechange = callBack;

  // we are doing this synchronously.

  req.open('POST', url, false);
  req.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' );
  //alert(content);
  req.send(content);

  // alert( "Response is '" + req.responseText + "'" );

  return( req.responseText );
  
  } // end of _postback()

// encrypt string using server side perl script. 

function encrypt(data) 
{

// var url = "http://www.apwuhp.com/user-cgi/encrypt.pl";

var url = "/user-cgi/encrypt.pl";


// post the data to the script. A callback will be issued to handle
// the response.

var encryptedString = _postback( url, data ); 

return encryptedString;

}

