function AddShipmentDescription(Description)
{
	if (Description=='')
	{
		alert('Please enter a description');
	}
	else 
	{
		window.location = "./AddDescription/?Description=" + Description;
	}
}
function EditShipmentDescription(ID)
{
	window.open('./EditDescription/?DescriptionID=' + ID, 'DescriptionLookup',  'width=450,height=250,status=no,resizable=no,top=200,left=200');
}
function DeleteShipmentDescription(ID)
{
	var confirmation = window.confirm('WARNING: Are you sure you wish to delete this description?');
	if (confirmation)
	{
		window.location = "./DeleteDescription/?DescriptionID=" + ID;
	}
	return;
}
function DeleteUser(UserName, Page)
{
	var confirmation = window.confirm('WARNING: Are you sure you wish to delete this user?');
	if (confirmation)
	{
		window.location = "./Delete/?Page=" + Page + "&ID=" + UserName;
	}
	return;
}
function DeleteAdministrator(UserName, Page)
{
	var confirmation = window.confirm('WARNING: Are you sure you wish to delete this administrator?');
	if (confirmation)
	{
		window.location = "./Delete/?Page=" + Page + "&ID=" + UserName;
	}
	return;
}
function DeleteGroup(GroupName, Page)
{
	var confirmation = window.confirm('WARNING: Are you sure you wish to delete this group?\nAll users in this group will individually inherit its permissions.');

	var re = /&/g;
	urlGroupName = GroupName.replace(re, '%26');    //Replace "&" with "%26".

	if (confirmation)
	{
		window.location = "./Delete/?Page=" + Page + "&ID=" + urlGroupName;
	}
	return;
}
function checkEmailPref(textobj, checker) {
	val=true;
	if (!checkNull(textobj)) {
		p=textobj.indexOf('@');
		val = (p<1 || p==(val.length-1));
	}
	if(checker == false || val == false)
	{
		val = false;
	}
	return val;
}
function checkEmail(textobj, checker) {
	val=true;
	if (!checkNull(textobj)) {
		p=textobj.indexOf('@');
		val = (p<1 || p==(val.length-1));
	}
	if((val == true) && (checker == true))
	{
		alert('Invalid E-mail Address!');
	}
	else if(checker == false)
	{
		val = false;
	}
	return !val;
}
function checkNull(textobj) {
	var checker = trim(textobj);
	return ((checker == "") || (checker == null));
}
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function 
/**
 * 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
    //    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 {
        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;
			//for(var i = 1; i < marked_row.length; i++){marked_row[i] = false;}
            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;
		//	for(var i = 1; i < marked_row.length; i++){marked_row[i] = false;}
            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...
    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

function setCellPointer(theCell, theAction, theDefaultColor, thePointerColor, theMarkColor)
{	
    // 1. Pointer and mark feature are disabled -> exits
    if ((thePointerColor == '' && theMarkColor == '')) {
        return false;
    }
    // 2. Gets the current color...
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 2.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCell.getAttribute) != 'undefined') {
        currentColor = theCell.getAttribute('bgcolor');
        domDetect    = true;
    }
    // 2.2 ... with other browsers
    else {
        currentColor = theCell.style.backgroundColor;
        domDetect    = false;
    } // end 2
    // 3. Defines the new color
    // 3.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;
        }
    }
    // 3.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
        }
    }
    // 3.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {           
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
        }
    } // end 3
    // 4. Sets the new color...
    if (newColor) {
        var c = null;
        // 4.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            theCell.setAttribute('bgcolor', newColor, 0);
        }
        // 4.2 ... with other browsers
        else {
            theCell.style.backgroundColor = newColor;
        }
    } // end 4
    return true;
} // end of the 'setCellPointer()' function

function EmailShippingDocuments(ShippingManifest, Trailer, ShippingLabel, BillOfLading, AddressLabel, EmailAddress, HWBNumber, ShippingLabelHeight, ShippingLabelWidth, AddressLabelHeight, AddressLabelWidth, HWBDate, Avery5168AddressLabel, Avery5168AddressLabelStartingPoint, Avery5126AddressLabel, Avery5126AddressLabelStartingPoint, Barcode3of9AddressLabel, Barcode3of9AddressLabelHeight, Barcode3of9AddressLabelWidth)
{            
	if ((ShippingManifest) || (ShippingLabel) || (BillOfLading) || (AddressLabel) || (Avery5168AddressLabel) || (Avery5126AddressLabel) || (Barcode3of9AddressLabel))
	{
	   Field = true;
	}
	else
	{
	   Field = false;
	   alert('Please select at least one document.');
	}       
	if(checkEmail(EmailAddress, true) && Field)
	{
								   
	   window.open ('../../Common/EmailShippingDocuments/?HWB=' + HWBNumber + 
		   '&ShippingLabelHeight=' + ShippingLabelHeight + 
		   '&ShippingLabelWidth=' + ShippingLabelWidth + 
		   '&AddressLabelHeight=' + AddressLabelHeight + 
		   '&AddressLabelWidth=' + AddressLabelWidth + 
		   '&To=' + EmailAddress + 
		   '&ShippingManifest=' + ShippingManifest + '&Trailer=' + Trailer + 
		   '&BillOfLading=' + BillOfLading + 
		   '&ShippingLabel=' + ShippingLabel + 
		   '&AddressLabel=' + AddressLabel + 
		   '&Date=' + HWBDate + 
		   '&Avery5168AddressLabel=' + Avery5168AddressLabel + 
		   '&Avery5168AddressLabelStartingPoint=' + Avery5168AddressLabelStartingPoint + 
		   '&Avery5126AddressLabel=' + Avery5126AddressLabel + 
		   '&Avery5126AddressLabelStartingPoint=' + Avery5126AddressLabelStartingPoint + 
		   '&Barcode3of9AddressLabel=' + Barcode3of9AddressLabel + 
		   '&Barcode3of9AddressLabelHeight=' + Barcode3of9AddressLabelHeight + 
		   '&Barcode3of9AddressLabelWidth=' + Barcode3of9AddressLabelWidth, 
		   '', 
		   'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=200,height=100,left=200,top=150'
	   ); 
	}
}
function DownloadShippingDocuments(ShippingManifest, Trailer, ShippingLabel, BillOfLading, AddressLabel, HWBNumber, ShippingLabelHeight, ShippingLabelWidth, AddressLabelHeight, AddressLabelWidth, HWBDate, Avery5168AddressLabel, Avery5168AddressLabelStartingPoint, Avery5126AddressLabel, Avery5126AddressLabelStartingPoint, Barcode3of9AddressLabel, Barcode3of9AddressLabelHeight, Barcode3of9AddressLabelWidth)
{
	if ((ShippingManifest) || (ShippingLabel) || (BillOfLading) || (AddressLabel) || (Avery5168AddressLabel) || (Avery5126AddressLabel) || (Barcode3of9AddressLabel))
	{
		Field = true;
	}
	else
	{
		Field = false;
		alert('Please select at least one document.');
	}
	if (ShippingManifest && Field)
	{
	   window.open('ShippingManifest/?Date=' + HWBDate + '&Trailer=' + Trailer, '', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes'); 
	}
	if (ShippingLabel && Field)
	{
	   window.open('ShippingLabel/?HWB=' + HWBNumber + '&LabelHeight=' + ShippingLabelHeight + '&LabelWidth=' + ShippingLabelWidth ,'','');
	}
	
	if (BillOfLading && Field)
	{
		window.open('BillOfLading/?HWB=' + HWBNumber,'','');
	}
	if (AddressLabel && Field)
	{
	   window.open('AddressLabel/?HWB=' + HWBNumber + '&LabelHeight=' + AddressLabelHeight + '&LabelWidth=' + AddressLabelWidth ,'','');
	}
	if (Avery5168AddressLabel && Field)
	{
		window.open('Avery5168AddressLabel/?HWB=' + HWBNumber + '&Avery5168AddressLabelStartingPoint=' + Avery5168AddressLabelStartingPoint,'','');
	}
	if (Avery5126AddressLabel && Field)
	{
		window.open('Avery5126AddressLabel/?HWB=' + HWBNumber + '&Avery5126AddressLabelStartingPoint=' + Avery5126AddressLabelStartingPoint,'','');
	}
	if (Barcode3of9AddressLabel && Field)
	{
	   window.open('Barcode3of9AddressLabel/?HWB=' + HWBNumber + '&LabelHeight=' + Barcode3of9AddressLabelHeight + '&LabelWidth=' + Barcode3of9AddressLabelWidth, '', '');
	}
}

var bIE = (window.navigator.appVersion.indexOf("MSIE") > -1);
function getHttpRequestObject(){
 if(bIE){
    return new ActiveXObject("Msxml2.XMLHTTP");
 } else {
    return new XMLHttpRequest();
 }
}