//GENERIC POPUPWINDOW CLASS
var GenericPopupWindow = Class.create();
GenericPopupWindow.default_width = 600;
GenericPopupWindow.default_height = 500;
GenericPopupWindow.scrolling = false;
GenericPopupWindow.prototype = {
	initialize: function( el ){
		this.el = el;
		this.winCount = 0;
		//super fancy regular expression width and height for popup class. -James
		this.classes = this.el.readAttribute('class');
		if(this.classes.indexOf('pop_w') > 0){
			var myRe = /(pop_w_)[0-9]*/;
			var myRe2 = /(pop_h_)[0-9]*/;
			var tempRe = myRe.exec(this.classes);
			var tempRe2 = myRe2.exec(this.classes);
			if(tempRe != null && tempRe2 != null){
				this.width = tempRe[0].replace(tempRe[1],'');
				this.height = tempRe2[0].replace(tempRe2[1],'');
			} else {
				this.width = null;
				this.height = null;
			}
		}
		if(this.width == null){
			this.width = ( this.el.hasAttribute('win_width') ? this.el.attributes['win_width'].value : GenericPopupWindow.default_width );
		}
		if(this.height == null){
			this.height = ( this.el.hasAttribute('win_height') ? this.el.attributes['win_height'].value : GenericPopupWindow.default_height );
		}
		this.scrolling = ( this.el.hasAttribute('scrolling') ? this.el.attributes['scrolling'].value : GenericPopupWindow.scrolling );
		Event.observe( this.el, 'click', this.clicked.bindAsEventListener( this ) );
	},
	clicked: function( event ){
		if(this.scrolling == '1'){
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1,scrollbars=1");
		} else {
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1");
		}
		try{
			Event.stop( event );
		}catch( e ){
		}
	}
}
var tab_object = Class.create({
	initialize: function(container) {		
		this.container = $(container);
		this.triggers = this.container.select('.tab_triggers li');
		this.triggersA = this.container.select('.tab_triggers li a');
		this.content = this.container.select('.tab_item');
		this.onLoad();
		this.startup();
	},
	onLoad: function() {
		var i = 0;
		this.triggers.each(function(elem){
			elem.writeAttribute('tab',i);
			elem.observe('click',this.handleToggle.bind(this));
			i++;
		}.bind(this));
		this.triggersA.each(function(elem){
			elem.observe('click',this.handleToggle.bind(this));
		}.bind(this));
		this.container.select('h2.removeHeading').each(function(elem){
			elem.hide();
		});
	},
	startup: function() {
		this.closeTabs();
		this.triggers[0].addClassName('active_tab');
		this.content[0].show();
	},
	closeTabs: function(){
		this.content.each(function(elem){
			elem.hide();
		});
		this.resetTriggers();
	},
	openTab: function(num) {
		this.closeTabs();
		this.triggers[num].addClassName('active_tab');
		this.content[num].show();		
	},
	jumpToTab: function(id,num) {
		this.closeTabs();
		this.triggers[num].addClassName('active_tab');
		this.content[num].show();
		Effect.ScrollTo(id);
	},
	resetTriggers: function(){
		this.triggers.each(function(elem){
			elem.removeClassName('active_tab');
		});
	},
	handleToggle: function(e){
		var tab = Event.element(e);
		if(!tab.hasClassName('dontstop')){
			Event.stop(e);
		}
		if(tab.readAttribute('tab') == undefined) {
			tab = tab.up();
		}
		this.closeTabs();
		tab.addClassName('active_tab');
		var tmp = parseInt(tab.readAttribute('tab'));
		try {
			this.content[tmp].show();
		} catch(e) {
			this.openTab(0);
		};
	}
});
//Fancy Login
var fancyLogin = Class.create({
	initialize: function(triggerID,formID) {
		this.trigger = $(triggerID);
		this.formID = $(formID);
		this.initEventHandlers();
	},
	initEventHandlers: function() {
		if(this.trigger != undefined){
			this.trigger.select('a')[0].observe('click',this.handleToggle.bind(this));
		}
		if($('fancyCloseBtn') != undefined){		
			$('fancyCloseBtn').observe('click',this.handleToggle.bind(this));
		}
	},
	handleToggle: function(e) {
		Event.stop(e);
		Effect.toggle(this.formID, 'appear',{duration:.4});
	}	
});
function showWhatForm(){
	var element = $('natureOfContact');
	var formID = $('propDetailsForm1');
	var containers = $$('.form_section');
	containers.each(function(elem){elem.hide();});
	if(element.selectedIndex == 1){
		formID.action = requestInfo;
	}else if(element.selectedIndex == 2){
		formID.action = scheduleLocation;
	}else if(element.selectedIndex == 3){
		formID.action = similarAction;
	}else{
		formID.action = requestInfo;
	}
	try{
		containers[(element.selectedIndex - 1)].show();
	} catch(e){}
}
function handleGATrackForm(e) {
	var myFormElement = Event.element(e);
	var myFormAction = '/virtual/goal' + myFormElement.action.replace('http://' + window.location.host,'');
	try{
		pageTracker._trackPageview(myFormAction);					
	}catch(e){}	
}
if(parseFloat(Prototype.Version) >= 1.6) {
	//if we have prototype 1.6 than we use this event because it's faster!
	document.observe("dom:loaded", function() {
		//popup window script
		$$( "a.PopupWin" ).each(function(el){new GenericPopupWindow(el);});
		$$('form.goalTrack').each(function(formEl){
			formEl.observe('submit',handleGATrackForm);
		});
	});
} else {
	throw('Prototype 1.6 or greater is not loaded! Some features may not function with a lesser version.');
}
