/***
*  Copyright 2004-2005 Glass Dimensions, Inc.
*  All rights reserved.
*
*  BE SURE TO CHANGE THE ITEM PRICING TAB TO BE (MSRP * .7) FOR COLLECTORS CLUB
*  AND (MSRP * .5) for Wholesale EndUser
*
*  When setting up the item of the month, there is one change necessary to this
*  file (pricing.js): set item_of_the_month equal to the appropriate item id in quotes.
*
*  See collectorsclub.html comments for all necessary changes to that file
*  when setting up the item of the month.
*/

var design_of_the_month = "3058";

var GDCC_standard_discount = 15;
var GDCC_item_of_the_month_discount = 30;

var ISA_standard_discount = 40;
var ISA_item_of_the_month_discount = 50;

function ShippingCalculator(){

  popup = window.open('http://glassdimensions.com/site/shipcalc.html','shipcalc','width=600,height=290');
  popup.focus();

}
var winnum = 1;
function Popup(p,w,h){

  //
  // The second arg to window.open MUST NOT contain any spaces
  // or you get an invalid argument javascript error from at least IE 6
  // 
  // tack on the value of the global 'winnum' counter to get a new 
  // window each time. 
  //
  var winname = "popup" + winnum;
  winnum += 1;
  var popup = window.open('http://shop.glassdimensions.com/'+p,winname,'width='+w+',height='+h+'resizable=yes,scrollbars=yes');
 
  popup.focus();

}

function zoom(item,image){

  //
  // The second arg to window.open MUST NOT contain any spaces
  // or you get an invalid argument javascript error from at least IE 6
  // 
  // tack on the value of the global 'winnum' counter to get a new 
  // window each time. 
  //
  var winname = "zoom" + winnum;
  winnum += 1;  
  popup = window.open('',winname,'width=600,height=500,resizable=yes,scrollbars=yes');
  
  open_header = '<html><head><title>Glass Dimensions - ' + item + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>';
  close_header = '<style>img{border-width:1px;border-color:#ccc;}</style></head>';
  body = '<body bgcolor="#666666"><table width="100%" style="margin-top:25px;"><tr><td align="center">';
  body += '<img src="http://glassdimensions.com' + image + '" alt="' + item + '" />';
  footer = '</td></tr></table></body></html>';

  popup.document.open("text/html", "replace");
  popup.document.write(open_header+close_header+body+footer);
  popup.document.close();
}


function Hide(tag,content){
  var gdi = 0;
  gdi = location.hostname.search(/glassdimensions/gi) != -1;
  
  if(gdi && content=="nl"){
    document.writeln(tag);
  }
  else if(!gdi && content=="gdi"){
    document.writeln(tag);
  }
}

function discountPercent(pricelevel,itemid)
{
    var discPercent = 0;
        
    switch(pricelevel){
      case "3 - ISA":
          if ( itemid == design_of_the_month ) discPercent = ISA_item_of_the_month_discount;
          else discPercent = ISA_standard_discount;
          break;
      case "4 - Collectors Club":
          if ( itemid == design_of_the_month ) discPercent = GDCC_item_of_the_month_discount;
          else discPercent = GDCC_standard_discount;          
          break;
      case "2 - Wholesale":
          discPercent = -1;          
          break;
      default : 
          discPercent = 0;
          break;
    }
   
	return discPercent;
}

function retailPricing(discPercent,strPrice)
{
    var floatPrice = parseFloat(strPrice);

	if(discPercent != 0 )
	  floatPrice = floatPrice * 100 / (100-discPercent);

  	return "$ " + floatPrice.toFixed(2);
}


function CollectorsClubPricing(d,sp,pl)
{
    var special_offer_ends = '<p style="font-size:8pt;font-weight:bold;">Offer ends June 30, 2004</p>';
    var login = '<p style="font-size:10pt;"><a style="color:#f00;" href="http://glassdimensions.com/checkout">Login</a> to view member pricing.' + '</p>';
    var join_today ='<p style="font-size:8pt;"><a style="color:#f00;" href="http://glassdimensions.com/join">Join</a> today and receive '+ GDCC_item_of_the_month_discount + ' % off the list price!' + '</p>' + special_offer_ends;
        
    var regularPrice = "";
    var yourPrice = "";


	sp = sp.replace("$","");
    var	dp = discountPercent(pl,d);
    var rp = retailPricing(dp,sp);
    sp = "$ " + sp;

    if(dp > 0){
        regularPrice = '<p style="font-weight:bold;font-size:8pt;">Design: <span style="font-weight:normal;">' + d + '</span>&nbsp;&nbsp;Regular Price: <span style="font-weight:normal;"> ' + rp + '</span></p><hr width="75%" />';
        yourPrice = '<p style="font-weight:bold;color:#ccf;">Your Price This Month: <span style="font-weight:normal;"> ' + sp + '</span></p>';
        document.write(regularPrice + yourPrice);
        //document.write( special_offer_ends );
    }
    
    //
    // Uncomment this 'else if' when 
    // Collectors Club tab is made public . . .
    // Be sure to add a Collectors Club item that when purchased
    // gives a customer member status.  Also, define a promotional url
    // http://glassdimensions.com/join.
    //
    //else if( pricelevel.search("MSRP")!= -1 )
    //{
    // document.write(join_today);
    //}
    
    // handles wholesale
    else if(dp==-1)
    {
    	regularPrice = '<p style="font-weight:bold;font-size:8pt;color:#404040;">Design: <span style="font-weight:normal;">' + d + '</span>&nbsp;&nbsp;Regular Price: <span style="font-weight:normal;"> ' + rp + '</span></p><hr width="75%" />';
        document.write(regularPrice);
    }

    else
    {
    	regularPrice = '<p style="font-weight:bold;font-size:8pt;color:#404040;">Design: <span style="font-weight:normal;">' + d + '</span>&nbsp;&nbsp;Regular Price: <span style="font-weight:normal;"> ' + rp + '</span></p><hr width="75%" />';
        document.write(regularPrice + login);
    }
}

function itemTemplatePricing(d,sp,pl)
{
	sp = sp.replace("$","");
	dp = discountPercent(pl,d);
    rp = retailPricing(dp,sp);
    sp = "$ " + sp;
    var designPrice = '<strong>Design: </strong>' + d + '&nbsp;&nbsp;<strong>Regular Price:</strong> ' + rp;
    var cc1 = '<p style="text-align:left;font-size:12pt;color:#ccf;font-variant:small-caps;"><strong>Design of the Month</strong><br /><span style="font-variant:normal;text-align:center;font-size:8pt;color:#ccc;">' + designPrice + '</span></p>';
    var cc2 = '<p style="color:#ccf;"><strong>Your Price This Month:</strong> ' + sp + '</p>';
    
	if(dp > 0 && d == design_of_the_month)
		document.write(cc1 + cc2);
	
	else if(dp > 0 && d != design_of_the_month)
    	document.write('<p>' + designPrice + '</p><p><strong>Your Price:</strong> ' + sp + '</p>');
    else
    	document.write('<p><strong>Design: </strong>' + d + '&nbsp;&nbsp;<strong>Price: </strong>' + sp + '</p>');
}

function DonationMessage(page,subtotal,org){
  var don = 0;

  if( org == "" )
    org = location.search;

  if(org.search(/P10059/gi)!=-1){
    don = 10;
    org = "Charlestown Mother's Association";
  }
  else if(org.search(/V1232/gi)!=-1){
    don = 20;
    org = "Rhode Island Hospital Guild";
  }

  if(page.match(/welcome/gi) && don > 0){
    document.write("\<p style='font-style:italic;font-size:10pt;color:ccf;text-align:center;font-weight:normal;'\>Glass Dimensions will donate\<br\>\<span style='font-style:normal;font-weight:bold;font-size:8pt;'\>" + don + "% to the " + org + "\</span\>\<br\>for every purchase you make!\</p\>");
  }
  else if(page.match(/checkout/gi)){
      document.write("\<p style='padding-right:10px;font-size:10pt;font-weight:bold;font-style:italic;color:#ffc;text-align:right;'\>After you click the 'Submit Order' button,");
    if( don > 0 ){
      donAmt = subtotal*(don/100);
      document.write("\<br\>Glass Dimensions will donate $" + donAmt.toFixed(2) + " to the \<br\>" + org + " and ");
    }

    document.write("\<br\>you will receive a confirmation email.\</p\>");
  }

}

function gdi_design_group_onsubmit(){
  var size = document.getElementById("gdi_design_size").value;
  if(size != "0"){
    document.getElementById('buyid').value = size;
    return ns_onsubmit();
  }
  else{
    alert("Please indicate your selection to be added to the cart.");
    return 0;
  }
}

function gdi_design_group_init(){

  // this init function is currently only relevant 
  // to the gdi_design_group pages which will have
  // a global variable gdi_design_group defined
  // prior to the inclusion of this group.js file...
  // If not, let's get out of here!

  // if(window.console) {
  //		window.console.log("init function."+typeof(gdi_design_group))
  //	} 
  //	else {
  //	  alert("typeof(gdi_design_group))
  //	}


  if(typeof(gdi_design_group) == 'undefined'){
    return;
  }

  // Netsuite's convention is to craft the 'add to 
  // cart' form name by combining 'form' and the
  // internalid of the particular design.  This
  // script depends on this convention, so, we
  // should keep an eye on this. 

  var ns_form_name = "form" + gdi_design_group;

  // For ornaments (internalid is 676), we simply
  // need to set the engraving option to the 
  // appropriate value based on the buypage category.

  if(typeof(gdi_buypage_cat) != 'undefined'){
    if(gdi_buypage_cat=="teacher"){
      document.forms[ns_form_name].elements["custcolornament_engraving"].value=22;
    }

    return;
  }

  // In order to insert our check for the selection 
  // of design size, it's necessary to swap in our
  // own onSubmit handler for the netsuite 'add to cart' 
  // form and save the netsuite onSubmit handler to
  // be called after we do our checking.
  // 

  ns_onsubmit = document.forms[ns_form_name].onsubmit;
  document.forms[ns_form_name].onsubmit = gdi_design_group_onsubmit;
}






