function validateForm()
  {
    if (document.forms[0].RegionId.options[document.forms[0].RegionId.selectedIndex].value > 0)
    {
      document.forms[0].action = "http://www.hotelpronto.com/Customer/Availability/HotelSearchResults.aspx?AffiliateId=1376";
      return true;
    }
    else if (document.forms[0].RegionId.options[document.forms[0].RegionId.selectedIndex].value == 0)
    {
      document.forms[0].action = "http://www.hotelpronto.com/Customer/Availability/HotelSearch.aspx?AffiliateId=1376";
      return true;
    }
    else
    {
      return false;
    }
  }
  
  var monthNames = new Array('Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember');
  
function setMonths() {
	var amy = document.forms[0].ArrivalMonthYear;
	amy.options[0] = null;
 	var now = new Date();
 	var curMonth = now.getMonth();
 	var curYear = now.getYear();
 	if(curYear < 2000) {
 		curYear += 1900;
 	}
  	for(var i=curMonth; i<(curMonth+12); i++) {  		
  		var y = curYear;
  		m = (i%12) + 1;  		
  		if((i%12) < curMonth) {
  			y++;
  		}
  		m < 10 ? m = '0'+m : m;
 	 	amy.options[amy.length] = new Option(monthNames[i%12],y+''+m);
  	}
  }
  
  function setRooms(nrOfRooms) {
  	nrOfRoomsBefore = document.forms[0].nrOfRooms.value;
  	dif = nrOfRooms - nrOfRoomsBefore;
  	if(dif > 0) {
  		for(var i=0; i<dif; i++) {
  			addRow(parseInt(nrOfRoomsBefore)+i+1);
  		}
  	} else if(dif < 0) {
	  	for(var i=dif; i<0; i++) {
  			removeRow();
  		}
  	}
  	document.forms[0].nrOfRooms.value = nrOfRooms;
  }
  
  function addAttribute(parentNode, attName, attValue) {
  	var att = document.createAttribute(attName);
  	att.nodeValue = attValue;
  	parentNode.setAttributeNode(att);
  	return parentNode;
  }
  
  function addRow(nr) {
  	var table = document.getElementById('occupants');
  	var row = document.createElement('tr');
  	addAttribute(row,'id','row' + nr);
  	
  	// Room
  	var cell = document.createElement('td');
  	addAttribute(cell,'width','50');
  	addAttribute(cell,'height','25');
  	addAttribute(cell,'align','left');
  	cell.style.paddingLeft = '7px';
  	cell.style.fontWeight = 'bold';
  	cell.style.fontStyle = 'italic';
  	
  	cell.appendChild(document.createTextNode('Rom ' + nr + ':'));
  	row.appendChild(cell);
  	
 		// Adults
  	cellx = document.createElement('td');
  	addAttribute(cellx,'width','47');
  	addAttribute(cellx,'height','25');
  	addAttribute(cellx,'align','right');
  	cellx.style.paddingRight = '3px';
  	cellx.appendChild(document.createTextNode('Voksne: '));
	row.appendChild(cellx);
	cell = document.createElement('td');
  	addAttribute(cell,'height','25');
  	addAttribute(cell,'align','left');
	var selName = 'Adults';
	if(nr > 1) { selName += nr; }
  	var selectAdults = document.createElement('select');
  	selectAdults = addAttribute(selectAdults,'id',selName);
  	selectAdults = addAttribute(selectAdults,'name',selName);
	selectAdults.className = "day";
  	selectAdults.onchange = function(e) { setRoomType(nr,this.value); }
  	for(var i=0; i<5; i++) {
  		var option1 = document.createElement('option');
  		addAttribute(option1,'value',i);
  		if(i==1)
  		{
  			addAttribute(option1,'selected','true');
  		}
	  	var optionText = document.createTextNode(i+'');
 	 	option1.appendChild(optionText);
  		selectAdults.appendChild(option1);  	
  	}
  	cell.appendChild(selectAdults);
  	row.appendChild(cell);
  	
  	// Children
	//cellx = document.createElement('<td align=right height=25 style=\'padding-right:3px;padding-left:6px\'>');
	cellx = document.createElement('td');  	
	addAttribute(cellx,'align','right');
	addAttribute(cellx,'height','25');
	cellx.style.paddingLeft = '6px';
	cellx.style.paddingRight = '3px';
  	cellx.appendChild(document.createTextNode('Barn: '));
	row.appendChild(cellx);
	
  	cell = document.createElement('td');  	
	selName = 'Children';
	if(nr > 1) { selName += nr; }
  	var selectChildren = document.createElement('select');
	selectChildren.className = "day";
  	addAttribute(selectChildren,'name',selName);
  	addAttribute(selectChildren,'id',selName);
  	selectChildren.onchange = function(e) { setChildAge(nr,this.value); setRoomType(nr,this.value); }
  	for(var i=0; i<3; i++) {
  		var option = document.createElement('option');
  		addAttribute(option,'value',i);
	  	var optionText = document.createTextNode(i+'');
 	 	option.appendChild(optionText);
  		selectChildren.appendChild(option);
  	}
  	cell.appendChild(selectChildren);
  	row.appendChild(cell);
  	if(navigator.appName == 'Microsoft Internet Explorer') {
	  	table.tBodies(0).appendChild(row);
  	} else {
	  	table.appendChild(row);	
  	}
   	
  }

  function setChildAge(nr, nrOfChildren) {
	var row = document.getElementById('row' + nr);
	c1 = document.getElementById(row.id + 'ChildAgeCell1');
	if(c1 != null)
		row.removeChild(c1);
	c2 = document.getElementById(row.id + 'ChildAgeCell2');
	if(c2 != null)
		row.removeChild(c2);

	for(var i=0; i<nrOfChildren; i++) {
  		addChildDropDown(row, i+1);
  	}
  }

  function addChildDropDown(row, nr) {
		cell = document.createElement('td');
		addAttribute(cell,'id',row.id+'ChildAgeCell' + nr);
		cell.style.paddingRight = '6px';
		if(nr == 1)
	  		cell.appendChild(document.createTextNode('Alder:'));
		selName = 'Child' + nr  + 'Age';
	  	var selectChildAge = document.createElement('select');
		selectChildAge.className = "day";
	  	addAttribute(selectChildAge,'name',selName);
		for(var j=0; j<19; j++) {
	  		var option = document.createElement('option');
	  		addAttribute(option,'value',j);
		  	var optionText = document.createTextNode(j+'');
 	 		option.appendChild(optionText);
	  		selectChildAge.appendChild(option);
		}
	  	cell.appendChild(selectChildAge);
  		row.appendChild(cell);
  }

  function removeChildDropDown(row, cellNr) {
	row.removeChild(document.getElementById('ChildAgeCell' + cellNr));
  }

  function createOption(txt,val) {
   option = document.createElement('option');
   addAttribute(option,'value',val);
   option.appendChild(document.createTextNode(txt));
   return option;
  }
  
  function setRoomType(nr,nrOfPersons,personType) {
	var row = document.getElementById('row' + nr);
	var roomTypeCell = document.getElementById(row.id + 'RoomTypeCell');
	if(roomTypeCell != null) {
		row.removeChild(roomTypeCell);	
	}
	
	var cell = document.createElement('td');
	addAttribute(cell,'id',row.id+'RoomTypeCell');
	cell.appendChild(document.createTextNode('Romtype: '));

	var selName = 'Adults';
	if(nr > 1) { selName += nr; }
	
	adults = parseInt(document.getElementById(selName).value);

	selName = 'Children';
	if(nr > 1) { selName += nr; }
	children = parseInt(document.getElementById(selName).value);

	selName = 'Room';
	if(nr > 1) { selName += nr; }
	var selectRoomTypes = document.createElement('select');
	addAttribute(selectRoomTypes,'name',selName);

	var hit = false;
	 if(adults == 1 && children == 0) {
	  selectRoomTypes.appendChild(createOption('Enkeltrom',1));
	
	  hit = true;
	 } else if(adults == 2 && children == 0) {
	  selectRoomTypes.appendChild(createOption('Dobbeltrom',2));
	  selectRoomTypes.appendChild(createOption('Tomannsrom',3));
	  hit = true;
	 } else if(adults == 3 && children == 0) {
	  selectRoomTypes.appendChild(createOption('Tremannsrom',4));
	  hit = true;
	 } else if(adults == 4 && children == 0) {
	  selectRoomTypes.appendChild(createOption('Firemannsrom',5));
	  hit = true;
	 } else if(adults == 1 && children == 1) {
	  selectRoomTypes.appendChild(createOption('Tomannsrom',3));
	  selectRoomTypes.appendChild(createOption('Dobbeltrom + barn',12));
	  selectRoomTypes.appendChild(createOption('Familierom',13));
	  hit = true;
	 } else if(adults == 1 && children == 2) {
	  selectRoomTypes.appendChild(createOption('Tremannsrom',4));
	  selectRoomTypes.appendChild(createOption('Familierom',14));
	  hit = true;
	 } else if(adults == 2 && children == 2) {
	  selectRoomTypes.appendChild(createOption('Firemannsrom',5));
	  selectRoomTypes.appendChild(createOption('Familierom',14));
	  hit = true;
	 } else if(adults == 2 && children == 1) {
	  selectRoomTypes.appendChild(createOption('Dobbeltrom + barn',12));
	  selectRoomTypes.appendChild(createOption('Tomannsrom + barn',11));
	  selectRoomTypes.appendChild(createOption('Tremannsrom',4));
	  selectRoomTypes.appendChild(createOption('Familierom',13));
	  hit = true;
	 }

	if(hit) {
	 cell.appendChild(selectRoomTypes);
	 row.appendChild(cell);
	}  	
  }
  
  function removeRow() {
	var table = document.getElementById('occupants');
	nrOfRows = table.tBodies(0).childNodes.length;
	table.tBodies(0).removeChild(table.tBodies(0).childNodes[nrOfRows-1]);
  }
  
  function setDefaults() {
  	document.forms[0].Rooms.selectedIndex = 0;
  	document.forms[0].nrOfRooms.value = 1;
  	setMonths();
  	addRow(1);
	var currDate = new Date(((new Date()).getTime() + 3*24*60*60*1000));
	document.forms[0].ArrivalDay.options[currDate.getDate()-1].selected = true;
	if((new Date()).getMonth() < currDate.getMonth()) {
		document.forms[0].ArrivalMonthYear.options[1].selected = true;
	}
  }