/*
$Revision: 21 $
$Author: Dan $
$Modtime: 4/01/05 13:54 $ 
*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// no longer used by trips, but references (may) exist in CMS pages
function FormActionFreetext(f_name) { 
    document.forms[f_name].action='/index.cfm/fa/home.textsearch/search_text/'+escape(document.forms[f_name].search_text.value);
    document.forms[f_name].submit();
}

function FormActionProperty(prop_url_key) {
    document.propertyform.action='/index.cfm/'+prop_url_key+'/'+escape(document.propertyform[prop_url_key].value);
    document.propertyform.submit();
}

//This function checks whether the required form field (text) has a value
function validRequired(formField,Message) {
	var result = true;
	if (formField.value == "") {
		alert(Message);
		formField.focus();
		result = false;
	}
	return result;
}

// function used by help pop-ups
var popupWinHelp;
function popupWindow(targ) {
	var popup = new Object;
	popup.url=targ;
	var winOpts='scrollbars=yes,width=350,height=350,resizable=yes,toolbar=no,location=no';
	if (popupWinHelp==null || popupWinHelp.closed) {
		popupWinHelp=window.open(popup.url,'popup',winOpts);
	} else {
		popupWinHelp.focus(popup.url,'popup',winOpts);
		popupWinHelp.open(popup.url,'popup',winOpts);
	}
}

function popupWindow2(url, f_width, f_height,f_resizable,f_scrollbars,winname) {	
	var f_left=0, f_top=0;
	if(screen){
		f_left=(screen.width-f_width)/2;
		f_top=(screen.height-f_height)/2;
	} 
	popup=open(url, winname, 'resizable='+f_resizable+',scrollbars='+f_scrollbars+',width='+f_width+',height='+f_height+',left='+f_left+',top='+f_top);
	popup.focus();
}

function openWindow(page,width,height,scrolling){
	var winWidth = width;
	var winHeight = height;
	var posLeft = (screen.availWidth - winWidth) / 2;
	var posTop = (screen.availHeight - winHeight) / 2;
	var winInfo = 'width=' + winWidth + ',height=' + winHeight + ',left=' + posLeft + ',top=' + posTop + ',location=no,menubar=no,toolbar=no,status=no,scrollbars=' + scrolling + ',resizable=yes';
	var poplaunch = window.open(page, 'poplaunch', winInfo);
        poplaunch.focus();
}

function resetVisibleFields(myform) {
	var f 	= document.forms[myform];
	var ln 	= f.elements.length;

	for (var i = 0; i < ln; i++) {
		var e = f.elements[i];
		var t = e.type;

		if (t == 'checkbox') {
			e.checked = false;
		} else if (t=='radio') {
			if (e.value == -1 || e.value == '') {
				e.checked = true; // -1 or '' are assumed to be the defulat "CHECKED" radio...
			} else {
				e.checked = false;			
			}
		} else if (t == 'text' || t == 'textarea' || t == 'password') {
			e.value = '';
		} else if (t == 'select-one' || t == 'select-multiple') {
			e.options[0].selected = true;
			for (var j = 0; j < e.length; j++) {
				e.options[j].selected = false;
			}
		}
	}
	return false;
}

function resetAllFields(myform) {
	var f 	= document.forms[myform];
	var ln 	= f.elements.length;

	for (var i = 0; i < ln; i++) {
		var e = f.elements[i];
		var t = e.type;

		if (t == 'checkbox') {
			e.checked = false;
		} else if (t=='radio') {
			if (e.value == -1 || e.value == '') {
				e.checked = true; // -1 or '' are assumed to be the defulat "CHECKED" radio...
			} else {
				e.checked = false;			
			}
		} else if (t == 'text' || t == 'textarea' || t == 'password' || t == 'hidden') {
			e.value = '';
		} else if (t == 'select-one' || t == 'select-multiple') {
			e.options[0].selected = true;
			for (var j = 0; j < e.length; j++) {
				e.options[j].selected = false;
			}
		}
	}
	return false;
}

function t2setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + '=' + escape(value) 
		+	((expires.length > 0) ? '; expires=' + expires.toGMTString() : '')
		+	((path) ? '; path=' + path : '')
		+	((domain) ? '; domain=' + domain : '')
		+	((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

function t2getCookie(name) {
	var dc = document.cookie;
	var prefix = name + '=';
	var begin = dc.indexOf('; ' + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) {
			return null;
		}
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(';', begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

// Rudimentary Browser Detection
IE4plus = (document.all) ? true : false;

/* ***************************
** Provided by
** Andrew Clover (and at doxdesk dot com)
** http://and.doxdesk.com/ 
** http://worldtimzone.com/blog/date/2002/09/24

Way to make form field entries URL-safe and also needed to support multiple languages. The JavaScript escape() function fixes ASCII characters that are not valid for use in URLs, but does not handle unicode characters well. 

The encodeURIComponent() function introduced in IE5.5, Netscape 6, and Mozilla does exactly what is needed. However, since the function is unavailable in Netscape 4.x and IE5, a different solution is needed. encodeURIComponentNew() created to properly escape characters for use in the URL.
*/

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

function switchEncodeURI(fld)
{
	if (fld == "") return false;
	var encodedField = "";
	var s = fld;
	if (typeof encodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		encodedField = encodeURIComponent(s);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		encodedField = encodeURIComponentNew(s);
	}
	return encodedField;
}




			
