	var itemID;
	var helpcategoryid;
	var formName;
	var formField;
	var languageId;

	function edit(strHelpcategoryid,frmName,frmField,langId) {
		var agt = navigator.userAgent.toLowerCase();
		if(agt.indexOf("safari") != -1) {
			alert('FCKedior does not work with Safari\n\nFor more information see http://www.fckeditor.net/safari');		
		} else {
			/*formName    = frmName;
			formField   = frmField;
			languageId  = langId;
			helpcategoryid = strHelpcategoryid;
			makeRequest('Help.php', 'helpcategoryid='+helpcategoryid +'&action=getHelp', 'loadContent');*/
			
			var strText = document.getElementById('help-text').innerHTML;
			setHelpText(strText);
		}
	}
	/* Added By rajesh for edit title*/
	
	function clearText()
	{
		var helpTitleTd = document.getElementById('help_title');
			helpTitleTd.innerHTML = '';
		var helpTextDiv = document.getElementById('help-text');
			helpTextDiv.innerHTML = '';	
		
		var targetLayer = document.getElementById('help');
		var fckObj = document.getElementById('FCKeditor');
		if (fckObj)
		{
			targetLayer.removeChild(fckObj);
		}

		/*	var img = document.createElement("IMG");
				img.src = "/images/ajax-loader(2).gif";
			helpTextDiv.appendChild(img);*/
	}
	function getHelpText(strHelpcategoryid,frmName,frmField,alignment)
	{
		
		clearText();
		//hideContentLayer('toolbar');
	    //hideContentLayer('toolbartitle');
		
		formName    = frmName;
		formField   = frmField;
		helpcategoryid = strHelpcategoryid;
		//alert(helpcategoryid);   
		//hlp_1
		//overlay('hlp_'+helpcategoryid, 'helpDiv');
		overlay('hlp_'+helpcategoryid, 'helpDiv',alignment);
	
		makeRequest('Help.php', 'helpcategoryid='+strHelpcategoryid+'&frmName='+formName+'&frmField='+formField+'&action=getHelp', 'replaceContent');
		showContentLayer('helpDiv');
		
		//showContentLayer('toolbarSaveTitle');				
		//showContentLayer('toolbar');
		//showContentLayer('toolbarTitle');
		//showContentLayer('toolbarSaveTitle');

		//hideContentLayer('toolbarSave');

	}
	
	
	function setEditorValue(instanceName, text ) {  
		document.ajaxform.FCKeditor1.value = text;
	}  


	function showContentValue() {
		//return FCKeditorAPI.GetInstance('FCKeditor1').GetXHTML(true);
		return document.getElementById('FCKeditor').value;
	}


	function hideContentLayer(layerID) { 
		var someLayer = document.getElementById(layerID);
		someLayer.style.display = 'none';
		if($("_hvrShm") && layerID == 'helpDiv')
		{
			$("_hvrShm").style.visibility = 'hidden';
		}
	}
	function showContentLayer(layerID) {
		var someLayer = document.getElementById(layerID);
		someLayer.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 {

		}
	}
	
	function urlencode(s) 
	{
		s = encodeURIComponent(s);
		return s.replace(/~/g,'%7E').replace(/%20/g,'+');
	}
	
     function makeRequest(url, parameters, passType) {
        //alert(url);
		//alert(parameters);
		//alert(passType);
		
		var http_request = false;
		replaceContentInLayer ('help-text','Loading...');
		http_request = new Ajax.Request(url,{
	  	
			contentType:'application/x-www-form-urlencoded',
			encoding:'UTF-8',
			method:'post',
			parameters:parameters,
			onFailure: alertContents,
			onComplete: function (originalRequest){
			var strText = originalRequest.responseText;
		
		    //var mySplitResult = hasQueryString3.split("pageFlag=");
           //var mySplitResultfirst=mySplitResult[1];

			 var strTextsplit = strText.split("~");
			 var formfield  =strTextsplit[0];
			 var helptext=strTextsplit[1];
			 var headertext=strTextsplit[2];
			  //alert($headertext);		
				
				//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 (strText == '') 
				{
					//do something ... anything you like ... 
					//someMsg = document.createTextNode('.');
					//document.getElementById('story').appendChild(someMsg); 
				} 
				else 
				{
					
					//alert(passType);
					
					//if (showLink)
					//{
						//showContentLayer('toolbar');
						//showContentLayer('toolbarTitle');
					//}
					
					//if(passType == 'loadContent') {
						
						//setHelpText(helptext);
						//setHelpTitle(headertext);
					//} 
						//alert(passType);

					   if (passType == 'replaceContent') {
						
						var helpTitle = document.getElementById('help_title');
						
						if(headertext !=''){
						  //helpTitle.innerHTML = '<strong>'+decodeURIComponent(unescape(headertext))+'</strong>';
						  helpTitle.innerHTML = decodeURIComponent(unescape(headertext));
						}
						
						else{
							
							      helpTitle.innerHTML = formfield;
						   }
						    
							
							replaceContentInLayer('help-text', decodeURIComponent(unescape(helptext)));
						    //need a reference point for these new layers?
					        showContentLayer('help-text');
						
					} else {
					
						alert('Error: No action has been specified for the call to the widget');
					
					}
				}
			}
		});
    }
	function submitFCKform() {

		var txtContent = showContentValue();
		if(txtContent.indexOf('<div id="help-text">') != 0) {
			//txtContent = '<div id="help-text">'+ txtContent +'</div>';
			//txtContent = '<div id="help-text">'+ txtContent +'</div>';
		}
		txtContent = escape(txtContent);
		replaceContentInLayer ('help-text', 'Saving...');
		showContentLayer('help-text');
		showContentLayer('toolbarTitle');
		
		makeRequest('Help.php', 'action=update&helpcategoryid='+helpcategoryid+'&FCKeditor1='+encodeURIComponent(txtContent), 'replaceContent');		

		var targetLayer = document.getElementById('help');
		var fckObj = document.getElementById('FCKeditor');
		if (fckObj)
		{
			targetLayer.removeChild(fckObj);
		}

		//showContentLayer('toolbar');				
		hideContentLayer('toolbarSave');
		showContentLayer('toolbar');
		
	}

	
	function cancelFCKform() {
		//return to the default state
		// window.location = 'Help.php?itemID='+itemID+'&templateID=people';
		//makeRequest('Help.php', 'helpcategoryid='+helpcategoryid +'&action=getHelp', 'replaceContent');
		makeRequest('Help.php', 'action=getHelp&helpcategoryid='+helpcategoryid,'replaceContent');		

		//makeRequest('Help.php', 'frmName='+formName+'&frmField='+formField+'&action=getHelp', 'replaceContent');
		//showContentLayer('toolbar');				
		hideContentLayer('toolbarSave');
		clearText();
	    showContentLayer('toolbar');
		showContentLayer('toolbarTitle');
	}
	function submitFCKformTitle(){

		
		var txtContent = showContentValue();
		//alert(txtContent);
		if(txtContent.indexOf('<div id="help-text">') != 0) {
			//txtContent = '<div id="help-text">'+ txtContent +'</div>';
			//txtContent = '<div id="help-text">'+ txtContent +'</div>';
		}
		txtContent = escape(txtContent);
		replaceContentInLayer ('help_title', 'Saving...');
		showContentLayer('help_title');
		
		makeRequest('Help.php', 'action=updateTitle&helpcategoryid='+helpcategoryid+'&FCKeditor1='+encodeURIComponent(txtContent), 'replaceContent');		

		var targetLayer = document.getElementById('help_title');
		var fckObj = document.getElementById('FCKeditor');
		if (fckObj)
		{
			targetLayer.removeChild(fckObj);
		}

						
		hideContentLayer('toolbarTitle');
		hideContentLayer('toolbarSaveTitle');
		showContentLayer('toolbar');
		showContentLayer('toolbarTitle');
		showContentLayer('help-text');
		
		
	}

	function cancelFCKformTitle() {
		//return to the default state
		// window.location = 'Help.php?itemID='+itemID+'&templateID=people';
		//makeRequest('Help.php', 'helpcategoryid='+helpcategoryid +'&action=getHelp', 'replaceContent');
		
		makeRequest('Help.php', 'action=getHelp&helpcategoryid='+helpcategoryid,'replaceContent');		

		//makeRequest('Help.php', 'frmName='+formName+'&frmField='+formField+'&action=getHelp', 'replaceContent');
		//showContentLayer('toolbar');				
		hideContentLayer('toolbarSaveTitle');
		clearText();
	    showContentLayer('toolbar');
		showContentLayer('toolbarTitle');
	
	}

	function setHelpText(strText)
	{
		/*var helpTitle = document.getElementById('help_title');
		helpTitle.innerHTML = '<strong>'+formField+'</strong>';*/
		
		//dont want anyone doing any special actions now, do we!
		hideContentLayer('toolbarTitle');
		hideContentLayer('toolbarSaveTitle');
		hideContentLayer('toolbar');
		showContentLayer('toolbarSave');				

		//need a reference point for these new layers?
		var targetLayer = document.getElementById('help');
		
		//create a msg layer
		var msgLayer = document.createElement('div');
		msgLayer.setAttribute('id', 'msgLayer');
		
		//stick the msg layer before the first child of the story layer
		//this is above where the story-content layer exists				
		targetLayer.insertBefore(msgLayer, targetLayer.firstChild);

		//create some text for our msg layer
		//var txt = document.createTextNode('Loading WYSIWYG editor...');
		//document.getElementById('msgLayer').appendChild(txt); 				
		//document.getElementById('msgLayer').innerHTML = 'Loading WYSIWYG editor...';

		//create a textarea layer
		var textarea = document.createElement('textarea');
		textarea.setAttribute('id', 'FCKeditor');
		textarea.setAttribute('name', 'FCKeditor');
		textarea.setAttribute('rows', '10');
		textarea.setAttribute('cols', '22');
		textarea.setAttribute('className', 'help_text_area');
		textarea.setAttribute('class', 'help_text_area');
		//textarea.setAttribute('style','height:202px; background-color:#86C542');

		// someSubmitButton create a submit button
		
		//create a cancel button
		

		//where we gonna put the textarea and the buttons?
		targetLayer.appendChild(textarea);
		textarea.value = strText;		

		/*********************************** uncomment below lines to use FCKEditor ********************/	
		//create fckeditor
		//oFCKeditor = new FCKeditor('FCKeditor1');
		//oFCKeditor.BasePath	= '' ;
		//oFCKeditor.ReplaceTextarea();
		/**********************************************************************************************/

		//now hide the original text layer
		hideContentLayer('help-text');
		
		//hide the loading msg info
		hideContentLayer('msgLayer');
	}

function editTitle(strHelpcategoryid,frmName,frmField,langId) {
		var agt = navigator.userAgent.toLowerCase();
		if(agt.indexOf("safari") != -1) {
			alert('FCKedior does not work with Safari\n\nFor more information see http://www.fckeditor.net/safari');		
		} else {
			/*formName    = frmName;
			formField   = frmField;
			languageId  = langId;
			helpcategoryid = strHelpcategoryid;
			makeRequest('Help.php', 'helpcategoryid='+helpcategoryid +'&action=getHelp', 'loadContent');*/
			
			var strTitle = document.getElementById('help_title').innerHTML;
			
			setHelpTitle(strTitle);
		}
	}

function setHelpTitle(strText)
	{
		var helpTitle = document.getElementById('help_title');
		helpTitle.innerHTML = strText;
		
		//dont want anyone doing any special actions now, do we!
		hideContentLayer('toolbar');
		hideContentLayer('toolbarTitle');
		showContentLayer('toolbarSaveTitle');				

		//need a reference point for these new layers?
		var targetLayer = document.getElementById('help_title');
		
		//create a msg layer
		var msgLayer = document.createElement('div');
		msgLayer.setAttribute('id', 'msgLayer');
		
		//stick the msg layer before the first child of the story layer
		//this is above where the story-content layer exists				
		targetLayer.insertBefore(msgLayer, targetLayer.firstChild);

		//create some text for our msg layer
		//var txt = document.createTextNode('Loading WYSIWYG editor...');
		//document.getElementById('msgLayer').appendChild(txt); 				
		//document.getElementById('msgLayer').innerHTML = 'Loading WYSIWYG editor...';

		//create a textarea layer
		var textarea = document.createElement('textarea');
		textarea.setAttribute('id', 'FCKeditor');
		textarea.setAttribute('name', 'FCKeditor');
		textarea.setAttribute('rows', '10');
		textarea.setAttribute('cols', '22');
		textarea.setAttribute('className', 'help_text_area');
		textarea.setAttribute('class', 'help_text_area');
		//textarea.setAttribute('style','height:202px; background-color:#86C542');

		// someSubmitButton create a submit button
		
		//create a cancel button
		

		//where we gonna put the textarea and the buttons?
		targetLayer.appendChild(textarea);
		textarea.value = strText;		

		/*********************************** uncomment below lines to use FCKEditor ********************/	
		//create fckeditor
		//oFCKeditor = new FCKeditor('FCKeditor1');
		//oFCKeditor.BasePath	= '' ;
		//oFCKeditor.ReplaceTextarea();
		/**********************************************************************************************/

		//now hide the original text layer
		hideContentLayer('help-text');
		
		//hide the loading msg info
		hideContentLayer('msgLayer');
	}

/*End By rajesh for edit title*/

