
// Begin number of characters limiter  
function taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
//  End 

/////////////////////////////////////////////////

// Begin formatting functions for adding tags in text area
function boldThis(from) { 
strSelection = document.selection.createRange().text; 
if (strSelection == "") { 
return false; 
} 
else document.selection.createRange().text = "[bold]" + strSelection 
+ "[/bold]"  
return;
}
function redThis(from) { 
strSelection = document.selection.createRange().text 
if (strSelection == "") { 
return false; 
} 
else document.selection.createRange().text = "[red]" + strSelection 
+ "[/red]" 
return;
}
function ulineThis(from) { 
strSelection = document.selection.createRange().text 
if (strSelection == "") { 
return false; 
} 
else document.selection.createRange().text = "[uline]" + strSelection 
+ "[/uline]" 
return;
}
//  End

/////////////////////////////////////////////////

// Begin validate numbers only in a field
function validate(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only numbers are accepted!");
field.focus();
field.select();
   }
}
//  End 

/////////////////////////////////////////////////

// form field validation
function validateForm (form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

if (el.name == 'Comments') {
	 } else {
    if (el.type == 'text' || el.type == 'textarea' ) { 
      if (el.value == '') {
        alert('Please fill out the text field ' + el.name);
        el.focus();
        return false;
      }
    }
    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked) {
        alert('Please check one of the radio buttons ' + el.name);
        el.focus();
        return false;
      }
    }
   }
  }
  return true;
}
// End

/////////////////////////////////////////////////

// form field validation
function validateBookConfForm (form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

if (el.name == 'booking_comments' || el.name == 'booking_deposit' || el.name == 'eid' || el.name == 'pid') {
	 } else {
    if (el.type == 'text' || el.type == 'textarea' ) { 
      if (el.value == '') {
        alert('Please fill out the text field ' + el.name);
        el.focus();
        return false;
      }
    }

    else if (el.type.indexOf('select') != -1) {
      if (el.selectedIndex == 0) {
        alert('Please select a value of the select field ' + el.name);
        el.focus();
        return false;
      }
    }

    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked) {
        alert('Please check one of the radio buttons ' + el.name);
        el.focus();
        return false;
      }
    }
   }
  }
  return true;
}
// End

/////////////////////////////////////////////////

// moves from left box to right box
function movelr(fbox, tbox, max) {

	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var arrValFbox = new Array();
	var arrValTbox = new Array();
	var arrValLookup = new Array();

	var i;

	// pj this bit gives out the limit warning value of 1=2, 2=3, 3=4,etc for the receive box
	if (tbox.options.length < max) {

		for (i = 0; i < tbox.options.length; i++) {
		//pj swapped arrLookup[tbox.options[i].text] = tbox.options[i].value; for below
		arrLookup[tbox.options[i].text] = tbox.options[i].text;
		arrValLookup[tbox.options[i].value] = tbox.options[i].value; // added
		arrTbox[i] = tbox.options[i].text;
		arrValTbox[i] = tbox.options[i].value; // added
		}

		var fLength = 0;
		var tLength = arrTbox.length;

		for(i = 0; i < fbox.options.length; i++) {

			//pj swapped	arrLookup[tbox.options[i].text] = tbox.options[i].value; for below
			arrLookup[fbox.options[i].text] = fbox.options[i].text;
			arrValLookup[fbox.options[i].value] = fbox.options[i].value; // added

			//pj swapped value below for text
			if (fbox.options[i].selected && fbox.options[i].text != "") {
			arrTbox[tLength] = fbox.options[i].text;
			arrValTbox[tLength] = fbox.options[i].value; // added
			tLength++;

			//pj added 2 lines below to include the selected option back into the left box
			arrFbox[fLength] = fbox.options[i].text;
			arrValFbox[fLength] = fbox.options[i].value; // added
			fLength++;

			} else {
				arrFbox[fLength] = fbox.options[i].text;
				arrValFbox[fLength] = fbox.options[i].value; // added
				fLength++;
			}
		}

		//pj hashed to prevent sorting
		//arrFbox.sort();
		//arrTbox.sort();

		fbox.length = 0;
		tbox.length = 0;
		var c;

		for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrValLookup[arrValFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
		}

		for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrValLookup[arrValTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	   }

	} else {

		// pj this bit gives out the limit warning
		alert('Selection will be discarded as the limit of ' + max + ' is reached.');

	}

}
// end

/////////////////////////////////////////////////

// moves from right box to left box
function moverl(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;

	for (i = 0; i < tbox.options.length; i++) {
	arrLookup[tbox.options[i].text] = tbox.options[i].value;
	arrTbox[i] = tbox.options[i].text;
	}

var fLength = 0;
var tLength = arrTbox.length;

	for(i = 0; i < fbox.options.length; i++) {
	arrLookup[fbox.options[i].text] = fbox.options[i].value;

		if (fbox.options[i].selected && fbox.options[i].value != "") {
		arrTbox[tLength] = fbox.options[i].text;
		tLength++;

//pj removed 2 lines below to remove the selected option from the right box.
//		arrFbox[fLength] = fbox.options[i].text;
//		fLength++;

		}
		else {
		arrFbox[fLength] = fbox.options[i].text;
		fLength++;
		}
	}

//pj hashed to prevent sorting
//arrFbox.sort();
//arrTbox.sort();

fbox.length = 0;
tbox.length = 0;
var c;

	for(c = 0; c < arrFbox.length; c++) {
	var no = new Option();
	no.value = arrLookup[arrFbox[c]];
	no.text = arrFbox[c];
	fbox[c] = no;
	}

	for(c = 0; c < arrTbox.length; c++) {
	var no = new Option();
	no.value = arrLookup[arrTbox[c]];
	no.text = arrTbox[c];
	tbox[c] = no;
   }
}
// End

/////////////////////////////////////////////////

// sends the formatted info from the selects
function sendInfo(formVar,box) {
    formVar.length = 0;
    var strValue = new String();
    for(var i=0; i<box.length; i++) {
        strValue += box[i].value;
        if (i < box.length-1) {
            strValue += ",";
        }
    }
    formVar.value = strValue;
}
//  End -->

/////////////////////////////////////////////////

// Begin open help window
function explain(msg) {
newwin = window.open('','help_window','scrollbars,top=150,left=150,width=350,height=400');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html><head><title>Help</title></head>');
write('<body onLoad="focus()"><p><input type=button style="background-color: COCOCO; border-color: 555555; border-width: 1; font-size: 10pt; font-family: arial;" value="Click to close when finished" onClick=window.close()></p>');
write('<p>' + msg + '</p>');
write('</body></html>');
close();
   }
}
//  End -->

/////////////////////////////////////////////////

// opend new window
function openNew(url) {
	var win = window.open(url, "details", "scrollbars,top=50,left=50,alwaysRaised=1,height=350,width=400");
	win.focus();
}
// End


/////////////////////////////////////////////////


// opens feedback window
function openFeedback(url) {
	var win = window.open(url, "details", "scrollbars,top=20,left=20,alwaysRaised=1,height=450,width=400");
	win.focus();
}
// End

/////////////////////////////////////////////////

// opens print window
function openPrint(url) {
	var win = window.open(url, "print", "scrollbars,menubar,top=50,left=50,alwaysRaised=1,height=400,width=400");
	win.focus();
}
// End

/////////////////////////////////////////////////

// removes back capability
//history.forward();
