/*
 This function opens a horizontally centered window, 10 pixels from the top of the 
 screen. A supplied URL is opened for the document. The window's name width and 
 heigth are all specified in the call
 
 @param url - url to open in the popup window
 @param name - name of the popup window, must be unique
 @param width - width of the popup window
 @param height - height of the popup window
*/
function openWindow(url, name, width, height)
{
	winwidth = width;
	winheight = height;
	var winl = (screen.width - winwidth) / 2;
	var wint = 10;
	var regexp = /-/g;
	name = name.replace(regexp, "_");
	
	win  = window.open(url, name, 'width=' + winwidth + ',height=' + winheight + ',top=' +wint+ ',left=' +winl+ ',resizable,scrollbars,status');
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/*
 This function strips HTML tags from an input field
  
 Example of use:
 <input type="text" onBlur="stripHTML(this)">
 
 @param formElement - the form element object that is being formatted
*/
function stripHTML(formElement) 
{
	var elementValue =  formElement.value;
	var a, b, c, d;
	var error = true;
	a = elementValue.indexOf("<");
	b = elementValue.indexOf(">");
	while(a != -1)
	{
		len = elementValue.length;
		c = elementValue.substring(0, a);
		if(b == -1)b = a;
		d = elementValue.substring((b + 1), len);
		elementValue = c + d;
		a = elementValue.indexOf("<");
		b = elementValue.indexOf(">");
	}
	formElement.value = elementValue;
}


/*
 This function opens a centered window. Supplied code is written to the 
 document body. The window's name, width, and height are all specified 
 in the call.
 
 @param textToWrite - text or HTML to write into the new window document
 @param name - name of the popup window, must be unique
 @param width - width of the popup window
 @param height - height of the popup window
*/
function writeToNewWindow(textToWrite, name, width, height)
{
	var leftalign = (screen.width - width) / 2;
	var topalign = (screen.height - height) / 2;
	writeWindow = open("", name, "width="+width+",height="+height+",top="+topalign+",left="+leftalign+",status=no,toolbar=no,menubar=no,resizable,scrollbars");

	// open document for further output
	writeWindow.document.open();
  
	// create document
	writeWindow.document.write("<html><head><title></title>");
	writeWindow.document.write('</head><body bgcolor="white">');
	writeWindow.document.write(textToWrite);
	writeWindow.document.write("</body></html>");
  	
	// align window for Netscape
	writeWindow.screenX = leftalign;
	writeWindow.screenY = topalign;
	
	// bring window to front
	writeWindow.focus();
}
