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 clear_link( field_id )
{
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_text' ).innerHTML = '';
	document.getElementById( field_id + '_text' ).style.backgroundColor = '';
}

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 = '';
	
	if( document.getElementById( field_id + "_name" ) )
	{
		document.getElementById( field_id + "_name" ).innerHTML = "";
		
	}	//end if
}

//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
    	var expires = "; expires="+date.toGMTString();
  	}
  	else expires = "";
  	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  	var nameEQ = name + "=";
  	var ca = document.cookie.split(';');
  	for(var i=0;i < ca.length;i++) {
    	var c = ca[i];
    	while (c.charAt(0)==' ') c = c.substring(1,c.length);
    	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  	}
  	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



function clearImage( formfield, imagepreview )
{
	document.getElementById( formfield ).value = '';
	document.getElementById( formfield + '_filename' ).value = '';
	document.getElementById( imagepreview ).src = '';
}

/*----------------------
hideHelp()
function to hide the help tips that will display when
a certain field of a form is focussed on.  
----------------------*/
function hideHelp() {
	handle = document.getElementById("helpDisplay"); 
	if( !handle ){
		alert("Cannot find the help display area in the document.");
	}
	else {
		handle.setAttribute("class", "helpDisplayOff"); 
		handle.setAttribute("className", "helpDisplayOff"); 
		handle.innerHTML = "";
	}
	return; 
}



//-------------------------------------------
function removeClassName (elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}
function addCSSClass (elem, className) {
	removeClassName (elem, className);
	elem.className = (elem.className + " " + className).trim();
}
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}
function stripedTable() {
	if( document.getElementById && document.getElementsByTagName ) 
	{
		var allTables = document.getElementsByTagName('table');
		if( !allTables ) { return; }

		for( var i = 0; i < allTables.length; i++ )
		{
			if( allTables[i].className.match(/[\w\s ]*stripedTable[\w\s ]*/) )
			{
				var trs = allTables[i].getElementsByTagName("tr");
				for( var j = 0; j < trs.length; j++ )
				{
					removeClassName(trs[j], 'alternateRow');
					addCSSClass(trs[j], 'normalRow');
				}
				for( var k = 0; k < trs.length; k += 2 )
				{
					if( !trs[k].className.match(/[\w\s ]*sectionRow[\w\s ]*/) )
					{
						removeClassName(trs[k], 'normalRow');
						addCSSClass(trs[k], 'alternateRow');
					}
				}
			}
		}
	}
}

function writeEmail(to, domain) {
	document.write('<a href="mailto:' + to + '@' + domain + '">' + to + '@' + domain + '</a>');
}

function getRivets(n) {

	var success = function (t) { 
		var bits = t.responseText;
		eval(bits);
		
		for(i=0;i<rivets.bit.length;i++) {
			//console.log(rivets.bit[i]);
			
			setRivet((i + 1), rivets.bit[i]);
		}
	}
	
	var params = {
		method: "get",
		parameters: "n=" + n,
		onComplete: success
	}
	
	new Ajax.Request(url + 'get_rivets.php', params);
}

function setRivet(n, bit) {
	
	var html = '<h3>' + bit.title + '</h3>';
	
	if(bit.img.length > 0) {
		src = url + 'files/library/' + bit.img;
		html = html + '<img src="' + src + '" />';
	}
	
	html = html + '<div class="p">' + bit.text + '</div>';
	
	if(bit.link.length > 0) {
		html = html + '<p><a href="' + bit.link + '">See More &raquo;</a></p>';
	}
	
	html = html + '<p><a href="#" onclick="javascript:newRivet(' + n + ');">More Stories</a></p>';
	
	$('rivet_' + n).innerHTML = html;
}

function newRivet(n) {

	$('rivet_' + n).innerHTML = "Loading rivet bit...";

	var success = function (t) { 
		var bits = t.responseText;
		eval(bits);
			
		setRivet(n, rivets.bit[0]);
	}
	
	var params = {
		method: "get",
		parameters: "n=1",
		onComplete: success
	}
	
	new Ajax.Request(url + 'get_rivets.php', params);
}

function europewindow(){
	window.open("http://europe.airstream.com/","","height=545,width=750,menubar=yes,resizable=yes, scrollbars=yes, status=0,titlebar=yes,toolbar=yes ,left=150,top=150")
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function splash() {

}

function asna() {
	$('splash').style.display = 'none';
	$('container').style.display = 'block';
}