// Utility functions for working with Objects cross browser platform.

var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function getObj(oname){		
	           	
     if ((ie4 || ie5)) return document.all[oname];	
     if (ns4) return document.layers[oname];
     if (ns6) return document.getElementById(oname);     
     return null; // Unsupported browser.
}

var pCnt=0;

function uc(cb) {
	if(cb.checked) pCnt++;
	else pCnt--;
	if(pCnt<0)pCnt=0;
}

function trim(s) {
  if(typeof(s)!='string') return s;
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isEmailAddr(Email)
{
  var result = false;
  var theStr = new String(Email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function sbIsValid() {
	var r='';
	if(trim(document.form1.firstname.value)=='') r+='\n - First Name';
	if(trim(document.form1.lastname.value)=='') r+='\n - Last Name';
	if(trim(document.form1.city.value)=='') r+='\n - City';
	if(trim(document.form1.state.value)=='') r+='\n - State';
	if(trim(document.form1.zip.value)=='') r+='\n - Zip Code';
	if(trim(document.form1.country.value)=='') r+='\n - Country';
	
	if(r=='' && !isEmailAddr(document.form1.email.value)) r+='\n - Valid Email Address';
	
	/* Optional fields.  Uncomment to make required */
	//if(trim(document.form1.localdealer.value)=='') r+='\n- Local Dealer.';
	//if(trim(document.form1.POno.value)=='') r+='\n- PO.';
			 
	 if(r!='') {
	 	 alert('Please enter the following:' +r);
	 	 return false;
		}

	return true;
}


function sbSubmit() {
	if(sbIsValid()) document.form1.submit();	
}


