function ParseQS()
{
	this.params = new Object()
	this.get = Querystring_get
    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	var qs = location.search.substring( 1, location.search.length )
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
    // split out each name = value pair
	for ( var i = 0; i < args.length; i++ )
	{
		var value;
		var pair = args[ i ].split('=')
		var name = unescape( pair[ 0 ] )

		if ( pair.length == 2 )
			value = unescape( pair[ 1 ] )
		else
			value = name
		
		this.params[ name ] = value
	}
}

ParseQS();

function MoveTo_SaveQuery( PrevPage, ToPage, Param ) 
{
    MoveTo_SaveQuery( PrevPage, ToPage, Param, false )
}

function MoveTo_SaveQuery( PrevPage, ToPage, Param, ClearQS )
{
	var target = document.location.href;
	if ( target.indexOf('/m/') > 0 )
	{
	    var str1 = target.substring( 0, target.indexOf('/m/') ) + '/'
	    var str2 = target.substring( target.indexOf('?') > 0 ? target.indexOf('?') : target.length ) 
	    target = str1 + PrevPage + ( ( str2.length > 0 ) ? str2 : '' )
	}
    target = target.replace( PrevPage, ToPage )
    target = target.replace( PrevPage.toLowerCase(), ToPage.toLowerCase() )
    if ( ClearQS == true )
        target = target.substring( 0, target.indexOf('?') > 0 ? target.indexOf('?') : target.length )
    if ( Param != '' )
    {
		sParam = Param.split( '=' )
		if ( sParam.length > 0 && sParam[ 0 ] != '' )
		    if ( target.indexOf( sParam[ 0 ] + '=' ) > 0 )
		        target = target.replace( sParam[ 0 ] + '=' + this.params[ sParam[ 0 ] ], sParam[ 0 ] + '=' + sParam[ 1 ] )
		    else if ( target.indexOf( '?' ) > 0 )
		        target = target + '&' + Param;
		    else
		        target = target + '?' + Param;
    }
    document.location.href = target;
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if ( default_ == null ) default_ = null;
	
	var value = this.params[ key ]
	if ( value == null ) value = default_;
	
	return value
}

function OpenAd( path )
{
	var wOpenAd = window.open( path , 'AdView', 'status=no, scrollbars=yes, height=530, width=900, top=0, left=0, titlebar=no, resizable=no', false);
	if ( wOpenAd )
	    wOpenAd.focus();
	return false;
}

function OpenLargImg( path )
{
	var wLargImg = window.open( path , 'PictureWindow', 'status=no, scrollbars=no, height=530, width=522, top=0, left=0, titlebar=no, resizable=no', false);
	if ( wLargImg )
	    wLargImg.focus();
	return false;
}

function GetCurrentTopY()
{
    var y;
    if ( self.pageYOffset ) // all except Explorer
	    y = self.pageYOffset;
    else if ( document.documentElement && document.documentElement.scrollTop )
	    y = document.documentElement.scrollTop; // Explorer 6 Strict
    else if ( document.body ) // all other Explorers
	    y = document.body.scrollTop;
	return y;
}

function GetCurrentLeftX()
{
    var x
    if ( self.pageXOffset ) // all except Explorer
	    x = self.pageXOffset
    else if ( document.documentElement && document.documentElement.scrollLeft )
	    x = document.documentElement.scrollLeft // Explorer 6 Strict
    else if ( document.body ) // all other Explorers
	    x = document.body.scrollLeft
	return x
}

function ShowGoogleMap( path, title )
{
    var y = GetCurrentTopY()
    $Get( 'MapView' ).src = path
    var MapForm = $Get( 'divMapForm')
    MapForm.style.display = ''
    if ( path.indexOf('small') > 0 )
        MapForm.style.top = 10 + y + 'px'
    else
        MapForm.style.top = 50 + y + 'px'
        
    var add = $Get( 'MapForm1_cAddressTitle' )
    if ( add == null )
        add = $Get( 'ctl00_MapForm1_cAddressTitle' ).innerText = title
    if ( add != null )
        add.innerText = title
	return false
}

function OpenVideo( path )
{
    var y = GetCurrentTopY()
    var x = GetCurrentLeftX()
    $Get( 'VideoView' ).src = path
    var VideoForm = $Get( 'divVideoForm')
    VideoForm.style.display = ''
    VideoForm.style.top = 150 + y + 'px'
    VideoForm.style.left = 400 + x + 'px'
	return false
	/*window.open( path , 'VideoWindow', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, status=no, scrollbars=no, height=265, width=240, top=220, left=420, titlebar=no, resizable=no', false);
	return false;*/
}

function OpenEmailToFriend( path )
{
	var wEmailToFriend = window.open( path , 'EmailToFriend', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, status=no, scrollbars=no, height=324, width=410, top=200, left=350, titlebar=no, resizable=no', false);
	if ( wEmailToFriend )
	    wEmailToFriend.focus();
	return false;
}

function OpenBackOfficeReport( path )
{
	var wBackOfficeReport = window.open( path , 'BackOfficeReport', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, status=no, scrollbars=no, height=260, width=405, top=200, left=350, titlebar=no, resizable=no', false);
	if ( wBackOfficeReport )
	    wBackOfficeReport.focus();
	return false;
}

function OpenAdAsPopUp( path )
{
	var wAdAsPopUp = window.open( path , 'OpenAdAsPopUp', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, status=yes, scrollbars=yes, height=530, width=900, top=100, left=150, titlebar=yes, resizable=yes', false);
	if ( wAdAsPopUp )
	    wAdAsPopUp.focus();
	return false;
}

function AddToFavorite( SiteUrl, SiteName ) 
{
    if ( document.all )
        window.external.AddFavorite( SiteUrl, SiteName );
    else if ( window.sidebar )
        window.sidebar.addPanel( SiteName, SiteUrl, "" )
} 
function SetAsHomePage( SiteUrl )    { if ( navigator.appName.indexOf('Microsoft') >= 0 ) $Get("hp").setHomepage( SiteUrl ) }
function PostAnAd( SiteUrl )         { document.location.href = SiteUrl + 'SiteNavigator.aspx?Ac=New' }
function OpenTermsOfUse( SiteUrl )   { window.open( SiteUrl + 'Serv/TermsOfUse.aspx',     'TermsOfUse',       'status=no, scrollbars=no, height=530, width=500, top=0, left=0, titlebar=no, resizable=no', false); }
function OpenFAQ( SiteUrl )          { window.open( SiteUrl + 'Serv/FAQ.aspx',            'FAQ',              'status=no, scrollbars=no, height=530, width=780, top=0, left=0, titlebar=no, resizable=no', false); }
function OpenAboutUs( SiteUrl )      { window.open( SiteUrl + 'Serv/AboutUs.aspx',        'AboutUs',          'status=no, scrollbars=no, height=530, width=500, top=0, left=0, titlebar=no, resizable=no', false); }
function OpenContactUs( SiteUrl )    { window.open( SiteUrl + 'Serv/ContactUs.aspx',      'ContactUs',        'status=no, scrollbars=no, height=328, width=522, top=0, left=0, titlebar=no, resizable=no', false); }
function TellYourFriend( SiteUrl )   { window.open( SiteUrl + 'Serv/TellYourFriend.aspx', 'TellYourFriend',   'status=no, scrollbars=no, height=324, width=410, top=0, left=0, titlebar=no, resizable=no', false); }
function resize( width, height )     { try { window.resizeTo( width, height );} catch(e){} }

