/**
 * @author jeremy crowe
 * jeremy.crowe(a)crowna.co.nz
 */
var t=true; var f=false;
function ele(id){return document.getElementById(id);}
function w(txt){(switch_w)? tmp+=txt : document.write(txt)} var tmp=""; var switch_w=f;  // writes direct to page or to GV 'tmp'

function fnd(){
	rope=0; //required to prevent recursion warnings
	
//	var homeurl = document.location.toString()
	var homeurl = 'http://mail.hutt-chamber.org.nz/' 

	 if(homeurl.indexOf('http')!=-1) homeurl = homeurl.substring( 0,homeurl.indexOf('/',9))
	
	var url=homeurl+'/srhhvccINC.php?sw=';
	
	//sequencer build
	fntSeqSet = new Array();
	seqInx = 0;
	fntSeqSet.push( new Array('init_newSkrp' , 'sr' , url+document.getElementById("fldid").value , t));
	fntSeqSet.push( new Array('displayresults' , 'a' , 'a' , 'a'));
//	fntSeqSet.push( new Array('init_newSkrp' , 'sr' , url+'*' , f));
//	fntSeqSet.push( new Array('end' , 'a' , 'a' , 'a'));
	fntSeqencer()
}

function displayresults(){
	var htm='';
	var m='';
	var hideCnt=10;
	var hideInx=0;
	var hidePgs=0;
	
	htm+='';
	for(var i=0;i<this.members.length;i++){
		m=this.members[i];
		if(m.web.indexOf('http')==-1 && m.web!='') m.web='http://'+m.web ;
		if(m.email.indexOf('@')!=-1) m.email='<a href="mailto:'+m.email+'?subject=Enquiry&body=Dear%20'+m.name+',\n">'+m.email+'</a>';
		htm+='<tr class="dis'+hidePgs+'"><td class="mlt">Company</td><td class="mlv">'+m.company+'</td><td class="mlt">Category 1</td><td class="mlv">'+m.cat1+'</td></tr>'
		+'<tr class="dis'+hidePgs+'"><td class="mlt"></td><td></td><td class="mlt">Category 2</td><td class="mlv">'+m.cat2+'</td></tr>'
		+'<tr class="dis'+hidePgs+'"><td class="mlt">Contact</td><td class="mlv">'+m.name+'</td><td class="mlt">Keywords</td><td class="mlv">'+m.keywords+'</td></tr>'
		+'<tr class="dis'+hidePgs+'"><td class="mlt">Tel.</td><td class="mlv">'+m.tel+'</td><td class="mlt">E-Mail</td><td class="mlv">'+m.email+'</td></tr>'
		+'<tr class="dis'+hidePgs+'"><td class="mlt">DDI</td><td class="mlv">'+m.DDI+'</td><td class="mlt">WWW</td><td class="mlv"><a href="'+m.web+'" target="_blank">'+m.web+'</a></td></tr>'
		+'<tr class="dis'+hidePgs+'"><td class="mlb" colspan="4"></td></tr>';
		hideInx++;
		if(hideInx==hideCnt){hideInx=0;hidePgs++;}
	}
	if(htm=='') //empty results
		htm+='<tr><td class="mlv">No results found!</td></tr><tr><td class="mlb">&nbsp;</td></tr>';

	htm='<table class="ml">'+htm+'</table>';
	
	//paging
	htm+='<table class="mli">';
	
	ele('memlist').innerHTML=htm;
	
	seqInx++;
	fntSeqencer()
}
	
	
function init_newSkrp(id,scpt_url,newLoad){ // modified for hvcc 100624
   var d = (scpt_url.indexOf('?')!=-1)? '&' : '?' ; d+='d='+new Date().valueOf(); //date stamp causes load every time
   var item =  ele(id)  ;
   if(item!=null) document.body.removeChild(item)
   var skrp = document.createElement('SCRIPT')
   skrp.src = scpt_url  ;
   skrp.src += (typeof newLoad!="undefined" && newLoad)? d :'' ; // forced reload
   skrp.id = id;
   document.body.appendChild(skrp);
}
				

var fntSeqSet = new Array();
var seqInx = 0;
var rope=0;
function fntSeqencer(){
	if(rope>=8){alert('recursion error\nseqInx is '+seqInx+'\nrope is '+rope);return;}
	rope++;
	if(seqInx==0) show_lookIndicator(t)
	if(fntSeqSet.length!=0 && fntSeqSet.length != seqInx && seqInx<=fntSeqSet.length){
		this[fntSeqSet[seqInx][0]](fntSeqSet[seqInx][1] , fntSeqSet[seqInx][2] , fntSeqSet[seqInx][3] )
		seqInx++;
	}else{
		show_lookIndicator(f);
		if(typeof end!="undefined")end();//end() action can be written in the calling page
		fntSeqSet =[];seqInx=0;
	} 
}
function show_lookIndicator(on){
	var l=ele('looking'); // if element found then hide/show it
	if(l!=null)
	l.style.visibility=(on)?'visible':'hidden';
	else  					//else alter the cursor
	document.body.style.cursor = (on)?'wait':'';
	
	if(typeof checkShowmee=='function' && !on) checkShowmee() ;
}
function werr(txt){ele('err').innerHTML=ele('err').innerHTML+'<br>'+txt;}
function end(){
	show_lookIndicator(f);
}
function nix(){}
