function odcGenerar(id){
	$('#odc_'+id).slideToggle('slow'); 
}
function odcAceptar(id){
	$('#odc_'+id).slideToggle('slow',function(){
		cont = $('.tit_'+id);
		len = cont.length;
		for (i = 0; i < len; i++){
			$('.tit_'+id)[i].setAttribute('style','color:#090')
		}
		$('#odcShow_'+id)[0].style.display = 'none';
		$('#odcUndo_'+id)[0].style.display = '';
		$('#odcConfirm_'+id)[0].value = '1';
	}); 
}
function odcDeshacer(id){
	$('#nombre_'+id)[0].value = '';
	$('#apellido_'+id)[0].value = '';
	$('#truck_'+id)[0].value = '';
	$('#semi_'+id)[0].value = '';
	$('#dni_'+id)[0].value = '';
	cont = $('.tit_'+id);
	len = cont.length;
	for (i = 0; i < len; i++){
		$('.tit_'+id)[i].setAttribute('style','')
	}
	$('#odcShow_'+id)[0].style.display = '';
	$('#odcUndo_'+id)[0].style.display = 'none';
	$('#odcConfirm_'+id)[0].value = '';		
}

function odcPermitir(){
	return false;
}

// wait for the DOM to be loaded 
$(document).ready(function() { 
    // bind 'myForm' and provide a simple callback function 
	$("#odcSubmit").click(function(){ 
		$.post("verificar1.php", 
			$("#formCuenta").serialize(),function(data){ 
//				alert(data);
				if (data == 'si'){
					$("#formCuenta").submit();
				} else if(data == 'vacio'){
					alert('Debe llenar alguna orden de carga antes de continuar');
				}else if(data == 'no'){
					alert('Faltan confirmar containers para llenar su orden de carga')
				}
			}
		); 
		return false;
	}); 
	
	$('#linkCostos').click(function(){
		$('#costos').toggle();
	});
}); 

function ingresarCodigo(id){
	$('#odcGeneradas_'+id)[0].style.display = '';
}
function pedirFactura(id){
	$.post("verificar2.php", {numAcr: $('#numAcr_'+id)[0].value, idAcr: id},function(data){ 
//		alert(data);
			if (data == 'si'){
				$('#odcGeneradas_'+id)[0].parentNode.innerHTML = 'La factura le llegar&aacute; al domicilio fiscal en 72 horas.';
			}
		}
	); 	
}

function calcCosto1(error1){
	val = parseFloat($('#costo')[0].value);
	if (isNaN(val)){
		msg = error1;
	} else {
		msg = number_format(Math.round((val*4.75)*100)/100,2,',','.');
		msg = '$ '+msg;
	}
	$('#resCosto')[0].innerHTML = msg;
}

function number_format( number, decimals, dec_point, thousands_sep ) {
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}





var claseAux;
var inputAux = false;

function mando(){
	mandar = true;
	if (inputAux != false){
		inputAux.className = claseAux;
	}
	if (($('#cuit')[0].value == '' || $('#cuit')[0].value.length != 11) && mandar == true) mandar = new Array($('#cuit')[0],'text','Por favor ingrese un cuit de 11 caracteres');
	if ($('#mail')[0].value == '' && mandar == true) mandar = new Array($('#mail')[0],'text','Por favor ingrese un email valido');
	
	//parte del formato de los emails
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#mail')[0].value)) && mandar == true){
		mandar = new Array($('#mail')[0],'text','Atencion: La direccion de mail no es valida');
	}
	
	if (mandar == true){
		return true;
	} else {
		alert(mandar[2]);
		tipo = mandar[1];
		switch (tipo){
			case 'text':
				inputAux = mandar[0];
				claseAux = mandar[0].className;
				mandar[0].className = 'bordeRemarcado';
				mandar[0].focus();				
			break;
			case 'mails':
				marcoInput(mandar[0]);
			break;
		}
		return false;
	}
}

