// JavaScript Documentvar vStrMsjOk="(*)";
var vMensajeOk="*";
var vMensajeEr1="Req";
var vMensajeEr2="Formato incorrecto";

function acumulaComent(pAcum,pValor)
{	if(pAcum!="")
		pAcum=pAcum+", ";
	pAcum=pAcum+pValor;
	return pAcum;
}
function mostrarMensaje(pPref,pCampo,pMensaje)
{	if(pPref!="")
		document.getElementById(pPref+pCampo).innerHTML=pMensaje;
}
//pCapaAlerta----> Capa de alerta
//pCapaCarga-----> Capa donde cargara Ajax
//pTipoEnvio-----> 1 POST, 2 GET, 3 form.submit
//pTipoCarga-----> Tipo de carga Ajax
//pTinPosicionar-> Posiciona? si / no
//pPosicionado --> Posición a donde te retorne el error
function valSimpleAjx1(pStrMsj,pForm,pCapaAlerta,pCapaCarga,pTipoEnvio,pTipoCarga,pLinkEnlace,pIntVertical)
{	var accum="";
	var varCmpClass="";
	var varCmpType="";
	var varCmpName="";
	var varEnlace="";
	var varCmpAlt="";
	var varAuxFile1="";
	var varAuxFile2="";
	var frm=eval('document.'+pForm);
	var frmTxt="document."+pForm;
	var parPost="";
	var total=0;
	
	var arrAsinc = new Array();
	var accAsinc = 0;
	var varIntError=0;
	
	for (i=0;i<frm.elements.length;i++)
	{	varCmpClass=frm.elements[i].className;
		varCmpType=frm.elements[i].type;
		varCmpName=frm.elements[i].name;
		varCmpAlt=frm.elements[i].alt;
		
		if(varIntError>0)
			varIntError=0;
		
		if(varCmpName==undefined){
			varCmpName='';
		}else{
			if(varCmpName=="txtSv")
			{	varEnlace=frm.elements[i].value;	}
			else
			{	if(parseInt(varCmpName.indexOf('noenviar'))>0)
				{	arrAsinc[accAsinc]=frm.elements[i].value;
					accAsinc=accAsinc+1;
				}
				else
				{	if(parPost!="")
						parPost=parPost+"&";
					if(varCmpType=="radio")
						parPost=parPost+varCmpName+"=";
					else
						parPost=parPost+varCmpName+"="+frm.elements[i].value;
				}
			}
			if(parseInt(varCmpClass.indexOf('req'))>0)
			{	switch(varCmpType)
				{	case "select-one":	
									varCmpType=varCmpType.replace("-one","");
									if((frm.elements[i].value=="")||(frm.elements[i].value=="0")||(frm.elements[i].value=="n"))
									{	accum=acumulaComent(accum,frm.elements[i].title);
										varIntError=varIntError+1;
									}
									break;
					case "file":	varAuxFile1=parseInt(i)-1;
									varAuxFile1=frm.elements[varAuxFile1].value;
									if((varAuxFile1=="")&&(frm.elements[i].value==""))
									{	//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
										accum=acumulaComent(accum,varCmpAlt);
										varIntError=varIntError+1;
									}else{
										varAuxFile2=varCmpName+"lib";
										varAuxFile2=eval(frmTxt+'.'+varAuxFile2+'.value');
										varAuxFile2=varAuxFile2.split(",");
										if(frm.elements[i].value!="")
										{	adres1 = frm.elements[i].value;
											for(j=0;j<parseInt(varAuxFile2.length);j++)
											{	if(j==0)
												{	index1 = adres1.indexOf("."+varAuxFile2[j]);	}
												else
												{	index1 = index1 + adres1.indexOf("."+varAuxFile2[j]);	}
											}
											//Si no es del formato establecido
											if (index1 == eval("-"+varAuxFile2.length))
											{	//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr2);
												accum=acumulaComent(accum,varCmpAlt+": formato incorrecto");
												varIntError=varIntError+1;
											}
										}
									}
									break;
					case "radio":	total=0;
									varAuxFile1=eval(frmTxt+'.'+varCmpName+'.length');
									varAuxFile2=0;
									for ( var j = 0; j < eval(frmTxt+'.'+varCmpName+'.length'); j++ )
									{	if(eval(frmTxt+'.'+varCmpName+'['+j+'].checked')) 
										{	total=parseInt(total)+1;
											varAuxFile2=eval(frmTxt+'.'+varCmpName+'['+j+'].value');
										}
									}
									alert(frmTxt+'.'+varCmpName+'.length');
									if(total=="0")
									{	mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
										accum=acumulaComent(accum,varCmpAlt);
									}
									parPost=parPost+varAuxFile2;
									i=parseInt(j)+parseInt(i)-1;
									break;
					case "checkbox":total=0;
									if(parseInt(varCmpName.indexOf('[]'))>0)
										varCmpName=varCmpName.replace('[]','');
									if(varAuxFile2!=varCmpName){
										varAuxFile1=eval(frmTxt+'.'+varCmpName+'.length');
										if(varAuxFile1<=1)
										{	if (!frm.elements[i].checked){//Elemento type=checkbox 
												//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
												accum=acumulaComent(accum,varCmpAlt);
											}
										}else{
											if(eval(frmTxt+'.'+varCmpName+'.length'))
											{	for ( var j = 0; j < eval(frmTxt+'.'+varCmpName+'.length'); j++ )
												{	if(eval(frmTxt+'.'+varCmpName+'['+j+'].checked')) 
													{	total=parseInt(total)+1;	}
												}
											}else{
												if(eval(frmTxt+'.'+varCmpName+'.checked')) 
												{	total=parseInt(total)+1;	}
											}
											varAuxFile1='';
											if(parseInt(varCmpClass.indexOf('chkGrupo'))>0)
												varAuxFile1=frm.elements[i].title;
											if(total=="0")
											{	//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
												accum=acumulaComent(accum,varCmpAlt);
												if(varAuxFile1!="")
													document.getElementById(varAuxFile1).className='boxEr';
											}else{
												if(varAuxFile1!="")
													document.getElementById(varAuxFile1).className='box';
											}
											i=parseInt(j)+parseInt(i)-1;
											varAuxFile2=varCmpName;
										}
									}
									break;
					default:		if(frm.elements[i].value=="")
									{	//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
										if(varCmpType=="textarea")
											varCmpAlt=frm.elements[i].title;
										accum=acumulaComent(accum,varCmpAlt);
										varIntError=varIntError+1;
									}
									break;
				}
			}
			if(parseInt(varCmpClass.indexOf('compar'))>0)
			{	varAuxFile1=eval(frmTxt+'.'+varCmpName+'compar');
				if(frm.elements[i].value!=varAuxFile1.value)
				{	frm.elements[i].className=varCmpType+'Er req compar';
					varAuxFile1.className=varCmpType+'Er req';
					varAuxFile2=eval(frmTxt+'.'+varCmpName+'comparLib').value;
					mostrarMensaje(pStrMsj,varCmpName,vMensajeEr1);
					accum=acumulaComent(accum,varAuxFile2);
				}
				else
				{	varAuxFile1.className=varCmpType+' req';
					mostrarMensaje(pStrMsj,varCmpName,vMensajeOk);
				}
			}
			if(parseInt(varCmpClass.indexOf('err'))>0)
			{	switch(varCmpType)
				{	case "text":	break;
					case "textarea":break;
					case "select-one":	break;
					case "file":	varAuxFile2=varCmpName+"lib";
									varAuxFile2=eval(frmTxt+'.'+varAuxFile2+'.value');
									varAuxFile2=varAuxFile2.split(",");
									if(frm.elements[i].value!="")
									{	adres1 = frm.elements[i].value;
										for(j=0;j<parseInt(varAuxFile2.length);j++)
										{	if(j==0)
											{	index1 = adres1.indexOf("."+varAuxFile2[j]);	}
											else
											{	index1 = index1 + adres1.indexOf("."+varAuxFile2[j]);	}
										}
										if (index1 == eval("-"+varAuxFile2.length))
										{	//frm.elements[i].className=varCmpType+'Er req';
											//mostrarMensaje(pStrMsj,varCmpName,vMensajeEr2);
											accum=acumulaComent(accum,varCmpAlt);
											varIntError=varIntError+1;
										}
									}
									break;
				}
			}
			if(parseInt(varCmpClass.indexOf('num'))>0)
			{	if(frm.elements[i].value!="")
				{	if(!valNumeros(frm.elements[i].value))
					{	accum=acumulaComent(accum,varCmpAlt+": numero valido");
						varIntError=varIntError+1;
					}
				}
			}
			if(parseInt(varCmpClass.indexOf('mail'))>0)
			{	if(frm.elements[i].value!="")
				{	if(!valMail(frm.elements[i].value))
					{	accum=acumulaComent(accum," email v&aacute;lido");
						varIntError=varIntError+1;
					}
				}
			}
			if((varCmpType!="radio")&&(varCmpType!="checkbox"))
			{	varCmpClass=varCmpClass.replace("Er","");
				if(varIntError>0){//ERROR
					varCmpClass=varCmpClass.replace(varCmpType,varCmpType+"Er");
				}
				frm.elements[i].className=varCmpClass;
			}
		}
	}
	if(accum!="")
	{	if((pIntVertical!="")&&(pIntVertical!="0"))
			window.scrollTo(0,pIntVertical);
		document.getElementById(pCapaAlerta).className="alerta1";
		document.getElementById(pCapaAlerta).innerHTML="Ingrese: <strong>"+accum+"</strong>";
		return;
	}
	else
	{	document.getElementById(pCapaAlerta).className="alerta2";
		document.getElementById(pCapaAlerta).innerHTML="<img src='images/loading.gif' style='float:left; margin:0 0 0 5px'> Loading<br clear='all' />";
		if(pTipoEnvio=="1"){
			recibeid2(varEnlace,"",parPost,pCapaCarga,1,pTipoCarga,pLinkEnlace);}
		else
		{	if(pTipoEnvio=="2"){
				recibeid2(varEnlace,parPost,"",pCapaCarga,1,pTipoCarga,pLinkEnlace);
			}else{
				frm.action=varEnlace;
				frm.submit();
			}
		}
		for(i=0;i<accAsinc;i++)
		{	setTimeout (arrAsinc[i], 1500);	}
	}
}

function valMail(parTexto)
{	var Template = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; //Formato de direccion de correo electronico
	if(parTexto!="") 
	{	if (Template.test(parTexto)) 
		{	return true; 
		}
		else
		{	return false;
		}		
	}else{
		return true;
	}
}

function valNumeros(parNumero)
{	var Template = /^[0-9]+$/i //Formato de alfanumerico	
	if(parNumero!="") 
	{	if (Template.test(parNumero)) 
		{	return true; 
		}
		else
		{	return false;
		}	
	}else{
		return true;
	}
}

function cambiarReq(pValor)
{	var pTot=document.getElementById('totalReq').value;
	var pVal='';
	for(var i=0;i<pTot;i++){
		pVal=document.getElementById('requeridos'+i).value;
		pVal=pVal.split('/');
		if(pValor==0){
			document.getElementById(pVal[0]).className=pVal[1]+" req";
			document.getElementById("cel_"+pVal[0]).innerHTML='(*)';
		}else{
			document.getElementById(pVal[0]).className=pVal[1];
			document.getElementById("cel_"+pVal[0]).innerHTML='';
		}
	}
}


//Borra contenido de formulario
function borrarForm1(pForm)
{	document.getElementById(pForm).reset();
}
function borrarForm2(pForm)
{	pForm=eval("document."+pForm);
	pForm.reset();
}

function valInscripcion(pIntIdIdioma,pValor1,pValor2)
{	var accum='';
	var cabeza='';
	if((document.getElementById('txtInsNombre').value==pValor1)||(document.getElementById('txtInsNombre').value==""))
		accum=document.getElementById('txtInsNombre').alt;
	if((document.getElementById('txtInsEmail').value==pValor2)||(document.getElementById('txtInsEmail').value=="")){
		if(accum!="")
			accum=accum+", ";
		accum=accum+document.getElementById('txtInsEmail').alt;
	}
	if(accum!='')
	{	if(pIntIdIdioma==1)
			cabeza="Ingrese: ";
		else
			cabeza="Enter: ";
		document.getElementById('alerta').innerHTML='<div class="alerta1">'+cabeza+accum+'</div>';
		return;
	}else{
		valSimpleAjx1('','frmInsc','alerta','lay_suscripcion',1,1,'',0);
	}
}

function cargarDocs(pItTit,pItVal){
	recibeid("documento.php",pItTit+"="+pItVal,"","lay_doc",1,1);
}
