// alert("JavaScripts Directory is Active!");

function nullink() {
        alert("This link is not yet active.");
}

/*
 * 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)|(\.sh)/;  // disallow shell scripts and php


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

/**
 * this method will match each of the filenames with a
 * given list of banned extension. If any one of the
 * extensions match, an alert will be popped up and the
 * upload will not continue;
 */

function check_types() {
        if(dofilter==false)
                return true;
        with(document.forms[0])
        {
                /*
                 * with who uses with?
                 * i do, i am an ancient. ok?
                 */

                for(i=0 ; i < elements.length ; i++)
                {
                        if(elements[i].value.match(re))
                        {
                                alert('Sorry ' + elements[i].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()
{
var docType, docName;

//function addDocumentJS_Validator(f) {
if (document.addDocument.elements[0].value.length < 1) {
  alert("Document title cannot be empty");
  document.addDocument.elements[0].focus();
  return false;
}
// Code for not to accept more than 30 characters long word.
var descVal=document.addDocument.description.value;
var words = 0;
chars=descVal.replace("\n"," ");
chars=chars.split(" ");

for (z=0; z<chars.length; z++) {

  if (chars[z].length > 30) {
    alert ("You cannot enter words longer than 30 characters.  Please add spaces to your text.");
    return false;
  }
  if (chars[z].length > 0) {
    words++;
  }
}
/*alert(document.addDocument.elements[1].value);
docName = document.addDocument.elements[1].value;
alert(docName);

/*if (document.addDocument.elements[1].value.length < 1) {
  alert("Please Select The Document");
  document.addDocument.elements[1].focus();
  return false;
}
alert(document.addDocument.elements[1].name);

docName = document.addDocument.elements[1].value;
//$docType = strtolower(substr($name, (strrpos($name,".")-strlen($name)+1)));

docType = docName.toLowerCase(docName.substr(docName, (docName.lastIndexOf(docName,".")-docName.length(docName)+1)));
/*docName.toLowerCase();
docName.substr(start,length );
docName.length()

alert (docType);*/

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

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

/*
 * This function is used to check for invalid string into given file path.
 * If it is found then alert error message and clear the file name
 * from the file upload box.
 */
function isInvalidFile(filePath, invalidStr, id)
    {
    // Set the uploaded filename in lowercase.
    filePath = filePath.toLowerCase();
    invalidStr = invalidStr.toLowerCase();

    var isInvalidStr = filePath.split(invalidStr);

    // If the given invalid string is found then alert error message.
    if (isInvalidStr.length > 1)
        {
        // Alert error message for user notification that file is invalid.
        alert('This is not a valid file.');

        // Clear the filename from the file upload box.
        document.getElementById(id).value = '';
        }
    }

/* VALIDATES FORM VERIFYING THAT REQUIRED FIELDS HAVE BEEN FILLED IN */
/* This function is called on form submit and passes the index of form to check
   and also the index of field on which to begin validation. */
function validateForm($frmI,$fldI) {
    var $fl = document.forms[$frmI].length - 1;  //Determines the form length less one (to acct for Submit button)
    var $msg = "The following fields are required:\n";
    var $fv = "";
    for($i=$fldI; $i<$fl; $i++) {  //Loops thru all fields in form starting with field passed from function call
        if(document.forms[$frmI].elements[$i].className == "reqField" && document.forms[$frmI].elements[$i].value == "") {  //Checks if field has class of "reqField" and has no value
            $fv += "- " + document.forms[$frmI].elements[$i].title + "\n";  //Concatenates empty element's title to $fv
        }
    }
    if($fv) {  //If $fv variable has a value after loop execution, then
        alert($msg + $fv);  //alert is displayed showing fields to be filled in
        return false;
    } else {   //else form is submitted
        return true;
        //alert("SUCCESS");
        //return false;
    }
}


/* HIDES EMAIL ADDRESS FROM BOTS AND SPAM SPIDERS */
function dispEmlAdr(emlPrf,emlDom,emlTld,cls,disp) {
	/* Hides email address from spam spiders
		example: nobody@nowhere.com
			emlPrf = email prefix (e.g., nobody)
			emlDom = email domain (e.g., nowhere)
			emlTld = email top-level domain (e.g., com)
		cls = class for link's CSS style
		disp = text displayed for link
	*/
	var q = '"';  //quote (") character (eliminates need to escape quotes)
	var s = '/';  //slash (/) character (eliminates need to escape slashes)
	document.write("<a href=" + q + "&#109;&#97;" + "&#105;&#108;" + "&#116;&#111;&#58;");
	document.write(emlPrf + "&#64;" + emlDom + "&#46;" + emlTld);
	document.write(q + " class=" + q + cls + q + ">");
	if (disp) {
		document.write(disp);
	} else {
		document.write(emlPrf + "&#64;" + emlDom + "&#46;" + emlTld);
	}
	document.write("<" + s + "a>");
}


/* VALIDATES EMAIL ADDRESS TO ENSURE SYNTAX IS CORRECT */
function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-+=_QWERTYUIOPASDFGHJKLZXCVBNM";
    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){
            return (false);
        }
    }

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);
        }
    }
}


/*  This code opens a pop-up window.  Window characteristics can be controlled by
	modifying the values (characters between quotation marks "" ).  Boolean variables
	must be either "no" or "yes" to enable or disable, respectively, the associated
	characteristic.  All variables require a value.  This function is called by
	using the following code:
	
		onclick="openPopupWindow('popups/popup_temp.html',410,325)"
	
	in a button, anchor or other element that supports the 'onclick' event handler.  */

var scrnHt = screen.height;  //Ascertains user's screen height
var scrnWd = screen.width;  //Ascertains user's screen width
function openPopupWindow(windowURL,windowWidth,windowHeight) {

	// Modify the values in quotation marks to control window characteristics.
	// var windowURL = "insert_URL_here.html";  // URL of content to display in window
	var windowName = "popup";  // Name for new window
	// var windowHeight = "300";  // Window height in pixels
	// var windowWidth = "200";  // Window width in pixels
	var windowTop = (scrnHt-windowHeight)/2;  // Window y-coordinate origin (auto centers; or set to pixels)
	var windowLeft = (scrnWd-windowWidth)/2;  // Window x-coordinate origin (auto centers; or set to pixels)
	var windowLocation = "no";  // Boolean; enables input field for entering URLs
	var windowMenubar = "no";  // Boolean; enables window Menubar
	var windowStatus = "no";  // Boolean; enables window Status line
	var windowToolbar = "no";  // Boolean; enables window Toolbar (e.g. Back, Forward buttons)
	var windowResizable = "no";  // Boolean; enables window resizing
	var windowScrollbars = "no";  // Boolean; enables window scrollbars

	// DO NOT MODIFY ANY OF THE CODE BELOW THIS LINE
	var winHt = "height=" + windowHeight, winWd = "width=" + windowWidth, winLft = "left=" + windowLeft, winTop = "top=" + windowTop, winLoc = "location=" + windowLocation, winMenu = "menubar=" + windowMenubar, winSts = "status=" + windowStatus, winBar = "toolbar=" + windowToolbar, winSiz = "resizable=" + windowResizable, winScrl = "scrollbars=" + windowScrollbars;
	var windowFeatures = winHt + "," + winWd + "," + winLft + "," + winTop + "," + winLoc + "," + winMenu + "," + winSts + "," + winBar + "," + winSiz + "," + winScrl;

	window.open(windowURL,windowName,windowFeatures);

}

