var popUpWin=0;

function popUpWindow(width, height, URLStr)
  {
    if (typeof(SymRealWinOpen)!="undefined")
        window.open = SymRealWinOpen;

    var left = (screen.width/2) - width/2;
    var top = (screen.height/2) - height/2;
    if(popUpWin)
      {
        if(!popUpWin.closed) popUpWin.close();
      }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    if (popUpWin==null)
        ; //alert("Please enable popups for this site");
    else
        popUpWin.focus()
  }

function popUpWindowFlexible(width, height, URLStr)
  {
    if (typeof(SymRealWinOpen)!="undefined")
        window.open = SymRealWinOpen;

    var left = (screen.width/2) - width/2;
    var top = (screen.height/2) - height/2;
    if(popUpWin)
      {
        if(!popUpWin.closed) popUpWin.close();
      }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=Yes,menubar=no,scrollbars=Yes,resizable=Yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    if (popUpWin==null)
        ; //alert("Please enable popups for this site");
    else
        popUpWin.focus()
  }

function getElement(id)
  {
  	return typeof(document.getElementById)=="undefined" ?
           document.all[id] : document.getElementById(id);
  }

function formatCurrency(n)
  {
    var n = Math.round(Number(n) * 100);
    var s = String(n/100);
    var parts = s.split(".");
    if (parts.length < 2)
        parts[1] = "00"
    else if (parts[1].length<2)
      {
        parts[1] += "0";
      }
    else
      {
        parts[1] = parts[1].slice(0,2);
      }
    return parts.join(".");
  }


function updateTotals(form)
  {
    var productIDs = form.productids.value.split(',');
    if (form.postage==null)
        var grandTotal = 0;
    else
        var grandTotal = Number(form.postage.value);
    for (i in productIDs)
      {
        var productID = productIDs[i];
        var price    = form['price' + String(productID)].value;
        var quantity = form['quantity' + String(productID)].value;
        var total = Number(price) * Number(quantity);
        el = getElement('total' + String(productID));
        el.innerHTML = formatCurrency(total);
        grandTotal += total;
      }
    el = getElement('grandtotal');
    form.TotalSale.value = grandTotal;
    el.innerHTML = '<b>AUD ' + formatCurrency(grandTotal) + '</b>';
  }

function updatePostage(radio)
  {
    var type = radio.value;
    var td = getElement("postagecharge");
    var cost = radio.form["postagecharge" + type].value;
    td.innerHTML = formatCurrency(cost);
    radio.form.postage.value=cost;
    updateTotals(radio.form);
    radio.checked = true;
  }

function loadVideo(url)
  {
  	var Player = getElement("Player");
  	Player.sendEvent("PLAY","true");

    //Player.src = url;
  	//Player.play();

  	return false;
  }
  
preloadedImaged = [];

function preloadImage(url) 
  {
	  var img = new Image();
	  img.src = url;
	  preloadedImaged.push(img);
  }

function addBookmark()
  {
    if (typeof(window.external)!='undefined' && typeof(window.external.AddFavorite)!='undefined')
        window.external.AddFavorite(location.href, document.title);
    else
        alert("Automated bookmarking is not available for this browser, please use you menu");
  }


function changeBackgroundReal(id, background)
  {
	var id = document.getElementById(id);
	if (id==null) return;
	id.background = background;
	id.style.backgroundImage = 'url(' + background + ')';
  }

function changeBackground(id, background, delay)
  {
	 window.setTimeout("changeBackgroundReal('" + id + "', '" + background + "')", delay);
  }
  
function changeFreeVideoRed(time) 
  {
  	changeBackground('freevideol','/images/htmiddlered-l.gif' ,time);
	changeBackground('freevideor','/images/htmiddlered-r.gif' ,time);
    changeBackground('freevideo', '/images/htbgred.gif', time)
  }
	
function changeFreeVideoBlue(time) 
  {
  	changeBackground('freevideol','/images/htmiddle.gif' ,time);
	changeBackground('freevideor','/images/htmiddle.gif' ,time);
    changeBackground('freevideo', '/images/htbg.gif', time)
  }
	
function changeFreeVideoBg() 
  {
	var intv;
	var flash;
	var flash = 500;
	for (var i=1; i<10; i++)
		{
			intv = i*flash;
			changeFreeVideoRed(intv);
			i++; intv = i*flash;	
			changeFreeVideoBlue(intv);
		}
	intv = i*flash;	
	changeFreeVideoRed(intv);
  }
	
function setCookie (name, value)
  {
    var date = new Date();
    if (typeof(date.setFullYear)!="undefined")
       date.setFullYear(date.getFullYear()+2);
    else
       date.setYear(date.getYear()+2);
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + date.toGMTString();
  }
  
function setTimeZoneCookie()
  {
	var visitortime = new Date();
	setCookie('TimezoneOffset', visitortime.getTimezoneOffset()/60);
  }

function show(id)
  {	
	var el = getElement(id);
	if (el!=null)
		el.style.display = '';
  } 

function hide(id)
  {	
	var el = getElement(id);
	if (el!=null)
		el.style.display = 'none';
  } 

setTimeZoneCookie();
