//window.onload = function () {
//	new Ajax.Autocompleter("order_owner", "autocomplete_choices", "admin/orders/search/", {});
//}


//function showCustomerHint() {
//	new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "/admin/orders/search", {});
//	new Ajax.Updater('customerHint', '/admin/orders/search', {
//  			parameters: { surname: $F('customer_surname') }
//	});
//}

//pridavani zbozi, uprava apod.
function showHint(str,controller)
{
	if (str.length==0)
	  { 
	  document.getElementById("txtHint").innerHTML="";
	  return;
	  }
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="/admin/"+controller+"/search";
	url=url+"/q/"+str;
	url=url+"/sid/"+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//porovnani zbozi
//function showGoods(id)
//{
//	if (str.length==0)
//	  { 
//	  document.getElementById("txtHint").innerHTML="";
//	  return;
//	  }
//	xmlHttp=GetXmlHttpObject();
//	if (xmlHttp==null)
//	  {
//	  alert ("Your browser does not support AJAX!");
//	  return;
//	  } 
//	var url="/goods/search";
//	url=url+"/q/"+id;
//	url=url+"/sid/"+Math.random();
//	xmlHttp.onreadystatechange=stateChanged;
//	xmlHttp.open("GET",url,true);
//	xmlHttp.send(null);
//}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	}
}

// predvyplneni formu
function fillForm(str,controller)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="/admin/"+controller+"/fill-form";
	url=url+"/q/"+str;
	url=url+"/sid/"+Math.random();
	xmlHttp.onreadystatechange=inputChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function inputChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 

			var response = xmlHttp.responseText;
			var responseArray = new Array();
			responseArray = response.split('#');
			
			if(document.goodsForm.goods_name)document.goodsForm.goods_name.value= responseArray[0];
			if(document.goodsForm.id_producer) document.goodsForm.id_producer.value= responseArray[1];
			if(document.goodsForm.id_category) document.goodsForm.id_category.value= responseArray[2];
			if(document.goodsForm.id_goods_type) document.goodsForm.id_goods_type.value= responseArray[3];
			if(document.goodsForm.basic_price) document.goodsForm.basic_price.value= responseArray[4];
			if(document.goodsForm.code) document.goodsForm.code.value= responseArray[5];
			if(document.goodsForm.prefill) document.goodsForm.prefill.value= responseArray[5];
			if(document.goodsForm.delivery_date) document.goodsForm.delivery_date.value= responseArray[6];
			if(document.goodsForm.id_description) document.goodsForm.id_description.value= responseArray[7];
			if(document.goodsForm.description_cs) {
				document.goodsForm.description_cs.value = responseArray[7];
				if(tinyMCE.getInstanceById('description_cs')) tinyMCE.getInstanceById('description_cs').getBody().innerHTML = responseArray[8];
			}
			if(document.goodsForm.description_en) {
				document.goodsForm.description_en.value = responseArray[8];
				if(tinyMCE.getInstanceById('description_en')) tinyMCE.getInstanceById('description_en').getBody().innerHTML = responseArray[9];
			}
	}
}

function fillFormCompare(id)
{
		new Ajax.Updater('compare_goods_select', '/goods/fill-form-compare/id/'+id, { method: 'get' });
}
 

function inputChangedCompare() 
{ 
	if (xmlHttp.readyState==4)
	{ 

			var response = xmlHttp.responseText;
			var responseSplit = new Array();
			responseSplit = response.split('#');
			
			document.goodsForm.id_goods.options.length = 0;
			
			for(var i = 0; i < responseSplit.length; i++){
				var split = new Array();
				split = responseSplit[i].split('$');
								
				document.goodsForm.id_goods.options[i] = new Option(split[1],split[0]);
			}
	}
}


function fillFormWizard(id,select)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="/goods/fill-form-wizard";
	url=url+"/id/"+id;
	url=url+"/sid/"+Math.random();
	xmlHttp.onreadystatechange=inputChangedWizard(select);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function inputChangedWizard(select) 
{ 
	if (xmlHttp.readyState==4)
	{ 

			var response = xmlHttp.responseText;
			var responseSplit = new Array();
			responseSplit = response.split('#');
			
			document.goodsForm.id_goods.select.length = 0;
			
			for(var i = 0; i < responseSplit.length; i++){
				var split = new Array();
				split = responseSplit[i].split('$');
								
				document.goodsForm.id_goods.options[i] = new Option(split[1],split[0]);
			}
	}
}