function confirmar(mensaje, url) {
	if (confirm(mensaje)) {
		window.location.href=url;
	}
}

function alerta(mensaje) {
	alerta = window.open("", "ventana", "width=150,height=100, toolbar=no,location=no,status=no,menubar=no");
	var algo = "sdfsdfd";
	alerta.document.writeln('<html><head>');
	alerta.document.writeln('<link href="estilos.css" rel="stylesheet" type="text/css">');
	alerta.document.writeln('</head><body bgcolor="#FFFFCC" onMouseOver="window.close()";>');
	alerta.document.writeln('<h4>'+mensaje+'</h4>');
	alerta.document.writeln('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">');
}

///////////////////////////////////////
function ventanita() {
	//ventanita = window.open("ventanita.htm", "ventanita", "width=170,height=30");
	izq = screen.width*0.35;
	superior = screen.height*0.35;
	ventanita = window.open("ventanita.htm", "ventanita", "width=170, height=10, left="+izq+", top="+superior);
}
///////////////////////////////////////
function cerrar_ventanita() {
	if (ventanita && !ventanita.closed) {
		ventanita.close();
	}
}
//////////////////////////////////////////
function ChequearTodos(chkbox) {
	for (var i=0;i < document.forms[0].elements.length;i++) {
		var elemento = document.forms[0].elements[i];
		if (elemento.type == "checkbox") {
			elemento.checked = chkbox.checked
		}
	}
}

function levantar_codigos(){
	valores = form1.cotizacion.value();
	return valores;
}

function accion_a_boton(direccion, msg_confirmacion, directo) {
	cotizaciones = objForm.cotizacion.getValue();
	direccion = direccion+cotizaciones;
	//alert(direccion);

	// si marcó alguna cotizacion le doy accion al boton, sinó no
	if (cotizaciones.length >=1) {

			if (directo) { // si es directo, no tengo que confirmar antes

					window.location.href = direccion;

			} else {

					if (confirm(msg_confirmacion)) {

						window.location.href = direccion;

					}// end if confirmacion

			}

	}  else {

			window.alert("No hay cotizaciones marcadas");

	}// end if longuitud cotiz

}//funcion

function button_action(direccion, msg_confirmacion, accion) {

		// cuento la cant de cotizaciones marcadas
		cant_cotiz = 0;
		for (var i=0;i < document.forms[0].elements.length;i++) {
			var elemento = document.forms[0].elements[i];
			if (elemento.type == "checkbox" && elemento.name == "cotizacion[]" && elemento.checked) {
				cant_cotiz++;
			}
		}

	// si marcó alguna cotizacion le doy accion al boton, sinó no
	if (cant_cotiz >=1) {

			if (accion) { // si viene alguna acción, pongo eso en un campo hidden
				document.form1.accion.value = accion;
			}
			document.form1.action = direccion;

			if (msg_confirmacion) { // si hay un mensaje de confirmacion, hago el confirm, sinó directo el submit del form

				if (confirm(msg_confirmacion)) {
						document.form1.submit();

				}// end if confirmacion

			} else { // directo el submit, sin confirmación
				document.form1.submit();
			}

	}  else {

			//window.alert("No hay cotizaciones marcadas");

	}// end if longuitud cotiz

}//funcion

/*
function combo(objeto, accion) {

	for (i = 0; i< objeto.length; i++) {
				if (accion == "marcar") {
				objeto[i].selected = true;
			} else {
				objeto[i].selected = false;
			}
	}

}
*/

function combo(objeto, accion) {

	for (i = 0; i< document.getElementById(objeto).length; i++) {
				if (accion == "marcar") {
				document.getElementById(objeto)[i].selected = true;
			} else {
				document.getElementById(objeto)[i].selected = false;
			}
	}

}

function validarCUIT(cuit) {
	if (cuit.length == 0) return true;
	else if (cuit.length != 11) return false;
		var sum = 0;
		var table = new Array(5, 4, 3, 2, 7, 6, 5, 4, 3, 2);
		for (i = 0; i < 10; i++) {
		  sum += parseInt(cuit.charAt(i)) * table[i];
	}
	var dif = sum % 11;
	if (dif > 0 && 11 - dif == parseInt(cuit.charAt(10))) return true;
	if (dif < 0 && dif == parseInt(cuit.charAt(10))) return true;
	return false;
}

/*
===========================================
 CHECKRADIO
===========================================
Parametros
   name: nombre del radio a evaluar
   value: valor que debe tener para ser valido
*/
function checkRadio( name, value ){
   var objRadio,i,resultado;
   objRadio = eval( "document.form1." + name );
   resultado = false;
   for ( i=0; i<objRadio.length; i++ ){
      if ( (objRadio[i].checked) && (objRadio[i].value == value) ){
         resultado = true;
      }
   }
   return resultado;
}

function checkear_chkbox(valor) {
	for (var i=0;i < document.forms[0].elements.length;i++) {
			var elemento = document.forms[0].elements[i];
					if (elemento.type == "checkbox" && elemento.value == valor) {
							elemento.checked = true;
			}
	}

}

// Toggles the layer visibility off
function capa(layerName, accion) {
	//alert(layerName);
	if (accion == 1) {
		//document.getElementById('t_ciaAseguradora_otra').style.visibility="visible";
		//document.getElementById(layerName).style.visibility="visible";
		document.getElementById(layerName).style.display="block";
	} else {
		//document.getElementById('t_ciaAseguradora_otra').style.visibility="hidden";
		//document.getElementById(layerName).style.visibility="hidden";
		document.getElementById(layerName).style.display="none";
	}
}

function habilitarCampoOtras(valorCampo, valorCondicion, claseCapa) {
	//alert('el valor del campo es ' + valorCampo);
	//alert('el valor de la condic es ' + valorCondicion);
	if (valorCampo == valorCondicion) {
		//capa(nombreCapa, 1);
		toggleDisplay2(claseCapa, 1);
	} else {
		//capa(nombreCapa, 0);
		toggleDisplay2(claseCapa, 0);
	}
}

function showElements(show,names)
{ if (show == 1) show = 'visible'; else show = 'hidden';
var e;
for (var i = 1; i < arguments.length; i++) {
e = document.getElementById(arguments[i]);
//if (e) e.style.display = show;
if (e) {
	 e.style.visibility = show;
	 //alert(document.getElementById(arguments[i]).style.visibility);
	} else {
			//alert('no');
	}
}
}

function toggleDisplay(itemname)
{
    tmp = document.getElementsByTagName('div');
    for (i=0;i<tmp.length;i++)
    {
        if (tmp[i].className == itemname) tmp[i].style.display = (tmp[i].style.display == 'none') ? 'block' : 'none';
    }
}

function toggleDisplay2(itemname, accion)
{
    tmp = document.getElementsByTagName('div');
    for (i=0;i<tmp.length;i++)
    {
        if (tmp[i].className == itemname) {
        	if (accion == 0) {
        		tmp[i].style.display = 'none'
        	} else {
						tmp[i].style.display = 'block'
        	}
        }
    }
}

function hideDiv(divID) {

	if (document.layers) {
		document.layers[divID].visibility="hide";
	} else {
		document.getElementById(divID).style.visibility="hidden";
		document.getElementById(divID).style.display="none";
	}
}

function showDiv(divID) {
	if (document.layers) {
		document.layers[divID].visibility="show";
	} else {
		document.getElementById(divID).style.visibility="visible";
		document.getElementById(divID).style.display="block";
	}
}

function toogleDiv(sourceField, valor, targetField) {
	if (document.getElementById(sourceField).value == valor) {
		showDiv(targetField);
	} else {
		hideDiv(targetField);
	}
}

function toogleDiv2(sourceField, valor, targetField) {
	if (document.getElementById(sourceField).value == valor) {
		hideDiv(targetField);
	} else {
		showDiv(targetField);
	}
}

function getRadioValue(nombre) {
	for (i=0;i<document.forms[0].elements[nombre].length;i++) {
		if (document.forms[0].elements[nombre][i].checked)	{
			return document.forms[0].elements[nombre][i].value;
		}
	}
}
