//----------------------------------------------------------------------//
//									//
//  Name:  marytsattic.js						//
//									//
//  Purpose:								//
//	This file holds the JavaScript routines to run Mary T's Attic	//
//	web page.							//
//									//
//  Author(s):								//
//	David H. Flatman	DHF	david.flatman@iwvisp.com	//
//									//
//  History:								//
//	02-Aug-1999	DHF	Added double_view			//
//	27-Dec-1998	DHF	Added see_inventory			//
//	23-Dec-1998	DHF	File creation.				//
//									//
//	Copyright 1998, David H. Flatman				//
//									//
//----------------------------------------------------------------------//

var separator_field = "-";
var separator_open  = "X-";
var separator_close = "-Y";

//----------------------------------------------------------------------//
//  Name:  interest_add							//
//  Purpose:								//
//	Add the item to the interest list.				//
//----------------------------------------------------------------------//
function ia(item) {interest_add(item); return false}

function interest_add(item) {
    if (!version_script()) {return (false);}

    var inv_item = separator_open + item + separator_close;
    var inventory = parent.navbar.document.cur.inv.value;
    var add_it = 1;

    if (inventory.length > 0) {
	if (inventory.indexOf(inv_item) != -1) {
	    add_it = 0;
	}
    }

    if (add_it) {
	parent.navbar.document.cur.inv.value = inventory + inv_item;
	interest_display();
    }
    return true;
}

//----------------------------------------------------------------------//
//  Name:  interest_display						//
//  Purpose:								//
//	Display the interest list.					//
//----------------------------------------------------------------------//
function interest_display() {
    if (!version_script()) {return (false);}

    var inventory = parent.navbar.document.cur.inv.value;

    parent.interest.document.open();

    iw("<html><head>");
    iw("<base href='http://www1.iwvisp.com/flatman/ct/'>");
//    iw("<base href='file://e|/WebSite/Source/ct/'>");
    iw("<META http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.classify.org/safesurf/\" l gen true for \"http://www1.iwvisp.com/flatman/ct/\" r (SS~~000 1))'>");
    iw("<script src='marytsattic.js' type='text/javascript'></script>");
    iw("</head><body background='sidepanel.jpg'><center><b><font size=+2>");
    iw("<form name='cur' method='post' action='mailto:mary.flatman@iwvisp.com'>");
    iw("<input type=hidden name='inv' value='" + inventory + "'>");
    iw("Interest List</font></b><hr width='80%'>");

    if (inventory.length == 0) {
	iw("<center>Still Looking</center>");
    } else {
	iw("<table align='center' border=0 width='100%'>");

	var total = 0;

	while (inventory.length > 0) {
	    var offset = inventory.indexOf(separator_close);
	    var item = "";

	    item = inventory.substr(separator_open.length, offset-separator_close.length);
	    var item_save = item;

	    if (offset+separator_close.length < inventory.length) {
		inventory = inventory.substr(
		    offset+separator_close.length
		  , inventory.length);
	    } else {
		inventory = "";
	    }

	    //----------------------------------------------------------//
	    //  Break the item into various fields:			//
	    //	    name-registration-cost-condition			//
	    //----------------------------------------------------------//
	    var name = item.substr(0,item.indexOf(separator_field));
	    item = item.substr(item.indexOf(separator_field)+1, item.length);
	    item = item.substr(item.indexOf(separator_field)+1, item.length);
	    var cost = item.substr(2,item.indexOf(separator_field)-2);
	    var cond = item.substr(item.indexOf(separator_field)+1, item.length);

	    total = Number(total) + Number(cost);

	    iw("<tr><td><b>" + name + "</b><br><font size=-1>" + cond);
	    iw(" at $" + cost + "</font></td>");

	    if (navigator.appName == "Microsoft Internet Explorer") {
		iw("<td align='right'><a href='JavaScript:interest_display();'");
		iw(" onClick='JavaScript:ir(" + '"' + item_save + '"' + ");'>");
	    } else {
		iw("<td align='right'><a href='JavaScript:parent.main.interest_display();'");
		iw(" onClick='JavaScript:parent.main.ir(" + '"' + item_save + '"' + ");'>");
	    }
	    iw("<img src='nointer.gif' border=0 alt='remove from interest list'></a>");
	    iw("</td></tr><tr><td colspan='2'><hr width='80%'></td></tr>");
	} // while

	//--------------------------------------------------------------//
	//  Add in shipping and total.					//
	//--------------------------------------------------------------//
	total += 5;
	iw("<tr><td>Shipping in US:</td><td align='right'>$5</td></tr>");
	iw("<tr><td>Total:</td><td align='right'>$" + total + "</td></tr>");
	iw("</table><center>");
	iw("<input type=submit value='Send List'></center>");
    } // if 

    iw("</body></html>");
    parent.interest.document.close();
    return true;
}

//----------------------------------------------------------------------//
//  Name:  interst_remove						//
//  Purpose:								//
//	Remove the given item from the interest list.			//
//----------------------------------------------------------------------//
function ir(item) {interest_remove(item);}

function interest_remove(item) {
    if (!version_script()) {return (false);}

    var inventory = parent.navbar.document.cur.inv.value;
    var inv_item = separator_open + item + separator_close;
    if (inventory.length > 0) {
        var offset = inventory.indexOf(inv_item);
	if (offset != -1) {
	    var new_inv = inventory.substr(0, offset);
	    if (offset + inv_item.length < inventory.length) {
	        new_inv += inventory.substr(
		    offset+inv_item.length
		  , inventory.length
	        );
	    }
	    parent.navbar.document.cur.inv.value = new_inv;
	}
    }
    interest_display();
    return true;
}


//----------------------------------------------------------------------//
//  Name:  iw								//
//  Purpose:								//
//	Write the given item to the interest list.			//
//----------------------------------------------------------------------//
function iw(item) {
    parent.interest.document.writeln(item);
    return true;
}


//----------------------------------------------------------------------//
//  Name:  see_category							//
//  Purpose:								//
//	Display the given category ... in the appropriate panel 	//
//	depending on classic versus script driven version.		//
//----------------------------------------------------------------------//
function see_category(cat, side) {
    if (version_script()) { // pl.indexOf("ct_script.html") != -1) {
        parent.inventory.location = "cat_" + cat + ".html";
	return false;
    } else { // if (pl.indexOf("ct_classic.html") != -1) {
        parent.side.location = "sidepanel" + side + ".html";
	return true;
    }
    return true;
}


//----------------------------------------------------------------------//
//  Name:  see_inventory						//
//  Purpose:								//
//	Change the inventory to the given item.				//
//  Parameter(s):							//
//	item_name	The name of the item's anchor.			//
//	item_cat	The category of the item to return to.		//
//----------------------------------------------------------------------//
function see_inventory(item_name, item_cat) {
    if (version_script()) { // pl.indexOf("ct_script.html") != -1) {
        parent.inventory.location = "../cat_" + item_cat + ".html#" + item_name;
	return false;
    } else if (version_classic()) {
        parent.inventory.location = "../inventory.html#" + item_name;
	return true;
    } else {
        _top.location = "../inventory.html#" + item_name;
	return false;
    }
}


//----------------------------------------------------------------------//
//  Name:  see_maryts							//
//  Purpose:								//
//	Return the top level to Mary T's Attic.				//
//----------------------------------------------------------------------//
function see_maryts() {
    if (version_script() || version_classic()) {
        parent.main.location = "intro.html";
	return false;
    } else {
        _top.location = "../ct.html";
	return true;
    }
}

//----------------------------------------------------------------------//
//  Name:  mw								//
//  Purpose:								//
//	Write the given item to the main window.			//
//----------------------------------------------------------------------//
function mw(item) {
    parent.main.document.writeln(item);
    return true;
}


//----------------------------------------------------------------------//
//  Name:  double_view							//
//  Purpose:								//
//	View two pictures side by side with text below.			//
//----------------------------------------------------------------------//
function double_view(pic1,nam1,pic2,nam2,explan)
{
    parent.main.document.open();
    mw("<html><head>");
    mw("<base href='http://www1.iwvisp.com/flatman/ct/'>");
//    mw("<base href='file://e|/WebSite/Source/ct/'>");
    mw("<meta name='description' content=\"Mary T's Attic:  A Place for Quality Cherished Teddies\">");
    mw("<meta name=\"keywords\" content=\"cherished teddies, figurines, enesco, quality\">");
    mw("<title>Mary T's Attic:  A Place for Quality Cherished Teddies</title>");
    mw("</head><body background='sidepanel.jpg'>");
    mw("");
    mw("<table border=1 align='center'><tr>");
    mw("<td><img src=\"trivia.gif\"></td>");
    mw("<td align='center'><b>");
    mw("    <font size=+2><i><a href=\"http://www1.iwvisp.com/flatman/ct.html\" target=\"_top\">Mary T's Attic</a></i></font><br>");
    mw("    A Place for Quality Cherished Teddies<hr width='70%'>");
    mw("    <font size=+1>Variations</font>");
    mw("</b></td><td><img src=\"trivia.gif\"></td>");
    mw("</table><br>");
    mw("");
    mw("<center>");
    mw("<table align='center'>");
    mw("  <tr>");
    mw("    <td align='center'>");
    mw("      <table border='1'><tr><td>");
    mw("        <img src='"); mw(pic1); mw("'>");
    mw("      </td></tr></table>");
    mw("    </td>");
    mw("    <td>&nbsp;&nbsp;</td>");
    mw("    <td border='1' align='center'>");
    mw("      <table border='1'><tr><td>");
    mw("        <img src='"); mw(pic2); mw("'>");
    mw("      </td></tr></table>");
    mw("    </td>");
    mw("  </tr><tr>");
    mw("    <td align='center'>");
    mw("      <table border='1'><tr><td bgcolor='#C4DDFF'>");
    mw(nam1);
    mw("      </td></tr></table>");
    mw("    </td>");
    mw("    <td>&nbsp;&nbsp;</td>");
    mw("    <td border='1' align='center'>");
    mw("      <table border='1'><tr><td bgcolor='#C4DDFF'>");
    mw(nam2);
    mw("      </td></tr></table>");
    mw("    </td>");
    mw("  </tr>   ");
    mw("</table>");
    mw("</center>");
    mw("");
    mw("<p align='center'>" + explan);
    mw("");
    mw("<hr width='100%'> &copy; 1999, Mary Flatman.  All rights reserved.");
    mw("</body>");
    mw("</html>");
    parent.main.document.close();
}


//----------------------------------------------------------------------//
//  Name:  version_classic						//
//  Purpose:								//
//	Return TRUE if this is the classic version of the web site,	//
//	else return FALSE.						//
//----------------------------------------------------------------------//
function version_classic() {
    var pl;
    pl = " " + parent.location + " ";

    return(pl.indexOf("ct_classic.html") != -1);
}


//----------------------------------------------------------------------//
//  Name:  version_script						//
//  Purpose:								//
//	Return TRUE if this is the script version of the web site,	//
//	else return FALSE.						//
//----------------------------------------------------------------------//
function version_script() {
    var pl;
    pl = " " + parent.location + " ";

    return(pl.indexOf("ct.html") != -1);
}


function miranda_bottom()
{
    parent.double_view(
      "desc/MirandaPrototypeBottom_n.jpg","Original Prototype","desc/MirandaPrototypeRevisedBottom_n.jpg","Revised Prototype"
     ,'After seeing the prototype, Priscilla or someone within Enesco often decides that the prototype should be changed. The most common change consists of new paint colors. The figurine is revised and again marked with the new date, stock number and a "revised" sticker on the bottom.'
    );

    return(0);
}

function miranda_proto()
{
    parent.double_view(
      "desc/MirandaPrototype_n.jpg","Original Prototype","desc/MirandaPrototypeRevised_n.jpg","Revised Prototype"
     ,"The &quot;CT&quot; heart was removed from the foot, Miranda's fur was changed to be taupe and the little teddy bear's fur was changed to white."
    );

    return(0);
}


function mike_proto()
{
    parent.double_view(
      "desc/MikeProto_n.jpg","Mike Prototype","desc/Mike_n.jpg","Revised Prototype"
     ,'The balloon color was changed from yellow to pink.'
    );

    return(0);
}


