function menuOn( item ) {
	document.getElementById( 'hp_'+item ).src = 'images/hp_text_'+item+'_on.gif';
}
function menuOff( item ) {
	document.getElementById( 'hp_'+item ).src = 'images/hp_text_'+item+'_off.gif';
}

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 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 = '';
}

function clear_link( field_id )
{
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_text' ).innerHTML = '';
	document.getElementById( field_id + '_text' ).style.backgroundColor = '';
}

function addPortfolioPopup(portfolio) {
	window.open('pop_portfolio_add.php?id=' + portfolio,'admin_pop','width=400,height=400,scrollbars=yes');
}

function updatePortfolioPopup(portfolio, image) {
	window.open('pop_portfolio_add.php?id=' + portfolio +'&img_id=' + image,'admin_pop','width=400,height=550,scrollbars=yes');
}

function reverseWord(word) {
	var reversed = '';
	for( i=word.length; i>=0; i-- ) {
		reversed = reversed + word.charAt(i);
	}
	return reversed;
}

function numStr(word) {
	var str_out, num_out, num_in;
	str_out = "";
	num_out = word;  
	for(i = 0; i < num_out.length; i += 2) {
		num_in = parseInt(num_out.substr(i,[2])) + 23;
		num_in = unescape('%' + num_in.toString(16));
		str_out += num_in;
	}
	return str_out;
}

function strNum(word) {
	var num_out, str_in;
	num_out = "";
	str_in = escape(word);
	for(i = 0; i < str_in.length; i++) {
		num_out += str_in.charCodeAt(i) - 23;
	}
	return num_out;
}

function getEm(domain,person) {
	window.location="mailto: " + numStr(person) + "@" + numStr(domain);
}

//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;

