function writeBanner(banner) {
   var abc = Math.random() + "";
   var random = abc.substring(2, abc.length);

   document.writeln("<SCRIPT type=\"text/javascript\" LANGUAGE=\"JavaScript1.1\" SRC=\"http://ad.doubleclick.net/adj/" +
                    banner + ";dcopt=ist;tile=1;sz=468x60;ord=" + random + "?\">\</SCRIPT>");
}

function shoppyPopUpWin() {
    var textlink='http://img.shopping.com/cctool/files/intro_win.html';
    var ht=540;
    var wd=720;
    var wPos=0;
    var hPos=0;

	if (screen) {
		wPos = (screen.availWidth-wd)/2;
		hPos = (screen.availHeight-wd)/2;
	}

    var agt=navigator.userAgent.toLowerCase();

    if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
    	var newwindow;
    }

	if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
		if (newwindow != null) { newwindow.close(); }
	}

	newwindow = window.open(textlink,'popup','height=' + ht + ',width=' + wd + ',left=' + wPos + ',top=' + hPos + ', scrollbars=no,toolbar=no,copyhistory=no,resizable=no,directories=no,menubar=no,status=no,location=no');
	newwindow.focus();
}

function whatIS(FileName) {
   var win = popupWin(FileName, "whatIS", 300, 460, "yes")
}

function rebatePop(link) {
   var win = popupWin(link, "whatIS", 425, 632, "no");
}

function popupWin(url, winName, height, width, scrollBars, hPos, wPos) {
    if (url == null) {
        return null;
    }

    var defaultHt = 540;
    var defaultWd = 720;
    var defaultWPos = 0;
    var defaultHPos = 0;

    if (height == null) {
        height = defaultHt;
    }
    if (width == null) {
        width = defaultWd;
    }
    if (wPos == null) {
        wPos = defaultWPos;
    }
    if (hPos == null) {
        hPos = defaultHPos;
    }
    if (winName == null) {
        winName = 'popup';
    }
    if (scrollBars == null) {
        scrollBars = 'no';
    }

    if (screen) {
        wPos = (screen.availWidth - width) / 2;
        hPos = (screen.availHeight - height) / 2;
    }

    var agt=navigator.userAgent.toLowerCase();

    if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
        var newwindow;
    }

    if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
        if (newwindow != null) { newwindow.close(); }
    }

    newWin = window.open(url, winName, 'height=' + height + ',width=' + width + ',left=' + wPos + ',top=' + hPos + ', scrollbars=' + scrollBars + ',toolbar=no,copyhistory=no,resizable=no,directories=no,menubar=no,status=no,location=no');
    newWin.focus();

    return newWin;
}

function transit(key, uk, partnerid) {
    var destination;
    if (key == 'dtuk') {
        destination = 'http://www.dealtime.co.uk/';
    } else if (key == 'dt') {
        destination = 'http://www1.dealtime.com/';
    } else if (key == 'joinmerch') {
        destination = 'https://merchants.shopping.com/' + uk + 'welcome.html';
    } else if (key == 'loginmerch') {
        destination = 'https://merchants.shopping.com/' + uk + 'MerchantTool/Home.html';
        if (partnerid != '') {
            destination += '?PartnerId=' + partnerid;
        }
    } else if (key == 'epinions') {
        destination = 'http://www.epinions.com/';
    } else if (key == 'joinmerchdtuk') {
        destination = 'https://www.dealtime.net/uk/welcome.html';
    } else if (key == 'loginmerchdtuk') {
        destination = 'https://www.dealtime.net/uk/MerchantTool/Home.html';
        if (partnerid != '') {
            destination += '?PartnerId=' + partnerid;
        }
    }
    document.location.href = destination;
}
function reload(){window.location.reload()}
function ws(s){window.status=s?s:'';return true}
function pop(url){window.open(url,'popup','screenX=0,screenY=0,resizable=yes,scrollbars=yes,height=300,width=400')}
function dc(url,ct){document.write('<a href='+url+'&CT='+ct+'>')}
function feat(){pop('http://img.shopping.com/sc/ds/sdc_featured_store.html')}
function trust(){pop('http://img.shopping.com/cctool/files/sdc_trusted.html')}
function smart(){pop('http://img.shopping.com/cctool/files/sdc_smart_buy.html')}
function why(){pop('http://img.shopping.com/sc/ds/sdc_whyList.html')}
function rebate(){pop('http://img.shopping.com/cctool/Rebates/21667966.html')}
function shoppy(){pop('http://img.shopping.com/cctool/files/intro_win.html')}

function userStatusPopup (status) {
   var win;
   if ( status == 'lead' ) {
      win = window.open('http://www.shopping.com/xProductReviews/memberLead.html','',"status=no,resizable=no,width=495,height=180");
   } else if ( status == 'advisor' ) {
      win = window.open('http://www.shopping.com/xProductReviews/memberAdv.html','',"status=no,resizable=no,width=495,height=200");
   } else {
      win = window.open('http://www.shopping.com/xProductReviews/memberTopRev.html','',"status=no,resizable=no,width=495,height=180");
   }
}

function sortReviews(prdName,mrId,zeroDeals) {
    var theForm = document.frmSort;
    var selectedIndex = theForm.sortby.selectedIndex;
    var sortVal = theForm.sortby.options[selectedIndex].value;
    var newLocation;
    if ( prdName ) {
        newLocation = '/xPR-' + prdName + '~S-' + sortVal;
        if (zeroDeals == 1) {
            newLocation     = newLocation + '~ZD-' + zeroDeals ;
        }
    } else {
        newLocation = '/xMR-~MRD-' + mrId + '~S-' + sortVal;
    }
    document.location.href=newLocation;
}

linkName2Index = new Object(); // cache previously looked up names
// get link by name - have to scan links collection in IE
function getLinkNamed(name){
   d = document;
   if (linkName2Index[name] >= 0){  // already cached?
      return d.links[i];
   }
   for (i=d.links.length-1; i>=0; i--){  // reverse since usually care about nearby link
      if (typeof d.links[i].name != "undefined"){
         if (d.links[i].name == name){
            linkName2Index[d.links[i].name] = i;
            return d.links[i];
         }
      }
   }
   return null; // no such link
}
// copy href, target.  replace CT getvar
function cplink(from, to, ct) {
   fromLink = getLinkNamed(from);
   toLink = getLinkNamed(to);
   if (fromLink != null && toLink != null){
      ctidx = fromLink.href.lastIndexOf('&CT=');
      if (ctidx != -1) {
         toLink.href = fromLink.href.substring(0, ctidx+4) + ct;
      } else {
         toLink.href = fromLink.href;
      }
      toLink.target = fromLink.target;
      toLink.className = "";
   }
}

