function Registro(){
this.zip = ""
	this.pueblo = new Array();
	this.pueblo[0] =  [["ADJUNTAS"], ["00601"]];
	this.pueblo[1] =  [["AGUADA"], ["00602"]];
	this.pueblo[2] =  [["AGUADILLA"], ["00603", "00604", "00605"]];
	this.pueblo[3] =  [["AGUAS BUENAS"], ["00703"]];
	this.pueblo[4] =  [["AGUIRRE"], ["00704"]];
	this.pueblo[5] =  [["AIBONITO"], ["00705"]];
	this.pueblo[6] =  [["ANASCO"], ["00610"]];
	this.pueblo[7] =  [["ANGELES"], ["00611"]];
	this.pueblo[8] =  [["ARECIBO"], ["00612", "00613", "00614"]];
	this.pueblo[9] =  [["ARROYO"], ["00714"]];
	this.pueblo[10] = [["BAJADERO"], ["00616"]];
	this.pueblo[11] = [["BARCELONETA"], ["00617"]];
	this.pueblo[12] = [["BARRANQUITAS"], ["00794"]];
	this.pueblo[13] = [["BAYAMON"], ["00956", "00957", "00958", "00959", "00960", "00961"]];
	this.pueblo[14] = [["BOQUERON"], ["00622"]];
	this.pueblo[15] = [["CABO ROJO"], ["00623"]];
	this.pueblo[16] = [["CAGUAS"], ["00725", "00726", "00727"]];
	this.pueblo[17] = [["CAMUY"], ["00627"]];
	this.pueblo[18] = [["CANOVANAS"], ["00729"]];
	this.pueblo[19] = [["CAROLINA"], ["00979", "00981", "00982", "00983", "00984", "00985", "00986", "00987", "00988"]];
	this.pueblo[20] = [["CASTANER"], ["00631"]];
	this.pueblo[21] = [["CATANO"], ["00962", "00963"]];
	this.pueblo[22] = [["CAYEY"], ["00736", "00737"]];
	this.pueblo[23] = [["CEIBA"], ["00735"]];
	this.pueblo[24] = [["CIALES"], ["00638"]];
	this.pueblo[25] = [["CIDRA"], ["00739"]];
	this.pueblo[26] = [["COAMO"], ["00769"]];
	this.pueblo[27] = [["COMERIO"], ["00782"]];
	this.pueblo[28] = [["COROZAL"], ["00783"]];
	this.pueblo[29] = [["COTO LAUREL"], ["00780"]];
	this.pueblo[30] = [["CULEBRA"], ["00775"]];
	this.pueblo[31] = [["DORADO"], ["00646"]];
	this.pueblo[32] = [["ENSENADA"], ["00647"]];
	this.pueblo[33] = [["FAJARDO"], ["00738"]];
	this.pueblo[34] = [["FLORIDA"], ["00650"]];
	this.pueblo[35] = [["FORT BUCHANAN"], ["00934"]];
	this.pueblo[36] = [["GARROCHALES"], ["00652"]];
	this.pueblo[37] = [["GUANICA"], ["00653"]];
	this.pueblo[38] = [["GUAYAMA"], ["00784", "00785"]];
	this.pueblo[39] = [["GUAYANILLA"], ["00656"]];
	this.pueblo[40] = [["GUAYNABO"], ["00965", "00966", "00968", "00969", "00970", "00971"]];
	this.pueblo[41] = [["GURABO"], ["00778"]];
	this.pueblo[42] = [["HATILLO"], ["00659"]];
	this.pueblo[43] = [["HORMIGUEROS"], ["00660"]];
	this.pueblo[44] = [["HUMACAO"], ["00791", "00792"]];
	this.pueblo[45] = [["ISABELA"], ["00662"]];
	this.pueblo[46] = [["JAYUYA"], ["00664"]];
	this.pueblo[47] = [["JUANA DIAZ"], ["00795"]];
	this.pueblo[48] = [["JUNCOS"], ["00777"]];
	this.pueblo[49] = [["LA PLATA"], ["00786"]];
	this.pueblo[50] = [["LAJAS"], ["00667"]];
	this.pueblo[51] = [["LARES"], ["00669"]];
	this.pueblo[52] = [["LAS MARIAS"], ["00670"]];
	this.pueblo[53] = [["LAS PIEDRAS"], ["00771"]];
	this.pueblo[54] = [["LOIZA"], ["00772"]];
	this.pueblo[55] = [["LUQUILLO"], ["00773"]];
	this.pueblo[56] = [["MANATI"], ["00674"]];
	this.pueblo[57] = [["MARICAO"], ["00606"]];
	this.pueblo[58] = [["MAUNABO"], ["00707"]];
	this.pueblo[59] = [["MAYAGUEZ"], ["00680", "00681", "00682"]];
	this.pueblo[60] = [["MERCEDITA"], ["00715"]];
	this.pueblo[61] = [["MOCA"], ["00676"]];
	this.pueblo[62] = [["MOROVIS"], ["00687"]];
	this.pueblo[63] = [["NAGUABO"], ["00718"]];
	this.pueblo[64] = [["NARANJITO"], ["00719"]];
	this.pueblo[65] = [["OROCOVIS"], ["00720"]];
	this.pueblo[66] = [["PALMER"], ["00721"]];
	this.pueblo[67] = [["PATILLAS"], ["00723"]];
	this.pueblo[68] = [["PENUELAS"], ["00624"]];
	this.pueblo[69] = [["PONCE"], ["00716", "00717", "00728", "00730", "00731", "00732", "00733", "00734"]];
	this.pueblo[70] = [["PUERTO REAL"], ["00740"]];
	this.pueblo[71] = [["PUNTA SANTIAGO"], ["00741"]];
	this.pueblo[72] = [["QUEBRADILLAS"], ["00678"]];
	this.pueblo[73] = [["RINCON"], ["00677"]];
	this.pueblo[74] = [["RIO BLANCO"], ["00744"]];
	this.pueblo[75] = [["RIO GRANDE"], ["00745"]];
	this.pueblo[76] = [["ROOSEVELT ROADS"], ["00742"]];
	this.pueblo[77] = [["ROSARIO"], ["00636"]];
	this.pueblo[78] = [["SABANA GRANDE"], ["00637"]];
	this.pueblo[79] = [["SABANA HOYOS"], ["00688"]];
	this.pueblo[80] = [["SABANA SECA"], ["00952"]];
	this.pueblo[81] = [["SAINT JUST"], ["00978"]];
	this.pueblo[82] = [["SALINAS"], ["00751"]];
	this.pueblo[83] = [["SAN ANTONIO"], ["00690"]];
	this.pueblo[84] = [["SAN GERMAN"], ["00683"]];
	this.pueblo[85] = [["SAN JUAN"], ["00901", "00902", "00906", "00907", "00908", "00909", "00910", "00911", "00912", "00913", "00914", "00915", "00916", "00917", "00918", "00919", "00920", "00921", "00922", "00923", "00924", "00925", "00926", "00927", "00928", "00929", "00930", "00931", "00933", "00935", "00936", "00937", "00938", "00939", "00940", "00955", "00975"]];
	this.pueblo[86] = [["SAN LORENZO"], ["00754"]];
	this.pueblo[87] = [["SAN SEBASTIAN"], ["00685"]];
	this.pueblo[88] = [["SANTA ISABEL"], ["00757"]];
	this.pueblo[89] = [["TOA ALTA"], ["00953", "00954", "00949", "00950", "00951"]];
	this.pueblo[90] = [["TRUJILLO ALTO"], ["00976", "00977"]];
	this.pueblo[91] = [["UTUADO"], ["00641"]];
	this.pueblo[92] = [["VEGA ALTA"], ["00692"]];
	this.pueblo[93] = [["VEGA BAJA"], ["00693", "00694"]];
	this.pueblo[94] = [["VIEQUES"], ["00765"]];
	this.pueblo[95] = [["VILLALBA"], ["00766"]];
	this.pueblo[96] = [["YABUCOA"], ["00767"]];
	this.pueblo[97] = [["YAUCO"], ["00698"]];
	
}





Registro.prototype.add_pueblos = function($selPueblo, $selZip){
	
	document.getElementById("pueblo").value = this.pueblo[0][0][0]
	
	var idPueblo = 0;
	
	for(var i=0; i<this.pueblo.length; i++){

		var $sel = "";
		if($selPueblo == this.pueblo[i][0][0]){
			idPueblo = i;
			this.zip = $selZip
			var $sel =' selected="selected"';
		}
		
		this.agregarItem(document.getElementById("cmb_pueblo"),this.pueblo[i][0][0], i, $sel)
		
		
		//document.getElementById("cmb_pueblo").innerHTML += '<option value="'+ i +'" ' + $sel + '>'+ this.pueblo[i][0][0] +'</option>'
	
	}
	
	this.chageZip(idPueblo)

	document.getElementById("step1").className = "en_paso"
	
}

Registro.prototype.chageZip = function($id){
	
	document.getElementById("pueblo").value = this.pueblo[$id][0][0]
	
	document.getElementById("cmb_zip").innerHTML = '';
	
	
	
	for(var i=0; i<this.pueblo[$id][1].length; i++){
		
		var $sel ='';
		if(this.zip ==  this.pueblo[$id][1][i]){
		
			var $sel =' selected="selected"';
		}
	
	this.agregarItem(document.getElementById("cmb_zip"), this.pueblo[$id][1][i], this.pueblo[$id][1][i], $sel)
		
		//document.getElementById("cmb_zip").innerHTML += '<option value="'+ this.pueblo[$id][1][i] +'"    '+$sel+'>'+ this.pueblo[$id][1][i] +'</option>'
	
	}
	
}

Registro.prototype.agregarItem = function(cual_, txt, valor, sel){

	var oOption = document.createElement("OPTION");
		oOption.text = txt;
		oOption.value = valor;
		
	oOption.selected = sel;
	
	if(cual_!=null){
	   
	   cual_.options.add(oOption);
		
	}

}

Registro.prototype.aceptar = function($edit){


	var txt_email = document.getElementById("txt_email").value 
	while (txt_email.charAt(0) == " "){
		txt_email = txt_email.substring(1, txt_email.length); 
		document.getElementById("txt_email").value = txt_email.substring(1, txt_email.length); 
    }
	///////////////////////
	var txt_pass =document.getElementById("txt_pass").value 
	while (txt_pass.charAt(0) == " "){
		txt_pass = txt_pass.substring(1, txt_pass.length); 
		document.getElementById("txt_pass").value = txt_pass.substring(1, txt_pass.length); 
    }
	////////////////////////////////////
	var txt_confirm_pass =document.getElementById("txt_confirm_pass").value 
	while (txt_confirm_pass.charAt(0) == " "){
		txt_confirm_pass = txt_confirm_pass.substring(1, txt_confirm_pass.length); 
		document.getElementById("txt_confirm_pass").value = txt_confirm_pass.substring(1, txt_confirm_pass.length); 
    }
	//////////////////////////////////////////
	var txt_nombre = document.getElementById("txt_nombre").value 
	while (txt_nombre.charAt(0) == " "){
		txt_nombre = txt_nombre.substring(1, txt_nombre.length); 
		document.getElementById("txt_nombre").value = txt_nombre.substring(1, txt_nombre.length); 
    }
	/////////////////////////////////////////////////
	var txt_apellido =document.getElementById("txt_apellido").value 
	while (txt_apellido.charAt(0) == " "){
		txt_apellido = txt_apellido.substring(1, txt_apellido.length); 
		document.getElementById("txt_apellido").value = txt_apellido.substring(1, txt_apellido.length); 
    }
	//////////////////////////////////////////////////
	var txt_direccion =document.getElementById("txt_direccion").value 
	while (txt_direccion.charAt(0) == " "){
		txt_direccion = txt_direccion.substring(1, txt_direccion.length); 
		document.getElementById("txt_direccion").value = txt_direccion.substring(1, txt_direccion.length); 
    }

	//txt_email
	//txt_pass
	//txt_confirm_pass
	//txt_nombre
	//txt_apellido
	//txt_direccion
	

	////////////////////////////////////////////////////////////////////////

document.getElementById("error_email").style.display = "none"
document.getElementById("error_pass").style.display = "none"
document.getElementById("error_confirm_pass").style.display = "none"
document.getElementById("error_nombre").style.display = "none"
document.getElementById("error_apellido").style.display = "none"
document.getElementById("error_direccion").style.display = "none"

	var error = false;
	var txt_error = "";

	if(txt_email==""){
		txt_error += "\n - Ingresa t\xFA e-email."
		document.getElementById("error_email").innerHTML = "Ingresa t\xFA e-email."
		document.getElementById("error_email").style.display = "block"
		error = true;
	}
	
	if(!this.emailchek(txt_email) && txt_email!=""){
		
		txt_error += "\n - Ingresa un e-email correcto."
		document.getElementById("error_email").innerHTML = "Ingresa un e-email correcto."
		document.getElementById("error_email").style.display = "block"
		error=true;
	}
	
	if(txt_pass==""){
		txt_error += "\n - Ingresa t\xFA clave."
		document.getElementById("error_pass").innerHTML = "Ingresa t\xFA clave."
		document.getElementById("error_pass").style.display = "block"
		error=true;
	}
	if(txt_confirm_pass==""){
		txt_error += "\n - Confirma t\xFA clave.";
		document.getElementById("error_confirm_pass").innerHTML = "Confirma t\xFA clave."
		document.getElementById("error_confirm_pass").style.display = "block"
		error=true;
	}
	
	
	



	if(txt_pass!=txt_confirm_pass){
		txt_error += "\n - La confirmaci\xF3n de la clave no coincide con la misma."
		document.getElementById("error_confirm_pass").innerHTML = "La confirmaci\xF3n de la clave no coincide con la misma."
		document.getElementById("error_confirm_pass").style.display = "block"
		error=true;
	}
	
	if(txt_nombre==""){
			txt_error += "\n - Ingresa t\xFA nombre."
			document.getElementById("error_nombre").innerHTML = "Ingresa t\xFA nombre."
			document.getElementById("error_nombre").style.display = "block"
			error=true;
	}
	
	if(txt_apellido==""){
			txt_error += "\n - Ingresa t\xFA apellido."
			document.getElementById("error_apellido").innerHTML = "Ingresa t\xFA apellido."
			document.getElementById("error_apellido").style.display = "block"
			error=true;
	}
	
	
	if(txt_direccion==""){
			txt_error += "\n - Ingresa t\xFA direcci\xF3n."
			document.getElementById("error_direccion").innerHTML = "Ingresa t\xFA direcci\xF3n."
			document.getElementById("error_direccion").style.display = "block"
			error = true;
	}
	

	window.scroll(0,0)
	
	
	if(error){
	//	alert("Disculpa. Hemos tenido problemas para procesar la informaci\xF3n recibida. Por favor verifica la informaci\xF3n se\xF1alada abajo: "  + txt_error)
	document.getElementById("div_error").style.display = "block"
		return
	}
	document.getElementById("div_error").style.display = "none"
	
		
	
	
	/////////////////////////////////////////////////////////////////////////////
	abrir_carga()
	
	document.getElementById("step1").className = "ya_paso"
	document.getElementById("step2").className = "en_paso"
	document.getElementById("form_registro").action = "verificar_email_existente.php?edit="+$edit
	document.getElementById("form_registro").target = "i_frame"
	document.getElementById("form_registro").submit(); 


	
}
Registro.prototype.envia_clave = function(){

		var email = document.getElementById("txt_email").value;
	
		if(email==""){
			alert("Ingresa t\xFA e-email.")
			return
		}
		
		if(!this.emailchek(email) && email!=""){
			
			alert("Ingresa un e-email correcto.")
			return
	
		}

		document.getElementById("btn_enviar_clave").value = "Enviando...";
		document.getElementById("btn_enviar_clave").disabled = true;
		petision("div.enviar_clave.php", "div_form_clave", "POST", "email=" + email);
		
}

Registro.prototype.mostrar_paso1 = function(){
	document.getElementById("paso0").style.display = "none"
	document.getElementById("paso1").style.display = "block"
	
}

Registro.prototype.enviar = function($edit){
	
	abrir_carga()
	document.getElementById("form_registro").action = "registro_save.php?edit=" + $edit
	document.getElementById("form_registro").target = "i_frame"
	document.getElementById("form_registro").submit(); 
}
Registro.prototype.ingresar = function(){

	var txt_email = document.getElementById("txt_email").value 
	var txt_clave =document.getElementById("txt_clave").value
	
	this.login(txt_email, txt_clave);
	
	
}
Registro.prototype.login = function($email, $pass){

	abrir_carga()
	document.getElementById("i_frame").src = "iframe.login_send.php?email="+$email+"&clave="+$pass

}




Registro.prototype.atras = function(){
	document.getElementById("step2").className = "ya_paso"
	document.getElementById("step1").className = "en_paso"
	document.getElementById("paso0").style.display = "block"
	document.getElementById("paso1").style.display = "none"
}

Registro.prototype.emailchek = function(str){

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		 
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		
		    return false
		 }

 		 return true					
	}

