var FaqSuggest = function(){
return {
template :'
',
uid :'',
options :{count:5,popupId:'',formId:'',fieldName:'subject',faqUid:'',requestPath:'/faqs_search_json.php',onSubmit:null,itemTitleLength:255,url:'/support/faq.html?'},
init :function(options){
if (options!=null){
for (var i in options){
if (options[i]!=null){
FaqSuggest.options[i] = options[i];
}
}
}
var FaqPopup = jQuery('#'+FaqSuggest.options.popupId);
if (FaqPopup.length==0) {
// need to create
jQuery('body').append(jQuery(''));
FaqPopup = jQuery('#'+FaqSuggest.options.popupId).html(FaqSuggest.template);
FaqPopup.find('#faq_popup_agree').click(function(){
if (jQuery(this).attr('checked')==true){
FaqPopup.find('#faq_popup_submit_link').show();
}else{
FaqPopup.find('#faq_popup_submit_link').hide();
}
});
FaqPopup.find("#faq_popup_submit_link>a[href$='#submit']").click(function(){
FaqSuggest.hidePopup();
jQuery('#'+FaqSuggest.options.formId).unbind().submit();
});
}
var obj = jQuery('#'+FaqSuggest.options.formId);
var params = {pager:{from:0,count:FaqSuggest.options.count}}
obj.submit(function(){
if (FaqSuggest.options.onSubmit!=null){
if (FaqSuggest.options.onSubmit(obj[0])==true){
FaqSuggest.getFaqItems(params);
}else{
return false;
}
}
return false;
});
},
loadBgLayer:function(){
if (jQuery('#backgroundblacklayer').length==0){
var div = jQuery('');
jQuery('body').append(div);
}else{
var div = jQuery('#backgroundblacklayer');
}
var pageSize = FaqSuggest.pageSize();
div.height(pageSize[1]);
div.width(pageSize[0]);
div.show();
},
showPopup :function(){
FaqSuggest.loadBgLayer();
var FaqPopup = jQuery('#'+FaqSuggest.options.popupId);
FaqPopup.show();
},
hidePopup :function(){
jQuery('#'+FaqSuggest.options.popupId).hide();
jQuery('#backgroundblacklayer').hide();
},
getFaqItems :function(params){
var query = jQuery('#'+FaqSuggest.options.formId).find(":input[name='"+FaqSuggest.options.fieldName+"']").val();
var pager_params = 'q='+query+'&f='+params.pager.from+'&c='+params.pager.count+'&l='+FaqSuggest.options.itemTitleLength;
jQuery.getJSON( FaqSuggest.options.requestPath+"?uid="+FaqSuggest.options.faqUid+"&c="+FaqSuggest.options.count+"&",
pager_params,
function(data){
if (data.pager.total>0){
//show popup
var FaqPopup = jQuery('#'+FaqSuggest.options.popupId);
FaqPopup.find('#faq_popup_total_items').html(data.pager.total);
if (data.pager.total>FaqSuggest.options.count){
FaqPopup.find('#faq_popup_pager').show();
if (data.pager.from==0){
FaqPopup.find("#faq_popup_pager>a[href='#prev']").hide();
FaqPopup.find("#faq_popup_pager>.faq_popup_pager_prev_arrow").hide();
}else{
FaqPopup.find("#faq_popup_pager>a[href='#prev']").show();
FaqPopup.find("#faq_popup_pager>.faq_popup_pager_prev_arrow").show();
}
if (data.pager.from>=data.pager.total-FaqSuggest.options.count){
FaqPopup.find("#faq_popup_pager>a[href='#next']").hide();
FaqPopup.find("#faq_popup_pager>.faq_popup_pager_next_arrow").hide();
}else{
FaqPopup.find("#faq_popup_pager>a[href='#next']").show();
FaqPopup.find("#faq_popup_pager>.faq_popup_pager_next_arrow").show();
}
FaqPopup.find('#faq_popup_pager>a').unbind().click(function(){
var jThis = jQuery(this);
if (jThis.attr('href').split('#')[1]=='next'){
if (data.pager.from>=data.pager.total-FaqSuggest.options.count){
return false;
}else{
var params = {pager:{from:parseInt(data.pager.from)+parseInt(FaqSuggest.options.count),count:FaqSuggest.options.count}}
FaqSuggest.getFaqItems(params);
}
}
if (jThis.attr('href').split('#')[1]=='prev'){
if (data.pager.from==0){
return false;
}else{
var params = {pager:{from:data.pager.from-FaqSuggest.options.count,count:FaqSuggest.options.count}}
FaqSuggest.getFaqItems(params);
}
}
});
}
if (data.results.length>0){
var faqList = jQuery('#'+FaqSuggest.options.popupId).find('.faq_list').empty();
if (faqList.length>0){
for (var i=0; i < data.results.length; i++){
var newel = jQuery(''+data.results[i].title+'- '+data.results[i].content+'
');
faqList.append(newel);
}
faqList.find("a[href='#view']").click(function(){
if (jQuery(this).parent().hasClass('clicked')){
jQuery(this).parent().removeClass('clicked').children('.answer').hide();
}else{
faqList.find('.clicked').removeClass('clicked');
faqList.find('.answer').hide();
jQuery(this).parent().addClass('clicked').children('.answer').show();
}
FaqSuggest.loadBgLayer();
});
FaqSuggest.showPopup();
}
}else{
jQuery('#'+FaqSuggest.options.formId).unbind().submit();
}
}else{
jQuery('#'+FaqSuggest.options.formId).unbind().submit();
}
});
}
}
}();
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
FaqSuggest.pageSize = function(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
// console.log(self.innerWidth);
// console.log(document.documentElement.clientWidth);
if (self.innerHeight) { // all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// console.log("xScroll " + xScroll)
// console.log("windowWidth " + windowWidth)
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
// console.log("pageWidth " + pageWidth)
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}