/*
* 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="progress.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;
	var theform=document.getElementById('upload2');
	with(theform)
	{
		/*
		* 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 isValidEmail(str)
{
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


function postIt(toolbar){
    if(check_types() == false){
	return false;
}
	var form=document.getElementById('upload2');
	var els=form.getElementsByTagName('input');
/*    if(document.getElementById('description')){
        if(document.getElementById('description').value==''){
            alert("Please enter description !");
            document.getElementById('description').focus();
            return false;
        }
    }*/

    if(document.getElementById('upload1').value==''){
	    alert("Please select a file !");
	    document.getElementById('upload1').focus();
	    return false;
    }
    
    if(document.getElementById('your_email')){
        if(document.getElementById('your_email').value!='' && !isValidEmail(document.getElementById('your_email').value)){
            alert("Invalid email address !");
            document.getElementById('your_email').focus();
            return false;
        }
    }
    if(document.getElementById('agreement')){
        if(!document.getElementById('agreement').checked){
            alert("You have to agree with terms and conditions !");
            document.getElementById('agreement').focus();
            return false;
        }
    }
	baseUrl = postLocation;
	//   sid = form.sessionid.value;
	//   did = form.did.value;
	iTotal = escape("-1");
	//   baseUrl += "?iTotal=" + iTotal;
	//   baseUrl += "&iRead=0";
	//   baseUrl += "&iStatus=1";
	rand=new Date();
	baseUrl += "?rand="+rand.getTime() + "&UPLOAD_IDENTIFIER=" + document.getElementById('sessionid').value ;
	//   baseUrl += "&did=" + did;
	//popUP(baseUrl,"progress_bar",460,262,false,false);
	document.getElementById('progress_bar_frame').style.display="block";
	if(pro_user)
	{
		document.getElementById('progress_bar_frame').style.height="100";
	}
	else
	{
		document.getElementById('progress_bar_frame').style.height="100";
	}
	//   document.getElementById('progress_bar_frame').src=baseUrl;
	//		window.open(baseUrl,'progress_bar_frame');
	/*   alert(baseUrl);
	alert(document.getElementById('progress_bar_frame').src);*/
	//document.getElementById('progress_bar_frame').document.location=baseUrl;
	/*   var uploadbtn=document.getElementById('upload_btn');
	uploadbtn.value="Please wait ...";
	uploadbtn.disabled=true;
	*/
	if(document.getElementById('upload_form_div')) document.getElementById('upload_form_div').style.display="none";
	var fsd=document.getElementById('file_select_div');
	var un=document.getElementById('upload_notice');
	//   alert(un.style.display);
	//   alert(fsd.style.visibility);
	if(un){
        un.style.display="";
        un.style.position="relative";
    }
    if(fsd){
        fsd.style.visibility="hidden";
        fsd.style.position="relative";
    }
	//   alert(un.style.display);
	//   alert(fsd.style.visibility);
    if(!toolbar) setTimeout("r()",5000);
	form.submit();
}
