var Ajax = new Object();
Ajax.Commands=new Object();

//properly URL encode a string
function URLencode(sStr) {
return escape(sStr).
         replace(/\+/g, '%2B').
            replace(/\"/g,'%22').
               replace(/\'/g, '%27').
                 replace(/\//g,'%2F');
}

 /*----SaveFaxAffinityEdit----*/
Ajax.Commands.SaveFaxAffinityEdit=function(elementId,ajaxCommand,cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter; 
    this.elementId = elementId;
    this.faxaffinityid = this.elementId;
    this.priority = document.getElementById("faxAffinityPriorityEdit" + this.elementId).value;
    this.serverid = document.getElementById("faxAffinityServerNameEdit" + this.elementId).value;
    var serveridindex = document.getElementById("faxAffinityServerNameEdit" + this.elementId).selectedIndex;
    
    this.servername = document.getElementById("faxAffinityServerNameEdit" + this.elementId).options[serveridindex].innerHTML;
    this.ajaxCommand = ajaxCommand;
}

Ajax.Commands.SaveFaxAffinityEdit.prototype.ToRequestString=function(){
    return "faxAffinityId=" + this.faxaffinityid + "&faxAffinityPriority=" + this.priority + "&faxAffinityServerId=" + this.serverid + "&faxAffinityServerName=" + this.servername;
}

Ajax.Commands.SaveFaxAffinityEdit.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    var affinityId=attrs.getNamedItem("affinityid").value;
    var affinitypriority=attrs.getNamedItem("priorityvalue").value;
    var affinityservername=attrs.getNamedItem("servername").value;

    if(status=="Successful")
    {
    document.getElementById("faxAffinityPriorityDisplay" + affinityId).innerHTML = affinitypriority;
    document.getElementById("faxAffinityServerNameDisplay" + affinityId).innerHTML= affinityservername;
    }
    
    document.getElementById("faxAffinityMessageDisplay").innerHTML =  message + "!";
    document.getElementById("faxAffinityMessageDisplay").style.display = 'block';
    document.getElementById("faxAffinityMessageDisplay").style.visibility = 'visible'; 
}
 
 /*----DeleteFaxAffinity----*/
Ajax.Commands.DeleteFaxAffinity=function(elementId,ajaxCommand,cmdCounter){
    var confirmDelete = confirm('Are you sure you want to delete this entry?');
    
    if(confirmDelete==true)
    { 
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter; 
	this.elementId = elementId;
	this.faxaffinityid = this.elementId;
	this.ajaxCommand = ajaxCommand;
	HideFaxAffinityDisplayRow(elementId);
    }
}

Ajax.Commands.DeleteFaxAffinity.prototype.ToRequestString=function(){
    return "faxAffinityId=" + this.faxaffinityid;
}

Ajax.Commands.DeleteFaxAffinity.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    var affinityId=attrs.getNamedItem("affinityid").value;
   
    document.getElementById("faxAffinityMessageDisplay").innerHTML =  message + "!";
    document.getElementById("faxAffinityMessageDisplay").style.display = 'block';
    document.getElementById("faxAffinityMessageDisplay").style.visibility = 'visible'; 
}

/////////////////////
// FaxServer Entries
/////////////////////

Ajax.Commands.SaveFaxServerEdit=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter; 
    this.elementId = elementId;
    this.faxserverid = this.elementId;
    this.ipaddress = document.getElementById("faxServerIPAddressEdit" + this.elementId).value;
    this.servername = document.getElementById("faxServerServerNameEdit" + this.elementId).value;
    this.machinename = document.getElementById("faxServerMachineNameEdit" + this.elementId).value;
    this.serverport = document.getElementById("faxServerPortEdit" + this.elementId).value;
    this.numberofports = document.getElementById("faxServerNumberOfPortsEdit" + this.elementId).value;

    this.ismonitorableid = document.getElementById("faxServerIsMonitorableEdit" + this.elementId).value;
    var ismonitorableidindex = document.getElementById("faxServerIsMonitorableEdit" + this.elementId).selectedIndex;
    this.ismonitorable = document.getElementById("faxServerIsMonitorableEdit" + this.elementId).options[ismonitorableidindex].value;
    
    this.hasvoiceid = document.getElementById("faxServerHasVoiceEdit" + this.elementId).value;
    var hasvoiceidindex = document.getElementById("faxServerHasVoiceEdit" + this.elementId).selectedIndex;
    this.hasvoice = document.getElementById("faxServerHasVoiceEdit" + this.elementId).options[hasvoiceidindex].value; 
    
    this.isserveractiveid = document.getElementById("faxServerIsActiveEdit" + this.elementId).value;
    var isserveractiveidindex = document.getElementById("faxServerIsActiveEdit" + this.elementId).selectedIndex;
    this.isserveractive = document.getElementById("faxServerIsActiveEdit" + this.elementId).options[isserveractiveidindex].value; 

    this.ajaxCommand = ajaxCommand;
}


Ajax.Commands.SaveFaxServerEdit.prototype.ToRequestString=function(){
    return "faxServerId=" + this.faxserverid + "&faxServerName=" + this.servername + "&faxServerMachineName=" + this.machinename + "&faxServerIPAddress=" + this.ipaddress + "&faxServerPort=" + this.serverport + "&faxServerNumberOfPorts=" + this.numberofports + "&faxServerHasVoice=" + this.hasvoice + "&faxServerIsMonitorable=" + this.ismonitorable + "&faxServerIsActive=" + this.isserveractive;
}


Ajax.Commands.SaveFaxServerEdit.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    var serverId=attrs.getNamedItem("faxserverid").value;
    var faxserveripaddress=attrs.getNamedItem("faxipaddress").value;
    var faxservername=attrs.getNamedItem("faxservername").value;
    var faxservermachinename=attrs.getNamedItem("faxservermachinename").value;
    var faxserverport=attrs.getNamedItem("faxserverport").value;
    var faxservernumberofports=attrs.getNamedItem("faxservernumberofports").value;
    var faxserverisactive=document.getElementById("faxServerIsActiveEdit" + serverId).value;
    if(faxserverisactive == 'N')
    {
	faxserverisactive = "No";
    }
    if(faxserverisactive == 'Y')
    {
	faxserverisactive = "Yes";
    }
    
    var faxserverismonitorable=document.getElementById("faxServerIsMonitorableEdit" + serverId).value;
    if(faxserverismonitorable == 'N')
    {
	faxserverismonitorable = "No";
    }
    if(faxserverismonitorable == 'Y')
    {
	faxserverismonitorable = "Yes";
    }	
    
    var faxserverhasvoice=document.getElementById("faxServerHasVoiceEdit" + serverId).value;
    if(faxserverhasvoice == 'N')
    {
	faxserverhasvoice = "No";
    }
    if(faxserverhasvoice == 'Y')
    {
	faxserverhasvoice = "Yes";
    }
    
    if(status=="Successful")
    {
	document.getElementById("faxServerServerNameDisplay" + serverId).innerHTML = faxservername;
	document.getElementById("faxServerMachineNameDisplay" + serverId).innerHTML = faxservermachinename;
	document.getElementById("faxServerIPAddressDisplay" + serverId).innerHTML = faxserveripaddress;
	document.getElementById("faxServerPortDisplay" + serverId).innerHTML = faxserverport;
	document.getElementById("faxServerNumberOfPortsDisplay" + serverId).innerHTML = faxservernumberofports;
	document.getElementById("faxServerActiveDisplay" + serverId).innerHTML = faxserverisactive;
	document.getElementById("faxServerMonitorableDisplay" + serverId).innerHTML = faxserverismonitorable;
	document.getElementById("faxServerHasVoiceDisplay" + serverId).innerHTML = faxserverhasvoice;
    }
    
    document.getElementById("faxServerMessageDisplay").innerHTML =  message + "!";
    document.getElementById("faxServerMessageDisplay").style.display = 'block';
    document.getElementById("faxServerMessageDisplay").style.visibility = 'visible'; 
}

Ajax.Commands.DeleteFaxServer=function(elementId, ajaxCommand, cmdCounter){
    var confirmDelete = confirm('Are you sure you want to delete this entry?');
    
    if(confirmDelete==true)
    { 
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter; 
	this.elementId = elementId;
	this.serverid = this.elementId;
	HideFaxServerDisplayRow(elementId);
	this.ajaxCommand = ajaxCommand;
    }
}

Ajax.Commands.DeleteFaxServer.prototype.ToRequestString=function(){
    return "faxServerId=" + this.serverid;
}

Ajax.Commands.DeleteFaxServer.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    var serverId=attrs.getNamedItem("faxserverid").value;
}

// Begin InternalMonitorUtils functions
// Order-Ready Email Notification to Customer
Ajax.Commands.SendOrderReadyEmailNotification=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.orderId = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.additionalNotes = URLencode(document.getElementById('additionalNotes').value);
    document.getElementById('emailNotificationStatus').innerHTML='';
    document.getElementById('emailNotificationStatus').innerHTML='<p align="center" style="color:orange">Sending Notification....</p>';
}

Ajax.Commands.SendOrderReadyEmailNotification.prototype.ToRequestString=function(){
    return "orderId=" + this.orderId + "&additionalNotes=" + this.additionalNotes;
}

Ajax.Commands.SendOrderReadyEmailNotification.prototype.ParseResponse=function(docEl){
    document.getElementById('emailNotificationStatus').innerHTML='';
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var orderid=attrs.getNamedItem("orderid").value;
    
    if(status=='Successful'){
	document.getElementById('orderId').value = '';
	document.getElementById('additionalNotes').innerHTML = '';
	document.getElementById('emailNotificationStatus').innerHTML = '<p align="center" style="color:green">Email Notification on Order: ' + orderid + ' ' + status + '.</p>';
    } else {
	document.getElementById('emailNotificationStatus').innerHTML = '<p align="center" style="color:red">Email Notification ' + status + '. ' + message + '.</p>';
    }
}

//Close vendor for day.
Ajax.Commands.CloseVendorForDay=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId
    this.vendorid = this.elementId;
    this.ajaxCommand = ajaxCommand;
      
    document.getElementById('closeVendorStatus').innerHTML='<p align="center" style="color:orange">Closing Vendor</p>';
}

Ajax.Commands.CloseVendorForDay.prototype.ToRequestString=function(){
    return "vendorId=" + this.vendorid;
}

Ajax.Commands.CloseVendorForDay.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    
    if(status=='successful'){
	document.getElementById('closeVendorStatus').innerHTML = "<p align=\"center\" style=\"color:green\">"+message+"</p>";
	document.getElementById('vendorSearchResultsForClosing').innerHTML = '';
	document.getElementById('vendorNameForClosing').value = '';
	var elementArray = new Array(2);
	elementArray[0]='closeVendorInstructions';
	elementArray[1]='closeVendorButton';
	toggleElementDisplay(elementArray, false);
    } else {
	document.getElementById('closeVendorStatus').innerHTML= "<p align=\"center\" style=\"color:red\">"+message+"</p>";
    }
}

//Cancel Order
Ajax.Commands.CancelOrder=function(elementId, ajaxCommand, cmdCounter) {
    this.priority = net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id = cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.cancelOrderId = this.elementId;
    this.reasonforordercancellation = URLencode(document.getElementById('reasonForOrderCancellation').value);
    this.ordercancellationrequestedby = URLencode(document.getElementById('orderCancellationRequestedBy').value);
    this.cancelOrderMode = URLencode(document.getElementById('cancelOrderMode').value);

    this.expectedordererlastname = document.getElementById('expectedOrdererLastNameForCancel').value;

    document.getElementById('cancelOrderStatus').innerHTML = '<p align="center" style="color:orange">Canceling Order</p>';
}

Ajax.Commands.CancelOrder.prototype.ToRequestString=function() {
    return "cancelOrderId=" + this.cancelOrderId + "&reasonForOrderCancellation=" + this.reasonforordercancellation + "&orderCancellationRequestedBy=" + this.ordercancellationrequestedby + "&cancelOrderMode="+ this.cancelOrderMode + "&expectedOrdererLastName=" + this.expectedordererlastname;
}

Ajax.Commands.CancelOrder.prototype.ParseResponse=function(docEl) {
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message = attrs.getNamedItem('message').value;


    if (this.cancelOrderMode == "CANCEL_ORDER_INITIAL") {
	//Set the cancelOrderMode element to confirm mode	
	document.getElementById('cancelOrderMode').value = "CANCEL_ORDER_CONFIRM";


	//Parse message response and display a confirmation box 
	//If they choose not to confirm then I need to have some logic to reset the cancelOrderMode to defaults.
	if (status == 'successful') {
	    var arrMessageData = message.split("|");
	    var confMsgTxt = "Are you sure you want to cancel order for\nCustomer Name: " + 
						    arrMessageData[0] + " " + arrMessageData[1] + "\n";
    		
	    confMsgTxt = confMsgTxt + "Vendor Name: " + arrMessageData[2] + "?";	
	    var blnIsConfirmed = confirm(confMsgTxt);
    		
	    if (blnIsConfirmed) {
		    cancelOrder();
	    } else {
		//restore defaults
		document.getElementById('cancelOrderMode').value = "CANCEL_ORDER_INITIAL";
		document.getElementById('cancelOrderStatus').innerHTML = '';
	    }
	} else {
	    //Display Errors in status
	    document.getElementById('cancelOrderStatus').innerHTML = "<p align=\"center\" style=\"color:red\">" + message + "</p>";
	    document.getElementById('cancelOrderMode').value = "CANCEL_ORDER_INITIAL";
	}
    }
    else if (this.cancelOrderMode == "CANCEL_ORDER_CONFIRM") {
	//Display Status message
	if (status == 'successful') {
	    document.getElementById('cancelOrderStatus').innerHTML = "<p align=\"center\" style=\"color:green\">" + message +"</p>";
	    document.getElementById('cancelOrderId').value = ''
	    document.getElementById('reasonForOrderCancellation').value = ''
	    document.getElementById('orderCancellationRequestedBy').value = ''
	    document.getElementById('expectedOrdererLastNameForCancel').value = ''
	} else {
	    document.getElementById('cancelOrderStatus').innerHTML = "<p align=\"center\" style=\"color:red\">" + message + "</p>";
	}
    	
	//Set the cancelOrderMode element to the initial conditions
	document.getElementById('cancelOrderMode').value = "CANCEL_ORDER_INITIAL";
    } else {
	//restore document to initial conditions
	document.getElementById('cancelOrderMode').value = "CANCEL_ORDER_INITIAL";
	document.getElementById('cancelOrderStatus').innerHTML = '';
    }
}

Ajax.Commands.AdjustOrder=function(elementId, ajaxCommand, cmdCounter){
    this.priority = net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id = cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.adjustOrderId = this.elementId;
    this.adjustOrderAmount = URLencode(document.getElementById('adjustOrderAmount').value);
    this.reasonForAdjustment = URLencode(document.getElementById('reasonForOrderAdjustment').value);
    this.orderAdjustmentRequestedBy = URLencode(document.getElementById('orderAdjustmentRequestedBy').value);

    this.expectedordererlastname = document.getElementById('expectedOrdererLastNameForAdjust').value;
    this.adjustOrderMode = document.getElementById('adjustOrderMode').value;

    document.getElementById('adjustOrderStatus').innerHTML = '<p align="center" style="color:orange">Adjusting Order</p>';	
}

Ajax.Commands.AdjustOrder.prototype.ToRequestString=function() {
    return "adjustOrderId=" + this.adjustOrderId + "&adjustOrderAmount=" + this.adjustOrderAmount + "&adjustOrderMode=" +
		    this.adjustOrderMode + "&reasonForOrderAdjustment=" + this.reasonForAdjustment + "&orderAdjustmentRequestedBy=" + this.orderAdjustmentRequestedBy + "&expectedOrdererLastName=" + this.expectedordererlastname;
}

Ajax.Commands.AdjustOrder.prototype.ParseResponse=function(docEl) {
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message = attrs.getNamedItem('message').value;

    if (this.adjustOrderMode == "ADJUST_ORDER_INITIAL") {
	    //Set the adjustOrderMode element to confirm mode
	document.getElementById('adjustOrderMode').value = "ADJUST_ORDER_CONFIRM";
	//parse message response and display confirmation box
	if (status == 'successful') {
	    var arrMessageData = message.split("|");
	    var confMsgTxt = "Are you sure you want to adjust order for\nCustomer Name: " +
						    arrMessageData[0] + " " + arrMessageData[1] + "\n";

	    var confMsgTxt = confMsgTxt + "Vendor Name: " + arrMessageData[2] + "\nAmount: " + this.adjustOrderAmount + "?";

	    var blnIsConfirmed = confirm(confMsgTxt);

	    if (blnIsConfirmed) {
		adjustOrder();
	    } else {
		//restore defaults
		document.getElementById('adjustOrderMode').value = "ADJUST_ORDER_INITIAL";
		document.getElementById('adjustOrderStatus').innerHTML = '';
	    }
	} else {
	    //Display errors and restore document
	    document.getElementById('adjustOrderStatus').innerHTML = "<p align=\"center\" style=\"color:red\">" + message + "</p>";
	    document.getElementById('adjustOrderMode').value = "ADJUST_ORDER_INITIAL";
	}
    } else if (this.adjustOrderMode == "ADJUST_ORDER_CONFIRM") {
	if (status == 'successful') {
	    document.getElementById('adjustOrderAmount').value = '';
	    document.getElementById('adjustOrderId').value = '';	
	    document.getElementById('reasonForOrderAdjustment').value = '';
	    document.getElementById('orderAdjustmentRequestedBy').value = '';
	    document.getElementById('expectedOrdererLastNameForAdjust').value = '';

	    document.getElementById('adjustOrderStatus').innerHTML = "<p align=\"center\" style=\"color:green\">" + message + "</p>";
	} else {
	    document.getElementById('adjustOrderStatus').innerHTML = "<p align=\"center\" style=\"color:red\">" + message + "</p>";
	}

	document.getElementById('adjustOrderMode').value = "ADJUST_ORDER_INITIAL";
    } else {
	//restore document to initial conditions
	document.getElementById('adjustOrderMode').value = "ADJUST_ORDER_INITIAL";
	document.getElementById('adjustOrderStatus').innerHTML = '';
    }
}

//Change Vendor Order Event Type
Ajax.Commands.ChangeVendorOrderEventType=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.vendorid = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.ordereventtype = document.getElementsByName('ordereventtypeid');
	
    for(var i=0; i<this.ordereventtype.length; i++){
        if(this.ordereventtype[i].checked){
            this.ordereventtypeid = this.ordereventtype[i].value;
            break;
        }
    }
    document.getElementById('vendorTypeChangeStatus').innerHTML='';
    document.getElementById('vendorTypeChangeStatus').innerHTML='<p align="center" style="color:orange">Changing Vendor Type....</p>';
}

Ajax.Commands.ChangeVendorOrderEventType.prototype.ToRequestString=function(){
    return "vendorId=" + this.vendorid + "&orderEventTypeId=" + this.ordereventtypeid;
}

Ajax.Commands.ChangeVendorOrderEventType.prototype.ParseResponse=function(docEl){
    document.getElementById('vendorTypeChangeStatus').innerHTML='';
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    if(status=='Successful'){
	    document.getElementById('vendorTypeChangeStatus').innerHTML = '<p align="center" style="color:green">' + message + '</p>';
	document.getElementById('vendorSearchResultsForChangingType').innerHTML = '';
	document.getElementById('vendorNameForTypeChanges').value = '';
        var elementArray = new Array(2);
        elementArray[0]='changeVendorTypeInstructions';
        elementArray[1]='changeVendorTypeButton';
        toggleElementDisplay(elementArray, false);
    } else {
	document.getElementById('vendorTypeChangeStatus').innerHTML = '<p align="center" style="color:red">Vendor Type Change ' + status + '. ' + message + '.</p>';
    }
}

//Change Vendor Order Event Type
Ajax.Commands.ViewOrder=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.orderid = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.invoicetypes = document.getElementsByName('invoiceType');

    for(var i=0; i<this.invoicetypes.length; i++){
        if(this.invoicetypes[i].checked){
            this.invoicetype = this.invoicetypes[i].value;
            break;
        }
    }
    document.getElementById('viewOrderStatus').innerHTML='<p align="center" style="color:red">Fetching Order...</p>';
}

Ajax.Commands.ViewOrder.prototype.ToRequestString=function(){
    return "orderId=" + this.orderid + "&invoiceTypeRequested=" + this.invoicetype;
}

Ajax.Commands.ViewOrder.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var orderurl=attrs.getNamedItem("orderurl").value;
    var orderid=attrs.getNamedItem("orderid").value;

    if(status=='Failed'){
	document.getElementById('viewOrderStatus').innerHTML = '<p align="center" style="color:red">' + message + '!</p>';
    }else{
        tilewindow = window.open(orderurl,"ShowOrder","toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,height=600,width=670");
	document.getElementById('viewOrderStatus').innerHTML = '<p align="center" style="color:green">Order: ' + orderid + " View " + status + '</p>';
	document.getElementById('orderNumber').value = '';
    }
}

//Search for Vendor
Ajax.Commands.VendorSearchForMenuCopy=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.vendorName = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.sourceSearchVendor = URLencode(document.getElementById('sourceSearchVendor').value);
    this.destSearchVendor = URLencode(document.getElementById('destSearchVendor').value);
    this.searchType = URLencode(document.getElementById('searchType').value);

    document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:orange">Searching For Vendor...</p>';
}

Ajax.Commands.VendorSearchForMenuCopy.prototype.ToRequestString=function() {
	return "sourceSearchVendor="+this.sourceSearchVendor+"&destSearchVendor="+this.destSearchVendor+"&searchType="+this.searchType;
}

Ajax.Commands.VendorSearchForMenuCopy.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    //var numberFound = attrs.getNamedItem("numberFound").value;
    //var tableSearchType = attrs.getNamedItem("searchType").value;

    var html = "<table id=\""+tableSearchType+"\">";

    var vendorsEl = docEl.childNodes[0];
    var attrsChild = docEl.childNodes[0].attributes;

    var numberFound = attrsChild.getNamedItem("numberFound").value;

    if (numberFound == 0) {
	document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:red">No Vendors found.</p>';
    }
    else {
	document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:green">'+numberFound+' Vendors Found.</p>';
    }
    var tableSearchType = attrsChild.getNamedItem("searchType").value;

    for (i=0; i<numberFound; i++){
	var elChild=vendorsEl.childNodes[i];
	if(elChild == null) {
	    break;
	}

	attrs = elChild.attributes;
	var vendorId=attrs.getNamedItem("vendorId").value;
	var vendorName=attrs.getNamedItem("vendorName").value;

	if (tableSearchType=="VendorSource") {
	    html += "<tr><td><input name='SourceChoices' id='srcChoice_"+vendorId+"' type='radio' value='"+vendorId+"' onclick='disableTargetVendor(" + vendorId + ")'>"+vendorName+"</input></td></tr>";
	}
	else {
	    html += "<tr><td><input name='DestinationChoices' id='destChoice_"+vendorId+"' type='checkbox' value='"+vendorId+"'>"+vendorName+"</td></tr>";
	}
    }

    html += "</table>"

    if (tableSearchType=="VendorSource") {
	document.getElementById('sourceSearchDiv').innerHTML = html;
    }
    else {
	document.getElementById('destSearchDiv').innerHTML = html;
    }
}

Ajax.Commands.MenuCopy=function(elementId, ajaxCommand, cmdCounter) {
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.ajaxCommand = ajaxCommand;
    this.elementId=elementId;

    this.srcChoice = URLencode(document.getElementById('srcChoice').value);
    this.destChoice = URLencode(document.getElementById('destChoice').value);

    document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:orange">Please wait while Menu Copy takes place...</p>';
}

Ajax.Commands.MenuCopy.prototype.ToRequestString=function() {
    return "srcChoice="+this.srcChoice+"&destChoice="+this.destChoice;
}

Ajax.Commands.MenuCopy.prototype.ParseResponse=function(docEl) {
    var attrs = docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    
    if(status=="success"){
        document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:green">' + message + '</p>';
    } else {
	document.getElementById('searchVendorStatus').innerHTML='<p align="center" style="color:red">The following error occurred: ' + message + '.</p>';
    }
    enableSearchButtons();
    
}


//Search for Vendor by VendorName
Ajax.Commands.VendorSearch=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.vendorName = this.elementId;
    this.ajaxCommand = ajaxCommand;

    //Where should the status be displayed
    this.statusDisplayTag = document.getElementById('vendorSearchStatusTag').value;
    //where should the result be displayed
    this.resultDisplayDiv = document.getElementById('vendorSearchResultDisplayDiv').value;
    //what mode should the result be displayed in
    this.resultDisplayType = document.getElementById('vendorSearchResultDisplayType').value;

    document.getElementById(this.statusDisplayTag).innerHTML='<p align="center" style="color:orange">Searching For Vendors...</p>';
}

Ajax.Commands.VendorSearch.prototype.ToRequestString=function() {
	return "searchVendorName="+this.vendorName;
}

Ajax.Commands.VendorSearch.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;

    var html = "<table id='vendorSearchResults'>";

    var vendorsEl = docEl.childNodes[0];
    var attrsChild = docEl.childNodes[0].attributes;

    var numberFound = attrsChild.getNamedItem("numberFound").value;

    document.getElementById('vendorSearchResultNumberFound').value = numberFound;

    if (numberFound == 0) {
	    document.getElementById(this.statusDisplayTag).innerHTML = '<p align="center" style="color:red">No Vendors found.</p>';
    } else {
	    document.getElementById(this.statusDisplayTag).innerHTML = '<p align="center" style="color:green">'+numberFound+' Vendors Found.</p>';
    }

    for (i=0; i<numberFound; i++){
	var elChild=vendorsEl.childNodes[i];
	if(elChild == null) {
	    break;
	}

	attrs = elChild.attributes;
	var vendorId=attrs.getNamedItem("vendorId").value;
	var vendorName=attrs.getNamedItem("vendorName").value;

	if (this.resultDisplayType=="RADIO") {
	    html += "<tr><td class='htil'><input name='resultVendorId' id='resultVendorId' type='radio' value='"+vendorId+"'";
	    if(i==0){
		html += " checked";
	    }
	    html += " />"+vendorName+"</td></tr>";
	}
	else {
	    html += "<tr><td class='htil'><input name='resultVendor_"+vendorId+"' id='resultVendor_"+vendorId+"' type='checkbox' value='"+vendorId+"' />"+vendorName+"</td></tr>";
	}
    }
    html += "</table>"

    document.getElementById(this.resultDisplayDiv).style.display = 'block';
    document.getElementById(this.resultDisplayDiv).innerHTML = html;

}

//Check Vendor Availability
Ajax.Commands.CheckSelectedVendorAvailability=function(elementId, ajaxCommand, cmdCounter) {
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.ajaxCommand = ajaxCommand;
    this.elementId=elementId;
    this.serviceareaid = this.elementId;
    this.firmid = document.getElementById('FirmId').value;

    document.getElementById('ajaxInProgressIndicator').innerHTML = '<img src="../images/ajaxIndicator.gif" />';
    document.getElementById('groupOrderTable').disabled = true;

    selectedDeliveryDay = document.getElementById('DeliveryDay').value;
    selectedDeliveryTime = document.getElementById('DeliveryTime').value;

    this.selecteddeliverydatetime = selectedDeliveryDay + ' ' + selectedDeliveryTime;

    selectedVendorLocations = document.getElementById('VendorsAllowed');
    this.selectedvendorlocationstring = '';
    for(var i=0; i<selectedVendorLocations.length;i++){
	if(selectedVendorLocations[i].selected){
	   if (this.selectedvendorlocationstring.length == 0){ 
		this.selectedvendorlocationstring = selectedVendorLocations[i].value + "|" + URLencode(selectedVendorLocations[i].text);
	    }else{
		this.selectedvendorlocationstring += ',' + selectedVendorLocations[i].value + "|" + URLencode(selectedVendorLocations[i].text);
	    }
	}
    }
}

Ajax.Commands.CheckSelectedVendorAvailability.prototype.ToRequestString=function() {
    return "serviceAreaId=" + this.serviceareaid + "&firmId=" + this.firmid + "&selectedDeliveryDateTime=" + this.selecteddeliverydatetime + "&selectedVendorLocations=" + this.selectedvendorlocationstring;
}

Ajax.Commands.CheckSelectedVendorAvailability.prototype.ParseResponse=function(docEl) {
    var attrs = docEl.attributes;
    var status=attrs.getNamedItem("status").value;
    var message=attrs.getNamedItem("message").value;
    var unavailablevendors=attrs.getNamedItem("unavailablevendors").value;

    document.getElementById('ajaxInProgressIndicator').innerHTML = '';
    document.getElementById('groupOrderTable').disabled = false;

    var vendorNodes = docEl.getElementsByTagName('vendor');
        
    var allowedVendors = "<Select id='VendorsAllowed' name=\"VendorsAllowed\" class=\"small\" multiple size=10  onchange='javascript:VendorSelector_OnChange(this);'>";
    for(var j=0; j<vendorNodes.length; j++){
	allowedVendors += "<option value=\"" + vendorNodes[j].attributes.getNamedItem("vendorLocationId").value + "\" " + vendorNodes[j].attributes.getNamedItem("selectedOrNot").value + " >" + vendorNodes[j].attributes.getNamedItem("vendorName").value + "</option>";
    }    
    allowedVendors += "</select>";
        
    if(unavailablevendors.length>0){
	alert('The following vendors from your selection are not available at the delivery time you selected. These will be removed from the list: \n\n' + unavailablevendors);
    }
    document.getElementById('AvailableVendors').innerHTML = allowedVendors;
}

//CheckMinimumTipAmountForGO
Ajax.Commands.CheckMinimumTipAmountForGO=function(elementId, ajaxCommand, cmdCounter) {
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.ajaxCommand = ajaxCommand;
    this.elementId=elementId;
    this.serviceareaid = this.elementId;
    this.firmid = document.getElementById('FirmId').value;

    document.getElementById('ajaxInProgressIndicator').innerHTML = '<img src=\"../images/ajaxIndicator.gif\" />';
    document.getElementById('groupOrderTable').disabled = true;

    selectedDeliveryDay = document.getElementById('DeliveryDay').value;
    selectedDeliveryTime = document.getElementById('DeliveryTime').value;

    this.selecteddeliverydatetime = selectedDeliveryDay + ' ' + selectedDeliveryTime;

    selectedVendorLocations = document.getElementById('VendorsAllowed');
    var ctr=0;
    this.selectedvendorlocationstring = '';
    for(var i=0; i<selectedVendorLocations.length;i++){
	if(selectedVendorLocations[i].selected){
	   if (ctr==0){ 
		this.selectedvendorlocationstring = selectedVendorLocations[i].value;
	    }else{
		this.selectedvendorlocationstring += ',' + selectedVendorLocations[i].value;
	    }
	    ctr++;
	}
    }
}

Ajax.Commands.CheckMinimumTipAmountForGO.prototype.ToRequestString=function() {
    return "serviceAreaId=" + this.serviceareaid + "&firmId=" + this.firmid + "&selectedVendorLocations=" + this.selectedvendorlocationstring;
}

Ajax.Commands.CheckMinimumTipAmountForGO.prototype.ParseResponse=function(docEl) {
    var attrs = docEl.attributes;
    var minimumTipAmount=1;
    minimumTipAmount=attrs.getNamedItem("minimumTipAmount").value;
    var responsibleVendor=attrs.getNamedItem("responsibleVendor").value;

    document.getElementById('ajaxInProgressIndicator').innerHTML = '';
    document.getElementById('groupOrderTable').disabled = false;

    var gratuityAmt = 1;
    gratuityAmt=document.frmGO.GratuityAmt.value;

    if(minimumTipAmount > 0){
	if(minimumTipAmount * 1 > gratuityAmt * 1){
//	    alert('Your tip amount has been changed.  The previous amount, ' + document.frmGO.GratuityAmt.value + ', is less than the minimum tip amount for ' 
//		+ responsibleVendor + '.');
	    document.frmGO.GratuityAmt.style.color='red';
	    document.frmGO.GratuityAmt.value=minimumTipAmount;
	} else {
	    document.frmGO.GratuityAmt.style.color='black';
	}    
	document.getElementById('minPossibleGratuity').innerHTML=minimumTipAmount;
	document.getElementById('minPossibleCause').innerHTML=responsibleVendor;
    } else {
	document.frmGO.GratuityAmt.style.color='black';
	document.getElementById('minPossibleGratuity').innerHTML='N/A';
	document.getElementById('minPossibleCause').innerHTML='N/A';
    }

    if(document.frmGO.TipChangeSource.value=='VendorChange' && gratuityAmt * 1 < minimumTipAmount * 1){
        document.frmGO.GratuityAmt.value=minimumTipAmount;
    }

}

//Update DeliveryAddress SMSLocationCode
Ajax.Commands.UpdateSMSLocationCode=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.deliveryaddressid = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.smslocationcode = document.getElementById('addr_' + this.deliveryaddressid).value;
}

Ajax.Commands.UpdateSMSLocationCode.prototype.ToRequestString=function(){
    return "deliveryAddressId=" + this.deliveryaddressid + "&smsLocationCode=" + this.smslocationcode;
}

Ajax.Commands.UpdateSMSLocationCode.prototype.ParseResponse=function(docEl){
    toggleInProgressGraphic('',false);
    toggleTableState('addressManagementTable',false)

    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var deliveryaddressid=attrs.getNamedItem("deliveryaddressid").value;
    var smslocationcode=attrs.getNamedItem("smslocationcode").value;
    
    var failMsg = document.getElementById('msg_'+deliveryaddressid);
    if(status=='Failed'){
	    failMsg.innerHTML = "<div id=\"AlertMessage\">" + message + "</div>";
    }else{
	    window.location.href = window.location.href;
    }
}


//Update FavoriteRank on Template
Ajax.Commands.UpdateFavoriteRank=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.templateid = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.favoriterank = document.getElementById('template_' + this.templateid).value;
}

Ajax.Commands.UpdateFavoriteRank.prototype.ToRequestString=function(){
    return "templateId=" + this.templateid + "&favoriteRank=" + this.favoriterank;
}

Ajax.Commands.UpdateFavoriteRank.prototype.ParseResponse=function(docEl){
    toggleInProgressGraphic('',false);
    toggleTableState('favoriteManagementTable',false)
    
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var templateid=attrs.getNamedItem("templateid").value;
    var favoriterank=attrs.getNamedItem("favoriterank").value;
    
    var failMsg = document.getElementById('message');
    if(status=='Failed'){
	    failMsg.innerHTML =  "<div id=\"AlertMessage\">" +message + "</div>";
    }else{
        window.location.href = window.location.href;
    }
}


//Update FirmLocation SMSLocationCode
Ajax.Commands.UpdateFirmLocationSMSCode=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.firmlocationid = this.elementId;
    this.ajaxCommand = ajaxCommand;
    this.smslocationcode = document.getElementById('firmLocation_' + this.firmlocationid).value;
    this.userid = document.getElementById('userId').value;
}

Ajax.Commands.UpdateFirmLocationSMSCode.prototype.ToRequestString=function(){
    return "firmLocationId=" + this.firmlocationid + "&userId=" + this.userid + "&smsLocationCode=" + this.smslocationcode;
}

Ajax.Commands.UpdateFirmLocationSMSCode.prototype.ParseResponse=function(docEl){
    toggleInProgressGraphic('',false);
    toggleTableState('firmLocationManagementTable',false)

    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var firmlocationid=attrs.getNamedItem("firmlocationid").value;
    var smslocationcode=attrs.getNamedItem("smslocationcode").value;
    
    var failMsg = document.getElementById('msg_'+firmlocationid);
    if(status=='Failed'){
	    failMsg.innerHTML = "<div id=\"AlertMessage\">" + message + "</div>";
    }else{
	    window.location.href = window.location.href;
    }
}

//AddReview Stuff

Ajax.Commands.AddReview=function(elementId, ajaxCommand, cmdCounter) {
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter;
	this.elementId = elementId;
	this.reviewText = elementId;
	this.ajaxCommand = ajaxCommand;
	this.reviewUserId = document.getElementById('reviewUserId').value;
	this.reviewVendorLocId = document.getElementById('reviewVendorLocId').value;
	this.foodRating = document.getElementById('foodRating').value;
}

Ajax.Commands.AddReview.prototype.ToRequestString=function() {
	return "reviewText=" + this.reviewText + "&reviewUserId=" + this.reviewUserId + "&reviewVendorLocId=" + this.reviewVendorLocId + "&foodRating=" + this.foodRating;
}

Ajax.Commands.AddReview.prototype.ParseResponse=function(docEl) {
		var attrs = docEl.attributes;
var status = attrs.getNamedItem('status').value;
var message = attrs.getNamedItem('message').value;
}

//Add User Tags
Ajax.Commands.AddUserTags=function(elementId, ajaxCommand, cmdCounter) {
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter;
	this.elementId=elementId;
	this.ajaxCommand = ajaxCommand;
	this.tagField = elementId;
	this.tagProductId = document.getElementById('tagProductId').value;
}

Ajax.Commands.AddUserTags.prototype.ToRequestString=function() {
	return "tagProductId="+this.tagProductId+"&tagField="+this.tagField;
}

Ajax.Commands.AddUserTags.prototype.ParseResponse=function(docEl) {
	var attrs = docEl.attributes;
	var status = attrs.getNamedItem('status').value;
	var message = attrs.getNamedItem('message').value;
}
//Get User Tags
Ajax.Commands.GetUserTags=function(elementId, ajaxCommand, cmdCounter) {
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter;
	this.ajaxCommand = ajaxCommand;
	this.elementId=elementId;
	this.tagProductId = elementId;
	this.tagUserId = document.getElementById('tagUserId').value;
}

Ajax.Commands.GetUserTags.prototype.ToRequestString=function() {
	return "tagProductId=" + this.tagProductId + "&userId=" + this.tagUserId;
}

Ajax.Commands.GetUserTags.prototype.ParseResponse=function(docEl) {
	var attrs = docEl.attributes;
	var status = attrs.getNamedItem('status').value;
	var message = attrs.getNamedItem('message').value;
	
	var tagsEl = docEl.childNodes[0];
	var attrsChild = docEl.childNodes[0].attributes;
	
	var html = "";
	
	var numberFound = attrsChild.getNamedItem('numberFound').value;
	
	
	for (var i=0; i < numberFound; i++) {
	    var elChild = tagsEl.childNodes[i];
	    attrs = elChild.attributes;
	    var Description = attrs.getNamedItem('description').value;
	    
	    html += Description + " ";
	}
	
	document.tagEditForm.tagField.value = html;
}

//Activate Daily Special Item
Ajax.Commands.ActivateDailySpecialItem=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.productIdentity = document.getElementById('ProductIdentity').value;
    this.activeFlag = document.getElementById('ActiveFlag').value;
}

Ajax.Commands.ActivateDailySpecialItem.prototype.ToRequestString=function(){
    return "productIdentity=" + this.productIdentity + "&productIsActive=" + this.activeFlag;
}

Ajax.Commands.ActivateDailySpecialItem.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    var productIdentity = attrs.getNamedItem('productIdentity').value;
    var weekDays = attrs.getNamedItem("weekDays").value;
    if(status=='failure'){
	document.getElementById('AlertMessage').innerHTML = "<div id=\"AlertMessage\" style=\"color:Red; margin-left: 20px; \">" + message + "</div>";
    } else {
	document.getElementById('WeekDays'+productIdentity).innerHTML = weekDays==" "? "&nbsp;" : weekDays;
    	document.getElementById('ActionResult').innerHTML = message;
    }
}


//Search Daily Specials by Item Name, sort by field
Ajax.Commands.ReloadDailySpecialList=function(elementId, ajaxCommand, cmdCounter) {
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.vendorId = document.getElementById('VendorId').value;
    this.searchItemName = document.getElementById('SearchItemName').value;
    this.orderBy = document.getElementById('OrderBy').value;
}

Ajax.Commands.ReloadDailySpecialList.prototype.ToRequestString=function(){
    return "vendorId=" + this.vendorId + "&itemName=" + this.searchItemName + "&sortBy=" + this.orderBy;
}

Ajax.Commands.ReloadDailySpecialList.prototype.ParseResponse=function(docEl){
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    if(status=='failure'){
	document.getElementById('AlertMessage').innerHTML = message;
    }else{
	var allIDs = "";
	var message = attrs.getNamedItem("message").value;
	var numberfound = attrs.getNamedItem('numberfound').value;
	var numberfounddiv = document.getElementById('SmartSearchDailySpecialsFoundSidebar');
	document.getElementById('SmartSearchDailySpecialsFoundSidebar').innerHTML = "<div style=\"float: left; display:inline; width: 73px;\">Results: " + numberfound + "</div><div style=\"display:block;\"><a href=\"Javascript:DeleteProduct('');\">Delete Selected Daily Specials</a></div>";	
	vendorsEl = docEl.childNodes[0];
	var html = "";
	if (vendorsEl != null) {
	    var numberToShow = vendorsEl.childNodes.length;
	    var numberfound = 0;

	    for(i=0;i<numberToShow;i++){
		var elChild=vendorsEl.childNodes[i];
		if(elChild == null) {
		    break;
		}

		var attrs=elChild.attributes;
		var productIdentity=attrs.getNamedItem("productIdentity").value;
		var itemName=attrs.getNamedItem("itemName").value;
		var description=attrs.getNamedItem("description").value; 
		var effectiveDate = attrs.getNamedItem("effectiveDate").value;
		var basePrice=attrs.getNamedItem("basePrice").value;
		var active = attrs.getNamedItem("active").value;
		var display = attrs.getNamedItem("display").value;
		var servingTime = attrs.getNamedItem("servingTime").value;
		var weekDays = attrs.getNamedItem("weekDays").value;
		var dow = attrs.getNamedItem("dow").value;
		
		if (allIDs.length == 0) {
		    allIDs += productIdentity;
		} else {
		    allIDs += "," + productIdentity;
		}

		html += "<div style=\"clear: both; display:block; margin-left: 0px; width: 740; background-color: White; ";
		html += i>0? "border-top: solid 2px #CECE94;":"";
		html += "\">";
		html += "<div style=\"float: left; width: 20px; margin-left: 10px;\">";
		html += "<input type=\"checkbox\" id=\"id"+productIdentity+"\" value='Y' />";
		html += "</div>";
		html += "<div id=\"ActiveDisplay_"+productIdentity+"\" style=\"float: left; width: 35px; margin-left:10px;\">";
		if (display == "inline") {
		    html += "<input type=\"checkbox\" id=\"Active_"+productIdentity+"\" name=\"Active_"+productIdentity+"\" value='Y' "+active+" onclick=\"Javascript:ActivateProduct('"+productIdentity+"');\"/>";
		}
		html += "&nbsp;</div> <div id=\"ItemInfoText_";
		html += productIdentity;
		html += "\" style=\"display:block; height: auto;\" > <div style=\"width: 125px; float: left; margin-left: 3px;\">";
		html += itemName;
		html += "&nbsp;</div> <div id=\"Description";
		html += productIdentity;
		html += "\" style=\"width: 122px; float: left; display: inline;\">";
		html += description;
		html += "&nbsp;</div> ";
		html += "<div id=\"ServingTime" + productIdentity + "\"";
		html += " style=\"width: 70px; float: left; display: inline;\">";
		html += servingTime + "&nbsp;</div> ";
		html += "<div id=\"WeekDays" + productIdentity + "\"";
		html += " style=\"width: 185px; float: left; display: inline;\">";
		html += weekDays + "&nbsp;</div> ";
		html += "<div style=\"float: right; width: 100px; display: inline; text-align: center;\"><a href=\"javascript:ToggleItem('ItemInfoText_";
		html += productIdentity;
		html += "','ItemInfoBox_";
		html += productIdentity;
		html += "', 'Description_";
		html += productIdentity;
		html += "');\">Edit</a> | <a href=\"javascript:DeleteProduct('";
		html += productIdentity;
		html += "');\">Delete</a></div> <div id=\"BasePrice";
		html += productIdentity;
		html += "\" style=\"display: block;\">$";
		html += basePrice;
		html += "&nbsp;</div> </div>";
//====================== end of ItemInfoText ==============================

		html += "<div id=\"ItemInfoBox_";
		html += productIdentity;
		html += "\" style=\"display:none;\"> <div style=\"width: 125px; float: left; display: inline; margin-left: 3px;\">";
		html += "<input id=\"ItemName_" + productIdentity + "\" type=\"text\" style=\"height:16px; font-size: 11px; width: 105px; border: solid 1px #666666;\" value=\"" + itemName + "\" />";
		html += "</div> <div style=\"width: 122px; float: left; display: inline;\"><textarea id=\"Description_";
		html += productIdentity;
		html += "\" name=\"Description\" style=\"font-size: 11px; font-family: arial; width: 120px; border: solid 1px #666666;\">";
		html += description;
		html += "</textarea></div>";
		html += "<div style=\"width: 70px; float: left; display: inline;\">";
		html += "<select id=\"ServingTime_" + productIdentity + "\" name=\"ServingTime\" style=\"font-size:10px; width: 70px; font-family:Arial;\">";
		html += "<option value=\"AllDay\"";
		if (servingTime == "All Day") {
		    html += " selected";
		}
		html += ">All Day</option>";
		html += "<option value=\"Lunch\"";
		if (servingTime == "Lunch") {
		    html += " selected";
		}
		html += ">Lunch</option>";
		html += "<option value=\"Dinner\"";
		if (servingTime == "Dinner") {
		    html += " selected";
		}
		html += ">Dinner</option>";
		html += "</select>";
		html += "</div> ";
    //--------------------------------------------------------------
		html += "<input type=\"hidden\" id=\"AvailableOnce"+productIdentity+"\" name=\"AvailableOnce"+productIdentity+"\" ";
		var y = display == "none" ? "N" : "Y";
		html += "value=\"" + y + "\" ";
		html += "/>";
		html += "<input type=\"hidden\" id=\"WeekDays"+productIdentity+"\" name=\"WeekDays"+productIdentity+"\" value=\"NNNNNNN\" />";
		html += "<div id=\"AvailabilityMenu"+productIdentity+"\" style=\"float: left;";
		html += " display: "+display+"; width: 185px;\">";
		//html += "<a href=\"Javascript:ToggleAvailability("+productIdentity+");\">Weekly</a> | <b>Once</b>";
		html += "<b>Once</b>";
		html += "</div>";
    //---------------- end of AvailabilityMenu ---------------------
		html += "<div id=\"AvailabilityWeekly"+productIdentity+"\" style=\"float: left;";
		if (display == "none") {
		    html += " display: inline;";
		} else {
		    html += " display: none;";
		}
		html += " width: 185px;\">";
		html += "Mon Tue Wed Thu Fri Sat Sun<br />";
		for (var j=1; j<=7; j++) {
		    html += "<input type=\"checkbox\" id=\"weekday"+j+productIdentity+"\" value=\"Y\" ";
		    if (dow[j-1] == "N") {
			html += "checked=\"checked\" ";
		    }
		    html += "/>";
		}
		//html += " | <a href=\"Javascript:ToggleAvailability("+productIdentity+");\">Once</a>";
		html += "</div>";
    //---------------- end of AvailabilityWeekly --------------------
		html += "<div style=\"float: right; width: 90px; display: inline; text-align: center; font-size: 10px;\"><a href=\"javascript:UpdateProduct('";
		html += productIdentity;
		html += "');\">Update</a> | <a href=\"javascript:ToggleItem('ItemInfoText_"+productIdentity;
		html += "','ItemInfoBox_"+productIdentity+"','Description_"+productIdentity+"');\">Cancel</a></div>";
		html += "<div style=\"display: block;\"><input type=\"text\" id=\"BasePrice_";
		html += productIdentity;
		html += "\" name=\"BasePrice\" value=\""+basePrice+"\" style=\"font-size: 11px; width: 60px; border: solid 1px #666666;\" /></div>  </div>"; 
		html += "</div>";
//====================== end of ItemInfoBox ==============================
	    }    
	    document.getElementById("SmartSearchDailySpecialsResult").innerHTML = html;
	    document.getElementById('AllProductIdentities').value = allIDs;
	    ToggleID();
	}
    }
}


// Add Daily Special Item
Ajax.Commands.AddDailySpecialItem=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.vendorId = document.getElementById('VendorId').value;
    this.itemName = document.getElementById('NewItemName').value;
    this.description = document.getElementById('NewDescription').value;
    this.basePrice = document.getElementById('NewBasePrice').value;
    this.servingTime = document.getElementById('ServingTime').value;
    this.availableOnce = document.getElementById('AvailableOnce').value;
    this.weekDays = document.getElementById('WeekDays').value;
}

Ajax.Commands.AddDailySpecialItem.prototype.ToRequestString=function() {
    return "vendorId=" + this.vendorId + "&itemName=" + this.itemName + "&description=" + this.description + "&basePrice=" + this.basePrice + "&servingTime=" + this.servingTime + "&availableOnce=" + this.availableOnce + "&weekDays=" + this.weekDays + "&sortBy=ProductNameSorter";
}

Ajax.Commands.AddDailySpecialItem.prototype.ParseResponse=function(docEl){
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message=attrs.getNamedItem("message").value;
    
    if(status=='failure'){
	document.getElementById('AlertMessage').innerHTML = message;
	document.getElementById('ActionResult').innerHTML = "";
    }else{

	var message = attrs.getNamedItem("message").value;
	document.getElementById('AlertMessage').innerHTML = "";
	document.getElementById('ActionResult').innerHTML = message;
	ResetInput();
	ReloadProductList('default');
    }
}

//Update Daily Special Item
Ajax.Commands.UpdateDailySpecialItem=function(elementId, ajaxCommand, cmdCounter){
    this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id=cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.productIdentity = document.getElementById('ProductIdentity').value;
    this.productName = document.getElementById('ItemName').value;
    this.description = document.getElementById('Description').value;
    this.basePrice = document.getElementById('BasePrice').value;
    this.servingTime = document.getElementById('ServingTime').value;
    this.availableOnce = document.getElementById('AvailableOnce').value;
    this.weekDays = document.getElementById('WeekDays').value;
}

Ajax.Commands.UpdateDailySpecialItem.prototype.ToRequestString=function(){
    return "productIdentity=" + this.productIdentity + "&itemName=" + this.productName + "&description=" + this.description + "&basePrice=" + this.basePrice + "&servingTime=" + this.servingTime + "&availableOnce=" + this.availableOnce + "&weekDays=" + this.weekDays;
}

Ajax.Commands.UpdateDailySpecialItem.prototype.ParseResponse=function(docEl){
    var attrs=docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message = attrs.getNamedItem("message").value;
    var nameChange = attrs.getNamedItem('nameChange').value;
    
    if(status=='failure'){
	document.getElementById('AlertMessage').innerHTML = message;
	document.getElementById('ActionResult').innerHTML = "";
    }else{
	document.getElementById('AlertMessage').innerHTML = "";
	document.getElementById('ActionResult').innerHTML = message;
	
	ReloadProductList('default');
//	if (nameChange == 'Y') {
//	    ReloadProductList('default');
//	} else {
//	    var productIdentity = attrs.getNamedItem('productIdentity').value;
//	    var active = attrs.getNamedItem('active').value;
//	    var activeDisplay = attrs.getNamedItem('display').value;
//	    var description = attrs.getNamedItem('description').value;
//	    var basePrice = attrs.getNamedItem('basePrice').value;
//	    var servingTime = attrs.getNamedItem('servingTime').value;
//	    var weekDays = attrs.getNamedItem('weekDays').value;
//	    var dow = attrs.getNamedItem('dow').value;
//	    
//	    if (activeDisplay == "inline") {
//		document.getElementById('ActiveDisplay_'+productIdentity).innerHTML = "<input type=\"checkbox\" id=\"Active_"+productIdentity+"\" name=\"Active_"+productIdentity+"\" value='Y' "+active+" onclick=\"Javascript:ActivateProduct('"+productIdentity+"');\"/>";
//	    } else {
//		document.getElementById('ActiveDisplay_'+productIdentity).innerHTML = "&nbsp;";
//	    }
//	    document.getElementById('Description'+productIdentity).innerHTML = description;
//	    document.getElementById('ServingTime'+productIdentity).innerHTML = servingTime;
//	    if (weekDays == "") {
//		document.getElementById('WeekDays'+productIdentity).innerHTML = "&nbsp;";
//	    } else {
//		document.getElementById('WeekDays'+productIdentity).innerHTML = weekDays;
//	    }
//	    document.getElementById('BasePrice'+productIdentity).innerHTML = "$"+basePrice;
//	    
//	    document.getElementById('ItemInfoText_'+productIdentity).style.display = "block";
//	    document.getElementById('ItemInfoBox_'+productIdentity).style.display = "none";
//	}
    }
}

//Delete a daily special and reload the former search list
Ajax.Commands.DeleteDailySpecialItem=function(elementId, ajaxCommand, cmdCounter) {
    this.priority = net.CommandQueue.PRIORITY_IMMEDIATE;
    this.id =cmdCounter;
    this.elementId = elementId;
    this.ajaxCommand = ajaxCommand;
    this.productIdentity = document.getElementById('DeleteProductIdentity').value;
    this.vendorId = document.getElementById('VendorId').value;
    this.searchItemName = document.getElementById('SearchItemName').value;
    this.orderBy = document.getElementById('OrderBy').value;
}

Ajax.Commands.DeleteDailySpecialItem.prototype.ToRequestString=function(){
    return "deleteProductIdentity=" + this.productIdentity + "&vendorId=" + this.vendorId + "&itemName=" + this.searchItemName + "&sortBy=" + this.orderBy;
}

Ajax.Commands.DeleteDailySpecialItem.prototype.ParseResponse=function(docEl){
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    
    if(status=='failure'){
	document.getElementById('AlertMessage').innerHTML = message;
	document.getElementById('ActionResult').innerHTML = "";
    }else{

	document.getElementById('AlertMessage').innerHTML = "";
	document.getElementById('ActionResult').innerHTML = attrs.getNamedItem("message").value;
	ReloadProductList('default');

    }
}

//Tag UnTag VendorLocationReview as Helpful
Ajax.Commands.TagUnTagReview=function(elementId, ajaxCommand, cmdCounter) {
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter;
	this.ajaxCommand = ajaxCommand;
	this.elementId=elementId;
	this.vendorLocationReviewId = elementId;
	this.userId = document.getElementById('userId').value;
	this.vendorLocationReviewTagType = document.getElementById('vendorLocationReviewTagType').value;
}


Ajax.Commands.TagUnTagReview.prototype.ToRequestString=function() {
	return "vendorLocationReviewId=" + this.vendorLocationReviewId + "&userId=" + this.userId + "&vendorLocationReviewTagType=" + this.vendorLocationReviewTagType;
}

Ajax.Commands.TagUnTagReview.prototype.ParseResponse=function(docEl) {
	var attrs = docEl.attributes;
	var status = attrs.getNamedItem('status').value;
	var message = attrs.getNamedItem('message').value;
	var tagupdatestatus = attrs.getNamedItem('tagupdatestatus').value;
	var vendorlocationreviewid = attrs.getNamedItem('vendorlocationreviewid').value;
	var helpfultagcount = attrs.getNamedItem('helpfultagcount').value;
	var nothelpfultagcount = attrs.getNamedItem('nothelpfultagcount').value;
	
	if(status == 'success'){
	
	    document.getElementById('helpfulTagCount' + vendorlocationreviewid).innerHTML = helpfultagcount;
	    document.getElementById('notHelpfulTagCount' + vendorlocationreviewid).innerHTML = nothelpfultagcount;
	    	
	    if(tagupdatestatus == 'Helpful'){
		    document.getElementById('helpfulTag' + vendorlocationreviewid).className = 'helpful tagged';
		    document.getElementById('notHelpfulTag' + vendorlocationreviewid).className = 'nothelpful';
	    }else if(tagupdatestatus == 'Not Helpful'){
		    document.getElementById('notHelpfulTag' + vendorlocationreviewid).className = 'nothelpful tagged';
		    document.getElementById('helpfulTag' + vendorlocationreviewid).className = 'helpful';
	    }else{
		    document.getElementById('notHelpfulTag' + vendorlocationreviewid).className = 'nothelpful';
		    document.getElementById('helpfulTag' + vendorlocationreviewid).className = 'helpful';
	    }	
	}else{
	    //alert(message);
	}
}

// Add/Update MenuItem for order
Ajax.Commands.UpdateOrderLineItem=function(elementId, ajaxCommand, cmdCounter) {
	this.priority=net.CommandQueue.PRIORITY_IMMEDIATE;
	this.id=cmdCounter;
	this.ajaxCommand = ajaxCommand;
	this.productId = elementId;
	this.orderId = document.getElementById('orderId').value;
	this.vendorId = document.getElementById('vendorId').value;
}


Ajax.Commands.UpdateOrderLineItem.prototype.ToRequestString=function() {
	return "vendorId=" + this.vendorId + "&orderId=" + this.orderId + "&productId=" + this.productId;
}

Ajax.Commands.UpdateOrderLineItem.prototype.ParseResponse=function(docEl) {
	var attrs = docEl.attributes;
	var status = attrs.getNamedItem('status').value;
	var message = attrs.getNamedItem('message').value;
	var vendorId = attrs.getNamedItem('vendorid').value;
	var orderId = attrs.getNamedItem('orderid').value;
	var productId = attrs.getNamedItem('productId').value;
	
	/*	
	if(status == 'success'){
	do something
	}else{
	    //alert(message);
	}
	*/
}