function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function go_back2(){
	if(history_level == 0 ){
		if(document.getElementById('mapdistrito')){
			//alert(jQuery('#mapdistrito').attr('class').substr(7));
			jQuery('#mapsublink').html('<img  usemap="#mapita" src="img/'+jQuery('#mapdistrito').attr('class').substr(7)+'.jpg" />');
		} else {
			location.href = 'index.php?route=index/map_select&type='+indi_type+'&comparar=provincia';
		}
	
	} else {
		//if(url_lista_indicadores > 22){
			jQuery('.indicadores').html('<span class="loading">Cargando...</span>');
			$.ajax({
				url: window.url_lista_indicadores + '&periodo=' + document.getElementById("cboperiodo").value,
				success: function(data) {
					document.getElementById('id_indicadores').innerHTML = data;
					runScripts(document.getElementById('id_indicadores'));
					//$('.indicadores').html(data.substr(0,data.length - 1));
				}
			});
		//}	
	}
	return false;
}

function runScripts(e) {
	if (e.nodeType != 1) return; //if it's not an element node, return
 
	if (e.tagName.toLowerCase() == 'script') {
		eval(e.text); //run the script
	}
	else {
		var n = e.firstChild;
		while ( n ) {
			if ( n.nodeType == 1 ) runScripts( n ); //if it's an element node, recurse
			n = n.nextSibling;
		}
	}
}

function submitForm(theform,container){
	$(theform).find('.form_error').html('<b>Validando...</b>');
    var options = { 
        success:       function(){showResponse(arguments[0],theform,container)}  // post-submit callback 
    }; 
	$(theform).ajaxSubmit(options); 
	return false;
}
function showResponse(responseText, theform,container)  { 
	if(responseText.search(/false:/)!=-1){
		$(theform).find('.form_alert').html(responseText.substr(6));
	}else {
		//$(theform).html('');
		$(theform).html(responseText);
		return false;
	}
} 



	
	jQuery.validator.addMethod("newpassword", function(value, element) { 
		alert(jQuery('#confirm_password').val());
	  if(value == jQuery('#confirm_password').val()) return true;
	  return false;
	}, "Contraseņas no coinciden");

	
	
		
function maximaLongitud(texto,maxlong){
	var tecla, int_value, out_value;

	if (texto.value.length > maxlong)
	{
		in_value = texto.value;
		out_value = in_value.substring(0,maxlong);
		texto.value = out_value;
		alert("La longitud maxima es de " + maxlong + " caracteres");
		return false;
	}
	return true;
}

function validateForm(t){
	var check = false;
	email = jQuery(t).find('.div_email input');
	reuse = jQuery(t).find('.reuse:checked');
	//$("p").fadeOut("slow");
	
	if(reuse && reuse.val() !== undefined){
		
		//obj_div_email.append('<div> </div>');
		$.getJSON(url_old_contact + email.val(), function(data) {
			if(data.result){
				jQuery(t).find('.div_email label').remove();
				jQuery(t).find('.div_phone label').remove();
				jQuery(t).find('.div_name label').remove();
				jQuery(t).find('.div_address label').remove();
				check = true;
				
				jQuery(t).find('.div_email input').removeClass('required');
				jQuery(t).find('.div_phone input').removeClass('required');
				jQuery(t).find('.div_name input').removeClass('required');
				jQuery(t).find('.div_address input').removeClass('required');
				
				if(jQuery(t).valid()){
					submitForm(t);
				} else {
					jQuery(t).find('.div_email input').addClass('required');
					jQuery(t).find('.div_phone input').addClass('required');
					jQuery(t).find('.div_name input').addClass('required');
					jQuery(t).find('.div_address input').addClass('required');
				}
			} else {
				obj_div_email = jQuery(t).find('.div_email').append('<label class="error">No se encontro registro</label>');
			}
		});
		return false;
	} else {
		//alert(email.val());
		if(jQuery(t).valid()){
			submitForm(t);
		}
	}
	return false;
}

function normalSubmit(t){
	if(jQuery(t).valid()){
		t.submit();
		return true;
		//document.form_web_recomendar.submit();
	}
	return false;
}

		function set_new_limit(){
			current = url_current;
			window.location = current + '/limit:' + jQuery('#page_limit').val();
		}

