// Replaces the character codes in str - match which character needs to be replaced with one from replaceArray.
function cnbc_strReplaceCharCodes (str, replaceArray)
{
    for (var i in replaceArray)
    {
        var replaceMap = replaceArray[i];

        for (var charCodeToReplace in replaceMap)
        {
            var stringToReplaceWith = replaceMap[charCodeToReplace];
            str = cnbc_replaceCharStr(str, charCodeToReplace,               
                    stringToReplaceWith);
        }
    }
    
    return str;
}

//replace the char code in a String with another string
function cnbc_replaceCharStr (str, charCodeToReplace, stringToReplaceWith) 
{
    var charToReplace = String.fromCharCode(charCodeToReplace);
    var index = str.indexOf(charToReplace);
    
    while (index >= 0) // match found
    {
        str = str.replace(charToReplace, stringToReplaceWith);        
        index = str.indexOf(charToReplace);
    }

    return str;
}


function cnbc_submit_commentsform(thisform, url)
{	
	var charReplaceArray = 
[
    {8217: "&rsquo;"},
	{8220: "&ldquo;"}, 
    {8221: "&rdquo;"},
	{34: "&quot;"},
	{39: "&#039"},
	{8218: "&sbquo;"},
	{8216: "&lsquo;"},
	{8222: "&bdquo;"}
	
];

		
	var cnbc_userComment =cnbc_strReplaceCharCodes(thisform.content.value, charReplaceArray);
	// show loader
    cnbc_showLoader('edit_submit','Submitting Comment', 'submit_btn');    
    //make flashproxy call   
    cnbc_com_cacheParams = cnbc_com_cacheParams +"&page="+ cnbc_com_futComid;    	     
    url = url+"?view=json&contentType="+thisform.contenttype.value+"&contentID="+thisform.contentid.value+"&commentText="+encodeURIComponent(cnbc_userComment)+"&partnerId="+cnbc_com_partnerid+"&authkey="+cnbc_readCookie('cnbcCommentsAuthKeyCookie')+"&cachebuster="+encodeURIComponent(cnbc_com_cacheParams)+"&location="+encodeURIComponent(window.location.href);
    document.getElementById("edit_but").style.display = "none";    
	getData_FlashProxy(url, "cnbc_SubmitResponseHandler");   
	return false;
}














