var lastId='';

// replaces all of the styles on input, buttons, submits, selects and textareas.
var changeInputStyles = function()
{
	var el=document.getElementsByTagName('input');
	
	for (var i=0; i < el.length ;i++ )
	{
		if(el[i].getAttribute('type')) 
		{
			switch (el[i].getAttribute('type'))
			{
				case "password":
				case "text":
					el[i].className +=' text';
				break;
				case "submit":
				case "button":
					el[i].className +=' button';
				break;
				case "checkbox":
					el[i].className +=' checkbox';
				break;
				case "radio":
					el[i].className +=' radio';
				break;
			}
		}	
	}
}

var loadProjectsByCategory = function(id)
{
	//new Ajax.Request(url,
	var url='_projects.asp?Mode=1&ProjectType=' + id + "&d=" + Math.random();
	new Ajax.Updater('category', url,		
	{     
		method:'get',
		onLoading: function() { 
			Element.hide('category');
			Element.show('loader');	
		},
		onLoaded: function() { 
			Element.hide('category');			
		},
		onSuccess: function() { 
			Element.hide('details');
			Element.hide('loader');
			Effect.Appear('category',{duration:.4});				
		},
		onFailure: function(){ Element.hide('loader'); alert('There was an error gathering the project data.') } 
	}); 
}

var loadProjectDetails = function(id,projectType,rfa,nextProject,projects)
{
	var url='_details.asp?rfa='+ rfa +'&id=' + id + '&projectType=' + projectType + "&np=" + nextProject + "&p=" + projects + "&d=" + Math.random();

	new Ajax.Updater('details', url,		
	{     
		method:'get',
		onLoading: function() { 
			Element.hide('details');
			Element.show('loader');			
			Element.hide('category');				
			
			Element.removeClassName('t_' + lastId,'img_border');
		},
		onLoaded: function() { 
			Element.hide('details');
			Element.show('loader');			
			Element.hide('category');			
		},
		onSuccess: function() { 
			Element.hide('loader');
			//Element.show('details');
			Effect.Appear('details',{duration:.4});
			
			// remove the border from the last selection
			Element.removeClassName('t_' + lastId,'img_border');
			// set the lastID to this ID
			lastId=id;
			// add the border to the current selection
			Element.addClassName('t_' + id,'img_border');
		},
		onFailure: function(){ Element.hide('loader'); alert('There was an error getting the project details.') } 
	}); 
}

var loadLocalProj = function(id)
{
	Element.hide('loader');		
	Effect.Fade('details',{duration:.20});
	Effect.Appear('category',{ duration:0.40});	
	
	// remove the border from the last selection
	Element.removeClassName('t_' + lastId,'img_border');
	// set the lastID to this ID
	lastId=id;
	// add the border to the current selection
	Element.addClassName('t_' + id,'img_border');
}

var loadNextProject = function()
{
	// get the list of projects from the query string and 
	// create an array of project id's
	var aProject=new Array(projects);
	var nextProjectId=0;
	
	if(aProject.length > nextProject-1)
	{
		nextProjectId=aProject[nextProject-1];
	}
	//new Ajax.Request(url,
	var url='_details.asp?rfa='+ rfa +'&id=' + Id + '&ProjectType=' + projectType + "&d=" + Math.random();
	
	new Ajax.Updater('details', url,		
	{     
		method:'get',
		onLoading: function() { 
			Element.hide('details');
			Element.show('loader');			
			Element.hide('category');	
		},
		onLoaded: function() { 
			Element.hide('details');
			Element.show('loader');
			Element.hide('category');			
		},
		onSuccess: function() { 
			Element.hide('loader');
			//Element.show('details');
			Effect.Appear('details',{duration:.3});					
		},
		onFailure: function(){ Element.hide('loader'); alert('There was an error getting the project details.') } 
	}); 
}

// for flash to hide the project details using prototype externally
var hideDetails = function()
{
	Element.hide('details');
}
var loadWIP = function()
{
	//new Ajax.Request(url,
	var url='_wip.asp' + "?d=" + Math.random();
	new Ajax.Updater('wip_category', url,		
	{
		method:'get',
		onLoading: function() { 
			Element.hide('wip_category');
			Element.show('loader');
		},
		onLoaded: function() { 
			Element.hide('wip_category');
			Element.show('loader');
		},
		onSuccess: function() { 
			Element.hide('loader');
			//Element.show('wip_category');
			Effect.Appear('wip_category',{duration:.4});
		},
		onFailure: function(){ Element.hide('loader'); alert('We\'re Sorry!\nThere was a problem getting the work in progress project listing.\nPlease try again later.') } 
	}); 
}
// Check that an email address is valid based on RFC 821
var isValidEmail = function(email) {
	var re  = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return re.test(email);
}
// Validates phone number
var isValidPhone = function(string){
	var re  = /^\(?[1-9]\d{2}\)?[- ]?\d{3}[- ]\d{4}$/;
	return re.test(string);
}

