/**
* Calls the remote method to make a trade
* Uses Seam remoting
*/

var makingPrediction = false;

function makePrediction(higher, contractId) {
  if (!makingPrediction) {
    makingPrediction = true;
    var tradingInstant = Seam.Component.getInstance("tradingInstant");
    tradingInstant.makePrediction(higher, contractId, predictionMade);
  }
}

var okButtonText = "<a href='#' onclick='setTableRowToUpdate(this.parentNode.parentNode); okClicked(); return false;'>OK</a>";

function predictionMade(result) {
  alert(result);
  /*
  for(i=0; i<row.childNodes.length; i++) {    
    if(row.childNodes [i].className == "hidden") {      
      row.childNodes [i].innerHTML = result + " " + okButtonText;
      row.childNodes [i].className = "predictionResult"
    } else {
      row.childNodes [i].className = "hidden";        
    }
  }
  */
  
  makingPrediction = false;
}

function okClicked() {
  for(i=0; i<row.childNodes.length; i++) {    
    if(row.childNodes [i].className == "predictionResult") {      
      row.childNodes [i].className = "hidden"              
    } else {
      row.childNodes [i].className = "";        
    }
  }
}

var row;

function setTableRowToUpdate(rowToUpdate) {
  row = rowToUpdate;
}