// JavaScript Document
	var LoadHotContentReq;

		function LoadHotContentXMLDoc(url) {

			// branch for native XMLHttpRequest object
			if (window.XMLHttpRequest) {
				LoadHotContentReq = new XMLHttpRequest();
				LoadHotContentReq.onreadystatechange = processLoadHotContentChange;
				LoadHotContentReq.open("GET", url, true);
				LoadHotContentReq.send(null);
			// branch for IE/Windows ActiveX version
			} 
			else if (window.ActiveXObject) {
				LoadHotContentReq = new ActiveXObject("Microsoft.XMLHTTP");
				if (LoadHotContentReq) {
					LoadHotContentReq.onreadystatechange = processLoadHotContentChange;
					LoadHotContentReq.open("GET", url, true);
					LoadHotContentReq.send();
				}
			}
		}
		
		function processLoadHotContentChange() {

			if(LoadHotContentReq.readyState == 1){
				//document.getElementById(this_div).innerHTML = '<strong>Validating...</strong>';
			}
			// only if LoadHotContentReq shows "complete"
			if (LoadHotContentReq.readyState == 4) {
				// only if "OK"
				if (LoadHotContentReq.status == 200) {
					// the goodnes
					var response = LoadHotContentReq.responseText;
					
					//Get the div we are updating
					document.getElementById('hot_content').innerHTML = response;
					
					// Tell the screen we are done
					document.getElementById('in_action').value = '';
					
				} 
				else {
					alert("There was a problem retrieving the XML data:\n" + LoadHotContentReq.statusText);
				}
			}
		}
		
		function loadHotProducts(base_address,locale_id, locale_code, branding_id, direction, limit) {
				
			// Check on set variable to see if somehtung is happening
			var isOngoing = document.getElementById('in_action').value;
			
			// Is it still going?
			if(isOngoing == 1) {
				
				// BLANK STUB
				//alert('still loading some content');
				return false;
			}
			else {
				// Not loading content so load some
				
				// Tell screne to not double up
				document.getElementById('in_action').value = 1;
				
				// Set the limit
				existingStart = document.getElementById('hot_content_start').value;
				existingStart = existingStart*1;
				
				// Set a Var
				var doNothing = false;
				
				// Deal with the start
				if(existingStart > 0) {
					// For next, add to limit
					if(direction == 'next') {
						
						//Check we are not about to go past the limit
						if((existingStart+limit) >= (document.getElementById('hot_content_max').value*1)) {
							//alert('You have reached the end');
							//Tell it to do nothing
							doNothing = true;
						}
						else {
							// We can go on
							document.getElementById('hot_content_start').value = existingStart+limit;
						}
					}
					else {
						// For previous subtract from limit
						document.getElementById('hot_content_start').value = existingStart-limit;
					}
					
				} //End
				else {
					
					// If its 0 and we are going backwards, do nothing
					if((existingStart == "" || existingStart == 0) && direction == 'prev') {
						//alert('You cant go back from 0');
						//Tell it to do nothing
						doNothing = true;
					}
					else if((existingStart == "" || existingStart == 0) && direction == 'next' && (existingStart+limit) >= (document.getElementById('hot_content_max').value*1)) {
						//alert('Not enough to go on');
						//Tell it to do nothing
						doNothing = true;
					}
					else if((existingStart == "" || existingStart == 0) && direction == 'start') {
						// Set this to 0
						document.getElementById('hot_content_start').value = 0;
					}
					else {
						//Not set yet and must be going forward
						document.getElementById('hot_content_start').value = limit;
					}
				}
				
				// Only do this if you are allowed
				if(doNothing == false) {
					// Input mode
					url  = base_address +'/includes/scripts/search_hot_products.php?locale_id='+ locale_id;
					url += '&locale_code='+ locale_code;
					url += '&branding_id='+ branding_id;
					url += '&start='+ document.getElementById('hot_content_start').value;
					url += '&limit='+ limit;
					LoadHotContentXMLDoc(url);
					
					// Put in some loader text
					document.getElementById('hot_content').innerHTML = '<img src="'+ base_address +'/images/loading_content.png" alt="Loading content" />';
				} //End being told to do nothing
				else {
					// Tell the screen we are done
					document.getElementById('in_action').value = '';
				} //End allowing forward or back
				
			} //End loading content

		}
