/* -------------------------------------------------------------------------- */
/* Application Scripts */
/* -------------------------------------------------------------------------- */

function iframe_get(iFrameName) {  
	var IFrame = document.getElementById(iFrameName);
	if (!IFrame.contentWindow.document.body) return '';
	var content = IFrame.contentWindow.document.body.innerHTML;       
	return content;
}

function iframe_clear(id) {
	var obj = document.getElementById(id);
	if (obj.contentWindow.document.body) {
		obj.contentWindow.document.body.innerHTML='';
	}
}

function go(url) {
  window.location = url;
}

function upload_start() {
	$("#upload_file").hide();
	$("#upload_processing").show();
	$("#upload_form").submit();
	setTimeout("upload_wait();",1000);
}

function upload_wait() {
	content = iframe_get("upload_frame");
	if (!content) {
		setTimeout("upload_wait();", 200);
		return;
	}
	else iframe_clear("upload_frame");
	
	$("#upload_file").val("").show();
	$("#upload_processing").hide();
	
	upload_complete(content);
}

function upload_complete(content) {
	obj = eval('(' + content + ')');
	if (obj) {
		if (obj.result == 1) {
			$("#upload_result").html("<img src='" + obj.image.medium + "' />").show();
		}
		else {
			alert('Error: ' + obj.error);
		}
	}
	else {
		alert("Cannot process your file...");
	}
}