function wpfaqajaxloading(action) {
	if (action == "show") {
		Effect.Appear('wpfaqloading', {duration:0.15, from:0, to:0.5});
		Effect.Appear('wpfaqloadingimage', {duration:0.15, from:0, to:1});
	} else {
		Effect.Fade('wpfaqloading', {duration:0.15, from:0.5, to:0});
		Effect.Fade('wpfaqloadingimage', {duration:0.15, from:1, to:0});
	}
}

function wpfaq_search(group_id) {
	var formvalues = Form.serialize($('wpfaq_search' + group_id + ''));
	
	new Ajax.Updater('wpfaqaccordion' + group_id + '', wpFaqAjaxBase + '?cmd=search&id=', {
		evalScripts: true,
		method: "POST",
		asynchronous: true,
		parameters: formvalues,
		onLoading: function(request) {
			Element.show('wpfaq_search_loading' + group_id + '');
		},
		onComplete: function(request) {
			Element.hide('wpfaq_search_loading' + group_id + '');
			Effect.Fade('wpfaqaccordion' + group_id + '', {from:0, to:1});
		}
	});
}

function wpfaq_ask(group_id) {
	var formvalues = Form.serialize($('wpfaq_askform' + group_id + ''));
	
	new Ajax.Updater('wpfaq_ask' + group_id + '', wpFaqAjaxBase + '?cmd=ask&id=' + group_id + '&group_id=' + group_id + '', {
		evalScripts: true,
		asynchronous: true,
		parameters: formvalues,
		onLoading: function(request) {
			Element.show('wpfaq_ask_loading' + group_id + '');
		},
		onComplete: function(request) {
			Element.hide('wpfaq_ask_loading' + group_id + '');
			Effect.Fade('wpfaq_ask' + group_id + '', {from:0,to:1});
		}
	});
}

function wpfaq_delete_group(id) {
	var confirm = wpfaqconfirmMessage('group_delete');

	if (confirm == true) {	
		new Ajax.Request(wpFaqAjaxBase + "?cmd=delete_group&id=" + id + "", {
			onLoading: function(request) {
				wpfaqajaxloading('show');
			},
			onComplete: function(request) {
				wpfaqajaxloading();
				$("grouprow" + id + "").style.backgroundColor = "#ff0000";
				new Effect.Fade("grouprow" + id + "", {from:1, to:0});
			}
		});
	} else {
		return false;
	}
}

function wpfaq_question_delete(id) {
	if (wpfaqconfirmMessage('question_delete')) {
		new Ajax.Request(wpFaqAjaxBase + '?cmd=delete_question&id=' + id + '', {
			onLoading: function(request) {
				wpfaqajaxloading('show');
			},
			onComplete: function(request) {
				wpfaqajaxloading();
				$('questionrow_' + id).style.backgroundColor = "#FF0000";
				new Effect.Fade('questionrow_' + id + '', {from:1, to:0});
			}
		});
	} else {
		return false;
	} 
}

function wpfaqcheckAllBoxes(obj, formname, fieldname) {		
	if(document.forms[formname].elements[fieldname+"[]"].length) {
		for (i = 0; i < document.forms[formname].elements[fieldname+"[]"].length; i++) {
			document.forms[formname].elements[fieldname+"[]"][i].checked = true;
		}
	} else {
		$(formname).elements[fieldname+"[]"].checked = true;
	}
	
	$('mainCheckLink').innerHTML = '<a href="javascript:wpfaqunCheckAllBoxes(this,\'' + formname + '\',\'' + fieldname + '\');" title="Uncheck all checkboxes">Uncheck</a>';
}

function wpfaqunCheckAllBoxes(obj, formname, fieldname) {
	if(document.forms[formname].elements[fieldname+"[]"].length) {
		for (i = 0; i < document.forms[formname].elements[fieldname+"[]"].length; i++)
		{
			document.forms[formname].elements[fieldname+"[]"][i].checked = false;
		}
	} else {
		document.forms[formname].elements[fieldname+"[]"].checked = false;
	}
	
	$('mainCheckLink').innerHTML = '<a href="javascript:wpfaqcheckAllBoxes(this,\'' + formname + '\',\'' + fieldname + '\');" title="Check all checkboxes">Check</a>';
}

function wpfaqgetPageSize(){
	
	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;
}