//document.load=load;
//document.onfocus=load;
function load() {
	if (!(document.getElementById || document.all || document.layers)) return;
	document.forms[0].elements[0].focus();
	if (document.forms[1]) {
	document.forms[1].elements[0].focus();
		breedsSelect=document.forms[1].elements['breed[]'];
		for(i=0; i<breedsSelect.length; i++) 
			if(breedsSelect.options[i].selected)
				breedsSelect.options[i].selected=true;
		if(document.forms[1].regcode.selectedIndex>-1)
			showRatings();
	}
} 

function goBack() {
	if(history.length>0)
		return('<a href="javascript:history.go(-1)">Go back</a>');
	else return('');
}

function showLinks() {
	if (!(document.getElementById || document.all || document.layers)) return;
	document.write('<a href="#breed" onclick="return showBreeds(0,0);">Show All breeds</a><br />');
	document.write('<a href="#breed" onclick= "return showBreeds(1,0);">Show AKC-recognized breeds</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,1);">AKC Sporting Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,2);">AKC Hound Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,3);">AKC Working Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,4);">AKC Terrier Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,5);">AKC Toy Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,6);">AKC Non-Sporting Group</a><br />');
	document.write('- <a href="#breed" onclick="return showBreeds(1,7);">AKC Herding Group</a><br />');
	document.write('<a href="#breed" onclick="showBreeds(2,0);">Show only cat breeds</a><br />');
}

function getObjectByID(id) {
	if (document.getElementById) {	// W3C DOM
		this.obj = document.getElementById(id);
		this.style = document.getElementById(id).style;
		}
	else if (document.all) { 		// IE4+
		this.obj = document.all[id];
		this.style = document.all[id].style;
	}
	else if (document.layers) {		// NS4+
		this.obj = document.layers[id];
   		this.style = document.layers[id];
   	}
}

// The following encodes the breed lists for the highest-level and group-level
// menus. Note that an AKC breed can be shown in more than one group (see Poodles)
var groups=
	['', 	// show all breeds
	[[''],	// show all AKC-recognized breeds
	 ['IWS','CR','LR','WG','EPT','CS','WS','CLS','GR','WE','GSP','BS','FR','VZ','IR','GWP','EC','FS','GSE','EN','SI','AWS','SU','ES','CB','DTR'],	// Group 1 - Sporting
	 ['AF','AH','BE','BH','BJ','BL','BZ','CN','DH','FH','GH','HA','IH','IW','PBG','NE','OH','PH','PL','RR','SDH','SL','WP'],				// Group 2 - Hounds
	 ['AM','AK','ANS','BMD','BMF','BX','BRU','DP','GD','GP','GMP','GSC','KU','KO','MF','NMF','NF','SA','RO','PW','SMH','SB','SC','SH','TM'],				// Group 3 - Working
	 ['AT','AUT','BD','BLT','BRT','CT','DD','FT','GIT','IRT','JT','KT','LAK','MBT','MSC','MT','NFT','NT','SBT','SEL','ST','STA','SYT','WF','WH','WHT','WT'], // Group 4 - Terriers
	 ['PO','MT','PN','PA','PG','PK','ML','IT','CH','YT','HAV','KCS','SKT','SHT','JS','MP','CHC','ET','BG','AFP','TFT'],					// Group 5 - Toy
	 ['PO','BU','SHU','TS','CC','BTR','LA','DM','FBU','LO','SP','BCF','KE','FNS','SK','TT','AE'],							// Group 6 - Non-Sporting
	 ['ACD','AS','BC','BEU','BM','BT','BSD','BF','BCO','CA','CO','FB','GS','PON','PU','SD','SS','VG','WCC','WCP'],						// Group 7 - Herding
	 ['RCN','DTR','GMP','GIT','TFT','BEU','BRU','NMF']],
	[['HP','HI','PC','ABY','DRC','BGT','BEC','HBO','MCC','TAC','CHR','BSC','SIM','SO']]];	// cat breeds

var breedsList;
function showBreeds(groupType,groupNumber) {
	if (!(document.getElementById || document.all || document.layers)) return;
	var breedsSelect=document.forms[1].elements['breed[]'];
	// before deleting the select list from the screen, save it
	// in memory
	if(!breedsList) {
		breedsList=new Array();
		for(i=0; i<breedsSelect.length; i++) {
			var breedCode=breedsSelect.options[i].value;
			var breedText=breedsSelect.options[i].text;
			breedsList[i]=[breedCode,breedText];
		}
	}
	// If groupType==0 [the default], we want to display the whole list
	if(groupType==0) {
		for(i=0; i<breedsList.length; i++) {
			breedsSelect.options[i]=
				new Option(breedsList[i][1],breedsList[i][0]);
		}
		return true;
	}
	// Otherwise we want to display the appropriate top-level list,
	// i.e. AKC or cats
	else {
		for (i=breedsSelect.options.length-1; i>=0; i--) {
			breedsSelect.options[i]=null;
		}

		if(groupNumber==0) {
			var set=groups[groupType];
			var group=new Array();
			var counter=0;
			for (i=0; i<set.length; i++) {
				if(set[i]) {
					var row=set[i];
					for(j=0; j<row.length; j++) {
						if(row[j]) {
							group[counter++]=row[j];
						}
					}
				}
			}
		} 
		// Otherwise we'll display a group-level menu
		else {
			group=groups[groupType][groupNumber];
		}
		for(i=0; i<breedsList.length; i++) {
			for (j=0; j<group.length; j++) {
				if(breedsList[i][0]==group[j]) {
					breedsSelect.options[breedsSelect.length]=
						new Option(breedsList[i][1],breedsList[i][0]);
					break;
				}
			}
		}  
	}  
	return true;
} 

var ratingList;
function showRatings() {
	if (!(document.getElementById || document.all || document.layers)) return;
	var regcode=document.forms[1].regcode[document.forms[1].regcode.selectedIndex].value;
	var ratingSelect=document.forms[1].elements['rating[]']; 
	var selectedRatings=new Array();
	if(!ratingList) {
		ratingList=new Array();
		counter=0;
		for(i=0; i<ratingSelect.length; i++) {
			if(ratingSelect.options[i].selected)
				selectedRatings[counter++]=ratingSelect.options[i].value;
			var ratingCode=ratingSelect.options[i].value;
			var ratingText=ratingSelect.options[i].text;
			ratingList[i]=[ratingCode,ratingText];
		}
	}

	// Here is where the actual updating of the select list takes place
	for (i=ratingSelect.options.length-1; i>=0; i--) {
		ratingSelect.options[i]=null;
	}
	var regexp = /(.*):/;
	for(i=0; i<ratingList.length; i++) {
		var regcode2=regexp.exec(ratingList[i][0]);
		if(regcode2 && regcode==regcode2[1]) {
			ratingSelect.options[ratingSelect.length]=
				new Option(ratingList[i][1],ratingList[i][0]);
		}
	}
	for(i=0; i<ratingSelect.length; i++) {
		for(j=0; j<selectedRatings.length; j++) {
			if(ratingSelect.options[i].value==selectedRatings[j])
				ratingSelect.options[i].selected=true;
		}
	}
	return true;
} 
