/** 
 * Function called onload and onclick ( input webCallRateButton class) 
 * that does the get request to our url and parses the result.
 */
function displayProductRate(){
	
    var sourceRegionId = document.getElementById("sourceRegion.id").value;
    var destinationRegionId = document.getElementById("destinationRegion.id").value;
    var productId = document.getElementById("product.id").value;
    var productAccessType = document.getElementById("productAccessType").value;
    
	$.ajax({
		   type: "GET",
		   url: "/productlist/viewProductRateEmpty.htm",
		   data: ({ "sourceRegion.id": sourceRegionId, "destinationRegion.id": destinationRegionId, "product.id": productId,"productAccessType": productAccessType }),
		   success: function(data){
				document.getElementById("productRateContainer").innerHTML=data
		   		},
		   error: function(data,options,error){
				document.getElementById("productRateContainer").innerHTML='Error Code '+data.status	
				}
		 });
}

function displayWeb2PhoneProductRate(){
	
    var sourceRegionId = document.getElementById("sourceRegion.id").value;
    var destinationRegionId = document.getElementById("web2PhoneDestinationRegion.id").value;
    var productId = document.getElementById("product.id").value;
    var productAccessType = document.getElementById("productAccessType").value;
    
	$.ajax({
		   type: "GET",
		   url: "/productlist/viewProductRateEmpty.htm",
		   data: ({ "sourceRegion.id": sourceRegionId, "destinationRegion.id": destinationRegionId, "product.id": productId,"productAccessType": productAccessType }),
		   success: function(data){
				document.getElementById("productRateContainer").innerHTML=data
		   		},
		   error: function(data,options,error){
				document.getElementById("productRateContainer").innerHTML='Error Code '+data.status	
				}
		 });
}

/** 
 * Function called onload and onclick ( input webCallRateButton class) 
 * that does the get request to our url and parses the result.
 */
function displaySmsProductRate(){
	
    var destinationRegionId = document.getElementById("sms.destinationRegion.id").value;
    
	$.ajax({
		   type: "GET",
		   url: "/eshop/product/viewSmsProductRateEmpty.htm",
		   data: ({ "destinationRegion.id": destinationRegionId }),
		   success: function(data){
				document.getElementById("smsRateContainer").innerHTML=data
		   		},
		   error: function(data,options,error){
				document.getElementById("smsRateContainer").innerHTML='Error Code '+data.status	
				}
		 });
}

/**
 * Makes a synchronous call to the server to obtain the escaped name. 
 * @param name the name to be escaed.
 * @returns the escaped name.
 */
function getAsyncEscapedName(name){
	var escapedName;
	$.ajax({
		   async: false,
		   type: "GET",
		   url: "/eshop/misc/viewEscapedNameEmpty.htm",
		   data: ({ "name": name}),
		   success: function(data){
			   escapedName = jQuery.trim(data);
		   }
		 });
	
	return escapedName;
}
