/*
 *
 * Copyright (C) 2009 EmbedOne.
 * Contact: EmbedOne Software Information (info@embedone.com)
 *
 * Commercial Usage
 * Licensees holding valid EmbedOne Commercial licenses may use this file
 * in accordance with the EmbedOne Commercial License Agreement provided
 * with the Software or, alternatively, in accordance with the terms
 * contained in a written agreement between you and EmbedOne.
 *
 * GNU General Public License Usage
 * Alternatively, this file may be used under the terms of the GNU
 * General Public License version 3.0 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.  Please review the following information to
 * ensure the GNU General Public License version 3.0 requirements will be
 * met: http://www.gnu.org/copyleft/gpl.html.
 *
 * If you are unsure which license is appropriate for your use, please
 * contact the EmbedOne sales department at sales@embedone.com.
 *
 */

var objTxtRawJsonP = new oTxtRawJsonP();

// Creating an object with multiple constants
function oTxtRawJsonP(){
	this.iTitle = "<h1>Send a Custom Request</h1>";
	this.iSubNav ="<ul> "
					+"</ul>"
					;
	this.iContent = '<strong>Request</strong><br><textarea name="data_request" id="data_request" rows="10" cols="80"></textarea><br><br><strong>Response</strong><br><textarea name="data_result" id="data_result" rows="10" cols="80" readonly=true>';
	this.iActions = '<input name="send_request" type="submit" id="button" value="Submit Report" onclick="mSendCustomRequest();" /> ' 
					;
	this.iFooter = '<div id="copyright"> '
			+"<p>Copyright &copy; 2009 EmbedOne. All rights reserved.</p> "
			+"</div>"
			;
}

var vLastRawRequest=null;
function mSendCustomRequest(){
	// constructing the data
	
	// sending JSON request
	// vRpcCallback = false;
	var vObj = document.getElementById("data_request").value;
	vLastRawRequest = document.getElementById("data_request").value;
	mSetWrapper( numConstWrapperStateWaiting );
	mEmiRpcTimeout( "mSendCustomCallback(null)", vRpcTimeout );
	mSendJSONP( "mSendCustomCallback" ,vObj);
	vRpcId = vRpcId + 1;
}

function mSendCustomCallback(dResult){
	 if( dResult == null ){
		alert("Custom request TimedOut");
		mSetWrapper( numConstWrapperStateMain );
		return;
	}	
	
	// else we have the expected id, now its time to check the result
	// vRpcCallback = true;  // cancel timeout
	clearTimeout(vRpcCallTO);
	mSetWrapper( numConstWrapperStateMain );
	document.getElementById("data_result").value = mSimpleJSONStringify(dResult) ;	
}
