/*	GLOBALS	*/faqId = 1;/*	END GLOBALS	*/

$(document).ready(function() {	$("ul.menu > li").hover(function(){		
		$(".submenu").hide();
		var submenu = '.menu'+$(this).children("a").text();
		$(submenu).show();		
	},function(){
		$(".submenu").hide();
	});

	/*	Form User friendly	*/  	$("form").find(".required").not(".email").each(function(){
		$(this).keyup(function(){
			if(IsBlank($(this).val())) // si el valor del input está vacío…
			{	
				if($(this).siblings("span.error").css("display") == "none" ){ 
					//$(this).siblings("span.error").remove();
					//$(this).css("border","1px solid #f00");
					//$(this).after('<span class="error">This is a required field.</span>');
					$(this).siblings("span.error").show();
				}
			}
			else    // si no está vacío el campo . . . 
			{
				//$(this).css("border","1px solid #E6E6E6");
				$(this).siblings("span.error").css("display","none");
			}
		});
	});
	$("form").find(".email").filter(".required").each(function(){
		$(this).keyup(function(){
			if(!isValidEmail($(this).val())){ // este input es pasado por la función ‘valid_email()’ … si no es correcto…				
				if($(this).siblings("span.error").css("display") == "none" ){ 
					//$(this).siblings("span.error").display("block");
					//$(this).css("border","1px solid #f00");
					//$(this).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").show();
				}
			}else{
				//$(this).css("border","1px solid #E6E6E6");
				$(this).siblings("span.error").css("display","none");
			}
		});
	});
	/*	Form User Friendly End	*/
	/*	INICIALIZAMOS PLUGINS	*/
	//$(".pictureFrame").scrollable();
	Shadowbox.init();
});

function showHole(order){
	$(".main").hide();
	$(".hole"+order).show();
}

function showFaq(id){
	faqId = id;
	$(".faqbox").hide();
	$(".faq"+id).show();
	$(".faq .left ul li").removeClass("active");	
	$(".faq .left ul li").eq(faqId-1).addClass("active");
}

function previousFaq(){
	var totalE = $('.faqbox').length;
	if ((faqId - 1) > 0){
		$(".faqbox").hide();
		$(".faq" + (faqId - 1) ).show();
		faqId--;
	}
	else {
		$(".faqbox").hide();
		$(".faq" + totalE).show();
		faqId = totalE;
		}
	$(".faq .left ul li").removeClass("active");
	$(".faq .left ul li").eq(faqId-1).addClass("active");
}

function nextFaq(){

	var totalE = $('.faqbox').length;

	if ((faqId + 1) <= totalE){
	
		$(".faqbox").hide();
		$(".faq" + (faqId + 1) ).show();
		faqId++;
	}
	else {
		$(".faqbox").hide();
		$(".faq1").show();
		faqId = 1;
		}
	$(".faq .left ul li").removeClass("active");
	$(".faq .left ul li").eq(faqId-1).addClass("active");

}

function showImage(src){

	$("img.bigImage").attr("src",src);
	$("a.linkBigImage").attr("href",src);
	Shadowbox.setup($("a.linkBigImage"));
}

function showDirections(styleClass){

	if($('li.'+styleClass).css("display") == 'none')$('li.'+styleClass).slideDown();
	else $('li.'+styleClass).slideUp();

}
/*Validación del formulario de contactos*/

function validate(formId)
{
	//var form = document.form;
	var ok = true;
	
	$("form#"+formId).find(".required").not(".email").each(function(){
		if(IsBlank($(this).val())) // si el valor del input está vacío…
		{		
			ok = false;
			if($(this).siblings("span.error").css("display") == "none" ){ 
				//$(this).siblings("span.error").remove();
				//$(this).css("border","1px solid #f00");
				//$(this).after('<span class="error">This is a required field.</span>');
				$(this).siblings("span.error").show();
			}
		}
		else    // si no está vacío el campo . . . 
		{
			//$(this).css("border","1px solid #E6E6E6");
			$(this).siblings("span.error").css("display","none");
		}
	});


	$("form#"+formId).find(".email").filter(".required").each(function(){ 
		if(!isValidEmail($(this).val())){ // este input es pasado por la función ‘valid_email()’ … si no es correcto…
			ok = false; // el ok sera ‘false’
			if($(this).siblings("span.error").css("display") == "none" ){ 
				//$(this).siblings("span.error").remove();
				//$(this).css("border","1px solid #f00");
				//$(this).after('<span class="error">Email is invalid.</span>');
				$(this).siblings("span.error").show();
			}
			
		}else{
		
			//$(this).css("border","1px solid #E6E6E6");
			$(this).siblings("span.error").css("display","none");
			
		}			
	});
	
	return ok;
}


function validnum(s)
{
     // Check for number
	 num = new RegExp(/^(?:\+|-)?\d+$/);
     if (!num.test(s)) {
          return false;
     }
	return true;
}

function IsBlank (strString)
{
	if (strString.length == 0)
		return true;

	for (i = 0; i < strString.length; i++)
	{
		strChar = strString.charAt(i);
		if (strChar != " ")
			return false;
	}
	return true;
}

function isValidEmail(email){

	if (email.length < 5)
		return false;

	subEmail=email.split('@'); //subEmail is a string array (contains strings splitted by '@')
	if (subEmail.length != 2)
		return false;

	dotStr=subEmail[1].split('.'); //dotStr is a string array (contains strings splitted by '.')

	if(dotStr.length<2)
		return false;

	for(i=1;i<dotStr.length;i++){
		if((dotStr[i].length!=2)&&(dotStr[i].length!=3))
			return false;
	}
return true;
}// End isValidEmail
