function MultiSelector(list_target,max){
    this.list_target  = list_target;
    this.count        = 0;
    this.id           = 0;
    if(max){
        this.max=max;
    }
    else{
        this.max=-1;
    };
    
    this.addElement=function(element) {
        if(element.tagName=='INPUT'&&element.type=='file') {
            element.name            = 'file_'+this.id++;
            element.multi_selector  = this;
            element.onchange = function() {
                var new_element   = document.createElement('input');
                new_element.type  = 'file';
                this.parentNode.insertBefore(new_element,this);
                this.multi_selector.addElement(new_element);
                this.multi_selector.addListRow(this);
                this.style.position = 'absolute';
                this.style.left     = '-1000px';
            };
            if(this.max!=-1&&this.count>=this.max){
                element.disabled=true;
            };
            this.count++;
            this.current_element=element;
        }
        else{
            alert('Error: not a file input element');
        };
    };
    
    this.addListRow=function(element) {
        var new_row         = document.createElement('div');
        var new_row_button  = document.createElement('input');
        new_row_button.type = 'button';
        new_row_button.value= 'Delete';
        new_row.element     = element;
        new_row_button.onclick=function() {
            this.parentNode.element.parentNode.removeChild(this.parentNode.element);
            this.parentNode.parentNode.removeChild(this.parentNode);
            this.parentNode.element.multi_selector.count--;
            this.parentNode.element.multi_selector.current_element.disabled=false;
            return false;
        }
        ;
        new_row.innerHTML=element.value;
        new_row.appendChild(new_row_button);
        this.list_target.appendChild(new_row);
    }
    ;
}
;

  function showMsg(show) {    
    var msg = document.getElementById('message');
    if (show) {
      var querystring=window.location.search.substring(1);
      var msgText = document.createTextNode(unescape(querystring.substring(querystring.indexOf('=')+1)));
      msg.appendChild(msgText);
    } else {
      if (msg.hasChildNodes())msg.removeChild(msg.firstChild);
    }
  }
  function exists(name) {
    var val = document.getElementById(name).value;
    if(val=='') return 0;
    else return 1;
  }
  function validate() {
    var picaccepted = document.getElementById('picacceptbox').checked;
    var tcaccepted = document.getElementById('tcacceptbox').checked;
    var ppaccepted = document.getElementById('ppacceptbox').checked;


    if(!exists('name')) {
      alert('Please enter your name');
      return false;
    }
    if(!exists('city')) {
      alert('Please enter your city of residence');
      return false;
    }
    if(!exists('state')) {
      alert('Please enter the state you are in');
      return false;
    }
    if(!exists('description')) {
      alert('Please enter a description for this photo');
      return false;
    }
    if(tcaccepted && ppaccepted && picaccepted) {
      return true;
    }
    else {
      alert('Please read and accept all of the Terms and Conditions and Privacy Policy statements');
      return false;
    }
  }
  var acceptWin = '';
  function popAcceptWin(url) {
    if (!acceptWin.closed && acceptWin.location) {
      acceptWin.location.href = url;
    } else {
      acceptWin = window.open(url, 'acceptWin', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=650');
    }    
    if (window.focus) { acceptWin.focus(); }
  }
