function getObj(name)
{
  if (document.getElementById)
  {
    return document.getElementById(name).style;
  }
  else if (document.all)
  {
    return document.all[name].style;
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
  else return false;
}

function displaydiscount(id,show) {
	if (show==1) {
		document.getElementById(id).style.display = 'block';
		document.getElementById(id+'plus').style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'none';
		document.getElementById(id+'plus').style.display = 'block';	
	}
}

function changedisplay(pid,show,total) {
	for(var i=0;i<total;i++) {
		showitem = show.selectedIndex;
		var tempi = i+'';
		if (i==showitem) {
			document.getElementById(pid+tempi).style.display = 'block';
		} else {
			document.getElementById(pid+tempi).style.display = 'none';
		}
	}
}


function show(object) {
	hide();
    if (document.layers && document.layers[object])
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';

}

function hide() {
	document.getElementById('menu1').style.visibility = 'hidden';
	document.getElementById('menu2').style.visibility = 'hidden';
	document.getElementById('menu3').style.visibility = 'hidden';
}

function rollover() {
  if (!document.getElementById) return
  var imgOrSrc;
  var imgPreload = new Array();
  var images = document.getElementsByTagName('img');
  for (var i = 0; i < images.length; i++) {
    if (images[i].getAttribute('rsrc')) {
      imgPreload[i] = new Image();
      imgPreload[i].src = images[i].getAttribute('rsrc');
      images[i].onmouseover = function() {
        imgOrSrc = this.getAttribute('src');
        this.setAttribute('src',this.getAttribute('rsrc'))
      }
      images[i].onmouseout = function() {
        this.setAttribute('src',imgOrSrc)
      }
    }
  }
}






function UserAgent() 
{
  var b=navigator.appName.toUpperCase();

  if (b=="NETSCAPE") this.b="ns";
  else if (b=="MICROSOFT INTERNET EXPLORER") this.b="ie";
  else if (b=="OPERA") this.b="op";
  else this.b=b;

  this.version=navigator.appVersion;
  this.v=parseInt(this.version);

  this.ns=(this.b=="ns" && this.v>=4);
  this.ns4=(this.b=="ns" && this.v==4);
  this.ns5=(this.b=="ns" && this.v==5);

  this.ie=(this.b=="ie" && this.v>=4);
  this.ie4=(this.version.indexOf('MSIE 4')>0);
  this.ie5=(this.version.indexOf('MSIE 5')>0);
  this.ie55=(this.version.indexOf('MSIE 5.5')>0);
  this.ie6=(this.version.indexOf('MSIE 6')>0);

  this.op = (this.b=="op");
  this.op4 = (this.b=="op" && this.v==4);
  this.op5 = (this.b=="op" && this.v==5);
}

at=new UserAgent();

//if you want to create the frame or layer dynamically, do not
//specify a name, do something like this, new exchanger();

function exchanger(name)
{
  //hold the dynamically created iframe or layer
  this.lyr = null;

  //to remember if the iframe or layer is created dynamically.
  this.isDynamic = false;

  this.name=name||"";
  this.fakeid=0;

  if (name == null || name=="")
  {
    this.isDynamic = true;
    this.create();
  }
  else
  {
    this.name=name;
    if (at.ns4)
    {
      this.lyr = window.document.layers[this.name];
    }
  }
}

//this function should not be called directly
exchanger.prototype.create=function()
{
  if (at.ns4) 
  {
    this.lyr=new Layer(0);
    this.visibility = "hide";
  }
  else if (at.ie || at.ns5) 
  {
    this.lyr=document.createElement("IFRAME");
    this.lyr.width=0;
    this.lyr.height=0;
    this.lyr.marginWidth=0;
    this.lyr.marginHeight=0;
    this.lyr.frameBorder=0;
    this.lyr.style.visibility="hidden";
    this.lyr.style.position="absolute";
    this.lyr.src="";
    this.name="tongIFrame"+window.frames.length;
    //this will make IE work.
    this.lyr.setAttribute("id",this.name);
    //this will make netscape work.
    this.lyr.setAttribute("name",this.name);
    document.body.appendChild(this.lyr);
  }
}

exchanger.prototype.sendData=function(url)
{
  this.fakeid += 1;
  var newurl = "";
  if (url.indexOf("?") >= 0)
    newurl = url + "&fakeId" + this.fakeid;
  else
    newurl = url + "?fakeId" + this.fakeid;

  if (this.isDynamic||at.ns4)
    this.lyr.src=newurl;
  else
  {
    if (at.ie || at.ns5 || at.op)
    {
      window.frames[this.name].document.location.replace(newurl);
    }
  }
}


exchanger.prototype.retrieveData=function(varName)
{
  if (at.ns4) 
  {
    return eval("this.lyr." + varName);
  }
  else if (at.ie || at.ns5 || at.op) 
  {
    return eval("window.frames['" + this.name + "']." + varName);
  }
}





var theBuffer;

function initialize()
{
	theBuffer = new exchanger("myframe");
}

function updatecartbox()
{
	theBuffer.sendData("http://www.alliumblue.com/catalogue/cart_box.php");
	window.setTimeout('showReturnData()', 2000);
}

function showReturnData()
{
	document.getElementById('shopq').innerHTML = theBuffer.retrieveData("shopq");
	document.getElementById('shopprice').innerHTML = theBuffer.retrieveData("shopprice");
}







function qty(qty,selected_qty_id) {
	new_qty = (document.getElementById(selected_qty_id).value*1) + qty;
	if (new_qty >= 0) {
		document.getElementById(selected_qty_id).value = new_qty;
	}
}

function send_qty(id) {
	// qty entered
	var qty = document.getElementById(id).value;
	var old_qty = document.getElementById(document.getElementById(id).sid).value;

	// currently selected options
	var sendvalue = "";
	currentsp = document.getElementById("last_selected_option").value;
	baseurl = "http://www.alliumblue.com/catalogue/add_product.php?";
	pid = document.getElementsByName("products_id")[0].value;
	sp = document.getElementsByName("selected_option");
	for (i = 0; i < sp.length; i++) {
		option = "id[" + sp[i].id + "]";
		value = sp[i].value;
		sendvalue = sendvalue + "&" + option + "=" + value;
	}

	if (/^\d+$/.test(old_qty) && qty>=0) {
		if (old_qty != qty) {
			//store
			document.getElementById(document.getElementById(id).sid).value = qty;
			data = baseurl + currentsp + "=" + id + "&cart_quantity=" + qty + sendvalue + "&products_id=" + pid;
//			theBuffer.sendData(data);
//			window.setTimeout('updatecartbox()', 3000);
		}
	} else {
			document.getElementById(document.getElementById(id).sid).value = 0;
			document.getElementById(id).value = 0;
			data = baseurl + currentsp + "=" + id + "&cart_quantity=0" + sendvalue + "&products_id=" + pid;
//			theBuffer.sendData(data);
//			window.setTimeout('updatecartbox()', 3000);
	}
}

function select_package(option_id, attri_id) {
	document.getElementById(option_id).value = attri_id;
	change_id(attri_id);
}


function change_id(attri_id) {
	pid = document.getElementsByName("qtybox");
	for (i = 0; i < pid.length; i++) {
		// save current value
		currentid = pid[i].sid;
		currentvalue = pid[i].value;
		document.getElementById(currentid).value = currentvalue;

		// chnage the field sID
		pid[i].sid = attri_id+"_"+pid[i].id;

		// show the corresponding new value
		pid[i].value = document.getElementById(attri_id+"_"+pid[i].id).value;
	}
}

function change_id_default(attri_id) {
	document.getElementById("selected_qty").id = "selected_qty_"+attri_id;
}

function dd_sel(pid,vid) {
	document.getElementsByName(pid)[0].value = vid;
}

function ShowPop(id)
{
   document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
   document.getElementById(id).style.visibility = "hidden";
}





