// JavaScript Document


//START HOME`S ROTATOR...
//Define Global vars for nextNews
i = 0;
time = 8000;
element = '.info .rotation';
var actNextNews;
var count=0;
//End Define Global vars for nextNews


function nextNews()
{
    var amount = $(element).length;
    if(amount > i+1)//amount > that number order (i+1) of .content
							{
									$(element).eq(i).fadeOut("slow");

                                    $(element).eq(i+1).fadeIn("slow");

									i++;
									clearTimeout(actNextNews);
							}
							else
							{
									$(element).eq(i).fadeOut("slow");

                                    $(element).eq(0).fadeIn("slow");

									i = 0;
									clearTimeout(actNextNews);
							}
   if(time != 0) actNextNews = setTimeout(nextNews,time);
}
//END HOME´S ROTATOR...



//START CONSERVATION´S ROTATOR...
//Define Global vars for nextNews
a = 0;
time = 8000;
ways = '.ways_scroll .ways_in';
var actNextWay;
//End Define Global vars for nextNews

function nextWay()
{
    var amountWay = $(ways).length;
    if(amountWay > a+1)//amount > that number order (i+1) of .content
							{
									$(ways).eq(a).fadeOut("slow");

                                    $(ways).eq(a+1).fadeIn("slow");

									a++;
									clearTimeout(actNextWay);
							}
							else
							{
									$(ways).eq(a).fadeOut("slow");

                                    $(ways).eq(0).fadeIn("slow");

									a = 0;
									clearTimeout(actNextWay);
							}
   if(time != 0) actNextWay = setTimeout(nextWay,time);
}


function prevWay()
{
    //clearTimeout(actPrevWay);                                      //stop slideshow
    //jQuery(".controlPrevWay").attr({src:"img/btn-play.png"});
    //play = false;             //and change image
    var amountWay = $(ways).length;
    if(a == 0)
							{
									$(ways).eq(a).fadeOut("slow");

                                    $(ways).eq(amountWay-1).fadeIn("slow");

                                    a = amountWay-1;

									//clearTimeout(actPrevWay);
							}
							else
							{
									$(ways).eq(a).fadeOut("slow");

                                    $(ways).eq(a-1).fadeIn("slow");

									a--;
									//clearTimeout(actPrevWay);
							}
}



//END CONSERVATION´S ROTATOR...

//START CUSTOM´S ROTATOR...
//Define Global vars for nextNews
a = 0;
//time = 1000;
custom = '.custom_scroll .text_custom';
var actNextCustom;
//End Define Global vars for nextNews

function nextCustom()
{
    var amountWay = $(custom).length;
    if(amountWay > a+1)//amount > that number order (i+1) of .content
							{
									$(custom).eq(a).fadeOut("slow");

                                    $(custom).eq(a+1).fadeIn("slow");

									a++;
									clearTimeout(actNextWay);
							}
							else
							{
									$(custom).eq(a).fadeOut("slow");

                                    $(custom).eq(0).fadeIn("slow");

									a = 0;
									clearTimeout(actNextWay);
							}
  // if(time != 0) actNextWay = setTimeout(nextWay,time);
}


function prevCustom()
{
    //clearTimeout(actPrevWay);                                      //stop slideshow
    //jQuery(".controlPrevWay").attr({src:"img/btn-play.png"});
    //play = false;             //and change image
    var amountWay = $(custom).length;
    if(a == 0)
							{
									$(custom).eq(a).fadeOut("slow");

                                    $(custom).eq(amountWay-1).fadeIn("slow");

                                    a = amountWay-1;

									//clearTimeout(actPrevWay);
							}
							else
							{
									$(custom).eq(a).fadeOut("slow");

                                    $(custom).eq(a-1).fadeIn("slow");

									a--;
									//clearTimeout(actPrevWay);
							}
}



//END CUSTOM´S ROTATOR...


function show_buy(){

		if($('#box_buy').css('display') == 'none'){

			$('#box_buy').slideDown('normal');

		}

	}


function hide_buy(){

		if($('#box_buy').css('display') == 'block'){

			$('#box_buy').slideUp('normal');

		}

	}

function show_buy2(){

		if($('#box_buy2').css('display') == 'none'){

			$('#box_buy2').slideDown('normal');

		}

	}


function hide_buy2(){

		if($('#box_buy2').css('display') == 'block'){

			$('#box_buy2').slideUp('normal');

		}

	}





$(document).ready(function(){

				Shadowbox.init();


				//Custom´s rotation (next)
				$(custom).eq(0).css({display:"block"});

				$("a.controlNextCustom").click(function (){nextCustom(); return false;});


				//Custom´s rotation (prev)
				$("a.controlPrevCustom").click(function (){prevCustom(); return false;});

				// End Custom's Rotation


	            //Home´s rotation
                $(element).eq(0).css({display:"block"});

                $("a.control").click(function (){nextNews();});

                if(time != 0)
                {
                    actNextNews = setTimeout(nextNews,5000);
                }

                //Conservation´s rotation (next)
                $(ways).eq(0).css({display:"block"});

                $("a.controlNextWay").click(function (){nextWay();});

                if(time != 0)
                {
                    actNextWay = setTimeout(nextWay,5000);
                }

                //Conservation´s rotation (prev)
                $("a.controlPrevWay").click(function (){prevWay();});
                /*if(time != 0)
                {
                    actPrevWay = setTimeout(prevWay,5000);
                }*/
                /*$("ul#menu").find("a.niv_1").each(function(){

                		$(this).click(function(){

                			//alert($(this).siblings("ul").css("display"));
                			//alert($(this).attr("class"));
                			if($(this).siblings("ul").css("display") == 'block'){

                				$(this).siblings("ul").hide("slow");

                			}else{

                				$(this).addClass("hc600");
                				$(".niv_2").hide("slow");//oculta todos los "li" de 2º nivel...//
                				$(this).siblings("ul").show("slow");


                				}

                		});

                	});*/

                	$("a.a_dealer").hover(function(){
                                    var img = $(this).attr("href");
                                    $("table.width_table img.img_dealer_pic2").attr("src",img);
                                    },function(){
                    });
	//$("a.a_dealer").attr("href")






	$("form").find(".required").not(".email").each(function(){
		$(this).keyup(function(){
			if(IsBlank($(this).val()) || $(this).val() == 'Name') // si el valor del input está vacío…
			{
				if($(this).siblings("span.error").length == 0 ){
					$(this).siblings("span.error").remove();
					$(this).after('<span class="error">This is a required field.</span>');
					$(this).focus();
					$(this).siblings("span.error").css("display","block");
				}
			}
			else    // si no está vacío el campo . . .
			{
				$(this).siblings("span.error").remove();
			}
		});

	});


	/*---Validación del formulario de dual_flush_hydroright---*/

	$("form").find(".email").filter(".required").each(function(){
		$(this).keyup(function(){
			if(!isValidEmail($(this).val()) || $(this).val() == 'Email'){ // 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).after('<span class="error">Email is invalid.</span>');
					$(this).focus();
					$(this).siblings("span.error").css("display","block");
				}

			}else{

				$(this).siblings("span.error").remove();

			}
		});
	});

	/*---END Validación del formulario de dual_flush_hydroright---*/

	
	$('.hr-info .main_hr.main_hd .box-content-tabs ul li a.tab-2').click(function(){
		
		$('.hr-info .main_hr.main_hd .box-content-tabs ul li a.tab-1').addClass('active');
		$(this).addClass('active');
		$('.hr-info .main_hr.main_hd .box-content-tabs .box-content-tab-1').css('display','none');
		$('.hr-info .main_hr.main_hd .box-content-tabs .box-content-tab-2').css('display','block');

	});
	
	$('.hr-info .main_hr.main_hd .box-content-tabs ul li a.tab-1').click(function(){
		
		$('.hr-info .main_hr.main_hd .box-content-tabs ul li a.tab-2').removeClass('active');
		$(this).removeClass('active');
		$('.hr-info .main_hr.main_hd .box-content-tabs .box-content-tab-2').css('display','none');
		$('.hr-info .main_hr.main_hd .box-content-tabs .box-content-tab-1').css('display','block');

	});
	



});

/*---Validación del formulario de dual_flush_hydroright---*/

function validateDual(formId)
	{
		//var form = document.form;
		var ok = true;

		$("form#"+formId).find(".required").not(".email").each(function(){
			if(IsBlank($(this).val()) || $(this).val() == 'Name') // si el valor del input está vacío…
			{
				ok = false;
				if($(this).siblings("span.error").length == 0 ){
					$(this).siblings("span.error").remove();
					$(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).siblings("span.error").remove();
			}
		});


		$("form#"+formId).find(".email").filter(".required").each(function(){
			if(!isValidEmail($(this).val()) || $(this).val() == 'Email'){ // 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).after('<span class="error">Email is invalid.</span>');
					$(this).siblings("span.error").css("display","block");
				}

			}else{

				$(this).siblings("span.error").remove();

			}
		});

    if(ok) {

      var url = "http://www.gomjsi.com/campaignmonitor/subscriber_add.php";

      $.post( url, $('form#'+formId).serialize(), function(data, responce) {

        $(".emailing-response").css("left", function() {
            return ($(window).width() / 2) - 260;
        });

        $(".emailing-response").css("top", function() {
            return ($(window).height() / 4);
        });


        $(".emailing-response").fadeIn(1000,

          function() {

            setTimeout( function() {

              $(".emailing-response").fadeOut(1000)

              }, 5000);
          }

        );

        $('form#'+formId).find('input[type!=submit], input[type!=reset]').val('');
        $('span.error').remove();

      } );

    }

    return false;


	}

/*---END Validación del formulario de dual_flush_hydroright---*/



function validate()
{
	var form = document.formContact;

	//Validating First Name
	var name = document.getElementById('firstname').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid First Name!");
		document.getElementById('firstname').focus();
		return false;
	}

	//Validate Last Name
	var lname = document.getElementById('lastname').value;
	if (IsBlank(lname))
	{
		alert ("Please enter a valid Last Name!");
		document.getElementById('lastname').focus();
		return false;
	}

	//Validate Email
	var email= document.getElementById('email').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('email').focus();
		return false;
    }

    //Validate Comment
	var comment = document.getElementById('comment').value;
	if (IsBlank(comment))
	{
		alert ("Please fill the field Comment!");
		document.getElementById('comment').focus();
		return false;
	}
//    form.submit();
	return true;
}

function validateLog()
{
	var form = document.formContact;


	//Validating First Name
	var name = document.getElementById('store').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid Store Number!");
		document.getElementById('store').focus();
		return false;
	}
	//Validating First Name
	var name = document.getElementById('firstname').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid First Name!");
		document.getElementById('firstname').focus();
		return false;
	}

	return true;
}
function validateDealer()
{
	var form = document.formDealer;

	//Validating First Name
	var name = document.getElementById('firstname').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid First Name!");
		document.getElementById('firstname').focus();
		return false;
	}

	//Validate Last Name
	var lname = document.getElementById('lastname').value;
	if (IsBlank(lname))
	{
		alert ("Please enter a valid Last Name!");
		document.getElementById('lastname').focus();
		return false;
	}

    //Validate contactlastname
	var comment = document.getElementById('contactlastname').value;
	if ( ( IsBlank(comment) ) || ( !isValidEmail(comment) ) )
    //if (IsBlank(comment))
	{
		alert ("Please enter a valid email address!");
		document.getElementById('contactlastname').focus();
		return false;
	}

	//Validate Email
/*	var email= document.getElementById('email').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('email').focus();
		return false;
    }*/

    //Validate Comment
/*	var comment = document.getElementById('comment').value;
	if (IsBlank(comment))
	{
		alert ("Please fill the field Comment!");
		document.getElementById('comment').focus();
		return false;
	}*/
//    form.submit();
	return true;
}

//  VALIDATE ORDER FORM
function validateOrder()
{
	var form = document.formOrder;
	var ok = true;

	//Validating Company
	var name = document.getElementById('company').value;
	if (IsBlank(name))
	{
		alert ("Please fill the field Company!");
		document.getElementById('company').focus();
		return false;
	}

    //Validate Contact
	var email= document.getElementById('contact').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email in Contact!");
		document.getElementById('contact').focus();
		return false;
    }

	//Validate Address
	var lname = document.getElementById('address').value;
	if (IsBlank(lname))
	{
		alert ("Please enter a valid Address!");
		document.getElementById('address').focus();
		return false;
	}

    //Validate City
	var comment = document.getElementById('city').value;
	if (IsBlank(comment))
	{
		alert ("Please fill the field City!");
		document.getElementById('city').focus();
		return false;
	}

	//Validate state
	var comment = document.getElementById('state').value;
	if (IsBlank(comment))
	{
		alert ("Please fill the field State!");
		document.getElementById('state').focus();
		return false;
	}

	//Validate zip
	var comment = document.getElementById('zip').value;
	if (!IsBlank(comment) && !validnum(comment))
	{
		alert ("Please fill the field Zip only with numbers!");
		document.getElementById('zip').focus();
		return false;
	}

	//Validate numeric
	$("form#formOrder").find(".numeric").each(function(){
		if(this.value != "")
		{
			if(!validnum(this.value) || this.value > 10)
			{
			 ok = false;
			}

		}
	});

	if(!ok)
	{
		alert('Please limit your order through this site to no more than 10 copies of each piece of literature. For larger orders, please call 1-888- GOMJSI-1.');
		return false;
	}
//    form.submit();
	return true;
}


function validateBuy()
{
	var form = document.formBuy;

	//Validating First Name
	var name = document.getElementById('name').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid  User Name!");
		document.getElementById('name').focus();
		return false;
	}

	//Validate Email
	var email= document.getElementById('jdutuh-jdutuh').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('jdutuh-jdutuh').focus();
		return false;
    }

//    form.submit();
	return true;
}

function validatehandy()
{
	var form = document.subForm;

	//Validating First Name
	var name = document.getElementById('name').value;
	if (IsBlank(name))
	{
		alert ("This field is required!");
		document.getElementById('name').focus();
		return false;
	}

	//Validate Email
	var email= document.getElementById('email').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('email').focus();
		return false;
    }

   form.submit();
	return true;
}


function buyValidate()
{
	var form = document.formBuy2;

	//Validating First Name
	var name = document.getElementById('name2').value;
	if (IsBlank(name))
	{
		alert ("Please enter a valid User Name!");
		document.getElementById('name2').focus();
		return false;
	}

	//Validate Email
	var email= document.getElementById('jdutuh-jdutuh2').value;
	if ( ( IsBlank(email) ) || ( !isValidEmail(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('jdutuh-jdutuh2').focus();
		return false;
    }

//    form.submit();
	return true;
}











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


function nextTestimonial()
{
    element1 = '.info .hydro-cont';
	amount1 = $(element1).length;

	eval(document.getElementById("hydro-cont-id"+count)).style.display="none";

    if(count == 4)//amount > that number order (i+1) of .content
	{
			eval(document.getElementById("hydro-cont-id"+0)).style.display="block";
			count=0;
	}
	else
	{
			j=count+1;
			eval(document.getElementById("hydro-cont-id"+j)).style.display="block";
			count++;
	}
}

function prevTestimonial()
{
    element1 = '.info .hydro-cont';
	amount1 = $(element1).length;

	eval(document.getElementById("hydro-cont-id"+count)).style.display="none";

    if(count == 0)//amount > that number order (i+1) of .content
	{
			eval(document.getElementById("hydro-cont-id"+2)).style.display="block";
			count=4;
	}
	else
	{
			j=count-1;
			eval(document.getElementById("hydro-cont-id"+j)).style.display="block";
			count--;
	}
}

function fnc_hideShowReviews(nArgValue)
{
	if(nArgValue=='hide')
		document.getElementById("hydro-pop-up").style.display="none";
	else
		document.getElementById("hydro-pop-up").style.display="block";
}







