/* -----------------------------------------------------------------------
	Title:		Shared scripts
	Author:		Tavis Tucker, ttucker@esitemarketing.com
	Copyright:	E-site Marketing, LLC, http://www.esitemarketing.com
	Created:	03 May 2006
------------------------------------------------------------------------- */
    function getSelect(channel,ttype){
        var doc = null;
        if (typeof window.ActiveXObject != 'undefined' ){
            doc = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            doc = new XMLHttpRequest();
        }
  		if (doc){
            doc.open("GET", "chiclets.php?id="+channel+"&type="+ttype, false);
            doc.send(null);
            document.getElementById("chiclets").innerHTML = doc.responseText;
  		}
    }

    function clear() {
        document.getElementById('chiclets').innerHTML ='';
    }

	function check_date()
	{
          var return_this = true
          var arrive = document.getElementById('arrive').value
          var depart = document.getElementById('depart').value
          arrive_array = arrive.split('/')
          depart_array = depart.split('/')
          if(arrive_array[0] > depart_array[0] || arrive_array[1] > depart_array[1] || arrive_array[2] > depart_array[2])
          {
           alert('\'Check In\' date can\'t be greater than \'Check Out\' date.')
           return_this = false
          }
          return return_this
         }


// Toggle Functions
// val = numeric value from toggle() (initially from form)
// elem = id of element to be shown/hidden
// d = display value (non-IE browsers)
function showHide( val, elem, d ) {
	if ( val == "Other: " ) { // show
		if ( navigator.appName.indexOf( "Microsoft" ) > -1 ) { // branch IE
			document.getElementById( elem ).style.display = "block";
		} else {
			document.getElementById( elem ).style.display = d;
		}
	} else { // hide
		document.getElementById( elem ).style.display = "none";
	}
}


// The Highlighter
// home-grown form highlighting script
function formHighlight() {
	var x = new Array( "input", "textarea" );
	for ( var i = 0; i < x.length; i++ ) {
		var y = document.getElementsByTagName( x[i] );
		for ( var j = 0; j < y.length; j++ ) {
			if ( y[j].type != "radio" && y[j].type != "checkbox" && y[j].type != "submit" && y[j].type != "image" ) { // prevents unsightly highlighting for these elements in IE
				y[j].onfocus = function() {
					this.style.backgroundColor = "#eef6fa";
					return false;
				}
				y[j].onblur = function() {
					this.style.backgroundColor = "#ffffff";
					return false;
				}
			}
		}
	}
}

/* Source : http://www.easy-designs.net/code/jsUtilities/ and http://www.embimedia.com/resources/labs/js-inarray.html */
Array.prototype.inArray = function(needle) {
	for (i = 0, j = this.length; i < j; i++) {
		if (this[i] === needle) {
			return i;
		}
	}
	return false;
};

/* Source : http://muffinresearch.co.uk/archives/2006/04/29/getelementsbyclassname-deluxe-edition/ */
function getElementsByClassName(strClass, strTag, objContElm) {
	strTag = strTag || "*";
	objContElm = objContElm || document;
	var objColl = (strTag == '*' && document.all) ? document.all : objContElm.getElementsByTagName(strTag);
	var arr = new Array();
	var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
	var arrClass = strClass.split(delim);
	for (i = 0, j = objColl.length; i < j; i++) {
	var arrObjClass = objColl[i].className.split(' ');
		if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
		var c = 0;
		comparisonLoop:
		for (k = 0, l = arrObjClass.length; k < l; k++) {
			for (m = 0, n = arrClass.length; m < n; m++) {
				if (arrClass[m] == arrObjClass[k]) c++;
				if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
					arr.push(objColl[i]);
					break comparisonLoop;
				}
			}
		}
	}
	return arr;
}

// To cover IE 5.0's lack of the push method
/*
Array.prototype.push = function(value) {
  this[this.length] = value;
}
*/

/* Source : http://prototype.conio.net/ */
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

/* Source : "DOM Scripting: Web Design with Javascript and the Document Object Model" Copyright 2005 by Jeremy Keith */
function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

function createPopupLinks(linkClass, container) {
	container = $(container) || document;
	linkClass = linkClass || "link-popup";
	arrLinks = getElementsByClassName(linkClass, "a", container);
	for ( i = 0, j = arrLinks.length; i < j; i++ ) {
		arrLinks[i].onclick = function () {
			arrParams = this.getAttribute("rel").split(",");
			strOptions = "width="+arrParams[1]+",height="+arrParams[2];
			if ( arrParams.length > 3 ) {
				for ( k = 3, l = arrParams.length; k < l; k++ ) {
					strOptions += "," + arrParams[k];
				}
			}
			window.open(this.getAttribute("href"),arrParams[0],strOptions);
			return false;
		}
	}
}

function createLinks(linkClass, container, altText, target) {
	container = $(container) || document;
	altText = altText || "";
	target = target || "_self";
	arrLinks = getElementsByClassName(linkClass, "a", container);
	imageName = linkClass.split("-");
	imageName = "images/icon-" + imageName[1] + ".gif";
	for (i = 0, j = arrLinks.length; i < j; i++) {
		wrapper = document.createElement("span");
		wrapper.style.whiteSpace = "nowrap";
		newLink = arrLinks[i].cloneNode(true);
		newLink.setAttribute("target",target);
		icon = document.createElement("img");
		icon.setAttribute("src",imageName);
		icon.setAttribute("alt",altText);
		icon.style.marginLeft = "3px";
		dummy = document.createElement("span");
		dummy.style.display = "inline-block";
		wrapper.appendChild(newLink);
		insertAfter(icon,newLink);
		insertAfter(dummy,icon);
		arrLinks[i].parentNode.replaceChild(wrapper,arrLinks[i]);
	}
}

/* Source : http://simon.incutio.com/archive/2004/05/26/addLoadEvent */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if ( typeof window.onload != "function" ) {
		window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

/* Source : http://www.brothercake.com/site/resources/scripts/domready/ and http://www.openjsan.org/doc/a/au/autarch/DOM/Ready/0.14/lib/DOM/Ready.html */
function onDomReady(func) {
	var t = setInterval( function() {
		if ( typeof document.getElementsByTagName != "undefined" && typeof document.getElementById != "undefined" && ( document.getElementsByTagName( "body" )[0] != null || document.body != null ) ) {
			if ( typeof func == "function" ) {
				func();
				clearInterval(t);
			}
		}
	}, 250 );
}

function previousSibling( elem ) {
	while( elem.previousSibling.nodeType != 1 ) {
		elem = elem.previousSibling;
	}
	return elem.previousSibling;
}

/* ----- Run function when DOM is loaded -------------------------------- */

// based on brothercake's domFunction: http://www.brothercake.com/site/resources/scripts/domready/
// and Dave Rolsky's DOM.Ready: http://www.openjsan.org/doc/a/au/autarch/DOM/Ready/0.14/lib/DOM/Ready.html
// Usage:
//		onDomReady( myFunction );

function onDomReady(f) {
	var t = setInterval( function() {
		if ( typeof document.getElementsByTagName != "undefined" && typeof document.getElementById != "undefined" && ( document.getElementsByTagName( "body" )[0] != null || document.body != null ) ) {
			f(); clearInterval(t);
		}
	}, 250 );
}


/* ----- Flash activation for IE ---------------------------------------- 
function activateActiveX() {
	if (getElementsByClassName('section-0')) { return false;}
	if ( !document.getElementsByTagName || !document.body.outerHTML || !document.compatMode ) return false;
	var elems = new Array( "object", "applet" );
	for ( i = 0, j = elems.length; i < j; i++ ) {
		var objects = document.getElementsByTagName(elems[i]);
		for( k = 0, l = objects.length; k < l; k++ ) {
			var params = "";
			for ( m = 0, n = objects[k].childNodes.length; m < n; m++ ) {
				params += objects[k].childNodes[m].outerHTML;
			}
			objects[k].outerHTML = objects[k].outerHTML.replace( "</" + elems[i].toUpperCase() + ">", params + "</" + elems[i].toUpperCase() + ">" );
		}
	}
}


onDomReady(activateActiveX);*/

