function $(id){
 	return document.getElementById(id);
}
function getHTTPObject() {
	var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	return http;
}
var http = getHTTPObject();
var path = "http://cdcmedical.co.uk/";
var url = path + "ajax.php";

function handler() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		$("basket").innerHTML = http.responseText;
		set_waiting();
	}
}

function set_waiting() {
 		JSFX_FloatDiv("status", 0, 0).flt();
		$("status").style.visibility="visible";
		$("status").innerHTML = '<img src="'+ path +'/images/icons/indicator_wheel2.gif"> Working, Please wait';
		setTimeout('set_confirm()', 1250);	
	}
function set_confirm() {
	$('status').innerHTML = '<img src="'+ path +'/images/icons/tick.png"> Thank you!';
	
	setTimeout('reset_waiting()', 1250);
}
function reset_waiting() {
	$('status').innerHTML = '';
	$("status").style.visibility="hidden";
}
	
function getMethod(params) {
	http.open("GET", url+"?"+ params, true);
	http.onreadystatechange = handler;
	http.send(null);
}
function updatebasket(params){
	
}
function postMethod(f, field) {
 	s_params = elmName(f);
	
	http.open("POST", url, true);
	
	//Send the proper header infomation along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", s_params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = handler;
	http.send(s_params);

	
}

/* form handlers */
/* Get all the elements from the form and construct the send string */
function elmName(f){
	var params = "send=1&";
	var o = $(f);
	for(i=0; i<o.elements.length; i++){  
		if(o.elements[i].type != 'button') {
			params += "&" + o.elements[i].name + "=" + o.elements[i].value;
		}
	}
	//alert(f.elements[0]);
	return params;
}

function update_link(id, target) {
	var amt = $(id).value;
	var target = $(target);
	if(isNaN(amt)) {
		alert("this is not an integer value");
		return false;
	} else {
		if(amt > 100) {
	 	confirm("Are you sure you want "+ amt +" items?!");
	} 
		target.innerHTML = '<a href="?basket:update&qty=' + amt + '&id=' + id + '"><img src="' + path + '/images/icons/accept.png" alt="Update item"></a>';
	} 
	
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
function JSFX_FloatDiv(id, sx, sy)
{
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    window[id + "_obj"] = el;
    if(d.layers)el.style=el;
    el.cx = el.sx = sx;el.cy = el.sy = sy;
    el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
    el.flt=function()
    {
    var pX, pY;
    pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
    document.documentElement && document.documentElement.clientWidth ? 
    document.documentElement.clientWidth : document.body.clientWidth;
    pY = ns ? pageYOffset : document.documentElement &&  
        document.documentElement.scrollTop ? 
    document.documentElement.scrollTop : document.body.scrollTop;
    if(this.sy<0) 
    pY += ns ? innerHeight : document.documentElement &&  
        document.documentElement.clientHeight ? 
    document.documentElement.clientHeight : document.body.clientHeight;
    this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
    this.sP(this.cx, this.cy);
    setTimeout(this.id + "_obj.flt()", 1);
    //this.id + "_obj.flt()";
    }
    return el;
}

