/**
 * SEVENSPIRE JS-UTILITIES
 * (c) 2008 by sevenspire.com
 * Author: Peter Wallner | peter@gtfo.at
 */


function Sevenspire()
{
	var that = this;

	this.$ = function(id) 
	{
		return document.getElementById(id); 
	}
	
	this.$v = function(id)
	{
		return document.getElementById(id).value; 
	}

	this.changeBgColor = function(id, color)
	{
		this.$(id).style.backgroundColor = color;
	}
	
	this.changeBorderColor = function(id, color)
	{
		this.$(id).style.borderColor = color;
	}

	this.validateForm = function(elements, msg)
	{
		var ret_val = true;
		var elements = elements.split(' ');

		for (i = 0; i <= (elements.length-1); i++) {
			var e = elements[i];
			this.highlightFormElement(e);
			
			if (!this.$v(e)) {
	  		ret_val = false;
	  	}
	  	
	  	if (e == 'input_agb' && !$(e).checked) {
	  		msg = 'Sie müssen die AGB akzeptieren';
	  		ret_val = false;
	  	}
		}

		if (ret_val == false && msg != '') {
			alert(msg);
		}

		return ret_val;
	}

	this.highlightFormElement = function(id, options)
	{
		if (!options) {
			options = new Array();
		}
	
		if (!options[0]) {
			options[0] = '#fff';
		}
		if (!options[1]) {
			options[1] = '#ffdfcd';
		}
		
		if (!this.$v(id)) {
			this.changeBgColor(id, options[1]);
		} else {
			this.changeBgColor(id, options[0]);
		}
	}

}


//create object
var s = new Sevenspire;
