function $m(theVar){
	return document.getElementById(theVar)
}
function remove(theVar){
	var theParent = theVar.parentNode;
	theParent.removeChild(theVar);
}
function addEvent(obj, evType, fn){
	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 isWebKit(){
	return RegExp(" AppleWebKit/").test(navigator.userAgent);
}
function ajaxUpload(classtype,usertype,action,form,fullpath,relpath,html_show_loading,html_error_http){
//	var form = this.form;
	var userid=(usertype=='admin')?document.getElementById('aid').value:document.getElementById('uid').value;
	var file=(usertype=='admin')?'../common/ajax/imgupload.php?':'common/ajax/imgupload.php?';
//	var file="../common/ajax/imgupload.php?"
		url=file+"filename=filename"
		url=url+"&maxSize=9999999999"
		url=url+"&maxW=200"
		url=url+"&fullPath="+fullpath
		url=url+"&relPath="+relpath
		url=url+"&classtype="+classtype
		if(document.getElementById('whichtable')){
			url=url+"&whichtable="+document.getElementById('whichtable').value
			url=url+"&tableid="+document.getElementById('tableid').value
		}
		url=url+"&colorR=255"
		url=url+"&colorG=255"

		url=url+"&colorB=255"
		url=url+"&maxH=300"
		url_action = url
	if(classtype=='1') var id_element = 'upload_area_'+action;
	if(classtype=='2') var id_element = 'upload_area_thumbnail';
	if(classtype=='3') var id_element = 'upload_area_images';

	var detectWebKit = isWebKit();
	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.toLowerCase()!="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 ajaxUpload:\n" + erro);
		return;
	}
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id","ajax-temp");
	iframe.setAttribute("name","ajax-temp");
	iframe.setAttribute("width","0");
	iframe.setAttribute("height","0");
	iframe.setAttribute("border","0");
	iframe.setAttribute("style","width: 0; height: 0; border: none;");
	form.parentNode.appendChild(iframe);
	window.frames['ajax-temp'].name="ajax-temp";
	var doUpload = function(){
		removeEvent($m('ajax-temp'),"load", doUpload);
		if(document.getElementById('user_img')) var user_img = document.getElementById('user_img').value;
		var cross = "javascript: ";
		if(classtype=='1'){
			cross += "window.parent.$m('imgform_"+action+"').style.display='none'; window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
		}else{
			cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
		}
//		cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0); window.parent.$m('imgform').style.display='none';";
		if(document.getElementById('user_img')) updateimglist(action,userid,user_img,classtype);
		if(classtype=='2' || classtype=='3') updateimageview(relpath,classtype);

		$m(id_element).innerHTML = html_error_http;
		$m('ajax-temp').src = cross;
		if(detectWebKit){
        	remove($m('ajax-temp'));
        }else{
        	setTimeout(function(){ remove($m('ajax-temp'))}, 250);
        }
    }
	addEvent($m('ajax-temp'),"load", doUpload);
	form.setAttribute("target","ajax-temp");
	form.setAttribute("action",url_action);
	form.setAttribute("method","post");
	form.setAttribute("enctype","multipart/form-data");
	form.setAttribute("encoding","multipart/form-data");
	if(html_show_loading.length > 0){
		$m(id_element).innerHTML = html_show_loading;
	}
	form.submit();
}