/* standard small functions */
function $m(quem){
	return document.getElementById(quem)
}

function addEvent(obj, evType, fn){
	// elcio.com.br/crossbrowser
	if (obj.addEventListener)
	obj.addEventListener(evType, fn, true)
	if (obj.attachEvent)
	obj.attachEvent("on"+evType, fn)
}
function removeEvent( obj, type, fn ) {
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, fn );
	} else {
		obj.removeEventListener( type, fn, false ); }
}

function removeElement(action_id, divNum) {
//alert(action_id +'  '+ divNum);
	var d = $m(action_id);
	var olddiv = $m(divNum);
	d.removeChild(olddiv);
}

/* THE UPLOAD FUNCTION */
function youliveAjaxUpload(form, url_action, id_element, html_error_http, action_id, temp_div){
	
	//testing if 'form' is a html object or a id string
	
	form = typeof(form)=="string"?$m(form):form;

	var erro="";
	if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n";}
	else if(form.nodeName!="FORM"){ erro += "The form of 1st parameter its not a form.\n";}
	//if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n";}
	if(erro.length>0) {
		alert("Error in call youliveAjaxUpload:\n" + erro);
		return;
	}
	var carregou = function() {

		removeEvent( $m('youlive-temp'),"load", carregou);
		//removeElement(action_id, temp_div);

		var cross = "javascript: ";
		cross += "window.parent.$m('" + temp_div + "').innerHTML = document.body.innerHTML; void(0); "; 
		$m('youlive-temp').src = cross;
		$m(action_id).className = 'show';

	}

	addEvent( $m('youlive-temp'),"load", carregou)

	//properties of form
	form.setAttribute("target","youlive-temp");
	//form.setAttribute("target","self");
	form.setAttribute("action",url_action);
	form.setAttribute("method","post");
	form.setAttribute("enctype","multipart/form-data");
	form.setAttribute("encoding","multipart/form-data");
	//submit
	form.submit();
}