var scrollPosX,scrollPosY;
String.prototype.toNumber=function(){
	/* 
		Purpose:	To convert a string to Numeric representation of the String
					Strips all white space and non-digit characters, with the exception of the decimal.
					e.g. "300.3" to 300.3, "$425.00" to 425.00, "100%" to 1.00 (or it's decimal equivalent);
					Intentionally Limited & Narrow in Scope
		Returns:	Number (Integer|Decimal)
	*/
	var n=Number(this.replace(/[^\d.]/g,''));
	if(this.match('%')!==null){
		n=(n/100);
	}
	return n;
};

var CFWI={};

	// helpers
	CFWI.Css={
		removeClassName:function(el,CssClass){
			if(CFWI.IsDefined(el)){
				if(el.className.toLowerCase().indexOf(CssClass.toLowerCase())>-1){
					el.className=el.className.replace(CssClass,'');
				}else{
					return;
				}
			}else{
				return;
			}
		}
	};
	
	// create custom defaultButtons object
	// Example: CFWI.DefaultButtons.registerButton('containerID','buttonID');
	CFWI.DefaultButtons={
		registerButton:function(cId,bId){
			var oC=document.getElementById(cId);
			var oB=document.getElementById(bId);
			if(CFWI.IsDefined(oC)&&CFWI.IsDefined(oB)){
				attachEventListener(oC,'keypress',function(e){
					CFWI.DefaultButtons.Click(e,oB);
				},true);
			}
		},
		Click:function(e,lbtn){
			if(!e.which&&!e.keyCode){
				return;
			}else{
				var k=(e.which||e.keyCode);
				var t=(e.target||e.srcElement);
				try{
					if(k===13){
						if(t.type==='text'){if(e.preventDefault){e.preventDefault();}e.returnValue=false;}
						if(t.type!=='textarea'){
							if(lbtn.getAttribute('onclick')){
								if(!(document.all)){
									s=lbtn.getAttribute('onclick').toString();
								}else{
									s=lbtn.attributes["onclick"].value;
								}
								if(s.indexOf('return ')>-1){
									s=s.replace('return ','');
								}
								if(eval(s)){
									eval(lbtn.href);
								}else{
									if(e.preventDefault){e.preventDefault();}
									e.returnValue = false;
									return false;
								}
							}else{
								eval(lbtn.href);
								return false;
							}
						}
					}
				}
				catch(err){
					//alert(err.message);
					return false;
				}
			}
		}
	};
	
	CFWI.IsArray=function(item){
		/*
			Purpose:		To determine if the item is an Object of Type Array
			Expects:		@param item = Any DOM or JavaScript Object OR Array of DOM or JavaScript Objects
			Dependencies:	BrokerIDX Object
			Returns:		(Boolean) true:false
		*/
		var s=typeof(item),rv=false;
		rv = (s==='object'&&item!==null)?(typeof(item.length)==='number'&&typeof(item.splice)==='function'&&(item.propertyIsEnumerable &&!(item.propertyIsEnumerable('length'))))?true:false:false;     
		return rv
	}
	CFWI.IsDefined=function(item){
		/*
			Purpose:		To determine if the item (or in the case of an Array, collection of items) exists before performing operations on the item
			Expects:		@param item = Any DOM or JavaScript Object OR Array of DOM or JavaScript Objects
							e.g. String,Object,Null,Function,Array,HTMLDomElement,Window,['String','String',Object,HTMLDomElement,Function]
			Dependencies:	BrokerIDX Object
			Returns:		(Boolean) true:false
		*/
		var s=typeof(item),rv=false;
		if(s!=='undefined'&&item!=='null'&&item!==null){
			rv=true;
			if(CFWI.IsArray(item)){
				for(var oI in item){
					if(typeof(item[oI])==='undefined'||item[oI]==='null'||item[oI]===null){
						rv=false;
						break;
					}
				}
			}
		}
		return rv;
	}
	
	CFWI.Tabs={
		CurrentTab:null,
		SelectEventFired:false,
		MultiPage:{
			ClearHeight:function(args){
				/*
				Purpose:		To Remove Inline CSS height declarations from MultiPage PageViews
				Expects:		@param args = An array literal containing ClientIDs of MultiPage PageView Objects in a TabStrip/MultiPage Setup
								e.g. args=['idA','idB']
				Dependencies:	Requires ASP.NET Ajax ScriptManager on Page
								CFWI Object
				Returns:		No Return Value
				*/
				var oP; 
				if(CFWI.IsDefined(args)){
					if(args.length>0){
						for(var i=0;i<args.length;i+=1){
							oP=$get(args[i]);
							if(CFWI.IsDefined(oP)){
								oP.style.height='auto';
								if(oP.offsetParent){
									oP.offsetParent.style.height='100px';
									oP.offsetParent.style.height='auto';
								}
							}
						}
					}
				}
			},
			PageView:{
				Select:function(sender,multipage){
					/*
					Purpose:		To raise a custom PageView Select event when associated TabStripTab is selected
					Expects:		@param sender = A reference to the selected ComponentArt TabStrip Tab Object
									@param multipage = A reference to the associated ComponentArt MultiPage Object
									e.g. (TabStripTabObject,MultiPageObject)
					Dependencies:	Requires ASP.NET Ajax ScriptManager on Page
									ComponentArt TabStrip/MultiPage Controls
									CFWI Object
					Returns:		No Return Value
					*/
					if(CFWI.IsDefined([sender,multipage])){
						var id = sender.get_pageViewId();
						var oPV = multipage.findPageById(id).get_element();
						CFWI.Tabs.MultiPage.IFrame.AdjustAll(oPV,true,false);
					}
				}
			},
			IFrame:{
				AdjustAll:function(pageview,cH,cW){
					/*
					Purpose:		Address width / height issues of dynamically sized iframes in MultiPage control when different PageView is selected before current PageView iframes have finished loading
					Expects:		@param pageview = A reference to the selected ComponentArt PageViewPage Object's DomElement
									@param cH = (Boolean|Integer) Whether to size the iframe to match the height of it's contents or to the value of the number provided // defaults to true
									@param cW = (Boolean|Integer) Whether to size the iframe to match the width of it's contents or to the value of the number provided // defaults to false
									e.g. (PageViewHTMLDomObject,ChangeHeight,ChangeWidth)
									
									@optional override param maxheight-{value} where {value} is an number of type (Integer|Decimal|Percentage) and is added to the Iframe's CssClass collection
									@optional override param maxwidth-{value} where {value} is an number of type (Integer|Decimal|Percentage) and is added to the Iframe's CssClass collection
									e.g. <iframe class="maxheight-350 maxwidth-90%" />
									
					Dependencies:	Requires ASP.NET Ajax ScriptManager on Page
									ComponentArt TabStrip/MultiPage Controls
									CFWI Object
					Returns:		No Return Value
					*/
					var H=cH?cH:true,W=cW?cW:false,oF,F,N;
					if(CFWI.IsDefined(pageview)){
						var aIF = pageview.getElementsByTagName("iframe");
						for(var iframe in aIF){
							oF=aIF[iframe];
							F=parent.frames[oF.name];
							if(CFWI.IsDefined(F)){
								if(oF.src.indexOf(F.location.pathname)===-1){
									var mH=this.UseMaxHeight(oF);
									var mW=this.UseMaxWidth(oF);
									if(mH[0]>0){
										this.SetHeight(oF,F,mH[0],mH[1]);	
									}else{
										this.SetHeight(oF,F,H);
									}
									if(mW[0]>0){
										this.SetWidth(oF,F,mW[0],mW[1]);
									}else{
										this.SetWidth(oF,F,W);
									}
								}
							}
						}
					}
				},
				Adjust:function(f,id,cH,cW){
					/*
					Purpose:		Override width / height issues of a single instance of an iframe
					Expects:		@param f = (String|Object) Can be either the name of an iframe or a reference to the instance of the iframe via the parent.frames[frameName] method
									@param id = (String|Object) Can be either the id of an iframe or a reference to the instance of the iframe via the $get(id) method
									@param cH = (Boolean|Integer) Whether to size the iframe to match the height of it's contents or to the value of the number provided // defaults to true
									@param cW = (Boolean|Integer) Whether to size the iframe to match the width of it's contents or to the value of the number provided // defaults to false
									e.g. (FrameName,$get(FrameID),ChangeHeight,ChangeWidth)
									
									@optional override param maxheight-{value} where {value} is an number of type (Integer|Decimal|Percentage) and is added to the Iframe's CssClass collection
									@optional override param maxwidth-{value} where {value} is an number of type (Integer|Decimal|Percentage) and is added to the Iframe's CssClass collection
									e.g. <iframe class="maxheight-350 maxwidth-90%" />
									
					Dependencies:	Requires ASP.NET Ajax ScriptManager on Page
									CFWI Object
					Returns:		No Return Value
					*/
					var H=cH?cH:true,W=cW?cW:false,F,oF;
					F=(typeof(f)==='string')?parent.frames[f]:(typeof(f)==='object')?f:null;
					oF=(typeof(id)==='string')?$get(id):(typeof(id)==='object')?id:null;
					if(CFWI.IsDefined([F,oF])){
						var mH=this.UseMaxHeight(oF);
						var mW=this.UseMaxWidth(oF);
						if(mH[0]>0){
							this.SetHeight(oF,F,mH[0],mH[1]);	
						}else{
							this.SetHeight(oF,F,H);
						}
						if(mW[0]>0){
							this.SetWidth(oF,F,mW[0],mW[1]);
						}else{
							this.SetWidth(oF,F,W);
						}
					}
				},
				SetHeight:function(oF,F,H,P){
					/*
						Purpose:	Supporting function used by CFWI.Tabs.MultiPage.Iframe Object methods (AdjustAll | Adjust).
									// DO NOT MODIFY
					*/
					var p=P?P:false,h=(Sys.UI.DomElement.getBounds(F.window.document.body).height)+10;
					switch(typeof(H)){
						case 'boolean':
							if(H){
								oF.style.height=(h)+'px';
							}
							break;
						case 'number':
							if(p){
								(h<(h*H))?oF.style.height=(h)+'px':oF.style.height=(h*H)+'px';
							}else{
								(h<H)?oF.style.height=(h)+'px':oF.style.height=(H)+'px';
							}
							break;
						default:
							oF.style.height=(oF.style.height)+'px';
							break;
					}
				},
				SetWidth:function(oF,F,W,P){
					/*
						Purpose:	Supporting function used by CFWI.Tabs.MultiPage.Iframe Object methods (AdjustAll | Adjust).
									// DO NOT MODIFY
					*/
					var p=P?P:false,w=(Sys.UI.DomElement.getBounds(F.window.document.body).width)+10;
					switch(typeof(W)){
						case 'boolean':
							if(W){
								oF.style.width=(w)+'px';
							}
							break;
						case 'number':
							if(p){
								(w<(w*W))?oF.style.width=(w)+'px':oF.style.width=(w*W)+'px';
							}else{
								(w<W)?oF.style.width=(w)+'px':oF.style.width=(W)+'px';
							}
							break;
						default:
							oF.style.width=(oF.style.width)+'px';
							break;
					}
				},
				UseMaxHeight:function(oF){
					/*
						Purpose:	Supporting function used by CFWI.Tabs.MultiPage.Iframe Object methods (AdjustAll | Adjust).
									// DO NOT MODIFY
					*/
					var rv=0,aCss,P=false;
					if(oF.className.length > 0 && oF.className.indexOf("maxheight")>-1){
						aCss = oF.className.split(" ");
						for(var c in aCss){
							if(aCss[c].indexOf("maxheight")>-1){
								rv=aCss[c].split("-")[1];
								break;
							}
						}
						if(typeof(rv)==='string'){
							if(rv.match("%")){
								P=true;	
							}
							rv=rv.toNumber();
						}
					}
					return [rv,P];
				},
				UseMaxWidth:function(oF){
					/*
						Purpose:	Supporting function used by CFWI.Tabs.MultiPage.Iframe Object methods (AdjustAll | Adjust).
									// DO NOT MODIFY
					*/
					var rv=0,aCss,P=false;
					if(oF.className.length > 0 && oF.className.indexOf("maxwidth")>-1){
						aCss = oF.className.split(" ");
						for(var c in aCss){
							if(aCss[c].indexOf("maxwidth")>-1){
								rv=aCss[c].split("-")[1];
								break;
							}
						}
						if(typeof(rv)==='string'){
							if(rv.match("%")){
								P=true;	
							}
							rv=rv.toNumber();
						}
					}
					return [rv,P];
				}
			}
		},
		LoadTabUrl:function(fName,url){
			/* Deprecated */
			if(CFWI.IsDefined(fName)&&CFWI.IsDefined(url)){
				var f=parent.frames[fName]?parent.frames[fName]:window.frames[fName];
				if(CFWI.IsDefined(f)){
					if(!(f.location.href.toLowerCase().indexOf(url.toLowerCase())>-1)){
						f.location.replace(url);
					}
				}
			}
		},
		SetTabPageHeight:function(args){
			/* Deprecated */
			if(!(document.all)){
				var obj;
				if(CFWI.IsDefined(args)){
					if(args.length>0){
						for(var i=0;i<args.length;i+=1){
							obj=$get(args[i]);
							if(CFWI.IsDefined(obj)){
								obj.style.height='auto';
								if(obj.offsetParent){
									obj.offsetParent.style.height='100px';
									obj.offsetParent.style.height='auto';
								}
							}
						}
					}
				}
			}
		},
		SetIframeHeight:function(iframe){
			/* Deprecated */			
			var d=parent.frames[iframe.name].document;
			if(CFWI.IsDefined(d)&&CFWI.IsDefined(iframe)){
				try{
					setTimeout(function(){
						iframe.style.height=(d.body.offsetHeight+40)+'px';
					},50);
				}
				catch(err){
					alert(err);
				}
			}
		}
	};
	
	
	// Handler for Selecting Search Types
	// Typical Usage: (using Microsofts $addHandler shortcut method)
	/*
		$addHandler(window,'load',function(e){
			CFWI.Search.addEvent($get('tabSearchType'));
		});
	*/
	CFWI.Search={
		selectedItem:null,
		onTypeSelect:function(e){
			var sender=null,n,pnl;
			if(CFWI.IsDefined(e)){
				sender=e.target||e.srcElement;
			}
			if(!(CFWI.IsDefined(sender))){
				sender=CFWI.Search.selectedItem;
			}
			if(CFWI.IsDefined(sender)){
				n=sender.parentNode;
				if(n.tagName.toLowerCase()!=='li'){
					while(n.tagName.toLowerCase()!=='li'){
						n=n.parentNode;
					}
					if(n.tagName.toLowerCase()==='li'){
						CFWI.Search.clearPrior(n.parentNode);
						n.className='type-selected';
						pnl=getObj(n.id+'_panel');
						if(CFWI.IsDefined(pnl)){
							pnl.style.display='block';
						}
					}else{
						return;
					}
				}
			}
		},
		clearPrior:function(el){
			var items,pnl;
			if(CFWI.IsDefined(el)){
				if(el.tagName.toLowerCase()==='ul'){
					items=el.getElementsByTagName('li');
					if(items.length>0){
						for(var i=0;i<items.length;i++){
							CFWI.Css.removeClassName(items[i],'type-selected');
							pnl=getObj(items[i].id+'_panel');
							if(CFWI.IsDefined(pnl)){
								pnl.style.display='none';
							}
						}
					}
				}
			}else{
				return;
			}
		},
		addEvent:function(el){
			var items,c=0;
			if(!(CFWI.IsDefined(el))){
				return;
			}else{
				if(el.tagName.toLowerCase()==='ul'){
					items=el.getElementsByTagName("input");
					if(items.length>0){
						for(var i=0;i<items.length;i++){
							if(items[i].type==='radio'){
								attachEventListener(items[i],'click',CFWI.Search.onTypeSelect,false);
								if(items[i].checked){
									c+=1;
									CFWI.Search.selectedItem=items[i];
								}
							}
						}
						if(c===0){
							items[items.length-1].checked=true;
							CFWI.Search.selectedItem=items[items.length-1];
						}
						CFWI.Search.onTypeSelect();
					}else{
						return;
					}
				}else{
					return;
				}
			}
		}
	}
	
	CFWI.Search.Map={
		loaded:false
	}
	
	CFWI.Search.Images={
		Main:{
			id:'',
			src:'',
			width:262,
			create:function(){
				var el='<img class="photo" id="' + this.id + '" src="' + this.src + '" width="' + this.width + '" onclick="CFWI.Search.Images.Main.enlarge(this)" title="" alt="" />';
				document.write(el);
			},
			update:function(sender,d){
				var img,el=getObj(CFWI.Search.Images.Main.id),n,l=CFWI.Search.Images.Thumbs.items.length;
				if(CFWI.IsDefined(el)&&CFWI.IsDefined(sender)){
					if(!(CFWI.IsDefined(d))){
						el.src=sender.href;
						img=sender.getElementsByTagName('img')[0];
						CFWI.Search.Images.Thumbs.cPos=CFWI.Search.Images.Thumbs.index(img);
						CFWI.Search.Images.Buttons.toggle(CFWI.Search.Images.Thumbs.cPos,l);
					}else{
						CFWI.Search.Images.Thumbs.cPos=CFWI.Search.Images.Thumbs.index(el);
						if(d==='p'){
							n=(CFWI.Search.Images.Thumbs.cPos-1);
							if(n>=0){
								el.src=CFWI.Search.Images.Thumbs.items[n].parentNode.href;
								CFWI.Search.Images.Buttons.toggle(n,l);
							}
						}else if(d==='n'){
							n=(CFWI.Search.Images.Thumbs.cPos+1);
							if(n<=(l-1)){
								el.src=CFWI.Search.Images.Thumbs.items[n].parentNode.href;
								CFWI.Search.Images.Buttons.toggle(n,l);
							}
						}
					}
					CFWI.Search.Images.Text.write();
				}
				return false;
			},
			enlarge:function(sender){
				if(CFWI.IsDefined(sender)){
					window.open(sender.src);
				}
			},
			init:function(){
				if(CFWI.IsDefined(CFWI.Search.Images.Thumbs.items)){
					var el=getObj(CFWI.Search.Images.Main.id);
					if(CFWI.IsDefined(el)){
						if(CFWI.Search.Images.Thumbs.length()>0){
							el.src=CFWI.Search.Images.Thumbs.items[0].parentNode.href;
							CFWI.Search.Images.Buttons.toggle(CFWI.Search.Images.Thumbs.cPos,CFWI.Search.Images.Thumbs.length());
							if(CFWI.Search.Images.Thumbs.length()===1){
								el.src=CFWI.Search.Images.Thumbs.items[0].parentNode.href;
								try{
									CFWI.Search.Images.Buttons.lbtnRow().style.display='none';
									CFWI.Search.Images.Thumbs.col().style.display='none';
								}catch(err){
									//alert(err);
								}
							}
						}else{
							el.src=CFWI.Search.Images.Main.src;
							try{
								CFWI.Search.Images.Buttons.lbtnRow().style.display='none';
								CFWI.Search.Images.Thumbs.col().style.display='none';
							}catch(err){
								//alert(err);
							}
						}
					}
				}
			}
		},
		Thumbs:{
			items:null,
			columnId:'',
			col:function(){
				return getObj(this.columnId);
			},
			length:function(){
				if(CFWI.IsDefined(CFWI.Search.Images.Thumbs.items)&&CFWI.Search.Images.Thumbs.items.length > 0){
					return CFWI.Search.Images.Thumbs.items.length;
				}else{
					return 0;
				}
			},
			index:function(el){
				var v=0;
				if(CFWI.IsDefined(this.items)&&this.items.length>0){
					for(var i=0;i<this.items.length;i++){
						if(this.items[i].src==el.src){
							v=i;
							break;
						}else if(this.items[i].parentNode.href==el.src){
							v=i;
							break;
						}
					}
				}
				return v;
			},
			cPos:0
		},
		Buttons:{
			rowId:'CFWI_imagePaging',
			prevId:'lbtnPrev',
			nextId:'lbtnNext',
			lbtnPrev:function(){
				return getObj(this.prevId);
			},
			lbtnNext:function(){
				return getObj(this.nextId);
			},
			lbtnRow:function(){
				return getObj(this.rowId);
			},
			toggle:function(index,count){
				if(CFWI.IsDefined(index)&&CFWI.IsDefined(count)){
					if(index>=0 && index<=(count-1)){
						if(index===0&&CFWI.IsDefined(CFWI.Search.Images.Buttons.lbtnPrev())){
							CFWI.Search.Images.Buttons.lbtnPrev().className=CFWI.Search.Images.Buttons.disabledCssClass;
						}else{
							CFWI.Search.Images.Buttons.lbtnPrev().className='';
						}
						if(index===(count-1)&&CFWI.IsDefined(CFWI.Search.Images.Buttons.lbtnNext())){
							CFWI.Search.Images.Buttons.lbtnNext().className=CFWI.Search.Images.Buttons.disabledCssClass;
						}else{
							CFWI.Search.Images.Buttons.lbtnNext().className='';
						}
						CFWI.Search.Images.Thumbs.cPos=index;
					}
				}else{
					return;
				}
			},
			disabledCssClass:'disabled-button'
		},
		Text:{
			id:'CFWI_viewText',
			span:function(){
				return getObj(this.id);	
			},
			write:function(){
				if(CFWI.IsDefined(this.span)){
					var s='';
					if(CFWI.IsDefined(CFWI.Search.Images.Thumbs.items)&&CFWI.Search.Images.Thumbs.items.length > 0){
						s='viewing <b>' + (CFWI.Search.Images.Thumbs.cPos+1) + '</b> of <b>' + CFWI.Search.Images.Thumbs.length() + '</b>';
						this.span().innerHTML=s;
					}
				}
			}
		}
	};
	
	// Custom Object to Force Reload of Framed Page
	CFWI.Frame={
		Reload:function(fName){
			if(CFWI.IsDefined(fName)){
				var f=parent.frames[fName]?parent.frames[fName]:window.frames[fName];
				if(CFWI.IsDefined(f)){
					f.location.replace(f.location.href);
				}
			}
		},
		ReloadSubFrame:function(obj){
			if(CFWI.IsDefined(obj)){
				obj.location.replace(obj.location.href);
			}
		}
	}
	
	CFWI.Effects={
		getOpacity:function(id){
			var o=getObj(id);
			if(typeof(o)!=='undefined'){
				if(typeof(o.style.opacity)!=='undefined'){
					if(o.style.opacity.toString().length>0){
						return (o.style.opacity*100);
					}else{
						return '';
					}
				}else if(typeof(o.style.MozOpacity)!=='undefined'){
					if(o.style.MozOpacity.toString().length>0){
						return (o.style.MozOpacity*100);
					}else{
						return '';
					}
				}else if(typeof(o.style.KhtmlOpacity)!=='undefined'){
					if(o.style.KhtmlOpacity.toString().length>0){
						return (o.style.KhtmlOpacity*100);
					}else{
						return '';
					}
				}else if(typeof(o.style.filter)!=='undefined'){
					if(o.style.filter.toString().length>0){
						return parseInt(o.style.filter.toString());
					}else{
						return '';
					}
				}
			}
		},
		setOpacity:function(id,v){
			var o=getObj(id),x=(v/100);
			if(typeof(o)!=='undefined'){
				o.style.opacity=(x);
				o.style.MozOpacity=(x);
				o.style.KhtmlOpacity=(x);
				o.style.filter="alpha(opacity="+v+")";
			}
		},
		fade:function(id,which,ms,display){
			var timer=0,i,speed,v,o;
			if(typeof(ms)==='undefined'){ms=500;}
			if(typeof(display)==='undefined'){display='block';}
			speed=Math.round(ms/100);
			if(typeof(id)!=='undefined'&&typeof(which)!=='undefined'){
				o=getObj(id);
				switch(which){
					case 'out':
						v=CFWI.Effects.getOpacity(id);
						if(v.toString().length===0||v.toString().length>1){
							for(i=100;i>=0;i--){
								setTimeout("CFWI.Effects.setOpacity('"+id+"',"+i+");",(timer*speed));
								timer++;
							}
							setTimeout(function(){
								o.style.display='none';
							},ms);
						}
						break;
					case 'in':
						v=CFWI.Effects.getOpacity(id);
						if(v.toString().length>0&&v.toString().length<3){
							getObj(id).style.display=display;
							for(i=0;i<=100;i++){
								setTimeout("CFWI.Effects.setOpacity('"+id+"',"+i+");",(timer*speed));
								timer++;
							}
						}
						break;
					default:
						break;
				}
			}
		}
	}
	

// Attaches an Event Listener to a valid document event type
	function attachEventListener(target, eventType, functionRef, capture){if(typeof target.addEventListener!="undefined"){target.addEventListener(eventType,functionRef,capture);}else if(typeof target.attachEvent!="undefined"){target.attachEvent("on"+eventType,functionRef);window.attachEvent("onunload",function(e){removeListeners(target,eventType,functionRef,capture);});}else{return false;}return true;}
	function removeListeners(target, eventType, functionRef, capture){if(typeof target.removeEventListener!="undefined"){target.removeEventListener(eventType,functionRef,capture);}else if(typeof target.detachEvent!="undefined"){target.detachEvent("on"+eventType,functionRef);}else{return false;}return true;}

// Generic GetHTML Object Functions
	function getObj(oId){var d=document,i,el;el=d.getElementById?d.getElementById(oId):d.all?d.all[oId]?d[oId]:d[oId]:null;if(!el){if(d.forms.length>0){for(i=0; !el && i<d.forms.length; i++){el=d.forms[i][oId];}}}return el;}
	function get_HtmlObjWH(obj){
		if(typeof(obj)!=='undefined'&&obj!==null){
			if(obj.offsetWidth&&obj.offsetHeight){
				return [obj.offsetWidth,obj.offsetHeight];
			}else{
				return [0,0];
			}
		}
	}
	function CFWI_getXYofElement(obj){var x=y=0;if(obj.offsetParent){x=obj.offsetLeft;y=obj.offsetTop;while(obj=obj.offsetParent){x+=obj.offsetLeft;y+=obj.offsetTop;}}return [x,y];}

// Get Viewport Dimensions & Scroll Distances
	function CFWI_getWHofViewport(){var w=window.innerWidth?window.innerWidth-21:document.documentElement?document.documentElement.clientWidth:document.body.clientWidth?document.body.clientWidth:null;var h=window.innerHeight?window.innerHeight-21:document.documentElement?document.documentElement.clientHeight:document.body.clientHeight?document.body.clientHeight:null;if(w&&h){return [w,h];}}
	function CFWI_getXYofViewportScroll(){var x=window.innerWidth?window.pageXOffset:document.documentElement?document.documentElement.scrollLeft:document.body.scrollLeft?document.body.scrollLeft:null;var y=window.innerHeight?window.pageYOffset:document.documentElement?document.documentElement.scrollTop:document.body.scrollTop?document.body.scrollTop:null;return [x,y];}
	function CFWI_setInitialXYofViewportScroll(){scrollPosX=CFWI_getXYofViewportScroll()[0],scrollPosY=CFWI_getXYofViewportScroll()[1];}
	attachEventListener(window,'load',CFWI_setInitialXYofViewportScroll,false);


// Generic Append / Replace Css ClassName functions
	function CFWI_appendCssClass(obj,n){obj.className+=n;}
	function CFWI_restoreCssClass(obj,n){obj.className=obj.className.replace(n,'');}
// Generic Focus Event Handler for IE Forms 
	function _ieFocus(obj,which){var cssclass=' has-focus';if(document.all){if(which.toLowerCase()=='focus'){CFWI_appendCssClass(obj,cssclass);}else if(which.toLowerCase()=='blur'){CFWI_restoreCssClass(obj,cssclass);}}else{return true;}}
	
// Generic Append to URL function
	// usage: 
	// srcId = Name of Cookie or Textbox that contains the value to be appended / replaced in the url
	// targetName = Name assigned to URL to be updated via the name attribute (e.g. <a name="mylink" href="">some text</a>
	// paramName = Name of Variable to find / append (e.g. find "key" in savedListing.aspx?format=print&key=guid&otherparams=something)
	function _appendToUrl(srcId,targetName,paramName){try{var strToAppend='',strToReplace='',newStr='',iStart,iStop,arr=document.getElementsByName(targetName),url='',val=getCookie(srcId);if(val==null||val=='null'){val=getObj(srcId);if(val&&val.type=='text'){val=val.value;}else{val='';}}if(arr&&arr.length>0){for(var i=0;i<arr.length;i++){url=arr[i].href;if(url.indexOf(paramName)==-1){strToAppend="?"+paramName+"="+val;if(url.indexOf("?")>-1){url=url.replace("?",(strToAppend+"&"));if(url.lastIndexOf("&")==url.length-1){url=url.substring(0,url.length-1);}}else{url=url+strToAppend;}}else if(url.indexOf(paramName)>-1){startindex=url.indexOf(paramName);stopindex=url.indexOf("&",startindex);newStr=paramName+"="+val;if(stopindex==-1){stopindex=url.length;}strToReplace=url.substring(startindex,stopindex);url=url.replace(strToReplace,newStr);}arr[i].href=url;}}}catch(err){}}

// Uses location.replace() method to set the href of the targeted iframe to prevent iframe url's from being added to history object.
	function CFWI_loadUrl(sender){try{if(sender.target){var theIframe=parent.frames[sender.target.toString()];if(theIframe){theIframe.location.replace(sender.href);}}else{if(sender.href){location.replace(sender.href);}}}catch(err){}}

// Generic Toggle Display Functions
	function CFWI_toggleDisplay(id,which){var obj=getObj(id);if(typeof obj=='undefined'){return}else{obj.style.display=which;return;};}

// Used to set the iframe width/height within the BrokerIDX UI Popup Window
	CFWI.ResizeDialog={
		IsInitialized:false,
		Title:'',
		Width:'',
		Height:'',
		MinWidth:250,
		MinHeight:100,
		oParent:'',
		oParentFrame:'',
		oParentTitle:'',
		oContent:'',
		Init:function(){
			CFWI.ResizeDialog.oParent=parent.getObj('cfwi_dialog');
			CFWI.ResizeDialog.oParentFrame=parent.document.getElementById('CFWI_Dialog_Iframe');
			CFWI.ResizeDialog.oContent=getObj('iframe-page-content');
			CFWI.ResizeDialog.oParentTitle=parent.getObj('CFWI_Dialog_Title');
			if(CFWI.ResizeDialog.Width.length===0){
				CFWI.ResizeDialog.Width=CFWI.ResizeDialog.GetWH()[0]+30;
			}
			if(CFWI.ResizeDialog.Height.length===0){
				CFWI.ResizeDialog.Height=CFWI.ResizeDialog.GetWH()[1]+30;
			}
			if(CFWI.ResizeDialog.Title.length!==0){
				CFWI.ResizeDialog.oParentTitle.innerHTML=CFWI.ResizeDialog.Title;
			}
		},
		GetWH:function(){
			var w,h,arr=get_HtmlObjWH(CFWI.ResizeDialog.oContent);
			if(arr[0]<CFWI.ResizeDialog.MinWidth){
				w=CFWI.ResizeDialog.MinWidth;
			}else{
				w=arr[0];
			}
			if(arr[1]<CFWI.ResizeDialog.MinHeight){
				h=CFWI.ResizeDialog.MinHeight;
			}else{
				h=arr[1];
			}
			return [w,h];
		},
		SetWH:function(arr){
			var aW=0,aH=0;
			if(typeof(arr)!=='undefined'){
				if(arr.length>0){
					aW=arr[0];
					aH=arr[1];
				}else{
					aW=aH=arr;
				}
			}
			CFWI.ResizeDialog.Width=CFWI.ResizeDialog.GetWH()[0]+30+aW;
			CFWI.ResizeDialog.Height=CFWI.ResizeDialog.GetWH()[1]+30+aH;
		},
		Resize:function(){
			if(!(CFWI.ResizeDialog.IsInitialized)){CFWI.ResizeDialog.Init();}
			CFWI.ResizeDialog.oParent.style.width=CFWI.ResizeDialog.Width+'px';
			CFWI.ResizeDialog.oParentFrame.style.height=CFWI.ResizeDialog.Height-20+'px';
			if(typeof(parent.oDialog)!=='undefined'){
				parent.oDialog.style.width=CFWI.ResizeDialog.Width+'px';
				parent.oDialog.style.height=CFWI.ResizeDialog.Height+'px';
				parent.CFWI_snapDialogToElement();
			}
		},
		UpdateTitle:function(s){
			if(CFWI.IsDefined(s)){
				if(s.length>0){
					CFWI.ResizeDialog.oParentTitle.innerHTML=s;
					return true;
				}else{
					CFWI.ResizeDialog.oParentTitle.innerHTML=CFWI.ResizeDialog.Title;
					return true;
				}
			}
		},
		Exec:function(){
			attachEventListener(window,'load',CFWI.ResizeDialog.Resize,false);
		}
	};

// Close the Dialog Window
	function CFWI_Dialog_Close(){
		if(typeof(parent.Dialog)!=='undefined'){
			parent.Dialog.Close();
		}
	}

// Determine how to handle, then process the parent window.  Used via Dialog Content iFrame.
	// Refresh, Change, Post Parent Window Functions
	function CFWI_Dialog_ReloadParent(){parent.document.location.replace(parent.document.location.href);}
	function CFWI_Dialog_ChangeParent(url){parent.document.location.replace(url);}
	function CFWI_Dialog_PostParent(){parent.document.forms[0].submit();}
	// Prep, then Handle / Process Parent Window
	function CFWI_PrepParentWindow(action,url){if(typeof action=='undefined'){return false;}else if(typeof url=='undefined'){return false;}else{try{var v=action+'|'+url;writeCookie("HandleParentWindow",v);return true;}catch(err){}}}
	function CFWI_HandleParentWindow(){if(getCookie("HandleParentWindow")&&getCookie("HandleParentWindow").length>0){var action=getCookie("HandleParentWindow").split("|")[0];var url=''+getCookie("HandleParentWindow").split("|")[1];writeCookie("HandleParentWindow",'');CFWI_ProcessParentWindow(action,url);}}
	function CFWI_ProcessParentWindow(action,url){if(typeof action=='undefined'){return false;}else{try{window.setTimeout('CFWI_Dialog_Close()',250);switch(action.toLowerCase()){case "changeparent":CFWI_Dialog_ChangeParent(url);break;case "reloadparent":CFWI_Dialog_ReloadParent();break;case "postparent":CFWI_Dialog_PostParent();break;case "none":break;default:break;}}catch(err){}}}

// ### Show Tab Based On QueryString Tab Id ### //
	function showTab(s){
		if(CFWI.IsDefined(s)){
			switch(s){
				case 'builder':
					tsEditItem.findTabById('tabBuilder').select();
					break;
				case 'builders':
					tsEditItem.findTabById('tabBuilders').select();
					break;
				case 'floorplan':
					tsEditItem.findTabById('tabFloorplan').select();
					break;
				case 'floorplans':
					tsEditItem.findTabById('tabFloorplans').select();
					break;
				case 'property':
					tsEditItem.findTabById('tabProperty').select();
					break;
				case 'properties':
					tsEditItem.findTabById('tabProperties').select();
					break;
				case 'neighborhood':
					tsEditItem.findTabById('tabNeighborhood').select();
					break;
				case 'neighborhoods':
					tsEditItem.findTabById('tabNeighborhoods').select();
					break;
				case 'description':
					tsEditItem.findTabById('tabDescription').select();
					break;
				case 'directions':
					tsEditItem.findTabById('tabDirections').select();
					break;
				case 'map':
					tsEditItem.findTabById('tabMap').select();
					break;
				default:
					return false;
					break;
			}
		}
	}
	
// ### Last Selected Tab Code ### //

    // Control Tabstrip Tab Select event on individual tabs to use location.replace() method to prevent tab selections from being
    // remembered in history.  This function works both separately and in conjuction with the tabstrip-wide CFWI_onTabSelect functions.
    function CFWI_TabstripTabSelect(sender){var iframe=parent.frames[sender.Target];if(!iframe){iframe=frames[sender.Target];}if(iframe){try{iframe.location.replace(sender.NavigateUrl);return false;}catch(err){}}}
    
    // Function to select the default tab index for the sidebar tabstrip control
	function CFWI_SelectDefault(){
		if(typeof tsSidebar!=='undefined'){
			var isVisible = tsSidebar.getSelectedTab().get_visible();
			if(isVisible!==true||isVisible!=='true'||isVisible!==1||isVisible!=='1'){
				CFWI_SelectedTab('tsSidebar',0);
			}
		}
	}
	
	// TabStrip-wide event handler that Selects, then stores the last selected TabStrip Tab
    function CFWI_onTabSelect(sender, eventArgs){
	    var oTabStripId=sender.get_id();
	    var oSelectedTabId=eventArgs.get_tab().get_id();
	    var selectedTabsList='';
	    var strFn=oTabStripId+'.findTabById(\''+oSelectedTabId+'\')';
	    var found=false;
	    
    	
	    if(getCookie("SelectedTabs")){
		    selectedTabsList=getCookie("SelectedTabs");
		    var arr=selectedTabsList.split("|");
		    for(var i=0;i<arr.length;i++){
			    if(arr[i].indexOf(oTabStripId)>-1){
				    selectedTabsList=selectedTabsList.replace(arr[i],strFn);
				    found=true;
				    break;
			    }
		    }
		    if(!found){
			    if(selectedTabsList.length>0){
				    selectedTabsList+='|'+strFn;
			    }else{
				    selectedTabsList=strFn;
			    }
		    }
	    }else{
		    selectedTabsList=strFn;
	    }
	    writeCookie("SelectedTabs",selectedTabsList);
    	if(eval(strFn+'.isSelected()')){
    		return false;
    	}
    }

    function CFWI_setLastSelectedTab(){
	    if(getCookie("SelectedTabs")){
		    var arr=getCookie("SelectedTabs").split("|"),updateTabsList=getCookie("SelectedTabs"),fn='',isVisible='',tn='';
		    for(var i=0;i<arr.length;i++){
			    try {
					tn=eval(arr[i]+'.get_id()');
					isVisible=arr[i]+'.get_visible()';
					fn=arr[i]+'.select()';
					if(eval(isVisible)===true||eval(isVisible)==='true'||eval(isVisible)===1||eval(isVisible==='1')){
						eval(fn);
					}else{
						throw("Tab " + tn + " Not Found");
					}					
			    } 
			    catch(err){
					//The tab doesn't exist on this page...so we clear this path from the cookie.
				    if(updateTabsList.length>0){
					    if(updateTabsList.indexOf('|'+arr[i])>-1){
						    updateTabsList=updateTabsList.replace('|'+arr[i],'');
					    }else if(updateTabsList.indexOf(arr[i]+'|')>-1){
						    updateTabsList=updateTabsList.replace(arr[i]+'|','');
					    }else{
						    updateTabsList=updateTabsList.replace(arr[i],'');
					    }
				    }
				    //If the Tab Strip in question is the Sidebar, and the previously selected tab is no longer visible,
				    //then we default its view to the first tab (index 0);
				    CFWI_SelectDefault();
			    }
		    }
		    writeCookie("SelectedTabs",updateTabsList);
	    }
    }

    // Usage: CFWI_setSelectedTab('<%=TabStrip.ClientID %>',index);
    // Index value of -1 exits the function before it runs
    function CFWI_setSelectedTab(tabStripId, index){
	    try {
		    if(index>-1){
			    var updateTabsList='',itemToReplace='';
			    var strFn=tabStripId+'.get_tabs().getTab('+index+')';
			    if(getCookie("SelectedTabs")){
				    var arr=getCookie("SelectedTabs").split("|"),updateTabsList=getCookie("SelectedTabs");
				    for(var i=0;i<arr.length;i++){
					    if(arr[i].indexOf(tabStripId)>-1){
						    itemToReplace=arr[i];
						    break;
					    }
				    }
				    if(itemToReplace.length>0 && updateTabsList.length>0){
					    updateTabsList=updateTabsList.replace(itemToReplace,strFn);
				    }else{
					    if(updateTabsList.length>0){
						    updateTabsList+='|'+strFn;
					    }else{
						    updateTabsList=strFn;
					    }
				    }
			    }else{
				    updateTabsList=strFn;
			    }
			    writeCookie("SelectedTabs",updateTabsList);
		    }
		    return;
	    }
	    catch(err){
			return;
	    }
    }

    function CFWI_SelectedTab(tabStripId,index){
	    var strFn=tabStripId+'.get_tabs().getTab('+index+').select()';
	    eval(strFn);
    }

//To validate the input types

    function validate_InputType(e,what){
			var key,keyChar,regexp;
			if(window.event){key=e.keyCode;}else if(e.which){key=e.which;}
			keyChar=String.fromCharCode(key);
			switch(what){
				case 'alpha':
					regexp=/[a-zA-Z\-\']|\0|[\b]|\t/;
					if(!regexp.test(keyChar)){
						if(e.preventDefault){e.preventDefault();}
						e.returnValue = false;
						return false;
					}
					break;
				case 'alphanumeric':
					regexp=/[a-zA-Z\-\']|\d|\0|[\b]|\t/;
					if(!regexp.test(keyChar)){
						if(e.preventDefault){e.preventDefault();}
						e.returnValue = false;
						return false;
					}
					break;
				case 'integer':
					regexp=/\d|\0|[\b]|\t/;
					if(!regexp.test(keyChar)){
						if(e.preventDefault){e.preventDefault();}
						e.returnValue = false;
						return false;
					}
					break;
				case 'decimal':
					regexp=/\d|\.|\0|[\b]|\t/;
					if(!regexp.test(keyChar)){
						if(e.preventDefault){e.preventDefault();}
						e.returnValue = false;
						return false;
					}
					break;
				case 'email':
					regexp=/\S|\t/;
					if(!regexp.test(keyChar)){
						if(e.preventDefault){e.preventDefault();}
						e.returnValue = false;
						return false;
					}
				default:
					break;
			}
		}


//Two List Boxes Control stuff
	function twoListBoxes_focusOnAvailable(id){var obj=getObj(id);for(var i=0;i<obj.options.length;i++){if(obj.options[i].selected==true){obj.options[i].selected=false;}}}
	function twoListBoxes_focusOnSelected(id){var obj=getObj(id);if(obj){for(var i=0;i<obj.options.length; i++){if(obj.options[i].selected==true){obj.options[i].selected=false;}}}}

/* ### Cookies 
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
*/
function setCookie(name, value, expires, path, domain, secure){
	var arrKeys=value.split("|"),c=arrKeys.length,newValue=value,tempValue='';
	var msg= 'A maximum of 50 listings may be selected for comparison at one tithis.\n';
		msg+='You have selected '+ c +' listings for comparison.\n';
		if((c-50)==1){
			msg+='The last listing will be de-selected automatically from your list.';
		} else {
			msg+='The last '+ (c-50) +' listings will be de-selected automatically from your list.';
		}
	if(arrKeys.length>50){
		for(var i=0;i<50;i++){
			if(tempValue==''){
				tempValue=arrKeys[i];
			} else {
				tempValue+='|'+arrKeys[i];
			}
		}
		newValue=tempValue;
		alert(msg);
	}
	writeCookie(name, newValue, expires, path, domain, secure);
} 

function writeCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ("; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/*
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
*/
function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1){
        begin = dc.indexOf(prefix);
        if (begin == -1) 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));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ("; path=/") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
