// JavaScript Document
var pageactual, divactual;
var claseError="claseError2";
var claseCorrecto="claseCorrecto";

function load_img(img,div){
loading(div);
$(div).innerHTML ='<img src="'+img+'" />';
jQuery(div).animate({ height: 'show', opacity: 'show' }, 'slow');
}

function notif(text,div_aviso,div){
jQuery('#'+div).show('slow'); 
$(div_aviso).innerHTML =text;
jQuery('#'+div).animate({ height: 'show', opacity: 'show' }, 'slow');
}

function close_notif(div){ jQuery('#'+div).hide('slow'); }

function loading(div){
$(div).innerHTML ='<div align="center"><br><br>Cargando datos, espere un momento por favor...<br><br></div>';
//jQuery('#'+div).animate({ height: 'show', opacity: 'show' }, 'slow');
jQuery('#'+div).animate({ width:'show', opacity: 'show' }, 'slow');
}

function loading2(div){
$(div).innerHTML ='Cargando...';
jQuery('#'+div).animate({ height: 'show', opacity: 'show' }, 'slow');
}
function hides(div){
//jQuery('#'+div).slideToggle(1000,"easeOutBounce");
jQuery('#'+div).animate({ width:'hide', opacity: 'hide' }, 'slow');
}

function login(url,div) {
var ajx = new Ajax.Updater(div, url, {method:"post", evalScripts: true, onLoading:loading2(div) } );
}

function open_page(url,div,parametros) {
var ajx = new Ajax.Updater(div, url, {method:"post", postBody:parametros, evalScripts: true, onLoading:loading(div) } );
}

function open_modal(url,div,parametros) {
var ajx = new Ajax.Updater(div, url, {method:"post", postBody:parametros, evalScripts: true, onLoading:loading(div) } );
}

function page(url,div) {
var ajx = new Ajax.Updater(div, url, {method:"post", evalScripts: true, onLoading:loading(div) } );
}

function get_page(op,url,div,parametros) {
var band=0;
var ban=0;
switch(op){
  case 'add':
  if(vacio($F('sku'))==false){ban++; jQuery("#sku").addClass("claseError");}else{jQuery("#sku").removeClass("claseError");}
  if(vacio($F('cantidad'))==false){ban++; jQuery("#cantidad").addClass("claseError");}else{jQuery("#cantidad").removeClass("claseError");}
  if(vacio($F('total'))==false){ban++; jQuery("#total").addClass("claseError");}else{jQuery("#total").removeClass("claseError");}
  if(vacio($F('descripcion'))==false){ban++; jQuery("#descripcion").addClass("claseError");}else{jQuery("#descripcion").removeClass("claseError");}
   if(ban==0){
	if(parseInt($F('cantidad'))!= 0){
      band=1;
	    //sku='++'&cant='+$F('cantidad')+'&
	  url=url+'&sku='+$F('sku')+'&cant='+$F('cantidad')+'&desc='+$F('descuento')+'&des1='+$F('desc1')+'&des2='+$F('desc2')+'&uni='+dformat($F('subtotal'))+'&precio='+dformat($F('precio'));
	    // parametros=$(parametros).serialize();
       }else{alert('NO SE HA ESPECIFICADO UNA CANTIDAD.');}
     }
  break;
  
  case 'imp':
  if(vacio($F('pagoCliente'))==false){ban++; jQuery("#pagoCliente").addClass("claseError");}else{jQuery("#pagoCliente").removeClass("claseError");}
  if(vacio($F('cambio'))==false){ban++; jQuery("#cambio").addClass("claseError");}else{jQuery("#cambio").removeClass("claseError");}
  if( dformat($F('vTotal'))>dformat($F('pagoCliente')) ){ ban++; alert('EL PAGO NO CORRESPONDE AL TOTAL A PAGAR'); }
  if( dformat($F('vTotal'))<0 ){ ban++; alert('SE TIENE QUE CUBRIR EL TOTAL DE LA NOTA DE CREDITO'); }
  if(ban==0){
    if($F('tip1')=='X'){ tipo='EFECTIVO'; }
	if($F('tip2')=='X'){ tipo='TARJETA'; }
	if($F('tip3')=='X'){ tipo='DOLARES'; }
    url=url+'?tipo='+tipo+'&sub='+$F('vSubtotal')+'&iva='+$F('vIva')+'&total='+$F('vTotal')+'&efectivo='+$F('pagoCliente')+'&cambio='+$F('cambio')+'&nc='+$F('idNota');
	band=1;
	//alert('pagado '+url);
  }
  break;

  case 'nc':
  if(vacio($F('cantu'))==false){ban++; jQuery("#cantu").addClass("claseError");}else{jQuery("#cantu").removeClass("claseError");}
  if(vacio($F('motivo'))==false){ban++; jQuery("#motivo").addClass("claseError");}else{jQuery("#motivo").removeClass("claseError");}
  
  if(ban==0){
    url=url+'&cant='+$F('cantu')+'&motivo='+$F('motivo')+'&precio='+dformat($F('precio'));
	band=1;
  }
  break;
  
}// fin del switch
  if(band==1){
  var ajx = new Ajax.Updater(div, url, {method:"post", postBody:parametros, evalScripts: true, onLoading:loading(div)} );
  }	
}