// javascript function library for sausalitobb.com


// rollover scriptcs

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		btn_home_o = newImage("images/btn_home_o.gif");
		btn_sanfran_o = newImage("images/btn_sanfran_o.gif");
		btn_monterey_o = newImage("images/btn_monterey_o.gif");
		btn_location_o = newImage("images/btn_location_o.gif");
		btn_reservations_o = newImage("images/btn_reservations_o.gif");
		btn_jacuzziapts_o = newImage("images/btn_jacuzziapts_o.gif");
		btn_slash_btn_reservations_o = newImage("images/btn_slash_btn_reservations_.gif");
		banner_photo01_jpg_btn_doublejacuzzi_o = newImage("images/banner_photo01.jpg_btn_doub.jpg");
		preloadFlag = true;
	}
}

 //validate subscription form
function winners_validate(){
	missinginfo = "";
	if (document.forms[1].bt_name.value == "") {
		missinginfo += "\n   -  Name";
	}
	if (document.forms[1].password.value == "") {
		missinginfo += "\n   -  Password";
	}

	if (document.forms[1].bt_city.value == "") {
		missinginfo += "\n   -  City";
	}
	if (document.forms[1].bt_address.value == "") {
		missinginfo += "\n   -  Address";
	}
	if (document.forms[1].phone.value == "") {
		missinginfo += "\n   -  Phone";
	}
	if (document.forms[1].fax.value == "") {
		missinginfo += "\n   -  Fax";
	}
	if (document.forms[1].bt_zip.value == "") {
		missinginfo += "\n   -  Zip or Postal Code";
	}
	if (document.forms[1].bt_state.selectedIndex == "0") {
		missinginfo += "\n   -  State or Province";
	}
	if (document.forms[1].bt_country.selectedIndex == "0") {
		missinginfo += "\n   -  Country";
	}

	if ((document.forms[1].email.value == "") ||
		(document.forms[1].email.value.indexOf('@') == -1) ||
		(document.forms[1].email.value.indexOf('.') == -1)) {
			missinginfo += "\n   -  Email Address";
	}


	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

// control date input on field

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

String.prototype.padL = function (nLength, sChar) {
  var sreturn = this;
  while (sreturn.length < nLength) {
    sreturn = String(sChar) + sreturn;
  }
  return sreturn;
}

function date_onkeydown() {
  if (window.event.srcElement.readOnly) return;
  var key_code = window.event.keyCode;
  var oElement = window.event.srcElement;
  if (window.event.shiftKey && String.fromCharCode(key_code) == "T") {
        var d = new Date();
        oElement.value = String(d.getMonth() + 1).padL(2, "0") + "/" +
                         String(d.getDate()).padL(2, "0") + "/" +
                         d.getFullYear();
        window.event.returnValue = 0;
    }
    if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
        if ((key_code > 47 && key_code < 58) ||
          (key_code > 95 && key_code < 106)) {
            if (key_code > 95) key_code -= (95-47);
            oElement.value =
                oElement.value.replace(/[mdy]/, String.fromCharCode(key_code));
        }
        if (key_code == 8) {
            if (!oElement.value.match(/^[mdy0-9]{2}\/[mdy0-9]{2}\/[mdy0-9]{4}$/))
                oElement.value = "mm/dd/yyyy";
            oElement.value = oElement.value.replace(/([mdy\/]*)[0-9]([mdy\/]*)$/,
                function ($0, $1, $2) {
                    var idx = oElement.value.search(/([mdy\/]*)[0-9]([mdy\/]*)$/);
                    if (idx >= 5) {
                        return $1 + "y" + $2;
                    } else if (idx >= 2) {
                        return $1 + "d" + $2;
                    } else {
                        return $1 + "m" + $2;
                    }
                } );
            window.event.returnValue = 0;
        }
    }
    if (key_code != 9) {
        event.returnValue = false;
    }
}
