
var filecount = 0
var ignorestring = ""
var lastbox=9999;
var lastboxarr = new Array();
lastboxarr.push(99);
function addFilebox(filenum){
		
		var boxnum=filenum.split("_")[1];
		
		
		
		var newnum=parseInt(boxnum)+1;
		
		var nextfilebox
		
		var filebox = document.getElementById(filenum)		
		var fullname = filebox.value
		var shortname = fullname.substring(fullname.lastIndexOf("\\")+1)
		var ignorestr = ",.exe,.dll,"
		var filetype = shortname.substring(shortname.indexOf("."))
		//get the item from the file_0 box to ensure it is a jpg file
		var thefilebox = document.getElementById('file_0')
		var fullname2 = thefilebox.value
		var shortname2 = fullname2.substring(fullname2.lastIndexOf("\\")+1)
		var filetype2 = shortname2.substring(shortname2.indexOf("."))
		//end get
		if (filetype2=='.jpg'){
			
			//add new box
			var themess = document.getElementById('nextmessage');	
			themess.style.display = "block";
				
			if(newnum < 3){
	  			var filebox = document.getElementById('file_'+newnum);	
				filebox.style.display = "block";
	  		}else{
			//	var filemaxi = document.getElementById('filemax');	
			//	filemaxi.style.display = "block";
			}
			
		}else{
			alert('The first file to be uploaded has to be an image with the file type of "jpg"');
		}
		if(ignorestr.indexOf(","+filetype+",")>-1){
			alert("Sorry, uploading files of type: " + filetype + " is not allowed") 
			filebox.style.display = "none"
		}
		var nope=0;
		for(x=0;x<lastboxarr.length;x++){
			
			if(filenum==lastboxarr[x]){
				nope=nope+1;
			}
		}
	//	alert('nope: '+nope);
		if (nope==1){
		}else{
				//alert(filecount+'  '+filenum+'  '+lastbox);
				filecount++;
			 } 
		
		lastboxarr.push(filenum);
}
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function showbar(){
	
	var theDiv = document.getElementById('hide_bar');
	theDiv.style.display = "block";
	
	

	
}
function checkuploadform(formname){

	var theform = document.forms[formname]
	var returnval = true
	var errorstring = "There were some errors in the form.\n\rPlease check the following:\n\r"
	var i=0
	var permissionStr
	var companyvar = ""
	var groupvar = ""
	
	if(formname == "uploadform_frm"){
		if(theform.file_0.value==''){
			errorstring += "Please ensure you select a file to upload.\r\n"
	  		returnval = false
		}
		if(theform.txtName.value==''){
			errorstring += "Please ensure your name is entered.\r\n"
	  		returnval = false
		}
		if(theform.txtTitle.value==''){
		errorstring += "Please ensure a title is entered.\r\n"
  		returnval = false
		}
		if(theform.txtDescription.value==''){
			errorstring += "Please ensure a description is entered.\r\n"
	  		returnval = false
		}
		if(theform.txtEmail.value==''){
			errorstring += "Please ensure your email address is entered.\r\n"
	  		returnval = false
		}else{
			var rslt=isValidEmail(theform.txtEmail.value);
			if (rslt!=true){
				errorstring += "Please ensure your email address valid.\r\n"
				returnval = false
			}
		}
  	
  			
	  	if(! returnval){
	  		alert(errorstring)
	  	}else{  		
				theform.filecount.value = filecount
				//set the ignore string
				theform.ignorestr.value = ignorestring	
	  	}
	  	return returnval
	}
	
}