/*
 * Adorable Doll Clothes
 * Copyright (c)2002
 * Written By Steve Duncan
 *
 * This javascript builds a product page and has support for Pay Pal.
 * this buildpage is special for home page only.
 *
 */


var i;


//the product object constructor
function product(description, number, size, price)
{
  this.description = description;
  this.number = number;
  this.size = size;
  this.price = price;
  return this;
}


function buildPage()
{
document.write("<TITLE>"+myTitle+windowTitle+"</TITLE>");
window.status="Adorable Doll Clothes"+windowTitle;

document.write("<table border='0' cellspacing='4' cellpadding='10' style='border-collapse: collapse' bordercolor='#111111' width='738'>");
document.write("  <tr>");

// display doll picture
document.write("    <td bgcolor='#FFF2F9' width='247'>");
document.write("      <p align='center'>");
document.write("      <img src=gifs/"+myPic+" alt='"+myTitle+windowTitle+"' border='1'>");
document.write("      <b><font face='Palatino Linotype' color='#0000FF'>"+myPicSize+"</font></b></p>");
document.write("    </td>");

// display subtitle
document.write("    <td valign='top' bgcolor='#FFF2F9' width='439'>");
document.write("      <table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' id='AutoNumber4' height='46' width='440'>");
document.write("        <tr>");
document.write("          <td width='439' height='46'>");
document.write("          <p align='center'>");
document.write("          <font color='#FF0080' face='Palatino Linotype' size='5'><b>" +myTitle+"</b></font></td>");
document.write("        </tr>");
document.write("      </table>");
//document.write("  </td>");

// display description paragraph
document.write("    <table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' id='AutoNumber2' width='440'>");
document.write("      <tr>");
document.write("        <td width='437' align='justify'><font color='#FF0080' face='Palatino Linotype'>"); 
document.write("          <B>"+myDescription+"</B></font><BR><BR></td>");
document.write("      </tr>");
document.write("    </table>");

// display Description, ItemNumber, Size, Price, Order Table
document.write("    <table border='1' cellpadding='1' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='440' id='AutoNumber1' height='64'>"); 
document.write("       <tr>");
document.write("          <td width='160' align='center' bgcolor='#FF0080' height='36'>");
document.write("            <font color='#FFFFFF' face='Palatino Linotype'><b>Description</b></font></td>");
document.write("          <td width='63' align='center' bgcolor='#FF0080' align='center' height='36'>");
document.write("            <font color='#FFFFFF' face='Palatino Linotype' size='2'><b>&nbsp;Item Number</b></font></td>");
document.write("          <td width='70' align='center' bgcolor='#FF0080' align='center' height='36'>");
document.write("            <font color='#FFFFFF' face='Palatino Linotype'><b>Size</b></font></td>");
document.write("          <td width='70' align='center' bgcolor='#FF0080' height='36'>");
document.write("            <font color='#FFFFFF' face='Palatino Linotype'><b>Price</b></font></td>");
document.write("          <td  align='center'bgcolor='#FF0080' height='36'>");
document.write("            <font color='#FFFFFF' face='Palatino Linotype'><b>Order</b></font></td>");
document.write("       </tr>");


// display item information in the table
for (i=0; item[i] != null;i++)
  displayItemInfo(item[i]);

/*
//start Express shipping cost adder
this.description="Express Delivery";
this.number = "EXPRESS";
this.size = "Two Days";
this.price = "$10.00";
document.write("          <tr>");
document.write("          <td width='160' align='left' bgcolor='#FFF2F9' height='36'>");
document.write("          <b><font face='Palatino Linotype' color='#FF0080'>"+this.description+"</b></font></td>");
document.write("          <td width='63' align='center' bgcolor='#FFF2F9' align='center' height='36'>");
document.write("              <font size='2' color='#FF0080'><b>"+this.number+"</b></font></td>");
document.write("          <td width='70' align='center' bgcolor='#FFF2F9' align='center' height='36'>");
document.write("              <font size='2' color='#FF0080'><b>"+this.size+"</b></font></td>");
document.write("          <td width='70' align='center' bgcolor='#FFF2F9' height='36'>");
document.write("              <p align='center'><b><font color='#FF0080'>"+this.price+"</font></b></td>");														
document.write("            <td width='160' align='left' height='24'><b>");
document.write("              <a href=javascript:PayPalAddToCartPopUp('"+escape(this.description)+"','"+escape(this.size)+"','"+escape(this.number)+"','"+escape(this.price)+"');>");
document.write("              <img src='../gifs/usps.gif' border='0' alt='Add Express Mail Delivery for guaranteed two-day service.' align='middle' width='92' height='24'></a>");
document.write("            </td>");
document.write("          </tr>");
//end Express shipping cost adder
*/


document.write("    </table>");


// display the ViewCart, OrderForm and Home buttons
document.write("    <table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' id='AutoNumber3'>");
document.write("      <tr>");
document.write("        <td align='center'>");
document.write("          <br clear='all'>");

//document.write("          <a href='https://www.paypal.com/cart/display=1&business=adc1140%40charter.net'>");
document.write("          <a href=javascript:PayPalViewCartPopUp();>");
document.write("          <img src='gifs/viewCart.gif' border = '0' alt='Click here to view your shopping cart contents.' align='middle' width='92' height='24'></a>");

document.write("          <a href='http://www.AdorableDollClothes.com'>");
document.write("          <img src='gifs/home.gif'  border = '0' alt='Click here to return to AdorableDollClothes.com.' align='middle' width='92' height='24'></a></td>");

document.write("      </tr>");
document.write("    </table>");

document.write("  </tr>");
document.write("</table>");

document.write("<br><br><br>"); 	/* seperate banner ads from our content */
}


function displayItemInfo(item)
{
document.write("          <tr>");
document.write("            <td width='160' align='left' height='24'><b>");
document.write("              <table border='0' cellpadding='1' cellspacing='0' bordercolor='#111111' width='160' height='24'>"); 
document.write("                <td><b><font face='Palatino Linotype' color='#FF0080'>"+item.description+"</b></font></td>");
document.write("              </table></td>");
document.write("            <td width='63' align='center' height='24'>");
document.write("              <font size='2' color='#FF0080'><b>"+item.number+"</b></font></td>");
document.write("            <td width='70' align='center' height='24'>");
document.write("              <p align='center'><font color='#FF0080'><b>"+item.size+"</b></font></td>");
document.write("            <td width='70' align='right' height='24'>");
document.write("              <p align='center'><b><font color='#FF0080'>"+item.price+"</font></b></td>");
document.write("            <td  height='24'><p>");

//the next line of code jumps to paypals url, not what you really wanna do.
//document.write("            <a href='https://www.paypal.com/cart/add=1&business=adc1140%40charter.net&item_name="+item.description+" ("+item.size+")&item_number="+item.number+"&amount="+item.price+"'>");

//if you pass a passed string you better escape() it!!!!!!!

//if the item is sold out then set the item.number to zero and don't display an order button.
if (item.number != 0)
{
  document.write("              <a href=javascript:PayPalAddToCartPopUp('"+escape(item.description)+"','"+escape(item.size)+"','"+escape(item.number)+"','"+escape(item.price)+"');>");
  document.write("              <img src='gifs/addtocart.gif' border='0' alt='Click here to add this item to your shopping cart.' align='middle' width='92' height='24'></a>");
}
else
{
  document.write("               SOLD OUT");
}

document.write("            </td>");
document.write("          </tr>");

}



//this function pops up the paypal Add to Cart window
//this function does not like single quotes included in the strings it is passed.
//this function pops up the paypal Add to Cart window
//this function does not like single quotes included in the strings it is passed.
function PayPalAddToCartPopUp(description, size, number, price) 
{
    // this worked before paypals upgrade - 8/23/09
    //var paypal = "https://www.paypal.com/cart/add=1";
    
    // change for paypal upgrade!
    var paypal = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&add=1";    
	
	var adc = "&business=info%40adorabledollclothes.com";	
	var itemDescription = "&item_name="+description+" ("+size+")";
	var itemNumber = "&item_number="+number;
	var itemAmount = "&amount="+price;
	//window.open(paypal+adc+itemDescription+itemNumber+itemAmount,"cartwin","toolbar=no, scrollbars=yes, resizable=yes");
	popitup(paypal+adc+itemDescription+itemNumber+itemAmount,"cartwin","toolbar=no, scrollbars=yes, resizable=yes");
}


//this function pops up the paypal view cart window
function PayPalViewCartPopUp() 
{
    // this worked before paypals upgrade - 8/23/09 
    //var paypal = "https://www.paypal.com/cart/display=1";

    // change for paypal upgrade!
    var paypal = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&display=1";
	
	var adc = "&business=info%40adorabledollclothes.com";	
	//window.open(paypal+adc,"cartwin","toolbar=no, scrollbars=yes, resizable=yes");
	popitup(paypal+adc,"cartwin","toolbar=no, scrollbars=yes, resizable=yes");
}


var newwindow="";
function popitup(url)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,'name',"toolbar=no, scrollbars=yes, resizable=yes");
		if (!newwindow.opener) newwindow.opener = self;

	}
	if (window.focus) {newwindow.focus()}

  return false;
} 



function setCookie(name,value)
{
  var expires = new Date();
  expires.setTime(expires.getTime()+24*60*60*30*1000);
  var expiryDate = expires.toGMTString();
  document.cookie= name + "=" + value + "; expires=" + expiryDate;
}

function getCookie(name)
{
  var cookieFound = false;
  var start=0;
  var end=0;
  var cookieString = document.cookie;

  var i=0;
  //scan for the cookie name
  while(i<=cookieString.length)
  {
    start=i;
    end=start + name.length;
    if (cookieString.substring(start,end) == name)
    {
      cookieFound=true;
      break;
    }
    i++;
  }
  if (cookieFound)
  {
    start = end+1;
    end = document.cookie.indexOf(";",start);
    if (end < start)
      end = document.cookie.length;
    return document.cookie.substring(start,end);
  }
  return "";  
}
