//* Copyright (c) 2000-2008 Cyber-dynamics International Inc. All Rights Reserved. *//
//* info@cyber-dynamics.com *//

window.defaultStatus=document.title;

var sSrchCookie='srchcookie',bFront=0,bStatic=0,bAdvanced=0,sSearchString;
// 2010 
var iGvtPage=2,bIsRefineSrch=0;
function cdAdvanced() {}

$(document).ready(function(){
	$(".menu > li").click(function(e){
		$(".fptb").removeClass("active"); // fptb = front page tab bar
		$(".fpt").hide(); // fpt = front page tab content
		var s=e.target.id;
		$("#"+s).addClass("active");
		$("div."+s).show();
		$('input[id=typ]').val(s);
	return false;
	});
});
function cdShowGovtImage(iX,iScTh) {
	if ((iX>0)&&(document.images['gpmain'])){
		document.images['gpmain'].src='/directory/govt10/gp'+iX+'.png';
		var d=document.getElementById('gpno').innerHTML=iX;
		if(iScTh==1) {document.getElementById('gp'+iX).scrollIntoView();self.location='#gtop';}	
}	}
// 2010
var bIsReverseLU=0;

var sURLStreets = '/directory/cdDirStreets.txt';
var sURLPlaces = '/directory/cdDirPlaces.txt';
var sURLCategories = '/directory/cdDirCategories.txt';

// LOCAL OR REMOTE
//var sURLScript  = '/directory/search10';
var sURLScript  = '/cgi-bin/cdDirectory-10.cgi';
	 
// strings
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;}}}	
// init
function init() {
	if (iGvtPage) {cdShowGovtImage(iGvtPage,1);}
	cdExtractSearch();	
	getImages();
	// 2010
	document.MyControl.srchQty.value=10;	
	setimgMaxSize();	
	if (bSupportsOptions!=1){cdCheckSupportsOptions(document.MyControl.iHistory);}
	cdGetSearchHistory(document.MyControl.iHistory);
}
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 cdRBget(fm,sRBname) {
	var sVal='';
	for (var i=0; i<fm.length;i++) {
		if ((fm.elements[i].type=='radio')&&(fm.elements[i].name==sRBname)&&(fm.elements[i].checked)){
				sVal=fm.elements[i].value;
				break;
	}	} 
	return(sVal);
}
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;
		}	}	}	}	
		// show active tab
		$(".fptb").removeClass("active"); // fptb = tab bar
		$(".fpt").hide(); // fpt = front page tab content
		s=$('input[id=typ]').val();
		$("#"+s).addClass("active");
		$("div."+s).show();
		fm.rl2.value=fm.rl.value;
}	}	
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 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);}
}}
//  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);}
}	
function cdStartSearch(i) {
	var f = document.MyControl,sTyp=f.typ.value;
	if (bIsRefineSrch==1) {
		sTyp=cdRBget(f,'typ2');
		f.typ.value=sTyp;
		f[sTyp].value=f.ypn2.value;
		f.lc.value=f.lc2.value;
	}else if (bIsReverseLU==1) {
		sTyp='rl';
		f.typ.value=sTyp;
		f[sTyp].value=f.rl2.value;
		f.lc.value='';	
	}
	var sVal=f[sTyp].value,sLoc=f.lc.value,s='',sT;		
	if (cdIsBlank(sVal)) {
		if (sTyp=='ypt') {alert('Please enter a business type for us to search against');return(false);}
			else{alert('Please enter a name for us to search against');return(false);}
	}
	if (sTyp=='rl') {cdStartReverseLookUp(i);return(false);}	
	if(sTyp=='gpn'){sT='G:';}else if (sTyp=='wpn'){sT='R:';}else{sT='B:';}	
	sT += sVal;			
	if (!cdIsBlank(sLoc)){sT+=' (' + sLoc + ')';}	
	cdRunSearch(i,'',sT);
}		
function cdStartReverseLookUp(i) {
	var f=document.MyControl,sRL=f.rl.value;
	if (sRL.length<2)	{alert('Please enter a PO Box No., post code, phone no., email address or web site address');return(false);} else {
		var sT='LU:'+sRL;
		sRL=encodeURIComponent(sRL);
		sRL=sRL.replace(/\'/g,'');
		var sSch='typ=rl&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,'..');
}
// 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)) {cdStartSearch();}}
document.onkeypress = cdKeyPress;

// 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;
}	}	}
//* 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 cdDisableSearchHistory(oLB,bDisable){
	if (bDisable) { 
		saveCookie(sSrchCookie,'null=1',180);
		oLB.options.length=1;
	}else{
		saveCookie(sSrchCookie,'',0);
	//	deleteCookie(sSrchCookie); // remove null=1
}	}
function cdSaveSearch(oLB,sV,sT) {
//alert('about to save');
	if (document.MyControl.iNoHist.checked==true) { 
		// don't save search history
		
	} else if ((sV != '')&&(sT != '')&&(sT != '..')&&(bSupportsOptions)&&(oLB)) { 		
		var iFound=-1,i,iLBlen=oLB.options.length;
		// 201001: unescape ... server sending escaped cat strings
		sT=unescape(sT);	
		// 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!='')&&(oLB.options[i].value!='Loading...')){sCk+=escape(oLB.options[i].text)+'~'+oLB.options[i].value+'|';}}
//alert('saving cookie '+sCk);
		saveCookie(sSrchCookie,'srch='+sCk,180);
}	}		
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 if (oObj.options[i].text == 'Loading...'){
				//
			}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 cdGetSearchHistory(oLB){
	var f = document.MyControl;
	if(bSupportsOptions){
		var i,s=getCookie(sSrchCookie),sOpt=new Array(),sNV=new Array();
		if (s=='') {
			if(!supportsCookies()) {
				oObj.options[1].text='No Browser Support';
			} else { 
				oLB.options.length=1;
//alert('read empty cookie');
		} } else if (s=="null=1") {// don't save search history
				if(f.iNoHist){f.iNoHist.checked=true;}
				oLB.options.length=1;
//alert('Cookie says dont save cookies');
		} else {
				s=s.substr(5);
//alert('found cookie '+s);				
				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[0]!='Loading...')&&(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!='')&&(oLB.options[oLB.selectedIndex].text!='Loading...')){
		sT = oLB.options[oLB.selectedIndex].text;
		sV = unescape(oLB.options[oLB.selectedIndex].value);	
		cdRunSearch(0,sV,sT);
}	}
function cdRunSavedSearch2(iX) {
	var oObj=document.MyControl.iHistory;
	if (oObj.options[iX].text != 'Loading...'){
		oObj.options[iX].selected = true;
		cdRunSavedSearch(oObj);
}	}
// --------------------- pop up tool tips -------------------------

var cdTipWidth=150; 			
var cdTipBGcolor='lightyellow';  
var cdTipDelay=500;  //  close (ms)
var cdTipY=5; 		
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;
	
// 	alert('added image ' + imageURL);
}
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);
}
// 2010 cookies 
function saveCookie(name,value,days) {if (days) {var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = ";expires="+date.toGMTString();}else{var expires="";}document.cookie=name+"="+value+expires+";path=/";}
function getCookie(name) {var nameEQ=name+"=",ca=document.cookie.split(';');for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		while(c.charAt(0)==' '){c=c.substring(1,c.length);}
		if (c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}
}return '';}
function supportsCookies(name){var sC='test',sT='text=hello';saveCookie(sC,sT);var sC=getCookie(sC);return(sC=sT);}
function deleteCookie(name){saveCookie(name,"",-1);}