function galleryUpload(f) {
	var myDiv = document.getElementById("UploadMsg");
	myDiv.innerHTML = "<h1>Uploading...Please wait...</h1>";
	myDiv.style.border = "1px solid black";
	f.submit();
}


function CheckForNewGallery(f,e) {
    // f = form, e = element
    if (e.options[e.selectedIndex].value==0)
        window.open('PhotoGallery.asp?action=new&blog=true','','width=640,height=520,scrollbars=1');
}

function closeGallery(strBlog,strGalleryName,lngGalleryID) {
    if(strBlog.length==4) {

        var win = window.opener

//        var e=window.opener.document.forms['uploadform'].GalleryID;
        var e = win.document.getElementById('GalleryID');
        var l=e.length-1;
        var elOptNew = e.document.createElement('option');
        elOptNew.text = strGalleryName;
        elOptNew.value = lngGalleryID;

        var elOptOld = e.options[l];
        try {
            e.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
        }
        catch(ex) {
          e.add(elOptNew, e.selectedIndex); // IE only
        }

       //e.options[l] = new Option(strGalleryName,lngGalleryID);
        e.selectedIndex = l;
    }
    window.close();
}

function showImageProperties() {
    var d = document.getElementById('ImageDetails');
    d.style.left=200;
    d.style.top=200;
    d.style.visibility='visible';
}

function hideImageProperties() {
    var d = document.getElementById('ImageDetails');
    d.style.visibility='hidden';
}

function addMoreBookingRows() {
	var i;
	var seatsLeft = document.getElementById('AvailableSeats').value
	if (seatsLeft==0) {
		alert("There are no seats left.");
	}
	else for (i=0;i<seatsLeft;i++) addMoreRows();
}

function addMoreRows() {
//
// code borrowed from: http://www.mredkj.com/tutorials/tableaddrow.html
//
  var tbl = document.getElementById('BookingDetails');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
// "del"
// "Prefix"
  var fields = new Array ("FirstName","LastName","DOB","PassportNumber","PassportExpiry","DateOfIssue","PlaceOfIssue","Nationality")
// "DatePosted"
  
  
  var cell = row.insertCell(0); // DELETE Button
  var el = document.createElement('input');
  el.type = 'checkbox';
  el.name = 'deleteme' + iteration;
  el.id = 'deleteme' + iteration;
  cell.appendChild(el);

  var cell = row.insertCell(1); // Select box
  var el = document.createElement('select');
  el.name = 'Prefix' + iteration;
  el.id = 'Prefix' + iteration;
  cell.appendChild(el);

	var el = document.getElementById('Prefix'+iteration);
	var l = document.getElementById('Prefix1');
	for (i=0;i<l.length-1;i++) {
		el.options[i] = new Option(l.options[i].text,l.options[i].value,false,false);
	}	


  for (i=0;i<fields.length;i++) {
	  var cell = row.insertCell(i+2);
	  var el = document.createElement('input');
	  el.type = 'text';
	  el.name = fields[i] + iteration;
	  el.id = fields[i] + iteration;
	  el.size = 5;
	  cell.appendChild(el);
  }
  
  // middle cell
  var cell = row.insertCell(i+2); // last field
  var textNode = document.createTextNode(" new ")
  cell.appendChild(textNode);
}


function addMoreFiles() {
//
// code borrowed from: http://www.mredkj.com/tutorials/tableaddrow.html
//
  var tbl = document.getElementById('FileTable');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var i
  for (i=lastRow;i<lastRow+5;i++) {
	  var row = tbl.insertRow(lastRow);
  
	  // left cell
	  var cellMiddle = row.insertCell(0);
	  var textNode = document.createTextNode("File:")
	  cellMiddle.appendChild(textNode);

	  // right cell
	  var cellRight = row.insertCell(1);
	  var el = document.createElement('input');
	  el.type = 'file';
	  el.name = 'File' + iteration;
	  el.size = 40;
	  cellRight.appendChild(el);
  }
}


function selectTrip(lngTripAvailabilityID,lngAvailable,strTripName,strStart,strEnd) {
	window.opener.TripName.innerText = strTripName;
	window.opener.document.forms["BookingForm"].tripavailabilityid.value = lngTripAvailabilityID;
	window.opener.document.forms["BookingForm"].AvailableSeats.value = lngAvailable;
	var seatsDisplay = window.opener.document.getElementById("seatsAvail");
	seatsDisplay.innerHTML = lngAvailable;
	var startDate = window.opener.document.getElementById("departureDate");
	startDate.innerHTML = strStart;
	var endDate = window.opener.document.getElementById("returnDate");
	endDate.innerHTML = strEnd;
	var startDate 
	window.close();
}

function openClose(divID) {
	var e = document.getElementById(divID);
	if (e.style.display == "block") e.style.display = "none"
	else e.style.display = "block";
}
