function removeAllChildNodes( node )
{
   if( node && node.hasChildNodes && node.removeChild ) {
      while( node.hasChildNodes() ) {
         node.removeChild( node.firstChild );
      }
   }
}


function signup1( formName, emailField, colocField, locationid )
{
   var	obj,
	addr,
	indx,
	domain,
	eml,
	li,
	ln,
	html,
	cell,
	bold,
	text,
	input,
	select,
	option,
	index,
	i;


// alert( "here" );
   obj  = document.forms[formName][emailField];
   addr = obj.value;
   // alert( "addr is " + addr );

   if( (addr == "") || (addr.length == 0) ) {
      return( true );
   }

   indx = addr.indexOf( '@' );
   if( indx <= 0 ) {
      alert( "Invalid work email address.  Please try again." );
      obj.focus();
      return( false );
   }

   domain = addr.substring( indx ).toLowerCase();
   // alert( domain );

   for( ii=0; ii<disabledom.length; ii++ ){
      if( domain == disabledom[ii].toLowerCase() ) {
		   // alert("We are experiencing some technical difficulties and are unable to complete your request.  Please contact us at support@sitelerwash.com to schedule your wash.");
		   // bug 516 august release 2007
		   alert("We apologize for the inconvenience, but Google employees have a new proccess. You will be redirected to " + document.domain + "/google to reserve your spot. If you are trying to make a payment for your service, you will be billed via email within 24hrs from the date of the service. If you have further enquiries, please call us at 888-SITE-LER (748-3537) or email support@sitelerwash.com.");
		   var domain1 = "";
		   var proto = window.location.protocol;
		   proto = proto.toLowerCase();		  
		   if(proto.indexOf( "https:" ) >= 0 )
				domain1 = "https://" + document.domain + "/google/";
		   else if( proto.indexOf( "http:" ) >= 0 )			
			domain1 = "http://" + document.domain + "/google/";
		   window.location.href =  domain1 ;	
		   // end bug 516 august release 2007
			return (false);
		 }
       }

   indx = -1;
   for( i=0; i<dom.length; i++ ) {
      if( domain == dom[i].toLowerCase() ) {
         indx = i;
         break;
      }
   }

   if( indx < 0 ) {
      alert( "We do not recognize your company by the work email address you entered - Make sure you use your company-provided email address. If your company is currently not being serviced by Siteler, please contact us at sales@SitelerWash.com." );
      cell = document.getElementById('coloc');
      removeAllChildNodes(cell);
      obj.focus();
      return( false );
   }

   html  = '';
   html += '<input type=hidden name="companyid" value="';
   html += cid[indx] + '">\n';
   html += '<b>' + cnm[indx] + '</b>\n';

   li = lid[indx].split( "|" );
   ln = lnm[indx].split( "|" );
   html += '<select name="locationid">\n';
   html += '<option value="">- select location -\n';
   for( i=0; i<li.length; i++ ) {
      html += '<option value="' + li[i] + '">' + ln[i] + '\n';
   }
   html += '</select>\n';

   // alert( html );
   // document.forms[formName][colocField].value = html;


   cell = document.getElementById('coloc');
   removeAllChildNodes(cell);

   // add company name in bold
   bold = document.createElement( "B" );
   text = document.createTextNode( cnm[indx] + " " );
   bold.appendChild( text );
   cell.appendChild( bold );

/*
   // mac ie doesn't like creating hidden vars in dhtml
   input = document.createElement( "INPUT" );
   input.setAttribute( "type" , "hidden"    );
   input.setAttribute( "name" , "companyid" );
   input.setAttribute( "value", cid[indx]   );
   cell.appendChild( input );
*/

   document.forms[formName]['companyid'].value = cid[indx];

   // create location menu
   select = document.createElement( "SELECT" );
   select.setAttribute( "name", "locationid" );

   if( li.length > 1 ) {
      option = new Option( "- select location -", "" );
      select.options[select.options.length] = option;
   }

   index = -1;
   for( i=0; i<li.length; i++ ) {
      if( li[i] == locationid ) {
         index = i + 1;
      }
      option = new Option( ln[i], li[i] );
      select.options[select.options.length] = option;
   }
   cell.appendChild( select );


   if( index >= 0 ) {
      select.options[index].selected = true;
   }

   select.focus();

   return( true );
}


function signup2( formName, emailField )
{
   var	obj,
	addr,
	indx,
	domain,
	eml,
	li,
	ln,
	html,
	cell,
	bold,
	text,
	input,
	select,
	option,
	index,
	i;


// alert( "here" );
   obj  = document.forms[formName][emailField];
   addr = obj.value;
   // alert( "addr is " + addr );

   if( (addr == "") || (addr.length == 0) ) {
      return( true );
   }

   indx = addr.indexOf( '@' );
   if( indx <= 0 ) {
      alert( "Invalid work email address.  Please try again." );
      obj.focus();
      return( false );
   }

   domain = addr.substring( indx ).toLowerCase();
   // alert( domain );


   indx = -1;
   for( i=0; i<dom.length; i++ ) {
      if( domain == dom[i].toLowerCase() ) {
         indx = i;
         break;
      }
   }

   if( indx < 0 ) {
      alert( "We do not recognize your company by the work email address you entered - Make sure you use your company-provided email address. If your company is currently not being serviced by Siteler, please contact us at sales@SitelerWash.com." );
      obj.focus();
      return( false );
   }

   // pre-select company
   obj = document.forms[formName]['companyid'];
   for( i=0; i<obj.length; i++ ) {
      obj.options[i].selected = false;
      if( obj.options[i].value == cid[indx] ) {
         obj.options[i].selected = true;
      }
   }

   // pre-select location
   li = lid[indx].split( "|" );
   obj = document.forms[formName]['locationid'];
   for( i=0; i<obj.length; i++ ) {
      obj.options[i].selected = false;
      if( obj.options[i].value == li[0] ) {
         obj.options[i].selected = true;
      }
   }

   obj = document.forms[formName]['locationid'].focus();

   return( true );
}


function validateCheckbox( formName, fieldName, label )
{
   var  obj,
        selected;


   obj = document.forms[formName][fieldName];
   if( obj == null ) {
      alert( 'undefined obj for ' + label + ' checkbox' );
      return( false );
   }

   selected = obj.checked;

   if( ! selected ) {
      alert( 'Please check the box to indicate you agree to our Terms and Conditions and Privacy Policy.' );
      obj.focus();
      return( false );
   }


   return( true );
}




