// JavaScript Document

function existe(id){
	var i;		
	var el = document.getElementsByTagName("select");
	for(i=0;i<el.length;i++){
		if(el[i].id==id){
			if(id=='estados' && el[i].name !='estado'){
				alert("Error: name debe ser 'estado' y es '"+el[i].name+"'");
			}
			if(id=='ciudades' && el[i].name !='ciudad'){
				alert("Error: name debe ser 'ciudad' y es '"+el[i].name+"'");
			}
			return true;
		}
	}
	return false;
}

function execpost(formobj)
{
	if (document.getElementById("ciudades").value != "nada") {
		//asignamos directamente la url del action a hacer submit
		if (document.getElementById("pais").value == "Mexico") { 
				formobj.action="/dirubic/servlet/DirUbicSrv";
		}
		else if (document.getElementById("pais").value == "Belize") {
				formobj.action="/dirubic/servlet/DirUbicBelize";
		}
		else if (document.getElementById("pais").value == "El Salvador") {
				formobj.action="/dirubic/servlet/DirUbicElSalv";
		}
		else if (document.getElementById("pais").value == "Guatemala") {
				formobj.action="/dirubic/servlet/DirUbicGuate";
		}
		formobj.submit();
	}
}

function listaestados(valuepais)
{
	var FullURL="";
	
	if(!existe('estados') || !existe('ciudades')){			
		return;
	}
	if(valuepais == 'nada')
	{
		document.getElementById('estados').length = 0;
		document.getElementById('estados').options[0] =  new Option('--Seleccione--','nada');
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');	
	} 
	else 
	{
		// document.getElementById('ps').value = valuepais;
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
			
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");
					return false;      
			   	}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('estados');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		
		FullURL=unescape(window.location.href);
		
		if(FullURL.indexOf("menu_lateral/centros_servicio")>=0)
		{
			xmlHttp.open("POST","/formatos/servlet/CServInfo?val=1&pais="+valuepais,true);
			xmlHttp.send(null);
		}
		else if(FullURL.indexOf("menu_lateral/gasauto")>=0)
		{
			xmlHttp.open("POST","/formatos/servlet/ECarbInfo?val=1&pais="+valuepais,true);
			xmlHttp.send(null);
		}
		//xmlHttp.open("POST","/formatos/servlet/AjaxInfo?val=1&pais="+valuepais,true);
	}
}
function listaciudades(valueestado)
{
	var FullURL="";

	if(valueestado == 'nada')
	{
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
		
	} 
	else 
	{
		//var combopais = document.getElementById('pais');
		var country = 'Mexico';
		var params="val=2&estado="+unescape(valueestado)+"&pais="+country;
		// document.getElementById('ps').value = valuepais;
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");      
					return false;      
				}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('ciudades');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		FullURL=unescape(window.location.href);
		
		if(FullURL.indexOf("menu_lateral/centros_servicio")>=0)
		{
			xmlHttp.open("post","/formatos/servlet/CServInfo",true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(params);
		}
		else if(FullURL.indexOf("menu_lateral/gasauto")>=0)
		{
			xmlHttp.open("post","/formatos/servlet/ECarbInfo",true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(params);
		}
		//xmlHttp.open("POST","/formatos/servlet/AjaxInfo?val=2&estado="+valueestado+"&pais="+country,true);
		//xmlHttp.send(null);  
	}
}

/*window.onload=function()
{	
	var tmpciudad=null;
	
	debugger;
	
	if ((typeof(document.getElementById('estados'))!='undefined'))
	{
		tmpciudad=document.getElementById('ciudades');
		
		if((tmpciudad==null))
		{
			listaestados('Mexico');
		}
	}
}

/*if(window.addEventListener)
{
	window.addEventListener('onload',cargainicial,true);
}
else if(window.attachEvent)
{
	window.attachEvent('onload',cargainicial);
}
/*window.onload=function()
{
	var intervalo;
	debugger;
	
	
	/*if(typeof(document.getElementById("estados"))!="undefined")
		listaestados('Mexico');
};*/

/* Funciones que solo aplican a las páginas de contrato, pedidos en línea y contactanos*/
function listaestados2(valuepais)
{
	if(!existe('estados') || !existe('ciudades'))
		return;
		
	if(valuepais == 'nada')
	{
		document.getElementById('estados').length = 0;
		document.getElementById('estados').options[0] =  new Option('--Seleccione--','nada');
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
			
			
	} 
	else 
	{
		// document.getElementById('ps').value = valuepais;
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
		
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");      
					return false;      
				}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('estados');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{            
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("POST","/formatos/servlet/AjaxInfo?val=1&pais="+valuepais,true);
		xmlHttp.send(null);  
	}
}
function listaciudades2(valueestado)
{
	
	if(valueestado == 'nada')
	{
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
			
	} 
	else 
	{
		var combopais = document.getElementById('pais');
		var country = combopais.options[combopais.selectedIndex].value;
		var params="val=2&estado="+unescape(valueestado)+"&pais="+country;
		// document.getElementById('ps').value = valuepais;
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");      
					return false;      
				}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('ciudades');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("post","/formatos/servlet/AjaxInfo",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}

/*Funciones que solo aplican para inscripción.js*/
function listaestados3(valuepais)
{
	if(!existe('estados') || !existe('ciudades'))
		return;
		
	if(valuepais == 'nada')
	{
		document.getElementById('estados').length = 0;
		document.getElementById('estados').options[0] =  new Option('--Seleccione--','nada');
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');	
	} 
	else 
	{
		// document.getElementById('ps').value = valuepais;
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
			
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");
					return false;      
			   	}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('estados');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("POST","/formatos/servlet/CanjeInfo?val=1&pais="+valuepais,true);
		xmlHttp.send(null);  
	}
}
function listaciudades3(valueestado)
{

	if(valueestado == 'nada')
	{
		document.getElementById('ciudades').length = 0;
		document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
		
	} 
	else 
	{
		var combopais = document.getElementById('pais');
		var country = combopais.options[combopais.selectedIndex].value;
		//var combopais = document.getElementById('pais');
		//var country = 'Mexico';
		var params="val=2&estado="+unescape(valueestado)+"&pais="+country;
		// document.getElementById('ps').value = valuepais;
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");      
					return false;      
				}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('ciudades');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("post","/formatos/servlet/CanjeInfo",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}
//agregado por Roberto Chavez 12 mayo 2010 para filtrar paises promociones.htm
function listaestadospromo(valuepais)
{
 if(valuepais == 'nada'){
	document.getElementById('estados').length = 0;
	document.getElementById('estados').options[0] =  new Option('--Seleccione--','nada');
	document.getElementById('ciudades').length = 0;
	document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
    
    
 } else {
	// document.getElementById('ps').value = valuepais;
	var combopais = document.getElementById('pais');
	var country = combopais.options[combopais.selectedIndex].value;
	document.getElementById('ciudades').length = 0;
	document.getElementById('ciudades').options[0] =  new Option('--Seleccione--','nada');
	if ((document.getElementById("pais").value == "Guatemala") || (document.getElementById("pais").value == "El Salvador")) { 	
		document.getElementById('edolabel').innerHTML = 'Departamento';
		document.getElementById('cdlabel').innerHTML = 'Municipio';
	}
	else if (document.getElementById("pais").value == "Mexico") { 	
		document.getElementById('edolabel').innerHTML = 'Estado';
		document.getElementById('cdlabel').innerHTML = 'Ciudad';
	}
	 var xmlHttp;
		try
		  {  // Firefox, Opera 8.0+, Safari 
			 xmlHttp=new XMLHttpRequest();  }
		catch (e)
		  {  // Internet Explorer  
			   try
				{    
				  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
			   catch (e)
				{    
				  try
				   {      
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
				  catch (e)
					  {      
						alert("Your browser does not support AJAX!");      
						return false;      
					   }    
				   }  
			}
		  xmlHttp.onreadystatechange=function()
			{
			if(xmlHttp.readyState==4)
			  {
			   var combo = document.getElementById('estados');
			   combo.options.length = 0;         
			   var response = xmlHttp.responseText;        
			   var items = response.split(";");        
			   var count = items.length; 
			   combo.options[0] =  new Option('--Seleccione--','nada');       
			   for (var i=0;i<count;i++){            
					 var options = items[i].split("-");            
					 combo.options[i+1] =  new Option(options[0],options[1]);        
			   }	      
			  }
			} 
		  xmlHttp.open("POST","/formatos/servlet/CanjeInfo?val=1&pais="+country,true);
		  xmlHttp.send(null);
	}
}
/*Función que solo aplica para el formato de inscripción de Zeta Premia para que carguen los combos de estados y ciudades
	MOLMOS(21/MAY/2009)
*/
function listaestados4(valuepais)
{
	if(!existe('estados') || !existe('ciudades')){			
		return;
	}
	if(valuepais == 'nada')
	{
		document.getElementById('estados2').length = 0;
		document.getElementById('estados2').options[0] =  new Option('--Seleccione--','nada');
		document.getElementById('ciudades2').length = 0;
		document.getElementById('ciudades2').options[0] =  new Option('--Seleccione--','nada');	
	} 
	else 
	{
		// document.getElementById('ps').value = valuepais;
		document.getElementById('ciudades2').length = 0;
		document.getElementById('ciudades2').options[0] =  new Option('--Seleccione--','nada');
			
		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");
					return false;      
			   	}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('estados2');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("POST","/formatos/servlet/CanjeInfo?val=1&pais="+valuepais,true);
		xmlHttp.send(null);  
	}
}

function listaciudades4(valueestado)
{

	if(valueestado == 'nada')
	{
		document.getElementById('ciudades2').length = 0;
		document.getElementById('ciudades2').options[0] =  new Option('--Seleccione--','nada');
	} 
	else 
	{
		//var combopais = document.getElementById('pais');
		var country = 'Mexico';
		var params="val=2&estado="+unescape(valueestado)+"&pais="+country;

		var xmlHttp;
		try
		{  // Firefox, Opera 8.0+, Safari 
			xmlHttp=new XMLHttpRequest();  
		}
		catch (e)
		{  // Internet Explorer  
			try
			{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
			catch (e)
			{    
				try
				{      
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				}
				catch (e)
				{      
					alert("Your browser does not support AJAX!");      
					return false;      
				}    
			}  
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var combo = document.getElementById('ciudades2');
				combo.options.length = 0;         
				var response = xmlHttp.responseText;        
				var items = response.split(";");        
				var count = items.length; 
				combo.options[0] =  new Option('--Seleccione--','nada');       
				for (var i=0;i<count;i++)
				{
					var options = items[i].split("-");            
					combo.options[i+1] =  new Option(options[0],options[1]);        
				}	      
			}
		}
		xmlHttp.open("post","/formatos/servlet/CanjeInfo",true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}

function PrepareText(obj)
{
	if((obj.tagName=="INPUT") && (obj.type=="text") && (obj.value=="(123)456-7890"))
	{
		obj.value="";
		obj.className="";
	}

	obj.select();
}

function ValidateText(obj)
{
	var valor=obj.value.trim();
	if(valor=="")
	{
		if(obj.name=="telefono")
			obj.value="(123)456-7890";
			
		obj.title="El campo no debe estar vacio";
	}
	else
	{
		switch(obj.name)
		{
			case "email":
				if(validatetextentry(obj,"^[\\w\\.\\-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"))
				{
					obj.style.backgroundColor="";
					obj.title="Valor Obligatorio";
				}
				else
				{
					obj.title="El correo electronico debe estar en el formato aaaa@bbbbb.com";
				}
			break;
			case "telefono":
				if(validatetextentry(obj,"^\\((\\d{2,3})\\)(\\d{3})[-](\\d{4})$"))
				{
					obj.style.backgroundColor="";
					obj.title="Valor Obligatorio";
				}
				else
				{
					obj.title="El teléfono debe estar en el formato (123)456-7890";
				}
			break;
		}
	}
}

function validarformato(formsource)
{
	var validatorMessage='Se encontraron los siguientes errores: \n\n';
	var selectarray=null;
	var inputarray=null;
	var tmpphonearray=null;   //NUEVO:Para obtener los textbox del telefono
	var tmpcelarray=null;     //NUEVO:Para obtener los textbox del celular
	var textareaarray=null;
	var textarray=new Array();
	var checkboxarray=new Array();
	var labelarray=null;
	var returnvalue=true;
	var tmprtnvalidation="";
	var erroremail=false;   //Para validar si el campo correo tuvo un error
	var errorphone=false;  //Para validar si el campo telefono tuvo un error
	var selcilindro=false;     //Para validar si se selecciono un cilindro
	var selestacionario=false; //Para validar si se selecciono estacionario
	var tmpphone=null;
	var tmpemail=null;
	var valerrorphone="";   //Para obtener el valor del error del teléfono
	var valerroremail="";   //Para obtener el valor del error del correo electrónico
	
	
	var i=0,j=0,k=0;
	//identificamos primeramente los campos a llenar y creamos arrays de controles
	
	selectarray=formsource.getElementsByTagName("select");
	inputarray=formsource.getElementsByTagName("input");
	textareaarray=formsource.getElementsByTagName("textarea");
	labelarray=formsource.getElementsByTagName("label");
	
	//Enseguida creamos el teléfono y el celular
	tmpphonearray=document.getElementsByName("tmptel");
	tmpcelarray=document.getElementsByName("tmpcel");
	document.getElementById("tel").value="("+tmpphonearray[0].value+")"+tmpphonearray[1].value+"-"+tmpphonearray[2].value;
	
	if((tmpphonearray[0].value.length==0) && (tmpphonearray[1].value.length==0) && (tmpphonearray[2].value.length==0))
		document.getElementById("tel").value="";
	
	document.getElementById("cel").value="("+tmpcelarray[0].value+")"+tmpcelarray[1].value+"-"+tmpcelarray[2].value;	
	
	if((tmpcelarray[0].value.length==0) && (tmpcelarray[1].value.length==0) && (tmpcelarray[2].value.length==0))
		document.getElementById("cel").value="";
	
	//Separamos los checkboxes de los textboxes
	for(i=0;i<inputarray.length;i++)
	{
		switch(inputarray[i].type)
		{
			case "text":
				textarray[j]=inputarray[i];
				j++;
			break;
			case "hidden":
				textarray[j]=inputarray[i];
				j++;
			break;
			case "checkbox":
				checkboxarray[k]=inputarray[i];
				k++;
			break;
		}
	}
	
	//Agregamos los textareas dentro de los textboxes ya que se manejan igual
	for(i=0;i<textareaarray.length;i++)
		textarray.push(textareaarray[i]);
		
	//Limpiamos los arrays de textareaarray e inputarray para que no ocupen espacio de memoria
	textareaarray=null;
	inputarray=null;
	
	//Validamos primeramente que los selects tengan valores mayores a 0
	for(i=0;i<selectarray.length;i++)
	{
		//Buscamos el label que concuerde con el select actual
		for(j=0;j<labelarray.length;j++)
		{
			if (labelarray[j].htmlFor==selectarray[i].id)
				break;
		}
		
		tmprtnvalidation=validateselect(selectarray[i],labelarray[j].innerHTML);
		
		if(tmprtnvalidation.length>0)
		{
			//Excepción cuando ejecutemos el combo de tipo de requerimiento
			//if selectarray[i]
			switch (selectarray[i].parentNode.id)
			{
				case "Estacionario":
					if(selectarray[i].parentNode.style.display=="none")
					{
						//El combo esta desabilitado...entonces borramos el mensaje de error en validación
						tmprtnvalidation="";
						selectarray[i].style.backgroundColor="";
					}
					else
					{
						validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
						returnvalue=false;
					}
				break;
				case "Cilindros":
					if(selectarray[i].parentNode.style.display=="none")
					{
						//El combo esta desabilitado...entonces borramos el mensaje de error en validación
						tmprtnvalidation="";
						selectarray[i].style.backgroundColor="";
					}
					else
					{
						validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
						returnvalue=false;
					}
				break;
				default:  //Para los demás componentes
					validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
					returnvalue=false;
			}
		}
	}
	//Validamos enseguida los textbox
	for(i=0;i<textarray.length;i++)
	{
		//Buscamos el label que concuerde con el select actual
		for(j=0;j<labelarray.length;j++)
		{
			if (labelarray[j].htmlFor==textarray[i].id)
				break;
		}
		//debugger;
		if((typeof(labelarray[j])=="undefined" && textarray[i].name=="tmptel") || (typeof(labelarray[j])=="undefined" && textarray[i].name=="telefono"))
			tmprtnvalidation=validatetext(textarray[i],"Telefono");
		else if(typeof(labelarray[j])=="undefined" && textarray[i].name=="tmpcel" || (typeof(labelarray[j])=="undefined" && textarray[i].name=="celular"))
			tmprtnvalidation=validatetext(textarray[i],"Celular");
		else
			tmprtnvalidation=validatetext(textarray[i],labelarray[j].innerHTML);
		
		if(tmprtnvalidation.length>0)
		{
			//Validamos si el campo actual es el campo del correo electrónico o del teléfono
			switch(textarray[i].name)
			{
				case "email":
					erroremail=true;
					tmpemail=textarray[i];
					valerroremail=tmprtnvalidation;
					
					if((erroremail==true && errorphone==true))
					{
						tmprtnvalidation="Es necesario especificar un correo electronico y/o un telefono válidos donde podamos contactarlo";
						validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
						returnvalue=false;
						if(tmpemail!=null)
							tmpemail.style.backgroundColor="rgb(255,255,153)";
						
						if(tmpphone!=null)
						{
							for(k=0;k<tmpphonearray.length;k++)
							{
								tmpphonearray[k].style.backgroundColor="rgb(255,255,153)";
							}
						}
					}
					else
					{
						if(tmpemail!=null)
							tmpemail.style.backgroundColor="";
						if(tmpphone!=null)
						{
							for(k=0;k<tmpphonearray.length;k++)
							{
								tmpphonearray[k].style.backgroundColor="";
							}
						}
					}
				break;
				case "telefono":
					errorphone=true;
					tmpphone=textarray[i];
					valerrorphone=tmprtnvalidation;
					
					if(tmpemail!=null)
						tmpemail.style.backgroundColor="rgb(255,255,153)";
					if(tmpphone!=null)
					{
						for(k=0;k<tmpphonearray.length;k++)
						{
							tmpphonearray[k].style.backgroundColor="rgb(255,255,153)";
						}
					}
					
					if(erroremail==true && errorphone==true)
					{
						tmprtnvalidation="Es necesario especificar un correo electronico y/o un telefono validos donde podamos contactarlo";
						validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
						returnvalue=false;
					}
					else
					{
						if(tmpemail!=null)
							tmpemail.style.backgroundColor="";
						if(tmpphone!=null)
						{
							for(k=0;k<tmpphonearray.length;k++)
							{
								tmpphonearray[k].style.backgroundColor="";
							}
						}
					}
				break;
				default:
					validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
					returnvalue=false;
			}
		}
	}
	if(valerroremail=="El correo electronico debe estar en el formato aaaa@bbbbb.com" && errorphone==false)
	{
		//Si pasó la validación, pero el correo electrónico esta en formato incorrecto. Por lo que impedimos el submit
		returnvalue=false;
		tmprtnvalidation="El correo electronico no se encuentra en el formato correcto. Para continuar puede corregirlo o dejarlo en blanco ya que el telefono es correcto";
		validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
				
		if(tmpemail!=null)
			tmpemail.style.backgroundColor="rgb(255,255,153)";
		if(tmpphone!=null)
		{
			for(k=0;k<tmpphonearray.length;k++)
			{
				tmpphonearray[k].style.backgroundColor="rgb(255,255,153)";
			}
		}
	}
	
	if(valerrorphone=="El telefono debe estar en el formato (123)456-7890" && erroremail==false)
	{
		//Si pasó la validación, pero el correo electrónico esta en formato incorrecto. Por lo que impedimos el submit
		returnvalue=false;
		tmprtnvalidation="El telefono no se encuentra en el formato correcto. Para continuar puede corregirlo o dejarlo en blanco ya que el correo electronico es correcto";
		validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
				
		if(tmpemail!=null)
			tmpemail.style.backgroundColor="rgb(255,255,153)";
		if(tmpphone!=null)
		{
			for(k=0;k<tmpphonearray.length;k++)
			{
				tmpphonearray[k].style.backgroundColor="rgb(255,255,153)";
			}
		}
	}
	
	//Por último revisamos los checkboxes
	tmprtnvalidation=validatecheckbox(checkboxarray,labelarray);
	
	if(tmprtnvalidation.length>0)
	{
		validatorMessage=validatorMessage+'\t-'+tmprtnvalidation+'\n';
		returnvalue=false;
	}

	validatorMessage=validatorMessage+"\nLos campos con errores se muestran remarcados en amarillo para su facil localizacion.\n";
	
	if(returnvalue==false)
		alert(validatorMessage);
	
	return returnvalue;
}

function validateselect(selectsource,labelname)
{
	if((selectsource.selectedIndex==0) && (selectsource.title.length>0))
	{
		selectsource.style.backgroundColor="rgb(255,255,153)";
		selectsource.title="El valor seleccionado no es correcto. Favor de seleccionar otro valor";
		//Buscamos el label que concuerde con la 
		return "El valor del campo "+labelname+" no es correcto.";
	}
	selectsource.style.backgroundColor="";
	return "";
}

function validatetext(textsource,labelname)
{	
	var tmptel=null;
	var i=0;
	
	if((textsource.title.length>0) && ((textsource.value.length==0) || (textsource.value=="(123)456-7890")) && (textsource.name!="tmptel"))
	{
		textsource.style.backgroundColor="rgb(255,255,153)";
		textsource.title="El valor no puede estar vacio.";
		return "El valor del campo "+labelname+" no debe estar vacio.";
	}
	else if((textsource.title.length>0) && (textsource.value!="(123)456-7890"))
	{
		switch(textsource.name)
		{
			case "telefono":
				if(validatetextentry(textsource,"^\\((\\d{2,3})\\)(\\d{3})[-](\\d{4})$")==false)
				{
					tmptel=document.getElementsByName("tmptel");

					for(i=0;i<tmptel.length;i++)
					{
						tmptel[i].style.backgroundColor="rgb(255,255,153)";
						tmptel[i].title="telefono incorrecto. El telefono debe estar en el formato (123)456-7890";
					}
					return "El telefono debe estar en el formato (123)456-7890";
				}
			break;
			case "email":
				if(validatetextentry(textsource,"^[\\w\\.\\-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$")==false)
				{
					textsource.style.backgroundColor="rgb(255,255,153)";
					textsource.title="Correo electronico incorrecto. El correo electronico debe estar en el formato adecuado";
					return "El correo electronico debe estar en el formato aaaa@bbbbb.com";
				}
			break;
			case "numero":
				if(validatetextentry(textsource,"\\d")==false)
				{
					textsource.style.backgroundColor="rgb(255,255,153)";
					textsource.title="Este campo solo acepta numeros";
					return "El campo Numero debe contener solo numeros";
				}
			break;
		}
		
	}
	textsource.style.backgroundColor="";
	
	if(textsource.name=="telefono")
	{
		tmptel=document.getElementsByName("tmptel");

		for(i=0;i<tmptel.length;i++)
		{
			tmptel[i].style.backgroundColor="";
		}
	}
	return "";
}

function validatecheckbox(checkboxarray)
{
	var i=0,j=0;
	var checkboxfieldsetparent=null;
	var legendtext="";
	
	if((checkboxarray!=null) && (checkboxarray.length>0))
	{
		for(i=0;i<checkboxarray.length;i++)
		{
			if(legendtext=="")
			{
				checkboxfieldsetparent=checkboxarray[i];
				
				while(checkboxfieldsetparent.tagName!="FIELDSET")
					checkboxfieldsetparent=checkboxfieldsetparent.parentNode;
					
				legendtext=checkboxfieldsetparent.getElementsByTagName("legend")[0].innerHTML;
	
			}
			
			checkboxarray[i].parentNode.style.backgroundColor="";
			
			if((checkboxarray[i].checked==true) && (checkboxarray[i].title.length>0))	
				j++;
		}
	
		//Si no se encontraron checkboxes seleccionados se ponen en amarillo y se pone la leyenda de error
		if(j==0)
		{
			for(i=0;i<checkboxarray.length;i++)
			{
				checkboxarray[i].parentNode.style.backgroundColor="rgb(255,255,153)";
				checkboxarray[i].title="Es necesario seleccionar por lo menos una opcion";
			}
			
			return "Debe seleccionar por lo menos un servicio";
		}
	}
	return "";
}

function validatetextentry(textsource,regex)
{
	var validador=new RegExp(regex,"i");
	
	return validador.test(textsource.value.trim());
}

//Función trim 
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function isNum(evt)
{
	var tecla=null;
	var numval=null;
	
	if (!evt) var evt = window.event;
	if (evt.keyCode) numval = evt.keyCode;
	if (evt.which) numval = evt.which;

	tecla=String.fromCharCode(numval);
	var keyval=new RegExp("\\d");
	//alert(evt.keyCode+" "+evt.which);
	//Validamos si la tecla es una de las flechas, backspace ó delete ya que mozilla bloquea tambien éstas teclas.
	if((((numval>=37 && numval<=40) || (numval==46)) && (typeof(evt.which)!="undefined") && (evt.which==0)) || (numval==8 && evt.which==8) || (numval==36 && evt.which==0) || (numval==35 && evt.which==0) || (numval==9 && evt.which==0))
		return true;
		
	return keyval.test(tecla);
}

function autotab(evt,curobj,nextobj)
{
	if(curobj.value.length==curobj.maxLength)
		document.getElementById(nextobj).focus();
}