var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {

/*	var newOne = $("#browse").clone(true);
	$("#browse").addClass("hidden");
	newOne.removeAttr("id").removeAttr("type").removeAttr("name").removeAttr("style").removeAttr("class");
	$("#browse").after("<div class='fakefile'></div>");
	newOne.appendTo(".fakefile");
	var changeValue = function(){
		$(this).val() = newOne.val();	
	}
	$("#browse").change(function(){
		var newValue = $(this).val();
		newOne.val(newValue);
	});
	$("#browse").mouseout(function(){
		var newValue = $(this).val();
		newOne.val(newValue);
	});
	*/
 	if (!W3CDOM) return;
	$("form.applicationForm input.file").css({
		"filter":"alpha(opacity: 0)",
		"opacity": "0"
	});
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	//var image = document.createElement('img');
	//image.src='/resources/styles/images/buttons/browse.gif';
	//fakeFileUpload.appendChild(image);
		var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
	    	if(this.value != ""){
	    		$(".applicationForm #upload").removeClass("disabled");
		    	$(".applicationForm #upload").removeAttr("disabled");
		    	$(".applicationForm #upload").click(function(){
		    		$("#application-loader").show();
		    	});
	    	}
		}
	}

}
