// JavaScript

$(document).ready(function(){

	$(".naviA").mouseenter(function(){
		$(this).stop();
		$(this).fadeTo(250,"0");
	});
	$(".naviA").mouseleave(function(){
		$(this).stop();
		$(this).fadeTo(250,"1");
	});
	
	$(".active").dblclick(function(event){
		$(this).stop();
		$(this).removeClass("active");
		$(this).addClass("naviA");
		event.preventDefault();
	});
	
	$(".faqBox").hide();
	
	$(".contactInput").fadeTo(0,"0.3");
	$("#ErrorBox").slideUp(0);
	$("#secExplBox").fadeTo(0,"0");
	
	$("#secExpl").mouseenter(function(){
		$("#secExplBox").stop();
		$("#secExplBox").fadeTo(250,"1");
	});
	$("#secExpl").mouseleave(function(){
		$("#secExplBox").stop();
		$("#secExplBox").fadeTo(250,"0");
	});
	
	$(".contactInput").mouseenter(function(){
		$(this).stop();
		$(this).fadeTo(250,"1");
	});
	$(".contactInput").mouseleave(function(){
		$(this).stop();
		$(this).fadeTo(250,"0.3");
	});
	
	$("#submitContact").click(function(){
		$("div#ErrorBox").html('');
		var error = false;
		var errorString = '';
		RegEx = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/
		
		if(document.contact.name.value == ''){
			toggleError('name');
			errorString += "\t<li> Παρακαλώ εισάγετε ονοματεπώνυμο!</li>\n";
			error = true;
		}else{
			toggleGood('name');
		}
		
		
		if(document.contact.email.value == '' || !RegEx.test(document.contact.email.value)){
			toggleError('email');
			errorString += "\t<li>Παρακαλώ εισάγετε email!</li>\n";
			error = true;
		}else{
			toggleGood('email');
		}
		
		if(document.contact.subject.value == '2' && document.contact.tel.value == ''){
			toggleError('tel');
			errorString += "\t<li>Αν θέλετε να σας καλέσουμε, συμπληρώστε το τηλέφωνό σας</li>\n";
			error = true;
		}else if(document.contact.tel.value != ''){
			toggleGood('tel');
		}
		
		if(document.contact.subject.value == '0'){
			toggleError('subject');
			errorString += "\t<li>Παρακαλώ επιλέξτε θέμα!</li>\n";
			error = true;
		}else{
			toggleGood('subject');
		}
		
		if(document.contact.sec.value == ''){
			toggleError('sec');
			errorString += "\t<li>Η απάντηση στην ερώτηση ασφαλείας είναι λάθος!</li>\n";
			error = true;
		}else{
			toggleGood('sec');
		}
		
		if(document.contact.subject.value == '2' || document.contact.subject.value == '3' || document.contact.subject.value == '4'){
			if(document.contact.message.value == ''){
				toggleError('message');
				errorString += "\t<li>Παρακαλώ γράψτε ένα μήνυμα!</li>\n";
				error = true;
			}else{
				toggleGood('message');
			}
		}
		
		
		if(error == true){
			document.getElementById('ErrorBox').innerHTML += "\n\n<ul class=\"errorList\">\n"+errorString+"\n</ul>\n\n";
			//$("div#ErrorBox").fadeTo(250,"1");
			$("div#ErrorBox").slideDown(250);
		}else{
			$("div#ErrorBox").slideUp(250);
			/*$("div#ErrorBox").fadeTo(250,"0");*/
			document.contact.submit();
		}
	});
	
});	

function toggleFaq(id){
	if(id == 00){
		$(".faqBox").slideUp(250);
	}else if(id == 99){
		$(".faqBox").slideDown(250);
	}else{
		$("#"+id).slideToggle(250);
	}
}

function toggleError(fieldId){
		$("#"+fieldId).mouseenter();
		document.getElementById(fieldId).style.borderWidth = "1px";
		document.getElementById(fieldId).style.borderStyle = "solid";
		document.getElementById(fieldId).style.borderColor = "#ff0000";
		document.getElementById(fieldId).style.padding = "4px";
		$("#"+fieldId).animate({
			opacity:1,
			backgroundColor:"rgb(255,200,200)",
			color:"rgb(255,0,0)"
		}, 250);
}	

function toggleGood(fieldId){
		document.getElementById(fieldId).style.borderWidth = "1px";
		document.getElementById(fieldId).style.borderStyle = "solid";
		document.getElementById(fieldId).style.borderColor = "#00ff00";
		document.getElementById(fieldId).style.padding = "4px";
		$("#"+fieldId).animate({
			opacity:1,
			backgroundColor:"rgb(200,255,200)",
			color:"rgb(0,100,0)"
		}, 250);
		$("#"+fieldId).mouseenter();
}	

