//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(/xx/i);
	if (r == -1){r = s.search(/xxx/i);}
	if (r == -1){r = s.search(/x.x.x./i);}
	if (r == -1){r = s.search(/xnitex xtatex/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 checkRequiredTextArea(theField,theMessage)
{
if (theField.text == "")
{
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 (getRadioValue(document.frmInc.ExpressFilingService) == 1){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
temp = getRadioValue(document.frmInc.KitNeeded);
if (temp == 1){mdblAddServices = mdblAddServices + 65;}

//TaxID
temp = getRadioValue(document.frmInc.TaxIDNeeded);
if (temp == 1){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);

parent.tally_frame.update_tally(mdblStateFee, mdblAgentFee, mdblAddServices, mdblShipping, mdblTotal);
	
	return true;
}

function set_service()
{
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "CA")
	document.frmInc.ExpressFilingService[1].checked = true;

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "MD")
	document.frmInc.ExpressFilingService[1].checked = true;

//    if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "NC")
//	window.top.location="https://www.incorporatetime.com/north_carolina.htm";
}

function check_service(form)
{

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "CA")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		var popurl="CaliforniaPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=380,height=340,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(380/2),screen.availHeight/2-(340/2));
		document.frmInc.ExpressFilingService[1].checked = true;
	}

	else if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "MD")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		var popurl="MarylandPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=380,height=340,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(380/2),screen.availHeight/2-(340/2));
		document.frmInc.ExpressFilingService[1].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")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		document.frmInc.SharesIssued.focus();
		var popurl="SharesParPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=275,height=165,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(280/2),screen.availHeight/2-(165/2));
		document.frmInc.ExpressFilingService[1].checked = true;
	}

	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "KY")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		document.frmInc.SharesIssued.focus();
		var popurl="SharesParPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=275,height=165,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(280/2),screen.availHeight/2-(165/2));
		document.frmInc.ExpressFilingService[1].checked = true;
	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "OH")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		document.frmInc.SharesIssued.focus();
		var popurl="SharesParPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=275,height=165,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(280/2),screen.availHeight/2-(165/2));
		document.frmInc.ExpressFilingService[1].checked = true;

	}
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "NY")
	{
		//alert("You must choose Expedited State Filing Service for the State of California.");
		document.frmInc.SharesIssued.focus();
		var popurl="SharesParPrompt.htm";
		var viewimageWin=window.open(popurl,"","width=275,height=165,scrollbars=1");
		viewimageWin.moveTo(screen.availWidth/2-(280/2),screen.availHeight/2-(165/2));
		document.frmInc.ExpressFilingService[1].checked = true;
	}

}

function PopFee()
{
	var popurl="FeePrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}
function PopNaming()
{
	var popurl="CorporateNamePrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}

function PopAgentServices()
{
	var popurl="AgentServicesPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=375,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(375/6));
	return false;
}
function PopNumShares()
{
	var popurl="StockPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=205,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(205/6));
	return false;
}
function PopCorpOfficer()
{
	var popurl="CorpOfficerPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=200,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(200/6));
	return false;
}
function PopDirectors()
{
	var popurl="DirectorsPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=200,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(200/6));
	return false;
}
function PopCorpKit()
{
	var popurl="CorpKitPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}
function PopNamingLLC()
{
	var popurl="LLCNamePrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}
function PopOrgStructureLLC()
{
	var popurl="OrgStructureLLCPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=150,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(150/6));
	return false;
}
function PopLLCKit()
{
	var popurl="LLCKitPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}
function PopTerms()
{
	var popurl="TermsPrompt.htm";
	var viewimageWin=window.open(popurl,"","width=395,height=250,scrollbars=1");
	viewimageWin.moveTo(screen.availWidth/1.5-(395/1.5),screen.availHeight/6-(250/6));
	return false;
}
function CharCheck()
{
	if(checkRequiredSelect(document.frmInc.State,"Please select a state.",true)){return false;}
//	changed 08-31-05 craig for new jersey error on form 
	if(document.frmInc.State.options[document.frmInc.State.selectedIndex].value == "XX")
	{
//	      var ValidChars(0) = "!%^&'*()_-+=.,<>?;:@#''`$|\/[]{}~";
//	      var ValidChars(0) = "!%^&'*()_-+=.,<>?;:@#''`$|\/[]{}~";

	      var ValidChars = "!%^&'*()_-+=.,<>?;:@#''`$|\/[]{}~";
//	      var ValidChars = "!%^&'*()_-+=.,<>?;:@#''`$|\/[]{}~";

	      var IsValid=true;
	      var Char;
	      var sText = document.frmInc.CompanyNameFirstchoice.value
 
              for (i = 0; i < ValidChars.length && IsValid == true; i++) 
	      { 
		      Char = ValidChars.charAt(i);
		      if (sText.indexOf(Char) != -1) 
	              {
		         IsValid = false;
		      }
      	      }
	if(IsValid == false)
	{
              alert("You have entered an invalid company name.");
	}
	return IsValid;
	}
	else
	{
	return true;
	}
//		if (document.frmInc.CompanyNameFirstchoice.value == "!")
//		{
//			alert("You have entered an invalid company name.");
//			document.frmInc.CompanyNameFirstchoice.focus();
//			return false;
//		}
}