var dosubmit = false;
var http = getHTTPObject(); // We create the HTTP Object
var statusDiv = null;
var isWorking = false;
var StatusField=null;
var EmploeeField = null;
var AppTypeField =null;
var PossibleFieldsHiddenField = null;
var ApptypeFieldTableDiv  =null;
var noBlanks=null;
var dataEmploees = null;
var initfield = null;

function handleStatus() {
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      var txtDocument = http.responseText;
      var dataArray = txtDocument.split( '$' );

      fillStatusSelect( StatusField, dataArray );
      document.body.style.cursor="";
        if(statusDiv){
          statusDiv.innerHTML='&nbsp;';
        }
      isWorking = false;
    }
  }
}


function makeStatusCall( page, appTypeid, Statusfield_id ){

  if (!isWorking && http) {

    document.body.style.cursor="wait";
    if(page.indexOf("=")>0){
    page = page + "&";
    }else{
    page = page + "?";
    }
    var url = page + "AppType=" + appTypeid;
    http.open("GET", url, true);
    http.onreadystatechange = handleStatus;
    isWorking = true;

    StatusField = document.getElementById(Statusfield_id);

    http.send(null);
  }
}






function fillStatusSelect(selobj,dataArray){
  var op = document.createElement("option");
  var tmp = null;
  var temparray=null;


  selobj.options.length = 0;

    tmp = op.cloneNode(true);
    tmp.appendChild(document.createTextNode("Όλες οι Καταστάσεις"));
    tmp.setAttribute("value", -1 );
    selobj.appendChild(tmp);

  for(i = 0;i < dataArray.length;i++)
  {
      temparray=dataArray[i].split("_");
      if(temparray[1]==null){continue;}
      if(trim(temparray[1]).length == 0 ) {continue;}
      tmp = op.cloneNode(true);
      tmp.appendChild(document.createTextNode(temparray[1]));
      tmp.setAttribute("value",temparray[0]);
      selobj.appendChild(tmp);
  }
}









function getHTTPObject() {

  var http_request = false;

  if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
          http_request.overrideMimeType('text/xml');
          // See note below about this line
      }
  } else if (window.ActiveXObject) { // IE
      try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) { alert('Παρουσιάστηκε σφάλμα!'); }
      }
  }

  if (!http_request) {
      alert('Cannot create an XMLHTTP instance');
      return false;
  }

  return http_request;
}


function trim(inputString) {
  if (typeof inputString != "string") return inputString;
    return inputString
      //clear leading spaces and empty lines
      .replace(/^(\s|\n|\r)*((.|\n|\r)*?)(\s|\n|\r)*$/g,"$2")

      //take consecutive spaces down to one
      .replace(/(\s(?!(\n|\r))(?=\s))+/g,"")

      //take consecutive lines breaks down to one
      .replace(/(\n|\r)+/g,"\n\r")

      //remove spacing at the beginning of a line
      .replace(/(\n|\r)\s/g,"$1")

      //remove spacing at the end of a line
      .replace(/\s(\n|\r)/g,"$1");

}








