//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;
		//super fancy regular expression width and height for popup class. -James
		this.classes = this.el.readAttribute('class');
		var myRe = /(pop_w_)[0-9]*/; //looks for a class name like pop_w_300 to set width to 300
		var myRe2 = /(pop_h_)[0-9]*/; //looks for a class name like pop_h_300 to set width to 300
		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;
		}
		this.winCount = 0;
		this.widthHeight = (this.el.hasAttribute('rel') ? this.el.attributes['rel'].value : String(GenericPopupWindow.default_width) + "x" + String(GenericPopupWindow.default_height)).split('x');
		if(this.width == null){
			this.width = ( this.el.hasAttribute('rel') ? this.widthHeight[0] : this.el.readAttribute('win_width') );
		}
		if(this.height == null){
			this.height = ( this.el.hasAttribute('rel') ? this.widthHeight[1] : this.el.readAttribute('win_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 ){}
	}
}
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 calcFunction(e){
	var trig = $('calcTrigger');
	var con = $('calc_container');
	if(con.visible()) {
		trig.addClassName('active');
		Effect.BlindUp(con,{duration:0.4});
	} else {
		trig.removeClassName('active');
		Effect.BlindDown(con,{duration:0.4});
	}			
}
function expandOpenHouse(trig,ele){
	var myDiv = $(ele);
	if(myDiv.visible()){
		Effect.BlindUp(myDiv,{duration:0.4});
		trig.removeClassName('activeOpenHouse');
	} else {
		Effect.BlindDown(myDiv,{duration:0.4});
		trig.addClassName('activeOpenHouse');
	}
}
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) {
	document.observe("dom:loaded", function() {
		$$( "a.PopupWin" ).each(function(el){new GenericPopupWindow(el);});
		if($('calcTrigger')){
			$('calcTrigger').observe('click',calcFunction);
		}
		$$('form.goalTrack').each(function(formEl){
			formEl.observe('submit',handleGATrackForm);
		});
	});
} else {
	Event.observe(window, 'load', function() {
		throw('Prototype 1.6 or greater is not loaded! Some features may not function with a lesser version.');
	});
}
