//<SCRIPT> // <- dummy script tag used to enable InterDev syntax coloring
//------------------------------------------------------------------------
// File:    sc_action.js
// Author:  Al Yanchak
// Date:    
//
// Revised: 
//
// SmartCAT v3.0 library file
//
// Implements client-side objects for SmartCAT widgets
//
// Copyright© 1999, I-Mark Inc. All Rights Reserved
//
// WARNING: The information in this file is protected by copyright law
// and international treaty provisions. Unauthorized reproduction or
// distribution of this file, or any portion of it, may result in severe
// criminal and civil penalties, and will be prosecuted to the maximum
// extent possible under the law.  Further, you may not reverse engineer,
// decompile, or disassemble the file.
//------------------------------------------------------------------------

function scAction(action_handler, famID, view_code, prtNo, strUOM, strKeyVar)
{
  var exists = false;
  eval("if(window." + action_handler + "){exists = true;}")
  if(exists == true)
  {
    if (imkIsEmpty(view_code))
      view_code = sc_GetViewID();
    if (view_code != null)
      eval(action_handler + "(famID, view_code, '" + prtNo + "', '" + strUOM + "', '" + strKeyVar + "')");
    else
      alert("Not available at this time \nPlease try again later");
  }
  else
  {
    alert("Not available at this time \nPlease try again later");
  }
}

function scNotAvail()
{
  alert("Not available at this time \nPlease try again later");
}

function scContact(famID, view_code, prtNo, strUOM, strKeyVar)
{
    Shadowbox.open({
        content:    'sc_contactus.asp?famID=' + famID + "&prtNo=" + prtNo,
        player:     'iframe',
        width: 497,
        height: 315
    });
}

function scPartEdit(famID, view_code, prtNo, strUOM, strKeyVar)
{
    var editLink = '../stl_app/stl_part_editor.asp?new=0&catEdit=true&strKeyVar=&strKeyInfo=' +
                    '&famID=' + famID +
                    '&prtNo=' + prtNo +
                    '&uom=' + strUOM +
                    '&vid=' + view_code;
    Shadowbox.open({
        content:    editLink,
        player:     'iframe',
        width: 740,
        height: 800
    });
}

function scEmailFriend(famID, view_code, prtNo, strUOM, strKeyVar)
{

    
    Shadowbox.open({
        content:    'sc_emailspecs.asp?famID=' + famID + "&prtNo=" + fixEscape(prtNo) + "&strUOM=" + strUOM + "&strKeyVar=" + strKeyVar + "&vid=" + view_code,
        player:     'iframe',
        width: 537,
        height: 380
    });
}
function fixEscape(str)
{
return escape(str).replace( /\+/g, "%2B" );
}
function scAddCart(famID, view_code, prtNo, strUOM, strKeyVar)
{
    var selected_parts = '<AddItm id="' + unescape(prtNo) + '" assy="0" qty="1" sid="' + unescape(prtNo) + '" sfid="' + famID + '" ai="1" />'
    var modCart = "<ModCart>" + selected_parts + "</ModCart>"

    var submitForm = getNewSubmitForm();
    createNewFormElement(submitForm, "modCart", modCart);
    createNewFormElement(submitForm, "pageAction", "updateCart");
    //createNewFormElement(submitForm, "pageType", "cartAdd"); 
    submitForm.method = "post"
    submitForm.target = "_top"
    submitForm.action = "/ecatalog/cart";
    submitForm.submit();
}  
function scUpSellAddCart(famID, view_code, prtNo, strUOM, strKeyVar)
{
  var theForm = document.upsell;
  var Items = "";
    
  for (var i = 0, len = theForm.p.length; i < len; ++i)
  {
    if (theForm.p[i].checked == true)
    {
   
      if (isNaN(parseInt(theForm["qty" + theForm.p[i].value].value)))
      {
        alert("Please enter a numeric quantity for " + theForm.p[i].value);
        theForm["qty" + theForm.p[i].value].focus();
        theForm["qty" + theForm.p[i].value].select();
        return;
      }
      else
      {
        //Items += theForm.p[i].value + "~~" + parseInt(theForm["qty" + theForm.p[i].value].value) + "~~" + theForm["desc" + theForm.p[i].value].value + "|";
        Items += theForm["pnum" + theForm.p[i].value].value + "~~" + parseInt(theForm["qty" + theForm.p[i].value].value) + "~~" + theForm["desc" + theForm.p[i].value].value + "|";
      }
    }
  }
 
  
  if (Items == "")
  {
    
    alert("Parts must be selected before adding to the shopping cart.");
    return;
  }
  sc_OpenLocation("../ss_app/ss_modcart.asp?Items=" + escape(Items) + "&vid=" + view_code);
}

function scViewSpec(famID, view_code, prtNo, strUOM, strKeyVar)
{
  strKeyVar = strKeyVar.replace(/~/g, "'");
  var prodFam = getISAPIfamName(famID)

  var str_specLoc = "/ecatalog/" + prodFam + "/" + strUOM + 
                    "/" + escape(prtNo).replace("+" , "|+|").replace("/","|-|").replace("/","|-|")
  sc_OpenLocation(str_specLoc, "_top",true);
}

function scViewSpecReleated(famID, view_code, prtNo, strUOM, strKeyVar)
{
  strKeyVar = strKeyVar.replace(/~/g, "'");
  var str_specLoc = "sc_specsheet.asp?famID=" + famID +
                    "&vid=" + view_code +
                    "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                    "&strUOM=" + strUOM +                    
                    "&strKeyVar=" + escape(strKeyVar);                    
    Shadowbox.open({
        content:    str_specLoc,
        player:     'iframe',
        width: 1000,
        height: 650
    }); 
}

//=============================================
//A new standard customizePart action function
//=============================================
function scCustomizePart(famID, viewID, prtNo, strUOM)
{
var frmMenu = sc_FindFrame("sc_header");
  var frmMain = sc_FindFrame("sc_main");
  var frmSel = sc_FindFrame("sc_prod_sel");
  var frmSrc = sc_FindFrame("c_srchtbl");
  
  if(frmMenu && frmSel)
  {               //selector page
		frmSel.theFilter.SaveState();
		setCookie('IsSaveSelState','true','')
  }

    var prodFam = getISAPIfamName(famID);
	 /*var strURL = "sc_custprt_main.asp?" +
							 "famID="   + famID  +
							 "&strUOM=" + encodeURI(strUOM) +
							 "&prtNo="  + encodeURI(prtNo)  +
							 "&vid="    + encodeURI(viewID);
	*/
  var strURL = "/ecatalog/" + prodFam + "/" + strUOM + 
                    "/customize/" + escape(prtNo).replace("+" , "|+|").replace("/","|-|")
  sc_OpenLocation(strURL, "_top");             
}

function scViewSpecReleated(famID, view_code, prtNo, strUOM, strKeyVar)
{
  strKeyVar = strKeyVar.replace(/~/g, "'");
  var str_specLoc = "sc_specsheet.asp?famID=" + famID +
                    "&vid=" + view_code +
                    "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                    "&strUOM=" + strUOM +                    
                    "&strKeyVar=" + escape(strKeyVar);                    
    Shadowbox.open({
        content:    str_specLoc,
        player:     'iframe',
        width: 1000,
        height: 650
    }); 
}

function scViewPrintSpec(famID, view_code, prtNo, strUOM, strKeyVar)
{
  strKeyVar = strKeyVar.replace(/~/g, "'");
 
  var str_specLoc = "sc_pdf_specsheet.asp?famID=" + famID +
                    "&vid=" + view_code +
                    "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                    "&strUOM=" + strUOM +
                    "&strStateVar=print" +
                    "&strKeyVar=" + escape(strKeyVar); 

                    
	/* var str_specLoc = "../app/activepdf/cutsheet.asp?famID=" + famID +
                    "&vid=" + view_code +
                    "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                    "&strUOM=" + strUOM +
                    "&strStateVar=print" +
                    "&strKeyVar=" + escape(strKeyVar); 
  */                   
  sc_OpenLocation(str_specLoc, "_blank");
  
}

function scViewSelector(famID, view_code, prtNo, strUOM)
{
  var str_selLoc = "sc_selframe.asp?famID=" + famID +
                   "&vid=" + view_code +
                   "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                   "&strUOM=" + strUOM +
                   "&strStateVar=" + escape("prtNo=" + prtNo);
                   
  sc_OpenLocation(str_selLoc, "sc_main");
}     

function scCompViewSpec(famID, view_code, prtNo, strUOM, strKeyVar, compPrtNo, page)
{
  var frmMenu = sc_FindFrame("sc_header");
  var frmMain = sc_FindFrame("sc_main");
  var frmSel = sc_FindFrame("sc_prod_sel");
  
  strKeyVar = strKeyVar.replace(/~/g, "'");

  if(frmMenu && frmSel)
  {
    frmSel.theFilter.SaveState();
    setCookie('IsSaveSelState','true','')
    frmMenu.MainLoc = "../sc_app/sc_selframe.asp?famID=" + frmSel.theFilter.FamID + "&UOM=" + frmSel.theFilter.strUOM + "&vid=" + view_code;
  }
  
  var str_specLoc = "../sc_app/sc_specsheet.asp?famID=" + famID +
                    "&vid=" + view_code +
                    "&prtNo=" + escape(prtNo).replace("+" , "%2b") +
                    "&strUOM=" + strUOM +
                    "&strKeyVar=" + escape(strKeyVar) +
                    "&compPrtNo=" + escape(compPrtNo) +
                    "&page=" + page;
                   
  sc_OpenLocation(str_specLoc, "sc_main");
}              

function scBack(famID, view_code, prtNo, strUOM)
{
 //history.go(-1);
  var prodFam = getISAPIfamName(famID)                      
  var str_specLoc = "/ecatalog/" + prodFam + "/" +  strUOM;
  sc_OpenLocation(str_specLoc, "_top"); 
}

function hoverClick(famID,view_code, prtNo, strUOM)
{
    
}           


function xlsCompareExport(famID, viewID, UOM, parts)
{
      var frmMenu = sc_FindFrame("sc_header");
      var frmMain = sc_FindFrame("sc_main");
      var frmSel = sc_FindFrame("sc_prod_sel");
      
     var submitForm = getNewSubmitForm();
     var xls_src = "sc_compxlsExport.asp"
     createNewFormElement(submitForm, "famID", famID);
     createNewFormElement(submitForm, "vid", viewID); 
     createNewFormElement(submitForm, "uom", UOM);     
     createNewFormElement(submitForm, "parts", parts);
  	       
     submitForm.method= "post"
     submitForm.target= "_top"
     submitForm.action= xls_src;
     submitForm.submit();  
}

function scGraphicalSelector(famID, selector, view_code, prtNo, strUOM, strKeyVar)
{
  // if we are on a filter page, use the uom value from the filter
  // control instead of the value that the page was opened with
  if(typeof(theFilter) != "undefined")
    strUOM = theFilter.strUOM;
    
  var str_loc = "../htm/productSelectors/Selector.asp?fam_id=" + famID +
                "&uom=" + escape(strUOM) +
                "&selector=" + selector;
  // get the current selection state
  var frmMenu = sc_FindFrame("sc_header");
  if(frmMenu)
  {  
    if(imk_GetCookie('strSelectionState'))
    {
      var arr_selState = imk_GetCookie('strSelectionState').split("|");
			
      var len = arr_selState.length;
      
      for(var i = 0; i < len; i++)
      {
        var param_id;
        var param_val; 

        var pos = arr_selState[i].indexOf("=");
        
       
        if(pos > 0)
        {
          param_id  = arr_selState[i].substr(0, pos);
          param_val = arr_selState[i].substr(pos + 1);
         
          if(param_id != "famID" && param_id != "uom")
            str_loc += "&param" + param_id + "=" + escape(param_val);
    
        }
      }
    }  
  }
   
  sc_OpenLocation(str_loc, "sc_main");
}


