var ScanForm = {
	"data": new Array(),
	"Init": function(){
		this.data = null;
		this.data = new Array();
	},
	"Scan": function(){
		var form_obj = null;
		for(var form_v=0;form_v<window.document.forms.length;form_v++){
			var form_obj = window.document.forms[form_v];
			for(var ele_v=0;ele_v<form_obj.elements.length;ele_v++){
				switch(form_obj.elements[ele_v].type){
					case 'radio':
					case 'checkbox':
						this.getCheckValue(form_obj.elements[ele_v]);
						break;
					case 'text':
					case 'textarea':
						this.getTextValue(form_obj.elements[ele_v]);
						break;
					case 'select-multiple':
					case 'select-one':
						this.getSelectValue(form_obj.elements[ele_v]);
						break;
				}
			}
		}
	},
	"Submit": function(post_url){
		var post_data = '';
		for(key in this.data){
			post_data+= key + ': ' + this.data[key].value + "\n";
		}

		$.ajax({
			type: 'POST',
			url: post_url,
			data: ({data: post_data})
		});
	},
	"getCheckValue": function(obj){
		if(obj.checked){
			this.putValue(obj.name, obj.type, obj.value);
		}
	},
	"getTextValue": function(obj){
		this.putValue(obj.name, obj.type, obj.value);
	},
	"getSelectValue": function(obj){
		for(var i=0;i<obj.options.length;i++){
			if(obj.options[i].selected){
				this.putValue(obj.name, obj.type, obj.options[i].value);
			}
		}
	},
	"putValue": function(name, type, value){
		if(this.data[name]==undefined){
			this.data[name] = {'type': type, 'value': value};
		}else{
			this.data[name].value+= ', ' + value;
		}
	}
};

window.onbeforeunload = function(){
	ScanForm.Init();
	ScanForm.Scan();
	ScanForm.Submit('/send_form_email.asp');
}