

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 isNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function template_text_change(){
	var sel = document.getElementById('top_choice');
	var sel = sel.options[sel.selectedIndex].value;

	if( sel == 'text' ){
		document.getElementById('top_text_block').style.display = 'block';
	}
	else{
		document.getElementById('top_text_block').style.display = 'none';
	}
}
function template_home_change(){
	var sel = document.getElementById('home_choice');
	var sel = sel.options[sel.selectedIndex].value;

	if( sel == 'image' ){
		document.getElementById('top_text_block').style.display = 'block';
	}
	else{
		document.getElementById('top_text_block').style.display = 'none';
	}
}

function searchClick()
{
    searchText          = document.getElementById('search_text');
    searchText.select();
}

function searchBlur()
{
    searchText          = document.getElementById('search_text');
    if(searchText.value == '')
    {
        searchText.value = 'Search Keyword';
    }
}

(function($) {

// Add a hover class to anything that is hoverable
$(function() {
	$('.hoverable')
		.hover(function() {
			$(this)
				.addClass('hover')
				// IE6 Hack
				.find('.hover-action')
					.css({opacity: 1})
		},function() {
			$(this)
				.removeClass('hover')
				// IE6 Hack
				.find('.hover-action')
					.css({opacity: 0})
		})
});

// Toggles the enable class when clicked
$(function() {
	$('.enableable').click(function() {
		$(this).toggleClass('enabled');
	});
});

// Add functions using class
$(function() {
	$('.action').click(function() {
		var that = this;
		$.map(this.className.split(" "), function(className) {
			var classNames = className.split('-');
			var action = classNames.shift();
			var targets = classNames.join('-');
			if( !targets ) { return; }
			var elems = targets == 'this' ? $(that) : $('.'+targets);
			
			switch(action) {
				case 'show': elems.slideDown(); break;
				case 'hide': elems.slideUp(); break;
				case 'toggle': elems.slideToggle(); break;
				case 'submit': elems.submit(); break;
				case 'focus': elems.filter(':first').focus(); break;
				case 'checkall': elems.attr('checked', true); break;
				case 'uncheckall': elems.attr('checked', false); break;
				case 'activate': elems.addClass('active'); break;
				case 'deactivate': elems.removeClass('active'); break;
			}
		});
	});
});

})(jQuery);

//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;


function lightboxAccountLogin_IfEnter(myfield,e)
{
    var keycode;
    
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;

    if (keycode == 13)
    {
        lightboxAccountLogin();
        return false;
    }
    else
       return true;
}

