if(document.images) {
	for(i=1; i<=7; i++) {
		a = new Image(370,210);
		b = new Image(370,210);
		a.src = "/pics/"+i+"a.jpg";
		b.src = "/pics/"+i+"b.jpg";
	}
}

function LoadHiRes(html,width,height) {
	div = document.getElementById('hires');
	div.style.width  = width;
	div.style.height = height;
	div.innerHTML = "<font color=FFFFFF>Loading...</font>";
	div.innerHTML = html;
}

function HiRes(rg) {
	rg = document.getElementById('rgimg');
	var img = rg.src.match(/\/\d+\/\w\w-\d+.jpg/);
	window.open("/hires.htm?rg="+img,'_hires','width=880,height=600,resizable=1,toolbars=0,scrollbars=1');
	return;
}

function SearchBoats(fld) {
	// clear the options that we dont know about yet.
	fields = new Array('newused','type','make','model','year');
	var clr=0;
	var nxt=''; // this will store the name of the next field to populate the options in...
	for(i=0; i<fields.length; i++) {
		if(clr==1) {
			obj = eval("document.form."+fields[i]);
			for(x=obj.length; x>=0; x--) { obj[x] = null; }
			obj[0] = new Option('','');
		}
		if(fld == fields[i]) {
			clr =1;
			n=(i+1);
			if(fields[n]) { nxt=fields[n]; }
		}
	}

	// build our query string to get the search results...
	var qry = "";
	es = eval("document.form.elements");
	for(i=0; i < es.length; i++) {
		k = es[i].name;
		v = urlencode(es[i].value);
		qry+=""+k+"="+v+"&";
	}


	var nc = new Date().getTime();
	var http = null;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET","/boatsales.htm?dosearch="+nc+"&"+qry+"fld="+fld,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			if(http.responseText) {
				div = document.getElementById('results');
				div.innerHTML=http.responseText;
				var lines = new Array();
				lines = http.responseText.split('OPTIONS');
				if(lines.length==3) {
					var pairs = new Array();
					pairs = lines[1].split('|');
					if(pairs.length > 0) {
						obj = eval("document.form."+nxt);
						obj[0] = null;
						if(pairs.length > 1) {
							obj[0] = new Option('...please select...','%');
							obj[0].style.color='0099CC';
						}
						for(p=0; p<pairs.length; p++) {
							var kv = new Array(2);
							kv = pairs[p].split('=');
							obj[obj.length] = new Option(kv[1],kv[0]);
						}
					}
				}
			}
		}
		if(pairs) {
			if((fld != 'year') && (pairs.length==1) && (nxt)) {
				SearchBoats(nxt);
			}
		}
	}
	http.send(null);
	return;
}

function GetOptions(fld,qry) {
	var nxt = "";
	var myFields = new Array('type','make','model','year');
	for(i=0; i<myFields.length; i++) {
		if(myFields[i] == fld) {
			i++; nxt = myFields[i];
		}
	}
	var nc = new Date().getTime();
	var http = null;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET","/getoptions.htm?nc="+nc+"&"+qry+"&fld="+fld,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			myPairs = http.responseText.split('|');
			if(myPairs.length > 0) {
				obj = eval("form."+fld);
				for(i=obj.length; i>=0; i--) { obj[i] = null; }
				if(myPairs.length > 1) {
					obj[0] = new Option('...please select one...','');
				}
				for(x=0; x<myPairs.length; x++) {
					var kv = new Array(2);   
					kv = myPairs[x].split(':');
					obj[obj.length] = new Option(kv[1],kv[0]);
				}
			}
		}
	}
	http.send(null);
	return;
}

function dumpProps(obj,parent) {
	var str = "";
	if(typeof obj == "object") {
		for (var i in obj) {
			if(typeof obj[i] == "object") {
				// dumpProps(obj[i],parent+"."+i);
			} else {
				str+=parent+"."+i+"="+obj[i]+"\n";
			}
		}
	} else {
		str+=parent+" is a string";
	}
	newWin = window.open('','new','width=800,height=800,resizable=1,scrollbars=1');
	newWin.document.write("<pre>"+str+"</pre>");
}

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function RgImage(id,tm) {
	img = document.getElementById('rgimg');
	img.src = "/pics/boats/"+id+"/rg-"+tm+".jpg";
}

function RowClick(id,bg) {
	// if(id == form.clickrow.value) { return; }
	if(form.clickrow.value > 0) {
		row = document.getElementById("row"+form.clickrow.value);
		row.style.backgroundColor = form.clickclr.value;
	}
	form.clickrow.value = id;
	form.clickclr.value = bg;
	row = document.getElementById("row"+id);
	row.style.backgroundColor='#7FCCE5';
	row.style.cursor='pointer';	
	ShowBoat(id);
}

function RowOver(id,bg) {
	if(id == form.lastrow.value) { return; }
	if(id == form.clickrow.value) { return; }
	if((form.lastrow.value > 0) && (form.lastrow.value != form.clickrow.value)) {
		row = document.getElementById("row"+form.lastrow.value);
		row.style.backgroundColor = form.lastclr.value;
	}
	form.lastrow.value=id;
	form.lastclr.value = bg;
	row = document.getElementById("row"+id);
	row.style.backgroundColor='#CCEBF5';
	row.style.cursor='pointer';
}

function ShowBoat(id) {
	div = document.getElementById('show');
	div.innerHTML= "Loading...";
	var nc = new Date().getTime();
	var http = null;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET","/boatsales.htm?showboat=1&id="+id+"&nc="+nc,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			if(http.responseText) {
				div.innerHTML = http.responseText;
			}
		}
	}
	http.send(null);
	return;
}

function CheckCursor() {
	img = document.getElementById('img_a');
	if(img.src.match(/2a.jpg/)) {
		document.getElementById('img_a').style.cursor='pointer';
		document.getElementById('img_b').style.cursor='pointer';
	} else {
		document.getElementById('img_a').style.cursor='normal';
		document.getElementById('img_b').style.cursor='normal';
	}		
}

function ClickImage(ab) {
	var url = "";
	img = document.getElementById('img_'+ab);
	if(img.src.match(/2a.jpg/)) { url="boatsales.htm?newused=new"; }
	if(img.src.match(/2b.jpg/)) { url="boatsales.htm?newused=used"; }
	if(! url) { return; }
	div = document.getElementById('main');
	div.innerHTML= "Loading...";
	var nc = new Date().getTime();
	var http = null;
	try { http=new XMLHttpRequest(); }
	catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
	if (http==null) { alert ("Your browser does not support AJAX!"); return; }
	http.open("GET",url+"&nc="+nc,true);
	http.onreadystatechange = function() {
		if(http.readyState==4) {
			if(http.responseText) {
				div.innerHTML = http.responseText;
			}
		}
	}
	http.send(null);
	return;
}

function GetPage(id) {
	var nc = new Date().getTime();

	if(! document.getElementById('page')) {
		div = document.getElementById('main');
		div.innerHTML= "Loading...";
		var http = null;
		try { http=new XMLHttpRequest(); }
		catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
		if (http==null) { alert ("Your browser does not support AJAX!"); return; }
		http.open("GET","/getpage.htm?temp=main&id="+id+"&nc="+nc,true);
		http.onreadystatechange = function() {
			if(http.readyState==4) {
				if(http.responseText) {
					div.innerHTML = http.responseText;
				}
			}
		}
		http.send(null);
	} else {
		div = document.getElementById('page');
		div.innerHTML= "Loading...";
		var http = null;
		try { http=new XMLHttpRequest(); }
		catch (e) { try { http=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { http=new ActiveXObject("Microsoft.XMLHTTP"); } }
		if (http==null) { alert ("Your browser does not support AJAX!"); return; }
		http.open("GET","/getpage.htm?id="+id+"&nc="+nc,true);
		http.onreadystatechange = function() {
			if(http.readyState==4) {
				if(http.responseText) {
					div.innerHTML = http.responseText;
				}
			}
		}
		http.send(null);
	}

	// no pics for news and hours page...
	if((id=='10') || (id=='11')) { return; }
	if(eval("document.getElementById('img_a')")) {
		document.getElementById('img_a').src = "/pics/"+id+"a.jpg";
		document.getElementById('img_b').src = "/pics/"+id+"b.jpg";
	}
	return;
}

function Directions() {
	var url = "http://www.mapquest.com/maps/map.adp?country=US&addtohistory=&address=14603+featherstone&city=woodbridge&state=VA&zipcode=22191&homesubmit=Get+Map";
	window.open(url,'_new','width=800,height=600,resizable=1');
}
