//* Copyright (c) 2000-2008 Cyber-dynamics International Inc. All Rights Reserved. *//
//* info@cyber-dynamics.com *//

window.defaultStatus=document.title;

var bSupportsOptions=0,sSrchCookie='srchcookie',bFront=0,bStatic=0,bAdvanced=0,sSearchString;

// 2009
var isReverseLookup=0;

// files
// location = lc
// category = ct
// wp name = wpn
var sURLStreets = '/directory/cdDirStreets.txt';
var sURLPlaces = '/directory/cdDirPlaces.txt';
var sURLCategories = '/directory/cdDirCategories.txt';

// LOCAL OR REMOTE
var sURLScript  = '/directory/search3';
// var sURLScript  = '/cgi-bin/cdDirectory-3.cgi';
	 
// strings
var strSrchCat = 'Category, Services, etc';
var strSrchNinst = 'Cayman Free Press<br />Key to Cayman<br />What&rsquo;s Hot<br />';
var strSrchMatch = '<div class="match" style="display:none;">'
 + ' <input type="radio" name="my" id="i_match4" class="iR" value="as" checked="checked" /> <label for="i_match4" accesskey="E">As <u>E</u>ntered</label>'
 + ' <input type="radio" name="my" id="i_match5" class="iR" value="ex" /> <label for="i_match5" accesskey="X">E<u>x</u>act match</label>'
 + ' <input type="radio" name="my" id="i_match6" class="iR" value="all" /> <label for="i_match6" accesskey="L">A<u>l</u>l words</label>'
 + ' <input type="radio" name="my" id="i_match7" class="iR" value="any" /> <label for="i_match7" accesskey="Y">An<u>y</u> words</label> </div>';
var strBusName = 'Name of Business';
var strWPname = 'Name of Subscriber';
var strCat = 'Select';
var strLocation = 'Island, Area, Street, PO Box or Post Code';
var sSrch = strBusName;

// images
var img = new Array(),imgs = new Array();
function getImages(){
	if (document.images) {
		imgs[0] = "/directory/images/b-business.gif";
		imgs[1] = "/directory/images/b-business-o.gif";
		imgs[2] = "/directory/images/b-business-a.gif";
		imgs[3] = "/directory/images/b-residential.gif";
		imgs[4] = "/directory/images/b-residential-o.gif";
		imgs[5] = "/directory/images/b-residential-a.gif";
//		imgs[6] = "/directory/images/CFPCCarrow.gif";
//		imgs[7] = "/images/shadow-grid.gif";
//		imgs[7] = "/images/shadow.png";
		imgs[8] = "/directory/images/i_edit.gif";
		imgs[9] = "/directory/images/i_edit-o.gif";
		imgs[10] = "/directory/images/i_validate.gif";
		imgs[11] = "/directory/images/i_validate-o.gif";
		
		for (var i = 0; i < imgs.length; i++) {
			if (imgs[i] != '') {
			img[i] = new Image();
			img[i].src = imgs[i];
} } } }

function selectBanner() {
var saBanners = Array ('Buzz-Banner1.jpg', 'Buzz-Banner2.jpg', 'Buzz-Banner3.jpg', 'Buzz-Banner4.jpg', 'Buzz-Banner5.jpg', 'Buzz-Banner6.jpg', 'Buzz-Banner7.jpg', 'Buzz-Banner8.jpg', 'Buzz-Banner9.jpg', 'Buzz-Banner10.jpg' );
var i = Math.round( Math.random() * (saBanners.length - 1));
document.write("<a href='http://www.caymanbuzz.com/directory/'><img src='/directory/banners/"  + saBanners[i] +  "' width='350' height='115' border='0' alt='Caymanbuzz - The independent phone directory of the Cayman Islands' title='Caymanbuzz - The independent phone directory of the Cayman Islands'/></a>");
}

function cdSwpImg(iImg,iIn){if((img[iIn])&&(document.images[iImg])){if(img[iIn].src){document.images[iImg].src=img[iIn].src;}}}	
// tabs
var bActiveTab='yp';
function cdSetTabs() {if(bStatic!=1){if (bActiveTab=='yp') {if (bFront==9){cdYPclickf();} else {cdYPclick();}} else {if(bFront!=9) {cdWPclick();}}}
	// 200902 reverse
	var f=document.MyControl;
	if (f.rld){
		if (bActiveTab=='yp'){
			f.rld[0].checked=true;
		}else{
			f.rld[1].checked=true;
	}	}
}
function cdYPover(iX) {if (bActiveTab!='yp') {if (iX==1){cdSwpImg('it2',1);}else{cdSwpImg('it2',0);}}}
function cdWPover(iX) {if (bActiveTab!='wp') {if (iX==1){cdSwpImg('it3',4);}else{cdSwpImg('it3',3);}}}
function cdWPoverf(iX) {if (bActiveTab!='wp') {if (iX==1){cdSwpImg('it3',7);}else{cdSwpImg('it3',6);}}}
function cdYPclick() {bActiveTab='yp';cdSwpImg('it2',2);cdSwpImg('it3',3);cdShowHide('divWP',0);cdShowHide('dcga',1);cdShowHide('divYP',1);document.MyControl.yp.value=1;document.MyControl.wp.value='';}
function cdYPclickI() {bActiveTab='yp';cdSwpImg('it2',2);cdSwpImg('it3',3);cdShowHide('divWP',0);cdShowHide('divYP',1);document.MyControl.yp.value=1;document.MyControl.wp.value='';}
function cdYPclickf() {bActiveTab='yp';cdSwpImg('it2',2);cdSwpImg('it3',6);cdShowHide('divWP',0);cdShowHide('dcga',1);cdShowHide('divYP',1);document.MyControl.yp.value=1;document.MyControl.wp.value='';}
function cdWPclick() {bActiveTab='wp';cdSwpImg('it2',0);cdSwpImg('it3',5);cdShowHide('divYP',0);cdShowHide('dcga',0);cdShowHide('divWP',1);document.MyControl.yp.value='';document.MyControl.wp.value=1;}
function cdWPclickI() {bActiveTab='wp';cdSwpImg('it2',0);cdSwpImg('it3',5);cdShowHide('divYP',0);cdShowHide('divWP',1);document.MyControl.yp.value='';document.MyControl.wp.value=1;}
function cdAdvanced(){
	var sA='<a href="#" onclick="cdAdvanced();return false;" title="Click for advanced search options">Advanced Search &gt;</a>'; 
	var sS='<a href="#" onclick="cdAdvanced();return false;" title="Click for simplified search">Simple Search &gt;</a>'; 
	bAdvanced=(bAdvanced==1)?0:1;
	s=(bAdvanced==1)?sS:sA;
	cdShowHide('dtypRr',bAdvanced);
	cdShowHide('typRr',bAdvanced);
	cdShowHide('dtypR',bAdvanced);
	cdShowHide('dc_typ',bAdvanced);
	cdShowHide('dlocR',bAdvanced);
	cdWriteDiv('dAdvR',s);
}
// init
function init() {
	cdSetTabs();
	getImages();
	if (sSearchString){
//		if(sSearchString.indexOf('adv=1')>0){cdAdvanced();}
		if((document.MyControl)&&(document.MyControl.srchQty)&&(sSearchString.indexOf('srchQty=')>0)){
			var i = getSearchValue(sSearchString,'srchQty');
			if (i>0){document.MyControl.srchQty.value=i;}
	}	}
	cdExtractSearch();
	setimgMaxSize();	
	cdCheckSupportsOptions(document.MyControl.iHistory);
	cdGetSearchHistory(document.MyControl.iHistory);
	setTimeout("cdSetTabs();",2000);
	setTimeout("cdSetTabs();",5000);
	setTimeout("cdSetTabs();",20000);
}
function cdReplace(s,sReplace,sWith){
	if(s){
		var i = s.indexOf(sReplace);
		var j = 0;
		if(sReplace) j=sReplace.length;
		if (i > -1) {s = s.substr(0,i) + sWith + s.substr(i+j,999);}	
	} 
	return(s);
}
function cdExtractSearch() {
	var sNVP = new Array(); var sNV = new Array(); 
	var s=window.location.search, fm=document.MyControl,i,j,sAdvanced=0;;
	if (s) {
		s = s.substr(1);
		sNVP = s.split("&");
		for (i=0; i<sNVP.length; i++) {
			sNV = sNVP[i].split("=");	
			if (sNV[0] && sNV[1]) {
				sNV[1] = unescape(sNV[1]);
				sNV[1] = sNV[1].replace(/\+/g,' '); // 2009
				if (sNV[0]=='ct') { // kluge
					sNV[1]= cdReplace(sNV[1],'&amp;','&');
				}
				for (j=0; j<fm.length;j++) {
					if ((fm.elements[j].name == sNV[0])&&(fm.elements[j].type)) {
						if ((fm.elements[j].type=='checkbox')&&(sNV[1]!=0)&&(sNV[1]!='N')) {
							fm.elements[j].checked = true;
						} else if (fm.elements[j].type.indexOf('select')>-1) {
							cdLBset(fm.elements[j],sNV[1])
						} else if (fm.elements[j].type=='radio') {
							cdRBset(fm,fm.elements[j],sNV[1])
						} else {						
							fm.elements[j].value = sNV[1];
						}
						break;
}	}	}	}	}	}
function getSearchValue(sStr,sName){
	var sValue='';
	if (sStr.indexOf(sName)>-1){
		sValue = sStr.substring(sStr.indexOf(sName+'=')+sName.length+1);
		if (sValue.indexOf("&")>-1){sValue=sValue.substring(0, sValue.indexOf("&"));}
	}
	return(sValue);
}
function cdClick(i,s) {
	cdCurrentInputValue = '';
	var f = document.MyControl;
	if (f[i]){
		if (f[i].value==s){f[i].value='';}
		f[i].style.color='#000000';
}	}
function cdBlur(i,d,s,t) {
	var f=document.MyControl;
	if ((f[i])&&(cdIsBlank(f[i].value))) {
		f[i].value=s;
		f[i].style.color='#c0c0c0';
	}	
	cdWriteDiv(d,t);
}			
onblur="cdBlur('c','dtyp',sSrch);"

function cdClickClear(oMe,sVal) {if (oMe.value==sVal){oMe.value='';}}
function cdClickShout(oMe,sVal) {if (cdIsBlank(oMe.value)){oMe.value=sVal;}}

function cdStatus(sStr) {window.status=sStr;document.returnValue=true;}
function cdBadField(str,minlength){if(cdIsBlank(str)||(str.length<minlength)){return true}else{return false}}	 
function cdIsBlank(str){if(str.length==0){return true};for(i=0;i<=str.length-1;i++){if(str.charAt(i)!=" "){return false}}return true;}

function cdSwapAntiSpam(sImage,sSRC1,sSRC2) {
	if (document.getElementById){
		var img = document.getElementById(sImage);
		if(img.src.indexOf(sSRC1)>-1) {
				document.getElementById(sImage).src=sSRC2;				
			}else {
				document.getElementById(sImage).src=sSRC1;
}	}	}	
function cdAntiSpamCheck(sFormID){
	var i=0,j=0,k=4,s = sFormID.i_antiSpamCheck.value;
	if (s.length==5) {
		for (j=0;j<4;j++){i = i + (k * s.charAt(j));k--;}
		if ((i%11) == s.charAt(4)) {
			return(1);
	}	}
		return(0);
}
var  supp;
// var st=window.location.search;if (st.indexOf('popup=')<0){
function cdPopUp(url,pLeft,pTop,pWidth,pHeight) {if (pWidth<10){pWidth=400;} if (pHeight<10){pHeight=200;} var str='left='+pLeft+',top='+pTop +',width='+pWidth+',height='+pHeight+',resizable=no,scrollbars=yes';if (supp) {if (supp.open) {supp.close();}}
url=url;supp=window.open(url,"popper",str);if (!supp.opener){supp.opener = self;}if (supp.focus != null) {supp.focus();}
return false;}
//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
var dragapproved=false;
var minrestore=0;
var initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;
function iecompattest() {if ((!window.opera)&&(document.compatMode)&&(document.compatMode!="BackCompat")){return(document.documentElement);}else{return(document.body);}}
function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px";}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px";}}
function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)
dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop}
function loadwindow(url,width,height){if (!ie5&&!ns6){window.open(url,"","width=width,height=height,scrollbars=1");}else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left="30px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url;}}
function maximize(){if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","/images/restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"}else{
minrestore=0; //restore window
document.getElementById("maxname").setAttribute("src","/images/max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px";}
function closeit(){document.getElementById("dwindow").style.display="none";}
function stopdrag(){dragapproved=false;document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="";}
// - END DHTML WINDOW
//  sOpt= 0,1 or blank to toggle; 
function cdShowHide(sElement,sOpt,sDisplay) {
	var oElement, i = sElement;
	if (!sDisplay) {sDisplay='block';}
	if (document.getElementById) {if (document.getElementById(sElement)) {oElement = document.getElementById(sElement).style;} }
	else {if (document.all) {if (document.all[sElement]){oElement = document.all[sElement].style;}}
	else {if (document.layers) {if(document.layers[sElement]){oElement = document.layers[sElement];}}}}
	if (oElement){if ((sOpt=='0')||(sOpt=='1')) {
			if (sOpt==0){sOpt='none';}else{sOpt=sDisplay;}	
			oElement.display = sOpt;
		} else {
			if (oElement.display == "none"){oElement.display = sDisplay;} else {oElement.display = "none";
}	}	}	}
function cdWriteDiv(divID,sText) {if ((document.getElementById)&&(document.getElementById(divID))) {document.getElementById(divID).innerHTML = sText;	
} else {if ((document.layers)&&(document.layers[divID])) {document.layers[divID].document.open();document.layers[divID].document.write(sText);document.layers[divID].document.close();
} else {if ((document.all)&&(document.all[divID])) {document.all[divID].innerHTML=sText;}}}}
function cdReadDiv(divID) {if ((document.getElementById)&&(document.getElementById(divID))) {return(document.getElementById(divID).innerHTML);} 
else {if ((document.all)&&(document.all[divID])) {return(document.all[divID].innerHTML);}
}}
// else {if ((document.layers)&&(document.layers[divID])) {document.layers[divID].document.open();
// document.layers[divID].document.write(sText);document.layers[divID].document.close();
//  XML
var sGETnextAction,sGETresult,sGETtextorxml; // 0 or 1
function cdGETRequest(url) {
var http_request = false;
	if (window.XMLHttpRequest) { // IE7, Mozilla, Safari, ...
    	http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
        	http_request.overrideMimeType('text/xml');
    }	} else if (window.ActiveXObject) { // IE6
    	try {http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {
        	try {http_request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
	}	}
    if (!http_request) {alert('Sorry. Cannot create an XML HTTP connection');return false;}
	http_request.onreadystatechange = function() {cdGETresponse(http_request);};
    http_request.open('GET', url, true);
//   http_request.send('');
    http_request.send(null);
}
function cdGETresponse(http_request) {
//	try {
	{if (http_request.readyState == 4) {
    		if ((http_request.status == 200) ||  (http_request.status == 0)) {
    			if ((document.getElementById)&&(document.getElementById('fStatus'))){document.getElementById('fStatus').innerHTML = "";}
				if (sGETtextorxml == 1) {
					sGETresult = http_request.responseXML;
				}else{
					sGETresult = http_request.responseText;
			}
			eval(sGETnextAction);
        	} else {
         		alert('Sorry. There was a problem communicating with the server.');
	}	}	}	
//   }	catch( e ) {alert('Sorry. There was a problem communicating with the server.' + "\n" + '(' + e.description + ')');}	
}
function cdGetXML(sXML,sTag) {
 try {
	 if(sXML) {
		 if ((document.getElementsByTagName)&&(sXML)&&(sXML!=null)&&(sTag!='')&&(sTag!=null)&&(sTag!='null')){
			if(!sXML.getElementsByTagName(sTag)){alert('Problem communicating with server');} else {
  	var sData = sXML.getElementsByTagName(sTag).item(0).firstChild;if (sData){return(sData.data);}}return('');	
  }}} catch(e) {return('Sorry, an error occurred ' + e.description);}
}	
var dWhat,sStreets='',sCats1='',sCats2='',sPlaces='',sMap='';
function cdSwitchInput(w){
	var sURL;
	dWhat=w;
	sGETnextAction 	= 'cdGotInput();';
	sGETresult		= '';
	sGETtextorxml	= 0;
	if(w=='st'){
		if (sStreets.length>100){sGETresult=sStreets;cdGotInput();return(0);}else{
	 	sURL=sURLStreets;
		cdShowHide('dlWait',1);
	} } else if (w=='tx') {
		sGETresult = '\<input type="text" name="lc" id="lc" class="iT" value="'+strLocation+'" onclick="cdClick(\'lc\',strLocation);" onblur="cdBlur(\'lc\',\'\',strLocation,\'\');" \/\>';
		cdGotInput();
		return(0);
	} else if (w=='pl') {
		if (sPlaces.length>100){sGETresult=sPlaces;cdGotInput();return(0);}else{
	 	sURL=sURLPlaces;
		cdShowHide('dlWait',1);
	}} else if (w=='mp') {
		if (sPlaces.length>100){sGETresult=sPlaces;cdGotInput();return(0);}else{
	 	sURL=sURLPlaces;
		cdShowHide('dlWait',1);	
	}} else if(w=='ct'){
		if (document.MyControl.cat.length>1){sGETresult=sCats2;cdGotInput();return(0);}else{
	 	sURL=sURLCategories;
		cdShowHide('dcWait',1);
	} } else if ((w=='ga')||(w=='gaR')) {
		sGETresult = sCats1;
		cdGotInput();
		return(0);
	}
	cdGETRequest(sURL); 
}
function cdGotInput() {
	var i,s = sGETresult,f=document.MyControl,br='\<br \/\>',s1='';
	sGETresult=''; br=br+br+br+br+br; 
	if (dWhat=='st'){
		cdShowHide('dlWait',0);
		cdWriteDiv('dlc',s+br);	 
		document.MyControl.lc.style.color='#000000';
		cdShowHide('diex',0);cdShowHide('dimp',0);
		cdShowHide('dlst',0,'inline');cdShowHide('dlga',1,'inline');cdShowHide('dlpl',1,'inline');cdShowHide('dlmp',1,'inline');
		sStreets=s;
	} else if (dWhat=='pl'){
		cdShowHide('dlWait',0);
		cdWriteDiv('dlc',s+br);	 
		cdShowHide('diex',0);cdShowHide('dimp',0);
		cdShowHide('dlpl',0,'inline');cdShowHide('dlga',1,'inline');cdShowHide('dlst',1,'inline');cdShowHide('dlmp',1,'inline');
		sPlaces=s;
	} else if (dWhat=='mp'){
		cdShowHide('dlWait',0,'inline');
		cdWriteDiv('dlc',s,'inline');	 
		cdShowHide('diex',0);cdShowHide('dimp',1);
		cdShowHide('dlpl',1,'inline');cdShowHide('dlga',1,'inline');cdShowHide('dlst',1,'inline');cdShowHide('dlmp',0,'inline');
		sPlaces=s;
	} else if (dWhat=='tx') {
		cdShowHide('dlWait',0);
		cdWriteDiv('dlc',s);	 
		cdBlur('lc','',strLocation,'');
		cdShowHide('diex',1);cdShowHide('dimp',0);
		cdShowHide('dlga',0,'inline');cdShowHide('dlst',1,'inline');cdShowHide('dlpl',1,'inline');cdShowHide('dlmp',1,'inline');
	} else if (dWhat=='ct'){
		cdShowHide('dcWait',0);
		//f.typ[0].checked = true;
		///cdClick('ct',sSrch);sSrch=strSrchCat;
		//if (sCats1==''){sCats1 = cdReadDiv('dc_typ');}
		//200801 - save cat value
		s1=cdLBget(f.cat);
		cdWriteDiv('dc_typ','\<label for="cat" accesskey="G"\>Cate<u>g</u>ory\<\/label\>\<br \/\>'+s);	 
		document.MyControl.cat.style.color='#000000';
		//200801 - restore cat value;
		if ((s1)&&(s1!='Select')&&(s1!='All')&&(s1!='Multiple')){cdLBset(f.cat,s1);}		 
		f.cat.focus();
		sCats2=s;
	} else if (dWhat=='ga') {
		cdShowHide('dcWait',0);
		cdWriteDiv('dc_typ',s);	 
		cdClick('ct',sSrch);sSrch=strBusName;
		cdBlur('ct','dtyp',sSrch,'Cayman Free Press\<br \/\>Key to Cayman<br \/\>What&rsquo;s Hot');
		cdShowHide('dcga',0);cdShowHide('dcct',1);
	} else if (dWhat=='gaR') {
		cdShowHide('dcWait',0);
		cdWriteDiv('dc_typ',s);	 
		cdClick('ct',sSrch);sSrch=strBusName;
		cdBlur('ct','dtyp',sSrch,'');
		cdShowHide('dcga',0);cdShowHide('dcct',1);
	}
		
}
function cdStartSearch(i) {
	if (isReverseLookup==1) {cdStartReverseLookUp(i);} else {	
		var f = document.MyControl,sCat,sLoc,sWPN,s='',sT;
		f.rl.value='';
		if (f.ct.type.indexOf('select')>-1){sCat=cdLBget(f.ct);}else{sCat=f.ct.value;}
		if (f.lc.type.indexOf('select')>-1){sLoc=cdLBget(f.lc);}else{sLoc=f.lc.value;}
		sWPN=f.wpn.value;
		var sCtgy=cdLBget(f.cat);
		if (sLoc==strLocation){sLoc='';}
		if (sCtgy==strCat){sCtgy='';}
		if ((sCat==strBusName)||(sCat==strWPname)) {sCat='';}
		if ( ((f.yp.value==1)&&((cdIsBlank(sCat)))&&(cdIsBlank(sCtgy)))  // &&((sLoc==strLocation)||(cdIsBlank(sLoc)))
			|| ((f.wp.value==1)&&((sWPN==sSrch)||(cdIsBlank(sWPN))))  )
						{alert('Please enter some details for us to search against');return(false);}
		else if ((f.yp.value==0) && (f.wp.value==0) && (cdBadField(f.srchTerm.value,1))) {alert('Please enter a search term');return(false);}
		else {
			if (f.wp.value==1){sT='R:';s=f.wpn.value;}else{sT='B:';s=sCat;
			if (f.typ[0].checked){s='Type='+s;}
			}	
			if ((!cdIsBlank(s))&&(!cdIsBlank(sCtgy))){sT+=s+'/'+sCtgy;}else{sT+=s+sCtgy;}
			if ((sLoc!='')&&(sLoc!=strLocation)){sT+=' (' + sLoc + ')';}
			cdRunSearch(i,'',sT) ;
}	}	}
function cdStartReverseLookUp(i) {
	var f;
	if (document.MyControl2) {f=document.MyControl2;}else{f=document.MyControl;}
	var sRL=f.rl.value,sSch='',sT;
	if (sRL.length<2)	{alert('Please enter a PO Box No., post code, phone no., email address or web site address');return(false);}
	else {
		if (f.rld[1].checked){sSch='wp=1';sT='R:reverse lookup:'+sRL;}else{sSch='yp=1';sT='B:reverse lookup:'+sRL;}
		sRL=encodeURIComponent(sRL);
		sRL=sRL.replace(/\'/g,'');
		sSch+='&rl=' + sRL;
		cdRunSearch(i,sSch,sT);
}}

function cdRunSearch(i,sSch,sT) { // i = 1 = AJAX, sT = LB text for saved search
	var f = document.MyControl,sCat,sLoc,sURL;
	if ((!i)||(i==undefined)) {i = 0;}
		f.srchStart.value = i;
		if((!sSch)||(sSch==undefined)||(sSch=='')){sSch=cdBuildSearch(f,'iHistory,iNoHist');}
		sURL=sURLScript;
		if (sSch!='') {			
			sURL=sURL+'?'+sSch;
			if ((sT)&&(sT!='')&&(f.iHistory)){cdSaveSearch(f.iHistory,sSch,sT);}else{cdSaveSearch('',sSch,sT);}			
		} 
		cdShowHide('dWait',1);
		cdShowHide('dSchWait',1);
		if (f.ax.value==1) {
			sGETnextAction 	= 'cdEndSearch();';
			sGETresult		= '';
			sGETtextorxml	= 1;
			cdGETRequest(sURL); 
		} else {
			self.location = sURL;
	}	
	return(false);
}
function cdEndSearch() {
	cdShowHide('dWait',0);
	cdShowHide('dSchWait',0);

	var s = sGETresult;
	s = cdGetXML(s,'results');
	sGETresult='';
	cdWriteDiv('d',s);	 
}
function cdBuildSearch(f,excl) {
	var s,sV,i,j,b,sEx=new Array();
	var s = String.fromCharCode(8217);
	var re = new RegExp(s);
	s='';
	if ((excl) && (excl!='')) {sEx = excl.split(',');}
	for (j=0; j<f.length;j++) {
		b=0;
		for (i=0; i<sEx.length;i++) {if (sEx[i] == f.elements[j].name) {b=1;break;}}		
		if (b==0) {
			sV = '';
			if ((f.elements[j].type=='radio')||(f.elements[j].type=='checkbox')){ if (f.elements[j].checked) {sV = f.elements[j].value;}}
			else if (f.elements[j].type.indexOf('select')>-1){sV=cdLBget(f.elements[j]);}
			else if (f.elements[j].value != '') {sV = f.elements[j].value;}
			if ( (sV != '') && (sV != strSrchCat) && (sV != strBusName) && (sV != strWPname) && (sV != strLocation)   ) {
				if (s!='') {s = s + '&';}
				sV = sV.replace(re, "'");
				sV = encodeURIComponent(sV);
				sV= sV.replace(/\'/g,'%27');
	     		s = s + f.elements[j].name + '=' + sV;
	}	}	}
	s = s.replace(/\n/g,'%20');
	s = s.replace(/\r/g,'');
	return (s);
}
	
	
function cdSrchGet(i,s) {	
	if (sSearchString) {sSearchString += '&srchStart=' + i + '&srchQty=' + document.MyControl.srchQty.value;} 
	cdRunSearch(i,sSearchString,'..');
}
function cdSrchGetAlpha(sAlpha,s) {	
	if (sSearchString) {sSearchString += '&alpha='+sAlpha+'&srchStart=0&srchQty=' + document.MyControl.srchQty.value;} 
	cdRunSearch(0,sSearchString,'..');
}
function cdShowCat(sCat) {
	if ((sCat)&&(!cdIsBlank(sCat))){
		cdShowHide('dWait',1);
		cdShowHide('dSchWait',1);
		sSch='yp=1&cat='+escape(sCat);
		var f=document.MyControl,sURL=sURLScript+'?'+sSch;
		if (f.iHistory){cdSaveSearch(f.iHistory,sSch,'B:/'+sCat);}			
		self.location = sURL;
}	}
//obsolete?
function cdGetCats(s) {
	var f = document.MyControl;
	f.cat.value = s;
	f.srchStart.value = 0;
	for (var i = 0;i<f.srchType.length; i++){f.srchType[i].checked = false;};
	f.srchTerm.value = unescape(s);
	cdRunSearch();
}
// business card
function cdBC(c,n) {var sURL = sURLScript + '?bc=1&c=' + escape(c) + '&n=' + escape(n);loadwindow(sURL,600,400);}
// show category and name
function cdCnN(c,n){
	//alert(c+n);
	if(c){c=c.replace(/\&rsquo;/,"'");c=c.replace(/\&amp;/,"&");c=c.replace(/\&quot;/g,'"');}
	if(n){n=n.replace(/\&rsquo;/g,"'");n=n.replace(/\&amp;/g,"&");n=n.replace(/\&quot;/g,'"');}
	cdShowHide('dWait',1);
	cdShowHide('dSchWait',1);
	sSch='yp=1&typ=ypn&cat='+escape(c)+'&ct='+escape(n)+'&my=ex&srchStart=0';
	var f=document.MyControl,sURL=sURLScript+'?'+sSch;
	if (f.iHistory){cdSaveSearch(f.iHistory,sSch,'B:'+n+'/'+c);}			
	self.location = sURL;
}
function cdMap(sURL) {cdPopUp(sURL,10,10,500,560);}
function cdKeyPress(e) {if ((e) && (e.keyCode == 13) && (node.type=="text")) {cdStartSrch();}}
document.onkeypress = cdKeyPress;

// set select when map clicked
function cdIMset(s) {cdLBset(document.MyControl.lc,s);}
// SELECT
function cdLBset(oLB,s){if((oLB)&&(s)){for (var i=0;i<oLB.length;i++){if (oLB.options[i].text==s){oLB.options[i].selected = true;return(i);break;}}}}
function cdLBget(oLB) {if((oLB)&&(oLB.selectedIndex > -1)){if (oLB.options[oLB.selectedIndex].value) 
{return(oLB.options[oLB.selectedIndex].value);}else {return(oLB.options[oLB.selectedIndex].text);}}else{return('.');}}
function cdRBset(fm,oRB,s) {
	for (var i=0; i<fm.length;i++) {
		if ((fm.elements[i].name==oRB.name)&&(fm.elements[i].type=='radio')&&(fm.elements[i].value==s)){
				fm.elements[i].checked=true;break;}
			}
//	alert(oRB.value + ' = ' + s);
	
//	if((oRB)&&(s)){for (var i=0;i<oRB.length;i++){
//	alert(i + oRB[i].value);
//	if (oRB[i].value==s){oRB[i].selected=true;return(i);break;}}}}
	
}

//* SAVE & RESTORE SEARCH *// 
function cdCheckSupportsOptions(oLB) {
	if((oLB)&&(oLB.options.length==2)){
		oLB.options[1]=null;
		if (oLB.options.length==1){bSupportsOptions=1;}
	}
	return(bSupportsOptions);
}
function cdSaveSearch(oLB,sV,sT) {
	if (document.MyControl.iNoHist.checked==true) { 
		// don't save search history
		oLB.options.length=1;
		saveCookie(sSrchCookie,'null=1',6);
	} else if ((sV != '') && (sT != '') && (sT != '..')  && bSupportsOptions &&(oLB)) { 
		var iFound=-1,i,iLBlen=oLB.options.length;
		// 200801: add match type
		if((sT.length>7)&&(sT.indexOf('Type=')!=2)) {
			var s=''; if (sT.substr(0,1)=='B'){s=getSearchValue(sV,'my');} else {s=getSearchValue(sV,'mw');}
			if (s=='ex'){sT += ' (exact match)'} else if (s=='all'){sT+=' (all words)';}else if (s=='any') {sT+=' (any words)';}
		}
		// escape value, show raw text 
		sV=escape(sV);
		// check if Val is in the list box already
		for (i=1;i<iLBlen;i++) {if (oLB.options[i].value == sV) {iFound=i;break;}}
		// ... if not, add at end
		if (iFound==-1) {
			iFound=iLBlen;
			oLB.options[iLBlen] = new Option('&nbsp;',''); 
			iLBlen++;
		}			
		// shuffle everything up
		for (i=iFound;i>1;i--) {
			oLB.options[i].value=oLB.options[i-1].value;
			oLB.options[i].text=oLB.options[i-1].text;
		}
		// stuff new value in at beginning	
		oLB.options[1].value = sV; 		
		oLB.options[1].text = sT; 	
		// save first 10 LB items as cookie
		if(iLBlen>11){iLBlen=11;} 	
		var sCk='';
		for (i=1;i<iLBlen;i++) {if(oLB.options[i].value!=''){sCk+=escape(oLB.options[i].text)+'~'+oLB.options[i].value+'|';}}
		saveCookie(sSrchCookie,'srch='+sCk,6);
}	}	
function showHistory(oObj,e){
	var s='Recent searches:<ul>',i;
	if (oObj.length == 1){
		s += '<li>No saved searches</li>';
	}else{ 
		for (i=1;i<oObj.length; i++){
			if (oObj.options[i].text == 'No Browser Support'){
				s += '<li>No Browser Support</li>';
			}else{
				s +=  "<li><a href='#' onclick='cdRunSavedSearch2(&quot;" + i + "&quot);return false;'>" + oObj.options[i].text + "</a></li>";
	}	}	}
	s += '</ul>';
	if ((oObj.length > 1)&&(oObj.options[1].text != 'No Browser Support')){
		s += "Memo: B: = search business listing. R: = search residential listing";
	}
	cdShowTip(s,oObj,e,400); 
}	
function cdRunSavedSearch2(iX) {
	var oObj=document.MyControl.iHistory;
	oObj.options[iX].selected = true;
	cdRunSavedSearch(oObj);
}
function cdGetSearchHistory(oLB){
	var f = document.MyControl;
	if(bSupportsOptions){
		var i,s=getCookie(sSrchCookie),sOpt=new Array(),sNV=new Array(); ;
//		alert(s);
		if ((s)&&(s!='')) {
		// don't save search history
			if(s=="null=1") {
				if(f.iNoHist){f.iNoHist.checked=true;}
				oLB.options.length=1;
			}	else {
				s=s.substr(5);
				sOpt = s.split('|');
				// clear LB
				oLB.options.length=1;
				for (i=0;i<sOpt.length;i++) {
					sNV = sOpt[i].split('~');
					sNV[0] = unescape(sNV[0]);
					if ((sNV[0]!='')&&(sNV[0]!=' ')&&(sNV[1]!='')&&(sNV[0]!=' ')) {
						oLB.options[i+1] = new Option(sNV[0],sNV[1]);
}	}	}	}	}	}

function cdRunSavedSearch(oLB) {
	var sT,sV;
	if ((oLB)&&(oLB.selectedIndex>0)&&(oLB.options[oLB.selectedIndex].value!='')){
		sT = oLB.options[oLB.selectedIndex].text;
		sV = unescape(oLB.options[oLB.selectedIndex].value);	
		cdRunSearch(0,sV,sT);
}	}

// --------------------- pop up tool tips -------------------------

var cdTipWidth=150; 			
var cdTipBGcolor='lightyellow';  
var cdTipDelay=500;  //  close (ms)
var cdTipY=10; 		
var cdTipX=-20; 	
var cdHiding,oMenu;
var ie4=document.all,ns6=document.getElementById&&!document.all;
function ieCompat(){return (document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;}
if (ie4||ns6) {document.write('<div id="cdTipDiv" class="ds" style="visibility:hidden;width:'+cdTipWidth+'px;"><div class="dsc" id="cdTipIHTML" onmouseover="cdTipCancelHide()" onmouseout="cdHideTip()" style="width:100%;background-color:'+cdTipBGcolor+'" ></div></div>');}
function cdShowTip(sHTML,oObj,e,cdTipWidth){
	if(window.event){event.cancelBubble=true}else{if(e.stopPropagation){e.stopPropagation();}}
	cdTipCancelHide();
	oMenu=document.getElementById?document.getElementById("cdTipDiv"):cdTipDiv;
	var oMenu2=document.getElementById?document.getElementById("cdTipIHTML"):cdTipIHTML;
	oMenu2.innerHTML=sHTML;
	if (ie4||ns6){
		cdTipShow(oMenu.style, e,"visible","hidden",cdTipWidth);
		oMenu.x=cdTipGetCoord(oObj, "x");
		oMenu.y=cdTipGetCoord(oObj, "y");
		oMenu.style.left=oMenu.x-clrFrame(oObj, "r")+"px";
		oMenu.style.top=oMenu.y-clrFrame(oObj, "b")+oObj.offsetHeight+"px";
}	}
function cdHideTip(){if (ie4||ns6){cdHiding=setTimeout("cdHideTipNow()",cdTipDelay);}}
function cdHideTipNow(e){if (typeof oMenu!="undefined"){if (ie4||ns6){oMenu.style.visibility="hidden";}}}
function cdTipCancelHide(){if (typeof cdHiding!="undefined") {clearTimeout(cdHiding);}}
function cdTipShow(obj, e, visible, hidden, cdTipWidth){
	if (ie4||ns6){oMenu.style.left=oMenu.style.top=-500;}
	if (cdTipWidth!=""){
		oMenu.oStyle=oMenu.style;
		oMenu.oStyle.width=cdTipWidth+'px';
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
		obj.visibility=visible
	}else{
		if (e.type=="click"){obj.visibility=hidden}
}	}
function cdTipGetCoord(oObj, iXY){
	var iCoord=(iXY=="x")? oObj.offsetLeft : oObj.offsetTop;
	var oParent=oObj.offsetParent;
	while (oParent!=null){iCoord=(iXY=="x")? iCoord+oParent.offsetLeft : iCoord+oParent.offsetTop;oParent=oParent.offsetParent;}
	return iCoord;
}
function clrFrame(oObj, frameXY){
	var edgeoffset=(frameXY=="r")?parseInt(cdTipX)*-1:parseInt(cdTipY)*-1;
	if (frameXY=="r"){
		var windowedge=ie4 && !window.opera? ieCompat().scrollLeft+ieCompat().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		oMenu.contentmeasure=oMenu.offsetWidth;
		if (windowedge-oMenu.x < oMenu.contentmeasure){edgeoffset=oMenu.contentmeasure-oObj.offsetWidth;}
	}else{
		var windowedge=ie4 && !window.opera? ieCompat().scrollTop+ieCompat().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		oMenu.contentmeasure=oMenu.offsetHeight;
		if (windowedge-oMenu.y < oMenu.contentmeasure){edgeoffset=oMenu.contentmeasure+oObj.offsetHeight+5;}
	}
	return edgeoffset
}


// --------------------- image pop ups-------------------------

var imgDelay = 0;				
var linkOutTimeout = 400;	
var imgOutTimout = 200;		
var imgMaxSize = 5000;
var displayPos = "L"
var ImgOutId = -1;
var linkOutTimeoutId = -1;
var imgOutTimoutId = -1;
var AdImageURLs = new Array();
var dImages = new Array();

function setimgMaxSize(iX){
	if (document.MyControl.iimagesize){
		iX=document.MyControl.iimagesize.value;
	}
	iX = 1 * iX;
	if (iX < 1) {iX=5000;}
	imgMaxSize=iX;
}


function addImageURL(iX, imageURL, linkURL){
	if(dImages[iX] == null){dImages[iX] = new Array();}
	dImages[iX] = new Image();
	dImages[iX].src = imageURL;
	if(AdImageURLs[iX] == null){AdImageURLs[iX] = new Array();}
	AdImageURLs[iX] = linkURL;
}
function daIsLoaded(iX){
	if(document.images["AdImage"].complete){
		document.images["AdImage"].style.display = "";
		document.getElementById("AdDivLoading").style.display = "none";
		resizeImg(iX);
	//	positionImage('');
	} else {
		window.setTimeout("daIsLoaded(" + iX + ")", 333);
}	}
// display ad - mouse out
function daOut(){
	if(ImgOutId != -1){
		clearTimeout(ImgOutId);
		ImgOutId = -1;
	}else{
		linkOutTimeoutId=window.setTimeout("closeImg()", linkOutTimeout);
}	}
// display ad - show on mouse over
function daOver(oObj,e,iX) {
	if(document.images["AdImage"]) {
		if(window.event){event.cancelBubble=true}else{if(e.stopPropagation){e.stopPropagation();}}
		if(linkOutTimeoutId != -1) {
			clearTimeout(linkOutTimeoutId);
			linkOutTimeoutId = -1;
		}
		if(imgOutTimoutId != -1){
			clearTimeout(imgOutTimoutId);
			imgOutTimoutId = -1;
		}		
		if(document.images["AdImage"].src != dImages[iX].src){		
			document.images["AdImage"].src = "";
			document.images["AdImage"].src = dImages[iX].src;
			document.images["AdImage"].galleryImg = false;

			if(!document.images["AdImage"].complete){
				document.images["AdImage"].style.display = "none";
				document.getElementById("AdDivLoading").style.display = "block";
				window.setTimeout("daIsLoaded(" + iX + ")", 333);
			}
			resizeImg(iX);
			document.getElementById("AdAnchor").href = AdImageURLs[iX];
		} 
		else {resizeImg(iX);}   // TESTING ONLY
		positionImg(e);		
		document.getElementById("AdDiv").style.visibility = "visible";	
		ImgOutId = -1;
}	}

function positionImg(e){	
	var oAdDiv=document.getElementById?document.getElementById("AdDiv"):'AdDiv';
	if (!oAdDiv) return;
   	var posX = 0, posY = 0;
   	if (!e) e = window.event;
   	if (e) {
      if ( typeof(e.pageX) == 'number' ) {
         posX = e.pageX; posY = e.pageY;
      } else if ( typeof(e.clientX) == 'number' ) {
         posX = e.clientX; posY = e.clientY;
         if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {
            posX += document.body.scrollLeft; posY += document.body.scrollTop;
         } else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {
            posX += document.documentElement.scrollLeft; posY += document.documentElement.scrollTop;
   }	}	}
   var scrollX = 0, scrollY = 0;
   if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) ) {
      scrollX = document.body.scrollLeft; scrollY = document.body.scrollTop;
   } else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) ) {
      scrollX = document.documentElement.scrollLeft; scrollY = document.documentElement.scrollTop;
   }
   var winWidth = 0, winHeight = 0;
   if (window.innerWidth && window.innerHeight) {
      winWidth = window.innerWidth; winHeight = window.innerHeight;
   } else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
      winWidth = document.documentElement.clientWidth; winHeight = document.documentElement.clientHeight;
   } else if (document.body && document.body.clientWidth && document.body.clientHeight) {
      winWidth = document.body.clientWidth; winHeight = document.body.clientHeight;
   }
   if (oAdDiv.offsetWidth && oAdDiv.offsetHeight) {
	  var oWidth = oAdDiv.offsetWidth, oHeight = oAdDiv.offsetHeight;
	  // X POS: space to right 
      if (posX - scrollX + oWidth + 20 < winWidth) {posX = posX + 25;}
      // otherwise
      else {posX = posX - (oWidth - (winWidth - (posX - scrollX)));} 	  
      // Y POS: small window: image has to go at top
      if (oHeight > winHeight) {posY = scrollY;}
      // room below link
      else if (winHeight - (posY - scrollY) > (oHeight-20)) {posY = posY-30;}
      // else min overlap at top 
      else {posY = posY - (oHeight - (winHeight - (posY - scrollY))) - 10;} 
   }
   oAdDiv.style.left = posX + "px"; oAdDiv.style.top = posY + "px";
}
 
function resizeImg(iX) {
//	dImages[iX].width = '';
//		alert(dImages[iX].width + ' x ' + dImages[iX].height);
		var hR = dImages[iX].height/imgMaxSize;
	var wR = dImages[iX].width/imgMaxSize;
	var iW = dImages[iX].width
	var iH = dImages[iX].height;
	if((hR > 1) || (wR > 1)) {if (hR >= wR) {iH=iH/hR; iW=iW/hR;} else {iH=iH/wR;iW=iW/wR;}} 
	document.images["AdImage"].height = iH;
	document.images["AdImage"].width = iW;
//	alert(iW + ' x ' + iH);
}

function closeImg(){
	document.getElementById("AdDiv").style.visibility = "hidden";
	ImgOutId = -1;
	linkOutTimeoutId = -1;
	imgOutTimoutId = -1;
}
// popup - mouseover
function daImgOver(){
	// stop the image from being closed.
	clearTimeout(linkOutTimeoutId);
	clearTimeout(imgOutTimoutId);
	linkOutTimeoutId = -1;
	imgOutTimoutId = -1;
}
// popup - mouseout
function daImgOut(){
	imgOutTimoutId = window.setTimeout("closeImg()", imgOutTimout);
}
