

// globals

pagename = "";

function gObj(me) {
	if (document.getElementById) {
	return document.getElementById(me);
	}
}

function gImg(me) {
	if (document.images) {
	return document.images[me];
	}
}

// image swap

function imgOn(a, h) {	
	h = typeof(h) != 'undefined' ? h : '';	
	gImg(a).src = h + "images/nav/" + a + "_on.jpg";
}

function imgOff(b, h) {
	h = typeof(h) != 'undefined' ? h : '';
	if ((pagename == b)&&(window.name == "oc_visited")) {
		gImg(b).src = h + "images/nav/" + b + "_on.jpg";
	} else {
		gImg(b).src = h + "images/nav/" + b + "_off.jpg";
	}
}

function trailImgOn(a, h) {
	h = typeof(h) != 'undefined' ? h : '';
	gImg(a).src = h + "images/order_trail/" + a + "_on.gif";
}

function trailImgOff(b, h) {
	h = typeof(h) != 'undefined' ? h : '';
	gImg(b).src = h + "images/order_trail/" + b + "_off.gif";
}

function allOff(h) {
	h = typeof(h) != 'undefined' ? h : '';
	var i;
	for (i = 0; i < imgarr.length; i++) {
		var c = imgarr[i];
		gImg(c).src = h + "images/nav/" + c + "_off.jpg";
	}
}

// header blurbs

function hiLite(lk) {
	gObj('head_'+lk).className = "on";
	gObj('lk_'+lk).className = "blurbon";
}

function hiLiteOff(lk) {
	gObj('head_'+lk).className = (((pagename == "save" )&&(lk == "left")) || ((pagename == "others" )&&(lk == "right"))) ? "on" : "none";
	gObj('lk_'+lk).className = "blurb";
}

function goTo(url) {
	window.location.href = url;
}

// form page functions 

// show invoice / hide invoice 

function showInv() {
	var inv = gObj('invDiv');
	inv.style.visibility = 'visible';
}

function hideInv() {
	var inv = gObj('invDiv');
	inv.style.visibility = 'hidden';
}

function openPpWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function keyCheck(field, event) {
	var keyCode = (event.keyCode) ? event.keyCode : ((event.which) ? event.which : event.charCode);
	if ((keyCode != 13)&&(keyCode != 3)) {
    	return true;
	}
	else {
    	return false;
	}
}

function ckNumKeyPress(field, event) {
	var keyCode = (event.keyCode) ? event.keyCode : ((event.which) ? event.which : event.charCode);
	// numbers
	if ((keyCode >= 48)&&(keyCode <= 57)) {  
		return true;
	// delete
	} else if (keyCode == 8) {
		return true;
	}
	return false;
}

function ckAlphaNumKeyPress(field, event) {  // ok for "@", delete, space, comma, period, dash, parentheses
	var keyCode = (event.keyCode) ? event.keyCode : ((event.which) ? event.which : event.charCode);
	// numbers
	if ((keyCode >= 48)&&(keyCode <= 57)) {  
		return true;
	// cap letters and "@" symbol
	} else if ((keyCode >= 64)&&(keyCode <= 90)) {  
		return true;
	// l.c. letters
	} else if ((keyCode >= 97)&&(keyCode <= 122)) {  
		return true;
	// comma, dash, period
	} else if ((keyCode >= 44)&&(keyCode <= 46)) {  
		return true;
	// delete, space, parentheses
	} else if ((keyCode == 8)||(keyCode == 32)||(keyCode == 40)||(keyCode == 41)) {
		return true;
	}
	return false;
}

function swMapImg(mp, h) {
	h = typeof(h) != 'undefined' ? h : '';
	var map_img = gImg('abcmap');
	map_img.src = h + "images/map/map_"+mp+".gif";
}

function clearNumHorses() {
	var theField = document.forms.orderform1['num_horses'];
	theField.value = '';
	gObj('holycow').style.display = "none";
	gObj('show_hide_div').style.visibility = "visible";
}

function copyAdd() {
	var theForm = document.forms['orderform2'];
	var fname = theForm['firstname'].value;
	var lname = theForm['lastname'].value;
	var add1 = theForm['address1'].value;
	var city = theForm['city'].value;
	var state = theForm['state'].options.selectedIndex;
	var zip = theForm['zip'].value;
	var sameadd = theForm['same_add'];
	if (sameadd.checked) {
		if ((fname == "")||(lname == "")||(add1 == "")||(city == "")||(state == "0")||(zip == "")) {
			alert("Please enter all the required (with *) billing-info fields before copying.");
			sameadd.checked = false;
			window.scrollTo(0,0);
		} else {
		theForm['firstname_shp'].value = fname;
		theForm['lastname_shp'].value = lname;
		theForm['company_shp'].value = theForm['company'].value;
		theForm['address1_shp'].value = theForm['address1'].value;
		theForm['address2_shp'].value = theForm['address2'].value;
		theForm['city_shp'].value = theForm['city'].value;
		theForm['state_shp'].options[state].selected = true;
		theForm['zip_shp'].value = theForm['zip'].value;
		}
	} else {
		theForm['firstname_shp'].value = "";
		theForm['lastname_shp'].value = "";
		theForm['company_shp'].value = "";
		theForm['address1_shp'].value = "";
		theForm['address2_shp'].value = "";
		theForm['city_shp'].value = "";
		theForm['state_shp'].options['0'].selected = true;
		theForm['zip_shp'].value = "";
	}
}

function whatIs() {
	var w = gObj('whatDiv');
	w.style.visibility = "visible";
}

function hideWhat() {
	var w = gObj('whatDiv');
	w.style.visibility = "hidden";
}

function ckCCKeyPress(field, event) {
	var keyCode = (event.keyCode) ? event.keyCode : ((event.which) ? event.which : event.charCode);
	// numbers
	if ((keyCode >= 48)&&(keyCode <= 57)) {  
		return true;
	// delete, or space
	} else if ((keyCode == 8)||(keyCode == 32)) {
		return true;
	}
	return false;
}

function chooseCard(cd) {
	var theForm = document.forms['orderform3'];
	theForm['card_type'].options[cd].selected = true;
	if (cd != "0") {
		var card_arr = new Array('visa','mc','disc');
		var i;
		for (i = 0; i < card_arr.length; i++) {
			theLink = gObj(card_arr[i] + "_link");
			if (i == cd-1) {
				theLink.className = "cclink_on";
			} else {
				theLink.className = "cclink";
			}	
		}
	}
}

function VF_form1(){ //v2.0
	var theForm = document.form1;
	var errMsg = "";
	var setfocus = "";

	if (((theForm['search'].value == "")&&((theForm['ins_b_date'].value == "")||(theForm['ins_e_date'].value == "")))||(((theForm['search'].value == "")&&theForm['ins_b_date'].value == "")&&(theForm['ins_e_date'].value == ""))) {
		errMsg = "Please enter search criteria, or choose 'from' and 'to' dates.";
		setfocus = "['search']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}





