/**
 * @author epaul
 */
 
/**
 * loadWork()
 * 
 * displays the work area
 * blinds the Name are
 * blindup action is called
 */ 

var browser = navigator.appName;
function loadWork(){
 	loadwork = true;
	loadname = false;
	new Effect.BlindUp('NameContentHeader', {duration: 0.3});
	$('WorkContent').style.display = "block";
	$('WorkContentHeader').style.display = "block";
	$('NameContent').style.display = "none";
	$('moreInfoName').style.display = 'block';
	$('moreInfoWork').style.display = 'none';
	setActiveStyleSheet('blue');
	if (browser == "Microsoft Internet Explorer"){ // IE6 & 7 hack
		$('myBody').style.backgroundColor = "#00A0C6";	
	}
}


/**
 * loadName()
 * 
 * displays the name area
 * blinds the work area
 * blindup action is called
 */
function loadName(){
 	loadname = true;
	loadwork = false;
	new Effect.BlindUp('WorkContentHeader', {duration: 0.3});
	
	$('WorkContent').style.display = "none";
	$('NameContent').style.display = "block";
	$('NameContentHeader').style.display = "block";
	$('moreInfoName').style.display = 'none';
	$('moreInfoWork').style.display = 'block';
	setActiveStyleSheet('white');
	if (browser == "Microsoft Internet Explorer"){ // IE6 & 7 hack
		$('myBody').style.backgroundColor = "white";
	}
}


/**
 * isEmail()
 * 
 * checks whether an email adress is valid or not  
 * 
 * @param {string} address
 * @return boolean
 */
function isEmail(address) {
	var isValid = false;
	isValid = (address!=null)
	&& (address.length >= 7)
	&& (address.indexOf('@')!=-1)
	&& (address.indexOf('@') == address.lastIndexOf('@'))
	&& (address.indexOf('.')!=-1);

	if (isValid) {
		var parts = address.split('@');
		var name  = parts[0].split('.');
		var host  = parts[1].split('.');
		var regName  = new RegExp("^([!#$%&'*+-/0-9=?A-Z^_a-z{}~]+)$"); 
		var regLabel = new RegExp("^(^[-0-9A-Za-z][-0-9A-Za-z]+)$"); 
		var regExt   = new RegExp("^([A-Za-z]{2,63})$"); 
		var i;
		for (i=0; i < name.length; i++) {
			isValid = isValid && (name[i].search(regName) != -1);
		}
		for (i=0; i < host.length-1; i++) {
			isValid = isValid && (host[i].search(regLabel) != -1) && (host[i].length <= 63);
		}
		isValid = isValid && (host[host.length-1].search(regExt) != -1);
	}
	return isValid;
}

/**
 * checkForm()
 * 
 * checks whether user has filled in the form 
 * form includes above described email check
 * 
 * @param {string / htmlelement} formId
 * @return boolean
 */
function checkForm(formId){
	var obj = new Object();	
	obj = $(formId).serialize(true);
	if (obj){
	return ((obj.name != "") && (isEmail(obj.email)) && (obj.message != ""))			
	}else {	
		return false;
	}
}

/**
 * arrowBack()
 * 
 * changes arrow state to back and changes the classnames of main Name header
 * call arrowNormal to return to normal state
 * 
 * a var is used to solve a IE6 bug => click
 */
var click = true;
function arrowBack(){
	click = false;
	$('name').className = 'nameBig';
	$('arrowName').className = "middleImageZuruck";
	$('arrowWork').className = "";	

	if($('work').className == 'headerBig'){
		$('arrowWork').style.display = "block";	
		$('work').style.display = "block";		
	}else {
		$('arrowWork').style.display = "none";	
		$('work').style.display = "none";	
	}
}


/**
 * arrowNormal()
 * 
 * changes state of arrow back to normal and returns classname of mainName back to default
 * call arrowBack() to change state * 
 */
function arrowNormal(){
	click = true;
	new Effect.toggle('contentOverlay','blind', {duration: 0.2});
	$('name').className = 'nameSmall';
	$('arrowName').className = "middleImageSmall";
	
	if($('work').className == 'headerBig'){
		$('arrowWork').className = "middleImageBig";
		$('arrowName').className = "middleImageSmall";
	}else{
		$('arrowWork').style.display = "block";	
		$('work').style.display = "block";
		$('arrowWork').className = "middleImageSmall";		
		$('arrowName').className = "middleImageBig";
		$('name').className = 'nameBig';		
	}
}

