﻿var YUUFontColor = '';
var YUUBodyColor = '';
var YUUFont = '';
var YUUFontStyle = '';
var YUUFontSize = '';
var YUUFontWeight = '';
var YUUTextDecoration = '';
var YUUStarsWidth = '350px';
var YUUStarsHeight = '45px';
var YUUURL = 'http://YUUReview.co.uk';
var YUUShowAwards = true;
var YUUShowPlayability = true;
var YUU_PFontColor = '';
var YUU_PBodyColor = '';
var YUU_PTabColor = '';
var YUU_PTabFontColor = '';
var YUU_PTabBorderColor = '';
var YUU_PTabBorderWidth = '1';
var YUUCorners = 'M';
var YUUSSOption = '1';

var YUUCSS=document.createElement("link");
YUUCSS.setAttribute("rel", "stylesheet")
YUUCSS.setAttribute("type", "text/css")
YUUCSS.setAttribute("href", YUUURL + "/css/YUU.css")
document.getElementsByTagName("head")[0].appendChild(YUUCSS)
   
function YUULoadText(ProductCode, Brand, ProductName, Test){
    
    if (Test != true){
        var divString = "<div style=''><div style='border: none; position: relative; left: 0px; top: 0px; ; z-index: 70; ' id='YUU" + ProductCode + "' width='" + YUUStarsWidth + "' height='" + YUUStarsHeight + "'></div>"
        divString = divString + "<div style='border: none; position: absolute; left: 0px; top: 0px; z-index: 80; ' id='YUUInvis" + ProductCode + "' width='" + YUUStarsWidth + "' height='" + YUUStarsHeight + "'></div></div>";
        document.write(divString);
    }
    
    var YUUDiv = document.getElementById("YUU" + ProductCode);
    
    starURL = YUUURL + '/Stars.aspx?ID=' + encodeURIComponent(ProductCode) + '&Brand=' + encodeURIComponent(Brand) + "&PN=" + encodeURIComponent(ProductName);
    starURL = starURL + '&YFC=' + encodeURIComponent(YUUFontColor);
    starURL = starURL + '&YBC=' + encodeURIComponent(YUUBodyColor);
    starURL = starURL + '&YF=' + encodeURIComponent(YUUFont);
    starURL = starURL + '&YFS=' + encodeURIComponent(YUUFontSize);
    starURL = starURL + '&YFW=' + encodeURIComponent(YUUFontWeight);
    starURL = starURL + '&YFSt=' + encodeURIComponent(YUUFontStyle);
    starURL = starURL + '&YFTd=' + encodeURIComponent(YUUTextDecoration);
    starURL = starURL + '&SA=' + encodeURIComponent(YUUShowAwards);
    starURL = starURL + '&SP=' + encodeURIComponent(YUUShowPlayability);
    starURL = starURL + '&SSO=' + encodeURIComponent(YUUSSOption);
    
    var FrameString = "<iframe id='YUUFrame' src='" + starURL + "' frameborder='0' scrolling='no' padding='0' allowtransparency='true' height='" + YUUStarsHeight + "' width='" + YUUStarsWidth + "'>"

//Bug in IE means that the ifram is sunken and can't change attribute
//    var YUUFrame = document.createElement("iframe");
//    YUUFrame.setAttribute('id', 'YUUFrame');
//    YUUFrame.setAttribute('src', starURL);
//    
//    YUUFrame.style.frameBorder = "0";
//    YUUFrame.setAttribute("marginwidth","0px");
//    YUUFrame.setAttribute("marginheight","0px");
//    YUUFrame.style.padding ="0px";
//    YUUFrame.style.border = 'none';
//        
//    YUUFrame.setAttribute('onclick', 'YUULoadReviews();')
//    YUUFrame.setAttribute('allowtransparency', 'true');
//    YUUFrame.style.width = YUUStarsWidth;
//    YUUFrame.style.height = YUUStarsHeight;
//    YUUDiv.appendChild(YUUFrame);
//END Bug in IE means that the ifram is sunken and can't change attribute

    YUUDiv.innerHTML = FrameString;
    
    var YUUDivO = document.getElementById("YUUInvis" + ProductCode);
    
    //if(navigator.appName.indexOf("Explorer") == -1) {    //rem'd out when copying to IIS7!!!
        
        YUUDiv.appendChild(YUUDivO);
        
        var YUUImg = document.createElement("img");
        YUUImg.setAttribute('style', 'width: ' + YUUStarsWidth + '; height: ' + YUUStarsHeight + '; cursor: pointer');
        YUUImg.setAttribute('src', YUUURL + '/images/blank.gif');
        YUUImg.setAttribute('onclick', 'YUULoadReviews(\'' + ProductCode + '\', \'' + Brand + '\', \'' + ProductName + '\');')
        YUUDivO.appendChild(YUUImg);
        
    //}else{    //rem'd out when copying to IIS7!!!
    //    YUUDivO.setAttribute('innerHTML', '<a href="javascript:YUULoadReviews(\'' + ProductCode + '\', \'' + Brand + '\', \'' + ProductName + '\')"><img src="' + YUUURL + '/images/blank.gif" border="0" width="' + YUUStarsWidth + '" height="' + YUUStarsHeight + '"></a>');
    //    YUUDiv.appendChild(YUUDivO);
    //}
}

function YUULoadReviews(ProductCode, Brand, ProductName) {
    //<div id="YUUoverlay"></div>
		//	<div id="YUUlightbox">
		//		<div id="YUUouterImageContainer">
  //			<div id="YUUimageContainer">
  //                <iframe....


  var objBody = document.getElementsByTagName("body").item(0);
  objBody.style.height = "100%";

  var objOverlay1 = document.createElement("div");
  objOverlay1.setAttribute('id', 'YUUoverlay');
  objOverlay1.style.zIndex = 1000;
  objOverlay1.onclick = function() { YUUend(); }
  objBody.appendChild(objOverlay1);

  
  //$('#YUUoverlay').html('<p><img src="' + YUUURL + '"/images/ajax-loader.gif" width="220" height="19" /></p>');

  var objOverlay2 = document.createElement("div");
  objOverlay2.setAttribute('id', 'YUUlightbox');
  objOverlay2.onclick = function() { YUUend(); }
  objBody.appendChild(objOverlay2);

  var YUUClose = document.createElement("div");
  YUUClose.setAttribute('id', 'YUUClose');
  YUUClose.setAttribute('style', 'left: 1px;')
  YUUClose.style.width = "505px";
  objOverlay2.appendChild(YUUClose);
  
  var YUUCloseA = document.createElement("a");
  YUUCloseA.setAttribute('id', 'bottomNavClose');
  YUUCloseA.setAttribute('href', '#');
  YUUCloseA.onclick = function() { YUUend; return false; }
  YUUClose.appendChild(YUUCloseA);
  
  YUUCloseImage = document.createElement("img");
  YUUCloseImage.setAttribute('src', YUUURL + '/images/CloseButton.png');
  YUUCloseImage.style.marginRight = '4px';
  YUUCloseImage.style.marginTop = '1px';
  YUUCloseA.appendChild(YUUCloseImage);
  
  var objOverlay3 = document.createElement("div");
  objOverlay3.setAttribute('id', 'YUUouterImageContainer');
  objOverlay3.style.backgroundColor = 'white';
  //objOverlay3.setAttribute('style', 'background-image: url(" + YUUURL + "/images/ajax-loader.gif)');
  objOverlay2.appendChild(objOverlay3);
  
  objFrame = createObjFrame(ProductCode, Brand, ProductName, YUUFontColor, YUUBodyColor, YUUFont, YUUFontSize, YUUFontWeight, YUUFontStyle, YUUTextDecoration);
  objOverlay3.appendChild(objFrame);
  
  var arrayPageSize = YUUgetPageSize();
  objOverlay1.style.height = arrayPageSize[1] + 'px';
  objOverlay1.style.width = arrayPageSize[0] + 'px';
    
  // calculate top and left offset for the lightbox 
  var arrayPageScroll = YUUgetPageScroll();
  var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
  var lightboxLeft = arrayPageScroll[0];
  objOverlay2.style.top = lightboxTop + 'px';
  objOverlay2.style.left = lightboxLeft + 'px';

  objOverlay2.style.display = "block";
  
  YUUhideSelectBoxes();
  YUUhideFlash();
}

function createObjFrame(ProductCode, Brand, ProductName, YUUFontColor, YUUBodyColor, YUUFont, YUUFontSize, YUUFontWeight, YUUFontStyle, YUUTextDecoration){

  var reviewURL = '';
  reviewURL = YUUURL + '/YUUReview.aspx?ID=' + encodeURIComponent(ProductCode) + '&Brand=' + encodeURIComponent(Brand) + '&PN=' + encodeURIComponent(ProductName);
  reviewURL = reviewURL + '&YFC=' + encodeURIComponent(YUU_PFontColor);
  reviewURL = reviewURL + '&YBC=' + encodeURIComponent(YUU_PBodyColor);
  reviewURL = reviewURL + '&YTC=' + encodeURIComponent(YUU_PTabColor);
  reviewURL = reviewURL + '&YTFC=' + encodeURIComponent(YUU_PTabFontColor);
  reviewURL = reviewURL + '&YTBC=' + encodeURIComponent(YUU_PTabBorderColor);
  reviewURL = reviewURL + '&YTBW=' + encodeURIComponent(YUU_PTabBorderWidth);
  reviewURL = reviewURL + '&YF=' + encodeURIComponent(YUUFont);
  reviewURL = reviewURL + '&YFS=' + encodeURIComponent(YUUFontSize);
  reviewURL = reviewURL + '&YFW=' + encodeURIComponent(YUUFontWeight);
  reviewURL = reviewURL + '&YFSt=' + encodeURIComponent(YUUFontStyle);
  reviewURL = reviewURL + '&YFTd=' + encodeURIComponent(YUUTextDecoration);
  reviewURL = reviewURL + '&SA=' + encodeURIComponent(YUUShowAwards);
  reviewURL = reviewURL + '&SP=' + encodeURIComponent(YUUShowPlayability);
  reviewURL = reviewURL + '&SC=' + encodeURIComponent(YUUCorners);
  
  var theBrower = navigator.userAgent;

  if (theBrower.indexOf('MSIE') > -1){
    reviewURL = reviewURL + '&B=1'
  }else{
    reviewURL = reviewURL + '&B=0'
  }

  var objFrame = document.createElement('iFrame');
  objFrame.setAttribute('id', 'YUUReviews')
  objFrame.style.width = '505px';
  objFrame.style.height = '460px';
  objFrame.style.border = 'none';
  objFrame.setAttribute('frameBorder', '0');
  objFrame.setAttribute('src', reviewURL);
  return objFrame;
}
function YUUgetPageSize() {

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = window.innerWidth + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;

  //	console.log(self.innerWidth);
  //	console.log(document.documentElement.clientWidth);

  if (self.innerHeight) {	// all except Explorer
    if (document.documentElement.clientWidth) {
      windowWidth = document.documentElement.clientWidth;
    } else {
      windowWidth = self.innerWidth;
    }
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if (yScroll < windowHeight) {
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

  //	console.log("xScroll " + xScroll)
  //	console.log("windowWidth " + windowWidth)

  // for small pages with total width less then width of the viewport
  if (xScroll < windowWidth) {
    pageWidth = xScroll;
  } else {
    pageWidth = windowWidth;
  }
  //	console.log("pageWidth " + pageWidth)

  arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
  return arrayPageSize;
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function YUUgetPageScroll() {

  var xScroll, yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
    xScroll = self.pageXOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
    xScroll = document.documentElement.scrollLeft;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
    xScroll = document.body.scrollLeft;
  }

  arrayPageScroll = new Array(xScroll, yScroll)
  return arrayPageScroll;
}

function YUUend(){
    
    var YUUDiv = document.getElementById("YUUoverlay");
    YUUDiv.setAttribute('style', 'visibility:hidden');
    
    var YUUDiv1 = document.getElementById("YUUlightbox");
    YUUDiv1.setAttribute('style', 'visibility:hidden');
    
    var objBody = document.getElementsByTagName("body").item(0);
    objBody.removeChild(YUUDiv);
    objBody.removeChild(YUUDiv1);
      
    YUUshowSelectBoxes();
    YUUshowFlash();
}

function YUUshowSelectBoxes() {
  var selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "visible";
  }
}

// ---------------------------------------------------

function YUUhideSelectBoxes() {
  var selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "hidden";
  }
}

// ---------------------------------------------------

function YUUshowFlash() {
  var flashObjects = document.getElementsByTagName("object");
  for (i = 0; i < flashObjects.length; i++) {
    flashObjects[i].style.visibility = "visible";
  }

  var flashEmbeds = document.getElementsByTagName("embed");
  for (i = 0; i < flashEmbeds.length; i++) {
    flashEmbeds[i].style.visibility = "visible";
  }
}

// ---------------------------------------------------

function YUUhideFlash() {
  var flashObjects = document.getElementsByTagName("object");
  for (i = 0; i < flashObjects.length; i++) {
    flashObjects[i].style.visibility = "hidden";
  }

  var flashEmbeds = document.getElementsByTagName("embed");
  for (i = 0; i < flashEmbeds.length; i++) {
    flashEmbeds[i].style.visibility = "hidden";
  }

}

//Lee code

function visible(me){
		if (me.style.visibility=="hidden"){
			me.style.visibility="visible";
			}
		else {
			me.style.visibility="hidden";
			}
		}
