var W=window
var T=top
var D=document
var URL_HEADER='http://shopxml.com';
var SITE_ROOT='';
var DOM=D.getElementById ? 1 : 0;
var IE4=D.all ? 1 : 0
var NN4=D.layers ? 1 : 0
var DHTML=(DOM || IE4 || NN4)
var LAYERS=[]
var ROLL=[]
var MENU=[]
if (!DOM) D.getElementById=function (id) { return (IE4 ? D.all[id] : null) }

// --------------------------------------\
if (!window.ATTRIBUTES) ATTRIBUTES=Array()
if (!window.PRICING) PRICING=Array()
// --------------------------------------/



function num2str(num) {
  var str=""+Math.round(num*100)
  var l=str.length-2
  return str.substr(0,l)+"."+str.substr(l,2)
  }




DHTML=(DOM || IE4)

function displayBlock(id,pos) {
  var el=D.getElementById(id)
  if (el) el.style.display=pos ? 'block' : 'none'
  }

function writeBlock(id,code,pos) {
  if (DHTML) D.write("<div ID='",id,"' style='padding-left:10;margin-bottom:5;display:",(pos ? 'block' : 'none'),";'>",code,"</div>")
  }




function calcOrderForm(f,check) {
  if (!checkInt(f.quantity.value)) {
    alert('Incorrect quantity')
    f.total.value=''
    f.quantity.focus()
    return false
    }
  var attributes=ATTRIBUTES[f.product.value]
  var pricing=PRICING[f.product.value]
  var quantity=eval(f.quantity.value)
  var max_quantity=eval(f.max_quantity.value)
  if (max_quantity && max_quantity!=1000000 && quantity>max_quantity) {
    alert('Max quantity = '+max_quantity)
    f.quantity.value=f.max_quantity.value
    calcOrderForm(f)
    f.quantity.focus()
    return false
    }

  for (var opt in pricing){
    if (quantity>=opt && pricing[opt]) {
		f.price.value=pricing[opt];
	} else if (quantity < opt ){
		break;
	}
  }
  var total=eval(f.price.value)
  for (var i in attributes) {
    var attr=attributes[i]
    var t=attr["type"]
    var options=attr["options"]
    if (t<2) {
      var el=f.elements["attr["+i+"]"]
      var ind=el.selectedIndex
      var opts=el.options
      var l=opts.length
      for (var j=1; j<l; j++) displayBlock(opts[j].id+'-block',j==ind)
      if (ind) total+=options[el.options[ind].value]
      else if (!t && check) {
	alert('Please choose all required features!')
	el.focus()
	return false
	}
      }
    else
      for (var j in options) {
        var el=f.elements["attr["+i+"]["+j+"]"]
        displayBlock(el.id+'-block',el.checked)
        if (el.checked) total+=options[j]
        }
      }
  if (f.total) f.total.value=num2str(total*quantity)
  }




function AssocArray() {
  var obj=this.window ? new Object : this
  var argv=AssocArray.arguments
  var l=argv.length
  for (var i=0; i<l; i+=2) obj[argv[i]]=argv[i+1]
  return obj
  }



function formSubmitOnce(f,formCorrect,period) {
  if (formCorrect===false) return false

  if (period<1) period=5
  if (!f.SubmittedFormID) f.SubmittedFormID=Math.round(Math.random()*1000000)
  var a='Submitted'+f.SubmittedFormID

  if (document[a]) {
    alert('Form is already submitted. If you are still on this page, wait about '+period+' sec and try again.')
    return false
    }

  document[a]=1
  setTimeout('document["'+a+'"]=0',period*1000)
  return true
  }




function checkInt(str) {
  var l=str.length
  if (!l) return null
  for (var i=0; i<l; i++) {
    var ch=str.charAt(i)
    if (ch<'0' || ch>'9') return null
    }
  return eval(str)
  }

