//Other function*****************************************************//

function ajaxFunction(method,url,element){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('You require IE 5 or higher, Firefox, Safari or Opera to use this site.  Apologies for the inconvenience.'); 
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById(element).innerHTML = ajaxRequest.responseText;
		}
	}
	//url = "http://www.decodepreview.co.uk/nokia/wp-content/themes/newspress/almanac/" + url;
	//alert("Getting url " + url);
	ajaxRequest.open(method, url, true);
	ajaxRequest.send(null); 
}
	
//*******************************************************************//

function ajaxformFunction(url){
	var ajaxRequest;  // The variable that makes Ajax possible!


	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('You require IE 5 or higher, Firefox, Safari or Opera to use this site.  Apologies for the inconvenience.'); 
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('ajax_res').innerHTML = ajaxRequest.responseText;
		}
	}

	var pid=encodeURIComponent(document.getElementById("pid").value);
	var catid=encodeURIComponent(document.getElementById("catid").value);
	var colour=encodeURIComponent(document.getElementById("colour").value);
	var sid=encodeURIComponent(document.getElementById("sid").value);
	var imgno=encodeURIComponent(document.getElementById("imgno").value);
	var href=url+"?pid="+pid+"&catid="+catid+"&colour="+colour+"&sid="+sid+"&imgno="+imgno;
	//alert(href);	

	ajaxRequest.open('GET',href, true)
	ajaxRequest.send(null); 
}

//*******************************************************************//

function ajaxtotalFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!


	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert('You require IE 5 or higher, Firefox, Safari or Opera to use this site.  Apologies for the inconvenience.'); 
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			top.window.document.getElementById('carttotal').innerHTML = ajaxRequest.responseText;
		}
	}
	//alert("firing");	

	ajaxRequest.open('GET','total.php', true)
	ajaxRequest.send(null); 
}
	
//*******************************************************************//

function TotalUpdate() {
    var t=setTimeout("ajaxtotalFunction()",500);
}

function timedTotalUpdate() {
    var t=setTimeout("ajaxFunction('GET','total.php','carttotal')",500);
	
	//alert("firing");
	//var t2=setTimeout("document.getElementById(\"popupcontent\").style.visibility = \"hidden\"",2000); 
}

// ajax.js

/*	This page defines a function for creating an Ajax request object.
 *	This page should be included by other pages that 
 *	need to perform an XMLHttpRequest.
 */
 
/*	Function for creating the XMLHttpRequest object.
 *	Function takes no arguments.
 *	Function returns a browser-specific XMLHttpRequest object
 *	or returns the Boolean value false.
 */
/*
function getXMLHttpRequestObject() {

	// Initialize the object:
	var ajax = false;

	// Choose object type based upon what's supported:
	if (window.XMLHttpRequest) {
	
		// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
		ajax = new XMLHttpRequest();
		
	} else if (window.ActiveXObject) { // Older IE browsers
	
		// Create type Msxml2.XMLHTTP, if possible:
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) { // Create the older type instead:
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
		
	} // End of main IF-ELSE IF.
	
	// Return the value:
	return ajax;

} // End of getXMLHttpRequestObject() function.
*/

function createRequestObject(){

  var req;

  try
  {
    // Firefox, Opera, Safari
    req = new XMLHttpRequest();
  }

  catch (e)
  {
    // Internet Explorer
    try
    {
      //For IE 6
      req = new ActiveXObject("Msxml2.XMLHTTP");
    }

    catch (e)
    {
      try
      {
        //For IE 5 
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }

      catch (e)
      {
        alert('You require IE 5 or higher, Firefox, Safari or Opera to use this site.  Apologies for the inconvenience.'); 
      }
    }
  }

  return req;
}


//Make the XMLHttpRequest Object
var http = createRequestObject();

function sendRequest(method, url){
  if(method == 'get' || method == 'GET'){
    http.open(method,url,true);
    http.onreadystatechange = handleResponse;
    http.send(null);
  }
}

function handleResponse(){
  if(http.readyState == 4 && http.status == 200){
    var response = http.responseText;
    if(response){
      document.getElementById("ajax_res").innerHTML = response;
    }
  } 
}