/* 
 * PHP File Uploader with progress bar Version 1.20
 * Copyright (C) Radiata Discarnate 2003
 * http://www.raditha.com
 
 * Modified by H&S Information Systems, Jan. 2005
 * http://hsinfosystems.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 Radiata Dissanayake.
 * Portions created by Radiata are Copyright (C) 2003
 * Radiata Dissanayake. All Rights Reserved.
 * 
 * Modified by H&S Information Systems, Dec. 2004.
 */
 

var postLocation="pgbar.php";

/* 
 * add any extension that you do not want to upload to the list 
 * below they should be placed within the /^ and / characters
 * separate each extension by a pipe symbol |
 */
 
var re = /^(\.php)|(\.sh)|(\.js)|(\.exe)|(\.bat)|(\.com)|(\.pif)|(\.htm)|(\.html)|(\.shtml)/;  // disallow shell scripts, php, js, etc.


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

/**
 * this method will match each the filename with a
 * given list of banned extensions. If any one of the
 * extensions match, an alert will be popped up and the
 * upload will not continue; other form fields will be checked
 * for non-emptiness (required fields).
 */
 
function check_types() {
    if(dofilter==false)
        return true;
    with(document.forms[0])
    {
        /*
         * with who uses with?
         * i do, i am an ancient. ok?
         */
         
         if (document.forms[0].phone.value=="" || document.forms[0].custname.value=="" || document.forms[0].email.value=="" || document.forms[0].applic.value=="" || document.forms[0].uploadfile.value=="") 
    {alert('A required field was left blank. Please edit your information.');
    return false;} 
    
if( document.forms[0].FTPCheckBox.checked) {
$filename = document.forms[0].uploadfile.value;

$filename = rightBackString($filename);
$filename = escape ($filename);

$custname = document.forms[0].custname.value;
$company = document.forms[0].company.value;
$phone = document.forms[0].phone.value;
$fax = document.forms[0].fax.value;
$email = document.forms[0].email.value;
$address = document.forms[0].address.value;
$city = document.forms[0].city.value;
$state = document.forms[0].state.value;
$zip = document.forms[0].zip.value;
$platform = document.forms[0].platform.value;
$applic = document.forms[0].applic.value;
$notes = document.forms[0].notes.value;

window.open('ftp://anonymous:guest@ftp.sonic.net/pub/users/howardt/incoming/', 'FTPBox', 'location=yes,toolbar=yes,menubar=yes,directories=yes,status=yes,resizable=yes,scrollbars=yes,height=480,width=640', false);

self.location.href= "ftpupload.php" 
+ "?uploadfile=" + $filename 
+"\&custname=" + $custname 
+ "\&company=" + $company 
+ "\&phone=" + $phone
+"\&fax=" + $fax 
+ "\&email=" + $email 
+ "\&address=" + $address 
+ "\&city=" + $city
+"\&state=" + $state 
+ "\&zip=" + $zip
+ "\&platorm=" + $platform
+"\&applic=" + $applic 
+ "\&notes=" + $notes; 
return false;}

if(document.forms[0].uploadfile.value.match(re))
            {
                alert('Sorry ' + document.forms[0].uploadfile.value + ' is not allowed');
                return false;
            }

    return true;
}
}

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'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

function postIt()
{
    if(check_types() == false )
    {
        return false;
    }
    baseUrl = postLocation;
    sid = document.forms[0].sessionid.value;
    iTotal = escape("-1");
    baseUrl += "?iTotal=" + iTotal;
    baseUrl += "&iRead=0";
    baseUrl += "&iStatus=1";
    baseUrl += "&sessionid=" + sid;

    popUP(baseUrl,"Uploader",460,262,false,false);
    document.forms[0].submit();
}

function rightBackString(fullString) {
   if (fullString.lastIndexOf("/") == -1 && fullString.lastIndexOf("\\") == -1) {
      return fullString;}
if (fullString.lastIndexOf("/") !== -1 )
      {return fullString.substring(fullString.lastIndexOf("/")+1, fullString.length);
   }
if (fullString.lastIndexOf("\\") !== -1 )
      {return fullString.substring(fullString.lastIndexOf("\\")+1, fullString.length);
   } 
   return fullString;
}


/* alternative code below ; not used, but stashed here.

function rightBackString(fullString, subString) {
   if (fullString.lastIndexOf(subString) == -1) {
      return "";
   } else {
      return fullString.substring(fullString.lastIndexOf(subString)+1, fullString.length);
   }
}

function getExtension(value) {
  return value.substring(value.lastIndexOf('.') + 1,value.length);
}

function validateExtension(form) {

var legalExts = new Array('pdf','jpg','jpeg','gif','png','tif','gz','zip', 'eps', 'ai', 'cdr', 'psd', 'wmf','emf','doc','ppt','other');
var illegalExts = new Array('exe','com','pif','bat');
var file=document.form1.fileupload.value;

var ftype = getExtension(file);
ftype = ftype.toLowerCase();

if (document.form1.phone.value=="" || document.form1.custname.value=="" || document.form1.email.value=="" || document.form1.applic.value=="" ) 
    {alert('A required field was left blank. Please edit your information.');
    return false;} 
    
    var l=illegalExts.length;
    var x=0; 
    for (x=0; x<l; x++) 
        { if (ftype == illegalExts[x] )

        {alert("Illegal file type submitted: "+ftype+" Please select again.");
            return false;}
        }

    var l=legalExts.length;
    var x=0; 
    for (x=0; x<l; x++) 
if (ftype == legalExts[x])
    {
        alert(ftype+' will be submitted. Please click \'OK\' and wait for the upload to complete.');
        document.form1.submit();
        return true;
    } 
     alert("Unacceptable file type submitted: "+ftype+" Please select again.");
            return false;
    } 
    
 end of alternative code    */
