<!--
/* ==================================================================
FILE:   code.js
DESCR:  Code library file for ACB's Rebate Tool application.
AUTHOR: Joel Stamey
DATE:   6/25/99 

Browser-specific code: 

This application adds optional elements (like 
DHTML) for high-end browsers. 
	n = netscape browsers that support DHTML
        ie =  msie DHTML browsers
================================================================== */

n = (document.layers) ? 1:0
ie = (document.all) ? 1:0

function document_onhelp(myTopic) {
	var x = myTopic;
	helptopiclaunch(x);
	return true
}

function hideLoadMessage() {
        hidelayer('loadmsg');
}

function hidelayer(name){
        if(n){
                document.layers[name].clip.width=0
                document.layers[name].clip.height=0
                document.layers[name].visibility="show"
                }
        if(ie){
                document.all[name].style.display = "none";
                }
}

function doWindowChange (zX,zY) {
      if (zX <= 0 || zY <= 0) return;
      if (n) { outerWidth = zX; outerHeight = zY; }
      else if (ie) resizeTo (zX,zY);
      return;
}

function makeStart(){
 if (navigator.userAgent.indexOf("Win")  > -1)
	{
	alert("You have selected the ACB Rebate Tool as your home page. When you click 'OK' you will be asked what you want to do. Please select 'Open this file from its current location' and click 'OK'");
	location.href = "../WesternDigital/classes/start.reg";
	}
 	else if (navigator.userAgent.indexOf("Mac") > -1)
	{
	alert("Thanks for choosing the ACB Rebate Tool as your home page. On your Mac: Ctrl+Click the page background and choose 'Set Home Page' from the popup menu (Internet Explorer Only)");
	}
}

/* ==================================================================
Navigation Code: 

Code for handling windows/ forms / passed data
================================================================== */

function getParm(string,parm) {
    // returns value of parm from string
    var startPos = string.indexOf(parm + "=");
    if (startPos > -1) {
        startPos = startPos + parm.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1)
            endPos = string.length;
        return unescape(string.substring(startPos,endPos));
    }
    return '';
}

// Used if Encoded Characters are sent by Browser

function replace(string,text,by) {
    // Replaces text with by in string
    var i = string.indexOf(text), newstr = '';
    if ((!i) || (i == -1))
        return string;
    newstr += string.substring(0,i) + by;
    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    return newstr;
}

function getParmVal(val) {
    var x = location.search.substring(1);
    var y = getParm(x,val) ;
    return y;
}

/* ==================================================================
Custom Navigation Code: 

This application spawns child window based upon these functions
================================================================== */

function launch(newURL, orgURL, ysnScroll) {
  var varURL = newURL + "?Path=" + orgURL;
  var newName = "ChildWindow";
  var newFeatures = "toolbar=no,scrollbars=" + ysnScroll + "status=no,menubar=no,resizable=yes,width=400,height=400";
  var orgName = "wndParent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function helplaunch(orgURL, ysnScroll) {
  var varURL = "/WesternDigital/help/help.htm";
  var newName = "helpWindow";
  var newFeatures = "toolbar=no,scrollbars=" + ysnScroll + "status=no,menubar=no,resizable=yes,width=535,height=430,top=45,left=220";
  var orgName = "wndParent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function adminlaunch(myURL) {
  var varURL =myURL;
  var newName = "wndAdmin";
  var newFeatures = "toolbar=no,scrollbars=yes,status=yes,menubar=no,resizable=yes,width=500,height=430,top=45,left=220";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function consolelaunch(myURL) {
  var varURL =myURL;
  var newName = "wndConsole";
  var newFeatures = "toolbar=no,scrollbars=no,status=yes,menubar=no,resizable=yes,width=500,height=430,top=45,left=220";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function wizardlaunch(myURL) {
  var varURL = myURL;
  var newName = "wndWizard";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=yes,top=45,left=220,width=500,height=400";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function processlaunch(myURL) {
  var varURL = "/WesternDigital/content/" + myURL;
  var newName = "wndProcess";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=yes,top=45,left=220,width=500,height=400";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function topiclaunch(myTopic) {
  var varURL = "/WesternDigital/help/helptopic.asp?key=" + myTopic;
  var newName = "helpWindow";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=yes,width=286,height=417,top=45,left=220";
  var orgName = "right";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
     remote.opener = window;
     remote.opener.name = orgName;
}

function helptopiclaunch(myTopic, orgURL, ysnScroll) {
  var varURL = "/WesternDigital/help/helptopic.asp?key=" + myTopic;
  var newName = "helpWindow";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=yes,width=286,height=417,top=45,left=220";
  var orgName = "wndParent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
     remote.opener = window;
     remote.opener.name = orgName;
}

function detailslaunch(myURL) {
  var newName = "rptWindow";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=yes,width=400,height=300";
  var orgName = "wndParent";
  var remote = open(myURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function settingslaunch(newURL) {
  var varURL = newURL;
  var newName = "ChildWindow";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=no,width=325,height=200";
  var orgName = "wndParent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function reportlaunch(myReport) {
  var varURL = myReport;
  var newName = "wndRpt";
  var newFeatures = "toolbar=no,scrollbars=yes,status=no,menubar=yes,resizable=yes,width=640,height=430,top=0,left=0";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
}

function download(myReport) {
  var varURL = myReport;
  var newName = "wndRpt";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=yes,resizable=yes,width=535,height=430,top=45,left=220";
  var orgName = "Parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    	remote.opener = window;
  	remote.opener.name = orgName;
}

function messagebox(myType,myPrompt,myButton,myTitle,myHelpContext) {
  var varURL = "/WesternDigital/messagebox.asp?type=" + myType +"&prompt=" + myPrompt + "&button=" + myButton + "&title=" + myTitle + "&helpcontext=" + myHelpContext;
  var newName = "wndMessage";
  var newFeatures = "toolbar=no,scrollbars=no,status=no,menubar=no,resizable=no,width=300,height=300,top=45,left=220,modal=yes";
  var orgName = "parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
     remote.opener = window;
     remote.opener.name = orgName;
}

function surveylaunch(myURL) {
  var varURL = myURL;
  var newName = "wndSurvey";
  var newFeatures = "toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=no,width=500,height=450,top=0,left=0";
  var orgName = "parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
	remote.opener.name = orgName;
}
function traininglaunch(myURL) {
  var varURL = myURL;
  var newName = "wndSurvey";
  var newFeatures = "toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=no,width=350,height=450,top=0,left=0";
  var orgName = "parent";
  var remote = open(varURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
	remote.opener.name = orgName;
}
function fetch(url) {
    opener.location = url;
}

function clearStatus() {
   opener.status=""
}

/* ==================================================================
Form Code: 

Tests for form action and validation
================================================================== */
function doSelectChange(el,dest) {
    dest.value = el.options[el.selectedIndex].text;	
}

  function lookupItem(el,dest) {
    var curValue = el.value.toLowerCase()
    var found = false
    var index = dest.selectedIndex
    var numOptions = dest.options.length
    var pos = 0
    // Repeat until found or end of list is reached
    while ((!found) && (pos < numOptions)) {
      // Do comparisons in lowercase
      found = (dest.options[pos].text.toLowerCase().indexOf(curValue)==0) 
      if (found) 
        index = pos
      pos++
    }
    if (found)  // Updated listbox
      dest.selectedIndex = index
  }

  function goValue(el) {
    var where
    if (el.selectedIndex>-1) { 
      // Make sure there is a selection
      where = el.options[el.selectedIndex].value
      window.open(where)
    }
  }

function AutoTab(what,e,max,action) {
// Syntax of call: onKeyUp="KeyPress(this,event,1,'what.form.text2.focus()')"
    if (document.layers) {
        if (e.target.value.length >= max)
            eval(action);
    }
    else if (document.all) {
        if (what.value.length > (max-1))
            eval(action);
    }
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

/* ==================================================================
Style/ Visibiltiy Code: 

Sets the appearance of document elements
================================================================== */

function makeCool(a) {
   a.style.color ="#000000";
   a.style.cursor = "hand";
   a.style.fontweight = "bold";
}
    
function makeNormal(a) {
   a.style.color = "#9A9A9A";
   a.style.fontweight = "normal";
}

/* ==================================================================
Correction: 

Corrects problems
================================================================== */

function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

//-->
