function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function updateLinkPath(thelink, thepathname) {
  var x;
  // for(i=0;i<document.links.length;i++) {
  for(i=document.links.length-1; i>=0; i--) {
    if (document.links[i].name != thelink)
      continue;
    document.links[i].pathname = thepathname;
    break;
  }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swap_ad(tier,num_in_tier,tier_pos,ad_id,ad_img_file,company_name) { // swap images in client list
	var img_location = '/display/images/';
	var click_logger = '/maxclick/p/';  

	// change ad image
	var image = document.getElementById('tier_'+tier+'_image');
	image.src = img_location+ad_img_file;
	image.alt = company_name;
	image.title = company_name;
	
	// change arrow image
	for (i=0;i<num_in_tier;i++) {
		bullet = document.getElementById('tier_'+tier+'_blt_'+i);
		bullet.src = '/images/furniture/mini_arrow'+((i==tier_pos)?'':'_blt')+'.gif';		
	}
	
	// change link destination
	document.getElementById('tier_'+tier+'_link').pathname = click_logger+ad_id;
}



function openCenterWin(url,theWidth,theHeight){
var theTop=(screen.height/2)-(theHeight/2);
var theLeft=(screen.width/2)-(theWidth/2);
var features=
'height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+
",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes";
theWin=window.open(url,'',features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
// Popup windows 
function isUndefined(v) {
    var undef;
    return v===undef;
}

var _POPUP_FEATURES = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

// Function to switch images in the catalogue product pages
function switchProductImage(id,ext) {
	image = document.getElementById('productImage');
	link = document.getElementById('productImageLink');
	
	image.src = '/display/catalogue/product/'+id+'_medium'+ext;
	link.href = '/display/catalogue/product/'+id+'_large'+ext;
}

