﻿/**/
function hacerPostBack(ctrl){	
		if(document.all){		    
			setTimeout('__doPostBack(\"' + ctrl + '\",\"\");', 1);								
		}
		else{															
			__doPostBack(ctrl,"");
		}		
}
/*function: Reorder*/
function Reorder(eSelect, iCurrentField, numSelects)
{
        var eForm = eSelect.form;
        var iNewOrder = eSelect.selectedIndex + 1;
        var iPrevOrder;
        var positions = new Array(numSelects);
        var ix;
        var y;
        for (ix = 0; ix < numSelects; ix++)
        {
                positions[ix] = 0;
        }
        for (ix = 0; ix < numSelects; ix++)
        {
            if((ix + 2) < 10)
                y = '0' + (ix + 2).toString();
            else
                y = (ix + 2).toString();                
            
                positions[eSelect.form["grvBanners_ctl" + y + "_drpOrden"].selectedIndex] = 1;                                                                
        }
        for (ix = 0; ix < numSelects; ix++)
        {
                if (positions[ix] == 0)
                {
                        iPrevOrder = ix + 1;
                        break;
                }
        }
        if (iNewOrder != iPrevOrder)
        {
                var iInc = iNewOrder > iPrevOrder? -1:1
                var iMin = Math.min(iNewOrder, iPrevOrder);
                var iMax = Math.max(iNewOrder, iPrevOrder);
                for (var iField = 0; iField < numSelects; iField++)
                {                           
                        if((iField + 2)<10)
                            y = '0' + (iField + 2).toString();
                        else
                            y = (iField + 2).toString();
                        
                        if (iField != iCurrentField)
                        {
                                if (eSelect.form["grvBanners_ctl" + y + "_drpOrden"].selectedIndex + 1 >= iMin && eSelect.form["grvBanners_ctl" + y + "_drpOrden"].selectedIndex + 1<= iMax)
                                {
                                        eSelect.form["grvBanners_ctl" + y + "_drpOrden"].selectedIndex += iInc;
                                }
                        }
                }
        }
}
/**/
function OrderGroup(eSelect, iCurrentField, accion){
    var x;
    var y;
    var z;
    var tmpValor;
    y = ((iCurrentField + 2)<10)?'0'+(iCurrentField + 2).toString():(iCurrentField + 2).toString();
    x = ((iCurrentField + 1)<10)?'0'+(iCurrentField + 1).toString():(iCurrentField + 1).toString();
    z = ((iCurrentField + 3)<10)?'0'+(iCurrentField + 3).toString():(iCurrentField + 3).toString();
      
    tmpValor = eSelect.form["grvBanners_ctl" + y + "_drpOrden"].value
    if(accion=='bajar'){        
        eSelect.form["grvBanners_ctl" + y + "_drpOrden"].value = eSelect.form["grvBanners_ctl" + z + "_drpOrden"].value;
        eSelect.form["grvBanners_ctl" + z + "_drpOrden"].value = tmpValor;
    }
    else if(accion=='subir'){
        eSelect.form["grvBanners_ctl" + y + "_drpOrden"].value = eSelect.form["grvBanners_ctl" + x + "_drpOrden"].value;
        eSelect.form["grvBanners_ctl" + x + "_drpOrden"].value = tmpValor;
    }
    return false;
}
/**/
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;
}

// Retorna 'es' ó 'en' si la cookie está en español o ingles 
function cIdioma(){
	var mcookie = document.cookie;
	var cookies = document.cookie.split(';');
	var idioma = 'es';
	var cookie = 'Idioma=';
	for( var i = 0 ; i < cookies.length ; i++){
		var mcookie = cookies[i];
		while(mcookie.charAt(0) == ' ')mcookie= mcookie.substring(1, mcookie.length);
		if(mcookie.indexOf(cookie) == 0 ) idioma = mcookie.substring(cookie.length, cookie.length + 2);
	}
	return idioma;		
}
// Permite saber si se encuentra bien escrito un correo, si el campo es vacio retorna true
// Recibe el control , el llamado se hace : validCorreo(this);
function validCorreo(campo) {	
	
	var x;
	var exp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
	if(campo.value != ''){
		 x= campo.value;
		 if(!exp.test(x)){
			campo.focus();
			campo.select();	
			var error = (cIdioma() == 'es'? "Dirección de correo no válida !":"Invalid mail address!")
			alert(error);
			return false;
		 }
		 else{
			return true;
		 }
	}
	else{
		return true;
	}
}
// Valida una Url
function validarUrl(campo) {	
	
	var x;
	var exp = new RegExp("\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", "i");
	if(campo.value != ''){
		 x= campo.value;
		 if(!exp.test(x)){
			campo.focus();
			campo.select();	
			var error = (cIdioma() == 'es'? "Dirección de internet incorrecta!":"Invalid internet address!")
			alert(error);						
			return false;
		 }
		 else{
			return true;
		 }
	}
	else{
		return true;
	}
}
// Valida un campo númerico
function esNumerico(campo){
	var x;
	var retorno = false;
	var exp=/(^\d+$)|(^\d+\.\d+$)|(^\d+\.\d+\.\d+$)|(^\d+\.\d+\.\d+\.\d+$)|(^\d+\.\d+\.\d+\.\d+\.\d+$)|(^\d+\.\d+\.\d+\.\d+\.\d+\.\d+$)|(^\d+\.\d+\,\d+$)|(^\d+\.\d+\.\d+\,\d+$)|(^\d+\.\d+\.\d+\.\d+\,\d+$)|(^\d+\.\d+\.\d+\.\d+\.\d+\,\d+$)|(^\d+\.\d+\.\d+\.\d+\.\d+\.\d+\,\d+$)|(^\d+\,\d+$)|(^\-\d+$)|(^\-\d+\.\d+$)|(^\-\d+\.\d+\,\d+$)|(^\-\d+\.\d+\.\d+\,\d+$)|(^\-\d+\.\d+\.\d+\.\d+\,\d+$)|(^\-\d+\.\d+\.\d+\.\d+\.\d+\,\d+$)|(^\-\d+\.\d+\.\d+\.\d+\.\d+\.\d+\,\d+$)|(^\-\d+\,\d+$)/
	if(campo.value != "")
	{
			x = campo.value;		
			if (!exp.test(x))
			/* En el caso que la expresión sea númerica separado por puntos y comas*/	
			{
				campo.focus();
				campo.select();
			}
			else
			{
				
				x = mformatNumber(campo);				
				campo.value = x;
				retorno = true;
			}
	}
	else
	{
			retorno = true;	
	}
	return retorno;
}
/* Retorna una cadena con el formato númerico ej: 123456789,467  retorna  123.456.789,47 */
function mformatNumber(campo)
{
	var numero = campo.value;
	var menos = ''; 
	var yArray = new Array(50);
	if(numero.lastIndexOf("-") == 0 ){menos = '-';}
	if(numero.lastIndexOf(",") > 0 )
	{
		yArray = numero.split(",");
		yArray[0] = cleanNum(yArray[0]);	
		numero = yArray[0] + '.' + yArray[1];
	}	
	else{
		numero = cleanNum(numero);
		
	}	
	
	var mvalue = parseFloat(numero);
	mvalue = Math.round(mvalue*100)/100;
	numero = mvalue + '';
	if(numero.lastIndexOf(".") > 0 )
	{
		//numero = numero + '.00';
		yArray = numero.split(".");
		yArray[0] = puntoFormato(yArray[0]);
		numero = menos + yArray[0] + ',' + yArray[1];
	}
	else{
		numero = puntoFormato(numero);
		numero = menos + numero;
	}
	 
	return numero;
	
}
/*	DEJA UN CONJUNTO DE NUMEEROS DE LA SIGUIENTE FORMA 1234431324.1234 */
function cleanNum(campo){
		var x;
		var i; 
		var numero = '';
		for(i = 0 ; i < campo.length; i++ ){
			 x = campo.charCodeAt(i);
			 if(x > 47 && x < 58 )
			 { numero = numero + campo.charAt(i);}
			 else{
				/* si es una coma */
				if( x == 44){
				numero = numero + '.';
				}
			 }
		}
		return numero;
}
/*  Si el número está de la siguiente forma 1234431324.1234 retorna 1.234.431.324,1234 */
function puntoFormato(campo){
		
		var numero='';
		var num;
		if(campo.length > 3 )
		{
			num = parseInt(campo);
			var samount = new String(num);
			for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
			{
				samount = samount.substring(0,samount.length-(4*i+3)) + '.' + samount.substring(samount.length-(4*i+3));
			}
			numero = samount;
		}
		else{numero = campo;}
		return numero; 
	
}

/* Remplaza  las ocurrencias de < y > por { y } respectivamente   */
function cambiarMenorMayor(campo ){
	
	var x, i;	
	var y = '';
	var cadena;
	if(campo.value != '')	
	{
	
		cadena = campo.value;
		for(i = 0; i < cadena.length; i++ ){
			
			x = cadena.charCodeAt(i);
			if( x==60 ){
				y = y  +   '{';
				
			}
			
			if( x==62 ){
				y = y + '}' ;
				
			}
			
			if(  x != 60 && x != 62  ){
				y 	= y + 	cadena.charAt(i);	
			}
		
		}
	   
	}
	
	return y;
}
/* Oculta el mensaje de error*/
function ocultarError(idobjeto){
	var objeto;
	if ((objeto = MM_findObj(idobjeto))!=null) {
		objeto.style.visibility='hidden';
	}
}
/*  Función que permite detener el envio de un evento al servidor
	cuando se hace clic sobre un botón
*/
function confirmar(mensaje){
	if (!confirm(mensaje)){
		event.returnValue=false 
	}
}
//*Es el rollOver para los botones.
//Argumentos, id del boton, imagen1(), imagen2(iluminada).
function s_rollOver(){
   var i,j=0,x,a=s_rollOver.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.oBackgroundImage) x.oBackgroundImage=a[i+1]		
		x.style.backgroundImage= 'url(' + a[i+2]+ ')';
   }
}
//*Es restaurar la imagen(apagada) del boton.
function s_restore(){	
	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oBackgroundImage;i++) {
		x.style.backgroundImage='url(' + x.oBackgroundImage + ')';
		//alert(x.oBackgroundImage);
	}
}
//*Mensaje de confirmacion para borrar
function f_messagetoDelete(message){
	if(!confirm(message)){return false;}
	else{return true;}
}
//------------------------------------------------
//2007/05/10
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 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];}}
}
















