var wndFill;
var blnFillInInformationIsOK = new Array();
var obj;
var allObj = new Array();

function checkFillInInformation() {
 //loop the objects list
 for (var i = 0; i < blnFillInInformationIsOK.length; ++i) {
  //bad data entered
  if (!blnFillInInformationIsOK[i]) {
   alert("You have entered bad data.  Please check your entries.");
   allObj[i].select();
   allObj[i].focus();
   return false;
  }
 }
 return true;
}

function setOKExternal(ptr, blnOK) {
 setObject(ptr);
 setOK(blnOK);
}

function setOK(blnOK) {
 //check for the current object in the objects list
 for (var i = 0; i < allObj.length; ++i) {
  //when they match, update the isok information
  if (allObj[i] == obj)
   blnFillInInformationIsOK[i] = blnOK;
 }
}

function setObject(ptr) {
 //global object variable
 obj = ptr;
 //search for the object
 for (var i = 0; i < allObj.length; ++i) {
  if (allObj[i] == obj) {
   blnFillInInformationIsOK[i] = false;
   return;
  }
 }
 //object isn't added to list already, add it
 i = allObj.length
 allObj[i] = ptr;
 blnFillInInformationIsOK[i] = false;
}

function fillInInformation(objID, strCallType, strCallPage, blnAPak, strField) {
 //make sure object is in check list
 setObject(objID);

 //close old window if it's open for some reason
 closeFillInWindow();

 //check if it's a number
 switch (strCallType) {
  case "pickvend":
  case "pickhotel":
   break;
  default:
   if (isNaN(objID.value)) {
    setOK(false);
    alert("Please enter a valid number.");
    objID.select();
    objID.focus();
    return false;
   }
   break;
 }

 //id of 0 is bad data
// else if (objID.value == 0)
//  setOK(false);
 //fill it in!
 openFillInWindow(strCallType, strCallPage, objID.value, blnAPak, strField);
}

function closeFillInWindow() {
 if (wndFill)
  wndFill.close();
}

function openFillInWindow(strCallType, strCallPage, strID, blnAPak, strField) {
 var strURL = '../utilities/fillin.asp?action=start&type=' + strCallType + '&call=' + strCallPage + "&id=" + strID + "&APak=" + blnAPak + "&fld=" + strField;
 wndFill = window.open(strURL, 'wndFill', 'height=100, width=200, scrollbars, resizable');
 wndFill.focus();
}

function fillInAccountInformation(objGL, objGL2, objGL3, objGL4, objGL5, strCallPage, blnAPak, strField) {
 setObject(objGL);
 var strAccount, blnOK;

 blnOK = true;
 //concatenate all the values
 if (objGL.value == '')
  blnOK = false;
 strAccount = objGL.value;

 if (objGL2.value == '')
  blnOK = false;
 strAccount += '-' + objGL2.value;

 if (objGL3.value == '')
  blnOK = false;
 strAccount += '-' + objGL3.value;

 if (objGL4.value == '')
  blnOK = false;
 strAccount += '-' + objGL4.value;

 if (objGL5.value == '')
  blnOK = false;
 strAccount += '-' + objGL5.value;

 if (!blnOK && objGL.value == ''&& objGL2.value == ''&& objGL3.value == '' && objGL4.value == ''&& objGL5.value == '')
  blnOK = true;

 if (blnOK) {
  closeFillInWindow();
  openFillInWindow('account', strCallPage, strAccount, blnAPak, strField);
 }
}

function fillinField_keypress(e) {
	if (e.which) {
		ascii = e.which;
	}
	else if (e.keyCode) {
		ascii = e.keyCode;
	}

	return (ascii != 13);
}
