﻿function WhatIsChecked()
{
    var importance = document.getElementsByName('importance');
    for (var i = 0; i < importance.length; i++)
        if (importance[i].checked)
            importance[i].onclick();
}

function HideList(arrList)
{
    for (var i = 0; i < arrList.length; i++)
    {
        var node = document.getElementById(arrList[i]);
        var note = document.getElementById(arrList[i] + 'Note');

        if (node) node.style.display = 'none';
        if (note) note.style.display = 'none';                
    }
}

function ShowList(arrList)
{
    for (var i = 0; i < arrList.length; i++)
    {
        var node = document.getElementById(arrList[i]);
        var note = document.getElementById(arrList[i] + 'Note');

        if (node) node.style.display = '';
        if (note) note.style.display = '';
    }
}

function ShowOneList(arrList)
{
    HideList(Low);
    HideList(Medium);
    HideList(Essential);
    ShowList(arrList);
}

function SwapById()
{
    var args = SwapById.arguments;
    for (var i = 0; i < args.length; i++) {
        var element = document.getElementById(args[i])
        element.style.display = element.style.display == 'none' ? '' : 'none';
    }
}

function SwapByClass()
{
    var args = SwapByClass.arguments;
    var elements = elements = document.all ? document.all : document.getElementsByTagName('*');

    for(var i = 0; i < elements.length; i++) {
	    var node = elements.item(i);
	    if (node.attributes) {
	        for(var j = 0; j < node.attributes.length; j++) {
		        if(node.attributes.item(j).nodeName == 'class') {
		            for (var c = 0; c < args.length; c++) {
			            if(node.attributes.item(j).nodeValue == args[c]) {
				            node.style.display = node.style.display == 'none' ? '' : 'none';
				            break;
			            }
			        }
			        break;
		        }
	        }
	    }
    }
}

function OnlyHideByClass()
{
    var allClass = ['note', 'intro', 'title', 'author', 'edition', 'dontownit']; //this is the list of all possible classes for showing or hiding
    var args = OnlyHideByClass.arguments;
    var elements = elements = document.all ? document.all : document.getElementsByTagName('*');

    for(var i = 0; i < elements.length; i++) {
	    var node = elements.item(i);
	    if (node.attributes) {
	        for(var j = 0; j < node.attributes.length; j++) {
		        if(node.attributes.item(j).nodeName == 'class') {
		            for (var c = 0; c < allClass.length; c++) {
			            if(node.attributes.item(j).nodeValue == allClass[c]) {
				            node.style.display = '';
				            break;
			            }
			        }
		            for (var c = 0; c < args.length; c++) {
			            if(node.attributes.item(j).nodeValue == args[c]) {
				            node.style.display = 'none';
				            break;
			            }
			        }
			        break;
		        }
	        }
	    }
    }
}

var pvid = "";

function LoadOmakase(AssociateID)
{
	var Omakase = document.getElementById('OmakaseDiv');
	if (Omakase)
	{
		var Content = document.getElementById('ContentDiv');
		var width = 160;
		var height = 600;
		
		if (pvid == "")
		{
			var $h2d = "0123456789ABCDEF";
			for(i = 0; i < 16; i++)
				pvid += $h2d.charAt(Math.floor( 16 * Math.random() ));
		}

		while (Omakase.offsetHeight + height + 260 < Content.offsetHeight)
		{
			var iframe = document.createElement('iframe');
			iframe.setAttribute('marginwidth', 0);
			iframe.setAttribute('marginheight', 0);
			iframe.setAttribute('broder', 0);
			iframe.setAttribute('frameborder', 0);
			iframe.setAttribute('scrolling', 'no');
			iframe.setAttribute('height', height + 10);
			iframe.setAttribute('width', width);
			iframe.style.border = 'none';
			iframe.style.paddingTop = '250px';
			//iframe.style.paddingBottom = '150px';
			iframe.style.marginLeft = '-10px';
			iframe.setAttribute('src', 'http://rcm.amazon.com/e/cm?t=' + AssociateID + '&o=1&p=14&l=op1&pvid=' + pvid + '&ref-url=' + escape(document.location) + '&bgc=FFFFFF&bdc=FFFFFF&pcc=990000&tec=000000&tic=3399FF&ac=CC6600&mp=1&hb=1&hl=1&f=ifr');
			Omakase.appendChild(iframe);
		}
		while (Omakase.offsetHeight >= Content.offsetHeight)
			Omakase.removeChild(Omakase.childNodes[Omakase.childNodes.length-1]);
			
		setTimeout('LoadOmakase("' + AssociateID + '");', 1000); //for when the page is resized or selections are changed
		}
}

