/* 
 * PHP File Uploader with progress bar Version 1.20
 * Copyright (C) Raditha Dissanyake 2003
 * http://www.raditha.com

 * Licence:
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Initial Developer of the Original Code is Raditha Dissanayake.
 * Portions created by Raditha are Copyright (C) 2003
 * Raditha Dissanayake. All Rights Reserved.
 * 
 */
 

var postLocation="pgbar.php";

/* 
 * add any extension that you do no want to upload to the list 
 * below they should be placed with in the /^ and / characters
 * separate each extension by a pipe symbol |
 */
var re = /^(\.php)|(\.php3)|(\.php4)|(\.php)|(\.htaccess)|(\.pl)|(\.cgi)|(\.html)|(\.exe)|(\.com)|(\.asp)|(\.js)|(\.jsp)|(\.xml)|(\.java)|(\.sh)/;


/**
 * dofilter = true; to enable filtering
 */
var dofilter=true;

/*****************************************************************************\
 * This gets the length of the content headers to fix a bug in perl code.    *
\*****************************************************************************/
function form_size()
{
  var j = 0;
  with (document.next_page_form)
      {
        for (i=0; i < elements.length; i++)
           {
             switch (elements[i].type)
                   {
                     case "text":
                     case "hidden":
                     case "textarea":
                     case "password":
                     case "select-one":
                     case "select-multiple":
                         {
                           j += String('-----------------------------7d412412a0518\r\n').length;
                           j += String('Content-Disposition: form-data; name="'+document.next_page_form.elements[i].name+'"\r\n\r\n').length;
                           j += String(elements[i].value+'\r\n').length;
                           break;
                         }
                     case "radio":
                     case "checkbox":
                         {
                           if (elements[i].checked)
                             {
                               j += String('-----------------------------7d412412a0518\r\n').length;
                               j += String('Content-Disposition: form-data; name="'+document.next_page_form.elements[i].name+'"\r\n\r\n').length;
                               j += String(elements[i].value+'\r\n').length;
                             }
                           break;
                         }
                     case "file":
                         {
                           j += String('-----------------------------7d412412a0518\r\n').length;
                           j += String('Content-Disposition: form-data; name="'+document.next_page_form.elements[i].name+'"; filename=""\r\nContent-Type: application/octet-stream\r\n\r\n\r\n').length;
                           j += String(elements[i].value+'\r\n').length;
// We don't want to send the file data.
                           break;
                         }
                     case "button":
                     case "action":
                     case "reset":
                     case "submit":
                     case "image":
                     case "layer":
                         {
                           break;
                         }
                     default:
                         {
                           alert("Unknown form element type: "+elements[i].type+".");
                           break;
                         }
                   }
           }
      }

// Add the footer.
  j += String('-----------------------------7d412412a0518--\r\n').length;
  return j;
}
/*****************************************************************************\
 * Check to see if any of the file extensions are in our banned list.        *
\*****************************************************************************/
function check_types()
{
  with (document.next_page_form)
      {
        for (i=0; i < elements.length; i++)
           {
             if (elements[i].value.match(re))
               {
                 alert('Sorry '+elements[i].value+' is not an allowed file.');
                 return false;
               }
           }
      }

  return true;
}
/*****************************************************************************\
 * Check to see if there are any files to upload, if not, skip uploading pg. *
\*****************************************************************************/
function check_files()
{
  var some_file = false;

  with (document.next_page_form)
      {
        for (i=0; i < elements.length; i++)
           {
             switch (elements[i].type)
                   {
                     case "file":
                         {
                           if (document.next_page_form.elements[i].value != "")
                             return true;
                           break;
                         }
                   }
           }
      }

  return false;
}
/*****************************************************************************\
 * Create a pop-up window to display progress meter in.                      *
\*****************************************************************************/
function popUP(mypage, myname, w, h, scroll, titlebar)
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  meter_win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4)
    meter_win.window.focus();
}
/*****************************************************************************\
 * Generates a random number so more than one pop-up window may be displayed.*
\*****************************************************************************/
function getRandom()
{
  today = new Date();
  var bigNumber = today.getSeconds() * today.getTime() * Math.sqrt(today.getMinutes());
  var randomNum = (bigNumber % 1000)+1;

  return Math.floor(randomNum);
}
/*****************************************************************************\
 * Create a form and post data to new window and start progress meter.       *
\*****************************************************************************/
function postIt()
{
  if (check_types() == false)
    {
      return false;
    }

  if (check_files() == false)
    {
      document.next_page_form.action = "order.php";
      document.next_page_form.submit();
    }
  else
    {
      baseUrl = postLocation;
      sid = document.next_page_form.sid.value;
      iTotal = escape("-1");
      baseUrl += "?iTotal="+iTotal;
      baseUrl += "&iRead=0";
      baseUrl += "&iStatus=1";
      baseUrl += "&sid="+sid;
      baseUrl += "&content_length="+form_size();

      popUP(baseUrl, getRandom(), 460, 200, false, false);
      document.next_page_form.submit();
    }
}