function ResetForm()
{
    mTema = document.frmCentral.all("xtem").value
    mSerie = document.frmCentral.all("xser").value
    mSigla = document.frmCentral.all("xcoa").value
    document.frmCentral.reset();
    PreSelect("tem", "T"+document.frmCentral.all("xtem").value)
    PreSelect("ser", "R"+document.frmCentral.all("xser").value)
    PreSelect("coa", "S"+document.frmCentral.all("xcoa").value)
}

function PostForm(theURL)
{
    if (!(TestForm()))
	return;
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    document.frmCentral.submit();
}

function PostFormPag(theURL)
{
    mNroPag = document.frmCentral.all("NroPag").value
    ResetForm();
    document.frmCentral.all("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.frmCentral.all(mVar);
    if (Tmp!=null)
  	  document.frmCentral.all(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.frmCentral.all(mVar);
    if (Tmp!=null)
  	  document.frmCentral.all(mVar).value = mVal;
    document.frmCentral.submit();
}

function SetAndPostPag2(theURL, mVar, mVal)
{
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.frmCentral.all(mVar);
    if (Tmp!=null)
  	  document.frmCentral.all(mVar).value = mVal;
    document.frmCentral.submit();
}

function SetAndPost2(theURL, mVar, mVal)
{
    document.frmCentral.method = "POST";
    document.frmCentral.action = theURL;
    Tmp = document.frmCentral.all(mVar);
    if (Tmp!=null)
  	  document.frmCentral.all(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 mVar = document.all[mnVar];
	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.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();
}
