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) 
{
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); 

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 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 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 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=1' +
                           ',status=0' +
                           ',toolbar=0' +
                           ',resizable=1' +
                           ',width=486' +
                           ',height=535' +
                           ',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 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;
   while(index < largeIds.length)
   {
       var entry = largeIds[index];
       if(entry.indexOf('[' + id + ']') > 0)
       {
        document.getElementById('largeLink').style.visibility = "visible";
        document.getElementById('noLargeLink').style.visibility = "hidden";
        unset = false;
       }
        index++;
   }
   if(unset)
   {
    document.getElementById('largeLink').style.visibility = "hidden";
    document.getElementById('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";
    }
}
