var uploadsuccess=false;

function none() { }


function rand()
{
  return(Math.floor(Math.random()*10000+1));
}


function getById(id)
{
	return document.getElementById(id);
}


function uploader_init ()
{
        if(!uploadsuccess) uploader = new clUploadData('/ajax.php');
		
}

function uploader_go (id)
{
	uploader.upload(id);
}


var uploader;


function get_by_id(id)
{
	var itm = null;
	if (document.getElementById){
		itm = document.getElementById(id);
	}
	else if (document.all){
		itm = document.all[id];
	}
	else if (document.layers){
		itm = document.layers[id];
	}
	return itm;
}


function print_to_div(id, text)
{
	var d = get_by_id(id);
	if (d) {d.innerHTML = text;}
}


function clUploadData ( thesrc ) {
	//   
	this.src = thesrc;
	//    GET
	this.src += "?";
	//   - text/javascript
	this.type = "text/javascript";
	this.oldScript  = document.createElement("SCRIPT");
	this.oldScript.type = this.type;
	this.callId = rand();
	document.body.appendChild(this.oldScript);
	this.upload = function ( theparams ) {
		//    par1=val1&par2=val2&...
		var tParams = theparams || "";
		var newScript = document.createElement("SCRIPT");
		newScript.type = this.type;
		this.callId += 1;
		newScript.src  = this.src + "callid=" + String(this.callId) + "&" + tParams;
		// alert(newScript.src);
		document.body.replaceChild(newScript,this.oldScript);
		this.oldScript = newScript;
	}
	uploadsuccess=true;
}
