/* ----------------- /*
	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(path,width,height)
{
	window.open(path,'win',"width="+width+",height="+height+",scrollbars=yes,status=no,resize=no");
}




/* --------------------------------------- /*
	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.forms['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('rem_'+document.getElementById('rem_id_list').value);
	//alert('pos_'+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 			= document.forms[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';
	}
}




/* --------------------------------- /*
	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));
		}
	}
}




/* ------------------------------------ /*
	helps the user find the cvv number
	on their credit card
/* ------------------------------------ */
function change_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;
	}
}





/* ------------------------------------ /*
	takes the email address and creates
	a protected mailto link. Prevents
	bots from harvesting email addresses.
	addresses must contain an '&' instead
	of the '@' symbol	
/* ------------------------------------ */
function create_p_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>');
}




function view_map(address)
{	
	window.open('http://maps.google.com/maps?q='+address+'&t=h&hl=en','map_window','width=640,height=480');
}

function swap_misc(image)
{
	var orig_image = eval('window.document.'+image);
	var img_string = eval('window.document.'+image+'.src');
	img_base = img_string.substr(0,img_string.length-4);
	img_type = img_string.substr(img_string.length-4,4);
	orig_image.src = img_base+'_over'+img_type;
}

function reset_misc(image)
{
	var orig_image = eval('window.document.'+image);
	var img_string = eval('window.document.'+image+'.src');
	img_base = img_string.substr(0,img_string.length-9);
	img_type = img_string.substr(img_string.length-4,4);
	orig_image.src = img_base+img_type;
}

function pop_up(address)
{	
	window.open(address,'new_window','width=520,height=365');
}





function isArray(obj)
{
	if(obj.constructor.toString().indexOf('Array') != -1) return false;
	else return true;
}