/////////////////////////////////////////////
/////////////////////////////////////////////
// geteventinfo(stringin,position)
// checkSelect(item)
// checkEmail(fieldvalue)
// checkLength(fieldvalue)
// checkChecked(item)
// checkPhone(fieldname,phonenumber)
// checkZip(fieldname,zipcode)
// checkcccnum(field)
// checkccexp(cmonthIN,cyearIN)
// setcountry(cstateIN)
// alphaNumeric(valueIN,valueType)
/////////////////////////////////////////////
/////////////////////////////////////////////
function geteventinfo(stringin,position)
{
	// leave function if any required values are missing
	// or are invalid
	if(stringin.length == 0)
	{
		return('');
	}
	if(position.length == 0 || isNaN(position))
	{
		return('');
	}
	else
	{
		position = parseInt(position);
	}
	delimiter = unescape('%1B'); //ASP chr(27)
	
	// create necessary variables
	var iBegin,iEnd,i,iError,retValue;
	iBegin = 0;
	iEnd = -1;
	i = 0;
	iError = 0;	
	retValue = '';
		
	for(i=1;i<=position;i++)
	{
		iEnd = iEnd + 1;
		iBegin = iEnd;
		iEnd = stringin.indexOf(delimiter,iEnd);		
		//iEnd = Instr(iEnd,stringin,cdelimiter);
		
		if(iEnd == -1)
		{
			iEnd = stringin.length;
		}
		if(iBegin > stringin.length)
		{
			iError = 7;
		}
	}
	
	if(iError == 0)
	{
		retValue = stringin.substring(iBegin,iEnd);
		//retValue = mid(sstring,iBegin,iEnd-iBegin);
	}
	else
	{
		retValue = '';
	}
return(retValue);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkSelect(item)
{
	if(item.selectedIndex == 0)
	{
		return(false);
	}
return(true);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkEmail(fieldvalue)
{
	if(fieldvalue.length == 0)
	{
		return(false);
	}

	var chkAt;
	var chkDot;
	var posAt;
	var posDot;

	chkAt = '@';
	posAt = fieldvalue.indexOf(chkAt);

	if (posAt < 0)
	{
		return (false);
	}

	chkDot = '.';
	posDot = fieldvalue.lastIndexOf(chkDot);

	if (posDot < 0)
	{
		return (false);
	}

	if (posDot <= posAt + 1)
	{
		return (false);
	}
	if (posDot >= (fieldvalue.length - 2))
	{
		return (false);
	}
return(true);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkLength(fieldvalue)
{
	if(fieldvalue.length <= 0)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkChecked(item)
{
// used for verifying that a checkbox or radio group
// has at least one of it's options checked. Returns
// the actual number of checked items (0 - n)
	var i;
	i = 0;
	var checkflag;
	checkflag = 0;
	
	if(item[0])
	{
		for(i=0;i<item.length;i++)
		{
			if(item[i].checked == true)
			{
				checkflag += 1;
			}
		}
	}
	else
	{
		if(item.checked == true)
		{
			checkflag += 1;
		}
	}
	return(checkflag);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkPhone(fieldname,phonenumber)
{
	var i;
	i = 0;
	var newphonenumber;
	newphonenumber = '';
	
	if(phonenumber.length > 0)
	{
		while(i >= 0)
		{
			phonenumber = phonenumber.replace(' ','');
			i = phonenumber.indexOf(' ');
		}
		for(i=0;i<phonenumber.length;i++)
		{
			if(!isNaN(phonenumber.substr(i,1)))
			{
				newphonenumber = newphonenumber + phonenumber.substr(i,1);
			}
		}

		if(newphonenumber.length != 10)
		{
			return(false);
		}
		else
		{
			newphonenumber = '(' + newphonenumber.substr(0,3) + ') ' + newphonenumber.substr(3,3) + '-' + newphonenumber.substr(6,4);
			
			var definitionstring;
			definitionstring = eval('document.mainform.' + fieldname);
			definitionstring.value = newphonenumber;
		}
		return(true);
	}
	else
	{
		return(false);
	}
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkZip(fieldname,zipcode)
{
	var i;
	i = 0;
	var newzipcode;
	newzipcode = '';
	
	if(zipcode.length > 0)
	{
		while(i >= 0)
		{
			zipcode = zipcode.replace(' ','');
			i = zipcode.indexOf(' ');
		}
		for(i=0;i<zipcode.length;i++)
		{
			if(!isNaN(zipcode.substr(i,1)))
			{
				newzipcode = newzipcode + zipcode.substr(i,1);
			}
		}
		
		if(isNaN(newzipcode))
		{
			return(false);
		}
		if(newzipcode.length != 5)
		{
			if(newzipcode.length != 9)
			{
				return(false);
			}
		}
	}
	else
	{
		return(false);
	}
return(true);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkcccnum(field)
{
	var check_char;
	var i = 0;

	// now check mod10
	var doubledigit = field.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for(i=0;i<field.length;i++)
	{
		tempdigit = eval(field.charAt(i))

		if(doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}
	return(checkdigit % 10) == 0 ? true : false;
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function checkccexp(cmonthIN,cyearIN)
{
	if(cmonthIN.length == 0)
	{
		return(false);
	}
	if(cyearIN.length == 0)
	{
		return(false);
	}
	
	// verify expiration date provided is at least present month/year
	cmonthIN = parseInt(cmonthIN);
	cyearIN = parseInt(cyearIN);
	
	var todayDate = new Date()
	var sMonth = todayDate.getMonth() + 1
	var sYear = todayDate.getFullYear()

	if (cyearIN < sYear)
	{
		return(false);
	}
	else if(cyearIN == sYear)
	{
		if(cmonthIN < sMonth)
		{
			return(false);
		}
	}
return(true);
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function setcountry(cstateIN)
{
	var i = 0;
	var state = cstateIN[cstateIN.selectedIndex].value;
	
	// values to match against. I do this so that if the format
	// of the country list changes we don't need to update all
	// of the switch statements below, just these two values and
	// it will all work.
	var usa = 'USA:USA';
	var canada = 'CANA:CANADA';
	var country = '';
	
	switch(state)
	{
		// non-country specific areas
		case 'VI:VIRGIN ISLANDS':
			country = 'VI:VIRGIN ISLANDS';
			break;
		// canadian provinces
		case 'AB:ALBERTA':
		{
			country = canada;
			break;
		}
		case 'BC:BRITISH COLUMBIA':
		{
			country = canada;
			break;
		}
		case 'MB:MANITOBA':
		{
			country = canada;
			break;
		}
		case 'NB:NEW BRUNSWICK':
		{
			country = canada;
			break;
		}
		case 'NF:NEWFOUNDLAND':
		{
			country = canada;
			break;
		}
		case 'NT:NORTHWEST TERRITORIES':
		{
			country = canada;
			break;
		}
		case 'NS:NOVA SCOTIA':
		{
			country = canada;
			break;
		}
		case 'ON:ONTARIO':
		{
			country = canada;
			break;
		}
		case 'PE:PRINCE EDWARD ISLANDS':
		{
			country = canada;
			break;
		}
		case 'QC:QUEBEC':
		{
			country = canada;
			break;
		}
		case 'SK:SASKATCHEWAN':
		{
			country = canada;
			break;
		}
		case 'YT:YUKON TERRITORIES':
		{
			country = canada;
			break;
		}
		default:
		{
			country = usa;
		}
	}
	
	if(country.length > 0)
	{
		var ccountry = document.getElementById('ccountry');
		for(i=0;i<ccountry.length;i++)
		{
			if(ccountry[i].value == country)
			{
				ccountry.selectedIndex = i;
			}
		}
	}
}
/////////////////////////////////////////////
/////////////////////////////////////////////
function alphaNumeric(valueIN,valueType)
{
	//value type key
	// '' = alphanumeric
	// 'alpha' = alpha only
	// 'numeric' = numeric only
	
	if(valueType != '' && valueType != 'alpha' && valueType != 'numeric')
	{
		alert('Unexpected valueType value provided.\n\nExpected: \'\', \'alpha\', \'numeric\'\n\nProvided: ' + valueType);
		return(valueIN);
	}
	
	var retValue = '';
	var i = 0;
	
	for(i=0;i<valueIN.length;i++)
	{	
		// we need to keep the following alpha characters
		switch (valueType)
		{
			case '':
				if('abcdefghijklmnopqrstuvwxyz0123456789'.indexOf(valueIN.substr(i,1).toLowerCase()) >= 0)
				{
					retValue = retValue + valueIN.substr(i,1);
				}
				break;
			case 'alpha':
				if('abcdefghijklmnopqrstuvwxyz'.indexOf(valueIN.substr(i,1).toLowerCase()) >= 0)
				{
					retValue = retValue + valueIN.substr(i,1);
				}
				break;
			case 'numeric':
				if('0123456789'.indexOf(valueIN.substr(i,1).toLowerCase()) >= 0)
				{
					retValue = retValue + valueIN.substr(i,1);
				}
				break;
		}
	}
	//alert('returning: ' + retValue);
return(retValue);
}
/////////////////////////////////////////////
/////////////////////////////////////////////