// JavaScript Document
function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}
/////////////////////////////
function objetos(tabla,ns,nf){
var objs= new Array();
var theForm = document.frm;
var n=3;
var ini;
var fin;
var j=0;
if(ns==0 && nf==0)
{ini=0; fin=theForm.elements.length;}else if(ns == 0 && nf!=0){ini=0; fin=nf;}else if(ns!= 0 && nf==0){ini=ns; fin=theForm.elements.length;}
   for(i=ini;i<fin;i++)
	{	

	 if(theForm.elements[i].type=='text')// || theForm.elements[i].type='select-one'
	 {	
			objs[j]=theForm.elements[i].name+'|'+theForm.elements[i].value.toUpperCase().split(',').join(' ').split('&').join(' ');
		j++;
	 }

   }
  	saveparam(objs,tabla);
} 
//------------
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function lengthd(val,len)
{ 
	if(val.length < len){}
	else
	{
		event.keyCode=0;
		alert('A excedido la longitud permitida');
	}
}
//--------------------
 function validCampo(sw)
 {      
  var theForm = document.frm;
   if(sw=='2')
   {
	theForm.elements[3].disabled =false;
	theForm.elements[3].style.backgroundColor='#FFFFFF';
	theForm.elements[7].disabled =false;
	theForm.elements[7].style.backgroundColor='#FFFFFF';
	theForm.elements[11].disabled =false;
	theForm.elements[11].style.backgroundColor='#FFFFFF';
	theForm.elements[14].disabled =false;
	theForm.elements[14].style.backgroundColor='#FFFFFF';
	theForm.elements[25].disabled =false;
	theForm.elements[25].style.backgroundColor='#FFFFFF';
	theForm.elements[26].disabled =false;
	theForm.elements[26].style.backgroundColor='#FFFFFF';
	theForm.elements[27].disabled =false;
	theForm.elements[27].style.backgroundColor='#FFFFFF';
	theForm.elements[30].disabled =false;
	theForm.elements[30].style.backgroundColor='#FFFFFF';
	theForm.elements[31].disabled =false;	
	theForm.elements[31].style.backgroundColor='#FFFFFF';
	theForm.elements[41].disabled =false;	
	theForm.elements[41].style.backgroundColor='#FFFFFF';
	theForm.elements[42].disabled =false;	
	theForm.elements[42].style.backgroundColor='#FFFFFF';	
   }else if(sw=='3')
   {
	theForm.elements[2].disabled =false; 
	theForm.elements[2].style.backgroundColor='#FFFFFF';	
	theForm.elements[4].disabled =false;
	theForm.elements[4].style.backgroundColor='#FFFFFF';
	theForm.elements[5].disabled =false;
	theForm.elements[5].style.backgroundColor='#FFFFFF';
	theForm.elements[10].disabled =false;
	theForm.elements[10].style.backgroundColor='#FFFFFF';
	theForm.elements[32].disabled =false;
	theForm.elements[32].style.backgroundColor='#FFFFFF';
	theForm.elements[33].disabled =false;
	theForm.elements[33].style.backgroundColor='#FFFFFF';
	theForm.elements[34].disabled =false;
	theForm.elements[34].style.backgroundColor='#FFFFFF';
	theForm.elements[35].disabled =false;
	theForm.elements[35].style.backgroundColor='#FFFFFF';
	theForm.elements[36].disabled =false;
	theForm.elements[36].style.backgroundColor='#FFFFFF';
	theForm.elements[37].disabled =false;
	theForm.elements[37].style.backgroundColor='#FFFFFF';
	theForm.elements[38].disabled =false;
	theForm.elements[38].style.backgroundColor='#FFFFFF';
   }else{
	theForm.elements[1].disabled =false;
	theForm.elements[1].style.backgroundColor='#FFFFFF';
	//----------panalpina
	theForm.elements[3].disabled =false;
	theForm.elements[3].style.backgroundColor='#FFFFFF';	
	///----------------------
	theForm.elements[6].disabled =false;
	theForm.elements[6].style.backgroundColor='#FFFFFF';
	//----------panalpina
	theForm.elements[7].disabled =false;
	theForm.elements[7].style.backgroundColor='#FFFFFF';
	//---------------------------------------
	theForm.elements[8].disabled =false;
	theForm.elements[8].style.backgroundColor='#FFFFFF';
	theForm.elements[9].disabled =false;
	theForm.elements[9].style.backgroundColor='#FFFFFF';
	theForm.elements[12].disabled =false;
	theForm.elements[12].style.backgroundColor='#FFFFFF';
	theForm.elements[13].disabled =false;
	theForm.elements[13].style.backgroundColor='#FFFFFF';
	theForm.elements[15].disabled =false;
	theForm.elements[15].style.backgroundColor='#FFFFFF';
	theForm.elements[16].disabled =false;
	theForm.elements[16].style.backgroundColor='#FFFFFF';
	theForm.elements[17].disabled =false;
	theForm.elements[17].style.backgroundColor='#FFFFFF';
	theForm.elements[18].disabled =false;
	theForm.elements[18].style.backgroundColor='#FFFFFF';
	theForm.elements[19].disabled =false;
	theForm.elements[19].style.backgroundColor='#FFFFFF';
	theForm.elements[20].disabled =false;
	theForm.elements[20].style.backgroundColor='#FFFFFF';
	theForm.elements[21].disabled =false;
	theForm.elements[21].style.backgroundColor='#FFFFFF';
	theForm.elements[22].disabled =false;
	theForm.elements[22].style.backgroundColor='#FFFFFF';
	theForm.elements[23].disabled =false;
	theForm.elements[23].style.backgroundColor='#FFFFFF';
	theForm.elements[24].disabled =false;
	theForm.elements[24].style.backgroundColor='#FFFFFF';
	theForm.elements[28].disabled =false;
	theForm.elements[28].style.backgroundColor='#FFFFFF';
	theForm.elements[29].disabled =false;
	theForm.elements[29].style.backgroundColor='#FFFFFF';
	theForm.elements[30].disabled =false;
	theForm.elements[30].style.backgroundColor='#FFFFFF';
	theForm.elements[37].disabled =false;
	theForm.elements[37].style.backgroundColor='#FFFFFF';///edita comentario	
	theForm.elements[39].disabled =false;
	theForm.elements[39].style.backgroundColor='#FFFFFF';
	theForm.elements[40].disabled =false;
	theForm.elements[40].style.backgroundColor='#FFFFFF';	
   }
   
 }
 function allCheck(v)
 {
	if(v==1)
	{
	  for( var i=2;i<42;i++)
	  {
		  document.frm.elements[i].checked=true;
	  }
	  document.getElementById('asignar').value=',filenum,shipnum,coornam,poname,proline,numefac,portori,porting,incoter,forwnam,findest,modtran,guianum,carrnam,numpiec,chaweig,desitem,custbro,custent,impocif,currimp,impduty,currcus,imporeg,dpreale,ddocuse,adarriv,dbrosub,dcuscla,dcarrec,eta,temexpi,issues,adddeil,forceme,imprlea,commen,attachm,etd,ata';
	}else{
	  for( var i=2;i<42;i++)
	  {
		  document.frm.elements[i].checked=false;
	  }	
	  document.getElementById('asignar').value='';
	}
 }
//--------------------------------------------------------------------VALIDO PARA INTRANET
function logIntra()
{
	document.getElementById('divLogIntra').style.display='block';
	document.getElementById('divLogIntra').style.top=findPosY(document.getElementById('intranet'))+28+'px';
	document.getElementById('divLogIntra').style.left=findPosX(document.getElementById('intranet'))-125+'px';
	var logui="<table bgcolor=#006020><tr><td colspan=2>&nbsp;</td></tr>";
	    logui=logui+"<tr><td style=color:#FFFFFF>Usuario</td><td><input type=text id=usri name=usri size=19></td></tr><tr><td style=color:#FFFFFF>Clave</td><td><input type=password id=pwdi name=pwdi></td></tr>";
		logui=logui+"<tr><td colspan=2 align=center><button type=button style=background-color:#0052A4;color:#FFFFFF id=enter name=enter onClick=CompCampIntra(document.getElementById('usri').value,document.getElementById('pwdi').value);>Ingresar</button><button type=button style=background-color:#0052A4;color:#FFFFFF id=cerr name=cerr onClick=document.getElementById('divLogIntra').innerHTML='';>&nbsp;Cerrar&nbsp;</button></td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr>";
		logui=logui+"<tr><td colspan=2>&nbsp;</td></tr></table>";
	document.getElementById('divLogIntra').innerHTML=logui;
}
//------------
function CompCampIntra(user,pwd)
{
	if(user=='')
	{
		alert('Ingrese Usuario');
		document.getElementById('usri').focus();
	}else if(pwd=='')
	{
		alert('Ingrese Clave');
		document.getElementById('pwdi').focus();
	}
	else
	{
		validaIntra(user,pwd);
	}
}
//----------------------
function validaIntra(user,pwd)
{	
	var ajax=nuevoAjax();
	param="user="+user+"&pwd="+pwd;
	ajax.open("POST","BAKER/proc/validaIntra.php?", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(param);//alert(param);
	ajax.onreadystatechange=function()
	{	
		if (ajax.readyState==4)
		{
				//alert(ajax.responseText);
				var rs=ajax.responseText;
				if(rs!='NO')
				{
				  location.href=rs;
				}else alert('Usuario no existe');				
		}
	}	
}
