/* OPEN 'OTHER' OPTION FIELD
------------------------------------------- /*
	if a text field is tied to a drop down menu,
	this function does 3 things:
	it shows the text field when a specific item is selected in the drop down
	it enables the field on show, or disables it on hide
	it may also show instructions for certain options
/* ------------------------------------------- */
function check_other(value){
	if(value == 'Code' || value == 'other' || value == 'Referral')
	{
		document.getElementById('referral_text').disabled = false;
		document.getElementById('ref_field').style.display = 'block';
		
		switch(value)
		{
			case 'other':
				document.getElementById('ref_num').style.display = 'none';
				document.getElementById('ref_info').style.display = 'block';
				document.getElementById('ref_name').style.display = 'none';
				break;
				
			case 'Code':
				document.getElementById('ref_num').style.display = 'block';
				document.getElementById('ref_info').style.display = 'none';
				document.getElementById('ref_name').style.display = 'none';
				break;
				
			case 'Referral':
				document.getElementById('ref_num').style.display = 'none';
				document.getElementById('ref_info').style.display = 'none';
				document.getElementById('ref_name').style.display = 'block';
				break;	
		}
	}
	else
	{
		document.getElementById('referral_text').disabled = true;
		document.getElementById('ref_field').style.display = 'none';
	}
}





/* LIMIT TEXT AREA
--------------------------------- /*
	limit the word or character count of a specific textarea
	different words/characters are determined by the separator
	comma separation does not allow any spaces anywhere
	
	to limit by characters, use '' as the separator, and 
	count as the number of characters.
/* --------------------------------- */
function limit_textarea(form,area,count,separator)
{
	var textarea 	= eval('document.'+form+'.'+area);
	var text_value 	= textarea.value;
	var word_list	= text_value.split(separator);
	var word_count	= word_list.length;
	
	if(text_value != '')
	{
		// if the separator is a comma, the textarea's value should be a comma separated list
		if(separator == ',')
		{
			// if a space is found in the text...
			if(text_value.indexOf(' ') != -1)
			{
				// alert the user that spaces are not allowed
				alert('No spaces allowed, comma separated list');
				
				// remove everything upto and including the space
				textarea.value = textarea.value.substring(0,textarea.value.lastIndexOf(' '));
			}
		}
		if(word_count > count)
		{
			// alert that the limit has been reached/passed
			alert('You\'ve Reached Your Limit');
			
			// remove everything up to the last separator
			if(separator == '') textarea.value = textarea.value.substring(0,count);
			else textarea.value = textarea.value.substring(0,textarea.value.lastIndexOf(separator));
		}
	}
}





/* LOCATE CVV
------------------------------------ *
	helps the user find the cvv number
	on their credit card
/* ------------------------------------ */
function locate_cvv(value)
{
	cvv_info = document.getElementById('cvv_info');
	switch(value)
	{
		case 'vis': cvv_info.innerHTML = 'Last 3 digits on back of card';		break;
		case 'mcd':	cvv_info.innerHTML = 'Last 3 digits on back of card';		break;
		case 'amx':	cvv_info.innerHTML = '4 small numbers on front of card';	break;
	}
}





/* CREATE PROTECTED EMAIL
------------------------------------ /*
	- Takes the email address and creates a protected mailto link.
	- Prevents bots from harvesting email addresses.
	- Addresses must contain an '&' instead of the '@' symbol
	- Requires replacement text
	
/* ------------------------------------ */
function protect_email(addr,text)
{
	addr_top = addr.substr(0,addr.indexOf('&'));
	addr_btm = addr.substr(addr.indexOf('&')+1,addr.length);
	
	addr = "mai" + "lto" + ":" + addr_top + "@" + addr_btm;
	document.write('<a href="javascript:;" onMouseOver="javscript:this.href=\''+addr+'\';">'+text+'</a>');
}





/* ADDRESS TO MAP LOCATION
------------------------------------ /*
	Takes an address (with city,state,zip)
	and opens up a window with a map.
	
	* May be blocked by popup blockers.
/* ------------------------------------ */
function view_map(address)
{	
	window.open('http://maps.google.com/maps?q='+address+'&t=h&hl=en','map_window','width=640,height=480');
}



/* ----------------- /*
	opens a form in a popup window
/* ----------------- */
function open_win(path,width,height)
{
	window.open(path,'win',"width="+width+",height="+height+",scrollbars=yes,status=no,resize=no");
}

