rackrate = new Array();
rackrate[0] = [149,194,204,194,204,283,323,699,0,0,149,194,204,194,204,283,323,699,0,0,'Rack Rate'];

ratecard = new Array(); // Weekday - Weekend // Version 06.10
ratecard[0] = ['','','','','','','','','','','','','','','','','','','','','None Posted'];
ratecard[0] = [139,184,194,184,194,273,313,699,0,0,139,184,194,184,194,273,313,699,0,0,'Rack Rate - 3 night min'];
ratecard[1] = [139,184,194,184,194,273,313,699,0,0,139,184,194,184,194,273,313,699,0,0,'Rack Rate - 2 night min'];
ratecard[2] = [149,209,219,209,219,295,325,699,0,0,149,209,219,209,219,295,325,699,0,0,'Rack Rate'];
ratecard[3] = [82,105,110,105,110,149,169,475,0,0,82,105,110,105,110,149,169,475,0,0,'Internet Hot Date (50%)'];
ratecard[4] = [175,249,259,249,259,325,350,850,0,0,175,249,259,249,259,325,350,850,0,0,'Special Event'];
ratecard[5] = [53,63,73,53,63,82,88,300,0,0,53,63,73,53,63,82,88,300,0,0,'Extreme Hot Date (75%)'];
ratecard[6] = [79,129,139,129,139,189,205,525,0,0,89,149,156,149,156,215,241,525,0,0,'Internet Early-Late 2010'];
ratecard[7] = [209,279,289,279,289,340,375,875,0,0,209,279,289,279,289,340,375,875,0,0,'Major Event'];
ratecard[8] = [118,156,166,156,166,233,266,605,0,0,138,176,186,176,186,253,286,625,0,0,'Internet Summer'];
ratecard[9] = [79,129,139,129,139,189,205,525,0,0,89,149,156,149,156,215,241,525,0,0,'Internet Early-Late 2011'];
ratecard[10] = [269,289,299,289,299,378,450,1020,0,0,269,289,299,289,299,378,450,1020,0,0,'US Open'];

rates = new Array();
//                                       1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3
//                     1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1
rates[1]  = ['01-2010',3,3,3,3,6,6,6,3,3,3,3,6,6,6,3,3,6,3,3,3,6,6,6,6,6,6,6,6,3,3,3];
rates[2]  = ['02-2010',3,3,6,5,3,3,6,6,6,0,0,0,0,3,5,3,6,6,6,6,3,3,3,3,5,6,6,3,6,6,6];
rates[3]  = ['03-2010',6,6,6,6,6,6,5,5,5,5,5,6,6,6,3,6,6,6,6,6,3,5,3,3,3,6,6,6,3,3,6];
rates[4]  = ['04-2010',6,6,6,5,5,3,3,5,6,6,3,6,6,6,5,1,1,3,3,3,3,6,6,6,6,3,3,3,5,6,6];
rates[5]  = ['05-2010',6,5,5,5,5,3,6,6,6,6,6,3,6,6,6,3,3,3,3,3,6,6,6,6,6,6,6,1,1,3,5];
rates[6]  = ['06-2010',5,5,5,3,3,3,8,8,8,5,8,8,3,3,10,10,10,10,10,10,1,1,8,8,8,8,8,8,8,8,8];
rates[7]  = ['07-2010',8,1,1,1,1,8,8,8,8,8,8,8,8,8,8,4,4,4,8,8,8,8,7,7,7,8,8,8,8,8,8];
rates[8]  = ['08-2010',8,8,8,8,8,8,8,8,4,4,4,4,4,4,4,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];
rates[9]  = ['09-2010',8,8,1,1,1,1,8,8,8,8,8,8,8,8,8,8,8,8,8,1,1,1,1,8,8,8,8,8,8,8,8];
rates[10]  = ['10-2010',6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6];
rates[11]  = ['11-2010',6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,1,1,6,6,6,6];
rates[12]  = ['12-2010',6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,1,1,6,6,6,6,1];
//                                        1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3
//                      1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1
rates[13]   = ['01-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[14]   = ['02-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[15]   = ['03-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[16]   = ['04-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[17]   = ['05-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[18]   = ['06-2011',8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];
rates[19]   = ['07-2011',8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];
rates[20]   = ['08-2011',8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];
rates[21]   = ['09-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[22]  = ['10-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[23]  = ['11-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];
rates[24]  = ['12-2011',9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];

Mon3 = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
Day3 = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
DayFull = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
thecard = 0;

window.onload = init;

function init(){
if(!document.register){ return};
theform=document.register;
theform.reset();
theform.Instructions.value="";
with (theform)InitYMDselector(YrSel, MoSel, DySel)
}

function LengthOfMonth(Y, M) {
with (new Date(Y,M,1,12)) { setDate(0) ; return getDate() }
}

var D_Opt = new Array() // 29..31

function MonLen(Yr, Mo, Dy){
var Dol, K, DiM, NsI
DiM = LengthOfMonth(+Yr.options[Yr.selectedIndex].text,Mo.selectedIndex+1)
Dol = Dy.options.length
if ( (NsI = Dy.selectedIndex) >= DiM ) NsI = DiM-1
for (K=Dol ; K >DiM ; K--){ D_Opt[K] = Dy.options[K-1] ; Dy.options[K-1] = null }
for (K=Dol+1 ; K<=DiM ; K++)   Dy.options[K-1] = D_Opt[K]
Dy.selectedIndex = NsI
ChangeOfDay(Yr, Mo, Dy)
}

function InitYMDselector(Yr, Mo, Dy){

Now = new Date();
Base = new Date().getFullYear();
with (Now){Yr.selectedIndex = getFullYear()-Base;Mo.selectedIndex = getMonth();Dy.selectedIndex = getDate()-1}
MonLen(Yr, Mo, Dy);
InitDate=theform.Arrive.value;
}

function ChangeOfDay(Yr, Mo, Dy){
FutureDate(Yr, Mo, Dy);
getRate(Yr,Mo,Dy);
i=GetDayOfWeek(Yr, Mo, Dy);
WriteWeekday(i);
WriteNights(i);
WriteVisitLength();
getArrive(Yr,Mo,Dy);
writeRooms(Yr,Mo,Dy);
}

function getRate(Yr,Mo,Dy){
thesel=theform.RoomType.selectedIndex;
wknd=(GetDayOfWeek(Yr, Mo, Dy)>4)?10:0;

thecard = rates[(Yr.selectedIndex*12)+(Mo.selectedIndex+1)][Dy.selectedIndex+1];
theform.Discount.value=ratecard[thecard][20];
theform.RoomRate.value="$"+ratecard[thecard][thesel+wknd];
}

function writeRooms(Yr,Mo,Dy){
cardcolor=(thecard == 3 || thecard==3)? "#990000":"#000000"; // Hotdates or Holiday in Red
MM_changeProp('RoomType','','style.color',cardcolor);
thesel=theform.RoomType.selectedIndex;
i=theform.RoomType.options;
i.length = 0;
wknd=(GetDayOfWeek(Yr, Mo, Dy)>4)?10:0;
xx=" - $";
i[0]=new Option("Lodge Queen (Non Smoking) - Sleeps 2"+xx+ratecard[thecard][0+wknd],"Lodge Queen (Non Smoking)");
i[1]=new Option("Lodge 2 Double Beds - Sleeps 4"+xx+ratecard[thecard][1+wknd],"Lodge Double-Double");
i[2]=new Option("Lodge 2 Doubles + Fireplace - Sleeps 4"+xx+ratecard[thecard][2+wknd],"Lodge Double-Double (Fireplace)");
i[3]=new Option("Lodge King (Non Smoking) - Sleeps 2"+xx+ratecard[thecard][3+wknd],"Lodge King (Non Smoking)");
i[4]=new Option("Lodge King + Fireplace - Sleeps 2"+xx+ratecard[thecard][4+wknd],"Lodge King (FirePlace)");
i[5]=new Option("Suites Studio + Fireplace - Sleeps 2"+xx+ratecard[thecard][5+wknd],"Suites Studio (FirePlace)");
i[6]=new Option("Suites Junior + Fireplace - Sleeps 4"+xx+ratecard[thecard][6+wknd],"Suites Junior (FirePlace)");
i[7]=new Option("Residence 2 Bedrooms - Sleeps 6"+xx+ratecard[thecard][7+wknd],"Executive Residence");

theform.RoomType.selectedIndex=thesel;
}

function WriteNights(NightNumber){
NsI=1;
minnights=(NightNumber == 6)? 2:1 // Sat Rate 2 Night Min
if (thecard==4){minnights=3}; // Special Rate 3 Night Min
if (thecard==7){minnights=3}; // Major Event  3 Night Min
if (thecard==0){minnights=3}; // Rack Rate   3 Night Min
if (thecard==1){minnights=2}; // Rack Rate    2 Night Min
if (thecard==2){minnights=2}; // Special Rate  2 Night Min
theform.Nights.options.length = 0;
for (J=0;  J<30-minnights ; J++) {          // Max Number of nights to display (5)
nts=(minnights+J==1)? " Night":" Nights";
if (minnights>1&&J==0) {nts=" Nights (Minimum)";NsI=J};
// if ((themonth > 9)&&(NightNumber < 3)&&(minnights+J == 3)){nts=" Nights - 3rd=50% 0ff!";NsI=2} //Remove 3rd Night Free
theform.Nights.options[J] = new Option(J+minnights+nts,J+minnights)}
theform.Nights.selectedIndex = NsI
}

function WriteWeekday(DayNumber){
MM_setTextOfLayer('daydisplay','',"<font size='2' class='fixfont'>Arrival Date - "+DayFull[DayNumber]+"</font>");
}

function WriteVisitLength(){
VisitLength=parseInt(theform.Nights.options[theform.Nights.selectedIndex].value);
with (theform)StartNight=GetDayOfWeek(YrSel, MoSel, DySel);
ss="Visit Length - "+Day3[StartNight]+" > "+Day3[(StartNight+VisitLength)%7];
MM_setTextOfLayer('visitdisplay','',"<font size='2' class='fixfont'>"+ss+"</font>");
themonth=theform.MoSel.options[theform.MoSel.selectedIndex].value;
// theform.Discount.value=((themonth<6)&&(VisitLength==3)&&(StartNight<3))?"3rd Night Half Price Sep-Dec":"Internet"; //Remove 3rd Night Free - 1st entry
}

function GetDayOfWeek(Yr, Mo, Dy){
return new Date(+Yr.options[Yr.selectedIndex].text,Mo.selectedIndex,Dy.selectedIndex+1).getDay()
}

function FutureDate(Yr, Mo, Dy){
var now = new Date();
now = now.getTime(); //NN3
var dateToCheck = new Date();
dateToCheck.setYear(Yr.options[Yr.selectedIndex].text);
dateToCheck.setMonth(Mo.selectedIndex);
dateToCheck.setDate(Dy.selectedIndex+1);
var checkDate = dateToCheck.getTime();
if ((dateToCheck-now)<0) {theform=document.register; with (theform)InitYMDselector(YrSel, MoSel, DySel)}
}

function padNumber(num){
return ( num < 10 ) ? '0' + num : num;
}

String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g,'');
}

function TrimSpaces(thefield){
thefield.value=thefield.value.trim();
}

function getfullname(i){
fn=theform.FirstName.value.trim();
ln=theform.LastName.value.trim();
fullname="";
if (fn!=""&&ln!=""){fullname=fn+" "+ln}
if (theform.CardName.value==""&&fullname!=""){theform.CardName.value=fullname}
}

function getExpires(){
theform.CardExpires.value=theform.CardMoSel.options[theform.CardMoSel.selectedIndex].value+"-"+theform.CardYrSel.options[theform.CardYrSel.selectedIndex].value;
}

function getArrive(Yr, Mo, Dy){
theform.Arrive.value=padNumber(Mo.options[Mo.selectedIndex].value)+"-"+padNumber(Dy.options[Dy.selectedIndex].value)+"-"+Yr.options[Yr.selectedIndex].text ;
}

function checkit(){
if (!oklen("FirstName",3)) return false;
if (!oklen("LastName",3)) return false;
if (!oklen("Address",8)) return false;
if (!oklen("City",4)) return false;
if (!oklen("State",2)) return false;
if (!oklen("ZipCode",5)) return false;
if (!oklen("Email",8)) return false;
if (!oklen("Phone",7)) return false;
if (!checkcard()) return false;
if (!checkbutton()) return false;
disablebutton();
if (!testsubmit()) return false;
theform.submit();
return true ;
}

function checkbutton(){
if(theform.Submit.value=="Request Sent!") {disablebutton();return false};
return true;
}

function disablebutton(){
theform.Submit.value="Request Sent!";
theform.Submit.disabled="true";
}

function checkcard(){
theform.WebAudit.value="";
cc = theform.CardType.options[theform.CardType.selectedIndex].value;
ii=". Use the TAB Key to move between Fields."
if (InitDate==theform.Arrive.value){alert("Please select an arrival date in the future"+ii);theform.MoSel.focus();return false}
if (cc =="None - Contact Me") {theform.CardNumber.value="Call to Confirm";return true};
if (cc =="") {alert("Please choose a credit card type to reserve your room"+ii);theform.CardType.focus();return false}
if (theform.CardExpires.value.length<7) {alert("Please enter the complete "+cc+" card expiration date"+ii);theform.CardMoSel.focus();return false}
if (theform.CardName.value.length<5) {alert("Please enter the "+cc+" card holders name"+ii);theform.CardName.focus();return false}
if (theform.CardNumber.value.length<13) {alert("Please enter a complete "+cc+" card number"+ii);theform.CardNumber.focus();return false}
if (!validatecard(theform.CardNumber.value)) {alert("Please check the "+cc+" card number you have entered"+ii);theform.CardNumber.focus();return false}
theform.SubjectTitle.value="LIGHTHOUSE LODGE WEBSITE RESERVATION "+theform.Arrive.value;
theform.WebAudit.value="VALID";
return true ;
}

function oklen(i,minlen){
ii=i;
if (i=="FirstName"){i="first name"};
if (i=="LastName"){i="last name"};
if (theform[ii].value.length<minlen){
alert("Please enter a complete "+i.toLowerCase()+" on the form. Use the TAB Key to move between Fields.");theform[ii].focus();return false}
return true ;
}

function validatecard(cardnum){
theform.CardNumber.value = cardnum = cardnum.replace(/\D/g, "");
if (cardnum.length< 13 || cardnum.length> 16 ) return false;
while (cardnum.length<16) cardnum = "0" + cardnum ;
var c = 0;
for (var i=0;i<8;i++){
var a = cardnum.charAt(i*2)*2;
c += a>9 ? Math.floor(a/10+a%10):a;
c += cardnum.charAt(i*2 +1)*1;
}
return (c!=0 && c%10==0);
}

function allcaps(thefield){
thefield.value=thefield.value.trim().toUpperCase();
}

function tonumeric(num){
return num.replace(/\D/g, "");
}

function capitalize(thefield){
var wd = thefield.value.toLowerCase().trim().split(" ");
for (var w=0; w<wd.length; w++) { var x = wd[w]; x = x.substr(0,1).toUpperCase() + x.substr(1);wd[w] = x;}
thefield.value = wd.join(" ");
}

function testsubmit(){//// Test Output
if (theform.CardNumber.value!="4111111111111111"){return true};
alertstring=""
for (var i=0; i<theform.length; i++)  //
	{
	if (theform[i].type=="select-one"){
	alertstring=alertstring+theform[i].name+": "+theform[i].options[theform[i].selectedIndex].value+"\n"
	}
	else {
	alertstring=alertstring+theform[i].name+": "+theform[i].value+"\n"
	}
	}
alertstring=alertstring+"\n"
alert (alertstring);
return false;
}

