
/*********************** SIDEBAR CALLBACK - (Recent viewed and Quotelist) *************************/
function processSidebar(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if(document.getElementById('quotelist-ajax-addresponse').style.display == "block"){
		document.getElementById('quotelist-ajax-addresponse').style.display = "none";
	}
	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
	document.getElementById('quotelist-ajax-waiting').style.display = "block";
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var xmldoc = myajax.responseXML;
            var root = xmldoc.getElementsByTagName('xmlresponse')[0];
            var product_id = root.getElementsByTagName('product')[0].firstChild.nodeValue;
            var action = root.getElementsByTagName('action')[0].firstChild.nodeValue;
            var message = root.getElementsByTagName('message')[0].firstChild.nodeValue;
            message = encodeURI(message);
            var message_type = root.getElementsByTagName('message_type')[0].firstChild.nodeValue;
            var num_items = root.getElementsByTagName('num_items')[0].firstChild.nodeValue;

			jQuery(document).ready(function($){
				if($('#quotelist-ajax-view').length != 0){
					if(num_items > 0){
						if($('#quotelist-ajax-list-container').length != 0){
							$('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
							$('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list');
							ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
						}
				
						showQuoteList();
					}
					else{
						showQuoteForm();
						
					}
				}
		
			});
		
            if(action == "Remove"){
            	jQuery = jQuery.noConflict();
				if(jQuery('#quotelist-ajax-list-container').length != 0){
					if(jQuery('#product_id').length != 0){
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
					}
		        }
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					});
					$('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";
	            if(jQuery('#quote-button-' + product_id).length != 0){
		            document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
			        if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "";
	            	}
		            if(jQuery('#add-button-' + product_id).length != 0){
						document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add-to-quote-list.jpg\" alt=\"Add\" /></a>";
	            	}
            	}
            	else{
	            	if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "";
					}
		            if(jQuery('#add-button-' + product_id).length != 0){
						document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add.png\" alt=\"Add\" /></a>";
					}
				}            	
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processSidebar,'xml'); return false\" title=\"Add Item To Your Quote List!\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/success.png\" alt=\"Add Item To Your Quote List!\" width=\"24px\" height=\"24px\" /></a>";
				}
				

            }
            else if(action == "Add"){
            	jQuery = jQuery.noConflict();
				if(jQuery('#quotelist-ajax-list-container').length != 0){
					if(jQuery('#product_id').length != 0){
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
					}
				}
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					 });
					 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";
	            if(jQuery('#quote-button-' + product_id).length != 0){
	            	document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"/quotelist\"\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
		            if(jQuery('#add-button-' + product_id).length != 0){
		            	document.getElementById('add-button-' + product_id).innerHTML = "<a href='/quotelist' title='Item Is In Your Quotelist' rel='nofollow'><img src='/skin/frontend/default/default/images/added.jpg' alt='Item Is In Your Quote List' /></a>";
					}
					if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Remove Item\" rel=\"nofollow\" style=\"margin-left: 6px;\"><img src=\"/skin/frontend/default/default/images/remove.jpg\" alt=\"Remove Item\" /></a>";
					}
				}
				else{
	            	if(jQuery('#add-button-' + product_id).length != 0){
						document.getElementById('add-button-' + product_id).innerHTML = "<a href='/quotelist' title='Item Is In Your Quotelist' rel='nofollow'><img src='/skin/frontend/default/default/images/added.png' alt='Item Is In Your Quote List' /></a>";
			        }
			        if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Remove Item\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item\" /></a>";
					}
				}
				
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processSidebar,'xml'); return false\" title=\"Remove Item From Your Quote List\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item From Your Quote List\" width=\"24px\" height=\"24px\" /></a>";
				}
            }
// Begin fade-out code
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
				var hide = false; 
				jQuery(document).ready(function($){
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000); 
				}); 
				
				jQuery(document).ready(function($){
					$("#quotelist-ajax-addresponse").hover(function(){ 
					if (hide) clearTimeout(hide); 
					}, function() { 
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000);  
					});
				}); 
// End of fade-out code
			if(jQuery('#quotelist-ajax-form-container').length != 0){
				ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax_xml/numItems','',updateItemCount,'xml');  
				if(num_items == 0){
					jQuery(document).ready(function($){
						setTimeout(function() { 
							document.getElementById('quotelist-ajax-form-container').style.display = "none";
						}, 1500);
					}); 
				}
				else{
					jQuery(document).ready(function($){
						setTimeout(function() { 
							document.getElementById('quotelist-ajax-form-container').style.display = "block";
						}, 2000);
					}); 
				}
			}
		}
	}
}


/*********************** PRODUCT LIST CALLBACK - (Grid and List view) *************************/
function processProductList(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if(document.getElementById('quotelist-ajax-addresponse').style.display == "block"){
		document.getElementById('quotelist-ajax-addresponse').style.display = "none";
		document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
	}
	document.getElementById('quotelist-ajax-waiting').style.display = "block";
	
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally

			var xmldoc = myajax.responseXML;
            var root = xmldoc.getElementsByTagName('xmlresponse')[0];
            var product_id = root.getElementsByTagName('product')[0].firstChild.nodeValue;
            var action = root.getElementsByTagName('action')[0].firstChild.nodeValue;
            var message = root.getElementsByTagName('message')[0].firstChild.nodeValue;
            message = encodeURI(message);
            var message_type = root.getElementsByTagName('message_type')[0].firstChild.nodeValue;
            var num_items = root.getElementsByTagName('num_items')[0].firstChild.nodeValue;

			jQuery(document).ready(function($){
				if(num_items > 0){
					if($('#quotelist-ajax-list-container').length != 0){
						$('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						$('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
			
						showQuoteList();
			
				}
				else{
						showQuoteForm();
					
				}
			});

			ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
			
	        jQuery(document).ready(function($){
		
				$('#quotelist-ajax-container').hover(function(e){
				    if( $(e.target).is('div') )
				       fn.call(e.target,e);
				 });
				 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
			});
			ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
			
			document.getElementById('quotelist-ajax-waiting').style.display = "none";
			document.getElementById('quotelist-ajax-addresponse').style.display = "block";

            if(action == "Add"){
	            // Check if item is in recent viewed - swap icon if yes
				if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href='/quotelist' title='Item Is In Your Quotelist' rel='nofollow'><img src='/skin/frontend/default/default/images/added.png' alt='Item Is In Your Quote List' /></a>";
		        }
		        if(jQuery('#remove-button-' + product_id).length != 0){
					document.getElementById('remove-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Remove Item\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item\" /></a>";
				// Check if item is in recent viewed - swap icon if yes
				}
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Remove Item From Your Quote List\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item From Your Quote List\" width=\"24px\" height=\"24px\" /></a>";
				}
   	        }
            else if(action == "Remove"){
            	if(jQuery('#remove-button-' + product_id).length != 0){
					document.getElementById('remove-button-' + product_id).innerHTML = "";
				}
	            if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add.png\" alt=\"Add\" /></a>";
				}
				// Check if item is in recent viewed - swap icon if yes
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Add Item To Your Quote List!\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/success.png\" alt=\"Add Item To Your Quote List!\" width=\"24px\" height=\"24px\" /></a>";
				}
            }
// Begin fade-out code
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
				var hide = false; 
				jQuery(document).ready(function($){
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000); 
				}); 
				
				jQuery(document).ready(function($){
					$("#quotelist-ajax-addresponse").hover(function(){ 
					if (hide) clearTimeout(hide); 
					}, function() { 
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000);  
					});
				}); 
// End of fade-out code

		}
	}
}

/*********************** PRODUCT VIEW CALLBACK *******************************************/
function processProductView(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if(document.getElementById('quotelist-ajax-addresponse').style.display == "block"){
		document.getElementById('quotelist-ajax-addresponse').style.display = "none";
		document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
	}
	document.getElementById('quotelist-ajax-waiting').style.display = "block";
	
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var xmldoc = myajax.responseXML;
            var root = xmldoc.getElementsByTagName('xmlresponse')[0];
            var product_id = root.getElementsByTagName('product')[0].firstChild.nodeValue;
            var action = root.getElementsByTagName('action')[0].firstChild.nodeValue;
            var message = root.getElementsByTagName('message')[0].firstChild.nodeValue;
            message = encodeURI(message);
            var message_type = root.getElementsByTagName('message_type')[0].firstChild.nodeValue;
            var num_items = root.getElementsByTagName('num_items')[0].firstChild.nodeValue;

			jQuery(document).ready(function($){
				if(num_items > 0){
					if($('#quotelist-ajax-list-container').length != 0){
						$('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						$('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					
						showQuoteList();
				}
				else{
						showQuoteForm();
					
				}
			});
		
			ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
			
			jQuery(document).ready(function($){
		
				$('#quotelist-ajax-container').hover(function(e){
				    if( $(e.target).is('div') )
				       fn.call(e.target,e);
				 });
				 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
			});
			ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
			
			document.getElementById('quotelist-ajax-waiting').style.display = "none";
			document.getElementById('quotelist-ajax-addresponse').style.display = "block";

            if(action == "Add"){
	            if(jQuery('#quote-button-' + product_id).length != 0){
		        document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"/quotelist\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
		        }
	            if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href='/quotelist' title='Item Is In Your Quotelist' rel='nofollow'><img src='/skin/frontend/default/default/images/added.jpg' alt='Item Is In Your Quote List' /></a>";
		        }
		        if(jQuery('#remove-button-' + product_id).length != 0){
					document.getElementById('remove-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Remove Item\" rel=\"nofollow\" style=\"margin-left: 6px;\"><img src=\"/skin/frontend/default/default/images/remove.jpg\" alt=\"Remove Item\" /></a>";	        }
		        }
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Remove Item From Your Quote List\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item From Your Quote List\" width=\"24px\" height=\"24px\" /></a>";
				}
            else if(action == "Remove"){
	            if(jQuery('#quote-button-' + product_id).length != 0){
		            document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
            	}
		        if(jQuery('#remove-button-' + product_id).length != 0){
					document.getElementById('remove-button-' + product_id).innerHTML = "";
            	}
	            if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add-to-quote-list.jpg\" alt=\"Add\" /></a>";
            	}
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Add Item To Your Quote List!\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/success.png\" alt=\"Add Item To Your Quote List!\" width=\"24px\" height=\"24px\" /></a>";
				}
            }
// Begin fade-out code
			ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax_xml/numItems','',updateItemCount,'xml');  
			
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
				var hide = false; 
				jQuery(document).ready(function($){
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000); 
				}); 
				
				jQuery(document).ready(function($){
					$("#quotelist-ajax-addresponse").hover(function(){ 
					if (hide) clearTimeout(hide); 
					}, function() { 
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000);  
					});
				}); 
// End of fade-out code
        
		}
	}
}


/*********************** QUOTE LIST CALLBACK - (Main page and within product page) *************************/
function processQuotelist(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if(document.getElementById('quotelist-ajax-addresponse').style.display == "block"){
		document.getElementById('quotelist-ajax-addresponse').style.display = "none";
		document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
	}
	document.getElementById('quotelist-ajax-waiting').style.display = "block";
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var xmldoc = myajax.responseXML;
            var root = xmldoc.getElementsByTagName('xmlresponse')[0];
            var product_id = root.getElementsByTagName('product')[0].firstChild.nodeValue;
            var action = root.getElementsByTagName('action')[0].firstChild.nodeValue;
            var message = root.getElementsByTagName('message')[0].firstChild.nodeValue;
            message = encodeURI(message);
            var message_type = root.getElementsByTagName('message_type')[0].firstChild.nodeValue;
            var num_items = root.getElementsByTagName('num_items')[0].firstChild.nodeValue;

			if((jQuery('#product_id').length != 0) && (num_items == 0)){
				showQuoteForm();
			}
			
			
            if(action == "UpdateAll"){
            	if(jQuery('#product_id').length != 0){
            		if(num_items > 0){
						jQuery('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						jQuery('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						showQuoteForm();
					}
				}
				else{
					ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
				}
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					 });
					 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action=updateAll&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
   	        }
            else if(action == "Remove"){
            	if(jQuery('#product_id').length != 0){
            		if(num_items > 0){
						jQuery('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						jQuery('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						showQuoteForm();
					}
				}
				else{
					ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
				}
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					 });
					 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";
	            if(jQuery('#quote-button-' + product_id).length != 0){
		            document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
			        if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "";
	            	}
		            if(jQuery('#add-button-' + product_id).length != 0){
						document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add-to-quote-list.jpg\" alt=\"Add\" /></a>";
	            	}
            	}
            	else if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add.png\" alt=\"Add\" /></a>";
				}
				
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processQuotelist,'xml'); return false\" title=\"Add Item To Your Quote List!\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/success.png\" alt=\"Add Item To Your Quote List!\" width=\"24px\" height=\"24px\" /></a>";
				}
				
            }
            else if(action == "RemoveAll"){
			
            	if(jQuery('#product_id').length != 0){
            		if(num_items > 0){
						jQuery('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						jQuery('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						showQuoteForm();
					}
				}
				else{
					document.getElementById('quotelist-ajax-list-container').innerHTML = "";
					ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
					document.getElementById('quotelist-ajax-form-container').style.display = "none";
				}
			
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					 });
					 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
			
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action=removeAll&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";
				document.getElementById('quotelist-ajax-addresponse').style.position = "fixed";
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
			
		        jQuery(document).ready(function($){
					$(function(){
						$(".quotelist-button").html("");
					});
				});
				if(product_id == "null"){
					product_id = document.getElementById('product_id').value;
				}
				
	            if(jQuery('#showother').length != 0){
					document.getElementById('showother').innerHTML = "<div class=\"aw-arp-noitems\">There are currently no related products available to display.</div>";
            	}

				
	            if(jQuery('#quote-button-' + product_id).length != 0){
		            document.getElementById('quote-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/get-a-quote.jpg\" alt=\"Get A Quote\" class=\"get-a-quote\" /></a>";
			        if(jQuery('#remove-button-' + product_id).length != 0){
						document.getElementById('remove-button-' + product_id).innerHTML = "";
	            	}
		            if(jQuery('#add-button-' + product_id).length != 0){
						document.getElementById('add-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/add','product=" + product_id + "',processProductView,'xml'); return false\" title=\"Add\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/add-to-quote-list.jpg\" alt=\"Add\" /></a>";
	            	}
            	}

           }
            else if(action == "Add"){
            	if(jQuery('#product_id').length != 0){
            		if(num_items > 0){
						jQuery('#quotelist-ajax-list-container').live('mousemove', Custom.init);				 
						jQuery('#quotelist-ajax-list-container').load(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product');
						ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list?heading=product', 'quotelist-ajax-list-container');
					}
					else{
						showQuoteForm();
					}
				}
				else{
					ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/list', 'quotelist-ajax-list-container');
					document.getElementById('quotelist-ajax-form-container').style.display = "block";
				}
				jQuery(document).ready(function($){
		
					$('#quotelist-ajax-container').hover(function(e){
					    if( $(e.target).is('div') )
					       fn.call(e.target,e);
					 });
					 $('#quotelist-ajax-container').load(ajaxpack.basedomain+'/quotelist/ajax/sidebar');
				});
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/sidebar', 'quotelist-ajax-container');
				ajaxpage(ajaxpack.basedomain+'/quotelist/ajax/response?action='+action+'&message='+message+'&message_type='+message_type, 'quotelist-ajax-addresponse');
				document.getElementById('quotelist-ajax-waiting').style.display = "none";

	            // Check if item is in recent viewed - swap icon if yes
				if(jQuery('#add-button-' + product_id).length != 0){
					document.getElementById('add-button-' + product_id).innerHTML = "<a href='/quotelist' title='Item Is In Your Quotelist' rel='nofollow'><img src='/skin/frontend/default/default/images/added.png' alt='Item Is In Your Quote List' /></a>";
		        }
		        if(jQuery('#remove-button-' + product_id).length != 0){
					document.getElementById('remove-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processProductList,'xml'); return false\" title=\"Remove Item\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item\" /></a>";
				// Check if item is in recent viewed - swap icon if yes
				}
		        if(jQuery('#recent-sidebar-button-' + product_id).length != 0){
					document.getElementById('recent-sidebar-button-' + product_id).innerHTML = "<a href=\"#\" onclick=\"setTop(this,190);ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax/remove','product=" + product_id + "',processQuotelist,'xml'); return false\" title=\"Remove Item From Your Quote List\" rel=\"nofollow\"><img src=\"/skin/frontend/default/default/images/remove.png\" alt=\"Remove Item From Your Quote List\" width=\"24px\" height=\"24px\" /></a>";
				}

				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
            }
// Begin fade-out code
				document.getElementById('quotelist-ajax-addresponse').style.display = "block";
				var hide = false; 
				jQuery(document).ready(function($){
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000); 
				}); 
				
				jQuery(document).ready(function($){
					$("#quotelist-ajax-addresponse").hover(function(){ 
					if (hide) clearTimeout(hide); 
					}, function() { 
					hide = setTimeout(function() { 
					    	$("#quotelist-ajax-addresponse").fadeOut("slow");
					    	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";
					    }, 5000);  
					});
				}); 
// End of fade-out code
			ajaxpack.getAjaxRequest(ajaxpack.basedomain+'/quotelist/ajax_xml/numItems','',updateItemCount,'xml');  

			if(jQuery('#product_id').length != 0){
           		if(num_items > 0){
					showQuoteList();

				}
				else{
					showQuoteForm();
				}
			}
			else{
				if(num_items == 0){
					jQuery(document).ready(function($){
						setTimeout(function() { 
							document.getElementById('quotelist-ajax-form-container').style.display = "none";
						}, 1500);
					}); 
				}
				else{
					document.getElementById('quotelist-ajax-form-container').style.display = "block";
				}				
			}

		
		}
	}
}

/*********************** CREATE POST STRING FOR QUOTELIST FORM *************************/
function updatePostData(){
	var quotelistForm = document.getElementById('quotelistForm');
	for (var i=0;i<quotelistForm.length;i++)
	{
		if(i == 0){
			var updatePostString = quotelistForm.elements[i].name + "=" + encodeURI(quotelistForm.elements[i].value);
		}
		else{
			updatePostString += "&" + quotelistForm.elements[i].name + "=" + encodeURI(quotelistForm.elements[i].value);
		}
	}

	return updatePostString
}

/*********************** CLOSE BUTTON *************************/

function closeAddBox(){
	document.getElementById('quotelist-ajax-addresponse').style.display = "none";
	document.getElementById('quotelist-ajax-addresponse').innerHTML = "";

}

/*********************** UPDATES SPAN WITH ITEM COUNT *************************/

function updateItemCount(){
	if(jQuery('#num_items').length != 0){
		var myajax=ajaxpack.ajaxobj
		var myfiletype=ajaxpack.filetype
		if (myajax.readyState == 4){ //if request of file completed
			if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
				var xmldoc = myajax.responseXML;
	            var root = xmldoc.getElementsByTagName('xmlresponse')[0];
	            var num_items = root.getElementsByTagName('num_items')[0].firstChild.nodeValue;
	
				if(num_items == 1){
					var word = "Item";
				}
				else{
					var word = "Items";
				}
					document.getElementById('num_items').innerHTML = num_items + ' ' + word;
			}
		}
	}
}

/*********************** SHOW/HIDE FORMS *************************/

function showQuoteList(){

	if(jQuery('#quotelist-ajax-view').length != 0){
		document.getElementById('quoteform-ajax-view').style.display = "none";
		document.getElementById('showquote').style.display = "none";
		document.getElementById('showquote-list').style.display = "none";
		document.getElementById('quotelist-ajax-view').style.display = "block";
	}					
}

function showQuoteForm(){

	if(jQuery('#quotelist-ajax-view').length != 0){
		document.getElementById('quotelist-ajax-view').style.display = "none";
		document.getElementById('showquote-list').style.display = "none";
		document.getElementById('showquote').style.display = "none";
		document.getElementById('quoteform-ajax-view').style.display = "block";
	}
}

/************************** DISCOUNT CODE CALLBACK *********************************/

function processDiscountCode(){
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	//openDiscount();
	if (myajax.readyState == 4){ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
			var xmldoc = myajax.responseXML;

            var root = xmldoc.getElementsByTagName('customer')[0];
            var email = root.getElementsByTagName('email')[0].firstChild.nodeValue;
            var discount_code = root.getElementsByTagName('discount_code')[0].firstChild.nodeValue;
            var message = root.getElementsByTagName('message')[0].firstChild.nodeValue;
            var response_type = root.getElementsByTagName('response_type')[0].firstChild.nodeValue;

			switch (response_type) {
				case "newcust":
					document.getElementById('discount-message').innerHTML = '<img src="skin/frontend/default/default/images/discount-gotone.gif" />';
					document.getElementById('discount-code').innerHTML = discount_code;
					document.getElementById('discount-email').innerHTML = 'We\'ve also emailed your voucher code to you!';
					break;
				case "newcode":
					document.getElementById('discount-message').innerHTML = '<img src="skin/frontend/default/default/images/discount-gotone.gif" />';
					document.getElementById('discount-code').innerHTML = discount_code;
					document.getElementById('discount-email').innerHTML = 'We\'ve also emailed your voucher code to you!';
					break;
				case "reminder":
					document.getElementById('discount-message').innerHTML = '<img src="skin/frontend/default/default/images/discount-gotone.gif" />';
					document.getElementById('discount-code').innerHTML = discount_code;
					document.getElementById('discount-email').innerHTML = 'We\'ve emailed a reminder of your voucher code to you!';
					break;
				case "denial":
					document.getElementById('discount-message').innerHTML = '<img src="skin/frontend/default/default/images/discount-gotone.gif" />';
					document.getElementById('discount-code').innerHTML = '';
					document.getElementById('discount-email').innerHTML = 'Sorry, you have already redeemed your code.';
					break;
				case "invalid":
					document.getElementById('discount-message').innerHTML = '';
					document.getElementById('discount-code').innerHTML = '';
					document.getElementById('discount-email').innerHTML = 'Please enter a valid email address.';
					break;
				default:
					document.getElementById('discount-code').innerHTML = "NO WAY!";
			}
			
			document.getElementById('discount-loading').style.display = "none";
			document.getElementById('discount-response').style.display = "block";
					
		}
	}
}

/*********************** CREATE POST STRING FOR QUOTELIST FORM *************************/
function getDiscountEmail(){
	var discountForm = document.getElementById('discount_form');

	email = discountForm.email.value;
	postString = "email = " + email;
	return postString;
}



