var tempohousing = {
	'#content .buttonback' : function(el) {
		el.onclick = function() {
			history.back();
		}
	},
	
	'#content .headerimage' : function(el) {
	
	el.style.backgroundImage=getImage();
	
	},
	
	// formcheck
	'form' : function(el) {
		el.onsubmit = function() {
			return formCheck();
		}
	},
	
	// external website
	
	'a.external' : function(el) {
		el.onclick = function() {
			this.target = "_blank";
		}
	},
	
	'.boxitem. a' : function(el) {
		el.onclick = function() {
			document.location.href=this.href;
		}
	},
	
	// mail
	'.mailto' : function(el) {
		el.onclick = function() {
			this.href = "mailto:" + this.title.replace(/\[at\]/, "@");
		}
	}
};
Behaviour.register(tempohousing);

// no frames
if (top != self) top.location.href = location.href;

function getImage() {
	var thePicture;
	var numberPictures=31;
	var randomnumber=Math.floor(Math.random()*numberPictures)
	thePicture="url(/images/header/" + randomnumber + ".jpg)";
	return thePicture;
}

function formCheck() {

	var doSubmit=true;
	
	// fieldid-check-formid
	
	fieldsCheck=new Array;
	fieldsCheck[0]='firstname-required-contact';
	fieldsCheck[1]='lastname-required-contact';
	fieldsCheck[2]='email-required-contact';
	fieldsCheck[3]='city-required-contact';
	fieldsCheck[4]='country-required-contact';
	fieldsCheck[5]='phone-required-contact';
	fieldsCheck[6]='request-required-contact';
	fieldsCheck[7]='lastname-required-quotations';
	fieldsCheck[8]='organisation-required-quotations';
	fieldsCheck[9]='city-required-quotations';
	fieldsCheck[10]='country-required-quotations';
	fieldsCheck[11]='email-email-quotations';
	fieldsCheck[12]='phone-required-quotations';
	fieldsCheck[13]='estimated_quantity_of_units-special1-quotations';
	fieldsCheck[14]='email-email-newsletter';
	
	for (var i=0; i < fieldsCheck.length; i++) {
	
		var splitFieldsCheck = fieldsCheck[i].split('-');
	
		requiredField=document.getElementById(splitFieldsCheck[0]);
		theCheck=splitFieldsCheck[1]; 
		theForm=splitFieldsCheck[2]; 
	
		// required check
	
		if (document.getElementById(splitFieldsCheck[2]) && theCheck=='required') {
		
			if (requiredField.value=="") {
				requiredField.className='required';
				doSubmit = false;
			}
			else {
				requiredField.className='';
			}
		}
		
		// e-mail check
		
		if (document.getElementById(splitFieldsCheck[2]) && theCheck=='email') {
			if (!requiredField.value.search(/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i) == 0) {
				requiredField.className='required';
				doSubmit = false;
			}
			else {
				requiredField.className='';
			}
		}
		
		//number check
		
		if (document.getElementById(splitFieldsCheck[2]) && theCheck=='number') {
			theValue=trim(requiredField.value);
			if (!theValue.search(/^[\d]+$/) == 0) {
				requiredField.className='required2';
				doSubmit = false;
			}
			else {
				requiredField.className='';
			}
		}
		
		
		//special 1 check
		
		if (document.getElementById(splitFieldsCheck[2]) && theCheck=='special1') {
			theValue=trim(requiredField.value);
			if (theValue < 50 || !theValue.search(/^[\d]+$/) == 0) {
				requiredField.className='required2';
				doSubmit = false;
			}
			else {
				requiredField.className='type1';
			}
		}
		
	}
	
	if (doSubmit==false) {
		document.getElementById("message").style.display = "block";
		// window.location.hash="top";
		}
		return doSubmit;
	
}

function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}