/* General */
function borraForma(obj){obj.reset();}
function marcaError(pid,flag){
	if(!document.getElementById(pid)){document.write("<div id=\"marca_"+pid+"\"></div>");}
	if(flag!="0"){
		document.getElementById("marca_"+pid).innerHTML="<img src=\"/images/6.jpg\" title=\"error...\">";
	}else{
		document.getElementById("marca_"+pid).innerHTML="";
	}
}
function codeRefresh(dest){
	if(document.getElementById("usu_docnumero")){var usu_docnumero=document.getElementById("usu_docnumero").value;}else{var usu_docnumero="";}
	if(document.getElementById("usu_doctipo")){var usu_doctipo=document.getElementById("usu_doctipo").value;}else{var usu_doctipo="";}
	if(document.getElementById("usuEmail")){var usuEmail=document.getElementById("usuEmail").value;}else{var usuEmail="";}
	if(document.getElementById("remitir")){var bot=document.getElementById("remitir").disabled=true;}
	document.step1.action = dest;
	document.step1.pag.value = "";
	document.step1.submit();		      
  }
function registra_step1(obj){
	var textErr = "";
	var errCount = 0;
	var men = "";
	obj.remitir.disabled = true;
	if(obj.usuEmail.value==""){errCount+=1; men="No ha ingresado ninguna dirección de e-mail!\n"; textErr+="- "+men; marcaError("usuEmail","1");}else{marcaError("usuEmail","0");}
	if(obj.codigo.value.length!=5){errCount+=1; men="No ha ingresado el código de verificación exactamente como aparece en la imagen mostrada!\n"; textErr+="- "+men; marcaError("codigo","1");}else{marcaError("codigo","0");}
	if (textErr!=""){textErr =	"Hay " + errCount + " errores u omisiones en el formulario de registro que desea remitir:\n"+
								"\n"+textErr;alert(textErr);obj.remitir.disabled=false;return (false);
	}	
}  
function showCheckBox(controlName,controlValor,valorOn){
	if(valorOn==null){valorOn="-1";}
	var html="<input style=\"border:none;background-color:transparent;\" type=\"checkbox\" id=\""+controlName+"\" name=\""+controlName+"\" value=\""+valorOn+"\"";
	if(valorOn==controlValor){html+="checked>";}else{html+=">";}
	document.write(html);
}
function showRadio(controlName,retValue,defValue){
	if(retValue==null){retValue="";}
	if(defValue==null){defValue=="";}
	var html="<input type=\"radio\" name=\""+controlName+"\" id=\""+controlName+"\" value=\""+defValue+"\" ";
	if(retValue==defValue){html+="checked >";}else{html+=">";}
	document.write(html);
}
function showDD(controlName,arrayObj,retValue,widthValue){
  if(retValue==null){retValue="";}
  if(widthValue==null){widthValue="";}else{widthValue=" style=\"width:"+widthValue+";\" ";}
  var html="<select"+widthValue+" class=\"inputText\" id=\""+controlName+"\" name=\""+controlName+"\" size=\"1\">";
  html+="<option value=\"\">- - -</option>";
  for(var i=0;i<arrayObj.length;i++){
  	html+="<option ";if(retValue==arrayObj[i][0]){html+="selected ";}
  	html+="value=\""+arrayObj[i][0]+"\">"+arrayObj[i][1]+"</option>";
  }
  html+="</select>";
  document.write(html);
}

function showCountries(controlName,arrayObj,retValue,widthValue){
  if(retValue==null){retValue="";}
  if(widthValue==null){widthValue="";}else{widthValue=" style=\"width:"+widthValue+";\" ";}
  var html="<select"+widthValue+" onchange=\"showUbigeo(this);\" class=\"inputText\" id=\""+controlName+"\" name=\""+controlName+"\" size=\"1\">";
  html+="<option value=\"\">- - -</option>";
  for(var i=0;i<arrayObj.length;i++){
  	html+="<option ";if(retValue==arrayObj[i][0]){html+="selected ";}
  	html+="value=\""+arrayObj[i][0]+"\">"+arrayObj[i][1]+"</option>";
  }
  html+="</select>";
  document.write(html);
}
function registra_step2(obj,objForm){
	var objValue = obj.value;
	var objTitle = obj.title;
	obj.value = "espere...";
	obj.title = "por favor espere unos segundo mientras se válida su registro...";
	obj.disabled = true;
	objForm.submit();
}
function showYears(controlName,retValue,iniYear,widthValue){
	if(retValue==null){retValue="";}
	if(widthValue==null){widthValue="";}
	var html="<select class=\"inputText\" id=\""+controlName+"\" name=\""+controlName+"\" size=\"1\">";
	html+="<option value=\"\">- - -</option>";
	for(var i=cYear;i>iniYear;i--){
		html+="<option ";if(retValue==i.toString()){html+="selected ";}
		html+="value=\""+i+"\">"+i+"</option>";
	}
	html+="</select>";
	document.write(html);html=null;
}
function showI(controlName,retValue,iniI,lastI,widthValue){
	if(retValue==null){retValue="";}
	if(widthValue==null){widthValue="";}
	var html="<select class=\"inputText\" id=\""+controlName+"\" name=\""+controlName+"\" size=\"1\">";
	html+="<option value=\"\">- - -</option>";
	for(var i=iniI;i<lastI;i++){
		html+="<option ";if(retValue==i.toString()){html+="selected ";}
		html+="value=\""+i+"\">"+i+"</option>";
	}
	html+="</select>";
	document.write(html);html=null;
}	
function showDepartamento(retValue){
	var html = "<select class=\"inputText\" style=\"width:98%;\" name=usu_departamento id=usu_departamento size=1 onchange=\"showProvincia();showDistrito();\">";
	html+="<option value=\"\">-- seleccione el departamento --</option>";
	for (var i=0;i<ubigeo.length;i++){
		if((ubigeo[i][1]=="00")&&(ubigeo[i][2]=="00")){
			html+="<option ";if(retValue==ubigeo[i][0]){html+="selected ";}
			html+="value=\""+ubigeo[i][0]+"\">"+ubigeo[i][3]+"</option>";
		}
	}
	html+="</select>";
	if(!document.getElementById("usu_departamento_div")){document.write("<div id=\"usu_departamento_div\"></div>");}
	document.getElementById("usu_departamento_div").innerHTML=html;html=null;
}
function showProvincia(retValue){
	cDepartamento = document.getElementById("usu_departamento").value;
	var html = "<select class=\"inputText\" style=\"width:98%;\" name=usu_provincia id=usu_provincia size=1 onchange=\"showDistrito();\">";
	html+="<option value=\"\">-- seleccione la provincia --</option>";
	for (var i=0;i<ubigeo.length;i++){
		if((ubigeo[i][0]==cDepartamento)&&(ubigeo[i][1]!="00")&&(ubigeo[i][2]=="00")){
			html+="<option ";if(retValue==ubigeo[i][1]){html+="selected ";}
			html+="value=\""+ubigeo[i][1]+"\">"+ubigeo[i][3]+"</option>";
		}
	}
	html+="</select>";
	if(!document.getElementById("usu_provincia_div")){document.write("<div id=\"usu_provincia_div\"></div>");}
	document.getElementById("usu_provincia_div").innerHTML=html;html=null;
}	
function showDistrito(retValue){
	cDepartamento = document.getElementById("usu_departamento").value;
	cProvincia = document.getElementById("usu_provincia").value;
	var html = "<select class=\"inputText\" style=\"width:98%;\" name=usu_distrito id=usu_distrito size=1>";
	html+="<option value=\"\">-- seleccione el distrito --</option>";
	for (var i=0;i<ubigeo.length;i++){
		if((ubigeo[i][0]==cDepartamento)&&(ubigeo[i][1]==cProvincia)&&(ubigeo[i][2]!="00")){
			html+="<option ";if(retValue==ubigeo[i][2]){html+="selected ";}
			html+="value=\""+ubigeo[i][2]+"\">"+ubigeo[i][3]+"</option>";
		}
	}
	html+="</select>";
	if(!document.getElementById("usu_distrito_div")){document.write("<div id=\"usu_distrito_div\"></div>");}
	document.getElementById("usu_distrito_div").innerHTML=html;html=null;
}	
function getSiNoT(controlNombre,retValue,toAdd){
	if(toAdd==null){toAdd="";}
	var sino = new Array(["Si","S"],["No","N"]);
	var html = "<select class=\"inputText\" name=\""+controlNombre+"\" size=1 "+toAdd+">";
	html+="<option value=\"\">- -</option>";
	for(var i=0;i<sino.length;i++){
		html+="<option ";
		if(retValue==sino[i][1]){html+="selected ";}
		html+="value=\""+sino[i][1]+"\">"+sino[i][0]+"</option>";
	}
	html+="</select>";
	document.write(html);html=null;
}
function getSiNo(controlNombre,retValue,toAdd){
	if(toAdd==null){toAdd="";}
	var sino = new Array(["Si","-1"],["No","0"]);
	var html = "<select class=\"inputText\" name=\""+controlNombre+"\" size=1 "+toAdd+">";
	for(var i=0;i<sino.length;i++){
		html+="<option ";
		if(retValue==sino[i][1]){html+="selected ";}
		html+="value=\""+sino[i][1]+"\">"+sino[i][0]+"</option>";
	}
	html+="</select>";
	document.write(html);html=null;
}
function showUbigeo(obj){
	var pais = obj.value.toUpperCase();
	if(pais=="PE"){
		if(document.getElementById("countryOthers")){document.getElementById("countryOthers").style.display="none";}
		if(document.getElementById("countryPeru")){document.getElementById("countryPeru").style.display="block";}
	}else{
		if(document.getElementById("countryOthers")){document.getElementById("countryOthers").style.display="block";}
		if(document.getElementById("countryPeru")){document.getElementById("countryPeru").style.display="none";}
	}
}
	
