﻿function getUbigeo() {
  mywin = open("rda_getubigeo.aspx", "titulo","HEIGHT=160,WIDTH=450");
}

function chUbigeo(x,y,z) {
   document.form1.hdUbigeo.value=y;
   var arr = x.split("\\");
   document.form1.txtDistrito.value=arr[2];
   document.form1.txtProvincia.value=arr[1];
   document.form1.txtDepartamento.value=arr[0];     
}

function validar()
{
	Msg_txtEmpresa = "La Razon Social es un campo obligatorio";
	Msg_txtRUC = "El RUC es un campo obligatorio";
	Msg_Marca = "El nombre o razón social es un campo obligatorio";
	
	Msg_Direcion = "La dirección es un campo obligatorio";
	Msg_Ciudad = "La ciudad es un campo obligatorio";
	Msg_Estado = "El Estado/Provincia es un campo obligatorio";
	Msg_Pais = "El país es un campo obligatorio";
	Msg_CodigoPostal = "El codigo postal es un campo obligatorio";
	
	//Contacto 1
	Msg_Nombres = "El nombre del representante es obligatorio";
	Msg_Apellidos = "El apellido del representante es obligatorio";
	Msg_Cargo = "El cargo del representante es obligatorio";	
	Msg_txtTelefono01 = "El Teléfono1 es un campo obligatorio";
	Msg_Celular01 = "El celular del representante es obligatorio";
	Msg_txtFax01 = "El Fax es un campo obligatorio";
	Msg_txtEmail01 = "El email del representante es obligatorio";
	//end Contacto 1
	
	//Contacto 2
	Msg_txtContacto02 = "El nombre del responsable de coordinación es obligatorio";
	Msg_txtCargo02 = "El cargo del responsable de coordinación es obligatorio";
	Msg_txtTelefono02 = "El Teléfono2 del responsable obligatorio";
	Msg_txtCMovil2 = "El celular del responsable de coordinación es obligatorio";
	Msg_txtEmail02 = "El email del responsable de coordinación es obligatorio";	
	//end Contacto 2
	
	
	if (document.form1.txtEmpresa.value=="") {
		alert(Msg_txtEmpresa);
		document.form1.txtEmpresa.focus();
		return false;
	}
	if (document.form1.txtRUC.value=="") {
		alert(Msg_txtRUC);
		document.form1.txtRUC.focus();
		return false;
	}	
	if(document.form1.txtNomComercial.value==""){
	    alert(Msg_Marca);
	    document.form1.txtNomComercial.focus();
	    return false;
	}
		
	if(document.form1.txtDireccion.value==""){
	    alert(Msg_Direcion);
	    document.form1.txtDireccion.focus();
	    return false;
	}
	
	if(document.form1.txtDistrito.value==""){
	    alert(Msg_Ciudad);
	    document.form1.txtDistrito.focus();
	    return false;
	}
	
	if(document.form1.txtProvincia.value==""){
	    alert(Msg_Estado);
	    document.form1.txtProvincia.focus();
	    return false;
	}
	
	
	if(document.form1.txtPais.value==""){
	    alert(Msg_Pais);
	    document.form1.txtPais.focus();
	    return false;
	}
	
	
	if(document.form1.txtCodigoPostal.value==""){
	    alert(Msg_CodigoPostal);
	    document.form1.txtCodigoPostal.focus();
	    return false;
	}
	
	
	if(document.form1.txtEmpRPNombre.value==""){
	    alert(Msg_Nombres);
	    document.form1.txtEmpRPNombre.focus();
	    return false;
	}
	
	
	if(document.form1.txtEmpRPApellido.value==""){
	    alert(Msg_Apellidos);
	    document.form1.txtEmpRPApellido.focus();
	    return false;
	}
	
	if(document.form1.txtEmpRPCargo.value==""){
	    alert(Msg_Cargo);
	    document.form1.txtEmpRPCargo.focus();
	    return false;
	}
	
	    

	if (document.form1.txtEmpRPTelefono.value=="") {
		alert(Msg_txtTelefono01);
		document.form1.txtEmpRPTelefono.focus();
		return false;
	}
	
	if (document.form1.txtEmpRPCelular.value=="") {
		alert(Msg_Celular01);
		document.form1.txtEmpRPCelular.focus();
		return false;
	}

	if (document.form1.txtEmpRPfax.value=="") {
		alert(Msg_txtFax01);
		document.form1.txtEmpRPfax.focus();
		return false;
	}
	
	if (document.form1.txtEmpRPemail.value=="") {
		alert(Msg_txtEmail01);
		document.form1.txtEmpRPemail.focus();
		return false;
	}

//END CONTACTO 1	


//INICIO CONTACTO 2
if (document.form1.txtEmpPANombre.value=="") {
		alert(Msg_txtContacto02);
		document.form1.txtEmpPANombre.focus();
		return false;
	}
	
	if (document.form1.txtEmpPACargo.value=="") {
		alert(Msg_txtCargo02);
		document.form1.txtEmpPACargo.focus();
		return false;
	}
	
	if (document.form1.txtEmpPATelefono.value=="") {
		alert(Msg_txtTelefono02);
		document.form1.txtEmpPATelefono.focus();
		return false;
	}
	
	
	if (document.form1.txtEmpPACelular.value=="") {
		alert(Msg_txtCMovil2);
		document.form1.txtEmpPACelular.focus();
		return false;
	}	
	
	if (document.form1.txtEmpPAemail.value=="") {
		alert(Msg_txtEmail02);
		document.form1.txtEmpPAemail.focus();
		return false;
	}
	
//end contacto 2

	return true;
}

function grabar()
{
	if (validar()==false) {
		return false;
	}
	
	r = confirm("Esta seguro de grabar los datos?");
	if (r==true) {

        crossPagePost('RegistroFin.aspx');
		return true;
	}
}

function crossPagePost(formAction)
{
 var formElementsArray = document.getElementsByTagName('FORM');
 
 if ( formElementsArray != null )
 {
  var formElement = formElementsArray[0];

  document.getElementById('__VIEWSTATE').name = 'NOVIEWSTATE';

  formElement.action = formAction;
  formElement.submit();
 }
}

function CortarCaracteres(poText, poTxtCount, nCars) {
	if (poText.value.length > nCars) {
		poText.value = poText.value.substring(0,nCars);
	}
	ContarCaracteres(poText, poTxtCount);
}

function ContarCaracteres(poText, poTxtCount) {
		document.getElementById(poTxtCount).innerHTML=poText.value.length;
}

