// JavaScript Document

//menu and submenu morphing
var subMenu = function(p) {
	if($F('openSub') != p){
		if(p=="company"){ 
			new Effect.Morph('menu', {
 				style: 'padding:130px 0px 0px 0px; height:230px;',
  				duration: 0.2 
			})
			
		}
		if(p=="lob"){
			new Effect.Morph('menu', {
 				style: 'padding:145px 0px 0px 0px; height:215px;',
  				duration: 0.2 
			})
		
		}
		if(p=="contact"){
			new Effect.Morph('menu', {
 				style: 'padding:175px 0px 0px 0px;height:185px;', 
  				duration: 0.2 
			})
		}
		new Effect.BlindDown(p,{duration:0.7});
		if($F('openSub')!="start"){
			new Effect.BlindUp($F('openSub'),{duration:0.7});
		}
		$('openSub').value=p;		
	} else {
		new Effect.BlindUp(p,{duration:0.7});
		new Effect.Morph('menu', {
 				style: 'padding:220px 0px 0px 0px; height:140px;',
  				duration: 0.2
			})
		$('openSub').value="start";
	}
}

//open gallery menu
var subGal = function(p){
	if($F('openGal') == 'close'){
		new Effect.BlindDown('galleryItems',{duration:0.4});
		$('openGal').value = "open";
	} else {
		new Effect.BlindUp('galleryItems',{duration:0.4});
		$('openGal').value = "close";
		openImg('0');
	}
}

//open gallery items
var openImg = function(n){
	if($F('openImg') != n){
		if($F('openImg') != '0'){
			new Effect.Fade($('img'+$F('openImg')),{duration:1.5});
		} else {
			new Effect.Fade($('img0'),{duration:1.5});
		}
		new Effect.Appear($('img'+n),{duration:1.5});
		($('openImg')).value = n;
	}
}

//open menus to keep erros away
var showMenus = function(){
	/*new Effect.Appear($('toMenu'),{duration:0.6});*/
	if($('toGal')){
		new Effect.Appear($('toGal'),{duration:1.5});		
	}
}

var openJob = function(p){
	if($F('openJob') != p){
		/*Element.show($('job'+p));*/
		new Effect.BlindDown('job'+p,{duration:0.2});
		if($F('openJob') != 'start'){
			/*Element.hide($('job'+p));*/
			new Effect.BlindUp('job'+$F('openJob'),{duration:0.3});
		}
		$('openJob').value=p;
	} else {
		/*Element.hide($('job'+p));*/
		new Effect.BlindUp('job'+$F('openJob'),{duration:0.3});
		$('openJob').value='start';
	}
}

var sendMsg = function() {
	
	if($F('inCompany') == ""){
		Element.show($('errorCompany'));  
	} else {
		Element.hide($('errorCompany'));  
	}
	if($F('inName') == ""){
		Element.show($('errorName'));  
	} else {
		Element.hide($('errorName'));  
	}
	if($F('inLastname') == ""){
		Element.show($('errorLastname'));
	} else {
		Element.hide($('errorLastname'));
	} 
	if($F('inStreet') == ""){
		Element.show($('errorStreet'));
	} else {
		Element.hide($('errorStreet'));
	} 
	if($F('inZip') == ""){
		Element.show($('errorZip'));
	} else {
		Element.hide($('errorZip'));
	} 
	if($F('inCity') == ""){
		Element.show($('errorCity'));
	} else {
		Element.hide($('errorCity'));
	} 
	if($F('inCountry') == ""){
		Element.show($('errorCountry'));
	} else {
		Element.hide($('errorCountry'));
	}
	if($F('inPhone') == ""){
		Element.show($('errorPhone'));
	} else {
		Element.hide($('errorPhone'));
	}
	if($F('inEmail') == ""){
		Element.show($('errorEmail'));
	} else {
		Element.hide($('errorEmail'));
	}
	if($F('inRecipient') == ""){
		Element.show($('errorRecipient'));
	} else {
		Element.hide($('errorRecipient'));
	} 
	if($F('inMsg') == ""){
		Element.show($('errorInMsg'));
	} else {
		Element.hide($('errorInMsg'));
	} 

	if($F('inCompany') == "" ||
	   $F('inName') == "" ||
	   $F('inLastname') == "" ||
	   $F('inStreet') == "" ||
	   $F('inZip') == "" ||
	   $F('inCity') == "" ||
	   $F('inCountry') == "" ||
	   $F('inPhone') == "" ||
	   $F('inEmail') == "" ||
	   $F('inRecipient') == "" ||
	   $F('inMsg') == ""){
		Element.show($('errorMsg'));
	} else {
		new Ajax.Request
		("con/contact.php", {
			 parameters:{
				action:"sendMail",
				inCompany:($F('inCompany')),
				inName:($F('inName')),
				inLastname:($F('inLastname')),
				inStreet:($F('inStreet')),
				inZip:($F('inZip')),
				inCity:($F('inCity')),
				inCountry:($F('inCountry')),
				inPhone:($F('inPhone')),
				inEmail:($F('inEmail')),
				inEmail:($F('inRecipient')),
				inMsg:($F('inMsg'))
			 },
			 onComplete:getMsgResult}
		 )
	}
}

var getMsgResult = function(xml){ 
	xml = xml.responseText; 
	if(xml = "ok"){
		new Effect.Fade('groupFormField',{ duration: 0.3, from: 1, to: 0 });
		setTimeout('new Effect.Appear('+"'mailSuccess'"+',{ duration: 0.3, from: 0, to: 1 })',600);
		
	}
}

var closeMaps = function(){
	new Effect.Fade($('featureContent'),{duration:0.4});
	new Effect.Fade($('iframe'),{duration:1});
	Element.hide($('loading'));
}
