/*!
* Form check Library 
*
* Copyright 2011, Alexander Shifrin
*
* Date: October 12 08:53:48 2011 
*/
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."

var globalErrMsg = "";
var firstErrField = null;
var errPrefixMissingRequired = "Please enter value for required field: " ;
var errInvalidPhoneNum = "Please enter a valid telephone number.";
var pEntryPrompt = "Please enter ";
var errInvalidDate = "Invalid date. Please enter date in mm/dd/yyyy format. ";

var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

document.oncontextmenu = disableRightClick;
function disableRightClick() {
  alert('Source code is COPYRIGHTED. Please, do not reproduce.');
  return false;
}

function doPeer() {
  alert('Medical Peer Review is a confidential and protected process that allows BWH to evaluate the quality of patient care that is provided, including but not limited to, evaluating the competency of providers and systems issues that may have caused injury.  With Peer Review protection, communications can be made in an open, honest setting, without fearing that evaluations or conclusions made could be disclosed in a legal proceeding (for example, a lawsuit).\r\n\r\nActivities at BWH that are considered protected under medical peer review in Massachusetts include, but are not limited to:  Morbidity and Mortality Rounds, Grand Rounds, Quality Assurance or Improvement Committees (department or hospital-wide), and this Mortality Review Instrument. In addition, certain documents or work product can be part of the process and are protected as well, for example: safety reports, notes, memos, or minutes that result from the activities of a peer review committee.\r\n\r\nIn order to make it easy to identify peer review work product, a header or footer that states \"Confidential - For Peer Review Purposes Only\" should always be used.  This header is already present on this Mortality Review Instrument.');
}

function preventCommand(e) 
{
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  var isCtrl;
	if(e)
	{
	  isCtrl = e.ctrlKey;
	}
	else
	{
	  isCtrl = (e) ? ((e.modifiers & e.CTRL_MASK) == e.CTRL_MASK) : false;
	}
	
	if(isCtrl) 
	{
		if(String.fromCharCode(key).toLowerCase() == 'r') 
		{
		  e.keyCode = 0;
		  return false;
		}
	}
	
	if(key == '116')
	{
		e.keyCode = 0;
		return false;
	}
	
	return true;
}

function checkLength(e,field,length) 
{
//used with keydown to limit the length of an input field ignore delete, backspace and arrow keys
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  if (!(key == 8 || key == 46 || (key >= 37 && key <= 40)))
	{
		if (field.value.length >= length) 
		{
			self.event.returnValue = false
			alert('Length allowed reached');
			if (field.value.length > length) 
			{
				field.value = field.value.substr(0,length);
			}
			return false;
		} 
		else 
		{
			return true;
		}
	} 
	else 
	{
		return true;
	}
}

	  
function dontTab(e)
{
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  if (key == 9)
  {
    e.keyCode = 0;
  } 
}

function doCheckForMRN(e)
{
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  if ((key < 48 || key > 57) && key != 8) // <0, >9,!=backspace
  {
    e.keyCode = 0;
    return false;
  }
}

function doCheckForDate(e)
{
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  if ((key < 47 || key > 57) && key != 8) // <0, >9, !=backspace, !=/
  {
    e.keyCode = 0;
    return false;
  }
}

function doCheckForNumber(e)
{
  var key;
  if (e.keyCode) key = e.keyCode;
  else if (e.which) key = e.which;
  if ((key < 48 || key > 57) && key != 8 && key != 46) // <0, >9, !=backspace, !=/
    e.keyCode = 0;
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0));
}

function isWhitespace (s)
{   
	var i;
	
	if (isEmpty(s)) return true;
	
	for (i = 0; i < s.length; i++)
	{ 
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isDigit (c)
{  
	return ((c >= "0") && (c <= "9"));
}

function isLetterOrDigit (c)
{   
	return (isLetter(c) || isDigit(c));
}

function isInteger (s)
{   
	var i;
	
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

function isFloat (s)
{   
	var i;
	var seenDecimalPoint = false;
	
	if (s == decimalPointDelimiter) return false;
	
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c)) return false;
	}
	return true;
}

function isAlphabetic (s)
{   
	var i;
	for (i = 0; i < s.length; i++)
	{
 		var c = s.charAt(i);
 		if (!isLetter(c)) return false;
	}
	return true;
}

function isAlphanumeric (s)
{   
	var i;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (! (isLetter(c) || isDigit(c) ) ) return false;
	}
	return true;
}

function stripCharsInBag(s, bag) {
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

function checkInternationalPhone(strPhone)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkPhoneNum (theField,sName) 
{
  var ctl = getElement(theField);
  if ((ctl.value == null) || (ctl.value == ""))
	{
		buildErrMsg(errPrefixMissingRequired + sName + ".");
		return;
	}
  if (checkInternationalPhone(ctl.value) == false)
	{
		buildErrMsg(sName + " is a phone number. " + errInvalidPhoneNum);
		return;
	}
	return;
}

function checkRequiredString (theField,sName) 
{
  var ctl = getElement(theField);
  if (isWhitespace(ctl.value)) 
	{
		buildErrMsg(errPrefixMissingRequired + sName + ".");
		if (firstErrField == null) firstErrField = theField;
	}
}

function checkRequiredDate (theField,sName) 
{
  var ctl = getElement(theField);
  if (isWhitespace(ctl.value) || ctl.value == 'mm/dd/yyyy') 
	{
		buildErrMsg(errPrefixMissingRequired + sName + ".");
		if (firstErrField == null) firstErrField = theField;
	}
	else
	{
	  if (!isValidDate(ctl.value))
		{
			buildErrMsg(errInvalidDate + sName + ".");
			if (firstErrField == null) firstErrField = theField;
		}
	}
}

function checkNumericField(theField,sName) 
{
  var ctl = getElement(theField);
  if (!isInteger(ctl.value)) 
		buildErrMsg("Entered value for " + sName + " should be numeric only.");
}

function checkRequiredDropDown (theField,sName) 
{
  var ctl = getElement(theField.id);
  for (var i = 1; i < ctl.length; i++) 
		if (ctl.options[i].selected == true) 
	    return;
	buildErrMsg(errPrefixMissingRequired + sName + ".");  
}

function checkNotRequiredDropDown (theField,sName) 
{
  var ctl = getElement(theField.id);
  if ((ctl.options[0].selected == true))
    ctl.options[0].selected = false;
  return;
}

function checkDate (theField,sName,nMonth,nDay,nYear) 
{  
	if (nMonth == 1 || nMonth == 3 || nMonth == 5 || nMonth == 7 || nMonth == 8 || nMonth == 10 || nMonth == 12) 
	{
		if (nDay < 1 || nDay > 31) 
		{
			buildErrMsg(sName + " is invalid. Please re-enter. ");
	   	if (firstErrField == null) firstErrField = theField;
		}
	}
	
	if (nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11) 
	{
		if (nDay < 1 || nDay > 30) 
		{
			buildErrMsg(sName + " is invalid. Please re-enter. ");
	   	if (firstErrField == null) firstErrField = theField;
		}
	}
	
	if (nMonth == 2 ) 
	{
		if (nYear % 4 == 0) 
		{
			if (nDay < 1 || nDay > 29) 
			{
				buildErrMsg(sName + " is invalid. Please re-enter. ");
		   	if (firstErrField == null) firstErrField = theField;
			}
		}
		else
		{
			if (nDay < 1 || nDay > 28) 
			{
				buildErrMsg(sName + " is invalid. Please re-enter. ");
		   	if (firstErrField == null) firstErrField = theField;
			}
		}
	}
}

function buildErrMsg(newErrMsg) 
{
	if (globalErrMsg != "") 
		globalErrMsg += "\n";
	globalErrMsg += newErrMsg;
}

function checkDisplayError() 
{
	if (globalErrMsg == "") 
		return true;
  else 
	{
		window.alert(globalErrMsg);
		if (firstErrField != null) 
		{
		  var ctl = getElement(firstErrField);
		  ctl.focus();
    	ctl.select();
		}
		return false;
	}  
}

function ValueInArray(arrArray,sValue) 
{
	for (var i = 0; i < arrArray.length; i++)
		if (arrArray[i] == sValue) 
			return true;
	return false;
}

function PrintArray(arrArray)
{
	for (var i = 0; i < arrArray.length; i++)
		alert(arrArray[i]);
}

function promptEntry (s)
{   
	window.status = pEntryPrompt + s;
}

function ClearForm(theForm) 
{
	for (var i = 0; i < theForm.length; i++)
	{
		var theElement = theForm.elements[i];
		
		if (theElement.type == "text" || theElement.type == "hidden") 
			theElement.value = "";
		if (theElement.type == "select-one") 
		{
			for (var j = 0; j < theElement.length; j++) 
				theElement.options[j].selected = false;
			theElement.options[0].selected = true;
			theElement.options[0].selected = false;
		}
		
		if (theElement.type == "select-multiple") 
			for (j = 0; j < theElement.length; j++) 
				theElement.options[j].selected = false;
		
		if (theElement.type == "radio") 
			if (theElement.defaultChecked == true) 
				theElement.checked = true;
			else 
				theElement.checked = false;
	}
	return true;
}

function checkEmail (theField,sName) 
{
  var ctl = getElement(theField.id);
  if (!isEmail(ctl.value)) 
	{
	  buildErrMsg("Please enter a valid email address.");
		if (firstErrField == null) firstErrField = theField.id;
	}
}

function isEmail(EmailAddress)
{
	EmailAddress = Trim(EmailAddress);
  var emailLength = EmailAddress.length;
	if (emailLength > 0) 
	{
		var i, result=true;
    for (i=1; i<emailLength; i++) 
		{
			var hereNow = EmailAddress.charAt(i);
			if (hereNow == "@") 
			{
				var atSign = "good";
				var atPos = i;
			} 
			else if (hereNow == ".") 
			{
				var periodSign = "good";
				var periodPos = i;
			}                       
    }
		if (atSign != "good"  && periodSign != "good") 
			result = false;
		else if (atSign != "good") 
			result = false;
		else if (periodSign != "good") 
			result = false;
		if (emailLength < 5 || atPos < 0 || periodPos < 3) 
			result = false;
		if (emailLength <= periodPos+1) 
			result = false;
		if ((periodPos-atPos) == 1) 
			result = false;
	}
	return result;
}

function LTrim(str)
/**********************************************************************
PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim

RETVAL: An LTrimmed string!
**********************************************************************/
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) 
	{
		// We have a string with leading blank(s)...
		var j=0, i = s.length;
		
		// Iterate from the far left of string until we don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		
		// Get the substring from the first non-whitespace character to the end of the string...
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(str)
/**********************************************************************
PURPOSE: Remove trailing blanks from our string.
IN: str - the string we want to RTrim

RETVAL: An RTrimmed string!
**********************************************************************/
{
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
	{
		// We have a string with trailing blank(s)...
		var i = s.length - 1;       // Get length of string
		
		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		   i--;
		
		// Get the substring from the front of the string to
		// where the last non-whitespace character is...
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str)
/**********************************************************************
PURPOSE: Remove trailing and leading blanks from our string.
IN: str - the string we want to Trim

RETVAL: A Trimmed string!
**********************************************************************/
{
	return RTrim(LTrim(str));
}


function Len(str)
/**********************************************************************
IN: str - the string whose length we are interested in

RETVAL: The number of characters in the string
**********************************************************************/
{  
	return String(str).length;  
}

function Left(str, n)
/**********************************************************************
IN: str - the string we are LEFTing
    n - the number of characters we want to return

RETVAL: n characters from the left side of the string
**********************************************************************/
{
	if (n <= 0)     // Invalid bound, return blank string
		return "";
	else if (n > String(str).length)   // Invalid bound, return
		return str;                // entire string
	else // Valid bound, return appropriate substring
		return String(str).substring(0,n);
}

function Right(str, n)
/**********************************************************************
IN: str - the string we are RIGHTing
    n - the number of characters we want to return

RETVAL: n characters from the right side of the string
**********************************************************************/
{
	if (n <= 0)     // Invalid bound, return blank string
		return "";
	else if (n > String(str).length)   // Invalid bound, return
		return str;                     // entire string
	else 
	{ // Valid bound, return appropriate substring
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function Mid(str, start, len)
/**********************************************************************
IN: str - the string we are LEFTing
    start - our string's starting position (0 based!!)
    len - how many characters from start we want to get

RETVAL: The substring from start to start+len
**********************************************************************/
{
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";
	
	var iEnd, iLen = String(str).length;
	if (start + len > iLen)
		iEnd = iLen;
	else
		iEnd = start + len;
	
	return String(str).substring(start,iEnd);
}

function parseDate(sDate)
{
	var j, d, m, y;
	j = sDate.indexOf('/');
	d = Right('0' + Left(sDate, j), 2);
	sDate = Mid(sDate, j+1, sDate.length);
	j = sDate.indexOf('/');
	m = Right('0' + Left(sDate, j), 2);
	y = Mid(sDate, j+1, sDate.length);
	if(y.length==2)
		y = Right('20' + y, 4);
	if(y.length==1)
		y = Right('200' + y, 4);
	return d + '/' + m + '/' + y;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
	} 
	return this;
}

function isValidDate(sDate)
{
	var dtCh = "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12);
	try
	{
		var dtStr = sDate;
		var pos1 = dtStr.indexOf(dtCh);
		var pos2 = dtStr.indexOf(dtCh,pos1+1);
		var strMonth = dtStr.substring(0,pos1);
		var strDay = dtStr.substring(pos1+1,pos2);
		var strYear = dtStr.substring(pos2+1);
		var strYr = strYear;
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
		for (var i = 1; i <= 3; i++) 
		{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
		}
		var month = parseInt(strMonth);
		var day = parseInt(strDay);
		var year = parseInt(strYr);
		if (pos1==-1 || pos2==-1)
		{
			//alert("The date format should be : mm/dd/yyyy")
			return false;
		}
		if (strMonth.length<1 || month<1 || month>12)
		{
			//alert("Please enter a valid month")
			return false;
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			//alert("Please enter a valid day")
			return false;
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		{
			//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false;
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{
			//alert("Please enter a valid date")
			return false;
		}
		return true;
	}
	catch(ex)
	{
		return false;
	}
}

function AcroPluginCheck()
{
	var msg = "No Acrobat Reader found";
	var agt = navigator.userAgent.toLowerCase();
	if(agt.indexOf("msie") != -1)
	{
		try{var MyObject = new Object("clsid:CA8A9780-280D-11CF-A24D-444553540000");}
		catch(e){alert(msg);}
	}
	else if(agt.indexOf("mozilla") != -1 && ((agt.indexOf("netscape") != -1) || (agt.indexOf("; nav") != -1)))
	{
		if (!navigator.plugins || navigator.plugins["Adobe Acrobat"].description == "") 
		alert(msg);
	}
}

function WebForm_GetScrollX() 
{
  if (__nonMSDOMBrowser) 
	{
    return window.pageXOffset;
  }
  else 
	{
    if (document.documentElement && document.documentElement.scrollLeft) 
		{
      return document.documentElement.scrollLeft;
    }
    else if (document.body) 
		{
      return document.body.scrollLeft;
    }
  }
  return 0;
}

function WebForm_GetScrollY() 
{
  if (__nonMSDOMBrowser) 
	{
    return window.pageYOffset;
  }
  else 
	{
    if (document.documentElement && document.documentElement.scrollTop) 
		{
      return document.documentElement.scrollTop;
    }
    else if (document.body) 
		{
      return document.body.scrollTop;
    }
  }
  return 0;
}

function WebForm_SaveScrollPositionOnSubmit() 
{
  theForm.__SCROLLPOSITIONX.value = WebForm_GetScrollX();
  theForm.__SCROLLPOSITIONY.value = WebForm_GetScrollY();
  if ((typeof(this.oldOnSubmit) != "undefined") && (this.oldOnSubmit != null)) 
	{
    return this.oldOnSubmit();
  }
  return true;
}

function WebForm_RestoreScrollPosition() 
{
  if (__nonMSDOMBrowser) 
	{
    window.scrollTo(theForm.elements['__SCROLLPOSITIONX'].value, theForm.elements['__SCROLLPOSITIONY'].value);
  }
  else 
	{
    window.scrollTo(theForm.__SCROLLPOSITIONX.value, theForm.__SCROLLPOSITIONY.value);
  }
  if ((typeof(theForm.oldOnLoad) != "undefined") && (theForm.oldOnLoad != null)) 
	{
    return theForm.oldOnLoad();
  }
  return true; 
}

function MyReplace(s,  one,  another) 
{
// In a string replace one substring with another
  if (s == "") return "";
  var res = "";
  var i = s.indexOf(one, 0);
  var lastpos = 0;
  while (i != -1) 
	{
    res += s.substring(lastpos, i) + another;
    lastpos = i + one.length;
    i = s.indexOf(one, lastpos);
  }
  res += s.substring(lastpos);  // the rest
  return res;  
}

function convJS(s) 
{
// Convert problem characters to JavaScript Escaped values
  if (s == null) return "";
  
  var t = s;
  t = MyReplace(t, "\\", "\\\\"); // replace backslash with \\
  t = MyReplace(t, "'", "''");  // replace an single quote with \'
  t = MyReplace(t, "\"", "\\\""); // replace a double quote with \"
  t = MyReplace(t, "\r", "\\r");  // replace CR with \r;
  t = MyReplace(t, "\n", "\\n");  // replace LF with \n;

  return t;
} 
		
function CompareDates(date1,date2)
{
	//returns true if date1>=date2 else false
	var Start = new Date(date1 + " 00:00:00");
	var End = new Date(date2 + " 00:00:00");
	diff = new Date();

	diff.setTime(Start.getTime() - End.getTime());			
	timediff = diff.getTime();
	if(timediff>=0) return true;			
	else return false;

}

function SetScrollPosition() {
  try {
    getElement("ScrollX").value = getScrollWidth();
    getElement("ScrollY").value = getScrollHeight();
  }
  catch (ex) {
  }
}

function GetScrollPosition() {
  try {
    document.body.scrollLeft = getElement("ScrollX").value;
    document.body.scrollTop = getElement("ScrollY").value;
    document.documentElement.scrollLeft = getElement("ScrollX").value;
    document.documentElement.scrollTop = getElement("ScrollY").value;
  }
  catch (ex) {
  }
}

function getScrollWidth() {
  var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
  return w ? w : 0;
}

function getScrollHeight() {
  var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
  return h ? h : 0;
}

//*************************************************************************
/*
var sleepTime = 500;
var currentTime = 0;
function check(def) {
  this.def = def;
  this.links = {};
  this.styles = {};
  this.hideifr = true;
};
{
  var Obj = check.prototype;

  Obj.create = function (d) {
    var rw = 'background-color:#FFFFFF;';
    var rg = 'background-color:#F0F8FF;';
    var td0 = "font-family:Verdana,sans-serif,Arial,Helvetica;color:black;font-size:7pt;text-align:center;font-weight:bold;'>";
    var td1 = "<td style='font-family:Verdana,sans-serif,Arial,Helvetica;color:black;font-size:7pt;text-align:left;'>";
    var p = "border-color:Black;border-width:1px;border-style:solid;border-collapse:collapse;text-align:left;background-color:#f5f5f5;'>";
    var s = "";
    s += "<div id='div_body' style='width:980px;height:300px;margin-top:0px;margin-right:5px;margin-left:5px;margin-bottom:0px;overflow:auto;" + p;
    s += "<table cellspacing='0' cellpadding='0' rules='all' style='width:100%;" + p;
    s += "<tr style='text-align:center;'>";
    s += "<td style='width:50px;" + td0 + "UserID</td>";
    s += "<td style='width:200px;" + td0 + "Name</td>";
    s += "<td style='width:200px;" + td0 + "Title</td>";
    s += "<td style='width:200px;" + td0 + "Department</td>";
    s += "<td style='" + td0 + "Email</td>";
    s += "</tr>";

    if (objRows != null) {
      for (var j = 0; j < objRows.length - 1; j++) {
        if ((j % 2) == 0)
          s += "<tr style='" + rw + "'>";
        else
          s += "<tr style='" + rg + "'>";

        s += td1 + objCols[j][0] + "</td>";
        s += td1 + "<a href='javascript:doReturn(\"" + objCols[j][1] + "\",\"" + objCols[j][4] + "\",\"" + objCols[j][0] + "\");'>" + objCols[j][1] + "</a></td>";
        s += td1 + objCols[j][2] + "</td>";
        s += td1 + objCols[j][3] + "</td>";
        s += td1 + objCols[j][4] + "</td>";
        s += "</tr>";
      }
    }

    s += "</table>";
    s += "</div>";
    d.write(s);
  };

  Obj.innerpopup = function (ctl) {
    this.ctl = ctl;
    var w = myFind(document, "check_frame");
    w.src = "check_iframe.html";
    w.style.visibility = 'visible';
    w.style.zIndex = 1;

    var b = myFind(document, "div_but");
    b.style.visibility = 'hidden';
    b.style.zIndex = 0;

    if (window.navigator.appVersion.indexOf("MSIE") == -1) {
      w.innerHeight = this.def.windowh + "px";
      w.innerWidth = this.def.windoww + "px";
      b.innerHeight = 0 + "px";
    }
    else {
      w.height = this.def.windowh + "px";
      w.width = this.def.windoww + "px";
      b.height = 0 + "px";
    }
  };
}

var objRows;
var objCols;
var check_definition = {
  windoww: 950,
  windowh: 300
};
var checkCtl = new check(check_definition);

function check_click(ctlClicked, x, y) {
  var nowTime = new Date();
  if (currentTime == 0)
    currentTime = nowTime;
  var intv = parseInt(nowTime.getTime() - currentTime.getTime());
  currentTime = nowTime;
  if (intv > sleepTime || intv == 0) {
    var arg = ctlClicked.value;
    if (arg != '') {
      arg = MyReplace(arg, ", ", ",");
      var arPPD = callWebService("Services.aspx?method=checkNames&Lookup=" + arg);
      if (arPPD.indexOf("Error") == -1) {
        var ret = MakeArray(arPPD);
        if (ret) {
          var coordinates = getAnchorPosition(ctlClicked.id);
          var ctl = getElement("check_frame");
          ctl.style.pixelTop = parseInt(coordinates.y + y);
          ctl.style.pixelLeft = parseInt(coordinates.x + x);
          ctl.style.top = parseInt(coordinates.y + y) + "px";
          ctl.style.left = parseInt(coordinates.x + x) + "px";
          checkCtl.innerpopup(ctlClicked.id);
        }
      }
    }
    else {
      doReturn('', '', '');
    }
  }
}

function MakeArray(ar) {
  try {
    if (ar.toString().indexOf("|") > -1) {
      objRows = ar.split("|");
      if (ar != "") {
        objCols = new Array(objRows.length);
        for (var j = 0; j < objRows.length; j++) {
          objCols[j] = objRows[j].split("^");
        }
      }
      else {
        return false;
      }
    }
    else {
      return false;
    }
  }
  catch (ex) {
    return false;
  }
  return true;
}

function doReturn(name, email, userid) {
  if (!isEmail(email) || userid == 'unknown') {
    alert('Selected record is wrong.');
  }
  else {
    parent.getElement("txtOther").value = name;
    parent.getElement("EmailAddr").value = email;
    parent.getElement("userID").value = userid;
    parent.getElement("check_frame").style.visibility = 'hidden';
    parent.getElement("div_but").style.visibility = 'visible';
  }
}

*/
//*************************************************************************

var windowObjectReference = null;

function xShowModalDialog(sURL) 
{
  var sFormat = "dialogTop:0px;dialogLeft:0px;dialogWidth:320px;dialogHeight:600px;resizable:no;help:no;status:no;scroll:no";
  var sWinFeat = "screenY=0px,screenX=0px,height=600px,width=320px,directories=0,menubar=0,titlebar=0,toolbar=0,resizable=0,status=0,scroll=0";
  if (window.navigator.appVersion.indexOf("MSIE") != -1) {
    windowObjectReference = window.showModalDialog(sURL, null, sFormat);
  }
  else 
  {
    if (windowObjectReference == null || windowObjectReference.closed) 
    {
      windowObjectReference = window.open(sURL, "", sWinFeat);
    }
    else 
    {
      if (windowObjectReference.focus) 
      {
        windowObjectReference.focus();
      }
    }
  }
}

function createXMLHttpRequest() {
  var types = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];

  for (var i = 0; i < types.length; i++) {
    try {
      return new ActiveXObject(types[i]);
    }
    catch (e) {
      try {
        return new XMLHttpRequest();
      }
      catch (e) {
        return false; // XMLHttpRequest not supported
      }
    }
  }
}

function callWebService(serverURL) {
  var sResult = "", xmlhttp;
  xmlhttp = createXMLHttpRequest();
  if (xmlhttp) {
    xmlhttp.open("POST", serverURL, false);
    xmlhttp.send();
    if (xmlhttp.status == 200) {
      sResult = xmlhttp.responsetext;
    }
    xmlhttp = null;
  }
  return sResult;
}

function getElement(ctl) {
  return (document.getElementById) ? document.getElementById(ctl) : document.all[ctl];
}


