if 	(document.getElementById)	var DOMS = 3	// Supports Web Standard (getElementById)
else if	(document.all)		 	var DOMS = 2	// Supports MS document.all
else if	(document.layers)	 	var DOMS = 1	// Supports NS layers
else				 	var DOMS = 0;	// No DOM gateway support

function analOut(s) {
  var WANAL = window.open('','ANALYZE','height=400,width=400')
  WANAL.focus();
  WANAL.document.open();
  WANAL.document.write('<pre>' + s + '</pre>');
  WANAL.document.close();
  this.focus;
}

// Return DOM Handle for specified DOM object ID
function getObj(oid) {
  switch(DOMS) {					// Check for various browsers
    case 1: return(document[oid]);			// Supports Layers (NS4)
    case 2: return(document.all[oid]);			// Supports document.all (ie4)
    case 3: return(document.getElementById(oid));	// Supports getElementById
  }
}

// Position DOM object:  obj = DOM object handle;  x = left coord;  y = top coord.
function setPos(obj,x,y) {
  switch(DOMS) {
    case 1:  obj.moveTo(x,y);			    break;	// NS 4
    default: obj.style.left = x; obj.style.top = y; break;	// IE4+,NS6+
  }
}

// Set DOM object visibility:  obj = DOM object handle;  s = visibility option
function setVis(obj,s) {
  switch(DOMS) {
    case 1:  obj.visibility       = s; break;		// layers
    default: obj.style.visibility = s; break;		// IE4+ and NS6+
  }
}

// Set DOM object text clor:  obj = DOM object handle;  s = color
function setColor(obj,s) {
  switch(DOMS) {
    case 1:  obj.color       = s; break;		// layers
    default: obj.style.color = s; break;		// IE4+ and NS6+
  }
}

// Set DOM object text clor:  obj = DOM object handle;  s = color
function swZ(obj1,obj2) {
  switch(DOMS) {
    case 1:  { obj1.zindex       = 6; obj2.zindex       = 5; break; }	// layers
    default: { obj1.style.zindex = 6; obj2.style.zindex = 5; break; }	// IE4+ and NS6+
  }
}

function aniBanner(s) { var obj1 = getObj('SWAPT1'); var obj2 = getObj('SWAPT2');
  switch(s) {
    case 2:  { setVis(obj2,'visible'); setColor(obj1,'#0bcced'); setColor(obj2,'#1d6acb'); swZ(obj2,obj1); setTimeout('aniBanner(3)' ,100);  break; }
    case 3:  {                         setColor(obj1,'#149bdc'); setColor(obj2,'#149bdc');                 setTimeout('aniBanner(4)' ,100);  break; }
    case 4:  {                         setColor(obj1,'#1d6acb'); setColor(obj2,'#0bcced');                 setTimeout('aniBanner(5)' ,100);  break; }
    case 5:  { setVis(obj1,'hidden' ); setColor(obj1,'#2639ba'); setColor(obj2,'#00ffcc');                 setTimeout('aniBanner(6)' ,2000); break; }
    case 6:  { setVis(obj1,'visible'); setColor(obj1,'#1d6acb'); setColor(obj2,'#0bcced'); swZ(obj1,obj2); setTimeout('aniBanner(7)' ,100);  break; }
    case 7:  {                         setColor(obj1,'#149bdc'); setColor(obj2,'#149bdc');                 setTimeout('aniBanner(8)' ,100);  break; }
    case 8:  {                         setColor(obj1,'#0bcced'); setColor(obj2,'#1d6acb');                 setTimeout('aniBanner(1)' ,100);  break; }
    default: { setVis(obj2,'hidden' ); setColor(obj1,'#00ffcc'); setColor(obj2,'#2639ba');                 setTimeout('aniBanner(2)' ,2000); break; }
  }                                                                                   
}                                                                                     

function aniIndex(s,tc) { 
  switch(s) {
    case 0:  { setVis(getObj('SB0'),'hidden'); setVis(getObj('SB1'),'visible'); setTimeout('aniIndex(1)',3000); break; }
    case 1:  { setVis(getObj('SB1'),'hidden'); setVis(getObj('SB2'),'visible'); setTimeout('aniIndex(2)',3000); break; }
    case 2:  { setVis(getObj('SB2'),'hidden'); setVis(getObj('SB3'),'visible'); setTimeout('aniIndex(3)',3000); break; }
    case 3:  { setVis(getObj('SB3'),'hidden'); setVis(getObj('SB4'),'visible'); setTimeout('aniIndex(4)',3000); break; }
    case 4:  { setVis(getObj('SB4'),'hidden'); setVis(getObj('SB0'),'visible'); setTimeout('aniIndex(0)',3000); break; }
    default: { break; }
  }                                                                                   
}                                                                                     

function imgRot(s,pt,tm) {
  document.images[s].src = eval(s)[pt].src;
  ++pt;  if ( !eval(s)[pt] ) { pt = 1 };
  setTimeout('imgRot("' + s + '",' + pt + ',' + tm + ')',tm);
}

// Reset input field color when changed
function fldReset() { this.style.backgroundColor=''; this.style.borderColor='#bbbbbb'; }

// display error message, color error field, set 
function setErm(f,m) {
  alert(m);
  f.onchange = fldReset;
  f.style.backgroundColor="#ff9";
  f.style.borderColor="#f00"; 
  f.focus();
  return false;
}

// Check mailto form field(s) for required input, When a field is found with missing input,
// alert user, set field pink, and set focus to it.
function chkMailform(s) {
  if (s.Name.value=='')			return setErm(s['Name'],		'You must enter your name to continue.')
  if (s.Address1.value=='')		return setErm(s['Address1'],		'You must enter your Street address to continue.')
  if (s.City.value=='')			return setErm(s['City'],		'You must enter your City to continue.')
  if (s.State.value=='')		return setErm(s['State'],		'You must enter your State to continue.')
  if (s.ZipCode.value=='')		return setErm(s['ZipCode'],		'You must enter your zipcode to continue.')
  if (s.Telephone.value=='')		return setErm(s['Telephone'],		'You must enter your day time phone number to continue.')
//  if (s.EveTelephone.value=='')		return setErm(s['EveTelephone'],	'You must enter your eveining phone number to continue.')
  if (s['MM_EMAILTO[]'][1].value=='')	return setErm(s['MM_EMAILTO[]'][1],	'You must enter your email address to continue.')
  s.Email.value = s['MM_EMAILTO[]'][1].value;
  return true;
}

function chkShip(s) {
  if (s.contact.value=='')		return setErm(s['contact'],		'You must enter your name to continue.')
  if (s.street1.value=='')		return setErm(s['street1'],		'You must enter your STREET address to continue.')
  if (s.city.value=='')			return setErm(s['city'],		'You must enter your city to continue.')
  if (s.country[s.country.selectedIndex].value=="UNITED STATES") { 
    if (s.state.value=='')		return setErm(s['state'],		'You must enter your state to continue.')
  }
  if (s.zipcode.value=='')		return setErm(s['zipcode'],		'You must enter your zipcode to continue.')
  if (s.phone.value=='')		return setErm(s['phone'],		'You must enter a contact phone number to continue.')
  if (s.email.value=='')		return setErm(s['email'],		'You must enter your email address to continue.')
  return true;
}

function chkPayment(s) {
  if (s.payby.selectedIndex<1)		return setErm(s['payby'],		'You must indicate a payment method to continue.')
  if (s.payby[s.payby.selectedIndex].value=="C") {
    if (s.cc_type.selectedIndex<1)	return setErm(s['cc_type'],		'You must indicate the credit card type to continue.')
    var Tar = s.cc_type[s.cc_type.selectedIndex].value.split("|");
//  if (s.cardcorp.value=='')		return setErm(s['cardcorp'],		'You must enter the card holder corporate name to continue.')
    if (s.cardname.value=='')		return setErm(s['cardname'],		'You must enter card holder name to continue.')
    if (s.cc_numb.value=='')		return setErm(s['cc_numb'],		'You must enter the credit card number to continue.')
    if ((s.cc_code.value=='') && (Tar[1]=="1")) return setErm(s['cc_code'],'You must enter the credit card security code to continue.')
    if (s.cc_expm.selectedIndex<1)	return setErm(s['cc_expm'],		'You must indicate the credit card expiration date month to continue.')
    if (s.cc_expy.selectedIndex<1)	return setErm(s['cc_expy'],		'You must indicate the credit card expiration date year to continue.')
  }
  return true;
}

function chkItem(s) {
  if (s.fid.selectedIndex<1)					return setErm(s['fid'],		'You must select a finish to continue.')
  if ((s.wint.selectedIndex<1) && (s.hint.selectedIndex<1))	return setErm(s['wint'],	'You must select a molding width or height to continue.')
  if (s.quantity.value<1)					return setErm(s['quantity'],	'You must specifiy the quantity of molding to continue.')
  return true;
}

function chkItemH(s) {
  if (s.quantity.value<1)					return setErm(s['quantity'],	'You must specifiy the quantity to continue.')
}

function chkAccess() {
  if (! document.validate.springs.checked) {
    if (!confirm('If you have ordered all of the retainers/springs you need, Click Yes.\nIf you need to order retainers/springs, click Cancel to continue shopping.')) return false;
    document.validate.springs.checked = true;
  }
  if (! document.validate.hangers.checked) {
    if (!confirm('If you have ordered all of the hangers you need, Click Yes.\nIf you need to order hangers, click Cancel to continue shopping.')) return false;
    document.validate.springs.checked = true;
  }
  return true;
}

function calcCost(minp,inchp,maxl) {
  var s = document.itemorder;
  if ((s.wint[s.wint.selectedIndex].value<5) || (s.wint.value == maxl)) s.wfrac.selectedIndex = 0;
  if ((s.hint.value == 0) || (s.hint.value == maxl)) s.hfrac.selectedIndex = 0;
  var wlen = (s.wint.value*1) + ((s.wfrac.selectedIndex>0)?1:0);
  var hlen = (s.hint.value*1) + ((s.hfrac.selectedIndex>0)?1:0);
  var wprice = ((wlen<5)?0:(minp*1)) + ((wlen<8)?0:(wlen-8)*inchp);
  var hprice = ((hlen<5)?0:(minp*1)) + ((hlen<8)?0:(hlen-8)*inchp);
  var cprice = (wprice) + (hprice);
  var dollars = Math.floor(cprice);
  var cents   = Math.round((cprice-dollars)*100);
  s.uprice.value = dollars+"."+((cents<10)?"0":"")+cents;
  return
}

// Credit Card Form display: s = object pointer
function cCard() {
  s = document.pay.payby;
  getObj('ccinput').style.display = ((s[s.selectedIndex].value=="C")?"block":"none"); 
}

function shipping() {
  window.open('shipping.php','shipping','height=450,width=500');
  return false; 
}

function verifyDelete(s) { return(confirm("Are you sure you want to delete " + s + "?")); }

function editLink(lcatid,lid)		{ window.open('admin_edit_link.php?lcatid='+lcatid+'&lid='+lid,'link','height=550,width=500,scrollbars,resizable'); return false; }
function editLinkCat(lcatid)		{ window.open('admin_edit_lcat.php?lcatid='+lcatid,'lcat','height=500,width=500,scrollbars,resizable'); return false; }
function editLinkmode()		{ window.open('admin_edit_linkmode.php','lmode','height=200,width=300,scrollbars,resizable'); return false; }
function editOrder(ADM_FUNC,oid)	{ window.open('admin_orders_edit.php?ADM_FUNC='+ADM_FUNC+'&oid='+oid,'orders','height=100,width=10'); return false; }
