// V.M. : 1.12.
//
// V.M   <----Date----> <-Time-> Inits    :  <----------------------------------------------Details----------------------------------------->
//01.00 0000/00/00 00:00:00 ???? : Original Version.
//01.10 2006/03/22 15:40:34 ACPM : Change "ALT" tag description.
//01.11 2006/08/15 15:21:11 ACPM : Change "ALT" tag description text from "Randomly Generated Advertising" to "Randomly generated advertising", as per Anna's request.
//01.12 2006/08/22 13:35:23 ACPM : Change "ALT" tag web address from "www.cbi.org.uk/advertising" to "www.cbi.org.uk/adverts" as per Anna's request.

//alert( "version:27100416:40" );
function startads() {
  browver= parseInt(navigator.appVersion);
  browtype = navigator.appName;
  browsertype = "old";
  if (browtype == "Netscape" && !(browver < 3)) {
    browsertype = "new"; 
  }
  if (browtype == "Microsoft Internet Explorer" && !(browver < 4)) {
    browsertype = "new";
  }
  if (browsertype == "new") {
    banneradcode=Math.round(Math.random() *3)
//    thetimer=setTimeout("changeimage()", 500)
    changeimage();
  }
  showSideImage(1);
  showSideImage(2);
  showSideImage(3);
  showSideImage(4);
  showSideImage(5);
  showSideImage(6);
}

function changeimage(){
  if (browsertype == "new") {
    banneradcode = banneradcode + 1;
    if (banneradcode == "100") {
      banneradcode = 0;
    }

	// Return relative URL
	var doubleSlashes = window.location.href.indexOf( "//" );
	if( doubleSlashes > -1 ){
 		var firstSlash = window.location.href.indexOf( "/" , doubleSlashes + 2 );
		} else{
		var firstSlash = 0;
	}
	var filePath = window.location.href.substring( firstSlash , window.location.href.length );

    imagesource = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=Image" + "&C=" + banneradcode 
// Navisite Europe Ltd (24 Dec 2004, Refer Anna Morrel)
//    imagesource = "http://www.cbi.org.uk:81/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=Image" + "&C=" + banneradcode 


    //imagesource = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(window.location.href)  + "&B=Image" + "&C=" + banneradcode 
    window.document.bannerad.src = imagesource;
    window.document.bannerad.alt="Randomly generated advertising. For a full list of adverts go to www.cbi.org.uk/adverts";
    thetimer = setTimeout("changeimage()", 20000);
  }
}

function changepage() { 
  if (browsertype == "new") {


	// Return relative URL
	var doubleSlashes = window.location.href.indexOf( "//" );
	if( doubleSlashes > -1 ){
 		var firstSlash = window.location.href.indexOf( "/" , doubleSlashes + 2 );
		} else{
		var firstSlash = 0;
	}
	var filePath = window.location.href.substring( firstSlash , window.location.href.length );


    newlocation = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=Link"  + "&C=" + banneradcode 
//    newlocation = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(window.location.href)  + "&B=Link"  + "&C=" + banneradcode 
    window.open(newlocation,'CBI_Advertiser','');
  }
}

function showSideImage(sideAdCode){


// Return relative URL
var doubleSlashes = window.location.href.indexOf( "//" );
if( doubleSlashes > -1 ){
 	var firstSlash = window.location.href.indexOf( "/" , doubleSlashes + 2 );
} else{
	var firstSlash = 0;
}
var filePath = window.location.href.substring( firstSlash , window.location.href.length );
imageSource = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=Image" + "&C=" + (sideAdCode + 104)
// Navisite Europe Ltd (24 Dec 2004, Refer Anna Morrel)
//imageSource = "http://www.cbi.org.uk:81/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=Image" + "&C=" + (sideAdCode + 104)

//alert( filePath );

// Return file name only 
//	var lastSlash = window.location.href.lastIndexOf( "/" );
//	var filename = window.location.href.substring( lastSlash + 1 , window.location.href.length );
//  imageSource = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(window.location.href)  + "&B=Image" + "&C=" + (sideAdCode + 104)

// Original version - full URL
//  imageSource = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filename)  + "&B=Image" + "&C=" + (sideAdCode + 104)




  if (window.document.images['sidead'+(sideAdCode+104)]) {
      window.document.images['sidead'+(sideAdCode+104)].src = imageSource;
      window.document.images['sidead'+(sideAdCode+104)].height=51;
      window.document.images['sidead'+(sideAdCode+104)].width=170;
      window.document.images['sidead'+(sideAdCode+104)].alt="Randomly generated advertising. For a full list of adverts go to www.cbi.org.uk/adverts";
      window.document.images['sidead'+(sideAdCode+104)].hspace=0;
      window.document.images['sidead'+(sideAdCode+104)].vspace=10;
      if(window.document.all){	
	  	  window.document.all['sidead'+(sideAdCode+104)+ 'anchor'].href="javascript:openSideLink(" + sideAdCode + ")";
	  }
	  else {  		 
			if (window.document.getElementById)
			{
							
				if (window.document.getElementById('sidead'+(sideAdCode+104)+ 'anchor'))
				{
			
					window.document.getElementById('sidead'+(sideAdCode+104)+ 'anchor').href="javascript:openSideLink(" + sideAdCode + ")";
				}
				else{

				}
				
			}

	  }
	  
  }

}

function openSideLink(sideAdCode){

// Return relative URL
var doubleSlashes = window.location.href.indexOf( "//" );
if( doubleSlashes > -1 ){
 	var firstSlash = window.location.href.indexOf( "/" , doubleSlashes + 2 );
} else{
	var firstSlash = 0;
}
var filePath = window.location.href.substring( firstSlash , window.location.href.length );
newLocation = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filePath)  + "&B=link" + "&C=" + (sideAdCode+104);



// Return file name only 
//	var lastSlash = window.location.href.lastIndexOf( "/" );
//	var filename = window.location.href.substring( lastSlash + 1 , window.location.href.length );
//  newLocation = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(filename)  + "&B=link" + "&C=" + (sideAdCode+104);

// Original version
//  newLocation = "/ads/ads.nsf/GetWebAds?OpenAgent" + "&A=" + escape(window.location.href)  + "&B=link" + "&C=" + (sideAdCode+104);


  window.open(newLocation,'CBI_Advertiser','');

  //reload images in case link clicked before images initially load
  showSideImage(1);
  showSideImage(2);
  showSideImage(3);
  showSideImage(4);
  showSideImage(5);
  showSideImage(6);
}

function hideLink(sideAdCode){
//alert( "Error for " + sideAdCode );
window.document.images['sidead'+sideAdCode].style.display="none";
}

//startads();

