/**
 * Javascript library for loading Share Price data
 * (c) 2010 Harmonic New Media 
 **/

var ajaxURLRequest = location.protocol + "/sharePriceAjax.php";
var timeOutAjax = 10000;

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function isEmpty(elementValue)
{

	elementValue = trim(elementValue);


        if((elementValue == '') || (elementValue == null) || (elementValue == ' '))
	{

	   return true;

	}
	else
	{

	   return false;

	}


}


function displayData(eleID,eleValue)
{

        if(!isEmpty(eleValue) && !isEmpty(eleID))
        {
            if(document.getElementById(eleID)!=null)
            {
                document.getElementById(eleID).innerHTML = eleValue;
            }
        }
        else if(isEmpty(eleValue) && !isEmpty(eleID))
        {
            if(document.getElementById(eleID)!=null)
            {
                document.getElementById(eleID).innerHTML = "Not Available";
            }
        }
        else
        {
               $('.sharePriceUpdate').html("Not Available.");
        }
         

}

$(document).ready(function() {
	$.ajax({
	   type: "POST",
	   url: ajaxURLRequest,
	   cache:false,
	   timeout:timeOutAjax,
	   error: function(XMLHttpRequest, textStatus, errorThrown){	
			displayData(null,null);
	   },
	   success: function(msg){
	
			try {
	
				var dataObj = jQuery.parseJSON(msg);
					
					 if(dataObj!==null)
					 {
							for(x in dataObj)
							{
								displayData(x,dataObj[x]);
							}
	
					}
					else
					{ 
						displayData(null,null);
					}
			} catch(err)
			{
			   displayData(null,null);
			}
	
	   }
	
	 });

});

