function updateJSON(ajax)
{
    json = eval(ajax.responseText);
    for (var i = 0; i < json.length; i++)
    {
        if ($(json[i][0]) != null)
          Element.update(json[i][0], json[i][1]);
    }
}
/**
  *   Copy billing information into shipping
  *
  */
function useBilling(form) {
    for(var i=0; i<form.elements.length; i++) {
        var el = form.elements[i];
        if (el.id != null && el.tagName != 'FIELDSET' && el.id.substring(0,8) == 'billing_') {
            var sel = document.getElementById('shipping_'+el.id.substring(8));
            if (sel != null)
                sel.value = el.value;
        }
    }
}
/**
  *   Opens a javascript window of specified size
  *
  */
function openWindow(url, h, w)
{
  if (w == '')
    w = 300;
  if (h == '')
    h = 300;
  window.open(url, 's', 'toolbar=no,scrollbars=yes,height=' + h + ',width=' + w + ', left=20, top=20');
}
/**
  *   Opens print window
  *
  */
function printWindow(url)
{
		//window.open(url,'s','toolbar=no,scrollbars=yes,height=600,width=900, left=20, top=20');
    openWindow(url, 600, 900);
}
/**
  *   Go to product's page
  *
  */
function goToProduct(field, selected)
{
    var title = trim(selected.id.substr(0,selected.id.indexOf('--c--')));
    var cId = selected.id.substr(selected.id.indexOf('--c--')+5);
    window.location.href = '/products/'+cId+'/'+title;
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function getWidth(){
   return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
}
function getHeight(){
   return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
}
