﻿// == DEFINE GLOBAL VARIABLES ===============================================================
var img_dir = "images/packages/";						// image directory
var printpagetitle = "<h2>Northern Extremes Package Quote</h2>";
var columns = 1;										// number of display columns
var colwidth = 421;										// display column width
var weekendDEF = 1;										// enter 1 if friday is a weekend day, 2 if only Sat and Sun are weekend days
var p_width = 225;										// width of info pop window	
var iw = 225;											// table size controls - DESC column width
var pw = 36;											// price column width
var sw = 70;											// suffix column width
var qw = 40;											// qty column width
var tw = (iw+pw+sw+qw);									// total column width
var head1 = "WEEKEND";									// column headers
var head2 = "MIDWEEK";									// column headers

var custdate;
var now = new Date();
var cur_year = now.getYear() + 1900;

function block(type,month,day,year){
	this.type = type;
	this.date = new Date(year, (month-1), day);
}

function I(k,t,ep,dp,x,l,i,g){						//	Define I Object
	this.cat = k;									//	Category
	this.desc = t;									//	Description
	this.we_price = ep;								//	Weekend Price
	this.wd_price = dp;								//	Weekday Price
	this.ppx = x;									//	Number of people covered by "price"
	this.link = l;									//	more info
	this.image = i;									//	link to image in PRESET directory
	this.flag = 0;									//	flag semaphore for choosing elements
	this.qty = 1;									// 	quantity
	this.qflag = g;									//  QTY flag
}
function C(a,b,t,k,g){
	this.n = a;										// name
	this.d = b;										// desc
	this.type = t;									// type of list
	this.chart = k;									// chart printing flag
	this.mw_total = 0;								// total for weekday category
	this.we_total = 0;								// weekend total
	this.qflag = g;									// QTY flag
}

c = new Array();
el = new Array();
blk = new Array();


var blc = 0;
blk[blc] = new block("Queen",2,3,2006);
blc++;
blk[blc] = new block("Queen",3,5,2006);
blc++;
// == CATEGORIES BEGIN HERE ==================================================================
// VARIABLE EXPLANATIONS:
// 1: Enter a string with the name of the category
// 2: Enter a short description string
// 3: Choose a type of list to display
//		a)  1 for radio  (single option)
//		b)  2 for check boxes (multiple options)
// 4. Enter 1 if it should build the full chart, 0 for just the item descriptions
// 5. Enter 1 if there should be a QTY column for that category
var cc = -1;
c[cc++] = new C("Lodging","Choose a lodging establishment",1,1,0);
c[cc++] = new C("Snowmobiles","Choose your sled option",1,1,0);
c[cc++] = new C("Dining","We'd be happy to make a reservation for you",1,1,0);


// == PACKAGE ITEMS BEGIN HERE ===============================================================
// VARIABLE EXPLANATIONS:
// 1: Enter the category NUMBER as outlined above
// 2: Enter the item description string
// 3: Enter the weekend price or 1st type of price
// 4. Enter the midweek price or 2nd type of price
// 5. Enter the number of people that the price refers to. eg: price per 3 people, enter 3
// 6. Enter the text for the pop-up window (careful with HTML tags)
// 7. Enter the corresponding image source name
// 8. Enter 1 if you want a quantity box to appear, 0 if not
var ec = -1;

el[ec++] = new I("none","none",0,0,1,"",0,0);				// default item
el[ec++] = new I(0,"Red Jacket Inn",149,89,2,"Standard Room with 1 King size bed or 2 queens.<hr>North Conways Premier Property.  Located on NH Corridor 19 Snowmobile Trail System where you can access all trails in the State of New Hampshire and Maine. The Red Jacket Features fabulous mountain views, tavern, dining room, entertainment, sleigh rides, indoor pool and brand new Spa. Midweek onsite rentals available. Located .2 miles from Northern Extremes.","redjacket.jpg",0);
el[ec++] = new I(0,"Golden Gables Inn 1", 78,59,2,"Regular Room<hr>Family run motel offering spacious rooms with 2 queen size beds and 1 king bed. All rooms feature wireless internet connection, refridgerator, microwave and Mt Views. Jacuzzi suites also available. Located on New Hampshire Corridor 19 Snowmobile Trail. On-site snowmobile rentals available. Located .2 miles from Northern Extremes","goldengables.jpg",0);
el[ec++] = new I(0,"Golden Gables Inn 2", 178,139,2,"Jacuzzi Suite<hr>Family run motel offering spacious rooms with 2 queen size beds and 1 king bed. All rooms feature wireless internet connection, refridgerator, microwave and Mt Views. Jacuzzi suites also available. Located on New Hampshire Corridor 19 Snowmobile Trail. On-site snowmobile rentals available. Located .2 miles from Northern Extremes","goldengables.jpg",0);
el[ec++] = new I(0,"Attitash Mountain Village",179,149,2,"Market Place Motel<hr>Jacuzzi, Fireplace Suite - Most reasonably priced jacuzzi accommodations in the Mt Washington Valley.<hr>Vacation Resort Village located at the base of Attitash Ski Area. Martketplace Motel offers Jacuzzi Fireplace units with 1 king bed. 2-3 bedroom condos are available for larger groups.  Resort features indoor pool, outdoor hot tub and restaurant. Located 8 miles from Northern Extremes.","attitash.jpg",0);
el[ec++] = new I(0,"Attitash Mountain Village",299,179,2,"2 Bedroom Condo<hr>A spacious unit for 6-10 people, with 2 bedrooms a living room with sofa-bed, kitchen facilities, and may have fireplace or wood stove.<hr>Vacation Resort Village located at the base of Attitash Ski Area. Martketplace Motel offers Jacuzzi Fireplace units with 1 king bed. 2-3 bedroom condos are available for larger groups.  Resort features indoor pool, outdoor hot tub and restaurant. Located 8 miles from Northern Extremes.","attitash.jpg",0);
el[ec++] = new I(0,"Attitash Mountain Village",399,269,2,"3 Bedroom Condo<hr>A larger unit furnished for 8-14 people with a large living room with sofa-beds, 2-3 bathrooms kitchen facilities, and may have a fireplace or woodstove.<hr>Vacation Resort Village located at the base of Attitash Ski Area. Martketplace Motel offers Jacuzzi Fireplace units with 1 king bed. 2-3 bedroom condos are available for larger groups.  Resort features indoor pool, outdoor hot tub and restaurant. Located 8 miles from Northern Extremes.","attitash.jpg",0);
el[ec++] = new I(0,"New England Inn","N/A",150,2,"Log Cabin<hr>Individual log cabin with fireplace and jacuzzi.<hr>Elegant Country Inn located 4 miles from Northern Extremes. Inn features rustic lodge and log cabins. Some of the finest accommodations in the North Country. Excellent dining at Tuckermans Tavern.","newenglandinn.jpg",0);
el[ec++] = new I(0,"New England Inn","N/A",89,2,"Lodge<hr>Room features king bed and country furnishings.<hr>Elegant Country Inn located 4 miles from Northern Extremes. Inn features rustic lodge and log cabins. Some of the finest accommodations in the North Country. Excellent dining at Tuckermans Tavern.","newenglandinn.jpg",0);
el[ec++] = new I(0,"North Conway Grand",159,79,2,"1 King or 2 Queens<hr>Located on NH Trail 19 at Settler’s Green Outlet Village. Walking distance to factory outlet shopping and dining. Indoor pool, restaurant, bar, meeting rooms. Rooms have 1 king or 2 queen beds.","noimage.jpg",0);
el[ec++] = new I(0,"Mount Washington Hotel","N/A","N/A",2,"No information available","noimage.jpg",0);

el[ec++] = new I(1,"Singles- 2 hr Guided Tour",95,85,1,"tours.html","single.jpg",0);
el[ec++] = new I(1,"Singles- 3 hr Guided Tour",135,115,1,"tours.html","single.jpg",0);
el[ec++] = new I(1,"Singles- Half day rental",150,110,1,"singles.html","single.jpg",0);
el[ec++] = new I(1,"Singles- Full day rental",210,170,1,"singles.html","single.jpg",0);
el[ec++] = new I(1,"Doubles- 2 hr Guided Tour",125,105,2,"tours.html","double.jpg",0);
el[ec++] = new I(1,"Doubles- 3 hr Guided Tour",165,135,2,"tours.html","double.jpg",0);
el[ec++] = new I(1,"Doubles- Half day rental",175,150,2,"doubles.html","double.jpg",0);
el[ec++] = new I(1,"Doubles- Full day rental",250,200,2,"doubles.html","double.jpg",0);

el[ec++] = new I(2,"Flatbread",0,0,1,"Organic Brick oven pizza. North Conway Village.","1.jpg",0);
el[ec++] = new I(2,"Cafe Noche",0,0,1,"Mexican<br>Family Restaurant, Conway.","1.jpg",0);
el[ec++] = new I(2,"White Mountain Hotel",0,0,1,"Fine dining, North Conway.","1.jpg",0);



var stop = el.length-1;						// finds total number of els to stop the "for" loop
var catstop = c.length-1;
var blockstop = blk.length-1;
//==============================================================================================================

function compute(form){
	var we_temp = 0;
	var mw_temp = 0;
	var grand_z = 0;		// grand total
	var month = parseInt(form.month.value);
	var day = parseInt(form.day.value);
	var year = parseInt(form.year.value);
	custdate = new Date(year, (month-1), day);
	var ratesuff = 0;
	var quant = 1;
	
	isBlocked(custdate,form);
	
	for(i=0; i <= catstop; i++){							// for each category
		
		c[i].mw_total = 0;									// reset values
		c[i].we_total = 0;		
		for (j=0; j <= stop; j++){							// run through all items

			if((c[i].qflag == 1) && (el[j].qflag==1)){		// if QTYs are both flagged
					el[j].qty = parseInt(document.getElementById(eval("\"qty"+j+"\"")).value);
					quant = el[j].qty;						// set the quantity
			}
			else{
				el[j].qty = form.adults.value;
				quant = el[j].qty;	
			}
			
			if((el[j].cat == i) && (el[j].flag ==1)){						// if we're in the right c and flagged
				c[i].mw_total += (el[j].wd_price/el[j].ppx) * quant;		// add price, divided by ppx, time qty to total: CHECK THIS OVER
				c[i].we_total += (el[j].we_price/el[j].ppx) * quant;
			}
			quant = 1;		// reset quantity for next item
		}
		if(i == 0){				// if it's lodging, multiply by number of nights
			mw_temp += c[i].mw_total * form.billable.value;		
			we_temp += c[i].we_total * form.billable.value;
		}
		else{
			mw_temp += c[i].mw_total;
			we_temp += c[i].we_total;
		}
	}
	if(isWeekend(custdate)){
		grand_z = we_temp;
		ratesuff = "weekend rate";
	} else{
		grand_z = mw_temp;	
		ratesuff = "midweek rate";
	}
	// display a total of all checked items	in TWO locations
	form.grand_z.value = "  $" + grand_z + " : " + ratesuff;
	form.grand_z2.value = form.grand_z.value;
}

//================================================================================================================
function dateBetween(m1,d1,y1,m2,d2,y2,m3,d3,y3){			// question date, first date, second date
		var chosenDate = new Date(y1, (m1-1), d1);
		var startDate = new Date(y2, (m2-1), d2);
		var endDate = new Date(y3, (m3-1), d3);
		
		if ((startDate.getTime() <= chosenDate.getTime()) && (chosenDate.getTime() <= endDate.getTime())){
			return 1;
		}
		else{
			return 0;
		}
}

function isWeekend(d){										// send a Date() object, returns 1 if it's a weekend day
	if(d.getDay() == 6 || d.getDay() == 0){					// if d is a sat or sun
		return 1;
	}
	else if(weekendDEF == 1){					// if FRIDAY is considered a weekend day
		if(d.getDay() == 5){					// if d is a sat or sun
			return 1;
		}
	}
	else{
		return 0;
	}
}

function isBlocked(d,f){
	for (i = 0; i <= blockstop; i++){		// for each block
		z = blk[i].date.getTime();			// blocked date
		zz = d.getTime();					// chosen date
		
		for(j = 0; j < f.nights.value; j++){										// for each night in block
			if (z == zz){
				alert("Night " +(j+1) +" is not available.  Please choose another date.");
				return 1;
			}
			zz += (1000*60*60*24);			// add a day to the date
		}
	}
	return 0;
}
//================================================================================================================
function printForm(form){
		var running = 0;
		var w = 700;												// window width
		var h = 600;												// window height
		var p = 0;
		var styleSheet = "ss/printform.css";
		var contact = ("<p>" + form.name.value + "<br />" + form.address.value + "<br />" + form.city.value + ", " + form.state.value + "  " + form.zip.value + "<br />Phone: ("+ form.phone1.value + ") " + form.phone2.value + "-" + form.phone3.value + "<br />Email: " + form.email.value);
		var payment = ("<p>Credit Card Info:<br />Card Number: " + form.cc.value + "  exp. " + form.expm.value + "/" + form.expy.value + "</p>");
		var wecheck = isWeekend(custdate);
		compute(form);		// recalculate the numbers
		mx=window.open("","displayWindow","toolbar=no,width="+w+",height="+h+",directories=no,status=no,scrollbars=yes,resize=yes,menubar=yes");
		mx.document.write("<HEAD><TITLE>"+printpagetitle+"</TITLE><link href=\""+styleSheet+"\" rel=\"stylesheet\" type=\"text/css\" media=\"all\" /></HEAD><BODY><div id='capsule'>"+ printpagetitle + "<p>" +contact + "<p>" + payment);
		mx.document.write("<p>" + (custdate.getMonth()+1) + "/" + custdate.getDate() + "/" + (custdate.getYear()+1900) + " qualifies for a ");

		if(wecheck){
			mx.document.write(head1);
		} else{
			mx.document.write(head2);
		}
		mx.document.write(" rate.</p>");
		
		mx.document.write("<table>");	
		
		for(i = 0; i <= catstop; i++){
			mx.document.write("<tr><td colspan=4><hr></td></tr><tr><td><b>" + c[i].n + "</td><td></td></tr>");
			
			for (j = 0; j <= stop; j++){							// go through all els
				if((el[j].cat == i) && (el[j].flag==1) && el[j].qty!=0){					// if it's in the right c and flagged
					if(wecheck){
						p = el[j].we_price;
						ptotal = c[i].we_total;
					} else{
						p = el[j].wd_price;
						ptotal = c[i].mw_total;
					}
					
					
					mx.document.write("<tr><td></td><td>" + el[j].desc + "</td><td width=200 align=right>$" + p + " x "+(el[j].qty/el[j].ppx) + " = $" + ptotal +"</td></tr>")
					running += ptotal;
				}
			}
		}
		mx.document.write("<tr><td colspan=4><hr></td></tr><tr><td></td><td valign=right>TOTAL:</td><td align=right>$"+ running +"</td></tr></table></div></body>");
		mx.document.close();
	}


function builder(){
	var stop = el.length-1;								// finds total number of els to stop the "for" loop
	var catstop = c.length-1;
	var suff = "text";									// initialize suffix variable as string
	var e;
	var list = 0;
	var colcount = 0;
	var numcols = columns;
	var fimage = " ";									// image string for info

	
	
	document.write("<table><tr>");
	for (ii = 0; ii <= catstop; ii++){					// run for each category
		
		if(colcount == numcols){
			document.write("</tr><tr>");
			colcount = 0;
		}
		document.write("<td width="+colwidth+" class='module'>");
		
		list = c[ii].chart;
			document.write("<table class='packagetable' cellpadding=0 width="+tw+" border=0><tr valign=bottom><td width="+ iw +"><span class=\'minitableheader\'>"+c[ii].n+"</span><br><i>"+ c[ii].d +"</i></td>");
			if(list != 1){
				document.write("<td width="+pw+"></td><td width="+pw+">");
			}
			else if(samerate(ii)){
				document.write("<td colspan=2 width="+(pw*2)+"><center><i>PRICE</i></center>");
			}
			else{
				document.write("<td width="+pw+"><center><i>"+head1+"</i></center></td><td width="+pw+"><center><i>"+head2+"</i></center>");
			}
				
			document.write("</td><td width="+sw+"></td><td><i>");
			if(c[ii].qflag!=0){
				document.write("QTY");
			}
			document.write("</i></td></tr><tr><td colspan=5><hr></td></tr>");
		
			for (i = 0; i <= stop; i++){											// for all elements in list				
				e = el[i];															// get chosen element												
				fimage = "<img border=1 src=" + img_dir + e.image + "><br>";	// establish the image link	
				if(e.cat == ii){	
					if (e.ppx == 1){														// if the element is priced per person
						suff = "per person";												// set suffix
					}
					else if (e.ppx == 0){											// if the element is priced per x people
						suff = "per item";											// set suffix with x people
					}
					else{															// if the element is priced per x people
						suff = "per " + e.ppx + " people";							// set suffix with x people
					}		
					document.write("<tr><td width="+ iw+">");
					if(c[ii].type == 1){				// RADIO						
						document.write("<input type=radio onclick=javascript:flag(" + i + ",\"" + ii + "\"); name=" + c[ii].n + " value='"+ e.desc +"'> ");
					}
					else if(c[ii].type == 2){			// CHECKBOX						
						document.write("<input type=checkbox onclick=javascript:multiflag(" + i + "); name=" + c[ii].n + "> ");
					}
					document.write("<a onmouseover=\"toolTip(\'" + fimage + e.link + "\',WIDTH,\'" + p_width +"\',CAPTION,\'" + e.desc + "\')\" onmouseout=\"toolTip();\">" + e.desc + "</a></td>");	
					
					if (list != 1){
						document.write("<td></td><td></td><td></td></tr>");
					}
					else if(e.we_price == e.wd_price){
						document.write("<td colspan=2><center>$" + e.we_price + "</center></td><td><i>" + suff + "</i></td>");
					}
					else{
						document.write("<td><center>$" + e.we_price + "</center></td><td><center>$" + e.wd_price + "</center></td><td><i>" + suff + "</i></td>");
					}
					if(c[ii].qflag == 1 && el[i].qflag==1){		// if the category and element are flagged for QTY

						document.write("<td><select id='qty" + i + "' name='qty" + i + "'><option value=1> </option><option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option></select></td>");
					}
					document.write("</tr>");
					
				}
				
			}
			if(c[ii].type == 1){				// RADIO	
						document.write("<tr><td><input type=radio onclick=javascript:flag(" + 0 + ",\"" + ii + "\"); name=" + c[ii].n + " checked=checked>  <a>None</a></td><td></td><td></td><td></td></tr>");
				}
			document.write("</table>");
			document.write("</td>");
			colcount++;
	}
	document.write("</tr></table>");
}

function multiflag(z){								// if it's 1, change to 0 and vice versa
	if (el[z].flag == 1){			
		el[z].flag = 0;
	} else if (el[z].flag == 0){
		el[z].flag = 1;
	}
	//alert(el[z].desc + "  " +el[z].flag);			// testing line
	return 0;
}

function flag(z,c){									// flags a chosen el I
	for (i = 0; i <= stop; i++){
		if(el[i].cat == c){							// make sure to only zero the right c
			el[i].flag = 0;							// zero the flags in that c
		}
	}
	el[z].flag = 1;									// set the new flagged item
	return 0;
}

function isExtra(k,f){									// returns the number of adults that don't divide evenly into per person rate
	if( k % f	 )										// if number of adults doesn't divide evenly into ppx
		return k % f;									// return TRUE - number is odd
}




function dateChooser(){			// displays a pull down menu with months, day, year (current through 2 years later) as an option
		var now = new Date();
		var cur_year = now.getYear();
		if( cur_year < 2000 )			// adjust for Firefox date bug or IE bug, whichever you want to call it
			cur_year+=1900;
		
		
		document.write("<select name='month' size='1'><option value=01>January</option><option value=02>February</option><option value=03>March</option><option value=04>April</option><option value=05>May</option><option value=06>June</option><option value=07>July</option><option value=08>August</option><option value=09>September</option><option value=10>October</option><option value=11>November</option><option value=12>December</option></select><select name='day' size='1'>");
		for (i=1; i <=31 ; i++){
			if(i<10)
				xtra = "0";
			document.write("<option value=" + xtra + i + ">" + i + "</option>");
			xtra = "";
		}
		document.write("</select><select name='year' size='1'>");					
		for (i=cur_year; i <=(cur_year+2) ; i++){
			document.write("<option value=" + i + ">" + i + "</option>");
		}
		document.write("</select>");
}

function samerate(c){
	for (i = 0; i <= stop; i++){		
		if (el[i].cat == c){
				if(el[i].we_price != el[i].wd_price){
						return 0;
				}
		}	
	}
	return 1;				
}


function resetAll(){
	window.location.reload();		
}