//==================================================================
//ECC2007.07.23 Mensajes de error comunes.
var msgSys01 = 'SELECT PRODUCTS TO COMPARE';
var msgSys02 = 'YOU CANNOT COMPARE MORE THAN SEVEN PRODUCTS';
var msgSys03 = 'YOU CANNOT COMPARE ONLY ONE PRODUCT';
var msgSys04 = 'THE PRODUCT IDs CANNOT BE DIFFERENT';

//==================================================================
function validaTextArea(myfield, e, strTipo, iLongitud ,strExtras)
{
  if(iLongitud)
  {
      if (myfield.value.length>iLongitud)
      {
    	var msj1 = document.getElementById('multilen1644').value;
    	var msj2 = document.getElementById('multilen1645').value;
    	alert (msj1+'' + iLongitud + ' '+ msj2);
        myfield.value= myfield.value.substr (0,iLongitud);
    	return false;
      }
  }
  switch (strTipo)
  {
         case 'a' : return permiteLetras(myfield, e, strExtras);
         case 'an': return permiteAlfanumerico(myfield, e, strExtras);
         case 'na': return permiteAlfanumerico(myfield, e, strExtras);
         case 'n' : return permiteNumeros(myfield, e, strExtras);
         case 't' : return permiteTexto(myfield, e, strExtras);
         default  : return true;
  }
}

//==================================================================

function permiteLetras(myfield, e, strExtras)
{
   var strCarValidos = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + strExtras;
   return validateChar(myfield,e,strCarValidos);
}

//==================================================================
function permiteNumeros(myfield, e, strExtras)
{
   var strCarValidos = '1234567890' + strExtras;
   return validateChar(myfield,e,strCarValidos);
}
//==================================================================
function permiteAlfanumerico(myfield, e, strExtras)
{
	var strCarValidos="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + strExtras;
   return validateChar(myfield,e,strCarValidos);}

//==================================================================
function permiteTexto(myfield, e, strExtras)
{
   var strCarValidos = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ,¿?¡!<>/@;.:-_()$&%#' + strExtras;
   return validateChar(myfield,e,strCarValidos);
}

//==================================================================
function ftipodato(Objeto, Tipo)
{
 var LongitudValor = Objeto.value.length + 1, Cadena = '', PintarCar209; //Ñ
 var SubCadena = String.fromCharCode(window.event.keyCode).toUpperCase();
 switch(Tipo)
 {
  case 0:  //SOLO LETRAS
	var cadStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '; PintarCar209 = true; break;
  case 1:  //Alfanumerico
	var cadStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ,#.'; PintarCar209 = true; break;
  case 2: //Números
	var cadStr = '0123456789';
	if(window.event.keyCode == 209)
		PintarCar209 = false;
	else
		PintarCar209 = true;
	break;
  case 3:  //Alfanumerico + @ + .
	var cadStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@._-'; PintarCar209 = true; break;
  case 4:  //LETRAS SOLAMENTE
	var cadStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ._- '; PintarCar209 = true; break;
 }

 if(LongitudValor>0)
 {
   for (i=1; i<=cadStr.length; i++)
   {
	if(PintarCar209)
	   if((cadStr.substring(i,i-1) == SubCadena) || (window.event.keyCode == 209)) Cadena=cadStr.substring(i,i-1);
	else
	   if(cadStr.substring(i,i-1) == SubCadena) Cadena=cadStr.substring(i,i-1);
   }
   if (Cadena.length==0) window.event.keyCode=0
 }
}
//==================================================================

function validateChar(myfield,e,validChars){ 
    var key;
    var keychar;
    
    if(window.event)
    	key = window.event.keyCode;
    else if (e)
    	key = e.which;
    else
    	return true;
    keychar = String.fromCharCode(key);
    
    //control keys
    if ((key==null)||(key==0)||(key==8)|| (key==9)||(key==13)||(key==27))
    	return true;
    //chars
    else if (((validChars).indexOf(keychar)>-1))
    	return true;	
    else
    	return false;
}


//==================================================================

function validaFormaAutomatico(oForma, strExcepciones,bValidaCamposOcultos,StrMsg)
{
  var listaObjetos = '', i = 0, bControlSinValor = false;
  	if(bValidaCamposOcultos)
		strTiposdeCamposAValidar="'text,select-one,password,hidden'";
	else
		strTiposdeCamposAValidar="'text,select-one,password'";

	for (i=0;i<oForma.length; i++){

	  if (strTiposdeCamposAValidar.indexOf(oForma[i].type)!=-1){ //buscar en estos tipos de objeto
		 if (strExcepciones){
		   if (strExcepciones.indexOf (oForma[i].name)!=-1){
			  continue; //los controles en la lista de excepciones se omiten
		   }
		 }
		 if (oForma[i].value==''){
			bControlSinValor=true;
			if(oForma[i].type!="hidden")
				oForma[i].focus();
			break;
		 }
	  }
	}
  //alert(StrMsg);
  if(bControlSinValor)
  {
	if(StrMsg == undefined)
 	   alert("PLEASE ENTER A VALUE IN " + '"' + ((oForma[i].title.length>0)?oForma[i].title:oForma[i].name) + '"');
  	else
	   alert(StrMsg + '"' + ((oForma[i].title.length>0)?oForma[i].title:oForma[i].name) + '"');
  }
  return !bControlSinValor;
}


//==================================================================
//ECC2007.07.03 Para validar el login.asp
function SubmitFormaLogin(oform,IsIP,str1408)
{
    //alert('hola');
    with(window.document)
    {
    	  getElementById('hdnUser').value = document.getElementById('User').value;
	getElementById('flagIP').value = IsIP;
	if(IsIP == 0)
	{
	    if(validaFormaAutomatico(oform, '','false',str1408))
		{
		  //getElementById('User').readonly = true;
		  //getElementById('Password').readonly = true;
		  //getElementById('PostalCode').readonly = true;

		  getElementById('User').style.visibility = 'hidden';
		  getElementById('Password').style.visibility = 'hidden';
		  getElementById('PostalCode').style.visibility = 'hidden';

		  getElementById('Usr').style.visibility = 'hidden';
		  getElementById('pass').style.visibility = 'hidden';
		  getElementById('CP').style.visibility = 'hidden';

		  getElementById('enter').style.display = 'none';
        	  getElementById('salir').style.display = 'none';
	  	  getElementById('enter2').style.display = '';
	  	  oform.submit();
		}
	}
	else if(validaFormaAutomatico(oform, 'User,Password,hdnUser','false',str1408))
	{
		oform.submit();
	}
    }
}
//ECC2007.07.07 LogOut al inicio del portal Employee.
function SubmitFormaLogOut(oform)
{
	with(window.document)
	{
	  getElementById('User').style.visibility = 'hidden';
	  getElementById('Password').style.visibility = 'hidden';
	  getElementById('PostalCode').style.visibility = 'hidden';

	  getElementById('Usr').style.visibility = 'hidden';
	  getElementById('pass').style.visibility = 'hidden';
	  getElementById('CP').style.visibility = 'hidden';

	  getElementById('enter').style.display = 'none';
	  getElementById('salir').style.display = 'none';
	  getElementById('enter2').style.display = '';
	}
	//window.location.href = './seleccionaLenguaje.asp';
	window.history.go(-1);
}

/*
function cambiaLenguaje(iLenguaje)
{
	//alert('<%=EC_PROFUNDIDAD_CODIGO%>\login.asp?lenguaje'+ iLenguaje);
	//window.location.href='<%=EC_PROFUNDIDAD_CODIGO%>\login.asp?lenguaje='+ iLenguaje;
	window.parent.location.href='<%= EC_PROFUNDIDAD_CODIGO %>\default.asp?lenguaje='+ iLenguaje;
}

function AbreVentanaInstrucciones()
{
      var MiPropiaVentana = '<%=EC_PROFUNDIDAD_CODIGO %>/comun/imagenes/sitio/default/changeresolution/changeresolution.html';
      window.open (MiPropiaVentana ,'','toolbar=no,directories=0,menubar=no,status=yes,scrollbars=1,resizable=1,heigth=200,width=800,titleblar=0',1)
}
*/

function LimpiarCamposLogin(strIPAcces)
{
  var IsIP = strIPAcces;
  with(window.document) //ECC2007.07.03
  {
     getElementById('flagIP').value = IsIP;
     mainForm.elements[0].focus();
     if(IsIP==1)
     {
 	  getElementById('user').style.display    = 'none';
	  getElementById('usuario').style.display = 'none';
	  getElementById('pass').style.display    = 'none';
	  getElementById('clave').style.display   = 'none';
          mainForm.elements[2].focus();
     }
  }
}

function AbreVentanaInstrucciones(idioma,strEC_PROFUNDIDAD_CODIGO)
{
      var MiPropiaVentana = '';
      MiPropiaVentana = strEC_PROFUNDIDAD_CODIGO + '/comun/imagenes/sitio/default/changeresolution/changeresolutionFrances.html';
      if(idioma == 1)
        MiPropiaVentana = strEC_PROFUNDIDAD_CODIGO + '/comun/imagenes/sitio/default/changeresolution/changeresolution.html';
      window.open(MiPropiaVentana ,'','toolbar=no,directories=0,menubar=no,status=yes,scrollbars=1,resizable=1,heigth=200,width=800,titleblar=0',1)
}

//ECC2007.07.30 Funciones de Detección para cerrar sitio y liberar sesiones del servidor.
function onCloseSite(str4006,strHttp)
{
  //if(strHttp == 'undefined') return;
  if(event.clientY < 0)
  {
    //if(!confirm(str4006))
    //  window.open(strHttp);
    //else
    //{
        var tmp = strHttp.split('/');
	var HH = ((screen.Height/2) - (50/2));
	var WW = ((screen.Width/2)-(200/2));
	strHttp = tmp[0] +'//'+ tmp[2] + '/' + tmp[4] + '/eliminarSesiones.asp';
	window.open(strHttp,'','toolbar=no,addressbar=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=no,height=50,width=200,left='+WW+',top='+HH+',center=yes,titleblar=no');
    //}
  }
}

function appClose()
{
  window.self.close();
}

function appMaximize()
{
    return
    window.moveTo(0,0); 
    window.resizeTo(screen.width,screen.height);
}

//ECC2007.07.30 Rollover para Selecciona.asp (Genérico para otras páginas)
function activeBTN(obj,iModo,msg)
{
  status = msg;
  with(document.getElementById(obj.id))
  {
     switch(iModo)
     {
         case 0: style.cursor='';     break; //className = 'btnluzbajaselIdiomaING'; break;
         case 1: style.cursor='hand'; break; //className = 'btnluzaltaselIdiomaING'; break;
         case 2: style.cursor='';     break; //className = 'btnluzbajaselIdiomaFRA'; break;
         case 3: style.cursor='hand'; break; //className = 'btnluzaltaselIdiomaFRA'; break;
     }
  }
  window.status = msg;
}

function submitForma(strLenguaje)
{

  with(window.document)
  {
	getElementById('English').style.visibility='hidden';
	getElementById('Francais').style.visibility='hidden';
	getElementById('enter2').style.display='';
	var oLenguaje = getElementById('lenguaje');
	oLenguaje.value = strLenguaje;
        fSubmit('');
  }
}

//ECC2007.07.09 Cambio de cursor.
function fCursor(iModo)
{
  with(window.document.body.style)
  {
     switch(iModo)
     {
	case 0: cursor = 'default'; break;
	case 1: cursor = 'wait'; break;
     }
  }
}
//ECC2007.07.10 Hace la petici{on de envío de forma al server.
function fSubmit2(strModo)
{
    with(window.document.mainForm)
    {
      if(strModo != '') action = strModo;
      submit();
    }
}

function fSubmit(strModo)
{
    with(window.document.mainForm)
    {
      if(strModo != '') accion.value = strModo;
      submit();
    }
}

function fSubmitMsg(strModo, strMsg)
{
    muestraMensaje('<%=MULTI_LEN(1537)%>',' '); fSubmit(strModo);
}

function fScroll(strY)
{
   window.scrollTo(0,strY);
}

//ECC2007.07.13 Rutina de Mensaje de error utilizado por omisión.
function mensajeError(pstrMensaje)
{
   if(pstrMensaje != '') alert(pstrMensaje);
}

//ECC2007.07.13 Valida si es home-delivery pedir si cambia a modo pickUP en /comun/home/default.asp
//ECC2007.07.13 Valida si es home-delivery pedir si cambia a modo pickUP en /comun/home/default.asp
function validarHomeDelivery(pDeliveryType,str3993,str3994,pstrPC)
{

  //ECC2007.07.13 Validacion #412 La primera vez que carga la página.
  if(document.getElementById('okDeliveryType').value == '')
  {
  if(pDeliveryType != 'home')
    if(confirm(str3993 + pstrPC + str3994))
    {
			validarHomeDelivery = 'pick'; //'contenido'
      window.document.getElementById('okDeliveryType').value = 'pick';
      //window.location.href = './default.asp?okDeliveryType=1';
			//window.parent.frames['nombreDireccion'].location.href = './nombreDireccionSuperior.asp?okDeliveryType=1';

    }
    else
 	window.history.go(-1);

  }
}

//YSH Se requiere esta función ya que la original validaba un elemento html
function validarHomeDeliveryY(pDeliveryType,str3993,str3994,pstrPC)
{
  if(pDeliveryType != 'home')
    if(confirm(str3993 + pstrPC + str3994))
    {
	return true;
    }else{
	return false;
    }
}

function faction(Obj)
{
   Obj.style.cursor = 'hand';
}

//ECC2007.07.16 Para la página nombreDireccionSuperior.asp
function AbrirVentanaCP()
{
  var pag = '../usuarios/updPostalCode.asp?pc=' + document.getElementById('txtPC').value + '&idPerson=' + document.getElementById('txtIdPerson').value;
  var HH = ((screen.Height/2) - (50/2));
  var WW = ((screen.Width/2)-(200/2));
  window.open(pag ,'','modal=yes,toolbar=no,addressbar=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=no,height=50,width=200,left='+WW+',top='+HH+',center=yes,titleblar=no');
  //window.open(pag ,'xwin','height=50,width=200,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes,left='+WW+',top='+HH);

  //window.showModalDialog(pag,'xwin',"dialogWidth:150px;dialogHeight:30px;center:yes;resizable:no;scroll:yes;status:no;help:no");
  return false;
}

//ECC2007.07.19 Para codigoPostalParametros.asp con posibilidad de reutilización.
function NoClick() { return false; }
function BuscarCP(pstr155, pstr1421) //ECC2007.07.17
{
  with(window.document)
  {
	var objFrame = getElementById('frmResultados');
	var objColonia = mainForm.colonia.value;
	var objCodigo_Postal = mainForm.codigo_postal.value;
	if(objColonia != '' || objCodigo_Postal != '')
        {
		with(window.frmResultados.document.body) //ECC2007.07.19
		{
		  onclick = NoClick; style.cursor = 'wait';
		}
		mainForm.submit(); MensajeBusqueda(pstr155);
	}
        else
	   alert(pstr1421);
  }
}

function MensajeBusqueda(pstrMensaje)
{
   var objmensajeBusqueda = document.getElementById('mensajeBusqueda');
   objmensajeBusqueda.innerHTML=pstrMensaje;
}

//ECC2007.07.20 funcciones para venta emergente de cambio de código postal.

//ECC y ATG2007.07.19 Desabilita link 'create order' en el paso 3.
function fDisableLink(OnOff)
{
  //alert("fDisableLink" + OnOff)
   var OnOff2 = 'none';
   if(OnOff == 'none') OnOff2 = '';
   with(window.opener.top.frames['contenido'].document) //ECC2007.07.17
   {
      if(getElementById('sec_num') != null)
      {
 	      if(getElementById('sec_num').value == 'sec 3')
        {
          getElementById('lnkCreateOrder').style.display = OnOff;
          //getElementById('lnkCreateOrder2').style.display = OnOff2;
        }
      }
   }
}

function fDisableBut()
{
	with(window.opener.top.frames['contenido'].document) //ECC2007.07.19
	{

	  if(getElementById('sec_num') != null)
		if(getElementById('sec_num').value == 'sec 4')
			window.document.getElementById('btnGo').disabled = true;
	}
        window.document.mainForm.txtPC1.focus();
}

function VerificaCodigoPostal(strMensaje1, strMensaje2, strMensaje3)
{
   	var msgError01 = 'PLEASE TYPE THE POSTAL CODE';
	with(window.document)
	{
		var pc1 = getElementById('txtPC1').value;
		var pc2 = getElementById('txtPC2').value;

  if(fLayOutPC(pc1+pc2,strMensaje1) == false)
    return

		//var IdPerson = getElementById('txtIdPerson').value;

		Mensaje1 = strMensaje1; Mensaje2 = strMensaje2;	Mensaje3 = strMensaje3;

		if(pc1.length!=3 || pc2.length!=3) { alert(msgError01); return; }
		//ECC2007.07.19 Si lo que va a salvar es igual a lo que consulta cerrar de inmediato ventana emergente.
		if((pc1 + pc2) == getElementById('hdnPC').value) { self.close(); return; }
	  	getElementById('enter2').style.display = '';
		getElementById('btnGo').disabled = true;
		getElementById('txtPC1').disabled = true;
		getElementById('txtPC2').disabled = true;
		getElementById('hdnPostalCode').value = pc1 + pc2;

		fSubmit2('updPostalCode.asp?okBuscar=1&hdnPostalCode='+getElementById('hdnPostalCode').value+'&txtIdPerson='+getElementById('txtIdPerson').value);

		//var strurl = 'ValidaCodigoPostal.asp?idPerson='	+ IdPerson + '&PostalCode=' + pc1 + pc2;
		//document.write(strurl); return;
		//alert(strurl); return;
	}
}
//------------------------------------------------------------------------------
	function fLayOutPC(pPC,pMessage)
	{
		if(pPC.length != 6){
			alert(pMessage);
			return false;
		}
		//Valiadamos los caracteres
		if(isNaN(pPC.substr(0,1))==false || isNaN(pPC.substr(2,1))==false || isNaN(pPC.substr(4,1))==false)
		{
			alert(pMessage);
			return false
		}
		//Valiadamos los numeros
		if(isNaN(pPC.substr(1,1))==true || isNaN(pPC.substr(3,1))==true || isNaN(pPC.substr(5,1))==true)
		{
			alert(pMessage);
			return false
		}
		return true
	}
//------------------------------------------------------------------------------

//ECC2007.07.20 Refresca páginas de Employee una vez actualizado Postal Code en ventana emergente.
function refreshPC()
{
	var newLocation = '../../comun/home/portada.asp'
	with(window)
	{
		opener.location.reload();
		with(opener.top.frames['contenido']) //ECC2007.07.19
		{
	   	   if(document.getElementById('sec_num') != null)
	   	   {
			if(document.getElementById('sec_num').value == 'sec 1')
			{
/*				var tipoBusqueda = document.mainForm.tipoBusqueda.value;
				var idFamilia = document.mainForm.idFamilia.value;
				var idNegocio = document.mainForm.idNegocio.value;
				var idLinea = document.mainForm.idLinea.value;
				var idSublinea = document.mainForm.idSublinea.value;
				var idPlataforma = document.mainForm.idPlataforma.value;
				var newLocation = "../../tienda/catalogo/listaProductos.asp?tipoBusqueda="+tipoBusqueda+"&idFamilia="+idFamilia+"&idNegocio="+idNegocio+"&idLinea="+idLinea+"&idSublinea="+idSublinea+"&idPlataforma="+idPlataforma*/
				var newLocation = "../../comun/home/portada.asp";
			}
			if(document.getElementById('sec_num').value == 'sec 2')
			{
			      document.getElementById('a_pagar').style.display = 'none';
			      document.getElementById('a_espere').style.display = '';
			      newLocation = '../../tienda/compra/carrito.asp';
                        }
			else if(document.getElementById('sec_num').value == 'sec 3')
			      newLocation = '../../tienda/compra/carrito.asp';

		   }
		   location.href= newLocation;
		}
	}
        self.close();
}

//ECC2007.07.23 Funciones generales ajax.
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
var xmlHttp, xmlHttp2;
//function GetProvinces(pObj){
//	if (pObj.selectedIndex == 0)	return;
//	fajax(pObj,2)
//}

function GetXmlHttpObject(handler)
{
	var objXMLHttp=null;
	if(window.XMLHttpRequest)
	   objXMLHttp = new XMLHttpRequest(); //Fire Fox
	else if (window.ActiveXObject)
	   objXMLHttp = new ActiveXObject('Microsoft.XMLHTTP'); //IE
	else
	   { alert('El navegador no soporta el objeto XMLHttp'); return; }
	return objXMLHttp;
}

function fajaxEB(url, iopcion)
{
  xmlHttp = GetXmlHttpObject();
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	xmlHttp.open('GET',url,true);
	xmlHttp.onreadystatechange = stateChangedEB;
	xmlHttp.send(null);
  }
}

//-----------------------------------------
function fMultyAjaxEB(PageRef, Params)
{
  xmlHttp = GetXmlHttpObject();
  var tmpurl= PageRef + '?' + Params + '&sid=' + Math.random();
  if((xmlHttp.readyState == 4)||(xmlHttp.readyState == 0))
  {
	xmlHttp.open('GET',tmpurl,true);
	xmlHttp.onreadystatechange = fMultystateChanged;
	xmlHttp.send(null);
  }
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++

function emailCheck(texto)
{
	var mailres = true;
	var cadena = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-';
	var nArrobas = 0;
	var arroba = texto.indexOf('@',0);
	if ((texto.lastIndexOf('@')) != arroba) arroba = -1;
	var punto = texto.lastIndexOf('.');
	if(arroba == -1 || punto == -1)  mailres = false;

         for(var contador = 0 ; contador < texto.length ; contador++)
         {
            if(cadena.indexOf(texto.substr(contador, 1),0) > 0 && texto.substr(contador, 1) == '@') nArrobas += 1;
	    if(cadena.indexOf(texto.substr(contador, 1),0) == -1 || nArrobas > 1) { mailres = false; break; }
	 }

	return mailres;
}


function fLengthPhone(pObj,pLong,pNextObj)
{
  if(pObj.value.length == pLong) pNextObj.focus();
}

function fmayuscula()
{
   window.event.keyCode = String.fromCharCode(window.event.keyCode).toUpperCase().charCodeAt(0);
}

//ECC2007.07.24 Para retener valor en un hidden de una selección por combo.
function VerificaValor(objDest,objFuente)
{
   objDest.value = objFuente.options[objFuente.selectedIndex].value;
}

//ECC2007.07.24 Receptor de AjaxEB para resultado del ciudad y provincia en base al Código Postal.
function stateChangedEB()
{
  var results, results2, bOKAll = true;
  with(window.document) //ECC2007.07.23
  {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        {
		results = xmlHttp.responseText.split('@|');
		if(results[0].toString().length > 0)
                {
			//getElementById('delete').innerHTML = results[0];
			if(results[0].indexOf('nada')==-1)
                        {
				//alert(results2);
				results2 = results[0].toString().split('|');
				idCity = results2[1]; idProvince = results2[2];
				getElementById('txt_city').innerHTML = results2[1];
				getElementById('txt_province').innerHTML = results2[2];
			
		try{
			if(getElementById('chkTermsCond').checked==true) //20 de enero dcmticly valida si ya Acepto los terminos
				{
				getElementById('button').disabled=false;
				}
 }
		  catch(e)
		  {
		  var strMensaje
		  strMensaje = e
		  }
				//20 de enero dcmticly habilita  el boton
				//alert(getElementById('city'));
					
			if (getElementById('city')!=null)
				{
					getElementById('city').value = results2[1];
					getElementById('province').value = results2[2];

					//20 de enero dcmticly habilita si el boton
					//alert(getElementById('city').value);
					//alert(getElementById('province').value);
				}
		/* else
		 
		 {
		 					
			try{
					if(getElementById('chkTermsCond').checked==true) // 20 de enero dcmticlyvalida si ya acepto los terminos
					{
					getElementById('button').disabled=false;
					}
					 }
		  catch(e)
		  {
		  var strMensaje
		  strMensaje = e
		  }
		 
		 }*/
				getElementById('PC').value = getElementById('txt_PC').value + getElementById('txt_PC2').value;
			}
                        else bOKAll = false;
		}
		else bOKAll = false;

		if(!bOKAll)
                {
		   idCity = ''; idProvince = '';
		   getElementById('txt_city').innerHTML = 'postal code not found';
		   getElementById('txt_province').innerHTML = 'postal code not found';
		   try
		   {
		  if(getElementById('chkTermsCond').checked==true) // 20 de enero dcmticly si estan Aceptados los terminos los desmarca  esto eso para que vuelva a validar si ya se 
{         getElementById('chkTermsCond').checked=false;                // se habilito el boton y mete un código no valido no deja marcarlo hasta que tengas un CP Valido 
		  getElementById('button').disabled=true;} // 20 enero dcmticly se agrego para deshabilitar el button si hay un not found
		  }
		  catch(e)
		  {
		  var strMensaje
		  strMensaje = e
		  }		 
		}
	 }
   }
}

function fValidPhone(str3918,str3919,oFrm)
{
   var yes1, yes2;
   with(oFrm) //ECC2007.07.23
   {
	if((trim(txt_TelDay.value) != '') || (trim(txt_TelDay1.value) != '') || (trim(txt_TelDay2.value) != ''))
        {
		if((txt_TelDay.value == '') || (txt_TelDay1.value == '') || (txt_TelDay2.value == ''))
                { alert(str3918); txt_TelDay.focus(); return false; }
		else
                {
			if((txt_TelDay.value.length == 3 ) && (txt_TelDay1.value.length == 3) && (txt_TelDay2.value.length == 4))
			   yes1 = 1;
			else {	alert(str3919); txt_TelDay.focus(); return false; }
		}
	}
	else
	{
			if((txt_TelDay.value.length == 3) && (txt_TelDay1.value.length == 3) && (txt_TelDay2.value.length == 4))
			   yes1 = 1;
			else { alert(str3919); txt_TelDay.focus(); return false; }

	}

	if((trim(txt_TelEve2.value) != '') || (trim(txt_TelEve1.value) != '') || (trim(txt_TelEve.value) != ''))
        {
		if((txt_TelEve2.value == '') || (txt_TelEve1.value == '') || (txt_TelEve.value == ''))
                { alert(str3918); txt_TelEve.focus(); return false; }
		else
                {
			if ((txt_TelEve.value.length == 3) && (txt_TelEve1.value.length == 3) && (txt_TelEve2.value.length == 4))
			   yes2 = 1;
			else { alert(str3919); txt_TelEve.focus(); return false; }
		}
	}
	/*else
        {
			if((txt_TelEve.value.length == 3) && (txt_TelEve1.value.length == 3) && (txt_TelEve2.value.length == 4))
			   yes2 = 1;
			else { alert(str3919); txt_TelEve.focus();return false; }
	}*/

   }
   if((yes1 == 1 || yes2 == 1)) return true;
}

function DeliveryInf(campo,pCP1,pCP2)
{
  ObjForm = window.document.mainForm
	var arrDelivery = '';
  var strDelivery = ObjForm.Delivery.value;
	ObjForm.txt_firstname.value = '';
	ObjForm.txt_lastname.value = '';
	ObjForm.txt_addres.value = '';
	ObjForm.txt_addres2.value = '';
	ObjForm.txt_PC.value = pCP1;
	ObjForm.txt_PC2.value = pCP2;
	ObjForm.txt_TelDay.value = '';
	ObjForm.txt_TelDay1.value = '';
	ObjForm.txt_TelDay2.value = '';
	ObjForm.txt_TelDayExt.value = '';
	ObjForm.txt_TelEve.value = '';
	ObjForm.txt_TelEve1.value = '';
	ObjForm.txt_TelEve2.value = '';
	ObjForm.txt_TelEveExt.value = '';
	ObjForm.txt_Email.value = '';
	if(ObjForm.chkDelivery.checked && strDelivery != '')
	{
	 arrDelivery = strDelivery.split('|');
   	 ObjForm.txt_firstname.value = arrDelivery[0];
   	 ObjForm.txt_lastname.value = arrDelivery[1];
   	 ObjForm.txt_addres.value = arrDelivery[2];
   	 ObjForm.txt_addres2.value = arrDelivery[3];
   	 ObjForm.txt_PC.value = arrDelivery[4];
   	 ObjForm.txt_PC2.value = arrDelivery[5];
   	 ObjForm.txt_PC.value = ObjForm.txt_PC.value.toUpperCase();
   	 ObjForm.txt_PC2.value = ObjForm.txt_PC2.value.toUpperCase();
   	 ObjForm.txt_TelDay.value = arrDelivery[6];
   	 ObjForm.txt_TelDay1.value = arrDelivery[7];
   	 ObjForm.txt_TelDay2.value = arrDelivery[8];
   	 ObjForm.txt_TelDayExt.value = arrDelivery[9];
   	 ObjForm.txt_TelEve.value = arrDelivery[10];
   	 ObjForm.txt_TelEve1.value = arrDelivery[11];
   	 ObjForm.txt_TelEve2.value = arrDelivery[12];
   	 ObjForm.txt_TelEveExt.value = arrDelivery[13];
   	 ObjForm.txt_Email.value = arrDelivery[14];
	}
	fGetCityProvice();
}
//==================================================================

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}





