var loaded = true ;
var IE = (document.all) ? true:false;
var NS = (document.all) ? false:true;
var lDebug = false;
var scrheight;
if (NS)
    {
    setCookie("NavLeft",window.innerWidth,0,"","","");
    }

if (strUnloaded == null) var strUnloaded = Date();
if (strLoaded == null) var strLoaded = "";
if (strStopped == null) var strStopped = "";

MSFPnav1n=MSFPpreload("ClassLookup.asp","","")
MSFPnav1h=MSFPpreload("ClassLookup.asp","_a","")
MSFPnav2n=MSFPpreload("CartDisplay.asp","","btn_cart")
MSFPnav2h=MSFPpreload("CartDisplay.asp","_a","btn_cart_over")
MSFPnav3n=MSFPpreload("ShoppingListChoose.asp","","btn_list")
MSFPnav3h=MSFPpreload("ShoppingListChoose.asp","_a","btn_list_over")
MSFPnav4n=MSFPpreload("OpenOrders.asp","","btn_open")
MSFPnav4h=MSFPpreload("OpenOrders.asp","_a","btn_open_over")
MSFPnav5n=MSFPpreload("OrderConfirmation.asp","","btn_checkout")
MSFPnav5h=MSFPpreload("OrderConfirmation.asp","_a","btn_checkout_over")
MSFPnav6n=MSFPpreload("QuickEntry.asp","","btn_quick")
MSFPnav6h=MSFPpreload("QuickEntry.asp","_a","btn_quick_over")
MSFPnav7n=MSFPpreload("Admin.asp","","")
MSFPnav7h=MSFPpreload("Admin.asp","_a","")
// install the global error-handler

window.onerror =  errorHandler;
document.onerror = errorHandler;
if (NS)
	{
	var origWidth=innerWidth;
	var origHeight=innerHeight;
	scrheight = window.innerHeight;
	setCookie("wHeight",scrheight,360,"","","");
	setCookie("sWidth",window.innerWidth,"","","");
	}
	
function OpenW(filename,windowname,properties,e)
	{
		var sX,sY,screenX, screenY;
		var zX=screen.width;
		var zXW=(zX/3);
		var zY=screen.height;
		var zYH=(zY/2)+8;
		if(IE) {
			screenY = document.body.offsetHeight;
			screenX = window.screen.availWidth;
		}
		else {
			screenY = window.outerHeight
			screenX = window.outerWidth
		}
		var leftvar = (screenX - zXW) / 2;
		var rightvar = (screenY - zYH) / 2;
		if(IE) {
			sX = leftvar;
			sY = rightvar;
		}
		else {
			sX = (leftvar - pageXOffset);
			sY = (rightvar - pageYOffset);
		}

		mywindow = window.open(filename,windowname,"top=" + sY + ",left=" + sX + ",width=" + zXW + ",height=" + zYH + ",menubar=no,titlebar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes,location=no");
		return false;
	}

function errorHandler(message, url, line)
    {	
	// message == text based error description
	// url		== url which exhibited the script error
	// line	== the line number being executed when the error occured
	
	// Handle the error here
	//alert("Error:" + url + "@" + line + "\r" + message);
	//window.location.href = "_PageError.asp";
	// stop the event from bubbling up to the default window.onerror handler
	//
	return false;
    }


if (IE == false)
    {
    document.captureEvents(Event.KEYDOWN);
    document.onKeyDown = IEKeydownHandler;
    }

function SubmitLookup(sForm,sAction,sActionAddon)
    {
    sForm.action = sAction + sActionAddon;
    window.location.href = sForm.action;
    return false;
    }

function IMGpreload(img) 
	{
	var a=new Image(); 
	a.src="images/" + img + ".gif" ;
	return a; 
	}
		
function MSFPpreload(img,suf,aimg) 
	{
	var a=new Image(); 
	a.src="/e-copas/_NavButtons/" + img + "_cmp_ubc-e-commerce-blue110_hbtn" + suf + ".gif" ;
	return a; 
	}

function LoadMfgPage()
	{
	var Temp = document.rsb.MFG.value;
	if (Temp != "")
		{
		document.rsb.submit();
		}
	}
	
function IEKeydownHandler(frm,e)
	{
	if (e != null)
	    {
	    if (e.which == 13 && frm != null)
	        {
	        frm.submit();
	        return false;
	        }
	    }
	}

function setCookie(name, value, expire, path, domain, secure)
	{
	var expires = new Date();
	var today = new Date();
	expires.setTime(today.getTime() + 1000*60*60*2*365);
	//alert('SetCookie w/ ' + name + '  ' + value + '  ' + expires);
	document.cookie = name + "=" + escape(value) +
	     ( (expires) ? ";expires=" + expires.toGMTString() : "" ) +
	     ( (path) ? ";path=" + path : "" ) +
	     ( (domain) ? ";domain=" + domain : "" ) +
	     ( (secure) ? ";secure" : "" );
	}

function ReadCookie (CookieName) {
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0;
	if (lDebug == true) alert('At ReadCookie ' + CookieName);
  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) {
      ReturnValue = CookiePieces[1];
    }

  }

     return ReturnValue;

}
	
function BCOpenWindow(filename,windowname,properties) 
	{
	    mywindow = window.open(filename,windowname,properties);
	    mywindow.focus();
	}
// -------------------------------------------------
// Set top position for IE/Netscape
// -------------------------------------------------

function SetBottom()
    {
    if (NS)
        {
        setCookie("NavLeft",window.innerWidth,0,"","","");
        }
    var frmLogon = document.LogonForm;
    var scrwidth = 0;
    var objOptCol = document.OptForm1;
    if (frmLogon != null && objOptCol != null && IE)
	{
		if (document.all.item("OptCol").style.display != "none")
		{
			if (frmLogon.PassWord != null) frmLogon.PassWord.focus();
			if (frmLogon.UserName != null )
			{
				if (frmLogon.UserName.value == "" )
				{
					frmLogon.UserName.focus();
				}
			}
		}
	}
    if (IE)
		{	// Internet Explorer
        setCookie("NavLeft",document.body.clientWidth,360,"","","");
        var navtop = document.all.item("NavTop");
		var logo = document.all.item("logo");
		if (lDebug == true) alert('At SetBottom');
		var oBTable = document.all.item("BTable");		// Bottom Table
		var oBBorder = document.all.item("BottomBorder");	//
		var oLeftBand = document.all.item("LeftBand");		// Left Margin Cell
		var oTopNav = document.all.item("TopNav");		// Top band with title/nav bar
		var oGlobal = document.Global;
		var sClassDisplay = "";
		if (oGlobal != null) sClassDisplay = oGlobal.ClassDisplay.value;
		if (oBTable != null && oTopNav != null)
			{
			var fBh = oBTable.clientHeight;		//Bottom table height
			var ch = document.body.clientHeight;
			var sh = document.body.scrollHeight;
			var clienth = ch;
			if (fBh == 0) fBh = 21;
			if (oLeftBand != null)
				{
				if (sClassDisplay >= "C" && sClassDisplay <= "G") fBh = 120;
				}
			if (ch < sh) 
			    {
			    clienth = sh + fBh;
			    }
			var ht = clienth - oTopNav.clientHeight - fBh;	// Distance from bottom of top to top of bottom
			var tp = clienth;
  			if (oLeftBand != null)
			    {
				oLeftBand.style.posHeight = ht;
				//oBBorder.style.posTop = oTopNav.clientHeight + ht;
				if (OptCol.style.display == "none")	oLeftBand.style.posHeight = ht;
				if (document.all.item("topb") != null)
					{
					document.all.item("topb").style.posWidth = document.all.item("OptCol").clientWidth;
					}
				if (sClassDisplay >= "C" && sClassDisplay <= "G")
					{
					if (document.all.item("bottomb") != null)
						{
						document.all.item("bottomb").style.posWidth = document.all.item("OptCol").clientWidth;
						}
					}
			    }
			else
			    {
				oBBorder.style.posTop=tp - fBh;
				if (document.all.item("topb") != null)
					{
					document.all.item("topb").style.display = "none";
					}
				if (sClassDisplay >= "C" && sClassDisplay <= "G")
					{
					if (document.all.item("bottomb") != null)
						{
						document.all.item("bottomb").style.display = "none";
						}
					}
				}
			}
			if (oBBorder != null) oBBorder.style.display = "";
		}
    else	 // Netscape
		{
		var stObj = document.layers["Btm"];
		var stObj1 = document.layers["OptCol"];
		if (stObj != null && stObj1 != null)
			{
			stObj.width = stObj1.width;
			}
		}
	}
	
function showHideLayers() 
  {

  var i, visStr, args, theObj;
  args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
    { //with arg triples (objNS,objIE,visStr)
    visStr   = args[i+2];
    if (navigator.appName == 'Netscape' && document.layers != null)
      {
      theObj = eval(args[i]);
      if (theObj) 
        {
        theObj.visibility = visStr;
        }
      }
    else if (document.all != null)
      { //IE
      theObj = eval(args[i+1]);
      if (visStr == '')
        {
        var tmp = theObj.style.display;
        visStr = 'hide';
        if (tmp == 'none') visStr = 'show';
        }
      if (visStr == 'show') visStr = ''; //convert vals
      if (visStr == 'hide') visStr = 'none';
      if (theObj)
         {
         theObj.style.display = visStr;
         }
      }
    }
  }

function formatPhone(me){
	myvalue=me.value;
	mySize=me.value.length;
	if (mySize == 11)
		myvalue=myvalue.replace(/(\w{1})(\w{3})(\w{3})(\w{4})/g,"$1-($2)$3-$4");
	if (mySize == 10)
		myvalue=myvalue.replace(/(\w{3})(\w{3})(\w{4})/g,"($1)$2-$3");
	if (mySize == 7)
		myvalue=myvalue.replace(/(\w{3})(\w{4})/g,"$1-$2");
	me.value=myvalue;
}

