/* ----------------- /*
	Opens help desk window
/* ----------------- */
function open_help()
{
	window.open('help.php','help_window','width=460,height=420,scrollbars=yes,status=no,resize=no');
}



/* ----------------- /*
	opens a form in a popup window
/* ----------------- */
function open_win(win,id,width,height)
{
	window.open('includes/styles/default/forms/'+win+'.php?id='+id , win , "width="+width+",height="+height);
}



/* --------------------------------------- /*
	this function is used for the admin.
	it adds item id's to the respective lists
	for either position updating or removal
	from the database
/* --------------------------------------- */
function mod_list(list)
{	
	elements 			= document.db_quickedit.elements;
	rem_id_list 		= '';
	upd_id_list 		= '';
		
	for(i=0;i<elements.length;i++)
	{
		element			= elements[i]
		element_name 	= element.id;																		// name of element
		element_id		= element_name.substring(element_name.lastIndexOf('_')+1, element_name.length);		// id of element
		element_checked = element.checked;																	// if the element is checked
		
		// adds checked checkboxes to the remove list
		if(element_name.indexOf('box_') != -1)
		{
			if(element_checked) rem_id_list += element_id+',';			// add it to remove list
		}
		
		// adds changed position fields to reposition list (for positions other than 0)
		if(element_name.indexOf('db_pos') != -1 && element.value != 0)
		{
			upd_id_list += element_id+',';								// add to the position update list
		}
	}
	
	rem_id_list = rem_id_list.substring(0,rem_id_list.length-1);		// remove last comma
	upd_id_list = upd_id_list.substring(0,upd_id_list.length-1);		// remove last comma
	
	if(document.getElementById('rem_id_list')) document.getElementById('rem_id_list').value = rem_id_list;
	if(document.getElementById('upd_id_list')) document.getElementById('upd_id_list').value = upd_id_list;
	
	//alert(document.getElementById('rem_id_list').value);
	//alert(document.getElementById('upd_id_list').value);	
}



/* --------------------------------------- /*
	this function is used for the admin.
	it adds item id's to the respective lists
	for either position updating or removal
	from the database
/* --------------------------------------- */
function media_mod_list(list,form)
{	
	elements 			= eval('document.'+form+'.elements');
	rem_id_list 		= '';
	
	for(i=0;i<elements.length;i++)
	{
		element			= elements[i]
		element_name 	= element.id;																		// name of element
		element_id		= element_name.substring(element_name.lastIndexOf('_')+1, element_name.length);		// id of element
		element_checked = element.checked;																	// if the element is checked
		
		// adds checked checkboxes to the remove list
		if(element_name.indexOf('box_') != -1)
		{
			if(element_checked) rem_id_list += element_id+',';			// add it to remove list
		}
	}
	
	rem_id_list = rem_id_list.substring(0,rem_id_list.length-1);		// remove last comma
	
	if(elements.rem_id_list) elements.rem_id_list.value = rem_id_list;
	
	//alert(elements.rem_id_list.value)
}


/* ------------------------------------------- /*
	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';
	}
}


/* --------------------------------------- /*
	this function aligns css columns to be 
	the same height. uses the height of the
	highest column.
/* --------------------------------------- */
function align_columns()
{
	right_col 	= document.getElementById('right_column');
	left_col 	= document.getElementById('left_column');
	space_col 	= document.getElementById('left_col_spacer');
	wrp		 	= document.getElementById('wrapper');

	right_col.style.height 	= left_col.offsetHeight+'px';
	space_col.style.height 	= left_col.offsetHeight+50+'px';
	wrp.style.height	 	= left_col.offsetHeight+50+'px';
}



/* --------------------------------- /*
	limit the word count of a specific 
	textarea
/* --------------------------------- */
function limit_textarea(form,area,count,separator){
	textarea 	= eval('document.'+form+'.'+area);
	text_value 	= textarea.value;
	word_list	= text_value.split(separator);
	word_count	= word_list.length;
	if(text_value != '')
	{
		if(separator == ',')	// if the separator is a comma, the textarea's value should be a comma separated list
		{
			if(text_value.indexOf(' ') != -1) // if a space is found in the text...
			{			
				alert('No spaces allowed, comma separated list'); // alert the user that spaces are not allowed
				textarea.value = textarea.value.substring(0,textarea.value.lastIndexOf(' ')); // remove everything upto and including the space
			}
		}
		if(word_count > count)
		{
			alert('You\'ve Reached Your Limit');
			textarea.value = textarea.value.substring(0,textarea.value.lastIndexOf(separator));
		}
	}
}



/* -------------------------------- /*
	creates a bot-proof email link
	from dynamic email address
/* -------------------------------- */
function create_p_email(addr)
{
	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+'\';">Send an Email</a>');
}