// JavaScript Document
function ajaxSelectItem(selectedForm,id)
{
	    if (window.XMLHttpRequest)
    	  {
    	  xhttp=new window.XMLHttpRequest()
    	  }
    	  else
    	  {
    	  xhttp=new ActiveXObject("Microsoft.XMLHTTP")
    	  }
		  xhttp.onreadystatechange=function()
			{
			if(xhttp.readyState==4)
			  {
				if (xhttp.status == 200)
					{
					  if (document.getElementById('loader'+id) != null) document.getElementById('loader'+id).style.visibility='hidden';
					  document.getElementById("ofertaSelectata").innerHTML=xhttp.responseText;
					}
				else { alert("there was a problem processing:"+xhttp.statusText); }
			  }
			}
		  if (document.getElementById('loader'+id) != null) document.getElementById('loader'+id).style.visibility='visible';
		  var rnd982g = Math.random();
		  var url= "getItemSelect.php";
		  var params = getForm(selectedForm);
    	  xhttp.open("GET",url+"?"+params+'&rnd982g='+rnd982g,true);
    	  xhttp.send(null);
}

function ajaxExecuteCommand(command,id,lang)
{
	if (window.XMLHttpRequest)
    	  {
    	  xhttp=new window.XMLHttpRequest()
    	  }
    	  else
    	  {
    	  xhttp=new ActiveXObject("Microsoft.XMLHTTP")
    	  }
		  xhttp.onreadystatechange=function()
			{
			if(xhttp.readyState==4)
			  {
				if (xhttp.status == 200)
					{
					  document.getElementById("ofertaSelectata").innerHTML=xhttp.responseText;
					}
				else { alert("there was a problem processing:"+xhttp.statusText); }
			  }
			}
		  var rnd982g = Math.random();
		  var url= "listFunctions.php";
		  var params = "command="+command+"&id="+id+"&lang="+lang;
    	  xhttp.open("GET",url+"?"+params+'&rnd982g='+rnd982g,true);
    	  xhttp.send(null);
}
function ajaxMainButtons(selectedForm,command)
{
	var rnd982g = Math.random();
	if (command=="view")
		  {
		  var url= "mainForm.php";
  		  var params = getForm(selectedForm)+"&command="+command;
    	  window.open(url+"?"+params+'&rnd982g='+rnd982g);
		  }
	if (command=="send")
		{
		if (window.XMLHttpRequest)
    	  {
    	  xhttp=new window.XMLHttpRequest()
    	  }
    	  else
    	  {
    	  xhttp=new ActiveXObject("Microsoft.XMLHTTP")
    	  }
		  xhttp.onreadystatechange=function()
			{
			if(xhttp.readyState==4)
			  {
				if (xhttp.status == 200)
					{
					  document.getElementById("centerContent").innerHTML=xhttp.responseText;
					}
				else { alert("there was a problem processing:"+xhttp.statusText); }
			  }
			}
		  var url= "/tools/sendmail.php";
		  var params = getForm(selectedForm)+"&command="+command;
    	  xhttp.open("GET",url+"?"+params+'&rnd982g='+rnd982g,true);
    	  xhttp.send(null);
		}
}

function getForm(fobj) {
 var str = "";
 var ft = "";
 var fv = "";
 var fn = "";
 var els = "";
 for(var i = 0;i < fobj.elements.length;i++) {
  els = fobj.elements[i];
  ft = els.title;
  fv = els.value;
  fn = els.name;
 switch(els.type) {
  case "text":
  case "hidden":
  case "password":
  case "textarea":
  // is it a required field?
  if(encodeURI(ft) == "required" && encodeURI(fv).length < 1) {
    alert('\''+fn+'\' is a required field, please complete.');
    els.focus();
    return false;
  }
  str += fn + "=" + encodeURI(fv) + "&";
  break; 
  case "checkbox":
  case "radio":
   if(els.checked) str += fn + "=" + encodeURI(fv) + "&";
  break;
  case "select-one":
    str += fn + "=" + els.options[els.selectedIndex].value + "&";
  break;
  } // switch
 } // for
 str = str.substr(0,(str.length - 1));
 return str;
}