
function ragamuffin( boj ) // use the ragamuffin!
{
	return boj.replace(/[a-zA-Z]/g, function(c){
	  return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
	});
}

function CreateAddEmAt( Site , Name )
{
	return ragamuffin( Name ) + '@' + ragamuffin( Site );
}

function UpdateThePropCount()
{
	var myAjax = new Ajax.Request( 'ajax/update_propcount.php',
	{ method: 'post', onFailure: null, onSuccess: function ( ro ) { $('thePropCount').innerHTML = ro.responseText; } } );
}

function adv_CheckAll( val )
{
	var Set=document.getElementsByName('sType[]');
	
	for ( i=0; i<Set.length; i++ )
	{
		Set[i].checked=val;
	}
	
	adv_CalulateChecks();
}

function adv_CalulateChecks()
{
	var all=true;
	
	var Set=document.getElementsByName('sType[]');
	for ( i=0; i<Set.length; i++ )
	{
		all = all && Set[i].checked;
	}
	
	$('C*').checked=all;
}

function OpenMagicWindow( id , calls , UseAutoScroll )
{
	var b=$('blackout_pane');
	var c=$('container_pane');
	var o=$('overlay_pane');

	/*
		b.style.width='auto';
		b.style.height='auto';
		c.style.width='auto';
		c.style.height='auto';
	*/
	
	o.style.width='auto';
	o.style.height='auto';
	o.style.position='absolute';
	o.innerHTML='';
	o.style.display='none';
	
	setTimeout( function() {
		c.style.marginLeft='-99999px';
		c.style.position='absolute';
		
		o.innerHTML = id;
		o.style.display='block';
		
		setTimeout( function() {
			
			id.evalScripts();
			
			setTimeout( function() {
				
				var Size=document.viewport.getDimensions();
				
				b.style.zIndex=1000;
				b.style.width=Size.width+'px';
				b.style.height=Size.height+'px';
				b.style.position='fixed';
				b.style.left='0px';
				b.style.top='0px';
				b.style.opacity=0.01;
				b.style.filter="alpha(opacity='0')";
				b.style.background='#000000';
				b.style.display='block';
				
				c.style.zIndex=1005;
				c.style.width=Size.width+'px';
				c.style.height=Size.height+'px';
				c.style.position=UseAutoScroll?'fixed':'absolute';
				c.style.left='0px';
				c.style.top='0px';
				c.style.display='block';
				
				var ow=o.offsetHeight;
				var oh=o.offsetWidth;
				
				o.style.zIndex=1015;
				o.style.border='0px none black';
				o.style.left='50%';
				o.style.top='50%';
				o.style.marginTop=(-ow/2)+'px';
				o.style.marginLeft=(-oh/2)+'px';
				o.style.height=ow+'px';
				o.style.width=oh+'px';
				o.style.backgroundColor='transparent';
				o.style.display='block';
				
				c.style.marginLeft='0px';
				
				if (browser == 'Internet Explorer') {
					lightbox.prototype.getScroll();
					lightbox.prototype.prepareIE('100%', 'hidden');
					lightbox.prototype.setScroll(0,0);
					lightbox.prototype.hideSelects('hidden');
					b.style.position='absolute';
					c.style.position='absolute';
				}
				
				Effect.Appear( b , { duration:0.1, to:0.4 } );
				Effect.Appear( o , { duration:0.1, afterFinish: function() { 
					
					if (browser == 'Internet Explorer') {
						selects = o.select('select');
						for(i = 0; i < selects.length; i++) {
							selects[i].style.visibility = 'visible';
						}
					
					}
					
				} } );
				
				if ( calls )
					setTimeout( function() { calls(o); } , 100 );
				
			} , 50 );
		} , 50 );
	} , 50 );
}

function CloseMagicWindow()
{
	var b=$('blackout_pane');
	var c=$('container_pane');
	var o=$('overlay_pane');
	Effect.Fade( b , { duration:0.2, from:0.4, to:0.0 } );
	Effect.Fade( o , { duration:0.2, afterFinish:function() { 

		b.style.display='none'; 
		c.style.display='none'; 
		o.style.display='none'; 

		if (browser == "Internet Explorer"){
			lightbox.prototype.setScroll(0,lightbox.prototype.yPos);
			lightbox.prototype.prepareIE("auto", "auto");
			lightbox.prototype.hideSelects("visible");
		}
	
	} } );
}

Event.observe( window , 'load' , function() {
	
	Event.observe( window , 'resize' , function() 
	{
		var Size=document.viewport.getDimensions();
		var b=$('blackout_pane');
		var c=$('container_pane');
		if ( b && c )
		{
			b.style.width=Size.width+'px';
			b.style.height=Size.height+'px';
			c.style.width=Size.width+'px';
			c.style.height=Size.height+'px';
		}
	} );
	
} );

function show_menu(a){
	if($('submenu'+a)){
		$('submenu'+a).clonePosition($('button'+a),{ offsetTop: 23, setHeight: false, setWidth: false });
		$('submenu'+a).style.display = 'block';	
	}
}
function hide_menu(a){
	if($('submenu'+a)){
		$('submenu'+a).style.display = 'none';	
	}
}

function OpenLoginWindow()
{
	var LB=new lightbox( $('fishy_link_king') );
	LB.activate();
}

function OpenRegisterWindow()
{
	var LB=new lightbox( $('fishy_link_king2') );
	LB.activate();
}

function NumberField( field )
{
	var r = field.value;
	
	r=r.replace( /[^0-9]+/g , '' );
	
	do
	{
		l=r.length;
		r=r.replace( /([0-9])([0-9]{3})(,|$)/ , '$1,$2$3' );
	}
	while ( l != r.length );
	
	field.value=r;
}

function show_details(originalRequest){
	OpenMagicWindow(originalRequest.responseText, undefined, true );
}

function get_details(a){
	var pdata = "MLS="+a;
	// alert(pdata);
	var myAjax = new Ajax.Request( 'showdetails.php',
	{ method: 'post', parameters: pdata, onFailure: null, onSuccess: show_details } );
}

function getImageLocation( func , f , w , h )
{
	var myAjax = new Ajax.Request( 'ajax/getThumb.php',
	{ method: 'get', parameters: { f:f, w:w, h:h } , onFailure: null, onSuccess: function( ro ) { func( ro.responseText ); } } );
}
