// 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 

function explain(msg) {
newwin = window.open('','help_window','scrollbars,top=150,left=150,width=250,height=250');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="focus()"><p><input type="button" value="click to close" onClick=window.close()></p>');
write('<p>' + msg + '</p>');
write('</body></html>');
close();
   }
}

function openNew(url) {
	var win = window.open(url, "details", "scrollbars,top=50,left=50,alwaysRaised=1,height=350,width=400");
	win.focus();
}


function openPrint(url) {
	var win = window.open(url, "print", "scrollbars,menubar,top=50,left=50,alwaysRaised=1,height=400,width=800");
	win.focus();
}


function openFeedback(url) {
	var win = window.open(url, "feedback", "scrollbars,top=20,left=20,alwaysRaised=1,height=450,width=400,screenX=400,screenY=400,top=400,left=400");
	win.focus();
}

function openTell(url) {
	var win = window.open(url, "tellfriend", "scrollbars,top=20,left=20,alwaysRaised=1,height=475,width=400,screenX=400,screenY=400,top=400,left=400");
	win.focus();
}

/////////////////////////////////////////////////

// booking 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') {
	 } 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

/////////////////////////////////////////////////

// custom form field validation
function validateCustomForm (form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

if (el.name == 'clientinterests' || el.name == 'clientchild' || el.name == 'clientchildages' || el.name == 'clientaddinfo' || el.name == 'clienttel' || el.name == 'clientstreet2' || el.name == 'clientzip') {
	 } else {
    if (el.type == 'text' || el.type == 'textarea' ) { 
      if (el.value == '') {
        alert('Please fill out the text field ' + el.name);
		//alert("Please fill out the text field " + '\n' + el.id);
        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

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();
   }
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function checkEmail (field) {
  if (!isValidEmail(field.value)) {
    alert('Please enter email address in the correct format e.g. you\@you.com');
    field.focus();
    field.select();
  }
}

// checks length of text in a textarea
function checkMaxLength(field, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
}

// Begin resize iframe

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
	iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
	var docHt = getDocHeight(iframeWin.document);
	// need to add to height to be sure it will all show
	if (docHt) iframeEl.style.height = docHt + 20 + "px";
  }
}

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
	if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
	if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
	if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

// AJAX  
////////////////////////////////////////////////////////////////////////////////
var xmlhttp;

function loadXMLDoc(method,url,input,cfunc) {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=cfunc;
	if (method == "get") {
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	} else if (method == "post") {
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send(input);
	}
}

function myAjax(method,url,input,target) {
	loadXMLDoc(method,url,input,function() { 
		if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
			/*
			// if you want more than one target for this result unhash this and seperate targets with , in the call
			var array_target=target.split(",");
			for(i=0;i<array_target.length;i++) {
				document.getElementById(array_target[i]).innerHTML=xmlhttp.responseText; 
			}
			*/
			document.getElementById(target).innerHTML=xmlhttp.responseText; 
		} 
	} );
}

// REPLACE ELEMENTS 
////////////////////////////////////////////////////////////////////////////////
function replaceContentWithValue(target,value) {
	document.getElementById(target).innerHTML=value;
}

// CHANGE SAME SIZE IMAGE 
////////////////////////////////////////////////////////////////////////////////
function replaceImage(target,value) {
	document.getElementById(target).src=value;
}

// SHOW HIDE ELEMENTS 
////////////////////////////////////////////////////////////////////////////////
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { 
		document.getElementById(d).style.display = "block"; 
	} else { 
		document.getElementById(d).style.display = "none"; 
	}
}

// REPLACE CONTENT OF A DIV WITH CONTENT OF A HIDDDEN DIV
function SwapDivContents(toid,fromid) {

	if (document.getElementById) {

		var from_container = document.getElementById(fromid);
		var from_content = from_container.innerHTML

		var to_container = document.getElementById(toid);
		to_container.innerHTML = from_content;

	  }

	  else if (document.all) {

		var from_container = window.document.all[fromid];
		var from_content = from_container.innerHTML

		var to_container = window.document.all[toid];
		to_container.innerHTML = from_content;

	  }

	  else if (document.layers) {

		var from_container = window.document.layers[fromid];
		var from_content = from_container.innerHTML

		var to_container = window.document.layers[toid];
		to_container.innerHTML = from_content;

	}


}

function toggleDiv(showdivid,hidedivids) {

	var hidedivids = hidedivids.split(",");

	for (i=0;i<hidedivids.length;i++) {
		if (hidedivids[i] == showdivid) {
			document.getElementById(hidedivids[i]).style.display = 'block';
			setIframeHeight('ifrm2');
		} else {
			document.getElementById(hidedivids[i]).style.display = 'none';
		}
	}
}

function getHash() {
	var hash = window.location.hash;
	return hash.substring(1); // remove #
}

function highlightLastTripViewed() {
	if (getHash()) {
		if (document.getElementById(getHash()))	{
			document.getElementById(getHash()).style.background = '#deedcd';
		}
	}
}

/*window.onload = function() {
	document.getElementById("package_itinerary_container").style.display = "none";
	document.getElementById("package_reviews_container").style.display = "none";
}*/

function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}

function move_up(obj) {
	obj.scrollTop = 0;
}
