var ulWindow;
function openUpload() {
	//set the automatic refresh variable
	$('quote_upload').value = 1;
	ulWindow = window.open('/quote/upload.php','upload','width=390,height=580,resizable=yes');
}



function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}



var o_url = '/quote/quote.php';
//var e_url = encodeURIComponent(o_url);
var e_url = o_url;

Event.observe( window, 'load', function() {
	//alert ('Called load event for window');
	try {
		Event.observe( 'quote', 'submit', function(e) { // e is the current event handler
			// If we get here, the data ought to be valid...  but we will check it anyway..  events are not guarenteed to happen in any particular order.
			//alert('Called submitdata on [' + this.name + ']');
			// Make sure all fields are filled out correctly if they are filled out, and make sure all required fields are filled out.
			
			// Make sure form validates...
			var callback_save = $('quote').ValidatorOptions.callback;
			$('quote').ValidatorOptions.callback = 'Prototype.emptyFunction();';
			$('quote').ValidatorValidate();
			$('quote').ValidatorOptions.callback = callback_save;
			if (!$('quote').ValidatorIsValid) {
				Event.stop(e);
				return false;
			}

			// Now, we submit the data back to the server...
			var formdata = $('quote').serialize(true);
				
			new Ajax.Request(e_url, {
				method: 'POST',
				parameters: formdata,
				onFailure: function(transport) {
					// Something went wrong with the request.  Inform user that the request failed and go nowhere.
					alert ('The request failed.  You can try again now or try again later.  We are sorry for the inconvenience. \n[' + transport.status + ']');
					// Do this if their is an error
					// Make the button active onthe form again.
					$('quote').enable();
					// Stop the call,the proces and everything.  Just stay on this page.
					return true;
				}
			});
			// Otherwise, let the form go through to the thank you page.  That page only displays the thank you.
			//  Now, backbutton brings you back to the page you filled your form out on.
		
			$('quote').enable();
			Event.stop(e);
			return false;
		});	
	} catch(err) {}
});

function update_current_files() {
		new Ajax.Updater('currentfiles_partial', '/quote/current_files.php', {
			method: 'POST'
		});
}

function delete_current_files(file) {
	new Ajax.Request('/quote/delete_file.php', {
		method: 'POST',
		parameters: {
			'filename':	file
		},
		onFailure: function(transport) {
			// Something went wrong with the request.  Inform user that the request failed and go nowhere.
			alert ('The request failed.  You can try again now or try again later.  We are sorry for the inconvenience. \n[' + transport.status + ']');
		}
	});
}