// JavaScript Document

// Client-side functionality for the subscription process Step One page

// 



function domainCheckPopup(pageVar)

{

   leftPos = 0;

   topPos = 0;

   if (screen)

   {

      leftPos = (screen.width/2)-300;

	  topPos = (screen.height/2)-300;  // a little higher than halfway

   }

   checkWindow = window.open(pageVar, 'checkWin', 

                             'width=500,height=300,scrollbars=yes,resizable=yes,left='+leftPos+',top='+topPos);

}

titleFlag = false;

function undecidedCheck()
{
   if (document.steponeform.date_undecided.checked)
   {
      document.steponeform.wed_month.disabled=true;
	  document.steponeform.wed_day.disabled=true;
	  document.steponeform.wed_year.disabled=true;
   }
   else
   {
      document.steponeform.wed_month.disabled=false;
  	  document.steponeform.wed_day.disabled=false;
	  document.steponeform.wed_year.disabled=false;
   }
}

function updateTitle()
{
   if ((document.steponeform.groom_first.value == "") ||
       (document.steponeform.bride_first.value == "") ||
	   (titleFlag == true))
   {
      return;
   }
   else
   {
      document.steponeform.title.value = document.steponeform.bride_first.value +
	     " and " + document.steponeform.groom_first.value + "'s Wedding Site";
   }
}



function checkChoices()  //deprecated

{

   if (document.steponeform.domainoption[0].checked)

   {

      // Option one selected - unique domain name

	  if (document.steponeform.dot_secondchoice.checked)

	  {

	     // User selected second choice to be wedshare domain

	     document.steponeform.dotname.disabled=false;

		 document.steponeform.domain1.disabled=false;

		 document.steponeform.domain2.disabled=true;

	  }

	 // else

	  //{

        // document.steponeform.dotname.disabled=true;

        // document.steponeform.domain1.disabled=false;

         //document.steponeform.domain2.disabled=false;

	 // } 

   

   }

   //else if (document.steponeform.domainoption[1].checked)

   //{

      		// Option two selected - wedshare domain name

	  // if (document.steponeform.dot_secondchoice.checked)

	  //{

	     	// User selected second choice to be wedshare domain

		// document.steponeform.domain1.disabled=false;

        // document.steponeform.dotname.disabled=true;

		// document.steponeform.dotname.disabled=false;

	 // }

	 // else

	 // {

      //   document.steponeform.domain1.disabled=true;

      //   document.steponeform.domain2.disabled=true;

	  //   document.steponeform.dotname.disabled=false;

     // }

  // }

}



function submitVerify(thisform)
{
	if (thisform.name.value == "")
   {
      alert("Please enter a contact name to associate with your account. Wedding planners, please include your company name.");
	  thisform.name.focus();
	  return false;
   }
	
   if (thisform.email.value == "")
   {
      alert("Please enter a valid email address\n where we may contact you\n with your website access details");
	  thisform.email.focus();
	  return false;
   }

   // validate email address format
   invalidChars = " /:,;"
   email = thisform.email.value;
   
   for (i=0; i < invalidChars.length; i++)
   {
      badChar = invalidChars.charAt(i);
	  if (email.indexOf(badChar,0) > -1)
	  {
	     alert("Your email address contains invalid characters");
		 thisform.email.focus();
		 return false;
	  }
   }
   
   atPos = email.indexOf("@",1);
   if (atPos == -1)
   {
      alert("Your email address seems to be missing the @ sign");
	  thisform.email.focus();
	  return false;
   }

   if (email.indexOf("@", atPos+1) > -1)
   {
      alert("There are too many @ signs in your email address");
	  thisform.email.focus();
	  return false;
   }
   
   periodPos = email.indexOf(".", atPos)
   if (periodPos == -1)
   {
      alert("Did you remember to include an extension in your email address?");
	  thisform.email.focus();
	  return false;
   }
   
   if (periodPos+3 > email.length)
   {
      alert("The extension in your email address doesn't seem to be valid");
	  thisform.email.focus();
	  return false;   
   }


   if (thisform.user_name.value == "")
   {
      alert("Please select a WedShare.com login ID");
	  thisform.user_name.focus();
	  return false;
   }
   
   result = checkValidUserName(thisform.user_name.value);
   if (result != "")
   {
	  alert("Sorry, " + thisform.user_name.value + " is not a valid login ID: " + result);
	  thisform.domain1.focus();
	  return false;
   }

   if (thisform.password1.value == "")
   {
      alert("Please enter in a password");
	  thisform.password1.focus();
	  return false;
   }
   
   if (thisform.password2.value == "")
   {
      alert("Please re-enter your password for verification");
	  thisform.password2.focus();
	  return false;
   }

   if (thisform.password1.value != thisform.password2.value)
   {
      alert("Your passwords do not match...try re-entering them");
	  thisform.password1.focus();
	  return false;
   }

   if (thisform.password1.value.length < 6)
   {
      alert("For security purposes, we ask that your password be at least 6 characters long");
	  thisform.password1.focus();
	  return false;
   }
   
   if (thisform.password1.value.length > 16)
   {
      alert("Your password is too long...limit it to 16 characters or less, please");
	  thisform.password1.focus();
	  return false;
   }
   
   if (thisform.domain1.value == "")
   {
	  alert("Please enter in a domain name as your website's name choice");
	  thisform.domain1.focus();
	  return false;
   }
	  
   result = checkValidDomain(thisform.domain1.value);
   if (result != "")
   {
	  alert("Sorry, " + thisform.domain1.value + " is not a valid domain name: " + result);
	  thisform.domain1.focus();
	  return false;
   }	    
 
   //if (thisform.gift_id.value == "")
   //{
	  // if (thisform.domain2.value == "")
	  // {
		//  alert("Please enter a second domain choice. This will be used if your first choice becomes unavailable during your free trial period.");
		 // thisform.domain2.focus();
		 // return false;
	   //}
	   
	  // result = checkValidDomain(thisform.domain2.value);
	  // if (result != "")
	  // {
		//  alert("Sorry, " + thisform.domain2.value + " is not a valid domain name: " + result);
		//  thisform.domain2.focus();
		//  return false;
	  // }
	   
	   //if ((thisform.domain1.value) == (thisform.domain2.value))
	  // {
		//  alert("Your first and second domain name choices should be different. " +
		//		"The second choice will be used if your first choice becomes unavailable during your free trial period.");
		//  return false;
	  // }
//}

	if (thisform.bride_first.value == "")
	{
      alert("Please enter the bride's first name\n for your WedShare.com website trial");
	  thisform.bride_first.focus();
	  return false;
	}

   if (thisform.groom_first.value == "")
   {
      alert("Please enter the groom's first name\n for your WedShare.com website trial");
	  thisform.groom_first.focus();
	  return false;
   }

     if (thisform.how_referred.value == "")
   {
      alert("Please let us know how you heard about us");
	  thisform.how_referred.focus();
	  return false;
   }

	if (!thisform.terms_agreement.checked)
   {
      alert("You must accept the Terms of Service and Private Policy in order to use WedShare.com's service");
	  return false;
   }
   
   document.steponeform.terms_agreement.checked;
   thisform.submit.value = 'One moment...';
   thisform.submit.disabled="true";
   return true;
}

  // check for Terms of Service and Privacy Policy Agreement Checked

// function agreementCheck()

// {

  // if (document.steponeform.terms_agreement.value == "")

  // {

    //  alert("You must accept the Terms of Service and Private Policy \n in order to use WedShare.com's service.");

	//  return false;

  // }

  // else

  // {

   

  // }

// }





function checkValidUserName(name)

{

	if (name.length < 3)

	{

		return "try a longer one.";

	}



  // check for invalid characters in user name

  invalidChars = " /:,;`~!@#$%^&*+=[]{}()|'<>\"\\";

  for (i=0; i<invalidChars.length; i++)

  {	

     badChar = invalidChars.charAt(i);

	  if (name.indexOf(badChar,0) > -1)

	  {

	     return ("try to avoid the '" + badChar + "' character.");

	  }

  }

  

  // check for names that aren't allowed

  if ((name=="root")||(name=="bin")||(name=="daemon")||(name=="adm")||(name=="lp")||(name=="sync")||(name=="shutdown")||

      (name=="halt")||(name=="mail")||(name=="news")||(name=="uucp")||(name=="operator")||(name=="games")||(name=="mysql")||

	  (name=="httpd")||(name=="nobody")||(name=="dummy")||(name=="www")||(name=="wwwrun")||(name=="cvs")||(name=="shell")||(name=="ftp")||(name=="irc")||

	  (name=="debian")||(name=="ns")||(name=="download")|(name=="wedshare"))

  {

     return ("try another.");

  }

  

  return "";

}



function checkValidDomain(name)

{

  var domain_ext=name.split(".");

  if (domain_ext.length > 2)

     return "Only one '.' should exist, dividing domain from extension";

  if (domain_ext.length < 2)

     return "A .xxx extension is required at the end of the domain name (example: .com)";

  

  domain = domain_ext[0];

  ext = domain_ext[1];

  

  // check for invalid characters in domain name

  invalidChars = " /:,;`~!@#$%^&*+=[]{}()|'<>\"\\";

  for (i=0; i<invalidChars.length; i++)

  {

     badChar = invalidChars.charAt(i);

	  if (domain.indexOf(badChar,0) > -1)

	  {

	     return (badChar + " is not a valid character.");

	  }

  }



  // check for accepted extensions

  if (ext != "com" && ext != "net" && ext != "org" && 

      ext != "info" && ext != "biz" && ext != "us")

  {

     return ("." + ext + " is not an extension we support.");

  }

  else

  {

     return "";

  }

}



function checkValidSubdomain(name)

{

  // check for invalid characters in subdomain name

  invalidChars = " /:,.;`~!@#$%^&*+=[]{}()|'<>\"\\";

  for (i=0; i<invalidChars.length; i++)

  {

     badChar = invalidChars.charAt(i);

	  if (name.indexOf(badChar,0) > -1)

	  {

	     return (badChar + " is not a valid character.");

	  }

  }



   return "";

}
