// disable right click 
// from www.dyn-web.com
/*
var clickmessage="For more information on these images, please contact John Rindlaub. Thank you!"

function disableclick(e) {
  e = e? e: window.event;
  var btn = e.button? e.button: e.which;
  if ( btn==2 || btn==3 ) {
   alert(clickmessage);
    return false;
  }
}

if (document.layers) document.captureEvents(Event.MOUSEDOWN);
if (!document.addEventListener)	document.onmousedown = disableclick;
if (document.addEventListener) document.addEventListener("mouseup",disableclick,false);
document.oncontextmenu = new Function( "return false;" );


*/







//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design under the GPL.  You must keep this comment ||
// unchanged in your code.  For more information contact               ||
// Scott@NopDesign.com                                                 ||
//                                                                     ||
// JavaScript Shop Module, V.4.1.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
   iNumberOrdered = 0;
   iNumberOrdered = GetCookie("NumberOrdered");
   iNumberOrdered++;

   if ( iNumberOrdered > 12 )
      alert("I'm Sorry, your cart is full, please proceed to checkout.");
   else {
     if ( thisForm.ID_NUM == null )
         strID_NUM    = "";
      else
         strID_NUM    = thisForm.ID_NUM.value;
      
      if ( thisForm.QUANTITY == null )
         strQUANTITY  = "1";
      else
         strQUANTITY  = thisForm.QUANTITY.value;
        
        
        
        
        
        
        //This sets the prices for the Photo Section
          
        
     if ( thisForm.ADDITIONALINFO == null )
         strPRICE     = "0.00";
         else 
      		if 
      			( thisForm.ADDITIONALINFO.selectedIndex == 0 )
      		strPRICE = "13.00";
      		
      			else 
      		if 
      			( thisForm.ADDITIONALINFO.selectedIndex == 1 )
      		strPRICE = "23.20";

      			else			
      		if 
      			( thisForm.ADDITIONALINFO.selectedIndex == 2 )
      		strPRICE = "32.48";
      		
      	;
      
      if ( thisForm.NAME == null )
         strNAME      = "";
      else
         strNAME      = thisForm.NAME.value;










//This sets the frame options and prices for the woodcuts

	
	if ( thisForm.FRAMEOPT == null )
        	 strFRAMEOPT  = "Matted";
    
      else 
     		if 
      			( thisForm.FRAMEOPT.selectedIndex == 0 )
      		strFRAMEOPT = "Framed";
      	
      else 
      		if 
      			( thisForm.FRAMEOPT.selectedIndex == 1 )
      		strFRAMEOPT = "Matted";
      else			
      		if 
      			( thisForm.FRAMEOPT.selectedIndex == 2 )
      		strFRAMEOPT = "Art Only";
      		
      		//alert(strFRAMEOPT)
      	
     if ( thisForm.FRAMEOPT == null )
        	 strPRICE  = strPRICE;
        
      else
      	
     		if
      			( thisForm.FRAMEOPT.selectedIndex == 0 )
      		strPRICE = thisForm.FRAMEOPT.value;
      else 
      		if 
      			( thisForm.FRAMEOPT.selectedIndex == 1 )
      		strPRICE = thisForm.FRAMEOPT.value;
      else			
      		if 
      			( thisForm.FRAMEOPT.selectedIndex == 2 )
      		strPRICE = thisForm.FRAMEOPT.value;	
      			
      			
      		
        
//JBR comment: Here is where I made it calculate the 15% shipping automatically    
      
        if ( thisForm.SHIPPING.value == null )
         strSHIPPING  = "0.00";
      else 
      		if 
      			(thisForm.SHIPPING.value == 1 ) 
         		strSHIPPING  = ((strPRICE) * 0.15);
      else
      		if 
      			(thisForm.SHIPPING.value == 2 ) 
         		strSHIPPING  = ((strPRICE) * 0.1);
      else 
      		if 
      			(thisForm.SHIPPING.value == 3 ) 
       			strSHIPPING  = ((strPRICE) * 0.05);
      
      
      
      
 
      if ( thisForm.ADDITIONALINFO == null )
         strADDTLINFO = "";
         
      else
         strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
       
      

      dbUpdatedOrder = strID_NUM    + "|" + 
                       strQUANTITY  + "|" +
                       strPRICE     + "|" +
                       strNAME      + "|" +
                       strSHIPPING  + "|" +
                       strFRAMEOPT  + "|" +
                       strADDTLINFO;

      strNewOrder = "Order." + iNumberOrdered;
      SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
      SetCookie("NumberOrdered", iNumberOrdered, null, "/");
      
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
   if ( confirm("Click 'Ok' to remove this product from your shopping cart.") ) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");
      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
      DeleteCookie(NewOrder, "/");
      location.href=location.href;
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    GetFromCart                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
if( fShipping )
      WriteToForm( true, fShipping );
   else
      WriteToForm( true, 0 );
}
//JBR comment: GetFrom Cart is the one that sucks all thie info onto the html page
//Apparantly WriteToForm is just called by GetFromCart...

//---------------------------------------------------------------------||
// FUNCTION:    WriteToForm                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product hidden fields Written to Document              ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function WriteToForm( bDisplay, fShipping ) {
   iNumberOrdered = 0;
   fTotal         = 0;
   strTotal       = "";
   strShipping    = "";
   strOutput      = "";
   
//JBR comment: here is where the California state sales tax is set
   catax          = 0.0875;
  
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( bDisplay )
      strOutput = "<p style=\"margin-left: 5px\"><table border=0 class=\"nopcart\" cellpadding=6><tr>" +
                  "<th class=\"nopheader\"><b>Title</b></th>" +
                  "<th class=\"nopheader\"><b>Frame Options</b></th>" +
                  "<th class=\"nopheader\"><b>Quantity</b></th>" +
                  "<th class=\"nopheader\"><b>Price</b></th>" +
                  "<th class=\"nopheader\"><b>Shipping</b></th>" +
                  "<th class=\"nopheader\"><b>Remove From Cart</b></th></tr><tr>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);
      Token5 = database.indexOf("|", Token4+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, Token5 );
      fields[6] = database.substring( Token5+1, database.length );

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      strTotal    = moneyFormat(fTotal);
      strShipping = moneyFormat(fShipping);

// JBR comment:   The ID_NUM field ([0]), is not presently in use
//---fields [1] = Quantity, [2] = price, [3] = name, [4] = shipping, [5] = framing options, [6] = additional info 

      if ( bDisplay ) {

        if ( fields[6] == "" )
            strOutput += "<tr class=\"nop-gray\"><td class=\"title\">"  + fields[3] + "</td>";
         else  
            strOutput += "<tr class=\"nop-gray\"><td class=\"title\">"  + fields[3] + " - <i>"+ fields[6] + "</i></td>";

         	strOutput += "<td class=\"nopentry\">"   + fields[5]  + "</td>" ;

         	strOutput += "<td class=\"nopentry\">"   + fields[1]  + "</td>" ;
         
         if ( parseFloat(fields[2]) > 0 )
         	strOutput += "<td class=\"nopentry\">$" + moneyFormat(fields[2]) + "/ea</td>";
		 else
            strOutput += "<td class=\"nopentry\">N/A</td>";
            
         if ( parseFloat(fields[4]) > 0 )
            strOutput += "<td class=\"nopentry\">$" + moneyFormat(fields[4]) + "/ea</td>";
         else
            strOutput += "<td class=\"nopentry\">N/A</td>";
            

         	strOutput += "<td class=\"nopentry\"><input type=\"button\" value=\"  Remove  \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"></td><td>&nbsp;</td></tr>";
		 
		 
		 
      }

			
      strOutput += "<tr><td style=\"border-bottom-style: none;\"><img src=\"images/dot.gif\" width=\"240\" height=\"1\" alt=\"spacer image\"><input type=\"hidden\" name=\"QUANTITY_" + i + "\" value=\"" + fields[1] + "\"></td>";
      strOutput += "<td style=\"border-bottom-style: none;\"><input type=\"hidden\" name=\"PRICE_"    + i + "\" value=\"" + fields[2] + "\"></td>";
      strOutput += "<td style=\"border-bottom-style: none;\"><input type=\"hidden\" name=\"NAME_"     + i + "\" value=\"" + fields[3] + "\"></td>";
      strOutput += "<td style=\"border-bottom-style: none;\"><img src=\"images/dot.gif\" width=\"69\" height=\"1\" alt=\"spacer image\"><input type=\"hidden\" name=\"SHIPPING_" + i + "\" value=\"" + fields[4] + "\"></td>";
      strOutput += "<td style=\"border-bottom-style: none;\"><input type=\"hidden\" name=\"FRAMEOPT"  + i + "\" value=\"" + fields[5] + "\"></td>";
      strOutput += "<td style=\"border-bottom-style: none;\"><input type=\"hidden\" name=\"ADDTLINFO_"+ i + "\" value=\'" + fields[6] + "\'></td><td></td></tr>";
   }
 
   if ( bDisplay ) 
   			if ( i > 2 )  {  
   			//alert("the if clause\; value of var i = " + i );
	      strOutput += "<tr class=\"nop-gray\"><td class=\"noptotal\" COLSPAN='3'><b>Subtotal</b></td>";
	      strOutput += "<td align='right'><b>$" + moneyFormat(strTotal) + "&nbsp;&nbsp;</b></td><td colspan='3'>&nbsp;</td>";
	      strOutput += "</tr>";
	      strOutput += "<tr><td COLSPAN='3'><b>Subtotal of shipping charges</b></td>";
	      strOutput += "<td>&nbsp;</td><td align='right'><b>$" + moneyFormat(strShipping) + "&nbsp;&nbsp;</b></td><td>&nbsp;</td><td>&nbsp;</td>";
	      strOutput += "</tr>";	    	strOutput += "<tr class=\"nop-gray\"><td COLSPAN='5'>&nbsp;<b>Total</b></td>";
	      strOutput += "<td align='right'><b>$" + moneyFormat((fTotal + fShipping)) + "&nbsp;</b></td><td>&nbsp;</td>";
	      strOutput += "</tr>";   strOutput += "</table>";
		  strOutput += "<input type=\"hidden\" name=\"SUBTOTAL\" value=\"$" + strTotal + "\">";
  		  strOutput += "<input type=\"hidden\" name=\"SHIPPING\" value=\"$" + strShipping + "\">";
  		  strOutput += "<input type=\"hidden\" name=\"TOTAL\"    value=\"$" + moneyFormat((fTotal + fShipping)) + "\">";     
		} else {//alert(" the 'else' clause\; value of  var i =  " + i);
      strOutput += "<tr class=\"nop-gray\"><td COLSPAN='5'>&nbsp;<b>Total</b></td>";
      strOutput += "<td align='right'><b>$" + moneyFormat((fTotal + fShipping)) + "&nbsp;</b></td><td>&nbsp;</td>";

      strOutput += "</tr>";
      
   /*   strOutput += "<tr class='ca-tax'><td COLSPAN='5'>Add CA Sales Tax, if applicable</td>";
      strOutput += "<td align='right'>$" + moneyFormat((strTotal * catax)) + "&nbsp;</td><td>&nbsp;</td>";
      strOutput += "<tr class='ca-totals'><td COLSPAN='5'>CA Total</td>";
      strOutput += "<td align='right'>$"+ moneyFormat((fTotal + fShipping) + (strTotal * catax)) + "&nbsp;</td><td>&nbsp;</td>";
	 
	  
	  */
      strOutput += "</tr>";
      strOutput += "</table>";

      strOutput += "<input type=\"hidden\" name=\"SUBTOTAL\" value=\"$" + strTotal + "\">";
      strOutput += "<input type=\"hidden\" name=\"SHIPPING\" value=\"$" + strShipping + "\">";
      strOutput += "<input type=\"hidden\" name=\"TOTAL\"    value=\"$" + moneyFormat((fTotal + fShipping)) + "\">"; 
   }

   document.write(strOutput);
   document.close();
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//                              V.4.0.0                                ||
//=====================================================================||



