//=====================================================================//
//Author: Mark Qian <markqian@hotmail.com>                             //
//WWW: http://www.coolshare.com/                                       //
//Copyright (c) 2006, Mark Qian                                        //
//                                                                     //
//You must contact Mark Qian to get a permission of use                //
//in case you want to make any use of the codes except viewing it     //
//on Mark's site.                                                      //
//=====================================================================//
function FrameCommunicator() {
  this.id = ""+(idCount++);
  this.type = "Frame";
  var pp = this;
  
  ///////////////////////////////////////////////////////////////////
  // Pattern "Template Method" is used here: implement its own concrete
  // "send" here. 
  /////////////////////////////////////////////////////////////////////
  this.send = function () {
    try {
      this.preSend();
      this.state = 2;
      var hid = "hiddenFrame_"+this.id; 
      var fid = "hiddenForm_"+this.id;
	  var fs=top.document.getElementsByTagName("frameset")[0];
	  this.hFrame = top.document.getElementById(hid);
	  
	  if (this.hFrame==null) {
	    var row = fs.rows;
	    this.hFrame = insertDomNode(this.w.document, this.w.document.getElementsByTagName('body')[0], "iframe", {"id":hid, "name":hid, "style":"display:none"}, "beforeEnd");    
	    fs.rows = fs.rows+",0";
	  }
	  
	  var para = (this.params==null)?("cId="+this.id+"&trans="+this.type):(this.params+"&cId="+this.id+"&trans="+this.type);
	      var url = this.url;
		  if (url.indexOf("?")>-1)
		    url += "&"+para;
		  else
		    url += "?"+para;
		 
	  var fHTML = ""   
	  if (this.form) {
	      fHTML = this.form.innerHTML;
	  }
		  this.hForm = this.w.document.getElementById(fid);
      if (this.hForm==null) {
        this.hForm = insertDomNode(this.w.document, this.w.document.getElementsByTagName('body')[0], "form", {"id":fid, "name":fid, "style":"display:none"}, "beforeEnd");
      }
      this.hForm = this.w.document.getElementById(fid);
      this.hForm.target = hid;
      this.hForm.action = this.url;
      this.hForm.method = "post";

	  this.hForm.innerHTML = fHTML+this.convertParaToInputs(url); 
      
      this.hForm.submit();
      this.postSend();

	}catch (err) {
	  this.state = 0;
	  var msg = err.description;
	  if (browser && browser=="Internet Explorer") {
	    msg+= "The item \"Navigate sub-frames across different domains\" \nunder your security option is required to be on";
	  }
	  alert(msg);
	}
  }
  
  
  
	  ///////////////// Wrapping the concrete callback ///////////
	  //
	  // I don't invoke the real callback function, "handler",
	  // directly when hidden iframe onloading. Instead, I wrapped
	  // the "handler" with a wrapper, "process" so
	  // that I can do some system level tasks before and
	  // after the "handler" is carried out. For example,
	  // I can update the state of the Communicator here
	  // when the Communicator is in my pool. See the invoking 
	  // in issue_1_select2.jsp
	  //
	  ////////////////////////////////////////////////////////////
  this.process = (function() {
           var res = function (w) {
	       // do the preprocess here...
	         pp.handler();
	       // do any clear up here...
	         pp.state = 0;
	         if (w)
  	           w.location.replace('about:blank');
	      }
	      return res;
	  })();
}



///////////////////////////////////////////////////////////////
//
// Subclass Communicator
//
//////////////////////////////////////////////////////////////
FrameCommunicator.prototype = new Communicator();


