function SubmitForm(action) 
{
    var f = document.DigiCatalogForm;
    f.Action.value = action;
    f.submit();
}

function DisableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}

function toggleDiv(div, tag) {
	div = document.getElementById(div);
	if  (div.style.display == "") {
		div.style.display = "none";
		tag.innerHTML = "[+]";
	}
	else {
		div.style.display = "";
		tag.innerHTML = "[-]";			
	}
}

function toggleRows(tableId, rowNr, cellId, productGroupId, tag){
	tbl = document.getElementById(tableId);

	cell = document.getElementById(cellId);

	var len = tbl.rows.length;

	if  (cell.innerHTML.length == 0)
	{
		cell.innerHTML = "<div class='BusyMessage' >Bezig met ophalen artikel details ...</div>";
		ZoomProductGroup(cellId, productGroupId)
	}

	if  (tbl.rows[rowNr].style.display == "none")
	{
		tag.innerHTML = "Verberg<br>details";
		tbl.rows[rowNr].style.display = "";
	}
	else
	{
		tag.innerHTML = "Toon<br>details";
		tbl.rows[rowNr].style.display = "none";
	}
}

function toggleSCRows(tableId, rowNr, cellId, tag, SupplierCatalogueKey, CalledFrom){
	tbl = document.getElementById(tableId);

	cell = document.getElementById(cellId);

	var len = tbl.rows.length;

	if  (cell.innerHTML.length == 0)
	{
		cell.innerHTML = "<div class='BusyMessage' >Bezig met ophalen detail gegevens ...</div>";
		ZoomSupplierCatalogue(cellId, SupplierCatalogueKey, CalledFrom);
	}

	if  (tbl.rows[rowNr].style.display == "none")
	{
		tag.innerHTML = "Verberg details";
		tbl.rows[rowNr].style.display = "";
	}
	else
	{
		tag.innerHTML = "Toon details";
		tbl.rows[rowNr].style.display = "none";
	}
}


function countChildElements(parent, child){
    var parentDIV = document.getElementById(parent);
    if (typeof parentDIV == "undefined" || parentDIV == null){
        return 0;
    } else {
        var childCount = parentDIV.getElementsByTagName(child).length;
        return childCount;
    }
}


var SRxmlHttp = false;

function DisplaySearchResultsProductGroup(Page, CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SRxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SRxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SRxmlHttp = false;
	    }
	}

	if (!SRxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SRxmlHttp = new XMLHttpRequest();
	}
	
	var ResultsPerpage;
	
	if (typeof document.DigiCatalogForm.ResultsPerPage != "undefined"){
	    ResultsPerPage = document.DigiCatalogForm.ResultsPerPage.value;
	} else {
	    ResultsPerPage = 25;
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    if  (CalledFrom == 'CatalogueSelection')
    {
    	var url = "SearchResultsProductGroup.cgi?Page=" + Page + "&ResultsPerPage=" + ResultsPerPage + "&CalledFrom=" + CalledFrom + "&ID=" + f.ID.value + "&Hash=" + hash;
	}
	else
    {
        if (f.OnlyImages.checked)
           var sOnlyImages = "Yes";
        else
           var sOnlyImages = "No";
        var url = "SearchResultsProductGroup.cgi?Page=" + Page + "&ResultsPerPage=" + ResultsPerPage + "&CalledFrom=" + CalledFrom + "&OnlyImages=" + sOnlyImages + "&Hash=" + hash;
	}
		
	//Open connection to server
	SRxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SRxmlHttp.onreadystatechange = function() 
	{
		if  (SRxmlHttp.readyState == 4 && SRxmlHttp.status == 200)
		{
			//alert(xmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(xmlHttp.responseText);
			if  (CalledFrom == "SearchCatalogue" || CalledFrom == 'EditStandardValues'){
		    	var div = document.getElementById("SearchResultsSearchCatalogue");
			} else {
		    	var div = document.getElementById("SearchResultsProductGroup");
			}
			
			div.innerHTML = SRxmlHttp.responseText;


	    	var SourceDiv = document.getElementById("SearchCatalogueNavigationTop");
	    	var DestinationDiv = document.getElementById("SearchResultsProductGroupNavigationTop");
	    	if (SourceDiv != null && DestinationDiv != null){
	    	    DestinationDiv.innerHTML = SourceDiv.innerHTML;
	    	}

			
		    if  (typeof document.DigiCatalogForm.SearchValue != "undefined")
			{
				var searchTerm = document.DigiCatalogForm.SearchValue.value;
			}
			
			if  (CalledFrom == "Search" && searchTerm != '')
			{
		        highlightStartTag = "<font style='color:Black; background-color:#fff999;'>";
		        highlightEndTag = "</font>";
		        if  (SelectedSearchMethod == "EXACT" ) 
		        {
		            var treatAsPhrase = true;
		        }
		        else
		        {
		            var treatAsPhrase = false;
		        }
		        var result = highlightSearchTerms(div, searchTerm, treatAsPhrase, false, highlightStartTag, highlightEndTag);
			}
		}
	}	
	//Send Request
	SRxmlHttp.send(null);
}

var SRBCxmlHttp = false;

function DisplaySearchResultsBrowseCatalogue(Page, CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SRBCxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SRBCxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SRBCxmlHttp = false;
	    }
	}

	if (!SRBCxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SRBCxmlHttp = new XMLHttpRequest();
	}
	
	var ResultsPerpage;
	
	if (typeof document.DigiCatalogForm.ResultsPerPage != "undefined"){
	    ResultsPerPage = document.DigiCatalogForm.ResultsPerPage.value;
	} else {
	    ResultsPerPage = 25;
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();

    if (f.OnlyImages.checked)
       var sOnlyImages = "Yes";
    else
       var sOnlyImages = "No";

    var url = "BrowseCatalogue.cgi?Action=Browse&CalledFrom=" + CalledFrom + "&ClassificationID=" + Page + "&OnlyImages=" + sOnlyImages + "&Hash=" + hash;

		
	//Open connection to server
	SRBCxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SRBCxmlHttp.onreadystatechange = function() 
	{
		if  (SRBCxmlHttp.readyState == 4 && SRBCxmlHttp.status == 200)
		{
			//alert(xmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(xmlHttp.responseText);
			var div = document.getElementById("SearchResultsProductGroup");
			
			div.innerHTML = SRBCxmlHttp.responseText;


            switch (countChildElements('ULBreadCrums','li')){
                case 1:
        			div = document.getElementById("SearchFilterContent");
        			div.innerHTML = '<div class="BusyMessage" >Bezig met opbouwen zoekfilter ...</div>';
        			div.style.display = "";
        			DisplaySearchFilter("Build", "All", "Search");
            		break;
                case 2:
                case 3:
                case 4:
        			div = document.getElementById("SearchFilterContentOverlay");
        			if (typeof div != "undefined"){
            			div.style.display = "";
            		}
            		break;
            	case 5:
    			    //alert('Toon artikelen');
    			    var div = document.getElementById("SearchResultsSearchCatalogue");
    			    div.style.display = '';
    			    DisplaySearchResultsProductGroup(1, CalledFrom);
    
            		div = document.getElementById("SearchFilterContent");
            		div.innerHTML = '<div class="BusyMessage" >Bezig met opbouwen zoekfilter ...</div>';
        		    DisplaySearchFilter("Build", "All", CalledFrom);
    		        div.style.display = "";
		        	break;
            }
			

			
		    if  (typeof document.DigiCatalogForm.SearchValue != "undefined")
			{
				var searchTerm = document.DigiCatalogForm.SearchValue.value;
			}
			
			if  (CalledFrom == "Search" && searchTerm != '')
			{
		        highlightStartTag = "<font style='color:Black; background-color:#fff999;'>";
		        highlightEndTag = "</font>";
		        if  (SelectedSearchMethod == "EXACT" ) 
		        {
		            var treatAsPhrase = true;
		        }
		        else
		        {
		            var treatAsPhrase = false;
		        }
		        var result = highlightSearchTerms(div, searchTerm, treatAsPhrase, false, highlightStartTag, highlightEndTag);
			}
		}
	}	
	//Send Request
	SRBCxmlHttp.send(null);
}


var SFxmlHttp = false;


function CheckEnterSearchFilterValue(Action, FilterName, CalledFrom, e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
          
     if (key == 13)
     {
     	DisplaySearchFilter(Action, FilterName, CalledFrom) 
     	return false;
     }
     else
     {
     	return true;
     }
}

function DisplaySearchFilter(Action, FilterName, CalledFrom) 
{
    var f = document.DigiCatalogForm;
    
    if  (Action == "Rebuild" && FilterName == "AttributeFilterOperand")
    {
    	AttributeFilterNumber = f["AttributeFilterNumber"].value;
    	AttributeFilterValue = f["AttributeFilterValue" + AttributeFilterNumber];
		if  (AttributeFilterValue == "ALL")
		{
	    	return;
	    }
    }
    if  (Action == "Rebuild" && FilterName == "AttributeFilterValue")
    {
        var div = document.getElementById("BusyFiltering");
        if  (div != null)
        {
	        div.style.display = "";
	    }
	}

    if  (Action == "DeleteAttributeFilter")
    {
        var div = document.getElementById("BusyFiltering");
        if  (div != null)
        {
	        div.style.display = "";
	    }
	}

    if  (Action == "Rebuild" && FilterName == "AttributeFilter")
    {
    	AttributeFilterNumber = f["AttributeFilterNumber"].value;
    	AttributeFilter = f["AttributeFilter" + AttributeFilterNumber];
    	AttributeFilterOperand = f["AttributeFilterOperand" + AttributeFilterNumber];
    	AttributeFilterValue = f["AttributeFilterValue" + AttributeFilterNumber];

		var div = document.getElementById("SearchFilterAttributeContainer");
        if  (AttributeFilter.value == "ALL")
        {
            div.style.display = "none";
            ExecuteSearchFilter(Action, FilterName, CalledFrom);
        }
        else
        {
            div.style.display = "";
            div.innerHTML='<div class="BusyIcon"></div>';
  			var result = AttributeFilter.value.split("|");
			if  (result[1] == "1" || result[1] == "0")
			{
			    DisplayAttributeValues(CalledFrom);
			}
			else
			{
			    div.innerHTML = '<input name="AttributeValueEntry" size="35" value="%%frm-zoek-waarde%%" type="text" class="inputbox" size="15" />';
			}
        }
    }
    else
    {
        ExecuteSearchFilter(Action, FilterName, CalledFrom);
    }
}

function AddAttributeFilter(CalledFrom)
{
	ExecuteSearchFilter('AddAttributeFilter', '', CalledFrom);
}

//function DisplaySearchFilter(Action, FilterName, CalledFrom) 
function ExecuteSearchFilter(Action, FilterName, CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SFxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SFxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SFxmlHttp = false;
	    }
	}

	if (!SFxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SFxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.forms[0];
    var hash = Math.random();
	var url = "SearchFilter.cgi?Action=" + Action + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
    if  (Action == 'Rebuild' || Action == 'AddAttributeFilter' || Action == 'DeleteAttributeFilter') 
    {
    	url = url + "&FilterName=" + FilterName;
    	url = url + "&BrandFilter=" + f.BrandFilter.value;
    	url = url + "&TypeFilter=" + f.TypeFilter.value;
    	url = url + "&ClassificationFilter=" + f.ClassificationFilter.value;
    	url = url + "&SupplierFilter=" + f.SupplierFilter.value;
    	url = url + "&AttributeFilterNumber=" + f.AttributeFilterNumber.value;
    	AttributeFilterNumber = f["AttributeFilterNumber"].value;
    	for(i=1;i<=AttributeFilterNumber;i++)
 		{
	    	AttributeFilter = f["AttributeFilter" + i];
	    	AttributeFilterOperand = f["AttributeFilterOperand" + i];
	    	AttributeFilterValue = f["AttributeFilterValue" + i];
            if  (typeof AttributeFilterValue != 'undefined')
            {
                url = url + "&AttributeFilter" + i + "=" + AttributeFilter.value;
            }
	    	if  (typeof AttributeFilterOperand != 'undefined')
	    	{
	        	url = url + "&AttributeFilterOperand" + i + "=" + AttributeFilterOperand.value;
	        }
	    	if  (typeof AttributeFilterValue != 'undefined')
	    	{
	        	url = url + "&AttributeFilterValue" + i + "=" + AttributeFilterValue.value;
	        }
	    }
        //alert(url);
    }
		
	//Open connection to server
	SFxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SFxmlHttp.onreadystatechange = function() 
	{
		if  (SFxmlHttp.readyState == 4 && SFxmlHttp.status == 200)
		{
			var div = document.getElementById("SearchFilter");
			
			div.innerHTML = SFxmlHttp.responseText;

            switch (countChildElements('ULBreadCrums','li')){
                case 2:
                case 3:
                case 4:
        			div = document.getElementById("SearchFilterContentOverlay");
        			div.style.display = "";
            		break;
            }


			if  (Action == "Rebuild" && FilterName == "AttributeFilterValue")
			{
				var div = document.getElementById("BusyFiltering");
		        if  (div != null)
		        {
			        div.style.display = "none";
			    }
			}
			
			if  (Action == "DeleteAttributeFilter")
			{
				DisplaySearchResultsProductGroup(1, CalledFrom);
				var div = document.getElementById("BusyFiltering");
		        if  (div != null)
		        {
			        div.style.display = "none";
			    }
			}

			if  (Action == "Rebuild")
			{
				DisplaySearchResultsProductGroup(1, CalledFrom);

				div = document.getElementById("SearchResultsPriceContent");
				if  (div != null){
    				if  (div.style.display == ""){
		    			var Minimized = false;
			    	} else {
					    var Minimized = true;
				    }
				    DisplaySearchResultsPrice(1, "Search", SelectedSearchMethod, Minimized);
				}

				div = document.getElementById("SearchResultsPriceContent");
				if (div != null){
    				if  (div.style.display == ""){
					    var Minimized = false;
			    	} else {
					    var Minimized = true;
			    	}
				    SearchSupplierCatalogues(1,'Search');
				}
			}
		}
	}
	
	//Send Request
	SFxmlHttp.send(null);
}

function DisplayAttributeValues(CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  DAVxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    DAVxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       DAVxmlHttp = false;
	    }
	}

	if (!DAVxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		DAVxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
	AttributeFilterNumber = f["AttributeFilterNumber"].value;
    var hash = Math.random();
	var url = "SearchFilter.cgi?Action=DisplayAttributeValues&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	url = url + "&BrandFilter=" + f.BrandFilter.value;
	url = url + "&TypeFilter=" + f.TypeFilter.value;
	url = url + "&ClassificationFilter=" + f.ClassificationFilter.value;
	url = url + "&SupplierFilter=" + f.SupplierFilter.value;
	url = url + "&AttributeFilterNumber=" + AttributeFilterNumber;
	for(i=1;i<=AttributeFilterNumber;i++)
	{
    	AttributeFilter = f["AttributeFilter" + i];
    	AttributeFilterOperand = f["AttributeFilterOperand" + i];
    	AttributeFilterValue = f["AttributeFilterValue" + i];
    	url = url + "&AttributeFilter" + i + "=" + AttributeFilter.value;
    	if  (typeof AttributeFilterOperand != 'undefined')
    	{
        	url = url + "&AttributeFilterOperand" + i + "=" + AttributeFilterOperand.value;
        }
    	if  (typeof AttributeFilterValue != 'undefined')
    	{
        	url = url + "&AttributeFilterValue" + i + "=" + AttributeFilterValue.value;
        }
    }
    //alert(url);

	//Open connection to server
	DAVxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	DAVxmlHttp.onreadystatechange = function() 
	{
		if  (DAVxmlHttp.readyState == 4 && DAVxmlHttp.status == 200)
		{
			var div = document.getElementById("SearchFilterAttributeContainer");
			div.innerHTML = DAVxmlHttp.responseText;
		    if  (AttributeFilter.value != f.AttributeFilterSave.value)
		    {
		        f.AttributeFilterSave.value = AttributeFilter.value
		    }
		}
	}
	
	//Send Request
	DAVxmlHttp.send(null);
}
function ProductGroupFromImage(url)
{
    var f = document.DigiCatalogForm;
    if  (typeof f["AttributeFilterNumber"] != 'undefined')
    {
        AttributeFilterNumber = f["AttributeFilterNumber"].value;
        for(i=1;i<=AttributeFilterNumber;i++)
        {
            AttributeFilter = f["AttributeFilter" + i];
            AttributeFilterOperand = f["AttributeFilterOperand" + i];
            AttributeFilterValue = f["AttributeFilterValue" + i];
            if  (typeof AttributeFilter != 'undefined')
            {
                url = url + "&AttributeFilter" + i + "=" + AttributeFilter.value;
            }
            if  (typeof AttributeFilterOperand != 'undefined')
            {
                url = url + "&AttributeFilterOperand" + i + "=" + AttributeFilterOperand.value;
            }
            if  (typeof AttributeFilterValue != 'undefined')
            {
                url = url + "&AttributeFilterValue" + i + "=" + AttributeFilterValue.value;
            }
        }
    }
    //alert(url);
    window.location = url;

}
function ZoomProductGroup(ObjectID, ProductGroupID) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  ZPGxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    ZPGxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       ZPGxmlHttp = false;
	    }
	}

	if (!ZPGxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		ZPGxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    if  (typeof document.DigiCatalogForm.SearchValue != "undefined")
	{
		var searchTerm = document.DigiCatalogForm.SearchValue.value;
	}
	else
	{
		var searchTerm = "Nothing";
	}
	var url = "ZoomProductGroup.cgi?ProductGroupID=" + ProductGroupID + "&SearchValue=" + searchTerm + "&Hash=" + hash;
    if  (typeof f["AttributeFilterNumber"] != 'undefined')
    {
        AttributeFilterNumber = f["AttributeFilterNumber"].value;
        for(i=1;i<=AttributeFilterNumber;i++)
        {
            AttributeFilter = f["AttributeFilter" + i];
            AttributeFilterOperand = f["AttributeFilterOperand" + i];
            AttributeFilterValue = f["AttributeFilterValue" + i];
            if  (typeof AttributeFilter != 'undefined')
            {
                url = url + "&AttributeFilter" + i + "=" + AttributeFilter.value;
            }
            if  (typeof AttributeFilterOperand != 'undefined')
            {
                url = url + "&AttributeFilterOperand" + i + "=" + AttributeFilterOperand.value;
            }
            if  (typeof AttributeFilterValue != 'undefined')
            {
                url = url + "&AttributeFilterValue" + i + "=" + AttributeFilterValue.value;
            }
        }
    }

		
	//Open connection to server
	ZPGxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	ZPGxmlHttp.onreadystatechange = function() 
	{
		if  (ZPGxmlHttp.readyState == 4 && ZPGxmlHttp.status == 200)
		{
			var object = document.getElementById(ObjectID);
			object.innerHTML = ZPGxmlHttp.responseText;
			if  (searchTerm != '')
			{
		        highlightStartTag = "<font style='color:Black; background-color:#fff999;'>";
		        highlightEndTag = "</font>";
		        if  (SelectedSearchMethod == "EXACT" ) 
		        {
		            var treatAsPhrase = true;
		        }
		        else
		        {
		            var treatAsPhrase = false;
		        }
		        var result = highlightSearchTerms(object, searchTerm, treatAsPhrase, false, highlightStartTag, highlightEndTag);
			}
		}
	}
	
	//Send Request
	ZPGxmlHttp.send(null);
}


var SRPxmlHttp = false;

function DisplaySearchResultsPrice(Page, CalledFrom, SearchMethod, Minimized)

{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SRPxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SRPxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SRPxmlHttp = false;
	    }
	}

	if (!SRPxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SRPxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    var SearchValue;
    if  (CalledFrom == "Search")
    {
    	SearchValue = f.SearchValue.value;
    }
	var url = "SearchResultsPrice.cgi?Page=" + Page + "&ResultsPerPage=" + f.ResultsPerPage.value + "&SearchValue=" + SearchValue + "&SearchMethod=" + SearchMethod + "&Minimized=" + Minimized +"&Hash=" + hash;
		
	//Open connection to server
	SRPxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SRPxmlHttp.onreadystatechange = function() 
	{
		if  (SRPxmlHttp.readyState == 4 && SRPxmlHttp.status == 200)
		{
			//alert(SRPxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(SRPxmlHttp.responseText);
			var div = document.getElementById("SearchResultsPrice");
			
			div.innerHTML = SRPxmlHttp.responseText;
		}
	}	
	//Send Request
	SRPxmlHttp.send(null);
}

var SPDxmlHttp = false;

function SearchPriceDetails()
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SPDxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SPDxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SPDxmlHttp = false;
	    }
	}

	if (!SPDxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SPDxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = document.location + "&Action=PerformSearch" +"&Hash=" + hash;
		
	//Open connection to server
	SPDxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SPDxmlHttp.onreadystatechange = function() 
	{
		if  (SPDxmlHttp.readyState == 4 && SPDxmlHttp.status == 200)
		{
			//alert(SRPxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(SRPxmlHttp.responseText);
			var div = document.getElementById("ViewPriceDetails");
			
			div.innerHTML = SPDxmlHttp.responseText;
		}
	}	
	//Send Request
	SPDxmlHttp.send(null);
}

var SPHxmlHttp = false;

function SearchPriceHeaders()
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SPHxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SPHxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SPHxmlHttp = false;
	    }
	}

	if (!SPHxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SPHxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "BrowsePricelists.cgi?SearchValue=" + document.DigiCatalogForm.SearchValue.value + "&Action=PerformSearch" +"&Hash=" + hash;
		
	//Open connection to server
	SPHxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SPHxmlHttp.onreadystatechange = function() 
	{
		if  (SPHxmlHttp.readyState == 4 && SPHxmlHttp.status == 200)
		{
			//alert(SRPxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(SRPxmlHttp.responseText);
			var div = document.getElementById("SearchResultsPrice");
			
			div.innerHTML = SPHxmlHttp.responseText;
		}
	}	
	//Send Request
	SPHxmlHttp.send(null);
}

var SSCxmlHttp = false;

function SearchSupplierCatalogues(Page,CalledFrom)
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  SSCxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    SSCxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       SSCxmlHttp = false;
	    }
	}

	if (!SSCxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		SSCxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
    if  (CalledFrom == "Search")
    {
		var url = "BrowseSupplierCatalogues.cgi?Page=" + Page + "&CalledFrom=Search" +"&Hash=" + hash;
	}
	else
	{
		var url = "BrowseSupplierCatalogues.cgi?SearchValue=" + document.DigiCatalogForm.SearchValue.value + '&CalledFrom=' + CalledFrom + "&Action=PerformSearch" +"&Hash=" + hash;
	}
		
	//Open connection to server
	SSCxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	SSCxmlHttp.onreadystatechange = function() 
	{
		if  (SSCxmlHttp.readyState == 4 && SSCxmlHttp.status == 200)
		{
			//alert(SRPxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(SRPxmlHttp.responseText);
			var div = document.getElementById("SearchResultsSupplierCatalogue");
			div.style.display = "";
			div.innerHTML = SSCxmlHttp.responseText;
		}
	}	
	//Send Request
	SSCxmlHttp.send(null);
}


var DPxmlHttp = false;

function DownloadPricelist(Supplier, PricelistID, Source)
{
	var div = document.getElementById("BusyGenerating");
	div.style.display = "";
	
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  DPxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    DPxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       DPxmlHttp = false;
	    }
	}

	if (!DPxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		DPxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "DownloadPricelist.cgi?Supplier=" + Supplier + "&Source=" + Source + "&PricelistID=" + PricelistID +"&Action=Generate&Hash=" + hash;
		
	//Open connection to server
	DPxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	DPxmlHttp.onreadystatechange = function() 
	{
		if  (DPxmlHttp.readyState == 4 && DPxmlHttp.status == 200)
		{
			//alert(DPxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(DPxmlHttp.responseText);
			var result = DPxmlHttp.responseText.split("|");
			if  (result[0] == "OK")
			{
				location.href = "DownloadPricelist.cgi?Action=Download&FileName=" + result[1];
			}
			div.style.display = "none";
		}
	}	
	//Send Request
	DPxmlHttp.send(null);
}

function ImportSupplierCatalogue(Supplier, CatalogueID, LinkFile, EntryFile)
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  ISCxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    ISCxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       ISCxmlHttp = false;
	    }
	}

	if (!ISCxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		ISCxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "ImportSupplierCatalogue.cgi?Supplier=" + Supplier + "&CatalogueID=" + CatalogueID + "&LinkFile=" + LinkFile + "&EntryFile=" + EntryFile + "&Action=Execute" +"&Hash=" + hash;
		
	//Open connection to server
	ISCxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	ISCxmlHttp.onreadystatechange = function() 
	{
		if  (ISCxmlHttp.readyState == 4 && ISCxmlHttp.status == 200)
		{
			//alert(ISCxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(ISCxmlHttp.responseText);
			var div = document.getElementById("ReadyMessageText");
			var result = ISCxmlHttp.responseText.split("|");
			div.innerHTML = result[1];
			if  (result[0] != "OK") 
			{
				div.style.className = "ErrorMessage";
			}
			div = document.getElementById("ImportBusyMessage");
			div.style.display = "none";
			div = document.getElementById("ReadyMessage");
			div.style.display = "";
	
		}
	}	
	//Send Request
	ISCxmlHttp.send(null);
}

var IUxmlHttp = false;

function ImportUsers(GLN, ImportFile)
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  IUxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    IUxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       IUxmlHttp = false;
	    }
	}

	if (!IUxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		IUxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "ImportUsers.cgi?GLN=" + GLN + "&ImportFile=" + ImportFile + "&Action=Execute" +"&Hash=" + hash;
		
	//Open connection to server
	IUxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	IUxmlHttp.onreadystatechange = function() {
		if  (IUxmlHttp.readyState == 4 && IUxmlHttp.status == 200) {
			//alert(IUxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(IUxmlHttp.responseText);
			var div = document.getElementById("ReadyMessageText");
			var result = IUxmlHttp.responseText.split("|");
			if  (typeof result[1] != "undefined") {
				div.innerHTML = result[1];
			}
			else {
				div.innerHTML = IUxmlHttp.responseText;
			}
			if  (result[0] != "OK") {
				div.style.className = "ErrorMessage";
			}
			div = document.getElementById("ImportBusyMessage");
			div.style.display = "none";
			div = document.getElementById("ReadyMessage");
			div.style.display = "";
	
		}
	}	
	//Send Request
	IUxmlHttp.send(null);
}

var IAxmlHttp = false;

function ImportPricelist(GLN, ImportFile)
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  IUxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    IUxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       IUxmlHttp = false;
	    }
	}

	if (!IUxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		IUxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "ImportPricelist.cgi?GLN=" + GLN + "&ImportFile=" + ImportFile + "&Action=Execute" +"&Hash=" + hash;
		
	//Open connection to server
	IUxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	IUxmlHttp.onreadystatechange = function() {
		if  (IUxmlHttp.readyState == 4 && IUxmlHttp.status == 200) {
			//alert(IUxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(IUxmlHttp.responseText);
			var div = document.getElementById("ReadyMessageText");
			var result = IUxmlHttp.responseText.split("|");
			if  (typeof result[1] != "undefined") {
				div.innerHTML = result[1];
			}
			else {
				div.innerHTML = IUxmlHttp.responseText;
			}
			if  (result[0] != "OK") {
				div.style.className = "ErrorMessage";
			}
			div = document.getElementById("ImportBusyMessage");
			div.style.display = "none";
			div = document.getElementById("ReadyMessage");
			div.style.display = "";
	
		}
	}	
	//Send Request
	IUxmlHttp.send(null);
}

var IAxmlHttp = false;

function ImportArtLink(GLN, ImportFile, Delete)
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  IAxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    IAxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       IAxmlHttp = false;
	    }
	}

	if (!IAxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		IAxmlHttp = new XMLHttpRequest();
	}
	
    var hash = Math.random();
	var url = "ImportArtLink.cgi?GLN=" + GLN + "&ImportFile=" + ImportFile + "&Action=Execute" + "&Delete=" + Delete + "&Hash=" + hash;
		
	//Open connection to server
	IAxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	IAxmlHttp.onreadystatechange = function() {
		if  (IAxmlHttp.readyState == 4 && IAxmlHttp.status == 200) {
			//alert(IAxmlHttp.getAllResponseHeaders() + "\n" + SRPxmlHttp.responseText);
			//alert(IAxmlHttp.responseText);
			var div = document.getElementById("ReadyMessageText");
			var result = IAxmlHttp.responseText.split("|");
			if  (typeof result[1] != "undefined") {
				div.innerHTML = result[1];
			}
			else {
				div.innerHTML = IAxmlHttp.responseText;
			}
			if  (result[0] != "OK") {
				div.style.className = "ErrorMessage";
			}
			div = document.getElementById("ImportBusyMessage");
			div.style.display = "none";
			div = document.getElementById("ReadyMessage");
			div.style.display = "";
	
		}
	}	
	//Send Request
	IAxmlHttp.send(null);
}


var ZSCxmlHttp = false;

function ZoomSupplierCatalogue(ObjectID, SupplierCatalogueKey, CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  ZSCxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    ZSCxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       ZSCxmlHttp = false;
	    }
	}

	if (!ZSCxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		ZSCxmlHttp = new XMLHttpRequest();
	}
	
	var SearchValue="";
	var SearchMethod="";
    if  (CalledFrom == "Search")
    {
    	var f = document.DigiCatalogForm;
    	SearchValue = f.SearchValue.value;
    	SearchMethod = SelectedSearchMethod;
    }
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
	var url = "ZoomSupplierCatalogue.cgi?Key=" + SupplierCatalogueKey + "&SearchValue=" + SearchValue + "&SearchMethod=" + SearchMethod + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
		
	//Open connection to server
	ZSCxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	ZSCxmlHttp.onreadystatechange = function() 
	{
		if  (ZSCxmlHttp.readyState == 4 && ZSCxmlHttp.status == 200)
		{
			var object = document.getElementById(ObjectID);
			
			object.innerHTML = ZSCxmlHttp.responseText;
		}
	}
	
	//Send Request
	ZSCxmlHttp.send(null);
}


/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:black; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          // skip everything between nohighlight comments
          if (lcBodyText.lastIndexOf("!--/nohighlight-->", i) >= lcBodyText.lastIndexOf("<!--nohighlight--", i)) {
            newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
            bodyText = bodyText.substr(i + searchTerm.length);
            lcBodyText = bodyText.toLowerCase();
            i = -1;
          }
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(object, searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (object == null) {
    object = document.body
  }
  if (typeof(object.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = object.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  object.innerHTML = bodyText;
  return true;
}

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) 
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

var EPxmlHttp = false;

function ProcessSupplierSelection(Action, Parameter, CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  EPxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    EPxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       EPxmlHttp = false;
	    }
	}

	if (!EPxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		EPxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    var Program;
    switch (CalledFrom)
    {
    	case "EditPreferredSuppliers":
    		Program = "SelectSuppliers";
    		break;
    	case "ExportProducts":
    		Program = "ExportProducts";
    		break;
    	case "SelectSuppliers":
    		Program = "SelectSuppliers";
    		break;
    }
    switch (Action)
    {
    	case "Initialize":
	    	var url = "SelectSuppliers.cgi?Action=Initialize&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "Back":
	    	var url = "SelectSuppliers.cgi?Action=Back&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "Search":
	    	var url = Program + ".cgi?Action=Search&SearchValue=" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "Add":
	    	var url = Program + ".cgi?Action=Add&Selection=" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "Delete":
	    	var url = Program + ".cgi?Action=Delete&Selection=" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "Export":
	    	var url = Program + ".cgi?Action=Export" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
    	case "SelectSavedSelection":
	    	var url = Program + ".cgi?Action=SelectSavedSelection&SavedSelectionID=" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
	    case "DeleteSavedSelection":
	    	var url = Program + ".cgi?Action=DeleteSavedSelection&SavedSelectionID=" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
	    case "DisplaySupplierSelections":
	    	var url = Program + ".cgi?Action=DisplaySupplierSelections&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
	    case "SaveSelection":
	    	var url = Program + ".cgi?Action=SaveSelection" + Parameter + "&CalledFrom=" + CalledFrom + "&Hash=" + hash;
	    	break;
	}
		
	//Open connection to server
	EPxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	EPxmlHttp.onreadystatechange = function() 
	{
		if  (EPxmlHttp.readyState == 4 && EPxmlHttp.status == 200)
		{
			//alert(EPxmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(EPxmlHttp.responseText);
		    switch (Action)
		    {
		    	case "Initialize":
			    	var Atag = document.getElementById("AvailableSuppliersContainer");
			    	var Stag = document.getElementById("SelectedSuppliersContainer");
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "ERROR") 
					{
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple></select>';
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple></select>';
						alert(result[1]);
					}
					else
					{
						result = EPxmlHttp.responseText.split("@#|@#");
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple>' + result[0] + '</select>';					
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple>' + result[1] + '</select>';					
					}
					f.AvailableSuppliers.selectedIndex = 0;
					f.SelectedSuppliers.selectedIndex = 0;
				   	break;
		    	case "Back":
			    	var Atag = document.getElementById("AvailableSuppliersContainer");
			    	var Stag = document.getElementById("SelectedSuppliersContainer");
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "ERROR") 
					{
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple></select>';
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple></select>';
						alert(result[1]);
					}
					else
					{
						result = EPxmlHttp.responseText.split("@#|@#");
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple>' + result[0] + '</select>';					
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple>' + result[1] + '</select>';					
					}
					f.AvailableSuppliers.selectedIndex = 0;
					f.SelectedSuppliers.selectedIndex = 0;
					sortOptions(f.SelectedSuppliers);
					break;
		    	case "SelectSavedSelection":
					var Atag = document.getElementById("AvailableSuppliersContainer");
					var Stag = document.getElementById("SelectedSuppliersContainer");
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "ERROR") 
					{
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple></select>';
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple></select>';
					}
					else
					{
						result = EPxmlHttp.responseText.split("@#|@#");
						Atag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple>' + result[0] + '</select>';					
						Stag.innerHTML = '<select name="SelectedSuppliers" id="SelectedSuppliers" class="selectbox" ondblclick="DeselectSupplier()"  multiple>' + result[1] + '</select>';					
					}
					f.AvailableSuppliers.selectedIndex = 0;
					f.SelectedSuppliers.selectedIndex = 0;
				   	break;
		    	case "DeleteSavedSelection":
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "ERROR") 
					{
						alert(result[1]);
					}
					else
					{
					    f.SavedSelectionID.options[f.SavedSelectionID.selectedIndex] = null;
					    ProcessSupplierSelection("Initialize", "0", CalledFrom);
					}
				   	break;
		    	case "Search":
			    	var tag = document.getElementById("AvailableSuppliersContainer");
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "ERROR") 
					{
						tag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple></select>';
						alert(result[1]);
					}
					else
					{
						tag.innerHTML = '<select name="AvailableSuppliers" id="AvailableSuppliers" class="selectbox" ondblclick="SelectSupplier()"  multiple>' + EPxmlHttp.responseText + '</select>';					
					}
					f.AvailableSuppliers.selectedIndex = 0;
				   	break;
		    	case "Export":
			    	var div = document.getElementById("ExportContainer");
			    	div.innerHTML = "Exporteren is gereed.";
			    	var div = document.getElementById("ButtonBar");
			    	div.style.display = "";
					var result = EPxmlHttp.responseText.split("|");
					if  (result[0] == "OK")
					{
						location.href = CalledFrom + ".cgi?Action=Download&FileName=" + result[1];
					}
				   	break;
				case "SaveSelection":
					SubmitForm("");
					break;
			}
		}
	}	
	//Send Request
	EPxmlHttp.send(null);
}

function DisplaySupplierSelections(CalledFrom) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  DSSxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    DSSxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       DSSxmlHttp = false;
	    }
	}

	if (!DSSxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		DSSxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    var Program;
    switch (CalledFrom)
    {
    	case "EditPreferredSuppliers":
    		Program = "SelectSuppliers";
    		break;
    	case "ExportProducts":
    		Program = "ExportProducts";
    		break;
    	case "SelectSuppliers":
    		Program = "SelectSuppliers";
    		break;
    }
   	var url = Program + ".cgi?Action=DisplaySupplierSelections&CalledFrom=" + CalledFrom + "&Hash=" + hash;
		
	//Open connection to server
	DSSxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	DSSxmlHttp.onreadystatechange = function() 
	{
		if  (DSSxmlHttp.readyState == 4 && DSSxmlHttp.status == 200)
		{
			//alert(DSSxmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(DSSxmlHttp.responseText);
	    	var div = document.getElementById("SupplierSelectionContainer");
	    	div.innerHTML = DSSxmlHttp.responseText;
		}
	}	
	//Send Request
	DSSxmlHttp.send(null);
}


function SelectSupplier() {
	var f = document.DigiCatalogForm;
	var SelectedValue = '';
	var SelectedText = '';
	var SelectedSuppliers = '';
	
	if (f.AvailableSuppliers.selectedIndex >= 0) {
		while(f.AvailableSuppliers.selectedIndex >= 0) {
			SelectedValue = f.AvailableSuppliers.options[f.AvailableSuppliers.selectedIndex].value;
			SelectedText = f.AvailableSuppliers.options[f.AvailableSuppliers.selectedIndex].text;
			f.SelectedSuppliers.options[f.SelectedSuppliers.options.length] = new Option(SelectedText ,SelectedValue);
			f.AvailableSuppliers.options[f.AvailableSuppliers.selectedIndex] = null;
			if (SelectedSuppliers.length > 0) {
				SelectedSuppliers += ',';
			}
			SelectedSuppliers += SelectedValue
			if (SelectedSuppliers.length > 1800) {
				ProcessSupplierSelection("Add", SelectedSuppliers, "ExportProducts");
				SelectedSuppliers = '';
			}
		}
		if (SelectedSuppliers.length > 0) {
			ProcessSupplierSelection("Add", SelectedSuppliers, "ExportProducts");
		}
		sortOptions(f.SelectedSuppliers);
		f.SelectedSuppliers.selectedIndex = 0;
	}
}

function DeselectSupplier() {
	var f = document.DigiCatalogForm;
	
	var SelectedValue = '';
	var SelectedText = '';
	var SelectedSuppliers = '';
  
	if (f.SelectedSuppliers.selectedIndex >= 0) {
		while(f.SelectedSuppliers.selectedIndex >= 0) {
			SelectedValue = f.SelectedSuppliers.options[f.SelectedSuppliers.selectedIndex].value;
			SelectedText = f.SelectedSuppliers.options[f.SelectedSuppliers.selectedIndex].text;
			f.AvailableSuppliers.options[f.AvailableSuppliers.options.length] = new Option(SelectedText ,SelectedValue);
			f.SelectedSuppliers.options[f.SelectedSuppliers.selectedIndex] = null;
			if (SelectedSuppliers.length > 0) {
				SelectedSuppliers += ',';
			}
			SelectedSuppliers += SelectedValue
			if (SelectedSuppliers.length > 1800) {
				ProcessSupplierSelection("Delete", SelectedSuppliers, "ExportProducts");
				SelectedSuppliers = '';
			}
		}
		if (SelectedSuppliers.length > 0) {
			ProcessSupplierSelection("Delete", SelectedSuppliers, "ExportProducts");
		}
		sortOptions(f.SelectedSuppliers);
		f.AvailableSuppliers.selectedIndex = 0;
	}
}
function deleteOption(object,index) {
    object.options[index] = null;
}

function addOption(object,text,value) {
    var defaultSelected = false;
    var selected = false;
    var optionName = new Option(text, value, defaultSelected, selected)
    object.options[object.length] = optionName;
    object.options[object.length-1].selected = false;
}

function sortOptions(what) {
    var copyOption = new Array();
    for (var i=0;i<what.options.length;i++)
        copyOption[i] = new Array(what[i].text,what[i].value);

    copyOption.sort();

    for (var i=what.options.length-1;i>-1;i--)
        deleteOption(what,i);

    for (var i=0;i<copyOption.length;i++)
        addOption(what,copyOption[i][0],copyOption[i][1])
}
function ProcessCatalogueSelection(ID, ClassificationID, tag) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  PCSxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    PCSxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       PCSxmlHttp = false;
	    }
	}

	if (!PCSxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		PCSxmlHttp = new XMLHttpRequest();
	}
	
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
    var Action;
    switch (tag.className)
    {
    	case "Checkbox":    
    		Action = "Select";
    		break
    	case "CheckboxGrey":    
    		Action = "Deselect";
    		break
    	case "CheckboxChecked":    
    		Action = "Deselect";
    		break
    }
    
	var url = "CatalogueSelection.cgi?Action=" + Action + "&ID=" + ID + "&ClassificationID=" + ClassificationID + "&Hash=" + hash;
	
	//Open connection to server
	PCSxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	PCSxmlHttp.onreadystatechange = function() 
	{
		if  (PCSxmlHttp.readyState == 4 && PCSxmlHttp.status == 200)
		{
			//alert(PCSxmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(PCSxmlHttp.responseText);
			var result = PCSxmlHttp.responseText.split("|");
			if  (result[0] == "OK") 
			{
			    switch (tag.className)
			    {
			    	case "Checkbox":    
			    		tag.className = "CheckboxChecked";
			    		break;
			    	case "CheckboxGrey":    
			    		tag.className = "Checkbox";
			    		break;
			    	case "CheckboxChecked":    
			    		tag.className = "Checkbox";
			    		break;
			    }

			}
			else
			{
				alert(result[1]);
			}
		}
	}	
	//Send Request
	PCSxmlHttp.send(null);
}


var VAxmlHttp = false;

function ViewActions(Page, Refresh) 
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	try 
	{
	  VAxmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) 
	  {
	  try 
	  {
	    VAxmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) 
	    {
	       VAxmlHttp = false;
	    }
	}

	if (!VAxmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		VAxmlHttp = new XMLHttpRequest();
	}
	
    var f = document.DigiCatalogForm;
    var hash = Math.random();
  	var url = "ViewActions.cgi?Page=" + Page + "&ResultsPerPage=" + f.ResultsPerPage.value + "&Refresh=" + Refresh + "&Hash=" + hash;
		
	//Open connection to server
	VAxmlHttp.open("GET", url, true);
	
	//Setup function to call when it's done:
	VAxmlHttp.onreadystatechange = function() 
	{
		if  (VAxmlHttp.readyState == 4 && VAxmlHttp.status == 200)
		{
			//alert(xmlHttp.getAllResponseHeaders() + "\n" + xmlHttp.responseText);
			//alert(VAxmlHttp.responseText);

			var div = document.getElementById("ViewActions");

			var result = VAxmlHttp.responseText.split("|");
			if  (typeof result[1] != "undefined") {
				div.innerHTML = result[1];
			}
			else {
				div.innerHTML = VAxmlHttp.responseText;
			}
			if  (result[0] != "ERROR") {
				div.style.display = "";
			}

			
		}
	}	
	//Send Request
	VAxmlHttp.send(null);
}


