/*
 * Software Copyright
 * Copyright @Sept, 1998-2007 Warner/Chappell Music, Inc. All Rights Reserved.
 *
 * Use of this Software is governed by the terms of the end user License
 * Agreement,
 * if any, which accompanies or is included with this Software.
 *
 * This Software is the confidential and proprietary information of Warner/Chappell Music.
 * You shall not disclose such confidential information and shall use it only in
 * accordance with the terms of the License Agreement.
 *
 * EXCEPT FOR THE EXPRESS WARRANTIES STATED IN THE LICENSE AGREEMENT
 * WARNER/CHAPPELL MUSIC. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
 * WARNER/CHAPPELL MUSIC. SHALL NOT BE LIABLE FOR ANY SPECIAL, INDIRECT
 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE, TORT OR OTHERWISE, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE OR ITS DERIVATIVES.
 */


/**
* ajax.js
* @author Ajay Agrawal
* @version 1.0
*/


/**
  * This method is to send a AJAX request to specified URL and set data into a DIV container.
  * @param divid : This is required to set the response data into a DIV container
  * @param url : Servelet path or any valid file name where you want to send your request.
  * @param handleas : This specify that the requested data will be handle as per your handleas parameter. Value will be "text"
  */

/**
Changes for cache issue on IE6
 Problem description: After clear cache page was not loading  
 Changes on method: Add attribute sync true in case of IE6
**/
function getHTMLContentForDiv(divid,url,handleas){   
	var isSync  = false;
	var isIE6 =navigator.appVersion.indexOf("MSIE 6.0") != -1;
	if(isIE6){
	 isSync = true;
	}	
	dojo.xhrPost({
	   
		url: url,
		handleAs: handleas,
		mimetype:"text/html",
		sync: isSync,
		handle: function(data,args){
			if(typeof data == "error"){
				//console.warn("error!");
				//console.log(args);
			}else{
				if(args.xhr.status==200){
				handleReterivedData(divid,data);
				}				
			}
		}
	});
};

/**
  * This method is to set the response value to a Div container
  * @param divid : This is required to set the response data into a DIV container
  * @param data : This is the response data
  */
function handleReterivedData(divid,data) {	
	if(dojo.byId(divid)){		
		dojo.byId(divid).innerHTML = data;

	} else {
		console.log("Please provide a valid container id");
		return;
	}
}

/**
  * This method is to submit our form with the post method
  * @param divid : This is required to set the response data into a DIV container
  * @param url : Servelet path or any valid file name where you want to send your request.
  */
 function submitFormData(divid,url) {
		dojo.xhrPost ({
				// The page that parses the POST request
				url: url,
	   
				// Name of the Form we want to submit
				form: 'post-form',
	   
				// Loads this function if everything went ok
				load: function (data) {				
						handleReterivedData(divid,data);			
				},
				// Call this function if an error happened
				error: function (error) {
						//console.warn("error!");
						//console.log(args);
				}
	});
}
