//State Fees
var maryStateFees = new Array();
var maryExpeditedStateFees = new Array();
var maryShippingFees = new Array();

function checkForCountry(theSelect)
{
var r;
var s = theSelect.value.toLowerCase();

	r = s.search(/us/i);
	if (r == -1){r = s.search(/usa/i);}
	if (r == -1){r = s.search(/u.s.a./i);}
	if (r == -1){r = s.search(/united states/i);}
	if (r == 0)
	{
		alert("Please enter a COUNTY.");
		theSelect.focus();
		return true;
	}
	
	return false;
}

function checkForPOBox(theText)
{
var r;
var s = theText.value.toLowerCase();

	r = s.search(/po/i);
	if (r == -1){r = s.search(/pob/i);}
	if (r == -1){r = s.search(/p.o. box/i);}
	if (r == -1){r = s.search(/po box/i);}
	if (r == 0)
	{
		alert("We are unable to ship to P.O. Boxes. Please enter a physical address.");
		theText.focus();
		theText.select();
		return true;
	}
	
	return false;
}

function isInteger(theField, emptyOK, theMessage)
{
  if (theField.value == "")
  {
	if (emptyOK)
	{
		return(true);
	}
	{
		alert(theMessage);
		theField.focus();
		theField.select();
	  return (false);
	}
  }

    var i;
    var s = theField.value;
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (!((c >= "0") && (c <= "9")))
        {
			alert(theMessage);
			theField.focus();
			theField.select();
            return (false);
        }
    }

  return (true);
}

function isNumeric(theField, emptyOK, theMessage)
{
  if (theField.value == "")
  {
	if (emptyOK)
	{
		return(true);
	}
	{
		alert(theMessage);
		theField.focus();
		theField.select();
	  return (false);
	}
  }
  
  var checkOK = "0123456789.";
  var checkStr = theField.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (allValid)
  { return(true) }
  {
	alert(theMessage);
	theField.focus();
	theField.select();
    return (false);
  }
}

function isEmpty(theField,theMessage)
{
if (theField.value == "")
	{	
	alert(theMessage);
	theField.focus();
	theField.select();
	return(true);
	}
	{
	return(false);
	}
}

function checkRequiredTextField(theField,theMessage)
{
if (theField.value == "")
{
alert(theMessage);
theField.focus();
return true;
}
return false;
}

function checkRequiredSelect(theField,theMessage,blnFirstOK)
{
var pSelectedIndex = theField.selectedIndex;
if (pSelectedIndex == -1)
{
alert(theMessage);
theField.focus();
return true;
}

if (!blnFirstOK)
{
	if (pSelectedIndex == 0)
	{
	alert(theMessage);
	theField.focus();
	return true;
	}
}

return false;
}

function getSelectValue(theSelect)
{

	if (theSelect.selectedIndex == -1)
	{
		return('');
	}else{
		return(theSelect.options[theSelect.selectedIndex].value);
	}

}

function letSelectValue(theSelect,theValue)
{

	for (var i = 0;  i < theSelect.options.length;  i++)
	{
		if (theSelect.options[i].value == theValue)
		{
			theSelect.selectedIndex = i;
			return true;
		}
	}
	
	return false;
}

function getRadioValue(theRadio)
{
	  for (var i = 0;  i < theRadio.length;  i++)
	  {
		if (theRadio[i].checked)
		{
		return(theRadio[i].value);
		}
	  }
}

function getRadioValueSelectedIndex(theRadio)
{
	  for (var i = 0;  i < theRadio.length;  i++)
	  {
		if (theRadio[i].checked)
		{
		return(i);
		}
	  }
	  return(-1);
}

dateVar = new Date();
weekday = dateVar.getDay();
if(weekday == 0){d_weekday = "Sunday";}
if(weekday == 1){d_weekday = "Monday";}
if(weekday == 2){d_weekday = "Tuesday";}
if(weekday == 3){d_weekday = "Wednesday";}
if(weekday == 4){d_weekday = "Thursday";}
if(weekday == 5){d_weekday = "Friday";}
if(weekday == 6){d_weekday = "Saturday";}

day = dateVar.getDate();
month = dateVar.getMonth();
if(month == 0){d_month = "January";}
if(month == 1){d_month = "February";}
if(month == 2){d_month = "March";}
if(month == 3){d_month = "April";}
if(month == 4){d_month = "May";}
if(month == 5){d_month = "June";}
if(month == 6){d_month = "July";}
if(month == 7){d_month = "August";}
if(month == 8){d_month = "September";}
if(month == 9){d_month = "October";}
if(month == 10){d_month = "November";}
if(month == 11){d_month = "December";}
year = dateVar.getYear();
if(year < 100){year += 1900;}

function update_stock(form){

var mdblStateFee;
var mdblAgentFee;
var mdblAddServices;
var mdblShipping;

if(checkRequiredSelect(document.frmInc.State,"Please select a state.",true)){return false;}

//Set Service option.
set_service();

//Set Shares Issued.
set_shares();

var temp = document.frmInc.State.selectedIndex;
if (temp == -1){return false;}
mdblStateFee = maryStateFees[temp];

//expedited
if (document.frmInc.ExpressFilingService.checked){mdblAddServices = maryExpeditedStateFees[temp];}else{mdblAddServices = 0;}

temp = getRadioValueSelectedIndex(document.frmInc.Shipping);
if (temp != -1)
{
mdblShipping = maryShippingFees[temp+1];
}

temp = getRadioValue(document.frmInc.Agent);
if (temp == 1){mdblAgentFee = 99;}else{mdblAgentFee = 0;}

//additional services

//corp kit
if (document.frmInc.KitNeeded.checked){mdblAddServices = mdblAddServices + 65;}

//TaxID
if (document.frmInc.TaxIDNeeded.checked){mdblAddServices = mdblAddServices + 25;}

//Prepare SCorp
temp = document.frmInc.PrepareSCorpDocument.checked;
if (temp){mdblAddServices = mdblAddServices + 25;}

var mdblTotal = mdblShipping+mdblAgentFee+mdblAddServices+mdblStateFee;

//alert(mdblShipping);
//alert(mdblAgentFee);
//alert(mdblAddServices);
//alert(mdblStateFee);

//update_tally(mdblStateFee, mdblAgentFee, mdblAddServices, mdblShipping, mdblTotal);
parent.tally_frame.update_tally(mdblStateFee, mdblAgentFee, mdblAddServices, mdblShipping, mdblTotal);
	
	return true;
}

function update_tally(stateFee, agentFee, optionsFee, deliveryFee, totalFee){

	document.frmTally.state_fees.value = stateFee;
	document.frmTally.agent_fees.value = agentFee;
	document.frmTally.options.value = optionsFee;
	document.frmTally.delivery.value = deliveryFee;
	document.frmTally.total.value = "$" + totalFee;

	return true;
}

function set_service()
{

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "CA")
	document.frmInc.ExpressFilingService.checked = true;
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "MD")
	document.frmInc.ExpressFilingService.checked = true;


}

function check_service(form)
{

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "CA")
	{
		alert("Currently, standard filings in California are in excess of 10 weeks. Thus, due to these delays, we are only accepting expedited filings in the state of California. As an expedited filing, we will hand deliver your documents to the secretary of state. Our walk in filings are accomplished within 12-14 business days.");
		document.frmInc.ExpressFilingService.checked = true;
	}
	else if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "MD")
	{
		alert("Currently, standard filings in Maryland are in excess of 10 weeks. Thus, due to these delays, we are only accepting expedited filings in the state of Maryland. As an expedited filing, we will hand deliver your documents to the secretary of state. Our walk in filings are accomplished within 12-14 business days.");
		document.frmInc.ExpressFilingService.checked = true;
	}
	else
	{
		update_stock(form);
	}	
}

function set_shares()
{
	document.frmInc.SharesIssued.value = 2000;
	document.frmInc.ParValue.value = ".01";

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "DE")
	{	
		document.frmInc.SharesIssued.value = 1500;
		document.frmInc.ParValue.value = 0;
	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "KY")
	{
		document.frmInc.SharesIssued.value = 1000;
		document.frmInc.ParValue.value = ".01";
	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "OH")
	{	
		document.frmInc.SharesIssued.value = 850;
		document.frmInc.ParValue.value = ".01";
	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "NY")
	{
		document.frmInc.SharesIssued.value = 200;
		document.frmInc.ParValue.value = 0;
	}
}

function check_shares(form)
{
	if(checkRequiredSelect(document.frmInc.State,"Please select a state.",true)){return false;}

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "DE")
	{
		document.frmInc.SharesIssued.focus();
 		alert("Changing the number of shares or par value may result in higher initial state filing fees or increased franchise taxes.  If you really want to effectuate such a change, you may do so in the comment section of this form.");
	}

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "KY")
	{
		document.frmInc.SharesIssued.focus();
		alert("Changing the number of shares or par value may result in higher initial state filing fees or increased franchise taxes.  If you really want to effectuate such a change, you may do so in the comment section of this form.");

	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "OH")
	{
		document.frmInc.SharesIssued.focus();
		alert("Changing the number of shares or par value may result in higher initial state filing fees or increased franchise taxes.  If you really want to effectuate such a change, you may do so in the comment section of this form.");
	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "NY")
	{
		document.frmInc.SharesIssued.focus();
		alert("Changing the number of shares or par value may result in higher initial state filing fees or increased franchise taxes.  If you really want to effectuate such a change, you may do so in the comment section of this form.");
	}
}
