jQuery(document).ready(function(){
	//Shadowbox.init();
	
	//menu header// //el menu del header tiene la funcion de tipo "hover"...(el evento hover tiene dos function(). El 1º para cuando abre 2º para cuando cierra...) ...
	 $(".header_down ul > li").hover(function(){	//se identifica al elemento donde queremos hacer hover y la aplicamos la función...
									
									$(this).children("ul.submenu").slideToggle("fast");//aca se le pide que abra el contenido del elemetno cuando se posicione sbore él		
									

								},function(){
  									
									$(this).children("ul.submenu").hide("fast");//aca se le pide que cierre elcontenido del elemento cuando se saque la posición del mouse sobre dicho elemento...
									
								});
									
	 $(".header_down ul > li").hover(function(){	
									
									$(this).children("ul.resource").slideToggle("fast");		
									

								},function(){
  									
									$(this).children("ul.resource").hide("fast");
								
	
								}); 
	 
	 $(".header_down ul > li").hover(function(){	
									
									$(this).children("ul.perferred").slideToggle("fast");		
									

								},function(){
  									
									$(this).children("ul.perferred").hide("fast");
								
	
								});  
	 
	 
	 


///////////////// HENRY //////////////////
$('#main .representative #represent_map .tool a').click(
      function(){
			$(this).parent().parent().addClass('active');
			$(this).parent().parent().siblings().removeClass('active');
			$('.representative .info_rep').css({display:'none'});
			$('.representative #'+$(this).attr('mark')).css({display:'block'});
			//return false;
        }
    );

	/*$('#represent_map .tool.one').addClass('active');
	$('.representative #one').css({display:'block'});*/
	//return false;
///////////////// HENRY //////////////////




//hover para que ande el hover de palabras de representative en ie6



$("#main .representative #represent_map .small_left_pic_map.active.tool .tip a").css("color","#EAE7D2");

$("#main .representative #represent_map .tool .tip").hover(function(){

									$(this).children("a").addClass("bg_color");


								},function(){

									$(this).children("a").removeClass("bg_color");

								});
								

//hovers para ver la imagen de fondo cuando se hace hover en ie6...

	$("#represent_map .small_left_pic_map .tip a").hover(function(){

									$(this).parent().parent(".small_left_pic_map").addClass("bg_left_small");


								},function(){

									$(this).parent().parent(".small_left_pic_map").removeClass("bg_left_small");

								});

    $("#represent_map .big_left_pic_map .tip a").hover(function(){

									$(this).parent().parent(".big_left_pic_map").addClass("bg_left_big");


								},function(){

									$(this).parent().parent(".big_left_pic_map").removeClass("bg_left_big");

								});
								
    $("#represent_map .small_right_pic_map .tip a").hover(function(){

									$(this).parent().parent(".small_right_pic_map").addClass("bg_right_small");


								},function(){

									$(this).parent().parent(".small_right_pic_map").removeClass("bg_right_small");

								});
								
								
    $("#represent_map .big_right_pic_map .tip a").hover(function(){

									$(this).parent().parent(".big_right_pic_map").addClass("bg_right_big");


								},function(){

									$(this).parent().parent(".big_right_pic_map").removeClass("bg_right_big");

								});
								
								

								

/*lo que sigue son hags para internet 6....*/
//jQuery("#header .header_down ul > li:first-child").css("background", "none"); 

//$("#header .header_down ul > li:first-child").css({background:"none"});

//$("#header .header_down ul li ul.submenu > li:hover").css({background:"#D3CFAC"});

$("#header .header_down ul li ul.submenu > li:last-child").css({background:"url(images/bg_down_submenu.gif) no-repeat"});

$("#header .rcbf_left ul > li:last-child").css({background:"url(images/rcbf_border_down.gif) no-repeat"});

$("#header .rcbf_left ul.saf > li:last-child").css({background:"none"});

$("#header .header_down ul li ul.submenu > li:hover").css({background:"#D3CFAC"});

$("#main .representative .rcbf_left ul li:last-child").css({background:"url(images/rcbf_border_down.gif) no-repeat"});

$("#header .header_down ul li ul.resource li:last-child").css({background:"url(images/bg_down_submenu_resource.gif) no-repeat"});
  
$("#header .header_down ul li ul.resource > li:hover").css({background:"#D3CFAC"});

$("#header .header_down ul li ul.perferred li:last-child").css({background:"url(images/bg_down_submenu_preferrer.gif) no-repeat"});
   
$("#main .representative .rcbf_left ul.saf li:last-child").css({background:"none"});

$("#header .header_down ul.menu > li:first-child").css({background:"none"});
  
// Validation form Contact us //

jQuery("form#contactus").submit(function() {


			if (!isFormValid('#contactus'))
			{
				alert("Please fill in the required fields marked with a *");
				return false;
			} else
			{
				return true;
			}

  });

});

function isFormValid(thisform){
	var ok = true;

	jQuery("form"+thisform+"").find(".required").each(function(){
		if(this.value == "")
			//this.focus();
			ok = false;
	});

   jQuery("form"+thisform+"").find(".email").filter(".required").each(function(){
		if(!valid_email(this.value))
			//this.focus();
			ok = false;
	});

return ok;
}


function validate()
{
	var form = document.contactus;

	//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) ) || ( !valid_email(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('email').focus();
		return false;
    }
	
	//Validate Address
	var address= document.getElementById('address').value;
	if ( IsBlank(address))
	{
		//alert ("Please enter a valid address!");
		document.getElementById('address').focus();
	
		return false;
    }
	
	//Validate City
	var city= document.getElementById('city').value;
	if ( IsBlank(city))
	{
		//alert ("Please enter a valid address!");
		document.getElementById('city').focus();
	
		return false;
    }
	
	//Validate State
	var state= document.getElementById('state').value;
	if ( IsBlank(state))
	{
		//alert ("Please enter a valid address!");
		document.getElementById('state').focus();
	
		return false;
    }
	
	//Validate Zip
	var zip= document.getElementById('zip').value;
	if ( IsBlank(zip))
	{
		//alert ("Please enter a valid address!");
		document.getElementById('zip').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;
	}

	//Validate Facility
	var facility= document.getElementById('facility').value;
	if ( IsBlank(facility))
	{
		//alert ("Please enter a valid address!");
		document.getElementById('facility').focus();
	
		return false;
    }
	
//    form.submit();
	return true;
}


//validacion de send to friend
function validatefriend()
{
	var form = document.contactus;

	//Validating email-friend
	var emailfriend= document.getElementById('emailfriend').value;
	if ( ( IsBlank(emailfriend) ) || ( !valid_email(emailfriend) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('emailfriend').focus();
		return false;
    }
	
	//validating name
	var name= document.getElementById('firstname').value;
	if (IsBlank(name))
	{
		alert ("please enter a name!");
		document.getElementById('firstname').focus();
		return false;
	}

	//Validate Email
	var youremail= document.getElementById('youremail').value;
	if ( ( IsBlank(youremail) ) || ( !valid_email(youremail) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('youremail').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;
}


//validacion de emailing_form
function validate_emailing()
{
	var form = document.emailing_form;

	//validating firstname
	var firstname= document.getElementById('firstname').value;
	if (IsBlank(firstname))
	{
		alert ("Please complete the fields with *");
		document.getElementById('firstname').focus();
		return false;
	}
	
	//validating lastname
	var lastname= document.getElementById('lastname').value;
	if (IsBlank(lastname))
	{
		alert ("Please complete the fields with *");
		document.getElementById('lastname').focus();
		return false;
	}
	
	//Validate Email
	var email= document.getElementById('email').value;
	if ( ( IsBlank(email) ) || ( !valid_email(email) ) )
	{
		alert ("Please enter a valid email address!");
		document.getElementById('email').focus();
		return false;
    }
	
	//validating comments
/*	var comments= document.getElementById('comments').value;
	if (IsBlank(comments))
	{
		alert ("Please complete the fields with* ");
		document.getElementById('comments').focus();
		return false;
	}
*/
	
	
	
	
//    form.submit();
	return true;
}





function valid_email(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	 if (str.indexOf(" ")!=-1){
		return false;
	 }
	 return true
}
function convert(form){

						// find out which option is selected then
						// assign the value of the selected option 

							  var i = form.fromunits.selectedIndex;
							  var fromvalue = form.fromunits.options[i].value;
							  var j = form.tounits.selectedIndex;
							  var tovalue = form.tounits.options[j].value;

						// perform the conversion
						   form.tovalue.value = (form.fromvalue.value * fromvalue) / tovalue;
						 return true;
						}

function clearfield(form)
{
	form.fromvalue.value = "";
	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;
}

