function window_open(open_url) {
	// launch popup window or alert if browser blocks request
	var foc = window.open(open_url, "new_window", "width=340,height=340,resizable=1");
	if( foc ) foc.focus();
	else alert("Your browser has blocked your request.\nPlease enable popup windows for this site.");
}

function ajaxFileUpload() {
		var upload_success = false;

		jQuery("#loading")
		.ajaxStart(function(){
			jQuery(this).show();
		})
		.ajaxComplete(function(){
			jQuery(this).hide();
		});

		jQuery.ajaxFileUpload
		(
			{
				url: cuBaseDir + '/wp-content/plugins/comment-image-uploader/scripts/doajaxfileupload.php',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							var item_link = data.file;
							jQuery("#image-preview").animate({width:"300",paddingTop:"15px",paddingRight:"15px",paddingLeft:"10px"}, 500);
							jQuery("#preview-image").html('<img src="/wp-content/plugins/comment-image-uploader/phpthumb/phpThumb.php?w=294&h=294&zc=C&ra=0&src=/wp-content/uploads/' + item_link + '" />');
							jQuery("#uploaded_files").html(item_link);
							jQuery("#choose-photo").html('Change Photo');
							jQuery("#fileToUpload").val('');

							add_img_to_comment(data.file);
						}
					}
				},
				error: function (data, status, e)
				{
					alert('Error: ' + e);
				}
			}
		)

		return false;

	}

function add_img_to_comment(img) {
	jQuery("#uploaded_comment_files").val("[img]" + img + "[/img]");
	return false;
}

/* added after the fact to upload image upon "Submit Comment" */
function upload_on_submit() {
	if ( jQuery('#fileToUpload').val() != '' ) {
		ajaxFileUpload();
		jQuery('#fileToUpload').bind("change", function(){ upload_on_submit(); });
	}
}

jQuery(document).ready(function() {
	jQuery('#fileToUpload').change(function () {
		upload_on_submit();
	});
});

