
addEvent(window,'load',inicializarEventos,false);

function inicializarEventos()
{
  var ob_nom=document.getElementById('dir');
  addEvent(ob_nom,'blur',cambioObjeto,false);
}

function cambioObjeto(e)
{
  var ob_nom1=document.getElementById('dir');
  ob_nom1.value = ob_nom1.value.replace(/Carrera/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Karrera/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Carrer/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Carre/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Carr/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Cra/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Krr/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Crr/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Car/gi,"KR");  
  ob_nom1.value = ob_nom1.value.replace(/Kra/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Cr/gi,"KR");
  ob_nom1.value = ob_nom1.value.replace(/Calle/gi,"CL");
  ob_nom1.value = ob_nom1.value.replace(/Call/gi,"CL");
  ob_nom1.value = ob_nom1.value.replace(/Cll/gi,"CL");
  ob_nom1.value = ob_nom1.value.replace(/Cal/gi,"CL");
  ob_nom1.value = ob_nom1.value.replace(/Avenida/gi,"AV");
  ob_nom1.value = ob_nom1.value.replace(/Avenid/gi,"AV");
  ob_nom1.value = ob_nom1.value.replace(/Aveni/gi,"AV");
  ob_nom1.value = ob_nom1.value.replace(/Aven/gi,"AV");
  ob_nom1.value = ob_nom1.value.replace(/Ave/gi,"AV");
  ob_nom1.value = ob_nom1.value.replace(/Diagonal/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Diagona/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Diagon/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Diago/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Diag/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Dia/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Di/gi,"DG");
  ob_nom1.value = ob_nom1.value.replace(/Autopista/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Autopist/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Autopis/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Autopi/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Autop/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Auto/gi,"AUTOP");
  ob_nom1.value = ob_nom1.value.replace(/Aut/gi,"AUTOP");  
  ob_nom1.value = ob_nom1.value.replace(/Manzana/gi,"MZ");
  ob_nom1.value = ob_nom1.value.replace(/Manzan/gi,"MZ");
  ob_nom1.value = ob_nom1.value.replace(/Manza/gi,"MZ");
  ob_nom1.value = ob_nom1.value.replace(/Manz/gi,"MZ");
  ob_nom1.value = ob_nom1.value.replace(/Man/gi,"MZ");
  ob_nom1.value = ob_nom1.value.replace(/Kilometro/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kilometr/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kilomet/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kilome/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kilom/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kilo/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Kil/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Ki/gi,"KM");
  ob_nom1.value = ob_nom1.value.replace(/Transversal/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Transversa/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Transvers/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Transver/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Transve/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Transv/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Trans/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Tran/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Tra/gi,"TV");
  ob_nom1.value = ob_nom1.value.replace(/Casa/gi,"CA");
  ob_nom1.value = ob_nom1.value.replace(/Cas/gi,"CA");
  ob_nom1.value = ob_nom1.value.replace(/Apartamento/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apartament/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apartamen/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apartame/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apartam/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Aparta/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apart/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apar/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apto/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Apt/gi,"AP");
  ob_nom1.value = ob_nom1.value.replace(/Bloque/gi,"BL");
  ob_nom1.value = ob_nom1.value.replace(/Bloqu/gi,"BL");
  ob_nom1.value = ob_nom1.value.replace(/Bloq/gi,"BL");
  ob_nom1.value = ob_nom1.value.replace(/Blo/gi,"BL");
  ob_nom1.value = ob_nom1.value.replace(/Interior/gi,"IN");
  ob_nom1.value = ob_nom1.value.replace(/Interio/gi,"IN");
  ob_nom1.value = ob_nom1.value.replace(/Interi/gi,"IN");
  ob_nom1.value = ob_nom1.value.replace(/Inter/gi,"IN");
  ob_nom1.value = ob_nom1.value.replace(/Int/gi,"IN");
  ob_nom1.value = ob_nom1.value.replace(/Torre/gi,"TO");
  ob_nom1.value = ob_nom1.value.replace(/Torr/gi,"TO");
  ob_nom1.value = ob_nom1.value.replace(/Tor/gi,"TO");
  ob_nom1.value = ob_nom1.value.replace(/Piso/gi,"PI");
  ob_nom1.value = ob_nom1.value.replace(/Pis/gi,"PI");
  ob_nom1.value = ob_nom1.value.replace(/Numero/gi,"#");
  ob_nom1.value = ob_nom1.value.replace(/Num/gi,"#");
  ob_nom1.value = ob_nom1.value.replace(/No/gi,"#");
}


//***************************************
//Funciones comunes a todos los problemas
//***************************************

function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}



function suscripcionBoletin(email){

	//Copia el contenido original en el backup para poder usar el volver
	document.getElementById('newsletter_orig').innerHTML = document.getElementById('newsletter_fieldset').innerHTML;

	if (email != 'E-mail'){
		if (validar_email(email)){
			getDataV1('suscripcionBoletin','ajax.php?object=suscripcionBoletin&email='+email,'newsletter_fieldset','');
		}
		else{
			document.getElementById('newsletter_fieldset_error').style.display = '';
			document.getElementById('newsletter_fieldset').style.display = 'none';
		}
	}
}

function newsletterVolver(){
	document.getElementById('newsletter_fieldset_error').style.display = 'none';
	document.getElementById('newsletter_fieldset').innerHTML = document.getElementById('newsletter_orig').innerHTML
	document.getElementById('newsletter_fieldset').style.display = '';
}

//Añadir a favoritos desde la pagina de detalle de catalogo, con reload
function addProdFavorito(e,id_prod,reload,nom_prod){
	
	var caso = '';
	if (reload == 1)	caso = 'addProdFavorito';

	if (userLogin()){
		if (id_prod > 0){
			getDataV1(caso,'ajax.php?object=addProdFavorito&id_prod='+id_prod,'favorito_rta','');
		
			var inner_v = '<p class="title">' + nom_prod + '</p><p>ha sido a&ntilde;adido a tu lista de favoritos</p>';
			alertLoginFav('mostrar',inner_v,e,reload);
		}
	}
	else{
		var inner_v = '<p class="alert_two"><span>Para a&ntilde;adir este producto a tus favoritos debes ingresar<br />';
		inner_v += 'con tu c&eacute;dula y contrase&ntilde;a en  la parte superior derecha.<br /><br />Si a&uacute;n no eres cliente <br />';
		inner_v += 'platinum haz</span><a href="registro/cliente/"> click aqu&iacute; </a><span>para registrarte.</span>';
		inner_v += '</p>';
		alertLoginFav('mostrar',inner_v,e,0);
	}
}

//Añadir a favoritos desde la pagina de detalle de producto, osea, sin reload
/*
function addProdFavoritoDetail(e,id_prod){
	
	if (userLogin()){
		if (id_prod > 0){

			getDataV1('','ajax.php?object=addProdFavorito&id_prod='+id_prod,'favorito_rta','');

			var inner_v = '<p><span>Producto a&ntilde;adido a sus favoritos<br />';
			inner_v += '</p>';
			alertLoginFav('mostrar',inner_v,e);
		}
	}
	else{

		var inner_v = '<p><span>Para a&ntilde;adir este producto a tus favoritos debes ingresar<br />';
		inner_v += 'con tu c&eacute;dula y contrase&ntilde;a en  la parte superior derecha.<br /><br />Si a&uacute;n no eres cliente <br />';
		inner_v += 'platinum has</span><a href="#"> click aqu&iacute; </a><span>para registrarte.</span>';
		inner_v += '</p>';

		alertLoginFav('mostrar',inner_v,e);
	}
}
*/

function delProdFavorito(e,id_prod,reload,nom_prod){
	
	var caso = '';
	if (reload == 1)	caso = 'delProdFavorito';
	
	if (id_prod > 0){
		getDataV1(caso,'ajax.php?object=delProdFavorito&id_prod='+id_prod,'favorito_rta','');
		
		var inner_v = '<p class="title">' + nom_prod + '</p><p><span>Producto eliminado de tu lista de favoritos</span></p>';
		alertLoginFav('mostrar',inner_v,e,reload);
		
	}
}

function userLogin(){
	if (document.getElementById('btn_login_out') == undefined)	return false;
	else					return true;
}


function alertEncuesta(accion,e,texto_enc_sat,reload){

    var reload_js = '';
	if (reload == 1){
     var inner_v = '<h4 style="font-size:14px; font-weight:normal; color:#8EB448; margin-top:30px; margin-bottom:20px; padding-bottom:0;">';
		inner_v += texto_enc_sat+'</h4><p>';
		inner_v += 'Tu opini&oacute;n es importante para nuestro continuo mejoramiento.<br/>Si eres elegido en el sorteo te estaremos contactando.';
		inner_v += '</p>';
    }
	
	else {
    var inner_v = '<h4 style="font-size:14px; font-weight:normal; color:#8EB448; margin-top:30px; margin-bottom:20px; padding-bottom:0;">Para participar en el sorteo debes<br />haber diligenciado<br />';
		inner_v += 'la '+texto_enc_sat+'.</h4><p>';
		inner_v += 'Tu opini&oacute;n es importante para nosotros.';
		inner_v += '</p>';
	}
	
	//Ancho de la imagen de fondo del alert 
	var w_div = 340;
	var h_div = 142;

	//Valor de left para que siempre salga en el centro
	var left_v = (docwidth() - w_div) / 2;
	var top_v = (docVisibleHeight() - h_div) / 2;

	obj_fondo = document.getElementById('div_bcg');

	if (accion == 'mostrar'){

		var inner_v = '<div class="log">' + inner_v + '</div>';
		inner_v += '<a href="#" onclick="alertEncuesta(\'ocultar\',event,\'\',0); '+reload_js+'; return false;"><div class="bot_acept"><p>Aceptar</p></div></a>';


		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{
			var alerta = document.getElementById('alert');
			if (alerta != undefined) document.body.removeChild(alerta);

			obj_fondo.style.display = '';
		} 

		var div = document.createElement('div');
		div.id = 'alert';
		div.style.zIndex = 500;
		div.style.left = left_v + 'px';
		div.innerHTML = inner_v;
		div.className = 'fixed';

		if (getBrowser() != 'ie'){
			div.style.top = top_v + 'px';
			div.style.position = 'fixed';
		}
		else{
			//crea el iframe para el combo de marca quede por debajo
			var iframe = document.createElement('iframe');
			iframe.id = 'iframe_bcg';
			iframe.style.width = docwidth() + 'px';
			iframe.style.height = docheight() + 'px';
			iframe.style.top = 0;
			iframe.style.left = 0;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.style.position = 'absolute';
			iframe.style.zIndex = 3;
			document.body.appendChild(iframe);

		}
		document.body.appendChild(div);
	}
	else{

		document.body.removeChild(document.getElementById('alert'));
		if (getBrowser() == 'ie')	document.body.removeChild(document.getElementById('iframe_bcg'));
		obj_fondo.style.display = 'none';
	}

} // Fin de la función alertEncuesta.



function alertTirilla(accion,e){
  
    var inner_2  = '<a href="registra_compra/formulario/" onclick="alertTirilla(\'ocultar\',event); return false;">';
	    inner_2 += '<img src="../img/tirilla_factura.png" alt="Tirilla" align="center" />';
		inner_2 += '</a>';
		
	//Ancho de la imagen de fondo del alert 
	var w_div = 455;  // Ancho 340  406 455 
	var h_div = 600;  // Alto  142  502 600

	//Valor de left para que siempre salga en el centro
	var left_v = (docwidth() - w_div) / 2;
	var top_v = (docVisibleHeight() - h_div) / 2;

	obj_fondo = document.getElementById('div_bcg');

	if (accion == 'mostrar'){

		var inner_v = '<div class="log">' + inner_2 + '</div>';
		inner_v += '<a href="registra_compra/formulario/" onclick="alertTirilla(\'ocultar\',event); return false;"></a>';


		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{
			var alerta = document.getElementById('alert');
			if (alerta != undefined) document.body.removeChild(alerta);

			obj_fondo.style.display = '';
		} 

		var div = document.createElement('div');
		div.id = 'alert';
		div.style.zIndex = 500;
		div.style.left = left_v + 'px';
		div.innerHTML = inner_v;
		div.className = 'fixed';

		if (getBrowser() != 'ie'){
			div.style.top = top_v + 'px';
			div.style.position = 'fixed';
		}
		else{
			//crea el iframe para el combo de marca quede por debajo
			var iframe = document.createElement('iframe');
			iframe.id = 'iframe_bcg';
			iframe.style.width = docwidth() + 'px';
			iframe.style.height = docheight() + 'px';
			iframe.style.top = 0;
			iframe.style.left = 0;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.style.position = 'absolute';
			iframe.style.zIndex = 3;
			document.body.appendChild(iframe);

		}
		document.body.appendChild(div);
	}
	else{

		document.body.removeChild(document.getElementById('alert'));
		if (getBrowser() == 'ie')	document.body.removeChild(document.getElementById('iframe_bcg'));
		obj_fondo.style.display = 'none';
	}

} // Fin de la función alertTirilla (muestra una imagen)



function alertExisteCedula(accion,inner,e,reload){
     
	var inner_2 = '<p class="alert_two"><span><br /><br />Tu c&eacute;dula a&uacute;n no se encuetra registrada.<br />';
		inner_2 += 'Para registrarte en Fedco Platinum haz </span><a href="registro/cliente/"> click aqu&iacute; </a><span>.</span>';
		inner_2 += '</p>';
	
	var reload_js = '';
	if (reload == 1)	reload_js = 'location.reload()';
	
	//Ancho de la imagen de fondo del alert 
	var w_div = 340;
	var h_div = 142;

	//Valor de left para que siempre salga en el centro
	var left_v = (docwidth() - w_div) / 2;
	var top_v = (docVisibleHeight() - h_div) / 2;

	obj_fondo = document.getElementById('div_bcg');

	if (accion == 'mostrar'){

		var inner_v = '<div class="log">' + inner_2 + '</div>';
		inner_v += '<a href="#" onclick="alertExisteCedula(\'ocultar\',\'\',event);'+reload_js+';return false;"><div class="bot_acept"><p>Aceptar</p></div></a>';


		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{
			var alerta = document.getElementById('alert');
			if (alerta != undefined) document.body.removeChild(alerta);

			obj_fondo.style.display = '';
		} 

		var div = document.createElement('div');
		div.id = 'alert';
		div.style.zIndex = 500;
		div.style.left = left_v + 'px';
		div.innerHTML = inner_v;
		div.className = 'fixed';

		if (getBrowser() != 'ie'){
			div.style.top = top_v + 'px';
			div.style.position = 'fixed';
		}
		else{
			//crea el iframe para el combo de marca quede por debajo
			var iframe = document.createElement('iframe');
			iframe.id = 'iframe_bcg';
			iframe.style.width = docwidth() + 'px';
			iframe.style.height = docheight() + 'px';
			iframe.style.top = 0;
			iframe.style.left = 0;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.style.position = 'absolute';
			iframe.style.zIndex = 3;
			document.body.appendChild(iframe);

		}
		document.body.appendChild(div);
	}
	else{

		document.body.removeChild(document.getElementById('alert'));
		if (getBrowser() == 'ie')	document.body.removeChild(document.getElementById('iframe_bcg'));
		obj_fondo.style.display = 'none';
	}

}



function alertMensajes(accion,inner,e,reload){
     
	inner_2 = '<p class="alert_two"><span>'+ inner +'</span></p>';
	
	var reload_js = '';
	if (reload == 1)	reload_js = 'location.reload()';
	
	//Ancho de la imagen de fondo del alert 
	var w_div = 340;
	var h_div = 142;

	//Valor de left para que siempre salga en el centro
	var left_v = (docwidth() - w_div) / 2;
	var top_v = (docVisibleHeight() - h_div) / 2;

	obj_fondo = document.getElementById('div_bcg');

	if (accion == 'mostrar'){

		var inner_v = '<div class="log">' + inner_2 + '</div>';
		inner_v += '<a href="#" onclick="alertMensajes(\'ocultar\',\'\',event);'+reload_js+';return false;"><div class="bot_acept"><p>Aceptar</p></div></a>';


		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{
			var alerta = document.getElementById('alert');
			if (alerta != undefined) document.body.removeChild(alerta);

			obj_fondo.style.display = '';
		} 

		var div = document.createElement('div');
		div.id = 'alert';
		div.style.zIndex = 500;
		div.style.left = left_v + 'px';
		div.innerHTML = inner_v;
		div.className = 'fixed';

		if (getBrowser() != 'ie'){
			div.style.top = top_v + 'px';
			div.style.position = 'fixed';
		}
		else{
			//crea el iframe para el combo de marca quede por debajo
			var iframe = document.createElement('iframe');
			iframe.id = 'iframe_bcg';
			iframe.style.width = docwidth() + 'px';
			iframe.style.height = docheight() + 'px';
			iframe.style.top = 0;
			iframe.style.left = 0;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.style.position = 'absolute';
			iframe.style.zIndex = 3;
			document.body.appendChild(iframe);

		}
		document.body.appendChild(div);
	}
	else{

		document.body.removeChild(document.getElementById('alert'));
		if (getBrowser() == 'ie')	document.body.removeChild(document.getElementById('iframe_bcg'));
		obj_fondo.style.display = 'none';
	}

}



function alertLoginFav(accion,inner,e,reload){

	var reload_js = '';
	if (reload == 1)	reload_js = 'location.reload()';
	
	//Ancho de la imagen de fondo del alert 
	var w_div = 340;
	var h_div = 142;

	//Valor de left para que siempre salga en el centro
	var left_v = (docwidth() - w_div) / 2;
	var top_v = (docVisibleHeight() - h_div) / 2;

	obj_fondo = document.getElementById('div_bcg');

	if (accion == 'mostrar'){

		var inner_v = '<div class="log">' + inner + '</div>';
		inner_v += '<a href="#" onclick="alertLoginFav(\'ocultar\',\'\',event);'+reload_js+';return false;"><div class="bot_acept"><p>Aceptar</p></div></a>';


		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{
			var alerta = document.getElementById('alert');
			if (alerta != undefined) document.body.removeChild(alerta);

			obj_fondo.style.display = '';
		} 

		var div = document.createElement('div');
		div.id = 'alert';
		div.style.zIndex = 500;
		div.style.left = left_v + 'px';
		div.innerHTML = inner_v;
		div.className = 'fixed';

		if (getBrowser() != 'ie'){
			div.style.top = top_v + 'px';
			div.style.position = 'fixed';
		}
		else{
			//crea el iframe para el combo de marca quede por debajo
			var iframe = document.createElement('iframe');
			iframe.id = 'iframe_bcg';
			iframe.style.width = docwidth() + 'px';
			iframe.style.height = docheight() + 'px';
			iframe.style.top = 0;
			iframe.style.left = 0;
			iframe.style.filter = 'alpha(opacity=0)';
			iframe.style.position = 'absolute';
			iframe.style.zIndex = 3;
			document.body.appendChild(iframe);

		}
		document.body.appendChild(div);
	}
	else{

		document.body.removeChild(document.getElementById('alert'));
		if (getBrowser() == 'ie')	document.body.removeChild(document.getElementById('iframe_bcg'));
		obj_fondo.style.display = 'none';
	}

}


//usa jquery.dimensions
function docwidth(){
	return $(document).width();
}
function docheight(){
	return $(document).height();
}
function docVisibleHeight(){

	if (self.innerWidth)
	{
		HeightW = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		HeightW = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		HeightW = document.body.clientHeight;
	}

	/*
	HeightS = document.body.scrollHeight;

	if (HeightW > HeightS)	return HeightW;
	else					return HeightS;
	*/

	return HeightW;
}

function validar_email(email_text){

	//re = /(\w+@[0-9a-zA-Z_]+?\.[a-zA-Z]{2,6})/;
	re = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;

	if(email_text.match(re))	return true
	else				return false;
}

function validarNum(e){
    
	var tecla = (e.which) ? e.which : e.keyCode;
	
	//Acepta backspace=8, left arrow=37, right arrow=39, delete=46, tab=9
    if (tecla == 8 || tecla == 9 || tecla == 37 || tecla == 39 || tecla == 46){
		return true;
	}

    var patron = /\d/;
    var te = String.fromCharCode(tecla);

    return patron.test(te);
}


//Elementos: String que tiene nombre_campo_forma,etiqueta_campo
//campo_email: valor del campo de email a validar, vacio si la forma no tiene este campo
function validar_forma(elementos,campo_email){
	var ElementosForma = elementos.split(",");
	var Error = "Los siguientes campos son requeridos:\n\n";
	var Error_i = 0;

	for (i=0;i<ElementosForma.length;i++){
		if (document.getElementById(ElementosForma[i]).type == "text" || document.getElementById(ElementosForma[i]).type == "password" || document.getElementById(ElementosForma[i]).type == "textarea" || document.getElementById(ElementosForma[i]).type == "select-multiple" || document.getElementById(ElementosForma[i]).type == "select-one" || document.getElementById(ElementosForma[i]).type == "file"){
			if (document.getElementById(ElementosForma[i]).value == ""){
				Error += "- " + ElementosForma[i+1] + "\n";
				Error_i = 1;
			}
		}
		else if (document.getElementById(ElementosForma[i]).type == "radio" || document.getElementById(ElementosForma[i]).type == "checkbox"){
			if (document.getElementById(ElementosForma[i]).checked == false){
				Error += "- " + ElementosForma[i+1] + "\n";
				Error_i = 1;
			}
		}

		i++;
	}

	if (Error_i == 1){
		alert(Error);
		return false;
	}
	else{
		if (campo_email != ""){
			if(!validar_email(campo_email)){
				alert('Formato de Email incorrecto');
				return false;
			}	 
		}
		else
			return true;
	}
}

function validarFormContacto(){
		
	//Check email
	var e1 = document.getElementById("email").value;
	var e2 = document.getElementById("email2").value;

	if(e1 != e2){
		alert("Los email no coinciden");
		document.getElementById("email").focus();
		return false;
	}

	return validar_forma('nombre,Nombre,apellido,Apellido,email,Email,ciudad,Ciudad,comentario,Comentario',document.getElementById('email').value);
}	

function getClickX(e){

	var IE = document.all ? true:false;
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = e.clientX;

		if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )){
			tempX += document.documentElement.scrollLeft;
		} 
		else if( document.body && ( document.body.scrollTop || document.body.scrollLeft )){
			tempX += document.body.scrollLeft;
		}
	} 
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
	}

	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}

	return tempX;
}

function getClickY(e){

	var IE = document.all ? true:false;
	if (IE) { // grab the x-y pos.s if browser is IE
		tempY = e.clientY;

		if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )){
			tempY += document.documentElement.scrollTop;
		} 
		else if( document.body && ( document.body.scrollTop || document.body.scrollLeft )){
			tempY += document.body.scrollTop;
		}
	} 
	else {  // grab the x-y pos.s if browser is NS
			tempY = e.pageY
	}

	// catch possible negative values in NS4
	if (tempY < 0){tempY = 0}

	return tempY;
}

function showDivEmail(e){

	var IE = document.all ? true:false;
	var offset_x = (docwidth() - (370)) / 2 ;
	var offset_y = 480;

	tempX = getClickX(e);
	tempY = getClickY(e);

	var obj = document.getElementById('sendToFriend');

	if (IE)	var disp = obj.currentStyle.display;
	else	 var disp = document.defaultView.getComputedStyle(obj, null).getPropertyValue("display"); 

	(disp == 'none') ? dis = 'block' : dis = 'none';

	obj.style.left = offset_x + 'px';
	var top =  (docVisibleHeight() - offset_y) / 2 ;

	obj.style.display = dis;
	
	obj.className='fixed';
	if (getBrowser() != 'ie'){
		obj.style.top = top + 'px';
		obj.style.position = 'fixed';
	}
	var obj_fondo = document.getElementById('div_bcg');

	if ( obj_fondo == undefined){
		//Fondo negro
		fondo = document.createElement('div');

		fondo.id = 'div_bcg';
		fondo.style.background = "#6B6B6B";
		fondo.style.opacity = 0.50;
		fondo.style.filter = 'alpha(opacity=50)';
		fondo.style.width = docwidth()+'px';
		fondo.style.height = docheight()+'px';
		fondo.style.zIndex = 5;
		fondo.style.position = 'absolute';
		fondo.style.top = 0;
		fondo.style.left = 0;
		document.body.appendChild(fondo);
	}
	else{
		obj_fondo.style.display = '';
	} 
	

}

function hideDivEmail(){
	document.getElementById('sendToFriend').style.display='none';
	document.getElementById('div_bcg').style.display='none';

	return false;
}
//esconder popup
function hidePopUp(){
	document.getElementById('pop_up2').style.display='none';
	//return false;
}
//Envia un contenido por email
function emailContenido(){

	you_f_n = document.getElementById('you_f_name').value;
	you_l_n = document.getElementById('you_l_name').value;
	you_e = document.getElementById('you_email').value;

	rec_f_n = document.getElementById('rec_f_name').value;
	rec_l_n = document.getElementById('rec_l_name').value;
	rec_e = document.getElementById('rec_email').value;

	copy_v = (document.getElementById('copy').checked == true) ? 1 : 0;
	url = window.location.href;

	if(validar_email(you_e) && validar_email(rec_e)){
		if (you_f_n != "" && you_l_n != "" && you_e != "" && rec_f_n != "" && rec_l_n != "" && rec_e != ""){

			str = 'you_f_name='+you_f_n+'&you_l_name='+you_l_n+'&you_email='+you_e+'&rec_f_name='+rec_f_n+'&rec_l_name='+rec_l_n+'&rec_email='+rec_e+'&copy='+copy_v+'&url='+url;

			getDataV1('','ajax.php?object=emailContenido&'+str,'rta_div_email','inner');
		}
		else	return false;
	}
	else	return false;


}

//Version Print
function printContenido(){

	var Url = location.href;
	Url = Url.replace(/.*\?(.*?)/,"$1");
	Variables = Url.split ("&");
	for (i = 0; i < Variables.length; i++) {
		Separ = Variables[i].split("=");
		eval ('var '+Separ[0]+'="'+Separ[1]+'"');
	}

	window.open('index2.php?print=1&mod=showContent&id_c='+id_c,'','width=600,height=600,top=100,left=100,scrollbars=1');
}

//Version Print Producto
function printProducto(){

	var Url = location.href;
	Url = Url.replace(/.*\?(.*?)/,"$1");
	Variables = Url.split ("&");
	for (i = 0; i < Variables.length; i++) {
		Separ = Variables[i].split("=");
		eval ('var '+Separ[0]+'="'+Separ[1]+'"');
	}

	window.open('index2.php?print=2&mod=showProduct&id_c='+id_c,'','width=900,height=600,top=100,left=100,scrollbars=1');
}

//Version PDF Contenido
function pdfContenido(){

	var Url = location.href;
	Url = Url.replace(/.*\?(.*?)/,"$1");
	Variables = Url.split ("&");
	for (i = 0; i < Variables.length; i++) {
		Separ = Variables[i].split("=");
		eval ('var '+Separ[0]+'="'+Separ[1]+'"');
	}

	location.href='index2.php?pdf=1&mod=showContent&id_c='+id_c,'','width=600,height=600,top=100,left=100,scrollbars=1';
}

//Version PDF Producto
function pdfProducto(){

	var Url = location.href;
	Url = Url.replace(/.*\?(.*?)/,"$1");
	Variables = Url.split ("&");
	for (i = 0; i < Variables.length; i++) {
		Separ = Variables[i].split("=");
		eval ('var '+Separ[0]+'="'+Separ[1]+'"');
	}

	location.href='index2.php?pdf=2&mod=showProducto&id_c='+id_c,'','width=600,height=600,top=100,left=100,scrollbars=1';
}

function showDivEnlarge (div_id,accion){


	var div = document.getElementById("div_" + div_id);
	var obj_fondo = document.getElementById('div_bcg');

	//var w_div = parseInt(div.style.width);
	var w_div = 521;
	var h_div = 400;
	//Valor de left para que siempre salga en el centro
	var left = (docwidth() - w_div) / 2;
	var top = (docVisibleHeight() - h_div) / 2;

	if (accion == 'mostrar'){
		div.style.left = left + 'px';
		div.style.display = '';
		div.className='fixed';
		if (getBrowser() != 'ie'){
			div.style.top = top + 'px';
			div.style.position = 'fixed';
		}

		if ( obj_fondo == undefined){
			//Fondo negro
			fondo = document.createElement('div');

			fondo.id = 'div_bcg';
			fondo.style.background = "#6B6B6B";
			fondo.style.opacity = 0.50;
			fondo.style.filter = 'alpha(opacity=50)';
			fondo.style.width = docwidth()+'px';
			fondo.style.height = docheight()+'px';
			fondo.style.zIndex = 5;
			fondo.style.position = 'absolute';
			fondo.style.top = 0;
			fondo.style.left = 0;
			document.body.appendChild(fondo);
		}
		else{

			obj_fondo.style.display = '';
		} 
	}
	else{
		div.style.display = 'none';
		obj_fondo.style.display = 'none';
	}
}

//Coloca el url a donde debe ir al cambiar la fecha del archivo de noticias, esto se hace para evitar multiples mm_aa en el url
function setUrlComboArchive(valor){

	url = location.href;

	url_tmp = url.split('?');
	args = url_tmp[1];
	url_t = args.split('&');

	args = '';
	for (var i=0;i<url_t.length;i++){

		par = url_t[i].split("=");

		if (par[0] == 'mm_aa')	par[1] = valor;

		if (par[0].indexOf('num_pag') == -1){
			if (args == '')	args = par[0] + '=' + par[1];
			else			args += "&" + par[0] + '=' + par[1];
		} 	
	}

	//Check si esta el parametro mm_aa
	if (url.indexOf('mm_aa') == -1){
		args += '&mm_aa=' + valor;
	}

	return url_tmp[0] + '?' + args;
}

//Retorna el valor de un parametro dado el url y el nombre del parametro
function getUrlParameter(url,parameter){
	url_t = url.split("&");

	for (var i=0;i<url_t.length;i++){

		par = url_t[i].split("=");

		if (par[0] == parameter)	return par[1];	
	}
}

//Login in
function signIn(){
	var u = document.getElementById('usuario').value;
	var p = document.getElementById('pass').value;

	if (u != 'C&eacute;dula' && p != 'Contrase&ntilde;a'){

		//coloca imagen loading
		document.getElementById('btn_login').style.display = 'none';
		document.getElementById('btn_login_loading').style.display = '';

		getDataV1('login','ajax.php?object=signIn&u='+u+'&p='+p,'login_div','inner');
	}
}

//Login out
function signOut(){
	//coloca imagen loading
	document.getElementById('btn_login_out').style.display = 'none';
	document.getElementById('btn_login_loading').style.display = '';

	getDataV1('logout','ajax.php?object=signOut','login_div','inner');
}

function focusLogin(obj){
	if(obj.value == 'C\xe9dula')	obj.value = '';
}

function blurLogin(obj){
	if(obj.value == '') obj.value = 'C\xe9dula';
}

function focusPassword(obj){

	var span = document.getElementById("input_pass");
	var type;
	var value = obj.value;

	if(value == 'Contrase\xf1a'){
		value = '';
		type = 'password';
		span.innerHTML = '<input type="'+type+'" id="pass" value="'+value+'" onfocus="focusPassword(this)" onblur="blurPassword(this)" />';
	}

	setTimeout("document.getElementById('pass').focus()",10);
}

function blurPassword(obj){

	var txt = 'Contrase\xf1a';
	var span = document.getElementById("input_pass");
	var value = obj.value;
	var type;

	if(value == ''){
		value = txt;
		type = 'text';
	}
	else{
		if (value == txt)	type = 'text';
		else				type = 'password';
	}

	span.innerHTML = '<input type="'+type+'" id="pass" value="'+value+'" onfocus="focusPassword(this)" onblur="blurPassword(this)" />';


}


//Login volver
function loginVolver(){
	//coloca imagen loading
	document.getElementById('btn_login_volver').style.display = 'none';
	document.getElementById('btn_login_loading').style.display = '';

	getDataV1('','ajax.php?object=signOut','login_div','inner');
}

//Registro
function registro(paso){
	if (paso == 2){

		var texto_email = document.getElementById('email').value;
		if(validar_forma('nombre,Nombre,apellido,Apellido,email,Email,cedula,C\xe9dula,contrasena,Contrase\xf1a','')){

			//Check solo numero en cedula
			var reg = /[0-9]/;
			var ced = document.getElementById("cedula").value;

			if (!validar_email(texto_email)){
				alert("Email no v\xe1lido");
				document.getElementById('email').focus();
				return false;
			}


			if(!ced.match(reg)){
				alert(latinChars("La c\xe9dula debe contener solo n\xfameros"));
				document.getElementById("cedula").focus();
				return false;
			}

			//Check email
			var e1 = document.getElementById("email").value;
			var e2 = document.getElementById("email2").value;

			if(e1 != e2){
				alert("Los email no coinciden");
				document.getElementById("email").focus();
				return false;
			}

			//Check contrase\xf1a
			var pass1 = document.getElementById("contrasena").value;
			var pass2 = document.getElementById("contrasena2").value;

			if(pass1 != pass2){
				alert("Las contrase\xf1as no coinciden");
				document.getElementById("contrasena").focus();
				return false;
			}

			var div_pasos = document.getElementById('pasos');
			div_pasos.innerHTML = '<div class="pasob1"><a href="#" onclick="registro(1); return false;">Paso 1</a></div><div class="pasob2"><a href="#" onclick="return false;">Paso 2</a></div></div>';

			var fieldset2 = document.getElementById('reg_paso2');
			var fieldset2b = document.getElementById('reg_paso2b');
			var fieldset1 = document.getElementById('reg_paso1');

			fieldset2.style.display = '';
			fieldset1.style.display = 'none';

			var hijos = document.getElementById('num_hijos');
			//if (document.getElementById('tarjetaExtendida').checked == true && hijos.options[hijos.selectedIndex].value > 0){
			if (document.getElementById('tarjetaExtendida').checked == true){
				fieldset2b.style.display = '';
			}
			else{
				fieldset2b.style.display = 'none';
			}
		}
	}

	//submit
	else if (paso == 3){
		if(validar_forma('dia,Dia Nacimiento,mes,Mes Nacimiento,aaaa,A\xf1o Nacimiento,estado_civil,Estado civil,tel,Telefono casa,dir,Direcci\xf3n,ciudad,Ciudad,profesion,Profesi\xf3n','')){

			//var hijos = document.getElementById('num_hijos');
			var ext = document.getElementById('tarjetaExtendida');

			//if (hijos.options[hijos.selectedIndex].value > 0){
			if (ext.checked == true){
				return validar_forma('nombre_p,Nombre Pareja,apellido_p,Apellido Pareja,dia_p,Dia Nacimiento Pareja,mes_p,Mes Nacimiento Pareja,aaaa_p,A\xf1o Nacimiento Pareja,profesion_p,Profesi\xf3n Pareja','');
			}
			/*
			else{
				return true;
			}
*/
			var div_pasos = document.getElementById('pasos');
			div_pasos.innerHTML = '<div class="pasob1"><a href="#" onclick="registro(1); return false;">Paso 1</a></div><div class="pasob2"><a href="#" onclick="return false;">Paso 2</a></div></div>';

			var fieldset2 = document.getElementById('reg_paso2');
			var fieldset2b = document.getElementById('reg_paso2b');
			var fieldset1 = document.getElementById('reg_paso1');

			fieldset2.style.display = '';
			fieldset2b.style.display = 'none';
			fieldset1.style.display = 'none';
		}
		else{
			return false;
		}
	}

	else if (paso == 1){
		var div_pasos = document.getElementById('pasos');
		div_pasos.innerHTML = '<div class="pasoa1"><a href="#" onclick="return false;">Paso 1</a></div><div class="pasoa2"><a href="#" onclick="registro(2); return false;">Paso 2</a></div>';

		var fieldset1 = document.getElementById('reg_paso1');
		var fieldset2b = document.getElementById('reg_paso2b');
		var fieldset2 = document.getElementById('reg_paso2');

		fieldset1.style.display = '';
		fieldset2.style.display = 'none';
		fieldset2b.style.display = 'none';

		return false;
	}
}

function changeInputType(oldObject, oType) {
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);

	return newObject;
}

function getBrowser() {
	var sBrowser = navigator.userAgent;

	if (sBrowser.toLowerCase().indexOf('msie') > 0)
		return 'ie';
	else
		return;
}

//Lista equivalente de tildes
//á = \xe1
//é = \xe9
//í = \xed
//ó = \xf3
//ú = \xfa
//ñ = \xf1
function latinChars(texto){
	var latin = Array("a","e","i","e","u","n");
	var web = Array("\xe1","\xe9","\xed","\xf3","\xfa","\xf1");
	//var web = Array("pppp","iiii","\xed","\xf3","\xfa","\xf1");


	for(var i=0;i<latin.length;i++){
		texto.replace(/latin[i]/,web[i]);
	}

	return texto;
}

function validarForgot(){
	if (validar_forma('email_forgot,E-mail','')){
		
		var texto_email = document.getElementById('email_forgot').value;
		if (!validar_email(texto_email)){
			/*alert("Email no v\xe1lido");
			document.getElementById('email').focus();*/

			var obj = document.getElementById('login_div');

			obj.innerHTML = '<h4>Clientes Platinum</h4><p class="inst">&nbsp;</p><form action="#"><fieldset><p class="logged">Email no v&aacute;lido</p><input type="submit" name="btn_login_volver" id="btn_login_volver" class="btn_log" value="Volver" onclick="loginVolver(); return false;" /><img id="btn_login_loading" src="img/ajax_loading.gif" style="display:none" /></fieldset> </form>';
			
			return false;
		}
		else	return true;
	}
	else{
		return false;
	}
}

function showForgotHtml(){
	var obj = document.getElementById('login_div');

	obj.innerHTML = '<h4>Clientes Platinum</h4><p class="inst">Ingrese su direcci&oacute;n de correo</p><form action="#"><fieldset><input name="email_forgot" type="text" id="email_forgot" value="E-mail" class="mail" onfocus="focusForgot(this)" onblur="blurForgot(this)" /><input type="submit" name="btn_forgot" id="btn_forgot" class="btn_log" value="Enviar" onclick="if (validarForgot()){forgotPassword();}else{return false;}; return false;" /><img id="btn_forgot_loading" src="img/ajax_loading.gif" style="display:none" /></fieldset> </form>';
	
}
//Login in
function forgotPassword(){
	var e = document.getElementById('email_forgot').value;

	if (e != 'E-mail'){

		//coloca imagen loading
		document.getElementById('btn_forgot').style.display = 'none';
		document.getElementById('btn_forgot_loading').style.display = '';

		getDataV1('','ajax.php?object=forgotPassword&e='+e,'login_div','inner');
	}
}

function focusForgot(obj){
	if(obj.value == 'E-mail')	obj.value = '';
}

function blurForgot(obj){
	if(obj.value == '') obj.value = 'E-mail';
}
