
// the function handles the validation for any form field
function validate_phodel(url_d, previmg, reitem, simg, del_b, upload_b)
{
	var phodelserverAddress = url_d;
	previmg1 = document.getElementById(previmg);
	reitem1 = document.getElementById(reitem);
	del_b1 = del_b;
	upload_b1 = upload_b;
	simg1 = simg;	
	if(reitem1.value ==''){
		alert("nothing to del");
		//return true;
	}
  // only continue if xmlHttp isn't void
  if (xmlHttp)
  {
    // if we received non-null parameters, we add them to cache in the
    // form of the query string to be sent to the server for validation
    if (url_d)
    {
      // encode values for safely adding them to an HTTP request query string
      action = encodeURIComponent(url_d);
	  //modelist = mode;
      // add the values to the queue
	 
		   keywords = encodeURIComponent(document.getElementById(reitem).value);
		    poststr = "&reitem=" + keywords; 
		 
      cache.push("action=" + action + poststr);
    }
    // try to connect to the server
    try
    {
      // continue only if the XMLHttpRequest object isn't busy
      // and the cache is not empty
      if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) 
         && cache.length > 0)
      {
        // get a new set of parameters from the cache
        var cacheEntry = cache.shift();
		        // make a server request to validate the extracted data
        xmlHttp.open("POST", phodelserverAddress, true);
        xmlHttp.setRequestHeader("Content-Type", 
                                 "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = handleRequestStateChangephodel;
        xmlHttp.send(cacheEntry);
      }
    }
    catch (e)
    {
      // display an error when failing to connect to the server
      displayError(e.toString());
    }
  }
}

// function that handles the HTTP response
function handleRequestStateChangephodel() 
{
  // when readyState is 4, we read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // read the response from the server
        readResponsephodel();
      }
      catch(e)
 
      {
        // display error message
        displayError(e.toString());
      }
    }
    else
    {
      // display error message
      displayError(xmlHttp.statusText);
    }
  }
}

// read server's response 
function readResponsephodel()
{
  // retrieve the server's response 
  var response = xmlHttp.responseText;
  // server error?
  if (response.indexOf("ERRNO") >= 0 
      || response.indexOf("error:") >= 0
      || response.length == 0)
    throw(response.length == 0 ? "Server error." : response);

  var html = response; 
  //alert(html);
  //document.getElementById("loading_movienew").style.display="none";
  if(html=='ok'){
	if(simg1 !=''){
  previmg1.src=simg1;
	}
  // show the error or hide the error
  reitem1.value='';
  document.getElementById(del_b1).style.display="none";
  document.getElementById(upload_b1).style.display="inline";
  }  
  // call validate() again, in case there are values left in the cache
  //setTimeout("validate_phodel();", 500);
}

