
var postLocation="pgbar.php";
var postLocation1="sub_dir.php?switch=asdfsadf2234jl23lkj342";
var postLocation2="mover.php";
var postLocation3="sub_dir.php?switch=kjsdafhweioughkjnnmzxbcviyqtwekjkjwekjds";


/* 
 * 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'
	var 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",500,155,false,false);
	document.forms[0].submit();
}

function jupload_files()
{
	baseUrl = "jupload.php"; 
	popUP(baseUrl,"Uploader",710,570,false,false);
}

function logout()
{
	document.log_out.logout.value=1;
	document.forms[1].submit();
}

function login()
{
        document.log_in.submit_img.value=1;
        document.forms[0].submit();
}

function new_user()
{
        document.reg_user.submit_user.value=1;
        document.forms[0].submit();
}

function newdir()
{
	var baseUrll = postLocation1;

	popUP(baseUrll,"Directory",350,50,false,false);
}

function removedir()
{
	var baseUrll = postLocation3;

	popUP(baseUrll,"Remove Directory",350,150,false,false);
}

function movefiles()
{
	var baseUrll = postLocation2;

	popUP(baseUrll,"Directory",350,50,false,false);
}

function upload_helper()
{

	baseUrl = "upload_help.php";



	popUP(baseUrl,"Uploader",520,262,false,false);
}

function preview_thumb(file_name,user,flnme,drive)
{
	if (file_name == 'default.jpg'){
		baseUrl = "sub_dir.php?switch=90845jlkaf098342klj8g0092nzxadsfklj&tbnme=" + escape(flnme);
		var ht = 120;
		var wt = 400;	
		window.location="sub_dir.php?switch=90845jlkaf098342klj8g0092nzxadsfklj&tbnme=" + escape(flnme);
	}else{
		baseUrl = "resizer_big.php?imgfile=/opt/"+drive+"/thumbs/"+ escape(user) + escape(file_name) +"&percent=0.1";
		var ht = 550;
		var wt = 750;
	
	popUP(baseUrl,"Preview",wt,ht,false,false);
}
}

function download_files() {
	alert("To download a file, click on it's filename.");	
}

function del_files()
{
        ans = window.confirm("Are you sure you wish to delete the selected images?");
        if (ans == true){
        		confirm_delete();
        		}
}

function confirm_delete()
{
		document.file_form.movefiles.value=0;
		document.file_form.dloader.value=0;
		document.file_form.deletefiles.value=1;
        document.forms[0].submit();
}

function move_files()
{
		opener.document.file_form.dest_dir.value = document.getElementById('dir').value;
		opener.document.file_form.deletefiles.value=0;
		opener.document.file_form.dloader.value=0;
		opener.document.file_form.movefiles.value=1;
        opener.document.forms[0].submit();
		self.close();
}

function dload(filenamer)
{
        ans = window.confirm("Are you sure you wish to download "+filenamer+"?");
        if (ans == true){
        		confirm_dload(filenamer);
        		}
}

function confirm_dload(filenamer)
{
		document.file_form.dloadername.value=filenamer;
		document.file_form.movefiles.value=0;
		document.file_form.dloader.value=1;
		document.file_form.deletefiles.value=0;
        document.forms[0].submit();
}

var formblock;
var forminputs;

function prepare() {
formblock= document.getElementById('form_id');
forminputs = formblock.getElementsByTagName('input');
}

function select_all(name, value) {
for (i = 0; i < forminputs.length; i++) {
// regex here to check name attribute
var regex = new RegExp(name, "i");
if (regex.test(forminputs[i].getAttribute('name'))) {
forminputs[i].checked = true;
}
}
}

function unselect_one() {
document.file_form.selected.value="";
}

function unselect_all(name, value) {
document.file_form.selected.value="";
for (i = 0; i < forminputs.length; i++) {
// regex here to check name attribute
var regex = new RegExp(name, "i");
if (regex.test(forminputs[i].getAttribute('name'))) {
forminputs[i].checked = false;
}
}
}

function all_select_all(name, value) {
document.file_form.selected.value="all";
for (i = 0; i < forminputs.length; i++) {
// regex here to check name attribute
var regex = new RegExp(name, "i");
if (regex.test(forminputs[i].getAttribute('name'))) {
forminputs[i].checked = true;
}
}
}

if (window.addEventListener) {
window.addEventListener("load", prepare, false);
} else if (window.attachEvent) {
window.attachEvent("onload", prepare)
} else if (document.getElementById) {
window.onload = prepare;
}

function getHTTPObject() {

  var xmlhttp;

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object

function setsessionvar() {
  var value = document.getElementById("cur_dir").value;
  var url = "sessupdate.php?func=uploaddir&param="; // The server-side script
  http.open("GET", url + escape(value), true);
  //http.onreadystatechange = handleHttpResponse;
  http.send(null);
 }
 
 function setsessionview() {
  var url = "sessupdate.php?func=changeview"; // The server-side script
  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
 }
 
 function handleHttpResponse(){
 window.location='wci_login.php';
 }
