function display(element) {
	var but = document.getElementById(element);
	but.style.display = 'block';
}
function hide(element) {
	var but = document.getElementById(element);
	but.style.display = 'none';
}
function visibleFlash(){
	var obj = top.document.getElementsByTagName("object");
	var emb = top.document.getElementsByTagName("embed");
	obj.style.visibility = 'visible';
	emb.style.visibility = 'visible';
}
function resizeHeight(altezza,id){
	var TotAltezza = altezza;
	var thisOne = document.getElementById(id);
	thisOne.style.height = TotAltezza + "px";
}
function resizeWidth(larghezza,id){
	var TotLarghezza = larghezza;
	var thisOne = document.getElementById(id);
	thisOne.style.width = TotLarghezza + "px";
}
function setMarginLeft(margin,id){
	var margine = margin;
	var thisOne = document.getElementById(id);
	thisOne.style.marginLeft = margine + "px";
}
function setTop(altezza,id){
	var TotAltezza = altezza;
	document.getElementById(id).style.top = TotAltezza + "px";
}
function linkInTopFrame(link,frame){
        top.frames[frame].location.href = link;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function changeLabel(id,newLabel){
	var idLab = document.getElementById(id);
	idLab.innerHTML = newLabel;
}
/* Numbers */
function numToDB(number){
	return number.replace(",","");
}
function number_format (number, decimals, dec_point, thousands_sep){
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1){
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }

  if (decimals != null){
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ?
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0){
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }

  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != ""){
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }

  return sign + integer + fractional + exponent;
}




/* TRIGGER */
var timerId;
function startTrigger(n){
	if(!n){
		n = 5000;
	}
	if(!timerId){
        	timerId = setTimeout('hide("labelFinish");stopTrigger();', n);
	}
}
function stopTrigger(){
	clearTimeout(timerId);
	timerId = false;
}

/* AJAX */
function callApiPOST(url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Internal Server Error');
		return false;
	}
	http_request.onreadystatechange = ajaxExecute;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
function ajaxExecute() {
	if (http_request.readyState < 4){
		// do nothing
	}else if (http_request.readyState == 4) {
		if (http_request.status == 200) {
                        var sn = document.getElementById('labelFinish');
                        sn.innerHTML = "Cart Updated Succesfully!";
                        display('labelFinish');
                        startTrigger();
		} else {
                        var sn = document.getElementById('labelFinish');
                        sn.innerHTML = "There was a problem Updating the cart!";
                        display('labelFinish');
                        startTrigger();
		}
	}
}
/* Flash */
function spitFlash(filename,width,height,xmlLoc,color){
	if(!width) var width='100%';
	if(!height) var height='100%';
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="artist" align="middle">');
		document.write('<param name="loop" value="false">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + filename + '" />');
		//document.write('<param name="wmode" value="transparent">');
		document.write('<param name="quality" value="high" />');
		//document.write('<param name="flashvars" value="overstretch=none&file='+xmlLoc+'" />');
		document.write('<param name="bgcolor" value="'+color+'" />');
		document.write('<embed src="' + filename + '" loop="false" quality="high" bgcolor="'+color+'" width="'+width+'" height="'+height+'" name="artist" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}