function ResetForm()
{
	mTema = document.getElementsByName("xtem").value;
	mSerie = document.getElementsByName("xser").value;
	mSigla = document.getElementsByName("xcoa").value;
    document.frmCentral.reset();
    PreSelect('tem', "T"+document.getElementsByName("xtem").value)
    PreSelect('ser', "R"+document.getElementsByName("xser").value)
    PreSelect('coa', "S"+document.getElementsByName("xcoa").value)
}

function PostForm(theURL)
{
    if (!(TestForm()))
	return;
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    document.frmCentral.submit();
}

function PostFormPag(theURL)
{
    mNroPag = document.getElementsByName("NroPag").value
    ResetForm();
    document.getElementsByName("NroPag").value = mNroPag
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    document.frmCentral.submit();
}


function SetAndPostPag(theURL, mVar, mVal)
{
    ResetForm();
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.getElementsByName(mVar);
    if (Tmp!=null)
  	  document.getElementsByName(mVar).value = mVal;
    document.frmCentral.submit();
}

function SetAndPost(theURL, mVar, mVal)
{
    if (mVar != "HIDNOR")
	    if (!(TestForm()))
			return;
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.getElementsByName(mVar);
    if (Tmp!=null)
  	  document.getElementsByName(mVar).value = mVal;
    document.frmCentral.submit();
}

function SetAndPostPag2(theURL, mVar, mVal)
{
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.getElementsByName(mVar);
    if (Tmp!=null)
  	  document.getElementsByName(mVar).value = mVal;
    document.frmCentral.submit();
}

function SetAndPost2(theURL, mVar, mVal)
{
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.getElementsByName(mVar);
    if (Tmp!=null)
  	  document.getElementsByName(mVar).value = mVal;
    document.frmCentral.submit();
}


function ToggleDisplay(Nombre, Nombre2)
{	
	mEl = document.all[Nombre];
	if (mEl.style.display == "none"){
		document.all[Nombre2].innerHTML = "Ocultar Buscador";
		mEl.style.display = "block" ;}
	else{
		mEl.style.display = "none";
		document.all[Nombre2].innerHTML = "Mostrar Buscador";
		}

}

function PreSelect(mnVar, mVal)
{
	var combo = document.getElementById(mnVar)[0];
	var cod = mVal;
	for (i=0; i<(combo.options.length); i++)
	{
		valor = combo.options[i].value.indexOf(",");
		if (valor == -1)
			{codigo = combo.options[i].value}
		else
			{codigo = combo.options[i].value.substring(0,(valor))}
		if (codigo == cod)
		{
			combo.selectedIndex = i;
			break
		}
	}
}

/*function PreSelect(mnVar, mVal)
{
	var mVar = document.getElementsByName(mnVar)[0];
	if (mVal.length > 0)
		mVar.options[mVal].selected = true;
}*/

function NewWindow(URL)
{
	window.open(URL, "", "top=0,left=0");
}



String.prototype.trim = trim_string;

function trim_string() {
     var ichar, icount;
     var strValue = this;
     ichar = strValue.length - 1;
     icount = -1;
     while (strValue.charAt(ichar)==' ' && ichar > icount)
         --ichar;
     if (ichar!=(strValue.length-1))
         strValue = strValue.slice(0,ichar+1);
     ichar = 0;
     icount = strValue.length - 1;
     while (strValue.charAt(ichar)==' ' && ichar < icount)
         ++ichar;
     if (ichar!=0)
         strValue = strValue.slice(ichar,strValue.length);
     return strValue;
 }

function MatchPattern(mVal, mPattern){
	Re = new RegExp(mPattern);
	if (Re.test(mVal)) {
		return 0;
	}
	return 1;
}

 function TAnos(mDAno, mHAno) {
	 mDAno = mDAno.trim();
	 mHAno = mHAno.trim();
	 if ((mDAno.length==0) && (mHAno.length==0))
		 return true;
	 mError = 0;
	 mError = MatchPattern(mDAno, "^\\d{4}$");
	 mError = mError + MatchPattern(mHAno, "^\\d{4}$");
	 if (mError > 0) {
		 window.alert("El formato de los años es incorrecto");
		 return false;
	 }
	 if ((mDAno > mHAno) || (mDAno > "2050") || (mDAno < "1935")){
		 window.alert("Campo Desde Año debe estar en el rango 1935-2050. Y debe ser menor al campo Hasta Año.");
		 mError = 1;
		 }
	 if ((mHAno > "2050") || (mHAno < "1935")) {
		 window.alert("Campo Hasta Año debe estar en el rango 1935-2050.");
		 mError = 1;
		 }
	 return (mError == 0);
 }

function TNumero(mVal) {
	mVal = mVal.trim();
	if (mVal.length==0)
		return true;
	mError = 0;
	mError = MatchPattern(mVal, "^\\d{1,8}\\**$");
	return (mError == 0);
}

function TLista(mVal) {
	mVal = mVal.trim();
	if (mVal.length==0)
		return true;
	mError = 0;
	mError = MatchPattern(mVal, "^(\\d{2}(.\\d{3}(.\\d{2})?)?){1,1}(,\\d{2}(.\\d{3}(.\\d{2})?)?){0,}$");
	return (mError == 0);
}

function TPal(mVal) {
	mVal = mVal.trim();
	if (mVal.length==0)
		return true;
	mError = 0;
	mError = MatchPattern(mVal, "^[0-9A-Za-z @_.,;:ñÑáéíóúÁÉÍÓÚÜü]+$");
	return (mError == 0);
}
function TestForm() {

	if (!(TAnos(document.getElementById("VIN").innerHTML,document.getElementById("VFI").innerHTML)))
		return false;
	if (!(TNumero(document.getElementById("num").innerHTML))){
		window.alert("Número");
		return false;
	}

	if (!(TLista(document.getElementById("ICS").innerHTML))){
		window.alert("ICS");
		return false;
	}
	if (!(TPal(document.getElementById("pa11").innerHTML))){
		window.alert("Palabra11");
		return false;
	}
	if (!(TPal(document.getElementById("pa12").innerHTML))){
		window.alert("Palabra12");
		return false;
	}
	if (!(TPal(document.getElementById("pa21").innerHTML))){
		window.alert("Palabra21");
		return false;
	}
	if (!(TPal(document.getElementById("pa22").innerHTML))){
		window.alert("Palabra22");
		return false;
	}
	return true;
}
/*
function TestForm() {

	if (!(TAnos(document.getElementsByName("VIN").value,document.getElementsByName("VFI").value)))
		return false;
	if (!(TNumero(document.getElementsByName("num").value))){
		window.alert("Número");
		return false;
	}

	if (!(TLista(document.getElementsByName("ICS").value))){
		window.alert("ICS");
		return false;
	}
	if (!(TPal(document.getElementsByName("pa11").value))){
		window.alert("Palabra11");
		return false;
	}
	if (!(TPal(document.getElementsByName("pa12").value))){
		window.alert("Palabra12");
		return false;
	}
	if (!(TPal(document.getElementsByName("pa21").value))){
		window.alert("Palabra21");
		return false;
	}
	if (!(TPal(document.getElementsByName("pa22").value))){
		window.alert("Palabra22");
		return false;
	}
	return true;
}
function TestForm() {
	if (!(TAnos(document.all ("VIN").value,document.all ("VFI").value)))
		return false;
	if (!(TNumero(document.all ("num").value))){
		window.alert("Número");
		return false;
	}

	if (!(TLista(document.all ("ics").value))){
		window.alert("ICS");
		return false;
	}
	if (!(TPal(document.all ("pa11").value))){
		window.alert("Palabra11");
		return false;
	}
	if (!(TPal(document.all ("pa12").value))){
		window.alert("Palabra12");
		return false;
	}
	if (!(TPal(document.all ("pa21").value))){
		window.alert("Palabra21");
		return false;
	}
	if (!(TPal(document.all ("pa22").value))){
		window.alert("Palabra22");
		return false;
	}
	return true;
}*/

function post(theURL)
{
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    document.frmCentral.submit();
}

