var mpics
var leftscroll

function ScrollWindow(n,s,d) {
  this.speed=s
  this.direction=d
  this.stop=false
  var obj=document.getElementById(n)
  var temp=obj.innerHTML
  obj.innerHTML='<div id=\"'+n+'1\" style=\"position: absolute; left: 0px; top: 0px; width: auto; height: auto\"></div><div id=\"'+n+'2\" style=\"position: absolute; left: 0px; top: 0px; width: auto; height: auto\"></div>'
  this.content=document.getElementById(n+'1')
  this.trailer=document.getElementById(n+'2')
  this.content.style.textAlign=obj.style.textAlign
  this.trailer.style.textAlign=obj.style.textAlign
this.content.innerHTML=temp
  if (d=='v') {
//    this.content.innerHTML=temp
    this.content.style.width=obj.style.width
    this.trailer.style.width=obj.style.width
  }
  else {
//    this.content.innerHTML=temp
    this.content.style.height=obj.style.height
    this.trailer.style.height=obj.style.height
  }
  if (d=='v') {
    this.containerheight=parseInt(obj.style.height)
    this.contentheight=this.content.offsetHeight
    if (this.contentheight>this.containerheight) {
      if (s>0) {
        this.trailer.style.top=this.contentheight+'px'
        this.trailer.innerHTML=temp
        var thisobj=this
        setTimeout(function(){thisobj.ScrollUp()}, 500)
      }
      else {
        this.content.style.height=obj.style.height
        this.content.style.overflow='scroll'
      }
    }
  }
  else {
    this.containerwidth=parseInt(obj.style.width)
    this.contentwidth=this.content.offsetWidth
    if (this.contentwidth>this.containerwidth) {
      if (s>0) {
        this.trailer.style.left=this.contentwidth+'px'
        this.trailer.innerHTML=temp
        var thisobj=this
        setTimeout(function(){thisobj.ScrollUp()}, 500)
      }
      else {
        this.content.style.width=obj.style.width
        this.content.style.overflow='scroll'
      }
    }
  }
}

ScrollWindow.prototype.ScrollUp=function() {
  if (this.direction=='v') {
    if (parseInt(this.content.style.top)<=-this.contentheight) {
      this.content.style.top='0px'
      this.trailer.style.top=this.contentheight+'px'
    }
  }
  else {
    if (parseInt(this.content.style.left)<=-this.contentwidth) {
      this.content.style.left='0px'
      this.trailer.style.left=this.contentwidth+'px'
    }
  }
  var thisobj=this
  setTimeout(function(){thisobj.ScrollUp()}, 20)
  if (this.stop) {return}
  if (this.direction=='v') {
    this.content.style.top=parseInt(this.content.style.top)-this.speed+'px'
    this.trailer.style.top=parseInt(this.trailer.style.top)-this.speed+'px'
  }
  else {
    this.content.style.left=parseInt(this.content.style.left)-this.speed+'px'
    this.trailer.style.left=parseInt(this.trailer.style.left)-this.speed+'px'
  }
}

ScrollWindow.prototype.ScrollPause=function(p) {
  this.stop=p
}

function centerDiv() {
  var sheight1=window.innerHeight;
  var sheight2=document.body.clientHeight;
  var swidth1=window.innerWidth;
  var swidth2=document.body.clientWidth;
  var sdh=740;
  var sdw=800;
  if (sheight1<sdh) {sheight1=parseInt(sheight1/2)}
  else {sheight1=parseInt(sdh/2)}
  if(sheight2<sdh){sheight2=parseInt(sheight2/2)}
  else {sheight2=parseInt(sdh/2)}
  if(swidth1<sdw){swidth1=parseInt(swidth1/2)}
  else {swidth1=parseInt(sdw/2)}
  if(swidth2<sdw){swidth2=parseInt(swidth2/2)}
  else {swidth2=parseInt(sdw/2)}
  if(window.innerHeight){ //checking for browsers that support window.innerHeight
//    document.getElementById("centered").style.marginTop=-sheight1 + "px"
    document.getElementById("centered").style.marginLeft=-swidth1 + "px"
//    if (document.getElementById("bgcentered")) {document.getElementById("bgcentered").style.marginTop=(-sheight1+201) + "px"}
  }
  else if (document.body.clientHeight) { //checking for browsers that support document.body.clientHeight
//    document.getElementById("centered").style.marginTop=-sheight2 + "px"
    document.getElementById("centered").style.marginLeft=-swidth2 + "px"
//    if (document.getElementById("bgcentered")) {document.getElementById("bgcentered").style.marginTop=(-sheight2+201) + "px"}
  }
}

function Button(obj,path,glow) {
  if (glow) {obj.style.backgroundImage='url('+path+'buttonglow.jpg)'}
  else {obj.style.backgroundImage='url('+path+'button.jpg)'}
}

function isValidEmail(str) {return (str.indexOf(".") > 2) && (str.indexOf("@") > 0)}

function ContactValidate() {
  var e=''
  var obj=document.getElementById('theform')
  if (obj.email.value=='') {e+='E-Mail Field\n'}
  else if (!isValidEmail(obj.email.value)) {e+='Invalid E-Mail\n'}
  if (obj.contact.value=='') {e+='Name Field\n'}
  if (obj.message.value=='') {e+='Enquiry Field\n'}
  if (e=='') {return true}
  window.alert('Please complete the\n'+e+'to continue.')
  return false
}

function QuestionValidate() {
  var e=''
  var obj=document.getElementById('theform')
  if (obj.email.value=='') {e+='E-Mail Field\n'}
  else if (!isValidEmail(obj.email.value)) {e+='Invalid E-Mail\n'}
  if (obj.contact.value=='') {e+='Name Field\n'}
  if (e=='') {return true}
  window.alert('Please complete the\n'+e+'to continue.')
  return false
}

function UploadValidate() {
  var obj=document.getElementById('theform')
  if (obj.pdf.value=='') {
    window.alert('Please click Browse to\nselect a file for upload')
    return false
  }
  var fn=obj.pdf.value.toLowerCase()
  var ln=fn.length
  fn=fn.substr(ln-4)
  if (fn!='.pdf') {
    window.alert('Only PDF files can be uploaded')
    return false
  }
  if (obj.pdfloc.value=='0') {
    window.alert('Please select the destination page for the PDF')
    return false
  }
  fn=obj.pdf.value
  ln=fn.length
  fn=fn.substr(0,ln-4)
  ln=fn.lastIndexOf('\\',ln)
  fn=fn.substr(ln+1)
  return window.confirm('PDF will appear as\n\n'+fn+'\nin\n'+obj.pdfloc.options[obj.pdfloc.selectedIndex].text)
}

function init() {
  if (arguments.callee.done) {return}
  arguments.callee.done = true
  centerDiv()
  if (document.getElementById('minipics')) {mpics=new ScrollWindow('minipics',1,'v')}
  if (document.getElementById('leftscroll')) {leftscroll=new ScrollWindow('leftscroll',2,'h')}
  if (document.getElementById('theform')) {
    if (document.getElementById('theform').email) {document.getElementById('theform').email.focus()}
  }
}

function unload() {
  if (arguments.callee.done) {return}
  arguments.callee.done = true
}

if (window.attachEvent) {
  window.attachEvent("onload", init)
  window.attachEvent("onunload", unload)
  window.attachEvent("onresize", centerDiv)
}
else if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false)
  document.addEventListener("unload", unload, false)
  document.addEventListener("resize", centerDiv, false)
}
window.onload = init
window.onunload = unload
window.onresize=centerDiv;
