$(function(){

                $('#about').hide();
                $('#stylists').hide();
                $('#contact').hide();
                $('#formsuccess').hide();



	$("#menu").hide( "slow", function(){
	        $('#wrap').animate({left:-130},"slow" );
	});

	$('#logo').mouseenter(function() {
 		$('#wrap').animate({left:0}, function() {
			$("#menu").show();
		});
	});

      	$('#leftSide').mouseleave(function() {

		$("#menu").hide();
		$('#wrap').animate({left:-130});
        });



	$('#menu_home').click(function(){
		showAll();
		$('#sections').animate({marginTop:0});
		$('#about').hide();
                $('#stylists').hide();
                $('#contact').hide();
                $('#formsuccess').hide();


	});

 	$('#menu_about').click(function(){
		showAll();
        	$('#sections').animate({marginTop:-1832});
		$('#stylists').hide();
                $('#contact').hide();
		$('#formsuccess').hide();

 	});

        $('#menu_stylists').click(function(){
		showAll();
                $('#sections').animate({marginTop:-2940});
                $("#contact").hide();
                $("#formsuccess").hide();

        });

        $('#menu_contact').click(function(){
		showAll();
                $('#sections').animate({marginTop:-5230});
		$("#formsuccess").hide();
        });

        $('#return_home').click(function(){
              showAll();
                $('#sections').animate({marginTop:0});
                $('#about').hide();
                $('#stylists').hide();
                $('#contact').hide();
                $('#formsuccess').hide();
        });


	
});

function checkEMail(){
	var cemail = document.getElementById('appointment').email.value;
	
	//ejemplo minimo: c@w.c
	var flag = true;
	
	if(cemail.length<6)
		return 0;
	
	if( !cemail.indexOf("@") )
		return 0;
		
	return 1;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }




function sendData(){
	
	var fields="";
	var flag = true;
	
	var cform = document.getElementById('appointment');
	
	document.location.href = "#error";

	if(cform.name.value=="" || cform.name.value=="name" ){
		fields += "\n Name,";
		flag = false;
	}

        if(cform.service.value=="" || cform.service.value=="Haircut or Color?" ){
                fields += "\n Service,";
                flag = false;
	}

        if(cform.date.value=="" || cform.date.value=="month,day" ){
                fields += "\n Date,";
                flag = false;
	}

	if(cform.time.value=="" || cform.time.value=="time" ){
                fields += "\n Time,";
                flag = false;
        }

	if(cform.phone.value=="" || cform.phone.value=="phone number" ){
		fields += "\n Phone Number,";
		flag = false;
	}
	if(cform.email.value=="" || cform.email.value=="email" ){
		fields += "\n E-Mail,";
		flag = false;
	}
	
	fields +=',';
	fields = fields.replace(',,','.') 
	
	if(!flag){
		var cdiv = document.getElementById('error');
		cdiv.innerHTML = 'Please fill correctly the following fields: ' + fields;
		$('#error').show();
	} else if(!checkEMail()){
		var cdiv = document.getElementById('error');
		cdiv.innerHTML = 'The E-Mail is incorrect';
		$('#error').show();
	} else	if(!IsNumeric(cform.phone.value)){
                var cdiv = document.getElementById('error');
                cdiv.innerHTML = 'The Phone is incorrect';
                $('#error').show();

	} else {

		var dataString = 'name=' + cform.name.value + '&service=' + cform.service.value + '&date=' + cform.date.value;
                dataString += '&time='+ cform.time.value + '&phone=' + cform.phone.value + '&email=' + cform.email.value;

		$.ajax( {type: "POST", url: "sendinfo.php", data: dataString });

		showAll();
		$('#sections').animate({marginTop:-5790});

	}
		
	
}


function showAll() {

	$('#home').show("fast");
        $('#about').show("fast");
        $('#stylists').show("fast");
        $('#contact').show("fast");
        $('#formsuccess').show("fast");
        $('#error').hide();

}



function show( component ) {

	if ( $( component ).hasClass("component_alpha") )
		$(component).removeClass("component_alpha").addClass("component_noalpha");
	else if( $( component ).hasClass("contact_alpha") )
		$(component).removeClass("contact_alpha").addClass("contact_noalpha");
		
}

