//mchk makes sure when a workshop is selected that a payment method is also selected
var mchk = 0
var nabb = new Array()
var abb = new Array()
//This function disables all workshops that occur in the past, it also disables the payment method until
//a workshop is chosen
function disable(){
var ecom = document.workshopreg
var d = new Date();
two4one()
nabbpop()
for(a=0; a < nabb.length; a++){
	for(i=0; i <  semdate.length; i++){
		if(nabb[a] == ecom.registration[i].value){
			if(semdate[i]<d){
				ecom.registration[i].disabled = true
				break;
			}
		}
	}
}
for(i=0;i<ecom.registration.length;i++){
	if(ecom.registration[i].checked == true){
		
		break;
	}
	else{
		totals = ecom.registration.length
		if(i>=totals-1){
			for(ja=0;ja<ecom.METHOD.length;ja++){
			ecom.METHOD[ja].disabled = true
			}
		}
	}
}
}
//This function enables the payment method as soon as a workshop is chosen
function enable(){
var ecom = document.workshopreg
for(i=0;i<ecom.registration.length;i++){
	if(ecom.registration[i].checked == true){
		for(z=0;z<ecom.METHOD.length;z++){
			ecom.METHOD[z].disabled = false
			}
	break;
	}
}
}

//This function unselects a workshop in the event that the user has selected a workshop but changed their mind
//and wants to send us contact info but not register for a workshop at this time
/*function uncheck(){
var ecom = document.workshopreg
for(i=0;i<ecom.registration.length;i++){
	if(ecom.registration[i].checked == true){
		ecom.registration[i].checked = false
	}
}
for(i=0;i<ecom.METHOD.length;i++){
	if(ecom.METHOD[i].checked == true){
	ecom.METHOD[i].checked = false
	}
	ecom.METHOD[i].disabled = true
}
ecom.whoops.checked = false
mchk=0
}*/

//This function enables/disables the Country & State selections for users outside the US
function nonUS(){
var ecom = document.workshopreg
if(ecom.stateselector.checked == true){
ecom.nonstate.disabled = false
ecom.nonstate.value = ""
ecom.STATETOSHIP.disabled = true
ecom.STATETOSHIP.value = "NA"
ecom.COUNTRYTOSHIP.disabled = false
ecom.COUNTRYTOSHIP.value = ""
}
else{
ecom.nonstate.disabled = true
ecom.nonstate.value = "For Non-US Residents"
ecom.STATETOSHIP.disabled = false
ecom.STATETOSHIP.value=""
ecom.COUNTRYTOSHIP.disabled = true
ecom.COUNTRYTOSHIP.value = "USA"
}
}

/*This function sets the price of the workshop and sets the description for the reciept.
  If an additional workshop is added (like maybe one for csfss2), make sure to add two lines like the ones between
  the dashes, under the switch(m) statement.
  ---------------------------------------------------------------------------------------------------------------
  case "BUTTON VALUE":
  desc = workshop[490000]
  ---------------------------------------------------------------------------------------------------------------
  The number inside the brackets will be determined by where you added it to the workshop descriptions at the top of the
  script.
*/
function price(){
	
//m is a placeholder for the registration value
//c is the Standard Cost of the workshops
var ecom = document.workshopreg
var m
c = costmech()
for(i=0;i<ecom.registration.length;i++){
	if(ecom.registration[i].checked==true){
	m = ecom.registration[i].value
	break;
	}
}

if(m!=null){
description(m)
document.workshopreg.DESCRIPTION.value = desc

if(ecom.stateselector.checked == false){
	ecom.STATETOSHIP.value = ecom.STATETOSHIP.value
	ecom.COUNTRYTOSHIP.value = "USA"
}
else{
	ecom.STATETOSHIP.value = ecom.nonstate.value
}

ecom.AMOUNT.value = c

if(mchk != 0){
	payment()
}
else{
	alert("You must choose a payment method")
}
}
}

//this function is to allow users to specify that their billing info is the same as the customer info.
function billing(){
var ecom = document.workshopreg
if(ecom.samebill.checked == true){
	ecom.NAME.value = ecom.NAMETOSHIP.value
	ecom.ADDRESS.value = ecom.ADDRESSTOSHIP.value
	ecom.CITY.value = ecom.CITYTOSHIP.value
	ecom.STATE.value = ecom.STATETOSHIP.value
	ecom.ZIP.value = ecom.ZIPTOSHIP.value
	ecom.COUNTRY.value = ecom.COUNTRYTOSHIP.value
	ecom.EMAIL.value = ecom.EMAILTOSHIP.value
	ecom.PHONE.value = ecom.PHONETOSHIP.value
}
else{
	ecom.NAME.value = ""
	ecom.ADDRESS.value = ""
	ecom.CITY.value = ""
	ecom.STATE.value = ""
	ecom.ZIP.value = ""
	ecom.COUNTRY.value = ""
	ecom.EMAIL.value = ""
	ecom.PHONE.value = ""
}
}


//This function handles the payment method, whether they are going to use e-commerce or register via e-mail
function payment(){
var ecom = document.workshopreg
var form = new Array(ecom.NAME,ecom.ADDRESS,ecom.CITY,ecom.STATE,ecom.ZIP,ecom.COUNTRY,ecom.PHONE,ecom.EMAIL,ecom.DESCRIPTION)
var echo = new Array(ecom.x_name,ecom.x_address,ecom.x_city,ecom.x_state,ecom.x_zip,ecom.x_country,ecom.x_phone,ecom.x_Email,ecom.x_desc)
for(e=0;e<form.length;e++){
	echo[e].value = form[e].value
}
for(i=0;i<ecom.METHOD.length;i++){

	if(ecom.METHOD[i].checked==true){
		a = i
		break;
	}
}

if(ecom.NAME.value != null){
	if(ecom.METHOD[a].value=='CC'){
		ecom.action = "https://payments.verisign.com/payflowlink"
	}
		else{
			ecom.action="http://infomanagementcenter.com/cgi-bin/merge.pl/emerge/jhwork/text.html"
		}
	}
	else{
		alert("You must enter your name")
	}


//ecom.x_Header_HTML_Receipt.value = "<style>font {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal; font-weight: normal};tr {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; font-style: normal; font-weight: normal};h3 {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-weight: normal};h1 {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: large; font-weight: bold; color: #FFFFFF; background-color: #003333};h2 {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-weight: bold};</style> <h3>Registration Continued for...<br>"+ecom.x_Description.value+"</h3>"
//ecom.x_Header_Email_Receipt.value = ecom.x_First_Name.value+", thanks for registering for "+ecom.x_Description.value
ecom.submit()
}

function nabbpop(){
	for(c=0; c < seminar.length; c++){
		abbseminar(seminar[c])
	}	
	for(d=0; d < abb.length; d++){
		if(abb[d] != abb[d+1]){
			nabb[d] = abb[d]+1
		}
		else{
			if(abb[d+1] == abb[d+2]){
				var count = 1
				for(f=d;abb[f] == abb[f+1];f++){
					count = count + 1
				}
				for(g=0;g<count;g++){
					nabb[d+g] = abb[d+g]+parseInt(g+1)
				}
				d = parseInt(d+g-1)
			}
			else{
				nabb[d] = abb[d]+1
				nabb[d+1] = abb[d+1]+2
				d++
			}
		}
	}
}

function abbseminar(sl){
var sa = new Array()
var no1 = 0

sa[0]=sl.charAt(0).toLowerCase()
	for(b=1;b<sl.length;b++){
		no1 = sl.indexOf(" ",no1+1)
			if(sl.charAt(no1+1) != "-"){
			sa[sa.length]=sl.charAt(no1+1).toLowerCase()
			}
			if(sl.slice(no1+1,no1+3)=="--"){
			abb[abb.length]=sa.join("")
			sa = new Array()
			break;
			}
	}

}

function two4one(){
var ecom = document.workshopreg
if(ecom.twoforone.checked == true){
gold = ""
ecom.USER6.disabled = false
ecom.USER6.value = gold
ecom.USER7.disabled = false
ecom.USER7.value = gold
ecom.USER8.disabled = false
ecom.USER8.value = gold
ecom.USER9.disabled = false
ecom.USER9.value = gold
}
else{
gold = "For CIDM Members Only"
ecom.USER6.disabled = true
ecom.USER6.value = gold
ecom.USER7.disabled = true
ecom.USER7.value = gold
ecom.USER8.disabled = true
ecom.USER8.value = gold
ecom.USER9.disabled = true
ecom.USER9.value = gold
}
}

//tc = Total Cost
function costmech(){
var ecom = document.workshopreg
var diff = "dassfxacmadwd1"
var tc = 925
for(a=0;a<ecom.registration.length;a++){
	if(ecom.registration[a].checked == true){
		break;
	}
}
if(ecom.registration[a].value == diff){
			var tc = 1400
}
return tc
}


