
// Slide del home (cuadritos)
function slideHome(pos,id){
	
	$('.main .home .up ul li a').removeClass('bg_down');
	
	$(id).addClass('bg_down');
	
	$(".main .home .up .all_box").fadeOut(100); 
	
	var href = $(id).attr("href"); 
	
	$(".main .home .up").children('div'+href).fadeIn(300);
	
	a = pos;
	
	return false;
}


//START HOME´S ROTATOR...
//Define Global vars for nextView
a = 0;
time = 10000;
custom = '.main .home .up .all_box';
var actNextCustom;
//End Define Global vars for nextview

function nextCustom()
{
    var amountCustom = $(custom).length;
    if(amountCustom > a+1)//amount > that number order (i+1) of .content
							{
									$(custom).eq(a).fadeOut(100);

                                    $(custom).eq(a+1).fadeIn(500);

									a++;
									clearTimeout(actNextCustom);
							}
							else
							{
									$(custom).eq(a).fadeOut(100);

                                    $(custom).eq(0).fadeIn(500);
                                    
									a = 0;
									clearTimeout(actNextCustom);
							}
							
	$('.main .home .up ul li a').removeClass('bg_down');
	
	$('#link_'+a).addClass('bg_down');
  	
	if(time != 0) actNextCustom = setTimeout(nextCustom,time);
}


function prevCustom()
{
    //clearTimeout(actPrevWay);                                      //stop slideshow
    //jQuery(".controlPrevWay").attr({src:"img/btn-play.png"});
    //play = false;             //and change image
    var amountCustom = $(custom).length;
    if(a == 0)
							{
									$(custom).eq(a).fadeOut(100);

                                    $(custom).eq(amountCustom-1).fadeIn(500);

                                    a = amountCustom-1;

									//clearTimeout(actPrevWay);
							}
							else
							{
									$(custom).eq(a).fadeOut(100);

                                    $(custom).eq(a-1).fadeIn(500);

									a--;
									//clearTimeout(actPrevWay);
							}
													
	$('.main .home .up ul li a').removeClass('bg_down');
	
	$('#link_'+a).addClass('bg_down');					
							
}



//END HOME´S ROTATOR...






/*---VALIDACIÓN-DE-FORMULARIO-(ONSUBMIT)---*/

	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").length == 0 ){ 
					$(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").css("display","block");
				}
			}
			else    // si no está vacío el campo . . . 
			{
				$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
			}
		});
	
	
		$("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").length == 0 ){ 
					$(this).siblings("span.error").remove();
					$(this).css("border","1px solid #f00");
					$(this).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").css("display","block");
				}
				
			}else{
			
				$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
				
			}			
		});
		
		return ok;
	}
	
	function validateMax(formId)
	{
		//var form = document.form;
		var ok = true;
		
		$("form#"+formId).find(".required").not(".email").each(function(){
			if(IsBlank($(this).val()) || $(this).val() == 'Name' || $(this).val() == 'comments') // si el valor del input está vacío…
			{		
				ok = false;
				if($(this).siblings("span.error").length == 0 ){ 
					$(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").css("display","block");
				}
			}
			else    // si no está vacío el campo . . . 
			{
				//$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
			}
		});
	
	
		$("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").length == 0 ){ 
					$(this).siblings("span.error").remove();
					//$(this).css("border","1px solid #f00");
					$(this).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").css("display","block");
				}
				
			}else{
			
				//$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
				
			}			
		});
		
		return ok;
	}
	
	function validateProp(formId)
	{
		//var form = document.form;
		var ok = true;
		
		$("form#"+formId).find(".required").not(".email").each(function(){
			if(IsBlank($(this).val()) || $(this).val() == 'Name' || $(this).val() == 'Comments' || $(this).val() == 'Bussiness Name') // si el valor del input está vacío…
			{		
				ok = false;
				if($(this).siblings("span.error").length == 0 ){ 
					$(this).siblings("span.error").remove();
					//$(this).css("border","1px solid #f00");
					$(this).after('<span class="error">Required</span>');
					$(this).siblings("span.error").css("display","block");
				}
			}
			else    // si no está vacío el campo . . . 
			{
				//$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
			}
		});
	
	
		$("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").length == 0 ){ 
					$(this).siblings("span.error").remove();
					//$(this).css("border","1px solid #f00");
					$(this).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").css("display","block");
				}
				
			}else{
			
				//$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
				
			}			
		});
		
		if(ok) saveForm();
		else return false;
	}
	
	/*---END-VALIDACIÓN-DE-FORMULARIO-(ONSUBMIT)---*/
	
	/*---FUNCIONES-DE-VALIDACIÓN-DE-FORMULARIO---*/
	
	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






$(document).ready(function() {
	
	$.preloadCssImages();
	
	$('.menu div ul li:last-child').css('border-bottom','none');

	/*---FUCIÓN-PARA-MENU---*/
	
	/*$(".menu table tr td.sub").hover(function(){ 			        
		
		$(this).children("div").slideDown('fast').animate({opacity: 1},{queue:false,duration:500}); 
		$(this).children("a").css({color:'#ffffff'});
		
	},function(){
		
		$(this).children("div").slideUp('fast').animate({opacity: 0},{queue:false,duration:500});
		$(this).children("a").css({color:'#00539F'});
		$('td.a_pos').children("a").css({color:'#ffffff'});
		
	});*/	

	/*---FUCIÓN-PARA-MENU---*/
	
	$(".menu table tr td.sub").hover(function(){ 			        
		
		$(this).children("div").children("div").slideDown('fast').animate({opacity: 1},{queue:false,duration:500}); 
		$(this).children("div").children("a").css({color:'#ffffff'});
		
	},function(){
		
		$(this).children("div").children("div").slideUp('fast').animate({opacity: 0},{queue:false,duration:500});
		$(this).children("div").children("a").css({color:'#00539F'});
		$('td.a_pos').children("div").children("a").css({color:'#ffffff'});
		
	});
	
	
	
	
	/*---funcion para mostrar en contenido por click---*/
	
	$(".main .home .all_box").eq(0).css({display:"block"});
	
	$(".main .home .up ul li a.first").addClass('bg_down');
	
	//Custom´s rotation (next)	
	$("a.controlNextView").click(function (){nextCustom(); return false;});
	
	if(time != 0){
		actNextCustom = setTimeout(nextCustom,10000);
	}
	
	
	//Custom´s rotation (prev)
	$("a.controlPrevView").click(function (){prevCustom(); return false;});
	
	// End Custom's Rotation
	
	
/*---VALIDACIÓN-DE-CAMPOS-VICIOS-DE-UN-FORMULARIO----------------------------------------------------------------------------*/
	
	$("form").not(".upgrade").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").length == 0 ){ 
					//$(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").css("display","block");
				}
			}
			else    // si no está vacío el campo . . . 
			{
				$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
			}
		});
		
	});


	$("form").not(".upgrade").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").length == 0 ){ 
					$(this).siblings("span.error").remove();
					$(this).css("border","1px solid #f00");
					$(this).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").css("display","block");
				}
				
			}else{
				$(this).css("border","1px solid #969696");
				$(this).siblings("span.error").remove();
				
			}
		});
	});

	/*---END-VALIDACIÓN-DE-CAMPOS-VICIOS-DE-UN-FORMULARIO---*/


}); // End Document ready


function saveForm(){

	$("#proposalForm").ajaxSubmit({	
		//beforeSubmit:  validateMax('proposalForm'),
        success: showMsg	
	});

}

function showMsg(){
	
	$(".proposalContForm").hide();
	$(".proposalContMsg").show();

}

function closeProposal(){
	
	$("#proposal").hide();
	
}
function openProposal(){
	
	$("#proposal").show();
	$(".proposalContForm").show();
	$(".proposalContMsg").hide();
	
}