var hlpcategoryidJS = "";
var headerTextJS = "";
function getContentHelpText(hlpcategoryid,frmName,frmField,alignment,headerText)
{	
		clearContentText();
		hideContentLayer(frmField);
		//hideContentLayer('getContentHelpText');
		hlpcategoryidJS = hlpcategoryid;
		headerTextJS = headerText;
		formName    = frmName;
		formField   = frmField;
		overlay('hlp_'+hlpcategoryid, 'help_text_comment',alignment);
		makeContentRequest('helptext.php', 'helpcategoryid='+hlpcategoryid+'&frmName='+formName+'&frmField='+formField+'&action=getHelp', 'replaceContent');
		//showContentLayer('finance_comment');
		//showContentLayer('toolbar');				
		//hideContentLayer('toolbarSave');

}

function saveHelpCommentsText(obj)
{
	formFieldtext =document.Help_content.help_content_text.value;

	//	txtContent = escape(formFieldtext);
	if(formFieldtext == "")
	{
		$('Content_help_menu').innerHTML = "  ";

	}
	else
	{
		$('Content_help_menu').innerHTML = formFieldtext;
	}
		formFields = formFieldtext;
		var ref_td = $('hlp_'+hlpcategoryidJS);
		//var numrows = 0;
		makeContentRequest('helptext.php', 'hlpcategoryid='+hlpcategoryidJS+'&frmField='+encodeURIComponent(formFieldtext)+'&headerText='+headerTextJS+'&Obj='+obj+'&action=saveContentText', 'replaceContent');
	
		hideContentLayer('help_text_comment');
		//alert(formFields)

}
	

		function clearContentText()
	{
			$('help_content_text').value ="";
	}


	function hideContentLayer(layerID) { 
		
		var someLayer = document.getElementById(layerID);
		someLayer.style.display = 'none';
		if($("_hvrShm") && layerID == 'help_text_comment')
		{
			$("_hvrShm").style.visibility = 'hidden';
		}
	}

		function urlencode(s) 
	{
		s = encodeURIComponent(s);
		return s.replace(/~/g,'%7E').replace(/%20/g,'+');
	}
	
	  function makeContentRequest(url, parameters, passType) {
        var http_request = false;
	    var URLText = SITE_HOST+"/"+url ;
		//replaceContentInLayer ('help_content_text','Loading...');
		http_request = new Ajax.Request(URLText,{
			contentType:'application/x-www-form-urlencoded',
			encoding:'UTF-8',
			method:'post',
			parameters:parameters,
			onFailure: alertContents,
			onComplete: function (originalRequest)
				{
				//alert(originalRequest.responseText)
				var strText = originalRequest.responseXML;
				
				var doc = strText.documentElement;
				var help = doc.getElementsByTagName('helps');
				var helptext = help[0].getElementsByTagName('helptext').item(0).firstChild.nodeValue;
				var headertext = help[0].getElementsByTagName('headertext').item(0).firstChild.nodeValue;
				var formfield = help[0].getElementsByTagName('formfield').item(0).firstChild.nodeValue;

				if (helptext != '' || helptext != 'NO_DATA' ) 
				{
					$('help_content_text').value = decodeURIComponent(helptext);
					$('update_107').style.display = "block";
					$('save_107').style.display = "none";
				} 
				else 
				{
					//$('help_content_text').value = "Please Add Help Content";
					$('update_107').style.display = "none";
					$('save_107').style.display = "block";
	
				}
			}
		});
    }

	function replaceContentInLayer(id,content){
		var someLayer = document.getElementById(id);
		someLayer.innerHTML = content;
		
	}

	function alertContents(http_request) {
		
		if (http_request.readyState == 4) {
			// everything is good, the response is received        
			if (http_request.status == 200) {
				return http_request.responseText;
			} else if(http_request.status == 500) {
				alert('500 Internal Server Error\nThe server encountered an unexpected condition which prevented it from fulfilling the request. ');
			} else if(http_request.status == 503) {
				alert('The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.');			
			} else if(http_request.status == 504) {
				alert('The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.	');		
			} else {
				//you can find more errors messages at:
				//http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
				alert('There was a problem with the request. Error code='+ http_request.status +'.');
			}
		} else {

		}
	}