﻿    /* Declare Global Variables */ 
var FULLSIZE_PATH = ""; 
var DEFAULT_WIDTH = 450; 
var DEFAULT_HEIGHT = 600; 
var DEFAULT_CAPTION = ""; 
var DEFAULT_WINDOW_NAME = "enlg_viewer"; 
var DEFAULT_WINDOW_PATH = "imgpopup.htm"; 

/* 
   Function Name: open_fullsize 
   This is the function called on from the onClick handler placed on the thumbnail images. 
   Newer browsers will allow this handler to be on the actual image tag itself, but older 
   browsers will not recognize this.  It would be best to place it in an anchor that is 
   wrapped around the thumbnail's image tag. 

   The function requires three arguments, the path to the popup, which if left blank will use 
   the default path set as a global variable.  This can be used if you want to have more than 
   once file displaying images.  The second argument is the path to the image to the full sized 
   image and the third is the image's caption.  If the caption is left blank, it will default to 
   the caption value set in as a global. 

   Only the path to the enlarged image is required. 
*/ 

function open_fullsize(page_url,img_path,img_caption){ 
   window_name = DEFAULT_WINDOW_NAME; 
   FULLSIZE_PATH = img_path;    
 
   if(img_caption == 'undefined' || !img_caption){ fullsize_caption = DEFAULT_CAPTION; } 
   else{ fullsize_caption = img_caption; } 

   if(FULLSIZE_PATH == 'undefined' || !FULLSIZE_PATH){ FULLSIZE_PATH = DEFAULT_WINDOW_PATH; } 

   wref = window.open(page_url,window_name,'width='+DEFAULT_WIDTH+',height='+DEFAULT_HEIGHT+',scrollbars=1'); 
   if(!wref.opener){ wref.opener = this.window; } 
   return false; 
} 

/* 
   Function Name: do_resize 
   This function is called from the popup window.  It does the actual work of resizing the 
   popup window based on the height and width, plus some buffer values.  This function takes 
   no arguments and requires the function get_photo_data. 

   This function is called from the onLoad event handler in the popup window that will display 
   the enlarged version of the photo. 
*/ 

function do_resize(){ 
   WMOD = 50; 
   HMOD = 150; 
   image_width = get_photo_data("photo","width"); 
   image_height = get_photo_data("photo","height"); 
   if(!(!image_width || !image_height)){ 
      window.resizeTo(image_width+WMOD,image_height+HMOD); 
   } 
   self.focus(); 
} 

/* 
   Function Name: get_photo_data 
   This function uses the getElementById object to determine the value of the height and width 
   of an elememt.  If the browser cannot use this object, the function returns false, otherwise 
   it returns either the height or width of the elememt. 

   The function takes two arguments.  "element" is the ID of the HTML element, which MUST be in 
   the HTML for this to work and "attribute" is the HTML attribute to look for.  This function is 
   designed only to look for height and width, in lowercase, and any other attribute value will result 
   in the function returning false. 
*/ 

function get_photo_data(element,attribute){ 
   if(document.getElementById){ 
      photo_obj = eval('document.getElementById(element)'); 
      if(attribute == "width"){ return photo_obj.width; } 
      else if(attribute == "height"){ return photo_obj.height; } 
   } 
   return false; 
} 

/* function to concatenate and format personalized text and submit to cart */

function formatMsg(form_obj){   
   
   //check min order
   if (form_obj.qty1.value < 20){
        alert("minimum order is 20 cards");
        return false;
    }
    else {          
        form_obj.product1.value = " ";
         
        form_obj.product1.value = "{b}" + form_obj.product.value + "{/b}";
   
         //envelope color
        selIndex = form_obj.ddl_env.selectedIndex;
        color = form_obj.ddl_env.options[selIndex].value;
  
        //template
        selIndex2 = form_obj.templates.selectedIndex;
        occasion = form_obj.templates.options[selIndex2].value;
        
        form_obj.product1.value = form_obj.product1.value + " {br} occasion: " + occasion + "{br} envelope color: " + color;
                
        //wording
        numlines_obj = "form_obj." + occasion + "_numlines.value";
        
         numlines = eval("form_obj." + occasion + "_numlines.value");
         
         for (i=1; i <= numlines; i++){
            form_obj.product1.value = form_obj.product1.value + "{br}" + eval("form_obj." + occasion + "_line" + i + ".value");     
            }

          //return address
          if (form_obj.print_address.checked){
               form_obj.qty2.value = 1;
               form_obj.price2.value = form_obj.qty1.value * .65;
               form_obj.product2.value = " ";
               form_obj.product2.value = "{b} return address printing {/b}";
       
                for (i=1; i <= 3; i++){
                    form_obj.product2.value = form_obj.product2.value + "{br}" + eval("form_obj.return_add" + i + ".value");
                }       
          }
          
                    
    } /*end if-else */
}

/* display correct template for invite/announcement */
function toggleTemplates(selBox_obj){
    
   sel= selBox_obj.selectedIndex;
    
   for(i=0; i < selBox_obj.options.length; i++){
       
        if (i==sel){
            document.getElementById(selBox_obj.options[i].value).style.display = "block";            
        }
        else
        {          
            document.getElementById(selBox_obj.options[i].value).style.display = "none";
        }
   }   
}    
 
/*change navigation background and colors */
function toggleProdNav(link_obj, row_id){
    link_obj.className = "white_bold";
   
    document.getElementById(row_id).className= "subnav_orange_18"; 
}

/*change navigation background and colors back to normal */
function toggleProdNavNorm(link_obj, row_id){
    link_obj.className = "green_link";
   
    document.getElementById(row_id).className= "subnav_white_18"; 
}

/*check minimum*/
function checkMin(form_obj, minValue){
   
   //check min order
   if (parseInt(form_obj.qty.value) < minValue){
        alert("minimum order is " + minValue );
        return false;
    }
    else {
        form_obj.product.value = "{b}" + form_obj.prodID.value + "{/b}:" + form_obj.description.value; 
    return true;
    }
}