/**
 *
 * Copyright (c) 2007, RightNow Technologies, Inc
 *
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 * -    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * -    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 * -    Neither the name of the RightNow Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

var faq_ans_url_addon = "/ps_embedded_adp_elink.php?p_faqid=" ; 
var search_term = "" ;
var search_correction = "" ;
var faq_source = "" ;
var temp = "";
var prev_next_indicator = false ;
var config = new RNTConfig() ;
var faqreaderid = 0;

var RNTFeed = {
	readers: null,
	rnt_ids: 0,
	callBack :  null,
			
	onloadCallback:function (call){
		RNTFeed.callBack = call;
	},
	init: function (){
	 if(RNTFeed.callBack)
		RNTFeed.callBack();
	},
	
	getReader :function(){
	 	var id = RNTFeed.rnt_ids++;
		var reader = new RNTReader();
		reader.id = id;
		
		if (!this.readers) { 
 			RNTFeed.readers = new Object(); 
 		}
		RNTFeed.readers[id] = reader;
		return reader;
	},
	
	getRSS:function(id){
		var feed = RNTFeed.readers[id];
		if(feed){
			feed.search();
		}
	},
	
	next:function(id){
		var open_faq_id = document.getElementById("open_faq_id") ;
		var open_faq_no = document.getElementById("open_faq_no") ;

		if(open_faq_id != null && open_faq_no != null)
		{
			if(open_faq_id.value != "" && open_faq_no.value != "")
			{
				blockAns(open_faq_no.value ,open_faq_id.value ) ;
			}
		}


		
		feed = RNTFeed.readers[id];
		feed.next();
	},
	prev:function(id){

		var open_faq_id = document.getElementById("open_faq_id") ;
		var open_faq_no = document.getElementById("open_faq_no") ;

		if(open_faq_id != null && open_faq_no != null)
		{
			if(open_faq_id.value != "" && open_faq_no.value != "")
			{
				blockAns(open_faq_no.value ,open_faq_id.value ) ;
			}
		}

		feed = RNTFeed.readers[id];
		feed.prev();
	},
	
	getRelated:function(id, searchTerms){
		var feed = RNTFeed.readers[id];
		if(feed.searchbox=='on'){
			feed.form.input.value = searchTerms;
		}
		feed.query = searchTerms;
		feed.getRSS();
	}

};

RNTFeed.div = function(clazz, id){
	var divElement = document.createElement("div");
	if(clazz){
		divElement.className = clazz;
	}
	if(id){
		divElement.id = id;
	}
	return divElement;
}


RNTFeed.table = function(space, pad, clazz){
	var element = document.createElement("table");
	element.setAttribute("cellSpacing", space?space:0);
	element.setAttribute("cellPadding", pad?pad:0);
	if(clazz){
		element.className = clazz
	}
	return element;
}



RNTFeed.row = function(table, n, clazz){
	var row = table.insertRow(-1);
	for(var i= 0; i < n;i++){
		RNTFeed.cell(row, clazz);
	}
	return row;
}

RNTFeed.cell = function(row, clazz){
	var cell= row.insertCell(-1);
	if(clazz)
	{
		cell.className = clazz
	}
	return cell;
}



RNTFeed.createButton = function(value, clazz, title){

	var input = document.createElement("input");
	input.type = "submit";
	input.value = value;
	input.title = title;
	input.name = value;
	
	if(clazz){
		input.className = clazz;
	}
	return input;
}

RNTFeed.createAnchor= function(id,value, clazz, title, href){
	var span = document.createElement("span") ;
	span.id = id ;
	if(clazz){
		span.className = clazz;
	}
		
	var anchor = document.createElement("a");
	anchor.href = href;
	anchor.title = title ;
	anchor.appendChild(document.createTextNode(value)) ;
	span.appendChild(anchor) ;
	
	return span ;	
}

RNTFeed.createInput = function(value){
	var input = document.createElement("input");
	input.setAttribute("autoComplete","on");
	input.type = "text";
	if(value)
		input.value = value;
	return input;
}

RNTFeed.createDiv = function(clazz, id){
	var div = document.createElement("div");
	if(clazz){
		div.className = clazz
	}
	if(id){
		div.id = id;
	}
	return div;
}

RNTFeed.createIMG = function(src){
	var img = document.createElement("img");
	if(src){
		img.src = src ;
	}
	return img;
}

RNTFeed.createForm = function(clazz, id){
	var form = document.createElement("form");
	form.className = clazz
	if(id){
		form.id = id;
	}
	return form;
}

RNTFeed.SearchForm = function (root, id, query){
	var form = RNTFeed.createForm("searchform", "searchform");
	form.action = "javascript:RNTFeed.getRSS("+id+")";
		
	this.searchButton = RNTFeed.createButton("Search", "searchButton", "RSS Search");
	this.searchButton.title = "RSS Search";
	
	this.input = RNTFeed.createInput(query);
	this.input.name = "q";
	var t = RNTFeed.table(0,0,"searcformtable"); 
	RNTFeed.appendChild(form, t);
	var r = RNTFeed.row(t, 0);
	var input = RNTFeed.cell(r, "searchinput");
	var search = RNTFeed.cell(r, "searchbutton");
	RNTFeed.appendChild(input, this.input);
	RNTFeed.appendChild(search, this.searchButton);
	RNTFeed.appendChild(root, form);
	
}


RNTFeed.NavigationForm = function (root, id){
	var prevNextDiv = RNTFeed.createDiv("PrevNext","PrevNext") ;
	var t = RNTFeed.table(0,2,"navigationtable");
	var r = RNTFeed.row(t, 0);
	var prev = RNTFeed.cell(r, "prev_Button");
	var seperator = RNTFeed.cell(r, "seperator");
	var next = RNTFeed.cell(r, "next_Button");
	
	//this.prevButton = RNTFeed.createAnchor("PrevLink","&lt;&lt;&nbsp;Prev", "anchor", "Previous Page","javascript:RNTFeed.prev(faqreaderid)");
	//this.nextButton = RNTFeed.createAnchor("NextLink","See More&nbsp;&gt;&gt;", "anchor", "See More","javascript:RNTFeed.next(faqreaderid)");
	this.prevButton = RNTFeed.createAnchor("PrevLink","&lt;&lt;&nbsp;Prev", "anchor", "Previous Page","javascript:RNTFeed.prev(faqreaderid)");
	this.nextButton = RNTFeed.createAnchor("NextLink","Next&nbsp;&gt;&gt;", "anchor", "Next Page","javascript:RNTFeed.next(faqreaderid)");
		
	RNTFeed.appendChild(prevNextDiv, t);
	RNTFeed.appendChild(prev, this.prevButton);
	RNTFeed.appendChild(next, this.nextButton);	
	
	this.navigation = RNTFeed.div("navigation", "navigation");
   		
   	RNTFeed.appendChild(this.navigation, prevNextDiv);
   	RNTFeed.appendChild(root, this.navigation);
   	
}


RNTFeed.appendChild = function(root,child){
	root.appendChild(child)
	return child
};


RNTFeed.RNT_ajaxCall = function(url, id, page_next){
 	var handler = RNTFeed.readers[id];
	Ajax.Responders.register({
   		onException:handler.handleException,
		onCreate: function(request) {
			handler.timeoutId = window.setTimeout(function() {
				if (request.transport.readyState==1 || 
					request.transport.readyState==2	|| 
					request.transport.readyState==3) {
					request.transport.abort();
				
					handler.handleTimeout();
					
				}
			}, handler.TIMEOUT);
				
		},
		onComplete: function(request) {
			window.clearTimeout(handler.timeoutId);
		},
		onException:handler.handleException
	});
		
	function process(response){
		if (response.readyState == 4 && response.status == 200)
		{
			if (response.responseText != null){  
				if(page_next == 1){		
         				RNT_processChannel(handler, response.responseText, false);  
					}else{
						handler.page = 1;
						RNT_processChannel(handler, response.responseText, true);  
				}
			}else{
// 				handler.status = 'Error';
//				handler.errorMessage = "Failed to receive RSS feed from the server.";
				handler.handleFailure() ;
			}
		}else{
			
//			handler.status = 'ERROR';
//			handler.errorMessage = 	"Error code " + response.status + " received: " + response.statusText;
			handler.handleFailure() ;
		}	
		handler.onFeedReady();
	}
 	new Ajax.Request(url, {method:'get', onSuccess:process, onFailure:handler.handleFailure, onException:handler.handleException});
};


RNTFeed.JSONCall = function(url, id, page_next){
	var handler = RNTFeed.readers[id];
    var head = document.getElementsByTagName("head").item(0);
    var script = document.createElement("script");
    RNTFeed.readers[id].onCompleteJSON = function (channel) {
    
    	if (Prototype.Browser.Gecko){ //IE crashes: A cleaner solution to be provided. 
 			head.removeChild(script);
 		}
   		if(page_next == 1)		
          	handler.channel.item = handler.channel.item.concat(channel.item);			
 		else
        	handler.channel = channel;
		handler.onFeedReady(); 
		return true;
	 }

	// this is the same dirty patch for pages using ajax and integrating with FAQ widget.
	// Instead of receiving the pure JSON object we receive the XML as JSON.
    RNTFeed.readers[id].onCompleteJSONXML = function (response) {
    	if (Prototype.Browser.Gecko){ //IE crashes: A cleaner solution to be provided. 
 			head.removeChild(script);
 		}

		if (response.readyState == 4 && response.status == 200)
		{
			if (response.responseText != null){  
				if(page_next == 1){		
						RNT_processChannel(handler, response.responseText, false);  
					}else{
						handler.page = 1;
						RNT_processChannel(handler, response.responseText, true);  
				}
			}else{
				handler.status = 'ERROR';
				handler.errorMessage = "Failed to receive RSS feed from the server.";
			}
			handler.onFeedReady();
		}
		else
		{
			handler.handleFailure() ;
		}
	 }

    script.setAttribute("type", "text/javascript");
	
	// this is the same dirty patch for pages using ajax and integrating with FAQ widget.
	// Instead of receiving the pure JSON object we receive the XML as JSON.
	if((faq_source != null) && (faq_source == 'ENDECA'  || faq_source == 'MARITZ'))
	{
	    script.setAttribute("src", url+"&callback=RNTFeed.readers["+id+"].onCompleteJSON");
	}
	else
	{
		script.setAttribute("src", url+"&callback=RNTFeed.readers["+id+"].onCompleteJSONXML");
	}

    head.appendChild(script);
 };


function RNTReader(){
    this.uri =  'opensearch.php?';
    this.status= 'SUCCESS';
    this.errorMessage=  null;
    this.searchbox= 'on';
    this.navigation= 'on';
    this.pagesize=  50;
    this.page=  1;
    this.query=  "";
    this.channel=  null;
    this.format=  'xml';
    this.proxy=  null;
    this.TIMEOUT= 20000;
    this.timeoutId=  null;
	this.root=  null;
   
 }
 
RNTReader.prototype.setQuery = function(parm){
  	var q = this.getQuery("q");
    if (typeof parm != 'undefined' && parm != ""){
		this.query = parm;
		if(this.searchbox=='on')
 			this.form.input.value = parm;
	}else if (this.form && this.form.input.value != ""){
		this.query = this.form.input.value;
    }else if(q != null){
   	 	this.query = q;
   	 	if(this.searchbox=='on')
 			this.form.input.value = q;
    }		    
		    
 };
 
     
RNTReader.prototype.search = function(parm){
  	this.setQuery(parm);
    this.getRSS();
		    
 };
    
    
RNTReader.prototype.render = function(divTag){
	this.root =  document.getElementById(divTag);
	
	
 	if(this.searchbox=='on'){
 		this.form = new RNTFeed.SearchForm(this.root, this.id, this.query);
 	}
 		
 	this.correction = RNTFeed.div("correction", "correction");
 	RNTFeed.appendChild(this.root, this.correction);
 		
 	this.related = RNTFeed.div("related", "related");
 	RNTFeed.appendChild(this.root, this.related);
 		
 	this.topics = RNTFeed.div("topics", "topics");
 	RNTFeed.appendChild(this.root, this.topics);
 		
 	this.feedContent = RNTFeed.div("feedContent", "feedContent");
 	RNTFeed.appendChild(this.root, this.feedContent);
 		
 	this.navigationForm = new RNTFeed.NavigationForm(this.root, this.id);
 	this.navigationForm.navigation.style.display="none";
 		
 };
    


RNTReader.prototype.getQuery =  function(name){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   	var regexS = "[\\?&]"+name+"=([^&#]*)";
   	var regex = new RegExp(regexS);
   	var results = regex.exec(window.location.href);
   	if( results == null )
   	    return null;
  	else   
  		return results[1];
 };
 
 
RNTReader.prototype.getRSS = function(){
  	this.status= 'SUCCESS';
  	var url = this.uri;
 	
 //retrive the faq_source
	faq_source = /faq_source=([A-Z]{1,10})/.exec(url)[1] ;

	if(faq_source == null)
	{
		faq_source = /faq_source=([a-z]{1,10})/.exec(url)[1] ;
	}

  	var ln = url.length;
  
  	if(url.charAt(ln-1)== '?' || url.charAt(ln-1)== '&' )
  		url += 'startIndex='+0+'&count='+this.pagesize;
  	else
  		url += '&startIndex='+0+'&count='+this.pagesize;
  		
	if(this.query != null && this.query != "")
                url += '&q='+escape(this.query);

  	if(this.format == "json" || this.proxy == null){
  		this.page = 1;
  		
		// format should be passed only when the faq_source is ENDECA.  
		// This is dirty patch to take care of pages using ajax and integrating with FAQ
		if((faq_source != null) && (faq_source == 'ENDECA' || faq_source == 'MARITZ'))
		{
			url += '&format=json';
		}
		
  		RNTFeed.JSONCall(url, this.id, 0);
  	}else{
  		if(this.proxy){
  			url = this.proxy+"?url="+escape(url);
  		}
  		RNTFeed.RNT_ajaxCall(url, this.id, 0);
  	}
};

  
RNTReader.prototype.next = function(){
	this.page++;
 	var pStart = (this.page-1)*this.pagesize;
 		
 	if(pStart >= this.channel.item.length){
		var url = this.uri;
 		var ln = url.length;
		
 		if(url.charAt(ln-1)== '?' || url.charAt(ln-1)== '&' )
 			url += 'startIndex='+pStart+'&count='+this.pagesize;
 		else
 			url += '&startIndex='+pStart+'&count='+this.pagesize;
 		
		if(search_term.length != 0) ;
                {
                        url += '&q='+search_term ;
                }	
 		
 		if(this.format == "json" || this.proxy == null){
			// format should be passed only when the faq_source is ENDECA. 
			// This is dirty patch to take care of pages using ajax and integrating with FAQ
			if((faq_source != null) && (faq_source == 'ENDECA'  || faq_source == 'MARITZ'))
			{
				url += '&format=json';
			}
 			RNTFeed.JSONCall(url, this.id, 1);
 		}else{
 			if(this.proxy){
 				url = this.proxy+"?url="+escape(url);
 			}
 			RNTFeed.RNT_ajaxCall(url,  this.id, 1);
 		}
	}else{
 		this.onFeedReady();
 	}
};
   
RNTReader.prototype.prev = function(){
   	this.page--;
   	this.onFeedReady();
};
   
RNTReader.prototype.trimStr = function(str){
  if(str == null)
   	return null;
  return str.replace(/^\s*|\s*$/g,'');
};


RNTReader.prototype.getRelated= function(searchTerms){
	if(this.searchbox=='on'){
		tthis.form.input.value = searchTerms;
	}else{
		this.query = searchTerms;
	}
	this.getRSS();
};
 
	 	
	 	
RNTReader.prototype.onFeedReady = function(){
		
	var RSS  = this.channel;

	this.correction.style.display="none";
   	this.related.style.display="none";
   	this.topics.style.display="none";
   	
	if ((typeof RSS == 'undefined' ||  RSS == null) || 
		((typeof RSS.Query == 'undefined' || RSS.Query == null || RSS.Query.length==0) 
		&& (typeof RSS.topic == 'undefined' || RSS.topic == null|| RSS.topic.length==0) 
		&& (typeof RSS.item == 'undefined' || RSS.item == null || RSS.item.length==0)) ){
		document.getElementById("topics").style.visibility='hidden';
		
		this.feedContent.innerHTML = '<div id="faq" ><div id="question">' + 
									 '<div id="noresults" class="Noresults">There are no FAQs for your query. Please try another search.</div>' 
									 '</div>/div>';
		return;
	}
	
	if(this.status == 'ERROR'){
		this.feedContent.innerHTML = this.errorMessage;
	 	return;
	}
	
// determine the search term and if it is correction
	if (typeof RSS.Query != 'undefined' && RSS.Query != null && RSS.Query.length != 0){	
		for (var i = 0; i < RSS.Query.length; i++){
			var query = RSS.Query[i];
			if(query.role == "request"){
				search_term = query.searchTerms ;
			} 
			else if(query.role == "correction"){
				search_correction = query.searchTerms ;
			} 			
		}
	}

	this.feedContent.innerHTML = "";

	if (typeof RSS.item != 'undefined' && RSS.item != null && RSS.item.length != 0){
		var faq_ans_url = RSS.item[0].link ;
		faq_ans_url = faq_ans_url.replace(/http:\/\//,"https://") ;
		faq_ans_url = faq_ans_url.substr(0,faq_ans_url.lastIndexOf("/")) + faq_ans_url_addon;	

		var pStart = (this.page-1)*this.pagesize;
		var pEnd = this.page*this.pagesize;
		var counter = 0 ;
		var tempStr = "" ;
		var style_trans_iframe = "trans_iframe" ;
		var style_PrevNext = "PrevNext" ;
		var style_dotted_img = "dotted_img" ;
		
		if(pEnd > RSS.item.length)
			pEnd  = RSS.item.length;
			
		
		if(faq_source == 'ENDECA' || faq_source == 'endeca'  || faq_source == 'MARITZ')
		{
			tempStr = '<div id="faq" ><div id="question">' ;
			style_trans_iframe = "trans_iframe" ;
			style_PrevNext = "PrevNext" ;		
			style_dotted_img = "dotted_img" ;
		}
		else if(faq_source == 'CMAX' || faq_source == 'cmax'){
			tempStr  = '' ;
			tempStr += '<div id="faq" ><div id="question_cmax">' ;
			style_trans_iframe = "trans_iframe_cmax" ;
			style_PrevNext = "PrevNext_cmax" ;		
			style_dotted_img = "dotted_img_cmax" ;
			if(document.getElementById('PrevNext') != null)
			{
				document.getElementById('PrevNext').className = "PrevNext_cmax" ;
			}
		}
		else
		{
			tempStr  = '' ;
			tempStr += "<div class=\"Regular_text\" > <span class=\"Regular_text\">If you are looking for more information, please try our site search.</span> </div> " ;
			tempStr += '<div id="faq" ><div id="question">' ;
			style_trans_iframe = "trans_iframe" ;
			style_PrevNext = "PrevNext" ;		
			style_dotted_img = "dotted_img" ;
		}


		var itemStr = '<input type="hidden" id="faqContentURL" value="' + faq_ans_url + '">' + 
					"<input type=hidden id=activated_card_set value=''>" +
					"<input type=hidden id='search_term' value='" + search_term + "'>" +
					"<input type=hidden id='faq_source' value='" + faq_source + "'>" +
					"<input type=hidden id='prev_next_indicator' value='" + prev_next_indicator + "'>" +
					"<input type=hidden id='open_faq_id' value=''>" +
					"<input type=hidden id='open_faq_no' value=''>" +
					"<input type=hidden id=no_of_sub_cards value=''>"	  +
					"<input type=hidden id=activated_faq_set value=''>" +
					"<input type=hidden id=links_size value='0'>" +
					"<input type=hidden id=faqs_size value='5'>" +
					"<input type=hidden id=is_embedded_trans value='false'>" +
					"<input type=hidden id=no_embedded_trans_cards value='0'>" +
					"<input type=hidden id=faq_value value='FAQ'>" +
					"<input type=hidden id=nodefaultfaq value='notdefaultfaq'>" +
					'<input type="hidden" id="transactionsStatus" value="notransactions">' +
					'<input type="hidden" id="total_faq" value="'+ RSS.totalResults +'">' +					
					'<input type="hidden" id="pStart" value="'+ pStart +'">' +
					'<input type="hidden" id="pEnd" value="'+ pEnd +'">' +
					tempStr ;
					

		for (var i = pStart; i < pEnd; i++)
		{
			var item = RSS.item[i];
		
			var i_link = this.trimStr(item.link)
			var i_title = this.trimStr(item.title);

			var faq_id = p_faqid=/[0-9]{1,4}/.exec(i_link); 	


			if(i_link != null && i_link != ""){


				itemStr += '<div id="showAns' + i + '" class="faq_outer_div">\n' ;
       			itemStr += '<div class="faq_inner_div">\n' ;
       			itemStr += '<span class="plus_gif" onClick="showAns(\'' + i + '\',\'' + faq_id + '\')">\n' ;
				itemStr += '<img src="' + config.getImagePath() + 'img_plus.gif" alt="Show Answer">\n' ;
				itemStr += '</span>\n' ;
				itemStr += '<span class="Normal" style="font:normal 11px \'arial\';color:#333333;" >' +  i_title + '</span>\n' ;
				itemStr += '</div>\n' ;
				itemStr += '<div id="FAQdottedgif' + counter + '">\n' ;
				itemStr += '<TABLE cellpadding=0 cellspacing=0 border=0> <TR>\n' ;
				itemStr += '<TD><img src="' + config.getImagePath() + 'img_dottedline_graybkgd.gif" class="' + style_dotted_img + '" /></TD>\n' ;
				itemStr += '</TR></TABLE>\n' ;
				itemStr += '</div>\n' ;
				itemStr += '</div>\n'  ;
				
     			itemStr += '<div id="blockAns' + i + '" class="show_firstfaq_outer_div">\n' ;
       			itemStr += '<div class="faq_inner_div">\n' ;
       			itemStr += '<span class="minus_gif" onClick="blockAns(\'' + i + '\',\'' + faq_id + '\')">\n' ;
				itemStr += '<img src="' + config.getImagePath() + 'img_minus.gif" alt="Hide Answer">\n' ;
				itemStr += '</span>\n' ;
				itemStr += '<span class="trans_desc">' + i_title + '</span>\n' ;
				itemStr += '</div>\n' ;
				itemStr += '<div id="faq_ans_div">\n' ;
				itemStr += '<iframe id="iframe' + i + '" src="' + config.getImagePath() + 'clear.gif" class="' + style_trans_iframe + '" frameborder="0"  marginwidth="0" marginheight="0"></iframe>\n' ;
				itemStr += '</div>\n' ;
				itemStr += '</div>\n'  ;
				counter++ ;
			}
		}
		itemStr += '<input type="hidden" id="total_faq_page" value="'+ counter +'">';
		itemStr += '</div></div>';
		
		//we could also check if itemsPerPage <= pagesize
		if(pEnd <  RSS.item.length || pEnd < RSS.totalResults ){ 
			if(this.navigation=='on'){
   				this.navigationForm.navigation.style.display="block";
			}
   		
//   		this.navigationForm.nextButton.disabled = false;
   			//document.getElementById("NextLink").innerHTML = '<A  title="See More" href="javascript:RNTFeed.next(faqreaderid)" style="FONT-SIZE: 11px; LINE-HEIGHT: 13px; FONT-FAMILY: Arial;  color: #88750D; text-decoration: none;padding-left:14px;" >See More</A>' ;
   			document.getElementById("NextLink").innerHTML = '<A  title="Next Page" href="javascript:RNTFeed.next(faqreaderid)">Next</A><FONT COLOR=blue font-weight=bold>&nbsp;&gt;&gt;</FONT>' ;
		
   		}
		else //if not this pagination
		{
			//document.getElementById("NextLink").innerHTML = "<FONT COLOR=#88750D font-family=Arial>See More</FONT>" ;
			//document.getElementById("NextLink").innerHTML = '<DIV style="FONT-SIZE: 11px; LINE-HEIGHT: 13px; FONT-FAMILY: Arial;  color: #88750D; text-decoration: none; padding-left:14px;" >See More</DIV>' ;
			document.getElementById("NextLink").innerHTML = "<FONT COLOR=#6E6E6E font-weight=bold>Next&nbsp;&gt;&gt;</FONT>" ;
  		}
	
		if(this.page > 1){
		    //document.getElementById("PrevLink").innerHTML = '<A  title="Previous Page" href="javascript:RNTFeed.prev(faqreaderid)" style="FONT-SIZE: 11px; LINE-HEIGHT: 13px; FONT-FAMILY: Arial;  color: #88750D; text-decoration: none; padding-left:13px;" >+</A>' ;
   			document.getElementById("PrevLink").innerHTML = '<FONT COLOR=blue font-weight=bold>&nbsp;&nbsp;&nbsp;&lt;&lt;&nbsp;</FONT><A  title="Previous Page" href="javascript:RNTFeed.prev(faqreaderid)">Prev</A><FONT  COLOR=#000000 font-weight=bold >&nbsp;&nbsp;|&nbsp;&nbsp;</FONT>' ;
		}
		else {
			//document.getElementById("PrevLink").innerHTML = '<DIV style="FONT-SIZE: 11px; LINE-HEIGHT: 13px; FONT-FAMILY: Arial;  color: #88750D; text-decoration: none; padding-left:13px;" >+</DIV>' ;
			document.getElementById("PrevLink").innerHTML = "&nbsp;&nbsp;&nbsp;<FONT  COLOR=#6E6E6E font-weight=bold >&lt;&lt;&nbsp;Prev</FONT><FONT  COLOR=#000000 font-weight=bold >&nbsp;&nbsp;|&nbsp;&nbsp;</FONT>" ;
		}
//		itemStr += "<textarea rows='5' cols='80'>" + temp + "</textarea>" ; 
		this.feedContent.innerHTML += itemStr;				
	}else{
		this.navigationForm.navigation.style.display="none";
		this.navigationForm.nextButton.disabled = true;
   		this.navigationForm.prevButton.disabled= true;
   		this.feedContent.innerHTML = '' +
									 '<div id="faq" ><div id="question">' + 
									 '<div id="noresults" class="Noresults">There are no FAQs for your query. Please try another search.</div>' 
									 '</div>/div>';
   	}
	
	postFAQLoad() ;
};


RNTReader.prototype.handleFailure = function(o){
	this.status = 'ERROR';
	this.errorMessage = "<div id='errortext' class='error_text'><B>We're Sorry...</B><br>We're unable to retrieve FAQ content at this time. We apologize for this inconvenience. Close the window and try again, or <A title='Contact Us' HREF='javascript:popContactUs()'  > Contact Us</A> for immediate assistance.</div>";	
	this.feedContent.innerHTML = this.errorMessage;
};

RNTReader.prototype.handleException = function(o, exception){
   	this.status = 'ERROR';
	this.errorMessage = "<div id='errortext' class='error_text'><B>We're Sorry...</B><br>We're unable to retrieve FAQ content at this time. We apologize for this inconvenience. Close the window and try again, or <A title='Contact Us' HREF='javascript:popContactUs()'  > Contact Us</A> for immediate assistance.</div>";
	this.feedContent.innerHTML = this.errorMessage;
};


RNTReader.prototype.handleTimeout = function(){
   	this.status = 'ERROR';
	this.errorMessage = "Call to server didn't return. Make sure you have appropriate timeout set";
	this.feedContent.innerHTML = this.errorMessage;
};
   
var newwindow;
function popContactUs()
{
	newwindow=window.open(config.getContactusURI(),'_blank');
}

// Comment out due to conflict with HotelCheckinCal.js in FFRF
//window.onload = RNTFeed.init; 


function RNT_processChannel(handler, rss, newSearch){

	var channel = null;
//	Added by Vimal
	var rssDom;
	try //Internet Explorer
  	{
 	 	rssDom=new ActiveXObject("Microsoft.XMLDOM");
 	 	rssDom.async=false;
  		rssDom.loadXML(rss);
  	}
	catch(e)
  	{
  		try //Firefox, Mozilla, Opera, etc.
    	{
   			parser=new DOMParser();
		    rssDom=parser.parseFromString(rss,"text/xml");
    	}
  		catch(e) {alert(e.message)}
  	}
	
	if(newSearch)
		handler.channel = new RNT_Channel(rssDom);

	var itemList = rssDom.getElementsByTagName("item");
	for (var i = 0; i < itemList.length; i++)
	{
		var item = new RNT_Item(itemList[i]);
		handler.channel.item.push(item);
	}


	handler.channel.totalResults =  RNT_elementValue(rssDom, 'opensearch:totalResults') ; 
	if (typeof handler.channel.totalResults == 'undefined' || handler.channel.totalResults == null || handler.channel.totalResults == "")
	{
		handler.channel.totalResults =  RNT_elementValue(rssDom, 'totalResults') ; 
	}

	handler.channel.startIndex =  RNT_elementValue(rssDom, 'opensearch:startIndex') ; 
	if (typeof handler.channel.startIndex == 'undefined' || handler.channel.startIndex == null || handler.channel.startIndex == "")
	{
		handler.channel.startIndex =  RNT_elementValue(rssDom, 'startIndex') ; 
	}

	handler.channel.itemsPerPage =  RNT_elementValue(rssDom, 'opensearch:itemsPerPage') ; 
	if (typeof handler.channel.itemsPerPage == 'undefined' || handler.channel.itemsPerPage == null || handler.channel.itemsPerPage == "")
	{
		handler.channel.itemsPerPage =  RNT_elementValue(rssDom, 'itemsPerPage') ; 
	}
}  
  
function RNT_Channel(rssDom)
{
	// alert("RNT_Channel");
	var cElement = rssDom.getElementsByTagName("channel")[0];

	this.Query = new Array();
	this.topic = new Array();
	
	var queryList = null;
	//Firefox bug:https://bugzilla.mozilla.org/show_bug.cgi?id=206053

	queryList = cElement.getElementsByTagName("opensearch:Query");	
	if (typeof queryList == 'undefined' || queryList == null || queryList.length == 0)
	{
		queryList = cElement.getElementsByTagName("Query");	
	}

	for (var i = 0; i < queryList.length; i++)
	{
		var query = new RNT_Query(queryList[i]);
		this.Query.push(query);
	}
	
	//items
	this.item = new Array();
	
}


//if tag is defined returns the value of the element in dom.
//else it returns the value of element
function RNT_elementValue(dom, tag)
{
	if (dom == null || (typeof dom == 'undefined'))
	{
		return null;
	}

	if (typeof tag == 'undefined' ) 
	{
		element = dom;
	}
	else   
	{
		element = dom.getElementsByTagName(tag)[0];
	}

	if(element == null || (typeof element == 'undefined'))
	{
		return null;
	}
	else
	{
		if(element.childNodes.length > 0)
		{
			return 	element.childNodes[0].nodeValue;
		}
		else
		{
			return "";
		}
	}
}

function RNT_getAttr(element, attribute)
{
	if(element == null)
		return null;
	else
		return element.getAttribute(attribute);
}


function RNT_Item(element)
{
	//All elements of an item are optional, however at least one of title or description must be present.
	this.title       = RNT_elementValue(element, 'title');
	this.link        = RNT_elementValue(element, 'link');
}

//OpenSearch element
function RNT_Query(element)
{
	this.role       = RNT_getAttr(element, "role");
    this.title      = RNT_getAttr(element, "title");
    this.searchTerms= RNT_getAttr(element, "searchTerms");
}
