var tempStyle;

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function printable() {
	tempStyle = getActiveStyleSheet();
	handle = window.open(location.href + "?print=1");
}

function backFromPrintable(){
	setActiveStyleSheet(tempStyle);
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}


var fHeight;

function getAndSetIFrameHeight(){
	if(document.getElementById('ifr')){
		fHeight = top['ifr'].document.getElementById('recommendedProducts').offsetHeight;
		wHeight = document.getElementById('wrapper').offsetHeight;
		if(fHeight > wHeight) document.getElementById('ifr').height = fHeight;
		else document.getElementById('ifr').height = wHeight;
	}
}

function setSponsorSide(){
	var t = document.getElementById("recommendedAlt");
	var c = document.getElementById("content");
	
	if(t){
		h = c.offsetHeight;
		t.style.height = h + "px";
	}
}

//window.onload=setSponsorSide;


if ( typeof window.addEventListener != "undefined" )

    window.addEventListener( "load", setSponsorSide, false );

else if ( typeof window.attachEvent != "undefined" ) {

    window.attachEvent( "onload", setSponsorSide );

}

else {

    if ( window.onload != null ) {

        var oldOnload = window.onload;

        window.onload = function ( e ) {

            oldOnload( e );

            setSponsorSide();

        };

    }

    else

        window.onload = setSponsorSide;

}

function setInlineWidth() {
	var d = document.images;
	var imgs = new Array();
	var j = 0;
	var found, found2;

	var t = document.getElementById("sideBody");


	for (j=0;j<t.childNodes.length;j++)
	{
		if(t.childNodes[j].className == "caption not4print") {
			found = t.childNodes[j];
			
			for(k=0;k<found.childNodes.length;k++) {
				if(found.childNodes[k].tagName == "IMG") {
					found2 = found.childNodes[k];		
				}
				
			}
			
		}

	}


	test = new Image();
	test.src = found2.src;
	found2.src = test.src;
	found2.height = test.height;
	found2.width = test.width;
	
	if(found2.width > 160) found2.width = 160;	
	
	alert(found2.width);

	for (i=0;i<d.length;i++)
	{
		text = d[i].id;

		//temp = new Image();
		//temp.src = d[i].src;
		
		//if(temp.width > 160) { alert(temp.src); temp.width = 160; };
		

		//d[i].width = temp.width;		
		//d[i].height = temp.height;
	
		x = text.indexOf("img_");

		if(x != -1) {
			curobj = document.getElementById(d[i].id);
			w = curobj.offsetWidth;

			//curobj.parentNode.style.width = w + "px";
			curobj.parentNode.parentNode.nextSibling.firstChild.style.width = w + "px";
			//alert(curobj.parentNode.nodeType);
			//curobj.parentNode.parentNode.lastChild.style.width = w + "px";
			//curobj.parentNode.parentNode.parentNode.style.width = w + "px";
			//curobj.parentNode.parentNode.parentNode.style.backgroundColor = 'pink';
		}
	}
}
