function LinkTo(cat,url,Make,Model,RegPlate,Price,Source,UniqueId,Comment,Groupid,Dealerid,Dealername,DealerRef,year) 
{
LinkToType(cat,url,Make,Model,RegPlate,Price,Source,UniqueId,Comment,Groupid,Dealerid,Dealername,DealerRef,'',year);
}
function LinkToType(cat,url,Make,Model,RegPlate,Price,Source,UniqueId,Comment,Groupid,Dealerid,Dealername,DealerRef,linkType,year,advertIdName,advertId) 
{
var width='';
var height='';
var sizes=url.substring(url.indexOf('POP_SIZE=')+9,url.length);
if(url.indexOf('POP_SIZE=') >-1)  
{
width=sizes.substring(0,sizes.indexOf('*'));
height=sizes.substring(sizes.indexOf('*')+1);
}
if (width =="" || width == null) width =520;
if (height == "" || height == null) height =480;
url = url.replace(/\$MAKE/,Make);
url = url.replace(/\$MODEL/,Model);
url = url.replace(/\$FULL_REG/,RegPlate);
url = url.replace(/\$PRICE/,Price);
url = url.replace(/\$ID/,UniqueId);
url = url.replace(/\$COMMENT/,Comment);
url = url.replace(/\$GROUPID/,Groupid);
url = url.replace(/\$DEALERID/,Dealerid);
url = url.replace(/\$DEALERNAME/,Dealername);
url = url.replace(/\$DEALERREF/,DealerRef); 
url = url.replace(/\$ADVERTIDNAME/,advertIdName);
url = url.replace(/\$ADVERTID/,advertId);

if (year && year != null)
{
    url = url.replace(/\$YEAR/,year);
}
url = url.replace(/\+/,'%2B');
var newUrl = 'http://atsearch.autotrader.co.uk/www/DealerRedirectServlet?channel=' + cat + 
'&source=' + Source + '&dealerId=' + Dealerid + '&linkType=' + escape(linkType) + '&redirectUrl=' + url;
pop_up(newUrl, '',width,height);
}
function tab_pop_up(cat, url, Dealerid, linkType, popName, Width, Height) 
{
var newUrl = 'http://atsearch.autotrader.co.uk/www/DealerRedirectServlet?channel=' + cat + 
'&source=TAB_POPUP&dealerId=' + Dealerid + '&linkType=' + escape(linkType) + '&redirectUrl=' + url;
pop_up(newUrl, popName, Width, Height);
}
function pop_up(URL,popName,Width,Height) 
{
if (Width =="" || Width == null) Width =486;
if (Height == "" || Height == null) Height =500;
var features =
',directories=0'+
',location=0'   +
',menubar=0'   +
',scrollbars=1'+
',status=0'   +
',toolbar=0'   +
',resizable=1' +
',width=' + Width +
',height=' + Height +
',screenX=15' +
',screenY=15' +
',top=15'+
',left=15';
URL = URL.replace(/\s/,'%20');
;
wind=window.open (URL, popName, features);
wind.focus();
}
function pop_up_ks_large_image()
{
var index = 0;
while(index < largeIds.length)
{
var entry = largeIds[index];
if(entry.indexOf('[' + id + ']') > 0)
{
var foundId = entry.substr(0,entry.indexOf('[' + id + ']'));
var features =    ',directories=0' +
',location=0' +
',menubar=0' +
',scrollbars=0' +
',status=0' +
',toolbar=0' +
',resizable=1' +
',width=460' +
',height=400' +
',screenX=15' +
',screenY=500' +
',top=15' +
',left=550';
var large_image = window.open( ks_large_url + foundId, "LargeImage", features );
large_image.focus();
index = largeIds.length;
}
index++;
}
}
function change_parent(URL)  
{
if (window.opener && !window.opener.closed)  
{
window.opener.location=URL;
window.opener.focus();
}
else 
{
window.open(URL, 'NEW');
}
}
function pop_up_sales_lead( url, id, manufacturer, model )
{
url = url + "?id=" + id + "&manufacturer=" + manufacturer + "&model=" + model + "&new=yes";
var features = ',directories=0' +
',location=0' +
',menubar=0' +
',scrollbars=1' +
',status=0' +
',toolbar=0' +
',resizable=1' +
',width=486' +
',height=635' +
',screenX=15' +
',screenY=15' +
',top=15' +
',left=15';
var new_car = window.open( url, "SalesLead", features );
new_car.focus();
}
function multiple_pop_up_large_image()
{
var index = 0;
while(index < largeIds.length)
{
var entry = largeIds[index];
if(entry.indexOf('[' + id + ']') > 0)
{
var foundId = entry.substr(0,entry.indexOf('[' + id + ']'));
var features = ',directories=0' +
',location=0' +
',menubar=0' +
',scrollbars=0' +
',status=0' +
',toolbar=0' +
',resizable=1' +
',width=680' +
',height=525' +
',screenX=15' +
',screenY=550' +
',top=15' +
',left=550';
var large_image = window.open( large_url + foundId, "LargeImage", features );
large_image.focus();
index = largeIds.length;
}
index++;
}
}
function popUpLargeImage(cssLocation)
{
    var index = 0;
    while(index < largeIds.length)
    {
        var entry = largeIds[index];
        if(entry.indexOf('[' + id + ']') > 0)
        {
            var foundId = entry.substr(0,entry.indexOf('[' + id + ']'));
            var features = ',directories=0' +
                           ',location=0' +
                           ',menubar=0' +
                           ',scrollbars=0' +
                           ',status=0' +
                           ',toolbar=0' +
                           ',resizable=1' +
                           ',width=930' +
                           ',height=711' +
                           ',screenX=15' +
                           ',screenY=550' +
                           ',top=15' +
                           ',left=550';
            var large_image = window.open( large_url + foundId + cssLocation, "LargeImage", features );
            large_image.focus();
            index = largeIds.length;
        }
        index++;
    }
}

function uvl_pop_up_large_image(cssLocation)
{
    popUpLargeImage('&csslocation=' + cssLocation);
}

function pop_up_large_image()
{
    popUpLargeImage('');
}

function printWindow()
{
if (window.print)
{
window.print();
}
}
function swapImage(image,id_)
{
document.master.src = image;
id = id_;
hide();
}
function hide()
{
var index = 0;
var unset = true;
var largeLink = document.getElementById('largeLink');
var noLargeLink = document.getElementById('noLargeLink');
while(index < largeIds.length)
{
var entry = largeIds[index];
if(entry.indexOf('[' + id + ']') > 0)
{
if (largeLink){
largeLink.style.visibility = "visible";
}
if (noLargeLink)
{
noLargeLink.style.visibility = "hidden";
}
unset = false;
}
index= index + 1;
}
if(unset)
{
if (largeLink)
{
largeLink.style.visibility = "hidden";
}
if (noLargeLink)
{
noLargeLink.style.visibility = "visible";
}
}
}
function checkAnchor(anchor)
{
var index = 0;
var unset = true;
while(index < largeIds.length)
{
var entry = largeIds[index];
if(entry.indexOf('[' + id + ']') > 0)
{
anchor.style.cursor = "pointer";
unset = false;
}
index++;
}
if(unset)
{
anchor.style.cursor = "default";
}
}
function checkAnchorZoom(anchor)
{
var index = 0;
var unset = true;
while(index < largeIds.length)
{
var entry = largeIds[index];
if(entry.indexOf('[' + id + ']') > 0)
{
anchor.style.cursor = "url(images/magniglass.cur)";
unset = false;
}
index++;
}
if(unset)
{
anchor.style.cursor = "default";
}
}

function sw(y, x, z, w) {
// function that's called on standard pop up for the more or less link
    if (y == "on") {
        document.getElementById(x).style.height = "68%";
        document.getElementById(z).style.display = "none";
        document.getElementById(w).style.display = "block";
    }
    if (y == "off") {
        document.getElementById(x).style.height = "158px";
        document.getElementById(z).style.display = "block";
        document.getElementById(w).style.display = "none";
    }
}

if(document.all){
function checkBodySize(){
var shdWidth=document.body.clientWidth;
var actWidth=document.documentElement.clientWidth;
if(actWidth<shdWidth){actWidth=shdWidth+10;
var tars4ds=["topBannerContainer","widerSkyScraperAd"];
for(var i=0;i<tars4ds.length;i++){
if(document.getElementById(tars4ds[i])!=null){
document.getElementById(tars4ds[i]).style.display="block";
}}}}window.onload=checkBodySize;
window.onresize=checkBodySize;
}
