var minHeight = 400;
var contentsId = 'mainContents';
//var parentPage = "http://www.joneslanglasalle.co.uk/UnitedKingdom/EN-GB/Pages/AuctionPropertiesTest.aspx";
//var parentPage = "http://www.joneslanglasalle.co.uk/UnitedKingdom/EN-GB/Pages/Auction-Properties.aspx";

var docurl=parent.location.href;
docurl =docurl.split('#',1)
var parentPage=docurl;

reSizeMe();

function reSizeMe()
{	

    var ref = document.referrer;
        
    if(ref == null)
        return;
    else if(ref == "")
	    ref = parentPage;
    var h = 0;

    var contents = document.getElementById(contentsId);
    if(contents && contents.style)
    {
        
	
	var s = contents.style.height;
        if (s != "" && s.indexOf('px') > 0)
        {

            s = s.substring(0, s.indexOf('px'));
            h = parseInt(s) + 120;
        }   
        else
        {
            h = getFrameHeight()
        }
    }
    else
    {
        h = getFrameHeight() + 120;

	}   
    
    if(h < minHeight)
	    h = minHeight; 

    if(checkDomain(self.location.href, ref))
    { 
	   top.location = parentPage + '#h'+ h +'-' + parseInt(Math.random()*1000);
    }
    else if(top != self && self.location.href != ref) 
    { 
        top.location = ref + '#h'+ h +'-' + parseInt(Math.random()*1000);
    }
}

function getFrameHeight()
{
    var height = getScrollSize()[1];
    
    //if(height < minHeight)
	//height = getClientSize()[1];

    return height;
}

function getClientSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function getScrollSize() 
{
    var scrOfX = 0, scrOfY = 0;
    if( document.documentElement && ( document.documentElement.scrollWidth || document.documentElement.scrollHeight ) ) {
        //IE6 + FF standards compliant mode
        scrOfY = document.documentElement.scrollHeight;
        scrOfX = document.documentElement.scrollWidth;
	//////alert('document.documentElement: ' + scrOfY + ' : ' + document.documentElement.clientHeight);
    }
    else if( typeof( window.pageYOffset ) == 'number' ) 
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } 
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } 
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
   
function checkDomain(url, ref)
{ 
    var sameDomain = false;
    try
    {
        var index = url.indexOf('.co.uk');
        if(index > -1)
        {
            var urlDomain = url.substring(url, index + 4);
            index = ref.indexOf('.co.uk')
            var refDomain = "";
            if(index > -1)
                refDomain = ref.substring(0, index + 4);
                
            if(urlDomain == refDomain)
                sameDomain = true;
        }
        else 
        {
            // TEST CODE
            sameDomain = true;
        }
    }
    catch(e) {}
    
    return sameDomain;

}


function Viewport()
{ 
    var windowX = (document.documentElement && document.documentElement.clientWidth) || 
                        window.innerWidth || self.innerWidth || document.body.clientWidth; 
    var windowY = (document.documentElement && document.documentElement.clientHeight) || 
                        window.innerHeight || self.innerHeight || document.body.clientHeight; 
    var scrollX = (document.documentElement && document.documentElement.scrollLeft) || 
                        window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
    var scrollY = (document.documentElement && document.documentElement.scrollTop) || 
                        window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
    var pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : 
                        (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
    var pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : 
                        (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
    
    
    //////alert( 'windowX: '  + windowX +  ' windowY: ' + windowY +  '\nscrollX: ' + scrollX +  ' scrollY: '  + scrollY + '\npageX: ' + pageX +  ' pageY: ' + pageY);
                        
    return [ windowX, windowY, scrollX, scrollY, pageX, pageY ];                     
                        
}

