$(document).ready(function() {
	$('#about-wrap .expand').hide();
	$('#about-wrap h3 a').click (function() {
		$(this).parent('h3').toggleClass('active').next('div.expand').toggle();
		return false;
	});
});

$.fn.check = function(mode) {
	var mode = mode || 'on'; // if mode is undefined, use 'on' as default
	return this.each(function() {
		switch(mode) {
		case 'on':
			this.checked = true;
			break;
		case 'off':
			this.checked = false;
			break;
		case 'toggle':
			this.checked = !this.checked;
			break;
		}
	});
};

//gets an array of elements with class:[classname] and optional call a callback function on each
function getElementByClass(classname,callBack){
	var inc=0;
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	var rtnCollection=new Array(0);
	for(var i=0;i<alltags.length;i++){
		if(alltags[i].className.indexOf(classname)>-1){
			//check for callback and execute
			if(callBack!="")
				eval(callBack+"(alltags[i]);");
			rtnCollection[rtnCollection.length]=alltags[i];
		}
	}
return rtnCollection;
}


//append an event to the window.onload event
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload !='function'){
		window.onload=func;
	}else{
		window.onload=function(){
			oldonload();
			func();
		}
	}
}




// safely switches a class from xxxxx to yyyyy even if multiple classes are specified
function switchClass(what,from,to){
	try{
		var re=new RegExp(from,"gi");
		what.className=what.className.replace(re,to);
	}
	catch(e){}
}

function xmlhttp(strURL,poststr,call_back) {
    var xmlHttpReq = false;
    var self = this;

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	//alert(qstr);
   	self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if(typeof call_back!="undefined"){
    	self.xmlHttpReq.onreadystatechange = function(){
						    															if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200){
						    																call_back(self.xmlHttpReq.responseText);
						    															}
						    														}
	 }
    self.xmlHttpReq.send(poststr);
	return false;
}



function displayMemberCount(mCount){
	//disable the search button and display the number of results
	if(parseInt(mCount)>0){
		document.getElementById('quick_search').disabled = false;
	}else{
		document.getElementById('quick_search').disabled = true;
	}
	document.getElementById('memberCount').innerHTML = "( <span>"+mCount+"</span> ) Search Results";
}

addLoadEvent(function(){ if(document.getElementById('quick_search')) document.getElementById('quick_search').disabled = true; });



function defaultValClear(elem){
	if(elem.value==elem.defaultValue){
		elem.value='';
	}
}
function defaultValSet(elem){
	if(elem.value==''){
		elem.value=elem.defaultValue;
	}
}

var member_count_timeout=null;
function getMemberCount(keywords){
	clearTimeout(member_count_timeout);
	if(keywords.length>0){
		member_count_timeout = setTimeout("xmlhttp('http://www.greenregister.org.uk/global/ajx/getMemberCount.php?keywords="+keywords+"', null, displayMemberCount);",400);
	}else{
		document.getElementById('memberCount').innerHTML='';
		document.getElementById('quick_search').disabled = true;
	}
}