// FormDocs JavaScript Library

function IsWellFormedEmailAddress (EmailAddress)
{
 if ((EmailAddress === null) || (EmailAddress === undefined))
   return (false) ;
				// regular expression takes from white-hat website
 var regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ ;
 return (regexp.test (EmailAddress)) ;
}
 

function GetPopupSpecs (Dx, Dy)
{
 // if Dx parameter not passed or too big, make 75% screen width
 if ((Dx === null) || (Dx === undefined) || (Dx > window.screen.availWidth))
   Dx = window.screen.availWidth * 3 / 4 ;  
 // if Dy parameter not passed or too big, make 75% screen height
 if ((Dy === null) || (Dy === undefined) || (Dy > window.screen.availHeight))
   Dy = window.screen.availHeight * 3 / 4 ;
 // define specifics: center on screen:
 return ("toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=yes,scrollbars=1" + 
		 ",left=" + ((window.screen.availWidth - Dx) / 2) + 
		 ",top=" + ((window.screen.availHeight - Dy) / 2) + 
		 ",width=" + Dx + ",height=" + Dy) ;
}

function OpenPopup (url, Dx, Dy)
{
	var specs = GetPopupSpecs (Dx, Dy) ;
	// if not a root-relative URL, compensate
	if (url.indexOf ("/") == -1)
	  url = "/" + url ;	
	var hWndPopup = window.open (url, "FormDocs", specs) ;
	if (hWndPopup)
	  hWndPopup.focus () ;
	// 2011-12-27 - don't want to return anything here; causes weird page results
	// return (hWndPopup) ;
}

function PopupImage (imgsrc, Dx, Dy)
{
	var specs = GetPopupSpecs (Dx, Dy) ;
	// open a blank window (not based on any htm file)
	var hWndPopup = window.open ("", "", specs) ;
	if (hWndPopup)
	  {	// open document for writing:
	   hWndPopup.document.open () ;
	   // write html file
	   hWndPopup.document.write ("<html><head><title>FormDocs</title>") ;
	   hWndPopup.document.write ("<link href=\"/popups/popup.css\" rel=\"stylesheet\" type=\"text/css\"></head>") ;
	   hWndPopup.document.write ("<body><div id=\"close_button\"><a href=\"javascript:window.close()\">Close Window</a></div>") ;
		// if not a full URL, compensate, as popup_image.htm is in a subfolder
	   if (imgsrc.indexOf ("/") == -1)
	     imgsrc = "/images/" + imgsrc ;		  
	   hWndPopup.document.write ("<img src=\"" + imgsrc + "\" alt=\"FormDocs\"></body></html>") ;
	   hWndPopup.document.close () ;
	   hWndPopup.focus () ;
	  }

/* 9-20-2011: technique not supported by all browsers!
	var hWndPopup = OpenPopup ("popups/popup_image.htm", null, Dx, Dy) ;
	if (hWndPopup)
	  {	// if not a full URL, compensate, as popup_image.htm is in a subfolder
	   if (imgsrc.indexOf ("/") == -1)
	     imgsrc = "../images/" + imgsrc ;
		// replace image source
	   var hImg = hWndPopup.document.getElementById ("image_placeholder") ;
	   if (hImg)
	     hImg.src = imgsrc ;	
	  }
*/
}

