//
// This is a collection of javascript functions used by NYU SoMIT
//
// by Tyler 7/2003
// 
// Update: Huming Tang 3/13/2006 created browser detect function
//
// TODO:
//	Make scripts run using a relative path, while still working for hostnames other
//	than *.med.nyu.edu.
//

// Makes popup windows (ugh).
function popUp(URL) {
id = (new Date()).getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=250,height=400');");
}

// Makes popup windows (ugh).
function popUp(URL,width,height) {
return window.open(URL, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height);
}

// Emails the URL of the current page by invoking the user's local mail client.
function emailPageViaClient() {
	mailto_str = "mailto:?subject=" + escape(document.title) +
		"&body=Here is a page at the NYU School of Medicine website I thought may interest you: " +  
		escape(location.href);
	location.href = mailto_str;
}

// Emails the URL of the current page through a web form & script,
// which sends the mail from our web server.
function emailPageViaBrowser() {
	winEmailToAFriend = window.open('http://www.med.nyu.edu/cgi-bin/emailtoafriend.cgi?url=' + escape(document.location) +
		'&title=' + escape(document.title),
		'emailtoafriend',
		'width=475,height=550,toolbar=no,scrollbars=yes,resizable=yes');
	winEmailToAFriend.focus();
}

// Calls a cgi script to format and display a printer-friendly version of the current page.
// **NOTE: Only works with pages that use the standard SoM Dreamweaver template.
//         Otherwise it simply displays the whole page as it was.
function printableVersion() {
	winPrintable = window.open('http://www.med.nyu.edu/cgi-bin/it/web/printable.cgi?url=' +
		escape(document.location),
		'printable',
		'toolbar=no,scrollbars=yes,resizable=yes');
	winPrintable.focus();
}

// Dreamweaver's wrapper function to open new windows
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//test popup blocker for browserDetect feature
function detectPopupBlocker(msg)
{
	var s = popUp("",1,1);

	if (!s)
	{
		alert(msg);
	}
	else
		s.close();
}
//to detect browser setting and redirect inappropriate browser to the specified page
function DetectBrowser(URL)
{
	//insert the redirect url here
	var redirectURL=URL;

	//detect the platform settings using the user agent
	var agt=navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();
	var is_mac   = (agt.indexOf("mac")!=-1); 
	var is_os2   = ((agt.indexOf("os/2")!=-1) || 
					   (navigator.appVersion.indexOf("OS/2")!=-1) ||   
						(agt.indexOf("ibm-webexplorer")!=-1));
	var is_linux = (agt.indexOf("inux")!=-1);
	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );

	//detect if the browser is ie
	var is_ie	= (appVer.indexOf("msie")!=-1);
	var msg = "Your current browser is no longer supported, \nto find out how to update your browser, \nplease enable popup on this site and refresh the page. \n\nThank You.";

	
	//detect if mac and ie, then redirect
	if (is_mac)
	{
		if (is_ie)
		{
			popUp(redirectURL,600,400);
			detectPopupBlocker(msg);
		}
	}

	//use object method to detect browser capability
	try
	{
		var s = agt.platform
	}
	catch(e)
	{
		popUp(redirectURL,600,400);
		detectPopupBlocker(msg);
	}

	
}

//activate browser detect here
DetectBrowser("/unsupportedbrowser.html");

//include cookie functions
<!--#include virtual="/js/cookie_management.js" -->

//find a doctor javascript
/*this function will use the http requester to get the form data, should provide faster data transfer for FAD*/
function getHttpData(params)
{
   
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }


    //http_request.onreadystatechange = insertContents;
    http_request.open('GET', 'logentry?'+params, true);
    http_request.send(null);
    

	
}
