

var currency = "$" ;




function make_code()
{
	


	var code = '<form name="form1" action="http://www.quotebreeze.com/cgi-bin/startquote.cgi" method="post">' ;

	code = code + '\n<input type="hidden" name="id" value="' + document.form.orig_id.value +'">' ;
	code = code + '\n<input type="hidden" name="defstate" value="' + document.form.state.value +'">' ;
	code = code + '\n<input type="hidden" name="tf" value="-1">' ;
	code = code + '\n<select size="1" name="type">' ;

	code = code + '\n<option value="-" selected>- Choose Insurance Type -</option>' ;

	if (document.form.lines_auto.checked) code = code + '\n<option value="car">Auto</option>' ;
	if (document.form.lines_home.checked) code = code + '\n<option value="home">Home</option>' ;
	if (document.form.lines_life.checked) code = code + '\n<option value="life">Life</option>' ;
	if (document.form.lines_health.checked) code = code + '\n<option value="health">Health</option>' ;
	if (document.form.lines_ltcare.checked) code = code + '\n<option value="ltcare">Long Term Care</option>' ;

	code = code + '\n</select>' ;
	code = code + '\n<p><input type="image" height="24" alt="Get Quote" width="101" src="http://www.quotebreeze.com/buttons/getquote.gif"></p>' ;
    code = code + '\n</form>' ;


	document.form.quote_code.value = code ;



}

function init_code()
{

var len=document.form.state.options.length;
for (i=0;i<len;i++) {
if (document.form.state.options[i].value == document.form.defstate.value) {
document.form.state.selectedIndex = i ;

   }
   
   make_code() ;
}



}




 //take out stuff....reuse it...

function validate_email(field) {

	if (field.value.length == 0) return ;

		  if (! emailCheck(field.value))
		  {
		  //alert("Invalid cell phone email address. Please enter a correct phone number with area code.");
		  field.focus();
		  field.select();
		  return ;
		  }



}


function cellco_check(field)
{

if (field.value.substr(0,1) == "-")
	alert ("If your wireless company is not in this list, you must enter the email address for your cell phone instead of the phone number. An example is '1234567890@mobile.att.net'. To find out the email address for your cell phone, please contact your wireless company or look on their website.")

}

function validate_number(field) {

if (field.value.length == 0) return ;

var valid = "0123456789"

var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";

}

if (ok == "no") {
alert("Invalid number. Please enter a valid number.");
field.focus();
field.select();
return ;
 }
}


function validate_decnumber(field) {

if (field.value.length == 0) return ;

var valid = ".0123456789"

var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";

}

if (ok == "no") {
alert("Invalid number. Please enter a valid number.");
field.focus();
field.select();
return ;
 }
}


function validate_phone(field) {


if (field.value.length == 0) return ;

var valid = "()-+0123456789"

var ok = "yes";
var digits = 0
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
if (valid.indexOf(temp) > 3 ) digits++ ;

}

if (ok == "no") {
alert("Invalid phone number. Please enter a correct phone number with area code.");
field.focus();
field.select();
return ;
   }


if (digits < 10) {
alert("Incomplete phone number. Please enter the full phone number with area code.");
field.focus();
field.select();
return ;
   }
}


function cp_presub()
{


	if (!document.form.docell.checked && !document.form.dofax.checked && !document.form.dovoice.checked && !document.form.doemail.checked && (document.form.status.value == 1))
	   {

		 alert("You must enable at least one way to deliver orders to your restaurant: cell phone, fax, voice call, or email. Or you must change the status to disable online ordering.")
         return false ;

       }

	if (document.form.docell.checked)
	  {
		 if (document.form.cellnumber.value.length == 0)
		   {
			   alert("You have turned on cell phone delivery of orders. You must enter a cell phone number.")
			   document.form.cellnumber.focus() ;
		       document.form.cellnumber.select() ;
		       return false ;
		   }
      }


	if (document.form.dofax.checked)
	  {
		 if (document.form.faxnum.value.length == 0)
		   {
			   alert("You have turned on fax delivery of orders. You must enter a fax number.")
			   document.form.faxnum.focus() ;
		       document.form.faxnum.select() ;
		       return false ;
		   }
      }


	if (document.form.dovoice.checked)
	  {
		 if (document.form.phone2email.value.length == 0)
		   {
			   alert("You have turned on voice phone call delivery of orders. You must enter a voice service email address.")
			   document.form.phone2email.focus() ;
		       document.form.phone2email.select() ;
		       return false ;
		   }
      }


	if (document.form.doemail.checked)
	  {
		 if (document.form.email.value.length == 0)
		   {
			   alert("You have turned on email delivery of orders. You must enter an email address.")
			   document.form.email.focus() ;
		       document.form.email.select() ;
		       return false ;
		   }
      }

		 if (document.form.phone.value.length == 0)
		   {
			   alert("Please enter the phone number for your restaurant's takeout service.")
			   document.form.phone.focus() ;
		       document.form.phone.select() ;
		       return false ;
		   }



   if (! check_menu(0))
     {
		document.form.menu.focus() ;
   		return false ;
     }




   var t = new Date();
   var h = t.getHours();
   var d = t.getUTCDate() ;



   document.form.currtime.value = h + "," + d ;



  return true ;

}


function validate_cell(field) {


	if (field.value.length == 0) return ;

	if (field.value.indexOf("@") > -1)
	  {

		  if (! emailCheck(field.value))
		  {
		  //alert("Invalid cell phone email address. Please enter a correct phone number with area code.");
		  field.focus();
		  field.select();
		  return ;
          }

      }
     else validate_phone(field)


}


function emailCheck (emailStr) {



/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Please enter a valid email address.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Please enter a valid email address.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("TPlease enter a valid email address.");
return false;
   }
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid

alert("Please enter a valid email address.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Please enter a valid email address.");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Please enter a valid email address.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("Please enter a valid email address.");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}




function check_menu(showmsg)
{

    currency = document.form.currency.value ;

    var m = document.form.menu.value ;
    found_error = 0 ;

	//alert(m) ;

	var prev_line = "" ;

	var proc = m + "\n";

	r = proc.indexOf("\n")

	n = 0 ;

	while (r)
	  {

		 line = proc.substr(0, r)
		 proc = proc.substr(r+1, proc.length) ;

		 n++


		 //alert(line) ;


		 if (line.substr(0,1) == "-")
		   {
			   if (prev_line.length > 2)
			     {
					alert("Error in Menu on line #" + n +": Section heading should be preceeded by a blank line:" + line)
					found_error = 1
					break ;

			     }


			}

		if (prev_line.substr(0,1) == "-")
		   {
			   if (line.length > 2)
			     {
					alert("Error in Menu on line #" + n +": Section heading should be followed by a blank line: " + prev_line)
					found_error = 1
					break ;

			     }


			}


		 if ((prev_line.length < 3) && (line.length > 3) && (line.substr(0,1) != "-"))
		    {

				if (line.substr(0,1) != "#")
				  {

					 alert("Error in Menu on line #" + n +": Missing Item Number (line must start with #), or you may have a blank line where there should not be one: " + line)
					 found_error = 1
					 break ;

			      }

			     k = line.indexOf(" ")

			     if ((k > 6) || (k < 2))
				  {

					 alert("Error in Menu on line #" + n +": This line must start with an item number followed by a space: " + line)
					 found_error = 1
					 break ;

			      }


				 k = line.indexOf("---")

				 if (k < 0)
				  {

					 alert("Error in Menu on line #" + n +": Missing '---' (3 hyphens prior to the price): " + line)
					 found_error = 1
					 break ;

				  }

				 endline = line.substr(k, line.length)

				 k = endline.indexOf(currency)

				 if (k < 0)
					{

						 alert("Error in Menu on line #" + n +": Missing '" + currency + "'. This line must include the price with currency symbol: " + line)
						 found_error = 1
						 break ;

					}

		    }

		  k = line.indexOf("++")

		  if (k > 0)
		    {

				alert("Error in Menu on line #" + n +": '++' must be at the beginning of the line: " + line)
				found_error = 1
				break ;
		    }

		  if (k == 0)
		   {
			   if (prev_line.length < 3)
				{

					alert("Error in Menu on line #" + n +": You cannot have a blank line before this line with menu addon items:" + line)
					found_error = 1
					break ;
				}

			   if ( (line.indexOf("<") < 0) && (line.indexOf("=") < 0) && (line.indexOf(currency) < 0) )
				{

					alert("Error in Menu on line #" + n +": This addon item line must either indicate a maximum or exact number of items (example: '<3' or '=1') and/or a price for each item (example: $1.50): " + line)
					found_error = 1
					break ;
				}

			   k = line.indexOf(":")
			   endline = line.substr(k+1,line.length)
			   k2 = endline.indexOf(":")

			   if ((k < 0) || (k2 < 0))
				{

					alert("Error in Menu on line #" + n +": This addon item line must include 2 colons ':', one after the addon label and a second before the first item: " + line)
					found_error = 1
					break ;
				}

	        }


		 //if (n > 4) break ;


		 prev_line = line ;
		 r = proc.indexOf("\n")

		 if (proc.length < 3) break ;
 	   }


  if ((found_error == 0) && (showmsg > 0)) alert("No errors were found in your menu.")

  if (found_error > 0) return false ;

  return true ;


}






function format_menu(showmsg)
{

    currency = document.form.currsym.value ;

    if (currency == "") currency = "$"

    var m = document.form.inmenu.value ;
    found_error = 0 ;



	var prev_line = "" ;

	var proc = m + "\n" ;



	r = proc.indexOf("\n")



	n = 0 ;
	var item = document.form.start.value
	if (item == "") item = 1


	document.form.prefix.value = document.form.prefix.value.replace(/ /g,"")

	var valid = "123456789"

	var newproc = ""

	while (r)
	  {


		 line = proc.substr(0, r)

		 proc = proc.substr(r+1, proc.length) ;



		 n++


         d = line.indexOf(currency)

         if (d < 0)
           {

			   if (document.form.nodollar.checked)
			     {

			        j = line.length - 1

			        v = valid + "."

			        if (currency != "$") v = v +","


			        found = 0

			        while ((found == 0) && (j > 0))
			          {

						  if (valid.indexOf(line.substr(j,1)) >= 0)
						  	{
							   found = 1
							   break ;
						    }

						  j-- ;
				      }


				     if (found)
				      {

						  found = 0



							while ((found == 0) && (j > 0))
							  {

								  if (v.indexOf(line.substr(j,1)) < 0)
									{
									   found = 1
									   break ;
									}

								  j-- ;

							  }


						    if (found)

						      {
								  d = j + 1

								  b = line.substr(0, d-1)
								  a = line.substr(d, line.length)

								  line = b + currency + a


						       }




				      }


			     }
	        }

         if (d >=0)
           {


			  nline = line ;
			  nline = nline.replace(/\t/g," ")

			  while (nline.substr(0,1) == " ") nline = nline.substr(1,nline.length) ;

 			  nline2 = ""

			  while (nline != nline2)
			   {
			     nline2 = nline
			  	 nline = nline.replace(/\.\./g,".")

			   }

			  nline2 = ""

			  while (nline != nline2)
			   {
			     nline2 = nline
			  	 nline = nline.replace(/  /g," ")

			   }

			  nline2 = ""

			  while (nline != nline2)
			   {
			     nline2 = nline
			  	 nline = nline.replace(/--/g,"-")

			   }


			  nline = nline.replace(/ \. /g," ")


			  f = nline.substr(0,1)


			  if (f != "#")
			    {

				  if (! document.form.hasitems.checked)
				   {


						  nline = "#"+ document.form.prefix.value + item + " " + nline
						  item++ ;

				    }
				   else nline = "#" + nline


			    }

			  d = nline.indexOf(currency)

			  b = nline.substr(0, d-1)
			  a = nline.substr(d, nline.length)

			  nline = b + " --- " + a + "\n\n"

			  newproc = newproc + nline

		   }



	     prev_line = line ;
		 r = proc.indexOf("\n")

		 if (proc.length < 3) break ;
 	   }

  if (newproc.length < 4) alert ("No menu items where found. Do your prices have a currency symbol ($)? If not, please check the box above.")


  document.form.menu.value = newproc ;


  return true ;


}