
// the function handles the validation for any form field
function vote_forward(id,s,d)
{
	var pigserverAddress = "catalog/function_forward.php";
  // 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 (id)
    {
      
      cache.push("id=" + id + "&s=" + s + "&d=" +d);
    }
    // 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();
		//message = document.getElementById("loading_pig");
		//message.innerHTML='<img src="image/ajax-loader.gif" style="margin-top:150px" />';
        // make a server request to validate the extracted data
        xmlHttp.open("POST", pigserverAddress, true);
        xmlHttp.setRequestHeader("Content-Type", 
                                 "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = handleRequestStateChangepig;
        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 handleRequestStateChangepig() 
{
  // 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
        readResponsepig();
      }
      catch(e)
 
      {
        // display error message
        displayError(e.toString());
      }
    }
    else
    {
      // display error message
      displayError(xmlHttp.statusText);
    }
  }
}

// read server's response 
function readResponsepig()
{
  // 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);

  xmlResponse = xmlHttp.responseText;
	  if(xmlResponse !=''){
	  alert(xmlResponse);
	    if(xmlResponse=='恭喜你投票成功'){
	     window.location.href = 'index.php';
		}
	  }else{
	  alert('nothing');
	  }
  // call validate() again, in case there are values left in the cache
  //setTimeout("validate_pig();", 500);
}

