// JavaScript Document   

//  BEGIN Function To Test Form For REQUIRED FIELD  
function validateForm(){	
	var formError = 0;
	
	// TEST txtEmail Form Field   
	var field = document.getElementById('txtEmail').value;		
	if(field == null || field == ''){
		formError = 1;
	}
	
	// TEST txtFullName Form Field   
	var field = document.getElementById('txtFullName').value;		
	if(field == null || field == ''){
		formError = 1;
	}
	
	// TEST txtPhoneNumber Form Field   
	var field = document.getElementById('txtPhoneNumber').value;		
	if(field == null || field == ''){
		formError = 1;
	}
	
	// TEST txtProduct Form Field   
	var field = document.getElementById('txtProduct').value;		
	if(field == null || field == ''){
		formError = 1;
	}
	
	// Check if fields are NULL   
	if(formError != 0){
		$('.requiredField').css('color','#F00');
		$('.requiredField').css('font-weight','bold');
		alert('Please Fill In All Required Fields');
	}else{
				
		//  TEST for Valid Phone Number Format   
		var reg = /^(([0-9]{1})*[- .(]*([0-9a-zA-Z]{3})*[- .)]*[0-9a-zA-Z]{3}[- .]*[0-9a-zA-Z]{4})+$/;
		var phone = document.getElementById('txtPhoneNumber').value;
		if(reg.test(phone) == false) {
			formError = 1;
			alert('Invalid Phone Number Format');
		}
		
		//  TEST for Valid Email Format   
		var reg = /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/;
		var address = document.getElementById('txtEmail').value;
		if(reg.test(address) == false) {
			formError = 1;
			alert('Invalid Email Format');
		}
	
		// CHECK if everything is Valid Format   
		if(formError != 0){
			
		}else{
			
			// CHECK for FILES in QUEUE
			var noFile = $('#fileInput2').uploadifySettings('queueSize');
			
			if(noFile <= 0){
				alert('You Must Select At Least 1 File To Upload');
			}else{
				// EXECUTE Uploadify Script   
				$('#fileInput2').uploadifySettings('scriptData', {'ext':$('#dirTimeStamp').val(), 'ext2':$('#txtEmail').val()});
				jQuery('#fileInput2').uploadifyUpload();
			}
			
		}
	}
}
//  END Function To Test Form For REQUIRED FIELD  

// BEGIN Uploadify Script  
$(document).ready(function() {
	var fileSizeLimitMB=150;
	var fileSizeLimit=((fileSizeLimitMB * 1024) * 1025);
	
	$("#fileInput2").uploadify({
		'scriptAccess'	 : 'always',
		'uploader'       : 'Scripts/uploadify/uploadify.swf',
		'script'         : 'Scripts/uploadify/freeFileReview/uploadify.php',
		'checkScript'    : 'Scripts/uploadify/check.php',
		'cancelImg'      : 'images/uploadify/cancel.png',
		'folder'         : 'upload/files/FreeFileReview',
		'sizeLimit'		 : fileSizeLimit,
		'multi'          : true,
		'fileDesc'       : 'Select Files (.jpg,.jpeg,.pdf,.psd,.ai,.zip,.sit,.sitx,.tiff,.png,.xls,.xlsx,.txt,.csv,.doc,.docx)',
		'fileExt'        : '*.jpg;*.jpeg;*.pdf;*.psd;*.ai;*.zip;*.sit;*.sitx;*.tiff;*.png;*.xls;*.xlsx;*.txt;*.csv;*.doc;*.docx;',
		'queueSizeLimit' : 3,
		onAllComplete    : function(){
			// required fields have been approved && files have been uploaded/completed SO execute submit function for form
			document.form1.submit();
		}
	});

});
// END Uploadify Script   

