////////////////////////////////////////////
// GateBuilder 1.6 - JavaScript Library	  //
// -cw, -pt, 6.3.2001					  //
////////////////////////////////////////////
// open a new Window:
function newWin(url,windowname,window_apperance) {
  if (url == null) url = '';
  if (windowname == null) windowname = '_blank';
  if (window_apperance == null || window_apperance == '') window_apperance = 'left=10,top=10,scrollbars=yes,menubar=no,resizable=yes,toolbar=no,location=no';
  newwindow = open(url,windowname,window_apperance);
}	
// close the window, optionally show message and/or refresh calling page:
function CloseWindow(message,bReload) {
  window.onerror = errorcheck;
  if (message == null) message="";
  if (bReload == null) bReload = true;
  if (bReload) { 
    if (self.opener != null) {
	  if (self.opener.closed != true) {
	    bListControlReload = false;
	    if (self.opener.document != null) { 
	      if (self.opener.document.forms != null) {
		    if (self.opener.document.forms['gblistcontrol'] != null) {
		      bListControlReload = true;
		    }	
		  }  
	    }		
	  }	
 	  if (bListControlReload) {
	    // special handling for refreshing a calling page that contains a listcontrol
		lcform = self.opener.document.forms['gblistcontrol']; 
		lcform.bPurgeCache.value="TRUE";
		lcform.submit();
	  }
	  else {
	    // standard refresh of calling page via ...
		// (a) self.opener.location.reload(true): RE-POST of DATA is possible, but there might be "page has to be reloaded"-warning
		// (b) self.opener.location = self.opener.location: just a new HTTP-Get, no RE-POST of DATA, but no warning either
	    self.opener.location = self.opener.location;
	  }
	}
  }	
  if (message != "") alert(message);
  self.close();
} 
// error-handling (low level ;-)
function errorcheck() {
  if (window.opener != null) window.close();
  return true;
}	
// set the URL (=href) for a anker tag:
function setURL(anker,string,hrefPre,hrefPos,bConfirm,message) {
  newHREF = "";
  if (bConfirm == null) bConfirm = false;
  if (message == null) message = 'Are you sure?';
  if (hrefPre != null) newHREF = hrefPre;
  if (string != null) newHREF = newHREF + escape(string);	
  if (hrefPos != null) newHREF = newHREF + hrefPos;
  anker.href = newHREF;
  if (bConfirm) return confirm(message);
  else return true;
}
// set the value of a form-field in another window:
function sendToCaller(string,formname,fieldname) {
  window.onerror = errorcheck;
  control = window.opener.document[formname][fieldname];
  if (control != null) {
    control.value = string; 
  }	
  window.close();
}
// resetting the multiselect-SelectBOX "on button click":
function resetSelectBox(selectbox) {
	opts = selectbox.options;
	for (i = 0; i < opts.length; i++)
	  if (opts[i].defaultSelected)
	    {opts[i].selected = true;}
	  else
	    {opts[i].selected = false;}
}
// selecting all entries of a multiselect-SelectBOX "on button click":
function selectAllSelectBox(selectbox) {
	opts = selectbox.options;
	for (i = 0; i < opts.length; i++)
      opts[i].selected = true;
}
// DATE-validation:
function dateValidate(sDate,sMask,sDelimiter,sErrorMessage){
	if (sErrorMessage == null) sErrorMessage = "Invalid Date Entry.";
	bSuccess = false;
    stDateParts = new Object();
 	if ((sMask.length == 3) && (sDelimiter.length == 1)) {
 	  iFirstPos = sDate.indexOf(sDelimiter);
	  iLastPos  = sDate.indexOf(sDelimiter, iFirstPos+1);
	  stDateParts[sMask.charAt(0).toUpperCase()]= sDate.substring(0, iFirstPos);
	  stDateParts[sMask.charAt(1).toUpperCase()]= sDate.substring(iFirstPos + 1, iLastPos);	
	  stDateParts[sMask.charAt(2).toUpperCase()]= sDate.substring(iLastPos + 1, sDate.length);	
	  day = stDateParts.D;
	  month = stDateParts.M;
	  year = stDateParts.Y;
	  if ((year != null)&&(year.length > 0)&&(year.length < 5)&&
	  	  (month != null)&&(month.length > 0)&&(month.length < 3)&&
		  (day != null)&&(day.length > 0)&&(day.length < 3)) {
		if ((year > 0) && (year < 10000)) {
		  if ((month > 0) && (month < 13)) {
		    if ((day > 0) && (day < 32)) {		    
			  if ((month == 4) || (month == 6) ||(month == 9) ||(month == 11)) {
			    if (day < 31) {
				  bSuccess = true;
				}  
			  }
			  else if (month == 2){
				if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
			      if (day < 30) {
				    bSuccess = true;				  
				  }	
				}  
				else {
			      if (day < 29) {
				    bSuccess = true;				  				  
				  }	
				}  
			  }
			  else {
			  	bSuccess = true;
			  }	
		    }
		  }  
		}
	  }	
	}
	if ((bSuccess == false) && (sErrorMessage != "")) alert(sErrorMessage);
	return bSuccess;
}		
// mandatory INPUT-field:
function mandatoryInput(control,name,message) {
  if (control == null) return;
  if (name == null) name=control.name;
  if (message == null) message="mandatory input";
  if (control.value == '' || control.value.charAt(0) == ' ') {
     if (message != "") alert( message + ' (' + name + ')' );
	 control.focus();
  }	 
} 
// append (navigation-)information to an ANKER's HREF-attribute
// from the GLOBAL jsUIC-object:
var jsUIC; // filled via "UIController-Data" inside gbformatting.cfm
function appendNodeIDsToURL(myAnker) {
  if ((jsUIC != null) && (myAnker != null) && (myAnker.href != null)) {
    myURL = myAnker.href;
	if (jsUIC.CategoryNodeID != null) {
      myURL = myURL + '&CategoryNodeID=' + jsUIC.CategoryNodeID;
	}
	if (jsUIC.MenuNodeID != null) {
      myURL = myURL + '&MenuNodeID=' + jsUIC.MenuNodeID;
	}
    myAnker.href =  myURL;
  }
  return true;
}  

// custom email window
function bkEmail(recipient)
{
var URL = "bkFormularInvoker.cfm?gbAction=bkEmail&recipient=" + recipient;
newWin(URL,'eMailWindow','width=490,height=450');
}
