
var feefoSliding = 0;
var FeefoSlideSpeed = 25;
var feefoParams="";
var firstFeeFoString = document.getElementById("firstFeeFo").value;
var firstFeeFo = parseInt(firstFeeFoString);

var feefoWidth = 0, feefoHeight = 0;

  feefoGetWindowSize();
  window.onresize = function(){feefoGetWindowSize()};
  document.onclick = function (e) {
      e = e || event

      var target = e.target || e.srcElement
      var feefopage = document.getElementById("feefopage");
      if (firstFeeFo == 0) {
          if (feefopage.style.right == "3000px") return;
          var feefologo = document.getElementById("feefologo");
          do {
              if (feefopage == target || feefologo == target) {
                  return
              }
              target = target.parentNode
          } while (target)
          feefopage.style.right = '3000px';
          document.getElementById("feefofade").style.display = "none";
     }
  } 
  
  
  function checkParent(t){ 
		while(t.parentNode){ 
			if(t==document.getElementById('feefologo')){ 
				return false 
			} 
			t=t.parentNode 
		} 
		return true 
	} 
 		

function feefoGetWindowSize(){
    feefoSliding = false;
    if (typeof (window.innerWidth) == 'number') {
       //Non-IE
       feefoWidth = window.innerWidth;
       feefoHeight = window.innerHeight;
   } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
       //IE 6+ in 'standards compliant mode'
       feefoWidth = document.documentElement.clientWidth;
       feefoHeight = document.documentElement.clientHeight;
   } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
       //IE 4 compatible
       feefoWidth = document.body.clientWidth;
       feefoHeight = document.body.clientHeight;
   }
   //alert("newsize");
    //document.getElementById("feefopage").style.right = "3000px";
  
}          
            
   


function feefojsonfeed(obj) {


 
   htmltext = "";
  for (i = 0;i < obj.html.length;i++)
		htmltext+=obj.html[i];
   		htmltext = htmltext.replace(/¬/gi,"'");
 
  htmltext = htmltext.replace("'WINDOWOPEN'","\"window.open(this.href,'Feefo','width=800,height=600,scrollbars,resizable'); return false\"");

   //extract the stylesheet to put into the header for IE
  if (htmltext.indexOf("stylesheet") > 0){ 
     
     spos = htmltext.indexOf("stylesheet");
     apos = -1;
     tpos = 0;
     while (apos < spos){
     apos = htmltext.indexOf("<",apos + 1);
     	if (apos < spos) tpos = apos;
     }
     hrefpos = htmltext.indexOf("href=", tpos);
     quotemark = htmltext.substring(hrefpos + 5, hrefpos + 6);
      endpos = htmltext.indexOf(quotemark, hrefpos + 7);
      stylesheetURL = htmltext.substring(hrefpos + 6,endpos); 
  		var headID = document.getElementsByTagName("head")[0];         
  		var cssNode = document.createElement('link');
  		cssNode.type = 'text/css';
  		cssNode.rel = 'stylesheet';
  		cssNode.href = stylesheetURL;
  		cssNode.media = 'screen';
  		//alert(cssNode);
  		headID.appendChild(cssNode);
  		//note:  maybe I should remove the original line...
  }  
  feefopage1 = document.getElementById("feefopage");
  feefopage1.style.right = "3000px";
  feefopage1.style.top = feefoHeight + "px";
  feefopage1.innerHTML = htmltext;
  setTimeout('FeefoSlide();', 500);

  
}	
 
   	   
   function FeefoSlide(){
	
       if (document.getElementById("feefopage").innerHTML.length < 10){ //no page loaded, but length may be 5!?
 
      	feefojson();
      	return;
		}
      FeefoSlider = document.getElementById("feefopage");
		FeefoFade = document.getElementById("feefofade");
		if (firstFeeFo == 0) {

		    newright = Math.round((feefoWidth - FeefoSlider.offsetWidth) / 2);
		    newtop = Math.round((feefoHeight - FeefoSlider.offsetHeight) / 2);
		    FeefoSlider.style.right = newright + "px";
		    FeefoSlider.style.top = newtop + "px";
		    FeefoFade.style.display = "block";
		    firstFeeFo = 1;

		} else if (firstFeeFo == 1) {

		    if (FeefoSlider.style.right == "3000px") {
		        newright = Math.round((feefoWidth - FeefoSlider.offsetWidth) / 2);
		        newtop = Math.round((feefoHeight - FeefoSlider.offsetHeight) / 2);
		        FeefoSlider.style.right = newright + "px";
		        FeefoSlider.style.top = newtop + "px";
		        FeefoFade.style.display = "block";


		    } else {
		        FeefoSlider.style.right = "3000px";
		        FeefoFade.style.display = "none";
		    }
		}
   }
   
   
   
function feefoloadlogo(logon, options){
 
   
 	
  	productcode = document.getElementById("feefoproduct");
   if (productcode){
    	if(productcode.value == "service")
   	 	feefoParams = "logon=" + logon;
   	else
      	feefoParams = "logon=" + logon + "&vendorref=" +  escape(productcode.value) + "&mode=product";
   }	
 	else{
  		feefoParams = "logon=" + logon;	
 	}	
   feefoParams = feefoParams + "&" + options;
  	
 		 
	template = feefotemplate();
	template=template.replace("LOGOPARAMS", feefoParams);
	//template=template.replace("VIEWPARAMS", feefoParams);
	template=template.replace("WINDOWOPEN","");
	document.write(template);
	feefoGetWindowSize();
	
}	
   
function feefotemplate(){
	template ='<LINK rel="stylesheet" type="text/css" href="https://www.feefo.com/logoscripts/feefoframe.css"/>';
	template+='<div id="feefologo">';
	template+='   <a href="javascript:" onclick="FeefoSlide();">';
	template+='			<img src="https://www.feefo.com/feefo/feefologo.jsp?LOGOPARAMS"/>';
	template+='		</a>';
	template+='</div>';
	template+='					<div id="feefopage">';
	template+='					</div>';
	template+='					<div id="feefofade"></div>';
return template;       
}    





function feefojson(){
   htmltext = "https://www.feefo.com/feefo/xmlfeed.jsp?html=json&" + feefoParams + "&nocache=true";
   script = document.createElement('script'),
   head = document.getElementsByTagName('head')[0] || document.documentElement;
   script.src = htmltext;
    head.appendChild(script);
}   
   

