// ******************************************************************
/*
 * PartSpecSheets.js
 *
 * Copyright (c) 2004 David Begin, Zurpsoft. All Rights Reserved.
 *
 * Utility functions for Techno part specification sheets.
 *
 * To Do:
 * Add error handling (to inline code also)
 */
// ******************************************************************

// --------------------------------------------------------
// Determine browser type and version
// --------------------------------------------------------

var msg="";
var ckvalue="";
function Browser()
{
    this.isIE    = false;  // Internet Explorer
    this.isNS    = false;  // Netscape
    this.version = null;

    var agent = navigator.userAgent;

    var pos = agent.indexOf("MSIE");
    if (pos >= 0) {
        this.isIE = true;
         this.version = parseFloat(agent.substr(pos + ("MSIE").length));
        return;
    }

    pos = agent.indexOf("Netscape/");
    if (pos >= 0) {
        this.isNS = true;
        this.version = parseFloat(agent.substr(pos + ("Netscape/").length));
        return;
    }

    pos = agent.indexOf("Netscape6/");
    if (pos >= 0) {
        this.isNS = true;
        this.version = parseFloat(agent.substr(pos + ("Netscape6/").length));
        return;
    }

    if (navigator.appName == "Netscape") {
        this.isNS = true;
        this.version = parseFloat(navigator.appVersion);
    }
}
var browser = new Browser();

// --------------------------------------------------------
// ModelServer class - Generate URLs for the CatDas Model
// Server.
// --------------------------------------------------------
function ModelServer()
{
}

// --------------------------------------------------------
// action = download or view
// techno_standard-slide.prt
// --------------------------------------------------------
ModelServer.generateURL = function(partNumber, partFile, action)
{
    return "http://catalog.catalogds.com/catalog/showPart?mfid=techno&pn=" + partNumber;
   /*
    return "http://www2.catdas.com/modelserv/servlet/websearch/pip2a9.ws." +
           "cGraphicalBrowse-loadPage?URL=http://www2.catdas.com/modelserv/" +
           "servlet/websearch/pip2a9.ws.cModelLoader-getModel?objectID=" +
           "cadtechno:" +
           partFile + ":" +
           partNumber.toUpperCase() + ":" +
           partNumber.toLowerCase() + ":" +
           "$(cad_format):TECHNOSLIDES:$(TRAVEL)&type=" +
           action + "&partNumber=" +
           partNumber.toUpperCase() + "&partKey=" +
           partNumber.toUpperCase() + "&plugin=true&mfid=techno";
 */
}


// --------------------------------------------------------
// RollOverImage class - functions for preloading and
// swapping image files.
// --------------------------------------------------------
function RollOverImage()
{
}

// --------------------------------------------------------
// Preload any images used with mouse over events.
// Syntax: roiPreloadImages(image1, image2, ...)
// --------------------------------------------------------
RollOverImage.roiPreloadImages = function()
{
    if (document.images) {
        for (var i = 0; i < arguments.length; i++) {
            (new Image()).src = arguments[i];
        }
    }
}

// --------------------------------------------------------
// Swap the named image with the new url
// Syntax: roiSwapImage(image name, new image url)
// --------------------------------------------------------
RollOverImage.roiSwapImage = function(imgName, imageURL)
{
    if (document.images) {
        document.images[imgName].filters[0].apply();
        document.images[imgName].src = imageURL;
	  document.images[imgName].filters[0].play();

    }
}

// --------------------------------------------------------
// --------------------------------------------------------
function validatePNSelectMD()
{
    var e = document.getElementById("pnSelectMD");
    var curMotor = e.options[e.selectedIndex].text;

    if (curMotor == 'X' || curMotor == 'C') {
        document.getElementById("pnSelectST").selectedIndex = 0;
    }
}

function validatePNSelectST()
{
    var e = document.getElementById("pnSelectST");
    var curScrew = e.options[e.selectedIndex].text;

    if (curScrew = 'K') {
        var e1 = document.getElementById("pnSelectMD");
        var curMotor = e1.options[e1.selectedIndex].text;
        if (curMotor == 'X' || curMotor == 'C') {
            alert("You must select a Motor Drive other than\n'No Motor' or 'Crank Handle' to select\na Screw Type of 'Side Mount Motor'.");
            e.selectedIndex = 0;
        }
    }
}

function addToCart(Desc)
{
    var qty = document.getElementById("qtySelect").value;
    var code = parsePartNumber();
    if (code=="Part Number:") return;
    //var qty = parseInt(qtyList.options[qtyList.selectedIndex].text);
    var cfmmsg = "Do you wish to add the following to your\nquotation list?\n\n" +
              "Part Number: " + code + "\n" +
              "Quantity: " + qty + "\n";
               

    if (confirm(cfmmsg)) {
        ReadCookie('lmsck'); 
        Insert(code,Desc,qty); 
        setCookie(msg);
    }
    // qtyList.selectedIndex = 0;
}

function showquote(){
document.location.href="../tibsRFQ.htm";
}

function setCookie(value){
 document.cookie = 'lmsck' + "=" + escape(value)+"; path=/";
}

function ReadCookie(CookieName) {
  var SelectSize
  var ReturnValue = "";
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
    var CookiePieces
    var x = 0;
  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) 
     {
    CookiePieces = CookieSet[x].split ('=');
    if (CookiePieces[0].substring (0,1) == ' ')
       {
      CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
       }
    if (CookiePieces[0] == CookieName)
       {
      ckvalue = unescape(CookiePieces[1]);
     
     } }
}


function Insert(code,name,qty){    
var Fld='';
gg = new Array(7);

var SelectSize=0;
var FldSet='';
msg=ckvalue;
if (msg.length <  3) msg='';
if (msg.length > 2) 
{
FldSet = msg.split ('+');
SelectSize=FldSet.length;
for (i = 0; i < 7; i++)
{ gg[i]=""; }
if (SelectSize > 7 ) SelectSize=7;
  for (x = 0; x < SelectSize; x++)
{
  Fld = FldSet[x].split ('=');
  if (Fld[0]==code) return;
}
msg=msg + "+";
} 
msg = msg +code+"="+name+"="+qty; 

if (SelectSize == 6){
    var msg10='Max. of 7 Items allowed per request have been selected.\n';
    msg10=msg10+'Please proceed to Quote Request Form by clicking '+'"REVIEW QUOTE'+'" button.';
    alert(msg10);
   }

}

