db_img = new Image();
db_img.src = "http://www.global-rs.com/calculators/img/loading.gif";
db_img2 = new Image();
db_img2.src = "http://www.global-rs.com/images/tick.gif";
db_img3 = new Image();
db_img3.src = "http://www.global-rs.com/calculators/img/refresh.gif";
db_img4 = new Image();
db_img4.src = "http://www.global-rs.com/calculators/img/refresh_gray.gif";

function update_price(id) {
 	if ( ! document.getElementById) {
  		return false;
 	}

	document.getElementById("refresh_button").innerHTML = '<img src="http://www.global-rs.com/calculators/img/loading.gif" alt="">';
	document.getElementById("updatenowtext").innerHTML = 'Updating...';
	var url = "http://www.global-rs.com/database/items/update.php?id="+id;

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { price_response(id); }
 	link.open("GET", url, true);
 	link.send(null);
}

function price_response(id) {
 	if (link.readyState == 4) {		
		var allvalues = link.responseText;
		var items = allvalues.split("|");
		
		if ( link.status == 200 && allvalues != "0" && items[0] == 'true' )
		{
			document.getElementById("ge_min").innerHTML = items[1];
			document.getElementById("ge_price").innerHTML = items[2];
			document.getElementById("ge_max").innerHTML = items[3];
			
			pricechange("ge_30", items[4]);
			pricechange("ge_90", items[5]);
			pricechange("ge_180", items[6]);
			
			document.getElementById("ge_updated").innerHTML = '1 second ago';
			document.getElementById("refresh_button").innerHTML = '<img src="http://www.global-rs.com/images/tick.gif" alt="" id="tick" width="16" height="16">';
			setTimeout("fadeout('tick',100,0,1000)", 1000);
			document.getElementById("updatenowtext").innerHTML = '&nbsp;';
		}
		else
		{
			alert("Could not load the item price value. Please refresh the page to try again.");
		}
	}
}
function pricechange(id, change) {
	var plus = '+';
	if ( change == 0 ) {
		document.getElementById(id).style.color = '#6060FF';
	}
	else if ( change > 0 ) {
		document.getElementById(id).style.color = '#006400';
	}
	else {
		document.getElementById(id).style.color = '#8B0000';
		plus = '';
	}
	
	document.getElementById(id).innerHTML = plus+change+'%';
}

function fadeout(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}