host_name = "www.etftide.com"
secure_host_name = "www.etftide.com"
domain = "timingcube"
secure_domain = "timingcube"
cookie_duration = 90
affiliates = new Array("stockcharts")

sessionid_prefix = "jsessionid"

if (typeof isIndex == 'undefined')
{
	document.cookie="sitename=etftide" 

	if (tc_getCookie("sitename") == "")
	alert("Access to etftide requires that per-session cookies be enabled.\n" +
		"Such cookies are only valid for the current session and are not stored on your hard disk.\n\n" +
		"Please change your Web browser security settings to enable per-session cookies and try again.")
}

tc_writeCookie()

/*
** Forbidden characters
*/
IONGATE = "~!#$%^&*()=|{}[]:;\"'?<>,"
TC		= '"\\'

/*
** Function to initialize array that will contain error messages
** array is errorList
**
** Serge Dacic etftide 9/29/2005
*/
errorList = new Array(15)
function tc_initErrorList()
{
	for (i = 0; i < 15; i++)
		errorList[i] = ''
}

/*
** Function to insert an block of error messages in an html page. This code works for Netscape 
** 6 and and higher and for IE 4 and higher. For older browsers we display an javascript 
** alert window containing the error messages.
** There is also a bug on ie6 that makes the location.hash crashing when we come back
** from external window so in that case we display an alert box to the user to let
** him/her know that there was an error.
**
** Serge Dacic etftide 9/29/2005
*/
function tc_insertErrorBlock(id, text1, text2)
{
	if (ns6 && win)
	{
		x = document.getElementById(id);
		x.innerHTML = text1;
		location.hash='top'
	}
	else if (ie4 && win)
	{
		x = document.all[id];
		x.innerHTML = text1;
		location.hash='top'
		
		// workaround bug in ie6, if page is defined this means we are coming back from
		// card subscription process and then the hash function has already been called
	}
	else	//Older browsers
		alert(text2)
}

/*
** Function to check if a text field is empty. 
** If empty the appropriate message is returned, else return an empty string
**
** Serge Dacic etftide 9/29/2005
*/
function tc_empty(field, text)
{
	if(field == '')
		return FIELD_EMPTY+text+notcolorTag+notboldTag+'.'
	else
		return ''
}

	
/*
** Function to display errors detected on the client side. 
** An array containing the messages to display is passed to the function.
** This function builds two types of message:
** - an html message which is a table that will be displayed at the top of the 
**   Login page if the browser version used is allowing it (Netscape 6 and higher
**   or IE 4 and higher). 
** - a sample text message to be displayed in a javascript warning window when older
**   browsers are used.
** The check whether or not there were errors is performed in the opening page, 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_clientError(list, block)
{
	text = 'Error processing your request.\n\n'
	html = '<table width="100%" cellpadding=2 cellspacing=0>'
	html += '<tr><td colspan=4><hr size=0></td></tr>'
	html += '<tr>'
    html += '<td align=center bgcolor="#e8e0cb"><font face="Arial, Helvetica, sans-serif" size=+1 color="#cc0000"><b>Error processing your request</b></font></td>'
    html += '</tr>'
	html += '<tr><td><font face="Arial, Helvetica, sans-serif" size="-1"><br>'
	html += '<ul>'
	
	i = 0
	while(list[i] != '')
	{
		html += '<li>'+list[i]
		text += list[i]+'\n'
		i++
	}
	
	html += '</ul></font></td></tr>'
	html += '<tr><td colspan=4><hr size=0></td></tr>'
	html += '</table>'
	
	tc_insertErrorBlock(block , html, text)
}

/*
** Function to display server errors. 
** The server sends back errors as predefined variables, this function displays them in a table
** at the top of the opening page. 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_serverError(block)
{
	text = 'Error processing your request.\n\n'
	html = '<table width="100%" cellpadding=2 cellspacing=0>'
	html += '<tr><td colspan=4><hr size=0></td></tr>'
	html += '<tr>'
    html += '<td align=center bgcolor="#e8e0cb"><font face="Arial, Helvetica, sans-serif" size=+1 color="#cc0000"><b>Error processing your request</b></font></td>'
    html += '</tr>'
	html += '<tr><td><font face="Arial, Helvetica, sans-serif" size="-1"><br>'
	html += '<ul>'
	text += eval(errorCode)
	html += '<li>'+eval(errorCode)
	html += '</ul></font></td></tr>'
	html += '<tr><td colspan=4><hr size=0></td></tr>'
	html += '</table>'

	tc_insertErrorBlock(block , html, text)
	
}

/*
** Function to display server errors coming from our and coming from iongate 
** The server sends back errors as predefined variables and as string this function displays them in a table
** at the top of the opening page. 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_serverErrorString(block, errorString)
{
	text = 'Error processing your request.\n\n'
	html = '<table width="100%" cellpadding=2 cellspacing=0>'
	html += '<tr><td colspan=4><hr size=0></td></tr>'
	html += '<tr>'
    html += '<td align=center bgcolor="#e8e0cb"><font face="Arial, Helvetica, sans-serif" size=+1 color="#cc0000"><b>Error processing your request</b></font></td>'
    html += '</tr>'
	html += '<tr><td><font face="Arial, Helvetica, sans-serif" size="-1"><br>'
	html += '<ul>'
	text += eval(errorCode)+' ('+eval(errorString)+')'
	html += '<li>'+eval(errorCode)+' ('+eval(errorString)+')'
	html += '</ul></font></td></tr>'
	html += '</table>'

	tc_insertErrorBlock(block , html, text)
	
}

/*
** Function to release a session. After the session is release we go back to the Home page
**
** Serge Dacic etftide 9/29/2005
*/
function tc_logout()
{
	document.cookie = "apr_pref="
	document.cookie = "cumulative_pref="
	document.cookie = "money_pref="
	document.cookie = "timertrac_pref="

	url = "http://"+host_name+"/app/html"+session_string+"?page=home&douser=logout"
	window.location.href = url
}
	
/*
** Function to check subscription phase 2 (card information) data. 
** It performs various checks. If everything is correct, the page is submitted to the
** server, if not errors are displayed in opening page
**
** Following checks are performed:
**
** Check if fields empty for (mandatory fields):
** - first_name
** - last_name
** - address
** - city
** - zip
** - phone
** - card_number
** - card_name
**
** Check iongate illegal characters for:
** - first_name
** - middle_initial
** - last_name
** - address
** - address2
** - city
** - zip
** - phone
** - email
** - card_number
** - card_name
**
** Check validity of email address for:
** - email
**
** Check validity of card number and expiration date
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkRegisterCard()
{
	// Test to prevent multiple Card submission
	if (nbTry > 0)
		return false
	
	tc_initErrorList()
	i = 0
	
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	first_name = tc_stripLeadingTrailing(document.form.first_name.value, ' ')
	middle_initial = document.form.middle_initial.value
	last_name = tc_stripLeadingTrailing(document.form.last_name.value, ' ')
	address = tc_stripLeadingTrailing(document.form.address.value, ' ')
	address2 = document.form.address2.value
	city = tc_stripLeadingTrailing(document.form.city.value, ' ')
	stateSel = document.form.state.selectedIndex
	state = document.form.state.options[stateSel].value
	zip = tc_stripLeadingTrailing(document.form.zip.value, ' ')
	countrySel = document.form.country.selectedIndex
	country = document.form.country.options[countrySel].value
	phone = tc_stripLeadingTrailing(document.form.phone.value, ' ')
	email = document.form.email.value
	email_confirm = document.form.email_confirm.value
	email2 = document.form.email2.value
	email2_confirm = document.form.email2_confirm.value
	card_number = document.form.card_number.value
	card_typeSel = document.form.card_type.selectedIndex
	card_text = document.form.card_type.options[card_typeSel].text
	card_type = document.form.card_type.options[card_typeSel].value
	card_verif_number = tc_stripLeadingTrailing(document.form.card_verif_number.value, ' ')
	card_name = tc_stripLeadingTrailing(document.form.card_name.value, ' ')
	// set in hidden field card_exp the month and year picked by the user
	exp_month_ind = document.form.card_expiration_month.selectedIndex
	exp_year_ind = document.form.card_expiration_year.selectedIndex
	document.form.card_expiration.value = document.form.card_expiration_month.options[exp_month_ind].value+document.form.card_expiration_year.options[exp_year_ind].value
	card_expiration = document.form.card_expiration.value
	if (document.form.card_verif_indicator[0].checked)
		card_verif_indicator = 9
	else
	if (document.form.card_verif_indicator[1].checked)
		card_verif_indicator = 2
	else
		card_verif_indicator = ''

	// Check if mandatory fields are not empty
	text = tc_empty(first_name, 'First Name')
	if(text != '')
		errorList[i++] = text	
	text = tc_empty(last_name, 'Last Name')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(address, 'Address Line 1')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(city, 'City')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(zip, 'Zip Code')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(phone, 'Telephone')
	if(text != '')
		errorList[i++] = text

	//Check validity of Email address and Confirmation E-mail address
	if(!tc_isValidEmail(email))
		errorList[i++] = EMAIL_FORMAT	
	else if(email != email_confirm)
		errorList[i++] = EMAIL_MATCH
	
	//Check validity of Second Email address (not mandatory field)
	if(email2 != '')
	{
		if(email == email2)
			errorList[i++] = EMAIL2_VALUE
		else if(!tc_isValidEmail(email2))
			errorList[i++] = EMAIL2_FORMAT
		else if(email2 != email2_confirm)
			errorList[i++] = EMAIL2_MATCH		
	}
	else if(email2_confirm != '')
		errorList[i++] = EMAIL2_MATCH
		
	text = tc_empty(card_name, 'Name on Card')
	if(text != '')
		errorList[i++] = text

	if(!tc_validCardNumber(card_number, card_type))
		errorList[i++] = boldTag+colorTag+'Credit Card Number'+notcolorTag+notboldTag+' is not a valid '+card_text+' number.'
		
	if(!tc_validCardDate(document.form.card_expiration_month.options[exp_month_ind].value, document.form.card_expiration_year.options[exp_year_ind].value))
		errorList[i++] = 'Invalid '+boldTag+colorTag+'Expiration Date'+notcolorTag+notboldTag+'.'

	text = tc_empty(card_verif_number, 'Card Verification Number')
	if(text != '' && !document.form.card_verif_indicator[0].checked && !document.form.card_verif_indicator[1].checked)
		errorList[i++] = text
		
	// Check validity of information in fields
	index = tc_stringFilter(document.form.first_name, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.first_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	
	index = tc_stringFilter(document.form.middle_initial, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.middle_initial.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	index = tc_stringFilter(document.form.last_name, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.last_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.address, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.address.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.address2, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.address2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.city, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.city.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.zip, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.zip.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.phone, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.phone.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.email, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	

	index = tc_stringFilter(document.form.email2, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
		
	index = tc_stringFilter(document.form.card_verif_number, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.card_verif_number.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.card_name, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.card_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
		
 	if (i == 0)
	{
	  	//???document.form.lease_type.value = lease_type
		//???document.form.payment_amount.value = cost
//		alert("tc_checkRegisterCard: Total Payment = "+total_payment)
//		document.form.payment_amount.value = total_payment

		// supress leading and tailing blanks in non mandatory fields and reassigned variables to send to the server
		document.form.first_name.value = first_name
		document.form.middle_initial.value = tc_stripLeadingTrailing(middle_initial, ' ')
		document.form.last_name.value = last_name
		document.form.address.value = address
		document.form.address2.value = tc_stripLeadingTrailing(address2, ' ')
		document.form.city.value = city
		document.form.zip.value = zip
		document.form.phone.value = phone
		document.form.email.value = tc_stripLeadingTrailing(email, ' ')
		document.form.email2.value = tc_stripLeadingTrailing(email2, ' ')
		document.form.card_number.value = tc_stripLeadingTrailing(card_number, ' ')
		document.form.card_verif_number.value = card_verif_number
		document.form.card_name.value = card_name
				
		tinywindow = window.open("http://"+host_name+"/app/html"+session_string+"?page=cc_process", "ETF_tinywindow", 'width=420,height=250')

		action = "https://"+secure_host_name+"/app/html"+session_string_secure
		document.form.action = action

		// Everything is ok we submit the transaction and we increment the tryNb counter to prevent
		// multiple clicks on 'Register'
		nbTry++
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		 document.form.first_name.value = first_name
		 document.form.middle_initial.value = middle_initial
		 document.form.last_name.value = last_name
		 document.form.address.value = address
		 document.form.address2.value = address2
		 document.form.city.value = city
		 document.form.state.selectedIndex = stateSel
		 document.form.zip.value = zip
		 document.form.country.selectedIndex = countrySel
		 document.form.phone.value = phone
		 document.form.email.value = email
		 document.form.email_confirm.value = email_confirm
		 document.form.email2.value = email2
		 document.form.email2_confirm.value = email2_confirm
		 document.form.card_number.value = card_number
		 document.form.card_type.selectedIndex = card_typeSel
		 document.form.card_verif_number.value = card_verif_number
		 document.form.card_name.value = card_name
		 document.form.card_expiration_month.selectedIndex = exp_month_ind
		 document.form.card_expiration_year.selectedIndex = exp_year_ind
		 document.form.card_expiration.value = card_expiration
		 if (card_verif_indicator == 9)
		 	document.form.card_verif_indicator[0].checked = true
		 else if (card_verif_indicator == 2)
			document.form.card_verif_indicator[1].checked = true
		 else
		 {
			document.form.card_verif_indicator[0].checked = false
			document.form.card_verif_indicator[1].checked = false
		 }
		 return false;
	}
}

/*
** Function to check subscription phase 3 (account information) data. 
** It performs various checks. If everything is correct, the page is submitted to the
** server, if not errors are displayed in opening page
**
** Following checks are performed:
**
** Check if fields empty for (mandatory fields):
** - userid
** - question
** - answer
**
** Check validity of password (should have between 6 and 10 characters) for:
** - password
**
** Check that password and 're-type' password are identical (password and password2)
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkRegister()
{
	tc_initErrorList()
	i = 0

	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	// supress leading and tailing blanks
	userid = tc_stripLeadingTrailing(document.form.userid.value, ' ')
	question = tc_stripLeadingTrailing(document.form.question.value, ' ')
	answer = tc_stripLeadingTrailing(document.form.answer.value, ' ')
	email_subject = document.form.email_subject.value
		
	// Check if mandatory fields are not empty	
	text = tc_empty(question, 'Security Question')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(answer, 'Answer'+notcolorTag+notboldTag+' to the Security Question'+boldTag+colorTag)
	if(text != '')
		errorList[i++] = text
		
	// Check validity of information in fields	
	str = new String(userid)
	if((str.length < 6) || (str.length > 10))
		errorList[i++] = USERID_FORMAT
		
	str = new String(document.form.password.value)
	if((str.length < 6) || (str.length > 10))
		errorList[i++] = PASSWORD_FORMAT

	if(document.form.password.value != document.form.password2.value)
		errorList[i++] = PASSWORD_MATCH
		
	// Check if there is "
	index = tc_stringFilter(document.form.userid, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.userid.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.question, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.question.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.answer, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.answer.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.password, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.password.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.password2, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.password2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.email_subject, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email_subject.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	
 	if (i == 0)
	{
		document.form.userid.value = userid
		document.form.question.value = question
		document.form.answer.value = answer
		document.form.email_subject.value = tc_stripLeadingTrailing(email_subject, ' ')
		
		//Check if user put an email address in email_subject field. If that is the case we empty it so that
		// the server can put the default string
		if(tc_isValidEmail(document.form.email_subject.value))
			document.form.email_subject.value = ''

		document.form.action= "https://"+secure_host_name+"/app/html"+session_string_secure

		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.userid.value = userid
		document.form.question.value = question
		document.form.answer.value = answer
		document.form.email_subject.value = email_subject
		document.form.password.value = ''
		document.form.password2.value = ''
	
		return false
	}
}

/*
** Function to check login data. 
** It performs various checks. If everything is correct, the page is submitted to the
** server, if not errors are displayed in opening page
** Following checks are performed:
**
** Check if fields empty for (mandatory fields):
** - userid
**
** Check validity of password (should have between 6 and 10 characters) for:
** - password
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkLogin()
{
	tc_initErrorList()
	i = 0

	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	userid = tc_stripLeadingTrailing(document.form.userid.value, ' ')
	
	str = new String(userid)
	if((str.length < 6) || (str.length > 10))
		errorList[i++] = USERID_FORMAT
		
	str = new String(document.form.password.value)
	if((str.length < 6) || (str.length > 10))
		errorList[i++] = PASSWORD_FORMAT
		
	// Check if there is "
	index = tc_stringFilter(document.form.userid, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.userid.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	index = tc_stringFilter(document.form.password, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.password.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	
	if(i == 0)
	{
		document.form.userid.value = userid
		document.form.action = "https://"+secure_host_name+"/app/html"+session_string_secure
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.userid.value = userid
		document.form.password.value = ''
		
		return false
	}
}


/*
** Function to validate user service information before submitting to server.
** Thierry Fabre etftide 10/25/2006
*/
function tc_servicesUpdate(update)
{
	return true;
}



/*
** Function to check updated data. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
** inputs:
** update  - true if a field has been touched
** special - true if record is a special case: life member or check subscription. In these situation ther are
** 			 credit card fields defined
** Following checks are performed:
**
** Check if fields empty for (mandatory fields):
** - first_name
** - last_name
** - address
** - city
** - zip
** - phone
** - email
** - question
** - answer
** - card_number
** - card_name
** - card verification number
**
** Check iongate illegal characters for:
** - first_name
** - middle_initial
** - last_name
** - address
** - address2
** - city
** - zip
** - phone
** - card_number
** - card_name
** - card verification number
**
** Check validity of password (should have between 6 and 10 characters) for:
** - password
**
** Check that current password and new password are different (old_password and new_password)
**
** Check that password and 're-type' password are identical (new_password and new_password2)
**
** Check validity of email address for:
** - email
**
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkUpdate(update, special)
{
	if(!update)
		return false
		
	tc_initErrorList()
	i = 0

	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	first_name = tc_stripLeadingTrailing(document.form.first_name.value, ' ')
	middle_initial = document.form.middle_initial.value
	last_name = tc_stripLeadingTrailing(document.form.last_name.value, ' ')
	address = tc_stripLeadingTrailing(document.form.address.value, ' ')
	address2 = document.form.address2.value
	city = tc_stripLeadingTrailing(document.form.city.value, ' ')
	stateSel = document.form.state.selectedIndex
	state = document.form.state.options[stateSel].value
	zip = tc_stripLeadingTrailing(document.form.zip.value, ' ')
	countrySel = document.form.country.selectedIndex
	country = document.form.country.options[countrySel].value
	phone = tc_stripLeadingTrailing(document.form.phone.value, ' ')
	email = document.form.email.value
	email_confirm = document.form.email_confirm.value
	email2 = document.form.email2.value
	email2_confirm = document.form.email2_confirm.value
	question = tc_stripLeadingTrailing(document.form.question.value, ' ')
	answer = tc_stripLeadingTrailing(document.form.answer.value, ' ')
	email_subject = document.form.email_subject.value
	old_password = document.form.old_password.value
	new_password = document.form.new_password.value
	new_password2 = document.form.new_password2.value

	// No credit card fields defined when special case
	if(!special)
	{
		card_number_new = document.form.card_number.value
		card_typeSel = document.form.card_type.selectedIndex
		card_text = document.form.card_type.options[card_typeSel].text
		card_type = document.form.card_type.options[card_typeSel].value
		card_verif_number = tc_stripLeadingTrailing(document.form.card_verif_number.value, ' ')
		card_name = tc_stripLeadingTrailing(document.form.card_name.value, ' ')
		// set in hidden field card_exp the month and year picked by the user
		exp_month_ind = document.form.card_expiration_month.selectedIndex
		exp_year_ind = document.form.card_expiration_year.selectedIndex
		document.form.card_expiration.value = document.form.card_expiration_month.options[exp_month_ind].value+document.form.card_expiration_year.options[exp_year_ind].value
		card_expiration = document.form.card_expiration.value
		if (document.form.card_verif_indicator[0].checked)
			card_verif_indicator = 9
		else
		if (document.form.card_verif_indicator[1].checked)
			card_verif_indicator = 2
		else
			card_verif_indicator = ''

		// Check the validity of credit card information
		text = tc_empty(card_name, 'Name on Card')
		if(text != '')
			errorList[i++] = text
	
		if (card_number_new != card_number)
			if(!tc_validCardNumber(card_number_new, card_type))
				errorList[i++] = boldTag+colorTag+'Credit Card Number'+notcolorTag+notboldTag+' is not a valid '+card_text+' number.'
			
		if(!tc_validCardDate(document.form.card_expiration_month.options[exp_month_ind].value, document.form.card_expiration_year.options[exp_year_ind].value))
			errorList[i++] = 'Invalid '+boldTag+colorTag+'Expiration Date'+notcolorTag+notboldTag+'.'
	
		text = tc_empty(card_verif_number, 'Card Verification Number')
		if(text != '' && !document.form.card_verif_indicator[0].checked && !document.form.card_verif_indicator[1].checked)
			errorList[i++] = text

		index = tc_stringFilter(document.form.card_name, IONGATE)
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.card_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
		index = tc_stringFilter(document.form.card_verif_number, IONGATE)
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.card_verif_number.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	}
		
	/*
	** If user entered something in old_password, new_password or new_password2, we assume he/she
	** wish to change his/her password. We then start to test the validity of these fields
	*/
	if(old_password != '' ||
	   new_password != '' ||
	   new_password2 != '')
	{
		str = new String(old_password)
		if((str.length < 6) || (str.length >10))
			errorList[i++] = CUR_PASSWORD_FORMAT
			
		str = new String(new_password)
		if((str.length < 6) || (str.length >10))
			errorList[i++] = NEW_PASSWORD_FORMAT
		else 
		{
			if(old_password == new_password)
				errorList[i++] = PASSWORD_DIFF
			else if(new_password != new_password2)
				errorList[i++] = NEW_PASSWORD_MATCH
		}
	}		
		
	// Check if mandatory fields are not empty
	text = tc_empty(first_name, 'First Name')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(last_name, 'Last Name')
	if(text != '')
		errorList[i++] = text	
	text = tc_empty(address, 'Address Line 1')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(city, 'City')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(zip, 'Zip Code')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(phone, 'Telephone')
	if(text != '')
		errorList[i++] = text

	//Check validity of Email address and Confirmation E-mail address
	if(!tc_isValidEmail(email))
		errorList[i++] = EMAIL_FORMAT	
	else if(email != email_confirm)
		errorList[i++] = EMAIL_MATCH
		
	//Check validity of Second Email address (not mandatory field)
	if(email2 != '')
	{
		if(email == email2)
			errorList[i++] = EMAIL2_VALUE
		else if(!tc_isValidEmail(email2))
			errorList[i++] = EMAIL2_FORMAT
		else if(email2 != email2_confirm)
			errorList[i++] = EMAIL2_MATCH		
	}
	else if(email2_confirm != '')
		errorList[i++] = EMAIL2_MATCH
			
	text = tc_empty(question, 'Security Question')
	if(text != '')
		errorList[i++] = text
	text = tc_empty(answer, 'Your Answer')
	if(text != '')
		errorList[i++] = text

	// Check validity of information in fields	
	index = tc_stringFilter(document.form.first_name, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.first_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	
	index = tc_stringFilter(document.form.middle_initial, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.middle_initial.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	index = tc_stringFilter(document.form.last_name, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.last_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.address, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.address.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.address2, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.address2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.city, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.city.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.zip, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.zip.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.phone, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.phone.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
	
	index = tc_stringFilter(document.form.email, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	

	index = tc_stringFilter(document.form.email2, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	

	// Check if there is "
	index = tc_stringFilter(document.form.old_password, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.old_password.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.new_password, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.new_password.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.new_password2, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.new_password2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.question, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.question.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.answer, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.answer.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.email_subject, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email_subject.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	if (i == 0)
	{
		// supress leading and tailing blanks in non mandatory fields and reassigned variables to send to the server
		document.form.first_name.value = first_name
		document.form.middle_initial.value = tc_stripLeadingTrailing(middle_initial, ' ')
		document.form.last_name.value = last_name
		document.form.address.value = address
		document.form.address2.value = tc_stripLeadingTrailing(address2, ' ')
		document.form.city.value = city
		document.form.zip.value = zip
		document.form.phone.value = phone
		document.form.email.value = tc_stripLeadingTrailing(email, ' ')
		document.form.email2.value = tc_stripLeadingTrailing(email2, ' ')
		document.form.question.value = question
		document.form.answer.value = answer
		document.form.email_subject.value = tc_stripLeadingTrailing(email_subject, ' ')
		
		if (!special)
		{
			document.form.card_name.value = card_name
			document.form.card_verif_number.value = card_verif_number
			document.form.special.value = "no"
		}
		else
			document.form.special.value = "yes"

		// Check if email addresses have been touched
		// if yes we put the new value in hidden fields prim_email and alt_email so that 'success' page 
		// could use them
		if(document.form.prim_email.value != document.form.email.value)
			document.form.prim_email.value = document.form.email.value
		else
			document.form.prim_email.value = ''
			
		if(document.form.alt_email.value != document.form.email2.value)
			document.form.alt_email.value = document.form.email2.value
		else
			document.form.alt_email.value = ''
		
		// Check if user put an email address in email_subject field. If that is the case we empty it so that
		// the server can put the default string
		if(tc_isValidEmail(document.form.email_subject.value))
			document.form.email_subject.value = ''
			
		document.form.action="https://"+secure_host_name+"/app/html"+session_string_secure
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.first_name.value = first_name
		document.form.middle_initial.value = middle_initial
		document.form.last_name.value = last_name
		document.form.address.value = address
		document.form.address2.value = address2
		document.form.city.value = city
		document.form.state.selectedIndex = stateSel
		document.form.zip.value = zip
		document.form.country.selectedIndex = countrySel
		document.form.phone.value = phone
		document.form.email.value = email
		document.form.email_confirm.value = email_confirm
		document.form.email2.value = email2
		document.form.email2_confirm.value = email2_confirm
		document.form.question.value = question
		document.form.answer.value = answer
		document.form.email_subject.value = email_subject
		document.form.old_password.value = ''
		document.form.new_password.value = ''
		document.form.new_password2.value = ''

		if(!special)
		{
			document.form.card_number.value = card_number_new
			document.form.card_type.selectedIndex = card_typeSel
			document.form.card_verif_number.value = card_verif_number
			document.form.card_name.value = card_name
			document.form.card_expiration_month.selectedIndex = exp_month_ind
			document.form.card_expiration_year.selectedIndex = exp_year_ind
			document.form.card_expiration.value = card_expiration
			if (card_verif_indicator == 9)
				document.form.card_verif_indicator[0].checked = true
			else if (card_verif_indicator == 2)
				document.form.card_verif_indicator[1].checked = true
			else
			{
				document.form.card_verif_indicator[0].checked = false
				document.form.card_verif_indicator[1].checked = false
			}
		}		
		return false
	}
}
	
/*
** Function to check userid/email data in forget password form. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check if fields empty for:
** - userid_email
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkPassword()
{
	tc_initErrorList()
	i = 0

	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	userid_email = tc_stripLeadingTrailing(document.passwordform.userid_email.value, ' ')
	email = document.useridform.email.value
	
	text = tc_empty(userid_email, 'User ID'+notcolorTag+notboldTag+' or '+boldTag+colorTag+'Primary E-mail')
	if(text != '')
		errorList[i++] = text

	index = tc_stringFilter(document.passwordform.userid_email, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.passwordform.userid_email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	
		
	if(i == 0)
	{
		document.passwordform.userid_email.value = userid_email
		document.passwordform.action="https://"+secure_host_name+"/app/html"+session_string_secure
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.passwordform.userid_email.value = userid_email
		document.useridform.email.value = email
				
		return false
	}
}

/*
** Function to check Answer to security question. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check if fields empty for:
** - answer
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkChallenge()
{
	tc_initErrorList()
	i = 0
	
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	userid_answer = tc_stripLeadingTrailing(document.form.user_answer.value, ' ')

	text = tc_empty(userid_answer, 'Your Answer'+notcolorTag+notboldTag+' to the Security Question'+boldTag)
	if(text != '')
		errorList[i++] = text
		
	// check if there is a "
	index = tc_stringFilter(document.form.user_answer, TC)	
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.user_answer.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

		
	if(i == 0)
	{
		document.form.user_answer.value = userid_answer
		document.form.action="https://"+secure_host_name+"/app/html"+session_string_secure
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.user_answer.value = userid_answer
		
		return false
	}
}		


/*
** Function to check email data in forget userid form. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check iongate illegal characters for:
** - email2
**
** Check validity of email address for:
** - email2
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkUserID()
{
	tc_initErrorList()
	i = 0
		
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	email = document.useridform.email.value
	userid_email = document.passwordform.userid_email.value
	
	//Check validity of Email address
	if(!tc_isValidEmail(email))
		errorList[i++] = EMAIL_FORMAT
		
	index = tc_stringFilter(document.useridform.email, IONGATE)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.useridform.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL	

	if(i == 0)
	{
		// supress leading and tailing blanks in non mandatory fields and reassigned variables to send to the server
		document.useridform.email.value = tc_stripLeadingTrailing(email, ' ')
		document.useridform.action="https://"+secure_host_name+"/app/html"+session_string_secure
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock2')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.useridform.email.value = email
		document.passwordform.userid_email.value = userid_email
		
		return false
	}
}

/*
** Function to check fields in feedback form. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check if no selection for:
** - browser selector
** - OS selector
**
** Check if fields empty for:
** - name
** - email address
** - feedback
**
** Serge Dacic etftide 9/29/2005
*/

function tc_checkContact()
{
	tc_initErrorList()
	i = 0
	
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	name = tc_stripLeadingTrailing(document.form.name.value, ' ')
	email = document.form.email.value
	email_confirm = document.form.email_confirm.value	
	document.form.orderid.value = orderid
	feedback = tc_stripLeadingTrailing(document.form.feedback.value, ' ')
	/* 
	browserSel = document.form.browser.options.selectedIndex
	browser = document.form.browser.options[browserSel].value
	osSel = document.form.os.options.selectedIndex
	os = document.form.os.options[osSel].value
	*/

	text = tc_empty(name, 'Name')
	if(text != '')
		errorList[i++] = text

	//Check validity of Email address and Confirmation E-mail address
	if(!tc_isValidEmail(email))
		errorList[i++] = UNKN_EMAIL_FORMAT
	else if(email != email_confirm)
		errorList[i++] = UNKN_EMAIL_MATCH	
			
	/*
	if (browserSel == 0)
	{
    	text = 'Please select the '+boldTag+colorTag+'Browser '+notcolorTag+notboldTag+'you are using.'
        errorList[i++] = text
    }
		
	if (osSel == 0)
	{
    	text = 'Please select the '+boldTag+colorTag+'Operating System '+notcolorTag+notboldTag+'you are using.'
        errorList[i++] = text
    }
	*/
	
	text = tc_empty(feedback, 'Feedback')
	if(text != '')
		errorList[i++] = text
		
	index = tc_stringFilter(document.form.name, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.email, TC)
	
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email_confirm.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	index = tc_stringFilter(document.form.feedback, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.feedback.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL


	if(i == 0)
	{
		document.form.name.value = name
		document.form.email.value = tc_stripLeadingTrailing(email, ' ')
		document.form.email_confirm.value = tc_stripLeadingTrailing(email_confirm, ' ')
		document.form.feedback.value = feedback
		for (iname = 0; iname < name.length; iname ++)
		{
			if (name.charAt(iname) == ' ')
				break;
		}
		if (iname == name.length && iname != 0)
			document.form.first_name.value = name
		else
		{
			fname = name.substring(0, iname)
			document.form.first_name.value = tc_stripLeadingTrailing(fname, ' ')
			lname = name.substring(iname+1, name.length)
			document.form.last_name.value = tc_stripLeadingTrailing(lname, ' ')
		}
		document.form.action="http://"+host_name+"/app/html"+session_string
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.name.value = name
		document.form.email.value = email
		document.form.email_confirm.value = email_confirm
		document.form.feedback.value = feedback
		/*
		document.form.browser.selectedIndex = browserSel
		document.form.os.selectedIndex = osSel
		*/
		
		return false
	}
}		

/*
** Function to check fields in referral form. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check fields (if not empty):
** - email address of 4 referrals
** - referrer e-mail
** - referrer name
** - e-mail subject
** - e-mail message
**
** Serge Dacic TimingCube 08/03/2005
*/

function tc_checkReferral()
{
	tc_initErrorList()
	i = 0
	empty = 0
	
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	name = tc_stripLeadingTrailing(document.form.name.value, ' ')
	email = document.form.email.value
	email_confirm = document.form.email_confirm.value	
	email1 = document.form.email1.value
	email2 = document.form.email2.value
	email3 = document.form.email3.value
	email4 = document.form.email4.value
	subject = tc_stripLeadingTrailing(document.form.subject.value, ' ')
	message = tc_stripLeadingTrailing(document.form.message.value, ' ')

	text = tc_empty(name, 'Name')
	if(text != '')
		errorList[i++] = text

	//Check validity of Email address and Confirmation E-mail address
	if(!tc_isValidEmail(email))
		errorList[i++] = UNKN_EMAIL_FORMAT
	else if(email != email_confirm)
		errorList[i++] = UNKN_EMAIL_MATCH	

	if(message.length > 750)
	{
    	text = boldTag+colorTag+'Message '+notcolorTag+notboldTag+'field, contains '+ message.length+' characters. The maximum number of characters is 750.'
        errorList[i++] = text
    }

	if(email1 != '')
	{
		text = tc_empty(email1, 'Referral 1 E-mail address')
		if(text != '')
			errorList[i++] = text

		//Check validity of Email addresses
		if(!tc_isValidEmail(email1))
			errorList[i++] = UNKN_EMAIL_FORMAT

		// Check forbidden characters
		index = tc_stringFilter(document.form.email1, TC)		
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.email1.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	}
	else
		empty++
		
	if(email2 != '')
	{
		text = tc_empty(email2, 'Referral 2 E-mail address')
		if(text != '')
			errorList[i++] = text

		//Check validity of Email addresses
		if(!tc_isValidEmail(email2))
			errorList[i++] = UNKN_EMAIL_FORMAT

		// Check forbidden characters
		index = tc_stringFilter(document.form.email2, TC)		
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.email2.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	}
	else
		empty++

	if(email3 != '')
	{
		text = tc_empty(email3, 'Referral 3 E-mail address')
		if(text != '')
			errorList[i++] = text

		//Check validity of Email addresses
		if(!tc_isValidEmail(email3))
			errorList[i++] = UNKN_EMAIL_FORMAT

		// Check forbidden characters
		index = tc_stringFilter(document.form.email3, TC)		
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.email3.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	}
	else
		empty++

	if(email4 != '')
	{
		text = tc_empty(email4, 'Referral 4 E-mail address')
		if(text != '')
			errorList[i++] = text

		//Check validity of Email addresses
		if(!tc_isValidEmail(email4))
			errorList[i++] = UNKN_EMAIL_FORMAT

		// Check forbidden characters
		index = tc_stringFilter(document.form.email4, TC)		
		if(index != -1)
			errorList[i++] = 'Character '+boldTag+colorTag+document.form.email4.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	}
	else
		empty++
		
	if(empty == 4)
		return false	
	
	// Check if not trying to refer self
	if((email.toLowerCase() == email1.toLowerCase() && email != "") || 
	   (email_sec.toLowerCase() == email1.toLowerCase() && email_sec != "")) 
	{
    	text = 'Your E-mail address is used in '+boldTag+colorTag+'Referral 1 '+notcolorTag+notboldTag+'field, you cannot refer yourself.'
        errorList[i++] = text
    }
	if((email.toLowerCase() == email2.toLowerCase() && email != "") || 
	   (email_sec.toLowerCase() == email2.toLowerCase() && email_sec != "")) 
	{
    	text = 'Your E-mail address is used in '+boldTag+colorTag+'Referral 2 '+notcolorTag+notboldTag+'field, you cannot refer yourself.'
        errorList[i++] = text
    }
	if((email.toLowerCase() == email3.toLowerCase() && email != "") || 
	   (email_sec.toLowerCase() == email3.toLowerCase() && email_sec != "")) 
	{
    	text = 'Your E-mail address is used in '+boldTag+colorTag+'Referral 3 '+notcolorTag+notboldTag+'field, you cannot refer yourself.'
        errorList[i++] = text
    }
	if((email.toLowerCase() == email4.toLowerCase() && email != "") || 
	   (email_sec.toLowerCase() == email4.toLowerCase() && email_sec != "")) 
	{
    	text = 'Your E-mail address is used in '+boldTag+colorTag+'Referral 4 '+notcolorTag+notboldTag+'field, you cannot refer yourself.'
        errorList[i++] = text
    }	  
	   		
	index = tc_stringFilter(document.form.name, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.email, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email_confirm.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	text = tc_empty(subject, 'Subject')
	if(text != '')
		errorList[i++] = text
	index = tc_stringFilter(document.form.subject, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.subject.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	text = tc_empty(message, 'Message')
	if(text != '')
		errorList[i++] = text
	index = tc_stringFilter(document.form.message, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.message.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	if(i == 0)
	{
		document.form.email1.value = tc_stripLeadingTrailing(email1, ' ')
		document.form.email2.value = tc_stripLeadingTrailing(email2, ' ')
		document.form.email3.value = tc_stripLeadingTrailing(email3, ' ')
		document.form.email4.value = tc_stripLeadingTrailing(email4, ' ')
		document.form.name.value = name
		document.form.email.value = tc_stripLeadingTrailing(email, ' ')
		document.form.email_confirm.value = tc_stripLeadingTrailing(email_confirm, ' ')
		document.form.subject.value = subject
		document.form.message.value = message
		document.form.action="http://"+host_name+"/app/html"+session_string

		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
		
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.email1.value = email1
		document.form.email2.value = email2
		document.form.email3.value = email3
		document.form.email4.value = email4
		document.form.name.value = name
		document.form.email.value = email
		document.form.email_confirm.value = email_confirm
		document.form.subject.value = subject
		document.form.message.value = message
		
		return false
	}
}		

/*
** Function to check fields in Free Report request form. 
** It performs various checks and fills out hidden variables defined in opening page. 
** It then submits the form to the server.
**
** Following checks are performed:
**
** Check if fields empty for:
** - email address
**
** Serge Dacic ETFTide 01/22/2008
*/

function tc_checkReport()
{
	tc_initErrorList()
	i = 0
	
	// We store every user value in temporary variables so that we can put them back in fields 
	// as is in case of errors
	email = document.form.email.value
	email_confirm = document.form.email_confirm.value
	first_name = tc_stripLeadingTrailing(document.form.first_name.value, ' ')	
	last_name = tc_stripLeadingTrailing(document.form.last_name.value, ' ')	
	phone = tc_stripLeadingTrailing(document.form.phone.value, ' ')

	//Check validity of Email address and Confirmation E-mail address
	if(!tc_isValidEmail(email))
		errorList[i++] = UNKN_EMAIL_FORMAT
	else if(email != email_confirm)
		errorList[i++] = UNKN_EMAIL_MATCH	
				
	index = tc_stringFilter(document.form.email, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.email_confirm.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	index = tc_stringFilter(document.form.first_name, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.first_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.last_name, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.last_name.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL
	index = tc_stringFilter(document.form.phone, TC)
	if(index != -1)
		errorList[i++] = 'Character '+boldTag+colorTag+document.form.phone.value.charAt(index)+notcolorTag+notboldTag+ILLEGAL

	if(i == 0)
	{
		document.form.email.value = tc_stripLeadingTrailing(email, ' ')
		document.form.email_confirm.value = tc_stripLeadingTrailing(email_confirm, ' ')
		document.form.first_name.value = first_name
		document.form.last_name.value = last_name
		document.form.phone.value = phone
		document.form.action="http://"+host_name+"/app/html"+session_string
		return true
	}
	else
	{
		tc_clientError(errorList, 'errorblock')
				
		// We have to restore fields with original values because Netscape 6 fills all the fields with
		// blanks when span area are displayed (bug???)		
		document.form.email.value = email
		document.form.email_confirm.value = email_confirm
		document.form.first_name.value = first_name
		document.form.last_name.value = last_name
		document.form.phone.value = phone
				
		return false
	}
}		

/*
** Function to test illegal characters in a string. 
** illegal characters are ~!#$%^&*()=|{}[]:;"'?<>,
** Function returns the index of the first illegal character or -1 if ok 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_stringFilter(input, filteredValues) 
{
	s = input.value
	
	var i 
	var returnString = ""
	
	// Search through string and append to unfiltered values to returnString.
	for (i = 0; i < s.length; i++) 
	{  
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) != -1) 
			return i
	}
	return -1
}

/*
** Function to strip leading characters. 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_stripLeading(string, chr) 
{
	var finished = false
	for (var i = 0; i < string.length && !finished; i++)
	if (string.substring(i, i+1) != chr) 
		finished = true
   
	if (finished) 
   		return string.substring(i-1)
	else if (i < string.length)
		return string
	else 
		return ''
}

/*
** Function to strip tailing characters. 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_stripTrailing(string, chr) 
{
	var finished = false
	for (var i = string.length - 1; i > -1 && !finished; i--)
		if (string.substring(i, i+1) != chr) 
			finished = true
			
	if (finished)
		return string.substring(0, i+2)
	else if (i > -1)
		return string
	else
		return ''
}

/*
** Function to strip tailing and leading characters. 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_stripLeadingTrailing(string, chr) 
{
    return tc_stripTrailing(tc_stripLeading(string,chr), chr)
}

/*
** Function to check if a substring is present inside a string 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_substringPresent(subS, fullS) 
{
	for (isub = 0; isub < fullS.length; isub++) {      
		if (fullS.substring(isub, isub + subS.length) == subS)
			return true
	}
	
	return false
}

/*
** Function to return all occurences of a substring1 by a substring 2 in a given 
** string 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_replace(str, subs1, subs2)
{
	while (str.indexOf(subs1) > -1)
 		str = str.replace(subs1, subs2)
	
	return str
}

/*
** Function to return a substring present after a given token
**
** Serge Dacic etftide 9/29/2005
*/
function tc_substringFromToken(s, t) 
{
	sLength = s.length
	
	i = sLength - 1
	while (s.charAt(i) != t)
		i--
	
	return s.substring(i+1, sLength)
}

/*
** Find and replace a string in another string, with optional case-sensitivity.
** s is the text in which to do the search
** o1 is the string to find
** o2 is the string to substitute into s in place of o1
** cs is true if case sensitive (defaults to true)
**
** Serge Dacic etftide 9/29/2005
*/
function tc_replaceAll(s, o1, o2, cs) 
{  
   searchFrom = 0
   offset = 0
   outText = ""
   searchText = ""
   if (cs == null) 
      cs = true
   if (!cs) 
   {
      searchText = s.toLowerCase()
      o1 = o1.toLowerCase()
   } 
   else 
   	searchText = s
	
   offset = searchText.indexOf(o1, searchFrom)
   while (offset != -1) 
   {
      outText += s.substring(searchFrom, offset)
      outText += o2
      searchFrom = offset + o1.length
      offset = searchText.indexOf(o1, searchFrom)
   }
   outText += s.substring(searchFrom, s.length)
   
   return (outText)
}

/*
** Function to select Monthly or Yearly subscription
**
** Serge Dacic etftide 9/29/2005
*/
function tc_leaseType(type)
{
	document.form.lease_type.value = type
	document.form.action="http://"+host_name+"/app/html"+session_string
	document.form.submit()
}

/*
** Function to open secure connection for the subscription step 3 (credit card)
**
** Serge Dacic etftide 9/29/2005
*/
function tc_runCard()
{
	document.form.action="https://"+secure_host_name+"/app/html"+session_string_secure
	document.form.submit()
}
function tc_changeOrder()
{
	document.form.action="https://"+secure_host_name+"/app/html"+session_string_secure
	document.form.submit()
}

/*
** List of functions used to manage the left side dynamic menu entries of every etftide pages.
**
** Functions include:
** - newImage
** - preloadImages
** - display
*/

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		cloudss_d4_1_over = newImage("../images/login_b.gif");
		cloudss_d4_2_over = newImage("../images/home_b.gif");
		cloudss_d4_3_over = newImage("../images/our_service_b.gif");
		cloudss_d4_4_over = newImage("../images/faq_b.gif");
		cloudss_d4_5_over = newImage("../images/subscriptions_b.gif");
		cloudss_d4_6_over = newImage("../images/member_results_b.gif");
		cloudss_d4_7_over = newImage("../images/admin_tasks_b.gif");
		cloudss_d4_8_over = newImage("../images/logout_b.gif");
		cloudss_d4_9_over = newImage("../images/member_profile_b.gif");
		cloudss_d4_10_over = newImage("../images/contact_b.gif");
		cloudss_d4_11_over = newImage("../images/results_b.gif");
		cloudss_d4_12_over = newImage("../images/print_b.gif");
		cloudss_d4_13_over = newImage("../images/member_weeklies_b.gif");
		cloudss_d4_14_over = newImage("../images/member_topetfs_b.gif");
		cloudss_d4_15_over = newImage("../images/member_trades_b.gif");
		cloudss_d4_16_over = newImage("../images/member_periods_b.gif");
		cloudss_d4_17_over = newImage("../images/admin_etf_b.gif");
		cloudss_d4_35_over = newImage("../images/managed_b.gif");
		cloudss_d4_37_over = newImage("../images/admin_emaildb_b.gif");

		cloudss_d4_18_over = newImage("../images/login_c.gif");
		cloudss_d4_19_over = newImage("../images/home_c.gif");
		cloudss_d4_20_over = newImage("../images/our_service_c.gif");
		cloudss_d4_21_over = newImage("../images/faq_c.gif");
		cloudss_d4_22_over = newImage("../images/subscriptions_c.gif");
		cloudss_d4_23_over = newImage("../images/member_results_c.gif");
		cloudss_d4_24_over = newImage("../images/admin_tasks_c.gif");
		cloudss_d4_25_over = newImage("../images/logout_c.gif");
		cloudss_d4_26_over = newImage("../images/member_profile_c.gif");
		cloudss_d4_27_over = newImage("../images/contact_c.gif");
		cloudss_d4_28_over = newImage("../images/results_c.gif");
		cloudss_d4_29_over = newImage("../images/print_c.gif");
		cloudss_d4_30_over = newImage("../images/member_weeklies_c.gif");
		cloudss_d4_31_over = newImage("../images/member_topetfs_c.gif");
		cloudss_d4_32_over = newImage("../images/member_trades_c.gif");
		cloudss_d4_33_over = newImage("../images/member_periods_c.gif");
		cloudss_d4_34_over = newImage("../images/admin_etf_c.gif");
		cloudss_d4_36_over = newImage("../images/managed_c.gif");
		cloudss_d4_38_over = newImage("../images/admin_emaildb_c.gif");
	
		preloadFlag = true;
	}
}

function process()
{
}

function leave()
{
}

function display_sub(page)
{
	display(page)
	if (page == "member_results")
	{
		if (menu_page == page ||
			menu_page == "member_trades" ||
			menu_page == "member_periods")
		{
			display("member_periods")
			display("member_trades")
			document.write('<font size="-4" face="Arial, Helvetica, sans-serif"><br></font>')
		}
	}
}

function display(page)
{
	//alert("display("+page+")")
	if (page == "print" && 
		menu_page != "faq" &&
		menu_page != "contact" &&
		menu_page != "member_topetfs" &&
		menu_page != "member_results" &&
		menu_page != "our_service" &&
		menu_page != "member_weeklies" &&
		menu_page != "member_trades" &&
		menu_page != "member_periods" &&
		menu_page != "results" &&
		menu_page != "site_map" &&
		menu_page != "member_site_map" &&
		menu_page != "report0208" &&
		menu_page != "managed")
		return
		
	if (page == menu_page)
	{
		b_href = ""
		e_href = ""
		img = "<img name=\""+page+".htm\" src=\"../images/"+page+"_c.gif\" border=0>"
	}
	else
	{
		e_href = "</a>"
		b_href = ""
		img = "<img name=\""+page+".htm\" src=\"../images/"+page+"_a.gif\" border=0>"

		if (page == "logout")
			b_href = "<a href=\"javascript:tc_logout()\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
		else if (page == "login" || page == "member_profile")
			b_href = "<a href=\"https://"+secure_host_name+"/app/html"+session_string+"?page="+page+"\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
		else if (page == "admin_tasks")
			b_href = "<a href=\"http://"+host_name+"/app/html"+session_string+"?page="+page+"&douser=num_pay_users\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
		else if (page == "admin_emaildb")
			b_href = "<a href=\"http://"+host_name+"/app/html"+session_string+"?page="+page+"&douser=emaildb_total\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
		else if (page == "print")
		{
			if(menu_page == "report0208")
				//realpage = "report0208_print&douser=report_request&report=report0208_print"
				realpage = "report0208_print&douser=report_request&report=report0208_print&key=534FD2A62E78F3B57CFAEF8E2F6C005500F5A90F2BC4DB73A2525438390F17FE"
			else
				realpage = menu_page+"_print"
			url = "http://"+host_name+"/app/html"+session_string+"?page="+realpage+"&bgc=FFFFFF&logged_in="+logged_in
			b_href = "<a href=\"javascript:tc_openWindow('"+url+"','print','width=650,height=600,resizable=yes,scrollbars=yes')\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
			img = "<img name=\""+page+".htm\" src=\"../images/"+page+"_a.gif\" border=0>"
 		}
		else 
			b_href = "<a href=\"http://"+host_name+"/app/html"+session_string+"?page="+page+"\" onmouseover=\"changeImages('"+page+".htm', '../images/"+page+"_b.gif'); return true;\" onmouseout=\"changeImages('"+page+".htm', '../images/"+page+"_a.gif'); return true;\">"
	}
	
	document.write(b_href+img+e_href+"<br>")
}

/*
** Function to set a select object to a given entry. 
** BE EXTREMLY CAREFUL to NOT USE a variable i in the calling function. Some VERY NASTY side effects
** could happen if you do...
**
** Serge Dacic etftide 9/29/2005
*/
function tc_setSelect(selectObj, entry)
{
	for (i = 0; i < selectObj.length; i++) 
	{      
		if (selectObj.options[i].value == entry)
		{ 
			selectObj.options[i].selected = true
			return
		}
	}

	alert('Stored value: '+entry+' is not a choice in this pulldown menu')
}
		
function tc_delete(userid)	
{
	if (confirm("Are you sure you want to delete this user?"))
	{
		url = "http://"+host_name+"/app/html"+session_string+"?douser=del&userid="+userid
		window.location.href = url
	}
}

/*
** Given a select object containing months in increasing order, this function
** selects the current month
**
** Serge Dacic etftide 9/29/2005
*/
function tc_setMonth(monthSelect)
{
	today = new Date()
	month = today.getMonth()

	monthSelect.options[month].selected = true
}

/*
** Given a select object containing years, this function
** selects the current year plus one
**
** Serge Dacic etftide 9/29/2005
*/
function tc_setYear(yearSelect)
{
	today = new Date()
	year = today.getFullYear()

	for (i = 0; i < yearSelect.length; i++) 
	{      
		if (yearSelect.options[i].text == year && i != yearSelect.length - 1)
		{ 
			yearSelect.options[i + 1].selected = true
			return
		}
	}

	alert('Stored value: '+year+' is not a choice in this pulldown menu')
}
	

/*
** Generic Function to open a window
**
** page 		= site page to open
** name 		= window name
** decoration 	= window decorations
**
** Serge Dacic etftide 9/29/2005
*/
function tc_openWindow(page, name, decoration)
{
	if(page != "")
	{
		if(page.substring(0,4) == "http")
			url = page
		else
			url = 'http://'+host_name+'/app/html'+session_string+'?page='+page
	}
	else
		url = ""

	window.open(url, "ETF_" + name, decoration)
}


/*
** Function to open a new page of the site 
**
** Serge Dacic etftide 9/29/2005
*/
function tc_openPage(page)
{
	if (page == "login" || page == "member_profile")
		 document.location.href = "https://"+secure_host_name+"/app/html"+session_string+"?page="+page
	else
		document.location.href = "http://"+host_name+"/app/html"+session_string+"?page="+page
}


/*
** There are three functions in this set for credit card validation.
** The main function is:
** 
** tc_validCardNumber(cardNumber,cardType)
** 	parameters:
** 		all paramaters are string values.
** 		cardType can be:
** 			'AMEX' for American Express
** 			'DISCOVER' for Discover
** 			'MASTERCARD' for MasterCard
** 			'VISA' for Visa
** 	description:
** 		This function will check string length, valid characters, specific credit card prefixes and test
** 		the Mod 10 (LUHN Formula) for validating possible credit card numbers.  This function can only
** 		authorize that the given card data is potentially valid.  You would still need to run actual
** 		card validation routines to verify the actual account.
** 	returns:
** 		this function returns true if the card number could be valid for the card type.
** 		false otherwise.	
** 
** supporting functions:
** 
** mod10( cardNumber )
** 	parameters:
** 		this function takes the text string card number and runs the Mod 10 formula on its respective digits.
** 	description:
** 		Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
** 	returns:
** 		this function returns true if the number passes the check digit test.
** 		false otherwise.
** 
** tc_validCardDate( cardMonth, cardYear )
** 	parameters:
** 		this function takes the text string values given by the html form.
** 	description:
** 		this function basically will check to make sure todays date is less than the expiration date the user inputs.
** 		this function is not locked into using 2 digit dates.
** 	returns:
** 		this fucntion returns true if the card is expired.
** 		false otherwise.
** 
** Serge Dacic etftide 9/29/2005
*/

function mod10( cardNumber ) 
{ 
	// LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;
	for( i = 0; i < cardNumber.length; ++i ) 
	{
		ar[i] = parseInt(cardNumber.charAt(i));
	}
	for( i = ar.length -2; i >= 0; i-=2 ) 
	{  										 // you have to start from the right, and work back.
		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
	}										 // if the double digit is > 9, add those individual digits together 
	for( i = 0; i < ar.length; ++i ) 
	{
		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
	}
	return (((sum%10)==0)?true:false);	  	
}

function tc_validCardDate( month, year ) 
{
	var now = new Date();
	var expiresIn = new Date('20'+year,month,0,0,0)		// create an expired on date object with valid thru expiration date
	if( now.getTime() < expiresIn.getTime() ) 
		return true;
	return false;
}

function tc_validCardNumber(cardNumber,cardType) 
{
	if( cardNumber.length == 0 )
		return false;				

	for( var i = 0; i < cardNumber.length; ++i ) 
	{		
		// make sure the number is all digits.. (by design)
		var c = cardNumber.charAt(i);
		if( c < '0' || c > '9' ) 
			return false;
	}
	var length = cardNumber.length;			//perform card specific length and prefix tests
	switch( cardType ) 
	{
		case 'AMEX':
			if( length != 15 ) 
				return false;
			var prefix = parseInt( cardNumber.substring(0,2));
			if( prefix != 34 && prefix != 37 ) 
				return false;
			break;
		case 'DISCOVER':
			if( length != 16 ) 
				return false;
			var prefix = parseInt( cardNumber.substring(0,4));
			if( prefix != 6011 ) 
				return false;
			break;
		case 'MASTERCARD':
			if( length != 16 ) 
				return false;
			var prefix = parseInt( cardNumber.substring(0,2));
			if( prefix < 51 || prefix > 55) 
				return false;
			break;
		case 'VISA':
			if( length != 16 && length != 13 ) 
				return false;
			var prefix = parseInt( cardNumber.substring(0,1));
			if( prefix != 4 ) 
				return;
			break;
	}
	if( !mod10( cardNumber ) )                           		
		return false;

	return true; // at this point card has not been proven to be invalid
}

/*
** Function to test if a given email address is valid
**
** Serge Dacic etftide 9/29/2005
*/
function tc_isValidEmail(str)
{
        var apos = str.indexOf("@");
        var dpos = str.indexOf(".");
        var epos = str.indexOf("]");
        var fpos = str.indexOf("[");     
        var gpos = str.indexOf(" ");     
        if (apos <= 0 || dpos <= 0 || epos > 0 || fpos > 0 || gpos > 0)
             return false;
        if (dpos+1 >= str.length)
             return false;
        return true;
}

/*
** Function to retrieve cookies. Also necessary to test if client has session cookies enabled or not
**
*/
function tc_getCookie(name) 
{
	search = name + "="
	returnvalue = ""
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) 
		{ 
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length
			returnvalue = unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue
}

/*
** Function to write sale tracking cookie
**
** Franck Minssieux etftide 9/29/2005
*/
function tc_writeCookie()
{
	if (tc_getCookie("source") != "")
		return

	found = false

	if (typeof homepage != "undefined")
	{
		pathname = window.location.pathname
	
		if (pathname.length > 1)
		{
			parts = pathname.substring(1).split('/', 2)
			if (!parts[1] || parts[1] == '')
			{
				source = parts[0]
				found = true
			}
			else
			{
				query = window.location.search
				index = query.indexOf("source=")
				if (index != -1)
				{
					source = query.substring(index + 7)
					if (source) 
						found = true
				}
			}
		}
	}

	if (!found)
	{
		referrer = document.referrer

		if (!referrer)
			return
			
		index_start = referrer.indexOf("//")
		if (index_start == -1)
			return
		index_start = index_start + 2
		index_end = referrer.indexOf("/", index_start)
		if (index_end != -1)
			hostname = referrer.substring(index_start, index_end)
		else
			hostname = referrer.substring(index_start)	
		parts = hostname.split('.') 
		source = parts[parts.length - 2]
		if (source != domain && source != secure_domain)
			found = true
	}
	
	if (found)
	{
		expires = cookie_duration
		today = new Date()
		expr = new Date(today.getTime() + (expires * 86400000))
		name = 'source'
		value = source
		path = '/'
		document.cookie = name + "=" +escape(value) +
		( (expires) ? ";expires=" + expr.toGMTString() : "") +
		( (path) ? ";path=" + path : "")
	}
}

/*
** Two functions to format the JavaScript date object.
** tc_formatDate takes a date object and a format string and returns a formatted date. 
** The format string should be supplied in standard date format, in any order with any delimiters.
** dd for Date of the month
** MM for month
** yy or yyyy for Year
** hh for hours
** mm for minutes
** ss for seconds
** 
** e.g. dd/MM/yy hh:mm:ss
** 
** formatDate(DateObject, FormatString) 
** 
** The function above uses tc_addZero function which takes a number converts it to a string and if 
** it is less than 10 adds a "0" in front of it. i.e. 1 returns 01, 2 returns 02 etc. 
**
** Serge Dacic etftide 9/29/2005
*/

function tc_addZero(vNumber)
{ 
  return ((vNumber < 10) ? "0" : "") + vNumber 
} 
        
function tc_formatDate(vDate, vFormat)
{ 
  var vDay              = tc_addZero(vDate.getDate()); 
  var vMonth            = tc_addZero(vDate.getMonth()+1); 
  var vYearLong         = tc_addZero(vDate.getFullYear()); 
  var vYearShort        = tc_addZero(vDate.getFullYear().toString().substring(3,4)); 
  var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
  var vHour             = tc_addZero(vDate.getHours()); 
  var vMinute           = tc_addZero(vDate.getMinutes()); 
  var vSecond           = tc_addZero(vDate.getSeconds()); 
  var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
  vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
  return vDateString 
} 

/*
** Function to always display two decimals
**  Serge Dacic  01/27/2006
*/
function tc_twodec(aNumber)
{  
	var sL = aNumber.length
	var dec = ""

	var pt = sL - 1
	while (aNumber.charAt(pt) != '.' && pt > 0)
		pt--
			
	if(pt == 0)
		dec = ".00"
	else if (pt == sL - 2)
		dec = "0" 
	else if (pt < sL - 2)
		aNumber = aNumber.substring(0, pt+3)
	return aNumber+dec
}

/*
** Function to clear of the Text objects of a given form
**
** Serge Dacic etftide 9/29/2005
*/

function tc_clear_form(aForm)
{
	for (i = 0; i < aForm.elements.length; i++)
	{
		if (aForm.elements[i].type == 'text')
			aForm.elements[i].value = ""
	}
}

/*
** Function to 'escape' the " character: replace " \"
**
** Serge Dacic etftide 4/17/2006
*/

function tc_escapeQuote(aText)
{
    Re = /"/g;    
    return aText.replace(Re,"\\\"")
}


/*
** Function to replace CR by a specific charater (|) in a given text. This needs to be done
** before sending to the server a text inserted in a textarea.
** The 'reverse' function should be used to put the CR back (tc_getText)
**
** Serge Dacic etftide 9/29/2005
*/

function tc_putText(aText)
{
	// BEWARE does not work with Mozilla
    Re = /\r\n/g;    
    return aText.replace(Re,"|")
}

/*
** Function to replace a specific charater (|) by a CR in a given text. 
** This is the 'complement' function of the function above (tc_putText)
**
** Serge Dacic etftide 9/29/2005
*/

function tc_getText(aText)
{    
	Re = /\|/g;    
	return aText.replace(Re,"\r\n")
}

/*
** Function to replace a specific charater (|) by a <br> in a given text. 
** This is the 'complement' function of the function above (tc_putText) for html generation
**
** Serge Dacic etftide 4/17/2006
*/

function tc_getText2(aText)
{    
	Re = /\|/g;    
	return aText.replace(Re,"<br>")
}

/*
** Function to test if a given String is a number
**
** Serge Dacic etftide 9/29/2005
*/
function tc_isANumber(str)
{
	start = 0
	firstChar = str.substring(0, 1)
	
	if (firstChar == ",")
		return false

	if (firstChar == "-")
		start = 1
	
	for (ichar = start; ichar < str.length; ichar++) 
	{ 
		oneChar = str.substring(ichar, ichar + 1)
		if (((oneChar < "0") || (oneChar > "9")) && (oneChar != ",") && (oneChar != ".")) 
			return false
	} 
		
	return true
}

/*
** Admin results details arrays
** stateField: array of state objects
** countryField: array of country objects
** sourceField: array of customer source objects
** affiliateField: array of customer affiliate objects
*/
var stateField 		= new Array()
var countryField 	= new Array()
var sourceField 	= new Array()
var affiliateField 	= new Array()

//*******************************************
// Functions to manage name-value pairs of information coming from the database
//*******************************************
/* 
**
** tc_fieldValue(fieldName, fieldValue)
** Object definition for name-value pair of information coming from the database. 
** Store the name and the value of and include a method to print these as an html
** table row
**
** tc_displayFieldValue()
** method used by tc_fieldValue(fieldName, fieldValue) to display field name and 
** field value as an html table row
**
** Serge Dacic etftide 9/29/2005
*/
function tc_displayFieldValue()
{
    document.write('<tr>')
    document.write('<td width="70%"><div align="right">')
    document.write('<font size="-2" face="Verdana, Arial, Helvetica, sans-serif">' + this.fieldName + ':</font>')
    document.write('</div></td>')
    document.write('<td>')
    document.write('<font size="-2" face="Verdana, Arial, Helvetica, sans-serif">')
    document.write('<b>' + this.fieldValue + '</b>')
    document.write('</font></td>')
    document.write('</tr>')
}

function tc_fieldValue(fieldName, fieldValue)
{
	this.fieldName = fieldName
	this.fieldValue = fieldValue
	this.tc_displayFieldValue = tc_displayFieldValue
}	

/*
** Function to define number of decimal point of a Float
** n = float number
** d = nb of decimal point wanted
**
**  Serge Dacic  10/23/2001
*/
function tc_fdp(n, d)
{  
	d = (d>10?10:d);
   	d = (d<0?0:d);
//   	var r = "" + Math.round(n * Math.pow(10,d));
//   	return (d == 0 ? r : r.substring(0,r.length-d)+"."+r.substring(r.length-d,r.length));
	if (n >= 0)
		r = "" + (Math.round(n * Math.pow(10,d)) + 0.1) / Math.pow(10,d)
	else
		r = "" + (Math.round(n * Math.pow(10,d)) - 0.1) / Math.pow(10,d)
	return r.substring(0, r.indexOf(".") + d + 1)
}

function withinArray(anElt, anArray)
{
	response = false
	for (var ii in anArray)
	{
		if (anArray[ii] == anElt)
		{
			response = true
			break
		}
	}
	return response
}

/*
** Function to draw a flash chart with the data contained in the provided xml file.
**
**  Serge Dacic  01/22/2007
*/
function flashChart(anXml)
{
	/* Linear chart
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="600" height="400" id="FCCusLine" align="">')
	document.write('<param name=movie value="../charts/FCCusLine.swf?IsLocal=1&dataURL='+anXml+'">')
	document.write('<param name=quality value=high>')
	document.write('<param name=bgcolor value=#FFFFFF>')
	document.write('<embed src="../charts/FCCusLine.swf?IsLocal=1&dataURL='+anXml+'" quality=high bgcolor=#FFFFFF  width="600" height="400" name="FCCusLine" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>')
	document.write('</object>')
	*/
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="600" height="400" id="LogMSLine" align="">')
	document.write('<param name=movie value="../charts/LogMSLine.swf?IsLocal=1&dataURL='+anXml+'">')
	document.write('<param name=quality value=high>')
	document.write('<param name=bgcolor value=#FFFFFF>')
	document.write('<embed src="../charts/LogMSLine.swf?IsLocal=1&dataURL='+anXml+'" quality=high bgcolor=#FFFFFF  width="600" height="400" name="LogMSLine" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>')
	document.write('</object>')		  	  
}