

			/**
			 * First, create a self-executing function to insulate all variables from
			 * any other javascript on the page
			 */
			(function(){
				/**
				 * Some utilites and global variables for this script
				 */
			    var scriptTarget = 'c4sForm';
				var scriptName = 'booking-portal.js';
				var prefix = 'c4s';

			    /**
			     * this structure solves the window onload problem, and is equivalent
			     * to the jquery document ready funciton
			     * SEE: http://www.javascriptkit.com/dhtmltutors/domready.shtml
			     */
			    var init = function(){
			        // quit if this function has already been called
					if (arguments.callee.done) {
						return;
					}

			        // flag this function so we don't do the same thing twice
					arguments.callee.done = true;

					/**
					 * This is the constructor function for the form.
					 * This is where the code for the doc-ready will be executed
					 */
					// Search Form
			        var form = document.createElement('form');
					form.name = prefix + 'searchForm';
					form.id = prefix + 'searchForm';
					form.action = 'http://www.click4snow.com/search/searchHotelResults/';
					form.target = '_blank';

					// Country Dropdown Object
					var country = {
						label: document.createElement('label'),
						input: document.createElement('select'),
						name: 'SearchCountry',
						container: document.createElement('div')
					};

					// Country Label
					country.label.htmlFor = country.name;
					country.label.innerHTML = 'Country';
					country.container.appendChild(country.label);

					// Country Dropdown
					country.input.name = country.name;
					country.input.id = prefix + country.name;
					country.input.options[0] = new Option('Select Country',0);
					
						country.input.options[1] = new Option('Australia',2);
					
						country.input.options[2] = new Option('Canada',5);
					
						country.input.options[3] = new Option('Italy',106);
					
						country.input.options[4] = new Option('Japan',108);
					
						country.input.options[5] = new Option('New Zealand',154);
					
					country.input.onchange = function(){
						region.input.options.length = 0;
						region.input.options[0] = new Option('Select Region',0);
						resort.input.options.length = 0;
						resort.input.options[0] = new Option('Select Resort',0);
						
							if (this.value == 2) {
								
								region.input.options[1] = new Option('NSW Snowy Mountains',3);
								
								region.input.options[2] = new Option('Victorian ski resorts',2);
								
							}
						else
							if (this.value == 5) {
								
								region.input.options[1] = new Option('Alberta',25);
								
							}
						else
							if (this.value == 106) {
								
								region.input.options[1] = new Option('Dolomites',21);
								
								region.input.options[2] = new Option('Milky Way',23);
								
								region.input.options[3] = new Option('Valle d Aosta ',22);
								
							}
						else
							if (this.value == 108) {
								
								region.input.options[1] = new Option('Hokkaido',19);
								
							}
						else
							if (this.value == 154) {
								
								region.input.options[1] = new Option('North Island',20);
								
								region.input.options[2] = new Option('South Island',18);
								
							}
						
					};
					country.container.appendChild(country.input);

					// Region Dropdown Object
					var region = {
						label: document.createElement('label'),
						input: document.createElement('select'),
						name: 'SearchRegion',
						container: document.createElement('div')
					};

					// Region Label
					region.label.htmlFor = region.name;
					region.label.innerHTML = 'Region';
					region.container.appendChild(region.label);

					// Region Input
					region.input.name = region.name;
					region.input.id = prefix + region.name;
					region.input.options[0] = new Option('Select Region',0);
					region.input.onchange = function() {
						resort.input.options.length = 0;
						resort.input.options[0] = new Option('Select Resort',0);
						
							if (this.value == 3) {
								
									resort.input.options[1] = new Option('Charlotte Pass',7);
								
									resort.input.options[2] = new Option('Perisher',6);
								
									resort.input.options[3] = new Option('Selwyn',4);
								
									resort.input.options[4] = new Option('Thredbo',5);
								
							}
						
							if (this.value == 2) {
								
									resort.input.options[1] = new Option('Falls Creek',9);
								
									resort.input.options[2] = new Option('Mount Baw Baw',10);
								
									resort.input.options[3] = new Option('Mount Buller',11);
								
									resort.input.options[4] = new Option('Mt Hotham',8);
								
							}
						
							if (this.value == 25) {
								
									resort.input.options[1] = new Option('Banff',24);
								
									resort.input.options[2] = new Option('Banff Norquay',23);
								
									resort.input.options[3] = new Option('Lake Louise',25);
								
									resort.input.options[4] = new Option('Sunshine Village Banff',26);
								
							}
						
							if (this.value == 21) {
								
									resort.input.options[0] = new Option('Other Resort',0);
								
							}
						
							if (this.value == 23) {
								
									resort.input.options[0] = new Option('Other Resort',0);
								
							}
						
							if (this.value == 22) {
								
									resort.input.options[1] = new Option('Cervinia',21);
								
									resort.input.options[2] = new Option('Courmayeur',22);
								
							}
						
							if (this.value == 19) {
								
									resort.input.options[0] = new Option('Other Resort',0);
								
							}
						
							if (this.value == 20) {
								
									resort.input.options[0] = new Option('Other Resort',0);
								
							}
						
							if (this.value == 18) {
								
									resort.input.options[1] = new Option('Cardrona',18);
								
									resort.input.options[2] = new Option('Coronet Peak',13);
								
									resort.input.options[3] = new Option('Mt Hutt',16);
								
									resort.input.options[4] = new Option('Ohau',17);
								
									resort.input.options[5] = new Option('Remarkables',14);
								
									resort.input.options[6] = new Option('Snow Park NZ',19);
								
									resort.input.options[7] = new Option('Treble Cone',15);
								
							}
						
					};
					region.container.appendChild(region.input);

					// Resort Dropdown Object
					var resort = {
						label: document.createElement('label'),
						input: document.createElement('select'),
						name: 'SearchResort',
						container: document.createElement('div')
					};

					// Resort Label
					resort.label.htmlFor = resort.name;
					resort.label.innerHTML = 'Resort';
					resort.container.appendChild(resort.label);

					// Resort Dropdown
					resort.input.name = resort.name;
					resort.input.id = prefix + resort.name;
					
					resort.input.options[0] = new Option('Select Resort',0);
					resort.container.appendChild(resort.input);

					// Date Input Object
					var arrival = {
						label: document.createElement('label'),
						day: document.createElement('select'),
						month: document.createElement('select'),
						year: document.createElement('select'),
						name: 'searchCheckInDate',
						container: document.createElement('div'),
						className: 'datepick'
					};

					arrival.day.className = arrival.className;
					arrival.month.className = arrival.className;
					arrival.year.className = arrival.className;

					// Date Label
					arrival.label.htmlFor = arrival.name;
					arrival.label.innerHTML = 'Check In';
					arrival.container.appendChild(arrival.label);

					// Date Inputs
					arrival.day.name = arrival.name + 'Day';
					arrival.day.id = prefix + arrival.name + 'Day';

					
					for (i=1;i<32;i++) {
						arrival.day[i-1] = new Option(i,i);
					}
					arrival.day.value = 3;
					arrival.container.appendChild(arrival.day);

					arrival.month.name = arrival.name + 'Month';
					arrival.month.id = prefix + arrival.name + 'Month';
					arrival.month[0] = new Option('Jan',1);
					arrival.month[1] = new Option('Feb',2);
					arrival.month[2] = new Option('Mar',3);
					arrival.month[3] = new Option('Apr',4);
					arrival.month[4] = new Option('May',5);
					arrival.month[5] = new Option('Jun',6);
					arrival.month[6] = new Option('Jul',7);
					arrival.month[7] = new Option('Aug',8);
					arrival.month[8] = new Option('Sep',9);
					arrival.month[9] = new Option('Oct',10);
					arrival.month[10] = new Option('Nov',11);
					arrival.month[11] = new Option('Dec',12);
					arrival.month.onchange = function() {
						arrival.day.options.length = 0;
						if(this.value == 9||this.value == 4||this.value == 6||this.value == 11) {
							for (i=1;i<31;i++) {
								arrival.day[i-1] = new Option(i,i);
							}
						} else if(this.value == 2) {
							for (i=1;i<30;i++) {
								arrival.day[i-1] = new Option(i,i);
							}
						} else {
							for (i=1;i<32;i++) {
								arrival.day[i-1] = new Option(i,i);
							}
						}
					};
					arrival.month.value = 9;
					arrival.container.appendChild(arrival.month);

					arrival.year.name = arrival.name + 'Year';
					arrival.year.id = prefix + arrival.name + 'Year';
					for (i=0;i<11;i++) {
						arrival.year[i] = new Option(2010 + i, 2010 + i);
					}
					arrival.container.appendChild(arrival.year);

					// Stay Input Object
					var stay = {
						label: document.createElement('label'),
						input: document.createElement('select'),
						name: 'searchNumberNights',
						container: document.createElement('div')
					};

					// Stay Label
					stay.label.htmlFor = stay.name;
					stay.label.innerHTML = 'Nights';
					stay.container.appendChild(stay.label);

					// Stay Input
					stay.input.name = stay.name;
					stay.input.id = prefix + stay.name;
					stay.input[0] = new Option('No. of Nights',2);
					for(i=1;i<15;i++){
						stay.input[i] = new Option(i,i);
					}
					stay.container.appendChild(stay.input);

					// Referrer Input
					var referrer = document.createElement('input');
					referrer.name = 'referrerTLD';
					referrer.type = 'hidden';
					// get both window and parent locations in case of iframes
					referrer.value = window.location.host + ',' + parent.window.location.host;

					// Submit
					var done = {
						input: document.createElement('input'),
						name: 'Search',
						container: document.createElement('div')
					};

					done.input.value = done.name;
					done.input.type = 'submit';
					done.input.id = prefix + 'submit';
					done.container.appendChild(done.input);

					var css = document.createElement('style');
					css.type = 'text/css';
					// to write to the CSS node in IE, you need to append it to the dom first
					document.getElementsByTagName('head')[0].appendChild(css);
					var radius = '7px';
					var url = 'http://www.click4snow.com/';
					var cssString = '' +
					'form#'+prefix+'searchForm {text-align:center;background:#F8F6F3;padding:7px;border:1px solid #EDE8E1;margin:0;}' +
					'form#'+prefix+'searchForm #'+prefix+'innerDiv {text-align:center;background:#FFF;margin:0 0 7px 0;padding:10px;border:1px solid #E5E0D8;*width:auto;}' +
					'form#'+prefix+'searchForm label {display:none;}' +
					'form#'+prefix+'searchForm select,form#'+prefix+'searchForm #'+prefix+'searchNumberNights {width:100%;margin-bottom:10px;}' +
					'form#'+prefix+'searchForm #'+prefix+'searchNumberNights {margin-bottom:0;}' +
					'form#'+prefix+'searchForm select.datepick {width:30%;margin-right:3%;*margin-right:2%;}' +
					'form#'+prefix+'searchForm select#'+prefix+'searchCheckInDateYear {margin-right:0;}' +
					'form#'+prefix+'searchForm input#'+prefix+'submit {cursor:pointer;background:url('+url+'/media/pics/site/widget-submit.gif) no-repeat;text-indent: -1000em;*text-indent:0;margin:0;border:0 none;padding:0;padding-left:0;*padding-left:1000px;overflow:hidden;width:97px;height:23px;}' +
					'div#'+prefix+'outerDiv div#'+prefix+'header {background:url('+url+'/media/pics/site/header-tile.gif) repeat-x; border:1px solid #EDE8E1;border-bottom:0 none;height:39px;text-align:center;display:block;margin:0;padding:0;}' +
					'div#'+prefix+'outerDiv div#'+prefix+'header {-webkit-border-top-right-radius: '+radius+';-webkit-border-top-left-radius: '+radius+';-moz-border-radius-topright: '+radius+';-moz-border-radius-topleft: '+radius+';border-top-right-radius: '+radius+';border-top-left-radius: '+radius+';}' +
					'div#'+prefix+'outerDiv div#'+prefix+'header h4 {background:url('+url+'/media/pics/site/widget-title.gif) no-repeat center;height:39px;text-indent:-1500em;display:block;margin:0;padding:0;}' +
					'div#'+prefix+'outerDiv div#c4sfooter {background:#E8E1D9 url('+url+'/media/pics/site/footer-tile.gif) repeat-x;height:15px;border:1px solid #EDE8E1;border-top:0 none;}' +
					'div#'+prefix+'outerDiv div#c4sfooter {-webkit-border-bottom-right-radius: '+radius+';-webkit-border-bottom-left-radius: '+radius+';-moz-border-radius-bottomright: '+radius+';-moz-border-radius-bottomleft: '+radius+';border-bottom-right-radius: '+radius+';border-bottom-left-radius: '+radius+';}' +
					'div#'+prefix+'outerDiv {clear:both;list-style-position:outside;}' +
					'';
					var rules = document.createTextNode(cssString);

					try {
						if(css.styleSheet){
							css.styleSheet.cssText = rules.nodeValue;
						} else {
							css.appendChild(rules);
						}
					}
					//This currently works in IE6 but it was problematic so this is a catch so the CSS can fail silently
					catch (e) {
					}

					// Build the form before writing
					var innerDiv = document.createElement('div');
					innerDiv.id = prefix + 'innerDiv';

					innerDiv.appendChild(country.container);
					innerDiv.appendChild(region.container);
					innerDiv.appendChild(resort.container);
					innerDiv.appendChild(arrival.container);
					innerDiv.appendChild(stay.container);
					form.appendChild(innerDiv);
					form.appendChild(referrer);
					form.appendChild(done.container);

					var outerDiv = document.createElement('div');
					outerDiv.id = prefix + 'outerDiv';
					var title = document.createElement('h4');
					title.innerHTML = 'Search For Accommodation';
					var header = document.createElement('div');
					header.id = prefix + 'header';
					var footer = document.createElement('div');
					footer.id = prefix + 'footer';

					header.appendChild(title);
					outerDiv.appendChild(header);
					outerDiv.appendChild(form);
					outerDiv.appendChild(footer);

			        docWrite(outerDiv);
			    };

				/**
				 * This function checks for an element with the above id first and write there
				 * else it looks for a script tag with the above script and if its not in the head
				 * of the document, writes there, else looks for the body of the document and
				 * writes there
				 */
			    var docWrite = function(domObject){
					var scripts;

			        if (document.getElementById(scriptTarget)) {
			            document.getElementById(scriptTarget).appendChild(domObject);
			        }
			        else {
						try {
							scripts = document.getElementsByTagName('script');
							for(i=0; i < scripts.length + 1; i++){
								if(scripts[i].src){
									if (scripts[i].src.split('/').reverse()[0] == scriptName && scripts[i].parentNode != document.getElementsByTagName('head')[0]) {
										scripts[i].parentNode.appendChild(domObject);
										break;
									}
								}
							}
						}
						// no length will cause this to break
						catch (e) {
							document.body.appendChild(domObject);
						}
			        }
			    };

			    /* for Mozilla */
			    if (document.addEventListener) {
			        document.addEventListener("DOMContentLoaded", init, false);
			    }

			    /* for Internet Explorer */
			    /*@cc_on @*/
			    /*@if (@_win32)
			    	document.write("<script defer src=ie_onload.js><"+"/script>");
			    /*@end @*/
			    /* for other browsers */
			    window.onload = init;
			})();

		
