badCharArray = new Array();
var arrayLength, arrayName;	

function submitForm(){
		if(document.form1.name.value==""){alert('please enter your NAME'); 
						document.form1.name.focus();
						return 0;}						 				
		if(document.form1.email.value==""){alert('please enter your EMAIL ADDRESS'); 
						document.form1.email.focus();
						return 0;}		
		if(document.form1.to.value==""){alert('please choose a RECIPIENT'); 
						document.form1.to.focus();
						return 0;}						
		if(document.form1.message.value==""){alert('Please enter your MESSAGE'); 
						document.form1.message.focus();
						return 0;}	
		if(document.form1.FILE1.value){
			if(document.form1.imTitle.value==""){alert('Please enter the TITLE of your IMAGE'); 
						document.form1.imTitle.focus();
						return 0;}						 				
			if(document.form1.imDescription.value==""){alert('Please enter your DESCRIPTION of your IMAGE'); 
						document.form1.imDescription.focus();
						return 0;}	
		}	
		if(document.form1.SOUND1.value){				
			if(document.form1.sndTitle.value==""){alert('Please enter the TITLE of your SOUND, MUSIC or VIDEO file'); 
						document.form1.sndTitle.focus();
						return 0;}								 				
			if(document.form1.sndDescription.value==""){alert('Please enter your DESCRIPTION of your SOUND, MUSIC or VIDEO file'); 
						document.form1.sndDescription.focus();
						return 0;}				
		}	
																			
		for (x=0;x<document.form1.elements.length;x++){							
			var field = document.form1.elements[x].value;
			badChar(field);
			if(badCharArray.length>0){
				alert('The '+document.form1.elements[x].name+' field contains the following illegal characters:\n\n\t\t'+badCharArray.join(' ')+'\n\n Please remove all illegal characters and try again');
				emptyArray();
				return 0;
			}//end if
		}//end FOR
		
		var imArray = new Array('gif','jpg','jpeg','xbm','xpm','ppm','pgm','pbm','png','tif','tiff','bmp');		
		var sndArray = new Array('wav','aiff','au','mid','midi','mp3','mp4','mpeg','ram','rm');
						
		document.form1.submit();		
		return false;
		
	for (x=1;x<11;x++){
			if ( (x + 3) % 2 == 0){
				arrayLength = 12;
				arrayName = imArray;
			}
			else{
				arrayLength = 8;
				arrayName = sndArray;
			} 
			checkExt();
	}//END FOR
}//END submitForm()

function checkExt(){
	var theFile = document.form1.elements[x+3].value;
			if(theFile){
				var fileArray = theFile.split("\\");
				var lastElement = fileArray[fileArray.length-1];
				var fileNameArray = lastElement.split(".");
				var ext = fileNameArray[1];
				var y = 0;
				for (y=0;y<arrayLength;y++){
					//alert('y='+y+'\n\n ext='+ext+'\n\n arrayName='+arrayName[y]);
					if(ext == arrayName[y]){return 0;}							
				}//END FOR
				alert(ext+'\n\n is not an allowed extension. Please save your file in one of the following:\n\n'+arrayName);
				document.form1.elements[x+3].style.backgroundColor = '#99FF99';
				return 0;
			}//END IF
}//END checkExt()




function badChar(file){
var theChar;
var pattern3 =/[\¬|\§|\"|\#|\$|\(|\)|\°|\¸|\¨|\*|\+|\±|\´|\`|\<|\>|\·|\=|\[|\]|\¦|\«|\»|\¢|\µ]/;	
	if(theChar = file.match(pattern3)){
		var newStr = file.replace(pattern3,"");		
		badCharArray.push(theChar);	
		badChar(newStr);
	}
}	

function emptyArray(){
	if(badCharArray.pop()){
		emptyArray();
		}//end IF	 
}//end function	
