

function clearField( field_name )
{
	document.getElementById( field_name ).value = '';
	document.getElementById( field_name ).style.backgroundColor = '';
}

function highlightFields( field_str )
{
	var fields = field_str.split(',');
	
	for( var i=0; i<fields.length; i++ )
	{
		highlightField( fields[i], '#F6F5CF' ); 
	}
	
}

function set_internal_input_link( element_id, url, color, strText )
{
	// replace single quotes with special characters
	strText = strText.replace( "'", "&#39;" );
	
	link = "<a href='" + url + "' title='" + strText + "'>";
	
	document.getElementById(element_id + "_url" ).value=link;
		
	document.getElementById(element_id + "_url" ).style.backgroundColor=color;
	
	if( strText != "" )
	{
		document.getElementById(element_id + "_alt" ).value=strText;
		
	}	//end if
		
}	//end function


function highlightField( field_name, field_color )
{
	document.getElementById( field_name ).style.backgroundColor = field_color;
}


function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') +  num + '.' + cents);
}	//end function

function validate_required_fields(frmName, strTextBoxes)
{
	var oForm = document.getElementById(frmName);
	
	//turn the comma separated list into an array
	var arrBoxes = strTextBoxes.split(",");
	
	error = 0;
	
	//loop thru each box and determine if the text value is empty
	for( var intCount = 0; intCount < arrBoxes.length; intCount++ )
	{
		arrBoxes[intCount] = arrBoxes[intCount].trim_spaces();
		
		//alert( "inCount: " + intCount + " - text box: -->" + arrBoxes[intCount] + "<--" );
		
		var strText = document.getElementById(arrBoxes[intCount]).value;
		
		if( strText.length == 0 )
		{
			error++;
			
		}	//end if
		
	}	//end for loop
	
	//if any errors, then user did not enter all the required fields
	if( error > 0 )
	{
		alert( "Please enter all the required fields." );
		
		valid = false;
		
	}	//end if
	
	else
	{
		valid = true;
		
	}	//end else
	
	return valid;
	
}	//end function

function pop_templates()
{
	window.open('pop_templates.php','admin_pop','width=600,height=400,scrollbars=yes,resizable=yes');	
}

//removes all spaces in a string
function removespaces() 
{
	return this.replace(/.*\S/,'');
	
}	//end function

//trims leading and trailing spaces
function trim_spaces() 
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
	
}	//end function

function clear_image( field_id )
{
	document.getElementById( 'pg-' + field_id ).src = 'images/spacer.gif';
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_filename' ).value = '';
}

//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;


function popUp(URL, width, height) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
}	//end function

function set_source_for_iframe()
{
	parent_url = document.location.href;
	
	var iframe = document.getElementById("iframe_menu");
	
	var new_source = iframe.src + '?djo_page=' + parent_url;
	
	iframe.src = new_source;
	
}	//end function

function changeBgColor( objElement, color )
{
	objElement.style.backgroundColor = color;
	
}	//end function

/*
<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->

<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
*/
function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
		
	}	//end if
	
	// otherwise, update 'characters left' counter
	else 
	{
		countfield.value = maxlimit - field.value.length;
		
	}	//end else
	
}	//end function



// Hide or show elements on a page
// nodeIds - ID of one or more (separated by "|") elements on a page
// visTo - takes a value of 0 or 1 to set visibility as either none or block (by default)
// visType (optional) - allows override of default block visibility type for other options (e.g. inline, table-row-group, etc.)
function hide_show(nodeIds, visTo, visType)
{
	var nodeIdArr = nodeIds.split("|");
	
	for(i=0; i<nodeIdArr.length; i++) {
		var nodeId = nodeIdArr[i];
		var thisNode = document.getElementById(nodeId);
		
		// check for node's current visibility
		if(visTo == 1) {
			if(visType) {
				if( (visType == "table-row-group" || visType == "table-row") && document.all ) visType = "block";
				thisNode.style.display = visType;
			} else {
				thisNode.style.display = "block";
			}
		} else if(visTo == 0) {
			thisNode.style.display = "none";
		} else { // find node current vis and assume the opposite
			var currVis = thisNode.style.display;
			
			if(currVis) {
				if(currVis == "none")
					thisNode.style.display = ( visType ? visType : "block" );
				else
					thisNode.style.display = "none";
			} else if(thisNode.className == "no_show") {
				thisNode.style.display = ( visType ? visType : "block" );
			} else { // assume element starts as visible
				thisNode.style.display = "none";
			}
		}
	}
}

function swap_expand_icons(clicked_header) {
	var curr_class = clicked_header.className;

	if( curr_class == "expandable")
		var new_class = "contractable";
	else
		var new_class = "expandable";

	clicked_header.className = new_class;
}

function redirectToURL()
{
	if (document.getElementById('archive') && document.getElementById('archive').value!="")
	{
		document.location = (document.getElementById('archive').value);
	}
}
