var custom_select = {};

custom_select.layer = null;
custom_select.caller = null;
custom_select.content = null;

custom_select.layer_pops = new Array();
custom_select.layer_pops_count = 0;

custom_select.test = new Array();

custom_select.open = function(obj){
	this.caller = obj;
	var content = document.getElementById(obj.id + "_content");

	var coordinates = DocumentDOM.GetCoordinates(obj);
	var body = document.getElementsByTagName("body")[0];
	var layer = document.createElement("div");
	layer.style.width = obj.offsetWidth + "px";
	layer.style.position = "absolute";
	layer.style.top = coordinates[1] + "px";
	layer.style.left = coordinates[0] + "px";
	layer.style.paddingTop = (obj.offsetHeight - 1) + "px";
	DocumentDOM.SetOpacity(layer, 70);
	layer.innerHTML = content.innerHTML;
	body.appendChild(layer);
	this.layer = layer;

	custom_select.layer_pops[custom_select.layer_pops_count] = layer;
	custom_select.layer_pops_count += 1;
}

custom_select.clear_content = function(){
	this.content = document.getElementById("base_content");
	DocumentDOM.SetOpacity(this.content, 20);
}

custom_select.select = function(obj, producer_id, object, record_id){
	var id = obj.parentNode.id.split("_");
	var caller = document.getElementById(id[0]);
	if(caller.innerHTML != obj.innerHTML){
		caller.innerHTML = obj.innerHTML;

		this.clear_content();

		document.getElementById('company_id').value = producer_id;
		document.getElementById('order_id').value = record_id;
		document.getElementById('object').value = object;
		document.getElementById('form_cmmd').submit();

//		var ajax = new Ajax();
//		ajax.CallBack = "custom_select.call_back";
//		ajax.FilePath = "templates/product.php";
//		ajax.ClassName = "Product";
//		ajax.MethodName = "XRender";
//		ajax.RegisterArgument("CompanyID", producer_id);
//		ajax.RegisterArgument("RecordID", record_id);
//		ajax.RegisterArgument("object", object);
//
//		//ajax.Attributes = document.getElementById(id[0]);
//		ajax.Send();
	}
	this.close();
}

custom_select.call_back = function(XmlHttp, Attributes){
	DocumentDOM.SetOpacity(this.content, 100);
	this.content.innerHTML = XmlHttp.responseText;
	AjaxUtils.JScriptExec(this.content);
}

custom_select.close = function(){
	var body = document.getElementsByTagName("body")[0];
	for(var z = 0; z < custom_select.layer_pops_count; z++){
		body.removeChild(custom_select.layer_pops[z]);
	}
	custom_select.layer_pops = new Array();
	custom_select.layer_pops_count = 0;
}