// JScript source code
//--------------------------------------------------------------------------------------------------*
// Include File for General JavaScript Form Functions
// 
// Property of Advanced Transportation Systems, Inc.
// Author: Sam Powell
// Date: 01/11/2003
//
//--------------------------------------------------------------------------------------------------*
// ATS Trim Function - Remove blank spaces.
// This will remove all spaces from the beginning and end of the string as well as extra spaces 
// between the words.
//--------------------------------------------------------------------------------------------------*
function ATSTrim(string)
{
	var strLength = string.length;
	var newstr = '';
	for (i=0; i <= strLength; i++) {
		if (string.substring(i,i+1) == ' ') {
			if (string.substring(i+1,i+2) != ' ') {
				newstr = newstr + string.substring(i,i+1);
			}
		} else {
			newstr = newstr + string.substring(i,i+1);
		}
	}

	var tString=newstr;
	tString = tString.replace(' ','');
	if (tString=='') {
		newstr = tString;
	}
    return newstr;
} //End ATSTrim()
//--------------------------------------------------------------------------------------------------*
// ATSRemoveSpaces() - Remove all spaces
//--------------------------------------------------------------------------------------------------*
function ATSRemoveSpaces(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
//--------------------------------------------------------------------------------------------------*
// Convert value to UpperCase
//--------------------------------------------------------------------------------------------------*
function ATSToUpperCase(objField) {

	objField.value = objField.value.toUpperCase();
}
//--------------------------------------------------------------------------------------------------*
// Function to Remove for user entering funny characters (like !@#$%^&* etc)
//--------------------------------------------------------------------------------------------------*
function ATSRemoveSpecialCharacters(objField) {

	Field = objField.value;
	for (i=1;i >= strlen(Field); i++)
	{
		
	}
}
//--------------------------------------------------------------------------------------------------*
// Convert value to LowerCase
//--------------------------------------------------------------------------------------------------*

function ATSToLowerCase(objField) {

   objField.value = objField.value.toLowerCase();

}

//--------------------------------------------------------------------------------------------------*
// Convert all elements in all forms to UpperCase
//--------------------------------------------------------------------------------------------------*

function ATSAllToUpperCase() {
	
	var NumberOfForms = document.forms.length;
	for (FormIndex=0;FormIndex < NumberOfForms; FormIndex++)
	{
		var NumberofFormElements = document.forms[FormIndex].length;
		for (ElementIndex=0;ElementIndex < NumberofFormElements; ElementIndex++)
		{
			if (document.forms[FormIndex].elements[ElementIndex].type == 'text')
				document.forms[FormIndex].elements[ElementIndex].value = document.forms[FormIndex].elements[ElementIndex].value.toUpperCase();
		}
	}
}

//--------------------------------------------------------------------------------------------------*
// Maximize Window Size
//--------------------------------------------------------------------------------------------------*

function ATSMaximizeWindow() {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

//--------------------------------------------------------------------------------------------------*
// Open a window up a maximum size or full width
//--------------------------------------------------------------------------------------------------*

function ATSFullWindow(MaxWidth,MaxHeight) {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
	if (aw > MaxWidth) aw = MaxWidth
	if (ah > MaxHeight) ah = MaxHeight
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

//---------------------------------------------------------------------------------
// Call Parties Search Window
//---------------------------------------------------------------------------------
// Function to do a search of Parties (Customers/Vendors/Shippers/Consignees etc.)
// Arguments:  CallingPage = php page calling this function
//             Action = Action to be taken by the search normally SEARCH
//             PartiesType= Type of parties names being searched ie. (CUSTOMER/VENDOR/SHIPPER)
//             SearchValue= Value to be searched (user input)
//             CustomerAccount=Customer account related to the partie
//             Formname= (used to know where to post the users selection)
//             FieldNames=(Field names of the calling form name needing to be populated)
//             Fieldvalue=(Field values to be passed to the Validate_Party.php routine)
//             Module=Name of module where it is being called from.
//
function ATSPartiesSearch(CallingPage,Action,PartiesType,SearchValue,CustomerAccount,FormName,FieldNames,FieldValues,Module)
{
	var CallValidation = 0;
	var PageToCall = '/EZFreight/Common/Validate_Party.php';
	var Parameters = 'PartiesType=' + escape(PartiesType);
	Parameters = Parameters + "&CallingPage=" + escape(CallingPage);
	Parameters = Parameters + "&SearchValue=" + escape(SearchValue);
	Parameters = Parameters + "&CustomerAccount=" + escape(CustomerAccount);
	Parameters = Parameters + "&FormName=" + escape(FormName);
	Parameters = Parameters + "&FieldNames=" + escape(FieldNames);
	Parameters = Parameters + "&FieldValues=" + escape(FieldValues);
	Parameters = Parameters + "&Action=" + escape(Action);
	Parameters = Parameters + "&Module=" + escape(Module);

	if (Action == "BUTTON") CallValidation = 1 ;
	if (SearchValue > "") CallValidation = 1;
	if (CallValidation) {
		Search.location.replace(PageToCall + '?' + Parameters);
	}
}

//---------------------------------------------------------------------------------
// Call Port Of Lading/Port of Unlading Search Window
//---------------------------------------------------------------------------------
function Validate_Port(FormName,SearchValue,Action,FieldNames,FieldValues,TransMode,Module)
{
	var PageToCall = '../Common/Validate_Port.php';
	var Parameters = 'FormName=' + escape(FormName);
	
	Parameters = Parameters + '&FieldNames=' + escape(FieldNames);
	Parameters = Parameters + "&s_SearchField=" + escape(SearchValue);
	Parameters = Parameters + "&TransMode=" + escape(TransMode);
	Parameters = Parameters + "&FieldValues=" + escape(FieldValues);
	Parameters = Parameters + "&Module=" + escape(Module);

	Search.location.replace(PageToCall + '?' + Parameters);
	
}
//---------------------------------------------------------------------------------
// Validate US Ports
//---------------------------------------------------------------------------------
function Validate_USPort(ElementName)
{
	var PageToCall = '../Common/Validate_Port.php';
	var Parameters = 'ElementName=' + escape(ElementName);
	
	if (ElementName) {
		if (document.billoflading.elements[ElementName+'Name'].value > '') {
			Parameters = Parameters + '&FormName=billoflading';
			Parameters = Parameters + "&s_SearchField=" + escape(document.billoflading.elements[ElementName+'Name'].value);
			Parameters = Parameters + "&s_IncludeCountry=US";
			Search.location.replace(PageToCall + '?' + Parameters);
		} else {
			document.billoflading.elements[ElementName].value = '';
		}
	}

}
//---------------------------------------------------------------------------------
// Call Carrier Search Window
//---------------------------------------------------------------------------------
function Validate_Carrier(ElementName,FormName,FieldNames,FieldValues,Action,Module,TransMode)
{
	var PageToCall = '../Common/Validate_Carrier.php';
	var Parameters = 'ElementName=' + escape(ElementName);
	Parameters = Parameters + "&FieldNames=" + escape(FieldNames);
	Parameters = Parameters + "&FieldValues=" + escape(FieldValues);
	Parameters = Parameters + "&Action=" + escape(Action);
	Parameters = Parameters + "&Module=" + escape(Module);
	Parameters = Parameters + "&FormName=" + escape(FormName);
	if (TransMode == "") {
		Parameters = Parameters + "&TransMode=" + escape(document.forms[FormName].TransMode.value);
	} else {
		Parameters = Parameters + "&TransMode=" + escape(TransMode);
	}
	
	if (document.forms[FormName].elements[ElementName].value > "") {

		Parameters = Parameters + "&s_SearchField=" + escape(document.forms[FormName].elements[ElementName].value);
		
		var CallURL = PageToCall + '?' + Parameters;
		
		$.ajax({
		  url: CallURL,
		  dataType: 'script'	  
		});

	} else {

		document.forms[FormName].elements[ElementName].value='';

	}

} // End Validate_Carrier()
//--------------------------------------------------------------------------------------------------*
// Generic Table validation
//--------------------------------------------------------------------------------------------------*
function Validate_Table(ElementName,TableName,FormName,FieldNames,FieldValues,Action,Module,AdditionalValues)
{
	
	var PageToCall = '../Common/Validate_Table.php';
	var Parameters = 'ElementName=' + escape(ElementName);
	Parameters = Parameters + "&TableName=" + escape(TableName);
	Parameters = Parameters + "&FieldNames=" + escape(FieldNames);
	Parameters = Parameters + "&FieldValues=" + escape(FieldValues);
	Parameters = Parameters + "&Action=" + escape(Action);
	Parameters = Parameters + "&Module=" + escape(Module);
	Parameters = Parameters + "&FormName=" + escape(FormName);
	Parameters = Parameters + "&AdditionalValues=" + escape(AdditionalValues);
	
	if (document.forms[FormName].elements[ElementName].value > "") {
		Parameters = Parameters + "&s_SearchField=" + escape(document.forms[FormName].elements[ElementName].value);
		Search.location.replace(PageToCall + '?' + Parameters);
	} else {
		document.forms[FormName].elements[ElementName].value='';
	}

} // End Validate_Table

//--------------------------------------------------------------------------------------------------*
// Get Cookies
//--------------------------------------------------------------------------------------------------*
function getCookie(label)
{
  var labelLen = label.length
  var cLen = document.cookie.length
  var i = 0
  var cEnd
  while (i < cLen) {
    var j = i + labelLen
    if (document.cookie.substring(i,j) == label) {
       cEnd = document.cookie.indexOf(";",j)
       if (cEnd == -1) {
          cEnd = document.cookie.length
       }
       return unescape(document.cookie.substring((j=j+1),cEnd))
     }
     i++
  }
  return ""
}


//------------------------------------------------------------------------------//
// Function to get today's date
// date will always go with a / separator
//
//------------------------------------------------------------------------------//
function ATSGetDate()
{
    var CurrentDate = new Date();
	var strDay = CurrentDate.getDate();
	var strYear = CurrentDate.getFullYear();
	var strMonth = CurrentDate.getMonth() + 1;
	
	if (strMonth.length == 1) {
		strMonth = "0" + strMonth;
	}

	if (strDay.length == 1) {
		strDay = "0" + strDay;
	}
	
	var Today = strMonth + "/" + strDay + "/" + strYear;
	return Today;
}

//------------------------------------------------------------------------------//
// Function to get current time
//------------------------------------------------------------------------------//
function ATSGetTime(Format)
{
    var TimeNow = new Date();
	var strHour = TimeNow.getHours();
	var strMinutes = TimeNow.getMinutes();
	var strSeconds = TimeNow.getSeconds();
	var CurrentTime = '';

	Format = Format.toUpperCase();

	if (strHour <= 9) strHour = "0" + strHour;
	
	if (strMinutes <= 9) strMinutes = "0" + strMinutes;
	
	if (strSeconds <= 9) strSeconds = "0" + strSeconds;

	if (Format == "") Format = "HH:MM";

	if (Format == "HH:MM" | Format == "H:M") {
		CurrentTime = strHour + ":" + strMinutes;
	}

	if (Format == "HH:MM:SS" | Format == "H:M:S") {
		CurrentTime = strHour + ":" + strMinutes + ":" + strSeconds;
	}

	return CurrentTime;
}
//------------------------------------------------------------------------------//
// Function to convert date from yyyy-mm-dd to mm/dd/yyyy
//------------------------------------------------------------------------------//
function ATSConvertDate(DateField)
{
	if (DateField == "") return;
	var DateToConvertArray = DateField.split('-');
	var strYear = DateToConvertArray[0];
	var strMonth = DateToConvertArray[1];
	var strDay = DateToConvertArray[2];
	DateField = strMonth + "/" + strDay + "/" + strYear;

	return DateField;
}
//------------------------------------------------------------------------------//
// Function to check and complete the date for a user
// If the user enters 07-14 system will complete to 07/14/2006 (2006=Currentyear)
// dates will always go with a / separator
//
//------------------------------------------------------------------------------//
function ATSCheckDate(DateField)
{
    var DateToCheck = new String(DateField.value);
    var Result=true;
    var CurrentDate = new Date();

	if (DateToCheck.length==8 && (!isNaN(DateToCheck))) {
		var TDateToCheck = DateToCheck.substring(0,2) + "/" + DateToCheck.substring(2,4) + "/" + DateToCheck.substring(4);
		DateToCheck = TDateToCheck;
	}

	if (DateToCheck.length==6 && (!isNaN(DateToCheck))) {
		var TDateToCheck = DateToCheck.substring(0,2) + "/" + DateToCheck.substring(2,4) + "/" + DateToCheck.substring(4);
		DateToCheck = TDateToCheck;
	}

	if (DateToCheck.length==4 && (!isNaN(DateToCheck))) {
		var TDateToCheck = DateToCheck.substring(0,2) + "/" + DateToCheck.substring(2);
		DateToCheck = TDateToCheck;
	}

    DateToCheck = DateToCheck.replace(/\-/g,"/");
    DateToCheck = DateToCheck.replace(/\./g,"/");

    if (DateToCheck.indexOf("/") == -1) {
		if (DateToCheck > '') {
            Result = false;
		}
    } else {
         var DateToCheckArray = DateToCheck.split("/");
         var strMonth = DateToCheckArray[0];
         var strDay = DateToCheckArray[1];
         if (DateToCheckArray.length == 3) {
             var strYear = DateToCheckArray[2];
             if (strYear.length == 2) strYear = '20' + strYear;
         } else {
              var strYear = CurrentDate.getFullYear();
         }

	   	 if (strMonth.length == 1) {strMonth = "0" + strMonth;}

	     if (strDay.length == 1) {strDay = "0" + strDay;}
	     	
         DateToCheck = strMonth + '/' + strDay + '/' + strYear;
         Result = ATSValidateDate(DateToCheck);
     }

     if (!Result) {
         alert ("Invalid Date Entered - Please try again");
         DateField.focus();
         DateField.value='';
		 Result=false;
     } else {
       	 DateField.value=DateToCheck;
		 Result=true;
     }

	 return Result;

} // End CheckDate();

//------------------------------------------------------------------------------//
// Function to check and complete the time for a user
// If the user enters 07.14 or 07.14 or 7.14 or 0714 system will complete to 
// 07:14 or 
// times will always go with a : separator
//
//------------------------------------------------------------------------------//
function ATSCheckTime(TimeField,Format)
{
    var TimeToCheck = new String(TimeField.value);
    var Result=true;
    var CurrentTime = new Date();
	var strHour = '';
	var strMinutes = '';
	var strSeconds = '';

    TimeToCheck = TimeToCheck.replace(/\-/g,":");
    TimeToCheck = TimeToCheck.replace(/\./g,":");
    TimeToCheck = TimeToCheck.replace(/\\/g,":");

	if (TimeToCheck <= '') {Result = false;}

    if (TimeToCheck.indexOf(":") == -1) {
		if (length(TimeToCheck) == 4) {
			var TempTime = TimeToCheck.substring(0,2);
			TempTime = TempTime + ":" + TimeToCheck.substring(3,2);
		}
	}
	
	var TimeToCheckArray = TimeToCheck.split(":");
	var strHour = TimeToCheckArray[0];
    var strMinutes = TimeToCheckArray[1];
	
	if (TimeToCheckArray.length == 3) {strSeconds = TimeToCheckArray[2];}
	
	if (isNaN(strHour)) {Result=false;}
	if (isNaN(strMinutes)) {Result=false;}
	if (isNaN(strSeconds) & strSeconds > "") {Result=false;}

	if (strHour < 0 | strHour > 24) {Result=false;}
	if (strMinutes < 0 | strMinutes > 59) {Result=false;}
	if ((strSeconds > "") & (strSeconds < 0 | strSeconds > 59)) {Result=false;}

	if (Result) {
		
		strHour = strHour.toString();
		strMinutes = strMinutes.toString();
		strSeconds = strSeconds.toString();

		if (strHour.length == 1) {strHour = "0" + strHour;}

		if (strMinutes.length == 1) {strMinutes = "0" + strMinutes;}
	
		if (strSeconds.length == 1 & strSeconds > '') {strSeconds = "0" + strSeconds;}

	    TimeToCheck = strHour + ':' + strMinutes + ((strSeconds > '') ?  ':' + strSeconds : '')
	}
	
	if (!Result) {
		alert ("Invalid Time Entered, Must be in "+Format+" Format - Please try again");
		Result=false;
	} else {
		TimeField.value=TimeToCheck;
		Result=true;
	}

	return Result;

} // End ATSCheckTime();

//-----------------------------------------------------------------------------//
// Compare two dates to make that one cannot be greater or less than the other
// Date will come in mm/dd/yyyy format so convert to yyyymmdd and compare
// Function assumes that both dates are there if not it returns false.
//
function ATSCompareDates(FirstDate,Operator,SecondDate)
{
	var Result=false;

	if (FirstDate == "") {return Result;}
	if (SecondDate == "") {return Result;}

    var FirstDateToCheckArray = FirstDate.split("/");
    var strMonth = FirstDateToCheckArray[0];
    var strDay = FirstDateToCheckArray[1];
    var strYear = FirstDateToCheckArray[2];
    FirstDate = strYear + strMonth + strDay;	
    var SecondDateToCheckArray = SecondDate.split("/");
    var strMonth = SecondDateToCheckArray[0];
    var strDay = SecondDateToCheckArray[1];
    var strYear = SecondDateToCheckArray[2];
	SecondDate = strYear + strMonth + strDay;

	FirstDate = Number(FirstDate);
	SecondDate = Number(SecondDate);

	if (Operator == '==') {
		if ((FirstDate == SecondDate)) {return true;}
	}

	if (Operator == '>=') {
		if ((FirstDate >= SecondDate)) {return true;}
	}

	if (Operator == '>') {
		if ((FirstDate > SecondDate)) {return true;}
	}

	if (Operator == '<=') {
		if ((FirstDate <= SecondDate)) {return true;}
	}

	if (Operator == '<') {
		if ((FirstDate < SecondDate)) {return true;}
	}

	if (Operator == '!=') {
		if ((FirstDate != SecondDate)) {return true;}
	}

	return Result;
}
//-----------------------------------------------------------------------------//
// Compare two dates to make that one cannot be greater or less than the other
// Date will come in mm/dd/yyyy format so convert to yyyymmdd and compare
function ATSCompareTimes(FirstTime,Operator,SecondTime)
{
	var Result=false;
	if (FirstTime == "") {return Result;}
	if (SecondTime == "") {return Result;}

    FirstTime = FirstTime.replace(/:/g,'');
	SecondTime = SecondTime.replace(/:/g,'');

	if (Operator == '==') {
		if ((FirstTime == SecondTime)) {return true}
	}

	if (Operator == '>=') {
		if ((FirstTime >= SecondTime)) {return true;}
	}

	if (Operator == '>') {
		if ((FirstTime > SecondTime)) {return true;}
	}

	if (Operator == '<=') {
		if ((FirstTime <= SecondTime)) {return true;}
	}

	if (Operator == '<') {
		if ((FirstTime < SecondTime)) {return true;}
	}

	if (Operator == '!=') {
		if ((FirstTime != SecondTime)) {return true;}
	}

	return Result;

}
//-----------------------------------------------------------------------//
// Date Validation
//-----------------------------------------------------------------------//
function ATSValidateDate(objName) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	// var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	//strDate = datefield.value;
	strDate = objName;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			} else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
   		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
   		}
	}
//Adjustment for short years entered
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
   			}
		}
	
		if (isNaN(intMonth)) {
			err = 3;
			return false;
   		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
   			}
		} else {
			if (intday > 28) {
				err = 10;
				return false;
      		}
   		}
	}
	return true;
}
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	} else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}
// End of Date Validation and Formatting
/*--------------------------------------------------------------------------------------------------*/
//--------------------------------------------------------------------------------------------------*
// Function to add a row to the end of a table
//--------------------------------------------------------------------------------------------------*
function addRow(id)
{
    var tbody = document.getElementById
	(id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("column 1"))
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("column 2"))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
}
//--------------------------------------------------------------------------------------------------*
// open new window script
//--------------------------------------------------------------------------------------------------*
// How to call the window
// JavaScript Bible 3rd Edition Page 234
// Paramaters:
// Document Name = Name of html File to load
// WindowName    = Name of window
// options       =
//        `toolbar`     boolean    "Back" "Forward and other buttons
//        `location`    boolean    "Location Bar"
//        `directories` boolean    "What's New and other buttons in row
//        `status`      boolean    Status bar at bottom of window
//        `menubar*`    boolean    Menubar at top of window
//        `scrollbars`  boolean    Displays
//        `resizable`   boolean    Interface elements that allow resizing by dragging
//        `copyhistory` boolean    Duplicates GO menu history for new window
//        `width`       pixelCount Window outer width in pixels
//        `height`      pixelCount Window height in pixels
// <a href="javascript:openWindow('DocumentName','WindowName',options)">Open new Window </a>
//--------------------------------------------------------------------------------------------------*
var popupWin = null
function openWindow(url, name, options) {
  if (!popupWin || popupWin.closed) {
    popupWin = window.open(url, name, options);
  } else {
    popupWin.open(url, name, options);
    popupWin.focus();
  }
}

//--------------------------------------------------------------------------------------------------*
// Function to show empty row Extracted from CodeCharge Studio Sample code
//--------------------------------------------------------------------------------------------------*
function ShowNewEmptyRow(thisObj)
{
   var NS6 = (!document.all && document.getElementById) ? 1 : 0;
   var IE  = (document.all) ? 1 : 0;
   var O = typeof(opera) != "undefined";
   var i;
   var FormState = document.forms[0].FormState.value.split(";");
   var AllLength = parseInt(FormState[0])+parseInt(FormState[1]);
   if (parseInt(FormState[0]) == 0 ) {
      FormState[0] = 1;
   }
 
   for (i=FormState[0]; i<AllLength; i++) {
       var objRow = document.getElementById('row'+i);
       if (NS6 || O) {
          if (objRow.style.display == "none") {
              objRow.style.display = "";
              objRow.LastAttribute == "True";
              break;
          }
      } else {
          if (objRow.style.display == "none") {
             objRow.style.display = "block"; 
             objRow.LastAttribute == "True";
             break;
          }
      }
   }
}
//--------------------------------------------------------------------------------------------------*
// Following code controls the color change on the row being mousedover
// This code was extracted from the phpAdmin programs created by Nusphere
//--------------------------------------------------------------------------------------------------*
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
	//alert("1. Pointer and mark feature are disabled or the browser can't get the");
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
	//alert("2. Gets the current row and exits if the browser can't get it");
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    } else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    } else {
        return false;
    }

    // 3. Gets the current color...
	//alert("3. Gets the current color...");
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
	//alert("5. Sets the new color..." + newColor);
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/*
 * Sets/unsets the pointer and marker in vertical browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 *
 * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
 */
function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        domDetect    = false;
    } // end 3

    var c = null;
    // 5.1 ... with DOM compatible browsers except Opera
    for (c = 0; c < rowCellsCnt; c++) {
        if (domDetect) {
            currentColor = theCells[c].getAttribute('bgcolor');
        } else {
            currentColor = theCells[c].style.backgroundColor;
        }

        // 4. Defines the new color
        // 4.1 Current color is the default one
        if (currentColor == ''
            || currentColor.toLowerCase() == theDefaultColor1.toLowerCase() 
            || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
            if (theAction == 'over' && thePointerColor != '') {
                newColor              = thePointerColor;
            } else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.2 Current color is the pointer one
        else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
                 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
            if (theAction == 'out') {
                if (c % 2) {
                    newColor              = theDefaultColor1;
                } else {
                    newColor              = theDefaultColor2;
                }
            }
            else if (theAction == 'click' && theMarkColor != '') {
                newColor              = theMarkColor;
                marked_row[theRowNum] = true;
            }
        }
        // 4.1.3 Current color is the marker one
        else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
            if (theAction == 'click') {
                newColor              = (thePointerColor != '')
                                      ? thePointerColor
                                      : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
                marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                      ? true
                                      : null;
            }
        } // end 4

        // 5. Sets the new color...
        if (newColor) {
            if (domDetect) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
            // 5.2 ... with other browsers
            else {
                theCells[c].style.backgroundColor = newColor;
            }
        } // end 5
    } // end for

     return true;
 } // end of the 'setVerticalPointer()' function


