/* 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="this.href=\''+addr+'\';">'+text+'</a>');
}






/* CHECK/REMOVE HTTP://
------------------------------------ /*
	Checks the value for http:// and 
	removes it if found.
------------------------------------ */
function check_http(id,value)
{
	var return_value = value;
	if(value.indexOf('http://') != -1) return_value = value.substring(7,value.length);
	document.getElementById(id).value = return_value;
}






/* SELECT ALL INBOX MESSAGES
------------------------------------ /*
	Selects all inbox messages for removal
------------------------------------ */
function select_all(form,checked)
{
	var form 		= document.forms[form];
	var id_list 	= new Array();
	
	for(var i=0;i<form.length;i++)
	{
		var element = form[i];
		var type	= form[i].type;
		var name	= form[i].name;
		var id		= name.substring(4);
		
		if(checked && type == 'checkbox')
		{
			element.checked = true;
			if(id) id_list.push(id);
		}
		else if(!checked && type == 'checkbox')
		{
			element.checked = false;
			id_list = new Array();
		}
	}
	
	document.getElementById('rem_id_list').value = id_list.toString();
}






/* SELECT ONE INBOX MESSAGE
------------------------------------ /*
	Selects one inbox messages for removal
------------------------------------ */
function select_one(form)
{
	var form 		= document.forms[form];
	var id_list 	= new Array();
	
	for(var i=0;i<form.length;i++)
	{
		var element = form[i];
		var type	= form[i].type;
		var name	= form[i].name;
		var checked = form[i].checked;
		var id		= name.substring(4);
				
		if(checked && type == 'checkbox')
		{
			if(id) id_list.push(id);
		}
	}
	document.getElementById('rem_id_list').value = id_list.toString();
}






/* CHANGES FORM ACTION
------------------------------------ /*
	this is used with image fields to initiate the cropping forms
	it is also used within the cropping forms, if there are multiple images needing to be cropped
	
	append the new action to url
/* ------------------------------------ */
function change_action(value,url)
{
	var form 			= document.forms[0];
	var count 			= form.length;
	var new_action 		= url+'crop/';
		
	if(value != '') document.forms[0].action = new_action;
	else document.forms[0].action = url;
}