	function el(field)
	{
		return document.getElementById(field);
	}

	getFormId = function(strId)
	{
		var frms = document.forms;
		for(i=0;i<frms.length;i++)
		{
			if(frms[i].id == strId)
			{
				return i;
			}
		}
		return false;
	};

	getFormById = function(strId)
	{
		var frmId = getFormId(strId);

		if(frmId != false)
		{
			return document.forms[frmId];
		}
	};

	function msgBox_wait(msg, smlmsg)
	{
		strSmlMsg = "";
		if(smlmsg && smlmsg.length > 0)
		{
			strSmlMsg = '<br /><span style="font-size: 10px;">' + smlmsg + '</span>';
		}

		var html =  '<div style="width:1px;height:18px;overflow:hidden"></div><p style="text-align: center;"><img src="/images/spinner/swan.gif" /><br />Please Wait... ' + msg + '<br /><br />' +
					'<img src="/images/spinner/bar.gif" align="middle"/><br />' + strSmlMsg + '</p>';

		internalPopup(html);
	}
	
	
	function msgBox_wait_big(msg, smlmsg)
	{
		strSmlMsg = "";
		if(smlmsg && smlmsg.length > 0)
		{
			strSmlMsg = '<br /><span style="font-size: 10px;">' + smlmsg + '</span>';
		}

		var html =  '<p style="text-align: center;"><img src="/images/spinner/swan.gif" /><br />Please Wait... ' + msg + '<br /><br />' +
					'<img src="/images/spinner/bar.gif" align="middle"/><br />' + strSmlMsg + '</p>';

		bigInternalPopup(html);
	}
	

	function msgBox_alert(title, message)
	{
		var content = '<div style="text-align:left; margin-left:15px;"><h4 style="font-size:14px;font-weight:bold;color:#6a7d84;">' + title + '</h4>' +
					'<p style="color:#9c9c9c">' + message + '</p></div>';
		var button = '<input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP"/>';
		var html2 = '<div style="float:left;width:80px;height:80px;margin-top:15px;"><img src="/images/web20/Alert.png"></div>'
					+'<div style="float:left;width:250px;height:155px;">'
						+'<div style="width:100%;height:130px;margin-top:20px;">'+content+'</div>'
						+'<div style="height:25px;text-align:right;margin-right:10px;">'+button+'</div>'
					+'</div>'
					+'<div id="clr"></div>';
		
		internalPopup(html2);
		el('clsIntP').focus();
	}

	/*
	 * Created this to deal with the Payment issue dealing with a dynamic amount of error messages. 
	 * The more error message now will use a larger window
	 */
	function msgBoxBig_alert(title, message, errorCount)
	{
		textHeight = 0;
		
		if (errorCount > 3)
			textHeight = 230;
		else
			textHeight = 130;
		
		var html =  '<div class="alert"><h4 class="default">' + title + '</h4>' +
					'<p>' + message + '<br /><br /><br /></p>' +
					'<input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP" /></div>';
		var content = '<div style="text-align:left; margin-left:15px;"><h4 style="font-size:14px;font-weight:bold;color:#6a7d84;">' + title + '</h4>' +
					'<p style="color:#9c9c9c">' + message + '</p></div>';
		var button = '<input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP"/>';
		var html2 = '<div style="float:left;width:80px;height:80px;margin-top:15px;"><img src="/images/web20/Alert.png"></div>'
					+'<div style="float:left;width:250px;height:155px;">'
						+'<div style="width:100%;">'+content+'</div>'
						+'<div style="height:25px;text-align:center;">'+button+'</div>'
					+'</div>'
					+'<div id="clr"></div>';
		
		if (errorCount > 3)
		{
			internalPopUp2(html2);
			el('clsIntP').focus();
		}
		else
		{
			internalPopup(html2);
			el('clsIntP').focus();
		}
	}
	
	msgBox_confirm = function(title, message, confirmFunc, confirmText, cancelText)
	{
		if(!confirmFunc) return false;
		if(!confirmText) var confirmText = 'Confirm';
		if(!cancelText) var cancelText = 'Cancel';

		var html =  '<div class="alert"><h4 class="default">' + title + '</h4>' +
					'<p>' + message + '<br /><br /><br /></p>' +
					'<input type="button" value="'+confirmText+'" onclick="'+confirmFunc+'closeInternalPopup();" id="cnfFunc" /> ' +
					'<input type="button" value="'+cancelText+'" onclick="closeInternalPopup();" id="clsIntP" /></div>';
		internalPopup(html);
		el('clsIntP').focus();
	};

	function addInputSubmitEvent(form, input, func)
	{

	    if(!func) var func = function(){form.submit();};

	    input.onkeydown = function(e)
	    {
	        e = e || window.event;
	        if (e.keyCode == 13)
	        {
	            func();
	            return false;
	        }
	    };
	}

	function internalPopup(html)
	{
		hideSelectBoxes();
		hideFlash();

		var intpopup;
		var pop_content;
		
		intpopup = $('intpopupdiv');
		pop_content = $('pop_content');
		
		if(intpopup == null)
		{
			intpopup = document.createElement('div');
			intpopup.setAttribute("id", "intpopupdiv");
			document.body.appendChild(intpopup);
		}

		if(pop_content == null){
			var overlay = document.createElement('div');
				overlay.setAttribute("id", "pop_overlay");
				/*
				overlay.setAttribute("style", "background: #000000; z-index: 100; position: absolute; left: 0px; top:0px; opacity: 0.6; filter: alpha(opacity=60);");
				*/
				overlay.style.background = "#000000";
				overlay.style.zIndex = "100";
				overlay.style.position = "absolute";
				overlay.style.top = "0px";
				overlay.style.left = "0px";
				overlay.style.opacity = "0.6";
				overlay.style.filter = "alpha(opacity=60)";
				
	
			var pop_window = document.createElement('div');
				pop_window.setAttribute("id", "pop_window_bg");
				pop_window.style.background = "url(/images/web20/popup_bg.png) no-repeat top left";
				pop_window.style.width = "350px";
				pop_window.style.height = "198px";
				pop_window.style.zIndex = "102";
				pop_window.style.position = "absolute";
				pop_window.innerHTML = "&nbsp;";
				
			var pop_window2 = document.createElement('div');
				pop_window2.setAttribute("id", "pop_window");
				pop_window2.style.width = "350px";
				pop_window2.style.height = "198px";
				pop_window2.style.zIndex = "110";
				pop_window2.style.position = "absolute";
				
				
				var pop_top = document.createElement('div');
					pop_top.setAttribute("id", "pop_top");
					pop_top.style.width='100%';
					pop_top.style.height='10px';
				
					pop_content = document.createElement('div');
					pop_content.setAttribute("id", "pop_content");
					pop_content.style.margin="0px 10px";
					
				var pop_footer = document.createElement('div');
					pop_footer.setAttribute("id", "pop_footer");
					pop_footer.style.width='100%';
					pop_footer.style.height='10px';
					
				pop_window2.appendChild(pop_top);
				pop_window2.appendChild(pop_content);
				pop_window2.appendChild(pop_footer);

			intpopup.appendChild(overlay);
			intpopup.appendChild(pop_window);
			intpopup.appendChild(pop_window2);
			document.body.appendChild(intpopup);
		}

		pop_content.innerHTML = html;
		/*
		var textHtml = document.createTextNode(html);
		$('pop_content').appendChild(textHtml);
		*/

		resizeInternalPopup();

		positionInternalPopup();

		window.onscroll = function() { positionInternalPopup(); };
	}
	
	function bigInternalPopup(html)
	{
		hideSelectBoxes();
		hideFlash();

		var intpopup;
		var pop_content;
		
		intpopup = $('intpopupdiv');
		pop_content = $('pop_content');
					  
		if(intpopup == null)
		{
			intpopup = document.createElement('div');
			intpopup.setAttribute("id", "intpopupdiv");
			document.body.appendChild(intpopup);
		}

		if(pop_content == null){
			var overlay = document.createElement('div');
				overlay.setAttribute("id", "pop_overlay");
				overlay.style.background = "#000000";
				overlay.style.zIndex = "100";
				overlay.style.position = "absolute";
				overlay.style.top = "0px";
				overlay.style.left = "0px";
				overlay.style.opacity = "0.6";
				overlay.style.filter = "alpha(opacity=60)";
				
	
			var pop_window = document.createElement('div');
				pop_window.setAttribute("id", "pop_window_bg");
				pop_window.style.background = "url(/images/web20/popup/bigPopupBg.png) no-repeat top left";
				pop_window.style.width = "699px";
				pop_window.style.height = "506px";
				pop_window.style.zIndex = "102";
				pop_window.style.position = "absolute";
				
			var pop_window2 = document.createElement('div');
				pop_window2.setAttribute("id", "pop_window");
				pop_window2.style.background = "url(/images/web20/popup/bigPopupBg.png) no-repeat top left";
				pop_window2.style.width = "699px";
				pop_window2.style.height = "506px";
				pop_window2.style.zIndex = "102";
				pop_window2.style.position = "absolute";
				
				
				var pop_top = document.createElement('div');
					pop_top.setAttribute("id", "pop_top");
					pop_top.style.width = "100%";
					pop_top.style.height = "10px";
				
					pop_content = document.createElement('div');
					pop_content.setAttribute("id", "pop_content");
					pop_content.style.margin = "0px 10px";
					
				var pop_footer = document.createElement('div');
					pop_footer.setAttribute("id", "pop_footer");
					pop_footer.style.width = "100%";
					pop_footer.style.height = "10px";
					
				pop_window2.appendChild(pop_top);
				pop_window2.appendChild(pop_content);
				pop_window2.appendChild(pop_footer);

			intpopup.appendChild(overlay);
			intpopup.appendChild(pop_window);
			intpopup.appendChild(pop_window2);
			document.body.appendChild(intpopup);
		}

		var close_button_html = '<div style="text-align: right"> <img src="/images/web20/popup/close_button.png" onclick="closeInternalPopup()" style="cursor:pointer"/></div>';
		
		pop_content.innerHTML = close_button_html+html;

		resizeInternalPopup();

		positionInternalPopup();

		window.onscroll = function() { positionInternalPopup(); };
	}
	
	function internalPopUp2(html)
	{
			hideSelectBoxes();
		hideFlash();

		var intpopup;
		var pop_content;
		
		intpopup = $('intpopupdiv');
		pop_content = $('pop_content');
					  
		if(intpopup == null)
		{
			intpopup = document.createElement('div');
			intpopup.setAttribute("id", "intpopupdiv");
			document.body.appendChild(intpopup);
		}

		if(pop_content == null){
			var overlay = document.createElement('div');
				overlay.setAttribute("id", "pop_overlay");
				overlay.style.background = "#000000";
				overlay.style.zIndex = "100";
				overlay.style.position = "absolute";
				overlay.style.top = "0px";
				overlay.style.left = "0px";
				overlay.style.opacity = "0.6";
				overlay.style.filter = "alpha(opacity=60)";
				
	
			var pop_window = document.createElement('div');
				pop_window.setAttribute("id", "pop_window_bg");
				pop_window.style.background = "url(/images/web20/popup/popupBg_370x370.png) no-repeat top left";
				pop_window.style.width = "370px";
				pop_window.style.height = "370px";
				pop_window.style.zIndex = "102";
				pop_window.style.position = "absolute";
				
			var pop_window2 = document.createElement('div');
				pop_window2.setAttribute("id", "pop_window");
				pop_window2.style.background = "url(/images/web20/popup/popupBg_370x370.png) no-repeat top left";
				pop_window2.style.width = "370px";
				pop_window2.style.height = "370px";
				pop_window2.style.zIndex = "102";
				pop_window2.style.position = "absolute";
				
				
				var pop_top = document.createElement('div');
					pop_top.setAttribute("id", "pop_top");
					pop_top.setAttribute("style", "width: 100%; height: 10px;");
				
					pop_content = document.createElement('div');
					pop_content.setAttribute("id", "pop_content");
					pop_content.setAttribute("style", "margin: 0px 10px;height: 315px;overflow-y: auto;");
					
				var pop_footer = document.createElement('div');
					pop_footer.setAttribute("id", "pop_footer");
					pop_footer.setAttribute("style", "width: 100%; height: 10px;");
					
				pop_window2.appendChild(pop_top);
				pop_window2.appendChild(pop_content);
				pop_window2.appendChild(pop_footer);

			intpopup.appendChild(overlay);
			intpopup.appendChild(pop_window);
			intpopup.appendChild(pop_window2);
			document.body.appendChild(intpopup);
		}

		pop_content.innerHTML = html;
		
		var button_html = '<div style="text-align: center"><input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP" style="background:transparent url(/images/web20/Flights/book_button.png) no-repeat; width:20px;height:80px;"/></div>';
		
		//pop_content.innerHTML += button_html;

		resizeInternalPopup();

		positionInternalPopup();

		window.onscroll = function() { positionInternalPopup(); };
	}
	
	function internalPopUp2_closeButton(html)
	{
		internalPopUp2(html);
		var button_html = '<div style="text-align: center"><input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP"/></div>';
		el('pop_footer').innerHTML = button_html;
		
	}
	
	pip = function(){positionInternalPopup();};

	function positionInternalPopup()
	{
		var POP_HEIGHT	= el('pop_window_bg').offsetHeight;
		var POP_WIDTH	= el('pop_window_bg').offsetWidth;

		var pagesize = getPageSize();

		var psTop = getPageScrollTop();
		var psLft = getPageScrollLeft();

		el('pop_window_bg').style.left	= psLft + ((pagesize[2] - POP_WIDTH)  / 2 ) + 'px';
		el('pop_window_bg').style.top	= psTop + ((pagesize[3] - POP_HEIGHT)  / 2 ) + 'px';
		
		var POP_HEIGHT	= el('pop_window').offsetHeight;
		var POP_WIDTH	= el('pop_window').offsetWidth;

		var pagesize = getPageSize();

		var psTop = getPageScrollTop();
		var psLft = getPageScrollLeft();

		el('pop_window').style.left	= psLft + ((pagesize[2] - POP_WIDTH)  / 2 ) + 'px';
		el('pop_window').style.top	= psTop + ((pagesize[3] - POP_HEIGHT)  / 2 ) + 'px';
	}

	function resizeInternalPopup()
	{
		var pagesize = getPageSize();

		el('pop_overlay').style.height = pagesize[1] + 'px';
		el('pop_overlay').style.width = pagesize[0] + 'px';
	}

	function getPageScrollTop()
	{
		var dele = document.documentElement;
		if (self.pageYOffset || self.pageXOffset)
		{
			return self.pageYOffset;
		}
		else if (dele && dele.scrollTop || dele.scrollLeft )
		{
			return dele.scrollTop;
		}
		else if (document.body)
		{
			return document.body.scrollTop;
		}
		return false;
	}

	function getPageScrollLeft()
	{
		var dele = document.documentElement;
		if (self.pageYOffset || self.pageXOffset)
		{
			return self.pageXOffset;
		}
		else if (dele && dele.scrollTop || dele.scrollLeft )
		{     // Explorer 6 Strict
			return dele.scrollLeft;
		}
		else if (document.body)
		{     // all other Explorers
			return document.body.scrollLeft;
		}
		return false;
	}

	function getPageSize()
	{
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY)
		{
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight)
		{     // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else
		{     // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;

		if (self.innerHeight)
		{	// all except Explorer
			if(document.documentElement.clientWidth)
			{
				windowWidth = document.documentElement.clientWidth;
			}
			else
			{
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{     // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body)
		{     // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		if(yScroll < windowHeight)
		{
			pageHeight = windowHeight;
		}
		else
		{
			pageHeight = yScroll;
		}

		if(xScroll < windowWidth)
		{
			pageWidth = xScroll;
		}
		else
		{
			pageWidth = windowWidth;
		}

		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	}

	function removeElement(obj)
	{
		var par = obj.parentNode;
		par.removeChild(obj);
	}

	function closeInternalPopup()
	{
		window.onscroll = '';
		/*
		new Effect.Puff(el('pop_window'), {duration: 0.5});
		
		var t = setTimeout("removeElement(el('pop_overlay'));removeElement(el('pop_window'));showSelectBoxes();showFlash();", 600);
		*/
		removeElement(el('pop_overlay'));
		removeElement(el('pop_window_bg'));
		removeElement(el('pop_window'));
		showSelectBoxes();
		showFlash();
		
	}
	
	function showSelectBoxes()
	{
		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++)
		{
			selects[i].style.visibility = "visible";
		}
	}

	function hideSelectBoxes()
	{
		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++)
		{
			selects[i].style.visibility = "hidden";
		}
	}

	function showFlash()
	{
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++)
		{
			flashObjects[i].style.visibility = "visible";
		}

		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++)
		{
			flashEmbeds[i].style.visibility = "visible";
		}
	}

	function hideFlash()
	{
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++)
		{
			flashObjects[i].style.visibility = "hidden";
		}

		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++)
		{
			flashEmbeds[i].style.visibility = "hidden";
		}

	}

	function selval(field)
	{
		obj = el(field);
		if(obj)
		{
			return obj.options[obj.selectedIndex].value;
		}
		else
		{
			return null;
		}
	}

	function radval(name)
	{

		var e = document.getElementsByName(name);
		if(!e) return false;

		for(i = 0; i < e.length; i++)
		{
			if(e[i].checked == true) return e[i].value;
		}
	}

	function setRadVal(name, val)
	{

		var e = document.getElementsByName(name);
		if(!e) return false;

		for(i = 0; i < e.length; i++)
		{
			e[i].checked = ((e[i].value == val) ? true : false);
		}
	}

	function ss_buildform(ref, dest, items)
	{
		var formobj = document.createElement('form');
		formobj.method = 'post';
		formobj.action = dest;
		formobj.id = ref;
		document.body.appendChild(formobj);

		for (i = 0; i<items.length;i++)
		{
			var html = '<input type="hidden" name="'+items[i].name+'" value="'+items[i].value+'" />';
			el(ref).innerHTML += html;
		}

		var html = '<input type="submit" id="'+ref+'submit" style="display: none;" />';
		el(ref).innerHTML += html;
	}

	function ss_reset_fields(items)
	{
		for(var item in items)
		{
			obj = el(item);
		}
	}

    var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

    function carSearchChangeDoCtry(ctry)
    {
        var doctry = document.getElementById('doctry_id');
        for(i = 0; i < doctry.length; i++)
        {
            if(doctry[i].value==ctry) doctry[i].selected = true;
        }
    }

    searchDateResetDays = function(fieldid, year, month)
    {
        var field = el(fieldid);
        var dd = new Date(year, month, 0);
        var dim = dd.getDate();
        var sval = field.options[field.selectedIndex].value;
        for(i = field.length -1; i > 0; i--)
        {
            removeElement(field.options[i]);
        }
        for(i = 0; i < 31; i++)
        {
            field.options[i] = new Option((i + 1), (i + 1));
            if(sval==i+1)field.options[i].selected = true;
        }

        for(i = field.length -1; i >= 0; i--)
        {
            if(field.options[i].value > dim)
            {
                removeElement(field.options[i]);
            }
        }

        while(field.options[field.selectedIndex].value != sval)
        {
            sval--;
            if(field.options[sval -1]) field.options[sval -1].selected = true;
        }
    };

    function carSearchValidateHome(items)
    {
		return true;
    }

	document.getElementsByClassName = function(clsName)
	{
		var retVal = new Array();
		var elements = document.getElementsByTagName("*");
		for(var i = 0;i < elements.length;i++)
		{
			if(elements[i].className.indexOf(" ") >= 0)
			{
				var classes = elements[i].className.split(" ");
				for(var j = 0;j < classes.length;j++)
				{
					if(classes[j] == clsName) retVal.push(elements[i]);
				}
			}
			else if(elements[i].className == clsName) retVal.push(elements[i]);
		}
		return retVal;
	};

	setActive = function(btn)
	{
		var currAct = document.getElementsByClassName('active');

		if(currAct.length)
		{
			currAct[0].className = '';
		}
		var ele = $('nav_' + btn).parentNode;
		ele.className = 'active';
		setCookie('currnav', btn);
	};

	function findPos(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent)
		{
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent)
			{
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}

	function setCookie(name, value, days)
	{
		if(days)
		{
			var date = new Date();
			date.setTime(date.getTime() + (days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else
		{
			var expires = "";
		}

		document.cookie = name + "=" + value + expires + "; path=/";
	}

	function getCookie(name)
	{
		var ce = document.cookie.split(';');
		for(i=0;i<ce.length;i++)
		{
			var c = ce[i];
			var tmp = c.split('=');
			if(tmp[0] != name) continue;
			if(tmp[1] != "")
			{
				return tmp[1];
			}
			else
			{
				return null;
			}
		}
		return null;
	}

	function delCookie(name)
	{
		createCookie(name, "", -10);
	}

	var pageLoaded = false;

	function addDOMLoadEvent(func)
	{
		if(pageLoaded)
		{
			func();
		}
		else
		{
			if (!window.__load_events)
			{
			    var init = function ()
			    {
                    // quit if this function has already been called
                    if (arguments.callee.done) return;

                    // flag this function so we don't do the same thing twice
                    arguments.callee.done = true;
                    pageLoaded = true;

                    // kill the timer
                    if (window.__load_timer)
                    {
                        clearInterval(window.__load_timer);
                        window.__load_timer = null;
                    }

                    // execute each function in the stack in the order they were added
                    for (var i=0;i < window.__load_events.length;i++)
                    {
                        window.__load_events[i]();
                    }
                    window.__load_events = null;
                };

                // for Mozilla/Opera9
                if (document.addEventListener)
                {
                    document.addEventListener("DOMContentLoaded", init, false);
                }

                // for Internet Explorer
                /*@cc_on @*/
                /*@if (@_win32)
                document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");
                var script = document.getElementById("__ie_onload");
                script.onreadystatechange = function()
                {
                    if (this.readyState == "complete")
                    {
                        init(); // call the onload handler
                    }
                };
                /*@end @*/

                // for Safari
                if (/WebKit/i.test(navigator.userAgent))
                { // sniff
                    window.__load_timer = setInterval(function()
                    {
                        if (/loaded|complete/.test(document.readyState))
                        {
                            init(); // call the onload handler
                        }
                    }, 10);
                }

                // for other browsers
                window.onload = init;

                // create event function stack
                window.__load_events = [];
            }

            // add function to event stack
            window.__load_events.push(func);
        }
    }

	function preLoadImages()
	{
		var d = document;
		if(d.images)
		{
			if(!d.SSpre) d.SSpre=new Array();
			var i,j = d.SSpre.length;
			var a = preLoadImages.arguments;
			for(i=0; i<a.length; i++)
			{
				if (a[i].indexOf("#")!=0)
				{
					d.SSpre[j]=new Image;
					d.SSpre[j++].src=a[i];
				}
			}
		}
	}

	// Checks to make sure there was a response recieved in an ajax request.
	// If not, update the pop_content div with a nice friendly error message.
	function checkAjaxResponse(response)
	{
		if(response.length == 0)
		{
			var html =  '<div style="width:1px;height:1px"></div><div class="alert"><h4 class="default">Search Failed</h4>' +
						'<p>Sorry, it seems there was a problem performing your search. Please try again in a few minutes. If the problem continues, please email <a href="mailto:support@skyswan.com.au">support@skyswan.com.au</a>.<br /><br /><br /></p>' +
						'<input type="button" value="Close" onclick="closeInternalPopup();" id="clsIntP" /></div>';
			el('pop_content').innerHTML = html;
			el('clsIntP').focus();
		}
		else
		{
			return true;
		}
	}

	setDayName = function(field,y,m,d)
    {
        var weekday=new Array(7);
        weekday[0]='Sun';
        weekday[1]='Mon';
        weekday[2]='Tue';
        weekday[3]='Wed';
        weekday[4]='Thu';
        weekday[5]='Fri';
        weekday[6]='Sat';

        var date = new Date();
        date.setFullYear(y,(m - 1),d);
        $(field).innerHTML = weekday[date.getDay()];
    };

    setDayNameMonthYear = function(field, my, d)
    {
    	var weekday=new Array(7);
        weekday[0]='Sun';
        weekday[1]='Mon';
        weekday[2]='Tue';
        weekday[3]='Wed';
        weekday[4]='Thu';
        weekday[5]='Fri';
        weekday[6]='Sat';

    	var month_year = new Array();
    	var currentTime = new Date();

    	var start_year = currentTime.getFullYear();
    	var start_month = currentTime.getMonth();

    	for(var index = 0; index < 11; index++)
    	{
    		month_year[start_month + 1] = start_year;

    		currentTime.setMonth(currentTime.getMonth() + 1);

    	    start_year = currentTime.getFullYear();
    	    start_month = currentTime.getMonth();
    	}

    	month = my;
    	year = month_year[my];

    	var date = new Date();
    	date.setFullYear(year, (month -1), d);
    	$(field).innerHTML = weekday[date.getDay()];
    };

    function updateUsername(email)
	{
	    var username = "";

	    if(email != "")
	    {
	   		username = email;
	    }
	    else
	    {
	    	username = "Your Username is your E-mail";
	    }

	    el('theUserName').innerHTML = username;
	}

	function resetField(originalValue, field)
	{
		el(field).value = originalValue;
	}

	function resetGender()
	{
		if(radval('gender') == "F")
		{
			document.personalDetails.male.checked = true;
		}
		else
		{
			document.personalDetails.female.checked = true;
		}
    }

	function swTab(tab)
    {
        if(loaded && currNav != tab)
        {
        	new Effect.Fade('headNav', {duration:0.25, queue:'end'});
        	new Effect.Appear('hcLoad', {duration:0.25, queue:'end'});
        	new Ajax.Updater('headNav', '/Main/getNav/' + tab,
        	{
        		asynchronous:true,
        		evalScripts:true,
        		onComplete:function(request, json)
        		{
        			new Effect.Fade('hcLoad', {duration:0.25, queue:'end'});
        			new Effect.Appear('headNav', {duration:0.25, queue:'end'});
        			loaded=true;
        		}
        	});
        	currNav = tab;
        	setActive(tab);
        }
    }

    doNifty = function(niftyFunc)
    {
 		var btns = document.getElementsByClassName('btn_exp');
 		var btns_blue = document.getElementsByClassName('btn_exp_blue');
 		for(i = 0; i < btns_blue.length; i++)
 		{
 			btns.push(btns_blue[i]);
 		}
    	for (var i = 0; i < btns.length; i++)
    	{
	        var btn = btns[i];
        	btn.style.display = 'none';
    	}

    	niftyFunc();

    	for (var i = 0; i < btns.length; i++)
    	{
	        var btn = btns[i];
        	btn.style.display = '';
    	}
    };

    function msgBox_wait_large(msg, smlmsg)
	{
		strSmlMsg = "";
		if(smlmsg && smlmsg.length > 0)
		{
			strSmlMsg = '<br /><span style="font-size: 10px;">' + smlmsg + '</span>';
		}

		var html =  '<p style="text-align: center;"><img src="/images/spinner/swan.gif" /><br />Please Wait... ' + msg + '<br /><br />' +
					'<img src="/images/spinner/bar.gif" align="middle"/><br />' + strSmlMsg + '</p>';

		internalPopupLarge(html);
	}

	function internalPopupLarge(html)
	{
		hideSelectBoxes();
		hideFlash();

		var overlay = '<div id="pop_overlay"></div>' +
					  '<div id="pop_window">' +
					      '<div class="pop_top_large"></div>' +
					      '<div id="pop_content_large"></div>' +
					      '<div class="pop_footer_large"></div>' +
					  '</div>';

		el('intpopupdiv').innerHTML = overlay;
		el('pop_content_large').innerHTML = html;

		var POP_HEIGHT	= el('pop_window').offsetHeight;
		var POP_WIDTH	= el('pop_window').offsetWidth;

		resizeInternalPopup();

		positionInternalPopup();

		window.onscroll = function() { positionInternalPopup(); };
	}

	handleAjaxError = function(response)
	{
		var responseText = response.responseText;
		var pc = $('pop_content');

		if(pc && pc.visible())
		{
			pc.innerHTML = responseText;
		}
		else
		{
			internalPopup(responseText);
		}
	};
	
	sortList = function(listObj)
	{
		var arrTexts = [];
		var arrValues = [];
		var arrOldTexts = [];
		
		for(i = 0; i < listObj.length; i++)
		{
			arrTexts[i] = listObj.options[i].text;
			arrValues[i] = listObj.options[i].value;
			arrOldTexts[i] = listObj.options[i].text;
		}

		arrTexts.sort();
		
		for(i = 0; i < listObj.length; i++)
		{
			listObj.options[i].text = arrTexts[i];
			for(j = 0; j < listObj.length; j++)
			{
				if(arrTexts[i] == arrOldTexts[j])
				{
					listObj.options[i].value = arrValues[j];
					j = listObj.length;
				}
			}
			
			if(i == 0) listObj.options[0].selected = true;
		}

	};
	
	moveNext = function(event, checkObj, focusObj, maxLength)
	{
		if(String.fromCharCode(event.which).match(/\w/) && checkObj.value.length >= maxLength) focusObj.focus();
	};