$(function() {      
  $('tr.odd, tr.even').mouseover(function() {  
       $(this).addClass("overrow").show("slow");  
  } )  
  $('tr.odd, tr.even').mouseout(function() {  
      $(this).removeClass("overrow").show("slow");  
  } )  
 
})  

  function hide_search(){
	  
	     $("#pixel").attr("src", "/public/img/search_img.jpg");
		$("#search").hide();
	  
  }
  
  function show_search(){
	  
	  	$("#pixel").attr("src", "/public/img/pixel.jpg");
		$("#search").show();
	  
  }

function doSubmit(id_form, action){
	$("#"+id_form).attr('action', action);
	$("#"+id_form).submit();
}

function doValid(id_form, action){
	
	if(initValidation(id_form)){	
		$("#"+id_form + "#img_enviar").hide();
		doSubmit(id_form, action);		
	}
}

function initValidation (id_form){
		
	var correcto = true;	
	// campos requeridos
	  $("#"+id_form).find(".required:visible").each(function(i) {
		id = $(this).attr("id");
	   valor=$(this).attr("value");
		
	   if (valor==undefined || valor=="0" || valor=="void"){
	   	   mark_field(id,'required');
		   correcto = false;		
	   }else 
	   		unmark_field(id,'required');
     
	   });
	  
	  
	    
	   // checkbox ----------------------------------------------
	var	k=0;	 
	var	numero_total=false;
	var checbox_validar = false;
	
	// buscamos todos los checkbox que tengan la clase required_check
	   $("#"+id_form).find(".required_check:visible").each(function(i) {
		id = $(this).attr("id");
		 
	  	// cogemos el id de cada uno y buscamos la longitud
	    var checked = $("input[@id="+id+"]:checked").length; 
        if (checked == 0) { k++; } // sumamos uno al contador si encontramos vacío
		
		numero_total++;
		checbox_validar = true;

	   });

	
		
	   if(true == checbox_validar && k==numero_total){ // comprobamos si hay como mínimo 1 seleccionado, de no ser así mostramos error
		correcto = false;
		 mark_field(id,'required');
	 	$("#interested").show();
	   }else{

		   $("#interested").hide();
	   }
	   // FIN checkbox ----------------------------------------------
	  

     
	  
	// Aceptar condiciones	
	if($("#accept_cond").attr("value") != undefined && $("#accept_cond:checked").val() == null){		
		mark_field('accept_cond','required');
	   correcto = false;
	}else{
		unmark_field('accept_cond','required');
	}
	  
	// campos password iguales	  
	pasw = $("#password").attr("value");		
	repasw = $("#repassword").attr("value");		
	if(pasw != undefined && pasw != ''){
		if (pasw == repasw){
   			unmark_field('password','match_password');  		
	   }else{ 
   		   mark_field('password','match_password');
		   correcto = false;
	   }  	
	}
	   
	  
	 
	// campos email
	$("#"+id_form).find(".valid_email:visible").each(function(i) {	
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  
	   if (valor!=undefined) {
	  if (!valor.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
	  	mark_field(id,'valid_email');
		correcto = false;
	  }else unmark_field(id,'valid_email');
	   }
	   });
	   
	 // min length
	 $("#"+id_form).find(".min_length:visible").each(function(i) {		
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  if (valor!=undefined) {
	  if (valor.length<6){
	  	mark_field(id,'min_length');
		correcto = false;
	  }
	   else unmark_field(id,'min_length');
	  }
	   });

	 $("#"+id_form).find(".minimum:visible").each(function(i) {			 
		id = $(this).attr("id");
	   valor=$(this).attr("value");
	  if (valor!=undefined) {
	  	id = $(this).attr("id");
	  	fieldcomp = id.substring(0, id.indexOf('_') );
	  	
	  	valor2=$("#"+fieldcomp).attr("value");
	  
	  	if (parseInt(valor)>parseInt(valor2)){
	  	correcto = false;
	  	mark_field(id,'minimum');
		}
	   else unmark_field(id,'minimum');
	  }
	   }); 	  
	 
	 return correcto;
}

function mark_field (id, type)
{	
	$("#"+id).css("background-color", "#FFE400");	
	//document.getElementById(id).style.backgroundColor="#ffffcc";
	//$("#"+id).addClass('fondo');

	$("#error_all_" + type).show();	
}

function unmark_field (id, type)
{	
	$("#"+id).css("background-color", "#FFFFFF");
	$("#error_"+ id + "_" + type).hide();
	//$("../",id).remove("span");
}

						
function borrar_opcion(text){
	if(confirm(text)){
		return true;
	}else return false;
}

function popup(page, title, width, height) {	
	window.open(page, title, "width=" + width + ",height="+height+",menubar=no,scrollbars=yes");
}

function doPost (uri, field_name, field_value)
{
	idForm=Math.round(Math.random()*10);
	
	htmlForm = "<form id='dyn_form' action='"+uri+"' method='POST'>";
	htmlForm+= "<input type='hidden' name='"+field_name+"' value='"+field_value+"' >";
	htmlForm+= "</form>";
	
	$("body").append(htmlForm);
	$("#dyn_form").submit();
}



function OFlash (file, width, height, bgcolor, mode) { document.write ("<object codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 height=" + height + " width=" + width + " classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME='FlashVars' VALUE=''><PARAM NAME='Movie' VALUE='" + file + "'><PARAM NAME='Src' VALUE='" + file + "'><PARAM NAME='WMode' VALUE='" + mode + "'><PARAM NAME='Play' VALUE='-1'><PARAM NAME='Loop' VALUE='-1'><PARAM NAME='Quality' VALUE='High'><PARAM NAME='SAlign' VALUE=''><PARAM NAME='Menu' VALUE='0'><PARAM NAME='Base' VALUE=''><PARAM NAME='AllowScriptAccess' VALUE='0'><PARAM NAME='Scale' VALUE='ShowAll'><PARAM NAME='DeviceFont' VALUE='0'><PARAM NAME='EmbedMovie' VALUE='0'><PARAM NAME='BGColor' VALUE='" + bgcolor +"'><PARAM NAME='SWRemote' VALUE=''><PARAM NAME='MovieData' VALUE=''><PARAM NAME='SeamlessTabbing' VALUE='1'><PARAM NAME='Profile' VALUE='0'><PARAM NAME='ProfileAddress' VALUE=''><PARAM NAME='ProfilePort' VALUE='0'><embed src='" + file + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='" + width + "' height='" + height +"'  wmode= '"+mode+"'></embed></object>"); }


function go_back(){
	history.back();
}

function toggle_him(id){
		
	  $(".arrow").attr("src", "/public/img/arrow_right.jpg");
  	  $("#arrow_"+id).attr("src", "/public/img/arrow_down.jpg");
	  $(".respuesta").hide();
	  $("#respuesta_"+ id).show();
	  

}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
