<!-- OTP SETUP begin -->

<!--
//configuration
function OAS_AD( placement ) 
{ 
    var ord = Math.random()*10000000000000000; 
    var specific; 
    switch ( placement ) 
    { 
        case "Top": 
            specific = "tile=1;dcopt=ist;sz=468x60;"; 
            break; 
        case "Right": 
            specific = "tile=2;sz=120x600;"; // ??? no dcopt for Right?? 
            break; 
        case "Middle": 
            specific = "tile=3;sz=300x250;"; // ??? no dcopt for Middle?? 
            break; 
        default: 
            return; // invalid call, just ignore it 
    } 
    var jscode = '<sc' + 'ript language="JavaScript" src="http://ad.uk.doubleclick.net/adj/desperateseller.otpmedia/ros/' 
               + placement + 
               ";pos=above;make=value;model=value;minp=value;maxp=value;pcode=value;" 
               + specific + 
               'ord=' + ord + '?" type="text/javascript"></scr' + 'ipt>'; 

    document.write( jscode ); 
} 
//-->

<!-- OTP SETUP end -->

function selectModelOfCar(selectedModel, modelOptions){
	for (count=0; count<modelOptions.length; count++){
		if ( modelOptions.options[count].value == selectedModel )
			modelOptions.options[count].selected = true;
	}

  } 
  //End of the banner code

  function validateForm(){
    var form = document.forms['searchForm'];
    var pos

    //If no values have been entered into the free text fields, then fill them with 'ANY'
    if(form.model.value == "")
      form.model.value = "ANY";

    if(form.minPrice.value == "")
      form.minPrice.value = "ANY";

    if(form.maxPrice.value == "")
      form.maxPrice.value = "ANY";

    //Make sure that the price fields are numeric
    if(form.minPrice.value != 'ANY' && isNaN(form.minPrice.value)){
      //Remove any commas in the number
      do{
        form.minPrice.value = form.minPrice.value.replace(',', '');
        pos = form.minPrice.value.indexOf(',');
      }while(pos > 0)

      //If the string is still not numeric, then return falase
      if(isNaN(form.minPrice.value)){
        alert('Please make sure that the minimum price is numeric');
        form.minPrice.focus();
        return false;
      }
    }
    if(form.maxPrice.value != 'ANY' && isNaN(form.maxPrice.value)){
      //Remove any commas in the number
      do{
        form.maxPrice.value = form.maxPrice.value.replace(',', '');
        pos = form.maxPrice.value.indexOf(',');
      }while(pos > 0)

      //If the string is still not numeric, then return false
      if(isNaN(form.maxPrice.value)){
        alert('Please make sure that the maximum price is numeric');
        form.maxPrice.focus();
        return false;
      }
    }


    if(form.newCars.checked == false && form.usedCars.checked == false){
      alert('Please choose either New or Used Cars');
      return false;
    }
    form.submit();
        
  }
  function validateDealerSearchForm(){
		//No validation required at the moment, therefore simply submit the form
    var form = document.forms['searchForm'];
    //Set the dealername to ANY if it contains 'Dealer Name - ANY'
    if(form.dealername.value == 'Dealer Name - ANY')
    	form.dealername.value = 'ANY';
    form.submit();
  }
      
  //function validate the submitting of a form
  function submitForm(){
    //Validate that all of the required fields are filled in
    var form = document.forms['sendEmail'];
    var valid = 0;
    //Validate that at least one email address has been entered
    if(form.email1.value == '' && form.email2.value == '' && form.email3.value == ''){
      alert('Please enter at least one Email address');
      form.email1.focus();    
      return false;     
    }
    //Validate that the users name has been enterd
    if(form.yourName.value == ''){
      alert('Please enter your name');
      form.yourName.focus();
      return false;     
    }
        
    //Validate that the users Email address has been entered
    if(form.yourEmail.value == ''){
      alert('Please enter your Email address'); 
      form.yourEmail.focus();
      return false;     
    }
       
    //Validate that a subject has been entered
    if(form.subject.value == ''){
      alert('Please enter a subject');
      form.subject.focus();
      return false;     
    }
    //Submit the form
    form.submit();
  }

  //Funcion to sort the array by the chosen column
  function sortByValue(sortedValue){
    var userForm = document.forms.recordsPage;

    //If this is the price field (Indicated by 4), then check to see whether it is 
    //Ascending or descending
    if(sortedValue == '4'){
      if(userForm.OrderBy.value.substring(0, 1) != '4'){
        userForm.OrderBy.value = '4A';
      }
      else{
        if(userForm.OrderBy.value == '4A')
          userForm.OrderBy.value = '4D';
        else
          userForm.OrderBy.value = '4A';
      }
    }
    else{
      userForm.OrderBy.value = sortedValue;
    }
    userForm.submit();
  }
  function sortCarFinderResults(orderBy){
  	var userForm = document.forms.recordsPage;
  	userForm.orderBy.value = orderBy;
  	
  	userForm.submit();
  }
      
  function nextPage(){
    //This function allows the user to scroll to the next page of search results
      
    var userForm = document.forms.recordsPage;
    userForm.StartRecord.value = parseInt(userForm.StartRecord.value) + parseInt(userForm.RecordsPerPage.value);
    if(userForm.EndRecord.value + userForm.RecordsPerPage.value > userForm.TotalRecords.value)
      userForm.EndRecord.value = parseInt(userForm.TotalRecords.value);
    else
      userForm.EndRecord.value = parseInt(userForm.EndRecord.value) + parseInt(userForm.RecordsPerPage.value);

    userForm.submit();
  }

  function previousPage(){
    //This function allows the user to scroll to the previous page of search results
    var userForm = document.forms.recordsPage;

    if(userForm.StartRecord.value - userForm.RecordsPerPage.value < 0)
      userForm.StartRecord.value = 1;
    else
      userForm.StartRecord.value = parseInt(userForm.StartRecord.value) - parseInt(userForm.RecordsPerPage.value);

    userForm.EndRecord.value = parseInt(userForm.EndRecord.value) - parseInt(userForm.RecordsPerPage.value);

    userForm.submit();
  }
      
  function showCar(vendor, orderID, Make, Model, Body, Colour, regLetter, regYear, Mileage, Price, ContactPhone, Homepage, subFolder){
    //This function will open up the window pointing to the Vendors unique product ID
    //so that the user can go to the Vendors actual web site and display the chosen car

    var urlString = "";

    //For each subfolder to be navigated up, include a ../ in the url string
    //for(i=0; i<subFolder; i++){
    //  urlString+= '../'
    //}

    urlString+= "/CommonFiles/showCar.asp?Vendor="  + vendor;
    urlString+= "&orderID=" + escape(orderID);
    urlString+= "&Make=" + Make;
    urlString+= "&Model=" + Model;
    urlString+= "&Body=" + Body;
    urlString+= "&Colour=" + Colour;
    urlString+= "&regLetter=" + regLetter;
    urlString+= "&regYear=" + regYear;
    urlString+= "&Mileage=" + Mileage;
    urlString+= "&Price=" + Price;
    urlString+= "&contactPhone=" + ContactPhone;
    urlString+= "&Homepage=" + Homepage;
    window.open(urlString, "", "width=822,height=600,resizable=yes,scrollbars=yes");
    
  }
  function moreDetails(vendor, orderID, Make, Model, Body, Colour, regLetter, regYear, Mileage, Price, ContactPhone, Homepage, showHeader){
    //This function will open up the window pointing to the Vendors unique product ID
    //so that the user can go to the Vendors actual web site and display the chosen car

    var urlString = "";

    //For each subfolder to be navigated up, include a ../ in the url string
    //for(i=0; i<subFolder; i++){
    //  urlString+= '../'
    //}

    urlString+= "/CommonFiles/showCar.asp?Vendor="  + vendor;
    urlString+= "&orderID=" + escape(orderID);
    urlString+= "&Make=" + Make;
    urlString+= "&Model=" + Model;
    urlString+= "&Body=" + Body;
    urlString+= "&Colour=" + Colour;
    urlString+= "&regLetter=" + regLetter;
    urlString+= "&regYear=" + regYear;
    urlString+= "&Mileage=" + Mileage;
    urlString+= "&Price=" + Price;
    urlString+= "&contactPhone=" + ContactPhone;
    urlString+= "&Homepage=" + Homepage;
    urlString+= "&showHeader=" + showHeader;
    window.open(urlString, "", "width=822,height=600,resizable=yes,scrollbars=yes");
    
  }
  function moreDetailsTheIndependent(vendor, orderID, Make, Model, Body, Colour, regLetter, regYear, Mileage, Price, ContactPhone, Homepage, showHeader){
    //This function will open up the window pointing to the Vendors unique product ID
    //so that the user can go to the Vendors actual web site and display the chosen car

    var urlString = "";

    //For each subfolder to be navigated up, include a ../ in the url string
    //for(i=0; i<subFolder; i++){
    //  urlString+= '../'
    //}

    urlString+= "/CommonFiles/showCarTheIndependent.asp?Vendor="  + vendor;
    urlString+= "&orderID=" + escape(orderID);
    urlString+= "&Make=" + Make;
    urlString+= "&Model=" + Model;
    urlString+= "&Body=" + Body;
    urlString+= "&Colour=" + Colour;
    urlString+= "&regLetter=" + regLetter;
    urlString+= "&regYear=" + regYear;
    urlString+= "&Mileage=" + Mileage;
    urlString+= "&Price=" + Price;
    urlString+= "&contactPhone=" + ContactPhone;
    urlString+= "&Homepage=" + Homepage;
    urlString+= "&showHeader=" + showHeader;
    window.open(urlString, "", "width=822,height=600,resizable=yes,scrollbars=yes");

  }
  function moreDetailsYourCarDeal(vendor, orderID, Make, Model, Body, Colour, regLetter, regYear, Mileage, Price, ContactPhone, Homepage, showHeader){
    //This function will open up the window pointing to the Vendors unique product ID
    //so that the user can go to the Vendors actual web site and display the chosen car

    var urlString = "";

    //For each subfolder to be navigated up, include a ../ in the url string
    //for(i=0; i<subFolder; i++){
    //  urlString+= '../'
    //}

    urlString+= "/CommonFiles/showCarYourCarDeal.asp?Vendor="  + vendor;
    urlString+= "&orderID=" + escape(orderID);
    urlString+= "&Make=" + Make;
    urlString+= "&Model=" + Model;
    urlString+= "&Body=" + Body;
    urlString+= "&Colour=" + Colour;
    urlString+= "&regLetter=" + regLetter;
    urlString+= "&regYear=" + regYear;
    urlString+= "&Mileage=" + Mileage;
    urlString+= "&Price=" + Price;
    urlString+= "&contactPhone=" + ContactPhone;
    urlString+= "&Homepage=" + Homepage;
    urlString+= "&showHeader=" + showHeader;
    window.open(urlString, "", "width=822,height=600,resizable=yes,scrollbars=yes");

    }
	//This function should replace the openStockList function
	function viewStockList(vendor, dealerName, showHeader){
		var urlString = "/commonfiles/searchresults.asp?vendor=" + 
				vendor + 
				"&stocklist=1" +
				"&dealerName=" + dealerName +
				"&stylesheet=/commonfiles/stylesheets/searchresults.xsl" +
				"&showHeader=" + showHeader;
				
				window.open(urlString, "", "");
	}
  function openStockList(vendor, dealerName, subFolder, folderPath){
    var urlString = "";
    //For each subfolder to be navigated up, include a ../ in the url String
    //for(i=0; i<subFolder; i++){
    //  urlString+= '../';
    //}
        
    //Check to see whether there is a need to navigate down another path
    //if(folderPath != null && folderPath != ""){
    //  urlString+= folderPath + "/";
    //}

    //Create the rest of the url
    urlString+= "/commonfiles/searchresults.asp";
    //Add the parameters
    urlString+= "?Vendor=" + vendor;
    urlString+= "&stocklist=1";
    urlString+= "&dealerName=" + dealerName;
    urlString+= "&stylesheet=/CommonFiles/Stylesheets/searchresults.xsl";

    window.open(urlString, "", "");
  }

  function openVendorWindow(URL, subFolder){
    //This function opens a new window which displays the list of Insurers
    var urlString = "";
    //For each subfolder to be navigated up, include a ../ in the url String
    for(i=0; i<subFolder; i++){
      urlString+= '../';
    }
        
    urlString+= "CommonFiles/" + URL;

    window.open(urlString, "", "width=775,height=600,scrollbars=yes,resizeable=yes");
  }


  function openLoansWindow(URL){
    //Replace the original parent window (in this case the searchresults.asp page)
    parent.window.opener.location.href=URL;
  }
 
  function openInsuranceWindow(URL){
    //Open a new window with insurers
    window.open(URL, "", "width=650,height=600,scrollbars=yes,resizeable=yes");
  }
  function setSelectValue(select, value){
  	var options;
  	options = document.getElementById(select);
    for(i=0; i<options.length; i++){
      if(options.options[i].value == value){
        options.selectedIndex = i;
        i = options.length;
      }
    }  	
  }

  //Function to set the search criteria in the search results page to that which was 
  //originally selected, so that the user does not have to re-enter the search criteria
  function setSearchCriteria(make, model, regYear, county, mileage, newCars, usedCars, recordsReturned, VehicleCC){
    //Set the value of each of the select options to be the values passed through
    //Make of car

    var options
    var searchForm = document.forms['searchForm'];
        
    options = searchForm.make;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == make){
        options.selectedIndex = i;
        i = options.length;
      }
    }
    options = searchForm.model;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == model){
        options.selectedIndex = i;
        i = options.length;
      }
    }

    //Registration Year
    options = searchForm.regYear;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == regYear){
        options.selectedIndex = i;
        i = options.length;
      }
    }
    //County
    options = searchForm.county;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == county){
        options.selectedIndex = i;
        i = options.length;
      }
    }
    //Mileage
    options = searchForm.mileage;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == mileage){
        options.selectedIndex = i;
        i = options.length;
      }
    }
    //new cars
    if(newCars == 'on')
      searchForm.newCars.checked = true;
    //used cars
    if(usedCars == 'on')
      searchForm.usedCars.checked = true;

    //RecordsReturned
    options = searchForm.RecordsReturned;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == recordsReturned){
        options.selectedIndex = i;
        i = options.length;
      }
    }

    //Engine
    //options = searchForm.VehicleCC;
    //for(i=0; i<options.length; i++){
    //  if(options.options[i].value == VehicleCC){
    //    options.selectedIndex = i;
    //    i = options.length;
    //  }
    //}
  }
  function setDealerSearchCriteria(county, dealername){
    var options
    var searchForm = document.forms['searchForm'];  	
    //County
    options = searchForm.county;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == county){
        options.selectedIndex = i;
        i = options.length;
      }
    }    
    //Dealer name
    if(document.getElementById("dealername").value == 'ANY')
    	document.getElementById("dealername").value = 'Dealer Name - ANY';
    
  }

  function writeSelect(inArray){
    //This function writes out the options for each of the selection areas
    var noElements;  
    var endPos;        
    var startPos;
    var index;

    //Get the starting position                             
    startPos = inArray.indexOf(',', 1);
    noElements = 0;
    //Calculate how many elements in the array there should be
    while(startPos != -1){
      noElements++;
      //Increment the index counter  
      startPos = inArray.indexOf(',', startPos + 1);      
    }
    //The number of elements is always 1 greater than the number of commas
    noElements++;	

    //Create the array with the number of elements found
    var SelectArray = new Array(noElements);
          
    //loop around and get all of the elements
    startPos = 0;
    endPos = inArray.indexOf(',', startPos + 1);
    index = 0;
    while(endPos != -1){     
      SelectArray[index] = inArray.substr(startPos, endPos - startPos);
      index++;
      //Make the starting position the end position of the previous selection
      startPos = endPos + 1;
          
      //Calculate the next end position
      endPos = inArray.indexOf(',', startPos + 1);
    }
    //Get the last element
    SelectArray[index] = inArray.substr(startPos, inArray.length - startPos);
    //Loop around the array and write out the options for the select
    for(i=0; i<noElements; i++){
      document.write('<option value="' + SelectArray[i] + '">' + SelectArray[i] + '</option>');
    }
  }

  function writeRegYear(inArray){
    var noElements;  
    var endPos;        
    var startPos;
    var index;

    //Get the starting position                             
    startPos = inArray.indexOf(',', 1);
    noElements = 0;
    //Calculate how many elements in the array there should be
    while(startPos != -1){
      noElements++;
      //Increment the index counter  
      startPos = inArray.indexOf(',', startPos + 1);      
    }
    //The number of elements is always 1 greater than the number of commas
    noElements++;	

    //Create the array with the number of elements found
    var SelectArray = new Array(noElements);
         
    //loop around and get all of the elements
    startPos = 0;
    endPos = inArray.indexOf(',', startPos + 1);
    index = 0;
    while(endPos != -1){     
      SelectArray[index] = inArray.substr(startPos, endPos - startPos);
      index++;
      //Make the starting position the end position of the previous selection
      startPos = endPos + 1;
          
      //Calculate the next end position
      endPos = inArray.indexOf(',', startPos + 1);
    }
    //Get the last element
    SelectArray[index] = inArray.substr(startPos, inArray.length - startPos);
    //Loop around the array and write out the options for the select
    for(i=0; i<noElements; i++){
      document.write('<option value="' + SelectArray[i] + '">' + SelectArray[i] + ' and after</option>');
    }
  }

  function gotoPage(pageNumber){
    var userForm = document.forms.recordsPage;
    var TotalRecords = userForm.TotalRecords.value;
    var RecordsPerPage = userForm.RecordsPerPage.value;
    var StartRecord = userForm.StartRecord.value;
    var EndRecord = userForm.EndRecord.value;

    StartRecord = ((pageNumber - 1) * RecordsPerPage) + 1;        
    EndRecord = pageNumber * RecordsPerPage;
    //If the EndRecord is more than the total records, then make the end be the total
    if(EndRecord > TotalRecords)
      EndRecord = TotalRecords;
	  
    //Set the values of the input fields to be the calculated ones
    userForm.StartRecord.value = StartRecord;
    userForm.EndRecord.value = EndRecord;
    userForm.submit();
  }

  function writePageNumbers(totalPages){
    var userForm = document.forms.recordsPage;
    var TotalRecords = userForm.TotalRecords.value;
    var RecordsPerPage = userForm.RecordsPerPage.value;
    var StartRecord = userForm.StartRecord.value;
    var EndRecord = userForm.EndRecord.value;
    var CurrentPage;

    //Calculate the current page
    if(EndRecord == TotalRecords)
      CurrentPage = totalPages;
    else
      CurrentPage = EndRecord/RecordsPerPage;

    //Perform a loop to write the pages
    for(i=1; i<=totalPages; i++){
      //Only display the current page as the number with no hyperlink
      if(i == CurrentPage)
	document.write(i);
      else
	document.write('<a class="type2" href="" onClick="gotoPage(' + i + '); return false;">' + i + '</a>');  

      //Write a comma after every page
      if(i<totalPages)
        document.write(', ');
    }
  }

//MyShowroom functions
  function getNextNumber(name){
    //This function is used to get the next number of the cookie name. This is so that the 
    //users can have several cookies (6 in total) stored for each of their selections
    var cookieArray = unescape((document.cookie)).split(';');
    var nextNumber = 1;
    var currentNumber;
    var cookieName;
        
    //Loop around the array
    for(i=0; i<cookieArray.length; i++){
      cookieName = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('=')));
      if(cookieName.substr(0, 8) == 'Showroom'){
        currentNumber = parseInt(cookieName.substr(cookieName.length - 1, 1));
        if(currentNumber == nextNumber)
          nextNumber++;
      }
    }
    if(nextNumber > 6){
      alert('You may only have upto 6 cars saved in your list');
      return -1;
    }
    else	  
      return nextNumber;
  }
      
  function setCookie(name, value, expires, path, domain, secure){  	
    //Get the key and value for the OrderID	  
    var orderValue = value.substr(value.indexOf('OrderID='))
    var cookieName = alreadyInList(orderValue);

    //set up the value of the cookie
    var nextNumber = getNextNumber(name);

    if(nextNumber > 0){
      if(cookieName == ''){
        var curCookie = name + String(nextNumber) + '=' + swapSpace(value, true) +
            ((expires) ? '; expires=' + expires : '') +
            ((path) ? '; path=' + path : '') +
            ((domain) ? '; domain=' + domain : '') +
            ((secure) ? '; secure' : '');
            
        //Create the cookie
        document.cookie = curCookie;
        alert("Advert added to MyShowroom sucessfully.  This is located in the search box.");

        //Set the icon to remove
        if(document.getElementById("addRemoveIcon_" + orderValue)){
          document.getElementById("addRemoveIcon_" + orderValue).src="/commonfiles/images/removeIcon.gif";            
        }
        else if(top.window.opener.document.getElementById("addRemoveIcon_" + orderValue)){
          top.window.opener.document.getElementById("addRemoveIcon_" + orderValue).src="/commonfiles/images/removeIcon.gif";            
        }
      }
      else{
        //alert('Already in your list');
        //Delete the cookie if it is already in the list
        deleteCookie(cookieName, path, domain);
        if(document.getElementById("addRemoveIcon_" + orderValue)){
          document.getElementById("addRemoveIcon_" + orderValue).src="/commonfiles/images/addIcon.gif";
        }
        else if(top.window.opener.document.getElementById("addRemoveIcon_" + orderValue)){
          top.window.opener.document.getElementById("addRemoveIcon_" + orderValue).src="/commonfiles/images/addIcon.gif";
        }
      }
    }
  }
      
  function deleteCookie(name, path, domain){
    //If the cookie exists, set the expiry to timesomewhere way in the past
    var curCookie = name + '=' + 
      ((path) ? '; path=' + path : '') +
      ((domain) ? '; domain=' + domain : '') + 
      '; expires=Thu, 01-Jan-70 00:00:01 GMT';        

    document.cookie = curCookie;
    alert("Advert Removed from MyShowroom sucessfully");
  }
      
  function alreadyInList(value){
    var cookieArray = (unescape(document.cookie)).split(';');
    var cookieName = '';
    var startPos;
    for(i=0; i<cookieArray.length; i++){
      cookieName = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('='))); 
      if(cookieArray[i].indexOf(value) > 0){
        break;         
      }
      else{
            cookieName = '';
      }
    }

    return cookieName;
  }

  function writeCookieTable(showHeader){     	 	
    var htmlString = '';
    var cookieArray = (unescape(document.cookie)).split(';');
    var cookieName;
    var startPos;
    var cookieValue;

    //Start of the table
    if(numberInList() > 0){
      htmlString = htmlString + '<table border="0" cellpadding="0" cellspacing="5" width="100%">';
      htmlString = htmlString + '<tr>';
      //htmlString = htmlString + '  <th><font color="#ffffff" size="1">Model</font></th>';
      //htmlString = htmlString + '  <th><font color="#ffffff" size="1">£</font></th>';
      //htmlString = htmlString + '  <th><font color="#ffffff" size="1">Del</font></th>';
      htmlString = htmlString + ' <td bgcolor="#ffffff" style="padding: 5px;" width="100%"><font color="ff0000">' + numberInList() + '</font><font color="#000000"> Cars Saved</font></td>';
      htmlString = htmlString + '</tr>';  
      htmlString = htmlString + '<tr><td></tr></tr>';  
    }
        
    //for(i=0; i<cookieArray.length; i++){
      //Get the current cookie name
    //  cookieName = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('=')));

      //Get the value of the current cookie
     // var orderValue = cookieArray[i].substr(cookieArray[i].indexOf('OrderID='));

      //If the cookie is one that is required, then print it
      //if(cookieName.substr(0,8) == 'Showroom'){
        //Start the row
        //htmlString = htmlString + '<tr>';


        //Get the Model of the car
        //cookieValue = swapSpace(cookieArray[i], false);
        //startPos = cookieArray[i].indexOf('Model=') + 6;
        //htmlString = htmlString + '  <td><font color="#000000" size="1">' + cookieValue.substr(startPos, cookieValue.indexOf('&', startPos) - startPos) + '</font></td>';

        //Get the Price of the car
        //startPos = cookieArray[i].indexOf('Price=') + 6;
        //htmlString = htmlString + '  <td><font color="#000000" size="1">' + cookieValue.substr(startPos, cookieValue.indexOf('&', startPos) - startPos) + '</font></td>';
        //End the row
        //htmlString = htmlString + '  <td><font color="#000000" size="1"><a href="" onClick="deleteCookie(\'' + cookieName + '\', \'/\', \'\'); writeCookieTable(); changeAddRemoveIcon(\'' + orderValue + '\'); return false;" name="deleteCookie" id="deleteCookie"><font color="#ff0000">X</font></a></td>';
        //htmlString = htmlString + '</tr>';
      //}
    //}
    //End of the table
    if(numberInList() > 0){
    	if(showHeader != "")
    		htmlString = htmlString + '<tr><td colspan="4"><a href="compareShowroom.asp?showHeader=' + showHeader + '" target="_blank"><font color="#ff0000"><b>Compare these cars</b></font></a></td></tr>';
    	else
      	htmlString = htmlString + '<tr><td colspan="4"><a href="compareShowroom.asp" target="_blank"><font color="#ff0000"><b>Compare these cars</b></font></a></td></tr>';
      htmlString = htmlString + '</table>'
    }

    document.getElementById('ShowRoomTable').innerHTML = htmlString;
  }

  function getCurrentDate(daysToAdd){
    var expiryDate = new Date();
   
    expiryDate.setDate(expiryDate.getDate() + 30);
    var dateString = expiryDate.toGMTString() ; 	  

    return dateString;
  }

  function trim(inputField){
    var returnVal = inputField
    while(returnVal.charAt(0) == ' '){
      returnVal = returnVal.substr(1);
    }
    return returnVal
  }

  function numberInList(){
    var cookieArray = unescape((document.cookie)).split(';');
    var cookieName;
    var cookiesCounted = 0;

    for(i=0; i<cookieArray.length; i++){
      cookieName = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('=')));
      //If the cookie is one that is required, then print it
      if(cookieName.substr(0,8) == 'Showroom')
        cookiesCounted++;
      }
    return cookiesCounted;
  }

  function changeAddRemoveIcon(iconSuffix){
    if(document.getElementById("addRemoveIcon_" + iconSuffix)){
      document.getElementById("addRemoveIcon_" + iconSuffix).src = "/commonfiles/images/AddIcon.gif";
    }
  }
      
  function addRemoveIcon(OrderID, Dealer){
    var orderValue = 'OrderID=' + OrderID + '&Dealer=' + Dealer;
    var cookieName = alreadyInList(orderValue);

    if(cookieName == '')
      document.write('<img src="/commonfiles/images/AddIcon.gif" id="addRemoveIcon_' + orderValue + '" border="0" height="22" width="22" />');
    else
      document.write('<img src="/commonfiles/images/RemoveIcon.gif" id="addRemoveIcon_' + orderValue + '" border="0"  height="22" width="22" />');
  }

  function ErrorLoadingPic(imageTag, Radar24Square, path){
    var imageName = path + Radar24Square + '.gif';
    imageTag.src=imageName;    
  }  

  function swapSpace(input, trueorfalse){
    var position;
    var output;

    output = input;
    if(trueorfalse){
      position = output.indexOf(' ');
      while(position > 0){
        output = output.replace(' ', '+');
        position = output.indexOf(' ');
      }	     
    }
    else{
      position = output.indexOf('+');
      while(position > 0){
        output = output.replace('+', ' ');
        position = output.indexOf('+');
      }
    }
    return output;
  }

  function nextPage(){
    var userForm = document.forms.recordsPage;   
    var startRecord = parseInt(document.getElementById("StartRecord").value);
    var endRecord = parseInt(document.getElementById("EndRecord").value);
    var recordsPerPage = parseInt(document.getElementById("RecordsPerPage").value);     
    var totalRecords = parseInt(document.getElementById("TotalRecords").value);

    document.getElementById("StartRecord").value = startRecord + recordsPerPage;
 
    if(endRecord + recordsPerPage > totalRecords)
      document.getElementById("EndRecord").value = totalRecords;
    else
      document.getElementById("EndRecord").value = parseInt(document.getElementById("StartRecord").value) + recordsPerPage - 1;
    //Submit the form
    userForm.submit();
  }

  function prevPage(){
    var userForm = document.forms.recordsPage;   
    var startRecord = parseInt(document.getElementById("StartRecord").value);
    var endRecord = parseInt(document.getElementById("EndRecord").value);
    var recordsPerPage = parseInt(document.getElementById("RecordsPerPage").value);     

    if(startRecord - recordsPerPage < 1)
      document.getElementById("StartRecord").value = 1;
    else
      document.getElementById("StartRecord").value = startRecord - recordsPerPage;
  
    document.getElementById("EndRecord").value = parseInt(document.getElementById("StartRecord").value) + recordsPerPage - 1;
    //Submit the form
    userForm.submit();
  }

  function submitEnquiryForm(cookieName, cookieValue, cookieExpiry, cookiePath, cookieDomain, secure){
    //Create the cookie for this user
    if(document.getElementById("nodetails").checked == false)
      cookieExpiry = "";
        
    var curCookie = cookieName + '=' + swapSpace(cookieValue, true) +
        ((cookieExpiry) ? '; expires=' + cookieExpiry : '') +
        ((cookiePath) ? '; path=' + cookiePath : '') +
        ((cookieDomain) ? '; domain=' + cookieDomain : '') +
        ((secure) ? '; secure' : '');
            
    //Create the cookie
    document.cookie = curCookie;
      
    document.enquiryForm.submit();
  }

	function swapImg(img){
		var tempImgSrc = img.src;
		img.src = document.getElementById("largePicture").src;
		document.getElementById("largePicture").src = tempImgSrc;
	}
	function escapeChar(stringToEscape, charToEscape){
		var regExpression = /'/g;
		
		return stringToEscape.replace(regExpression, "''");
	}
	
	
	function writeName(){
		var cookievalue = getCookie('firstname');		
		if ( cookievalue != null && cookievalue != 'undefined'){
			document.write('<font size=2>Welcome <b>');
			document.write(getCookie('firstname') + ' ' + getCookie('lastname'));
			document.write('</b> (not you? <img border="0" src="http://www.desperateseller.co.uk/siteimages/bluearrow.gif" width="10" height="11"><a class="type1" href="/findacar/login.asp?rp=' + document.location.href + '">sign in</a>)');
		}		
	}
  function getCookie(cookiename){
    //This function is used to get the next number of the cookie name. This is so that the 
    //users can have several cookies (6 in total) stored for each of their selections
    var cookieArray = unescape((document.cookie)).split(';');    
    var name, cookievalue;
        
    //Loop around the array
    for(i=0; i<cookieArray.length; i++){
      name = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('=')));
      
      if ( name == cookiename ){		
		cookievalue = cookieArray[i].substr(cookieArray[i].indexOf('=') + 1);
      }      
    }
      return cookievalue;
  }
	
	
	
//-->

