//
// Default Javascript functions
//
// I should cycle through these a bit as I suspect many of the functions
// can be optimized, or at least the code size optimized.  As I also cycle
// through the main pages, I can improve these as well.
//

//
// Brings the current window on top of others
// This function seems to not always work.
function stayontop() {
        window.focus();
        setTimeout("stayontop()", 10);//1000=1sec. Adjust seconds here
}

//
// Opens a new popup and puts it on top.
// Args:
//   url:    URL to open
//   targ:   Target name
//   opts:   Window Options (size, location, etc)
//           Passed as a string
function openpopup(url, targ, opts) {
	popup = window.open(url, targ, opts, replace=1);
	if (window.focus) {
		popup.focus();
	}
}

//
// Opens a help popup.
// The default sizes are defined here, and passed to openpopup.
// Args:
//   url:    URL that will be opened.
//   h:      Height of new box
//   w:      Width of new box
//
function help_popup(url, w, h) {
	opts = 'height=' + h + ', width=' + w + ', toolbar=0, menubar=0,';
	opts = opts + 'scrollbars=1, hotkeys=0, status=0, ';
	opts = opts + 'directories=0, dependant=1, resizeable=1, ';
	opts = opts + 'alwaysRaised=1';
	openpopup(url, 'help', opts);
}

//
// Opens a Zipcode Search popup.
// The main difference between this and help_popup is that this
// function needs to fetch the current zipcode in the form and feed
// it to the url.
// The default sizes are defined here, and passed to openpopup.
// Args:
//   url:    URL that will be opened.
//   h:      Height of new box
//   w:      Width of new box
//
function zip_popup(url, w, h, zip) {
	opts = 'height=' + h + ', width=' + w + ', toolbar=0, menubar=0,';
	opts = opts + 'scrollbars=1, hotkeys=0, status=0, ';
	opts = opts + 'directories=0, dependant=1, resizeable=1, ';
	opts = opts + 'alwaysRaised=1';
	if (zip != "") {
		url = url + "&zip=" + zip;
	}
	openpopup(url, 'help', opts);
}

// This is the default loadset for the help popups.
// Args:
//   secs:   Number of seconds till window closes
//
function helpdefaults(secs) { 
	var timeout = secs * 1000;
	setTimeout('window.close();', timeout);
}

//
// Opens a new browser window
// The default sizes are defined here, and passed to openpopup.
// Args:
//   url:    URL that will be opened.
//   h:      Height of new box
//   w:      Width of new box
//
function newwindow(url, w, h) {
	opts = 'height=' + h + ', width=' + w;
	openpopup(url, 'new', opts);
}

//
// Writes the string to the element "div"
//

function writediv(div, string) {
	window.document.getElementById(div).innerHTML = string;
}

//
// Sends the local information (city, state, zip, etc.) in the passed
// form to the specified form.  Callers can specify a different window.
//
function send_local(f, d, target) {
	if (target == "dog") {
	   if (f.state.options[f.state.selectedIndex].value != "") {
		d.dogstate.value = f.state.options[f.state.selectedIndex].value;
	   }
	   if (f.zip.value != "") {
		d.dogzip.value = f.zip.value;
	   }
	   if (f.region.value != "") {
		d.local_region.value = f.region.value;
	   }
	} else if (target == "contact") {
	   if (f.city.value != "") {
		d.city.value = f.city.value;
	   }
	   if (f.state.options[f.state.selectedIndex].value != "") {
		d.c_state.value = f.state.options[f.state.selectedIndex].value;
	   }
	   if (f.zip.value != "") {
		d.c_zip.value = f.zip.value;
	   }
	} else {
//	if (target == "org") {
	   if (f.city.value != "") {
		d.city.value = f.city.value;
	   }
	   if (f.state.options[f.state.selectedIndex].value != "") {
		d.state.value = f.state.options[f.state.selectedIndex].value;
	   }
	   if (f.zip.value != "") {
		d.zip.value = f.zip.value;
	   }
	   if (f.region.value != "") {
		d.local_region.value = f.region.value;
	   }
	}

	window.close();
}
