
var objDoc = this.document;
var objForms = objDoc.forms;
var childWin;
var WINDOW_WIDTH = 670;
var WINDOW_HEIGHT = 400;
var intClientWidth=0;
var intClientHeight=0;

// get available width/height of screen less the size of the new window
intClientWidth = parseInt((screen.availWidth - WINDOW_WIDTH)/2);
intClientHeight = parseInt((screen.availHeight - WINDOW_HEIGHT)/2);
  
window.onUnload = closeChildWin


function OpenAddModWin(oLineItem) {
  // open a window object with name same as line item name
  var oLineItemValue="";
  
  // get lineitem sequence value to be sent to child window
  if (objForms["pepCalc"]) {
      eval("oLineItemValue =  escape(objForms[\"pepCalc\"]." + oLineItem + ".value)");
      }
   childWin = window.open("/apps/peptideModWin.asp?ParentValue=" + oLineItemValue + "\&ParentElement=" + oLineItem, "win_" + oLineItem, "width=" + WINDOW_WIDTH + ",height=" + WINDOW_HEIGHT + ",resizable=1,toolbar=0,scrollbars=1");
   
   // reposition and focus new child window
   childWin.moveTo(intClientWidth, intClientHeight);
   childWin.focus();
  }
  
  
function OpenAddIsotopeWin(oLineItem) {
  // open a window object with name same as line item name
  var oLineItemValue='';
  
  // get lineitem sequence value to be sent to child window
  if (objForms["pepCalc"]) {
      eval("oLineItemValue =  escape(objForms[\"pepCalc\"]." + oLineItem + ".value)");
      }
   
   if (oLineItemValue != '') {
		childWin = window.open("addIsotopeWin.asp?ParentValue=" + oLineItemValue + "\&ParentElement=" + oLineItem, "win_" + oLineItem, "width=" + WINDOW_WIDTH + ",height=" + WINDOW_HEIGHT + ",resizable=1,toolbar=0,scrollbars=1");
		   
		// reposition and focus new child window
		childWin.moveTo(intClientWidth, intClientHeight);
		childWin.focus();
		}
	else {
		alert("Peptide Sequence is empty.\r\n\r\nPlease enter your Peptide Sequence first.");
		}
  }

function writeOpenAddIsotopeWin(oLineItem) {
  // write the link to open the sequence builder
  document.write("<a href=\"javascript:OpenAddIsotopeWin('" + oLineItem + "')\" title=\"Add Peptide isotope residues to Sequence\" onMouseOver=\"window.status=this.title;return true\" onMouseOut=\"window.status='';return true\"><img src=\"/images/btn_addIsotope.gif\" alt=\"Add Peptide isotope residues to Sequence\" border=\"0\"></a>");
  }

function writeOpenAddModWin(oLineItem) {
  // write the link to open the sequence builder
  document.write("<a href=\"javascript:OpenAddModWin('" + oLineItem + "')\" title=\"Add Peptide Mod to Sequence\" onMouseOver=\"window.status=this.title;return true\" onMouseOut=\"window.status='';return true\"><img src=\"/images/btn_addMod.gif\" alt=\"Add Peptide Mod to Sequence\" border=\"0\"></a>");
  }


function updateSequence(oLineItemValue, oLineItem) {
  // called externally to update the parent form field sequence value
  eval("objForms[\"pepCalc\"]." + oLineItem + ".value = oLineItemValue");
  }

function closeChildWin() {
  if (childWin && !childWin.closed) {   // -- if the child window exists and is open, then close it
      childWin.closeWindow();
      }
  return;
  }
