function validaMisCompras(Formulario){
	return true;
}

function TogleComentario(id){
	if(xGetElementById('comentarios_container_'+id).style.display == 'none'){
		fadeOutIn('comentarios_container_'+id,'in');
	}else{
		fadeOutIn('comentarios_container_'+id,'out');
	}
}

function DisableCodigo(){
	xGetElementById('promocode').disabled = true;
	xGetElementById('btAplicarCodigo').disabled = true;
}

function EnableCodigo(){
	xGetElementById('promocode').disabled = false;
	xGetElementById('btAplicarCodigo').disabled = false;
}

function EnableForm(){
	xGetElementById('btFinalizarCompra').disabled = false;
}

function DisableForm(){
	xGetElementById('btFinalizarCompra').disabled = true;
}

function ModificarCarro(Accion,Pais,idProd){
	switch (Accion){
		case 'actualizar': 	
			PonerTapa('mc_container_carro');
			PonerMensaje('tapa');
			makeRequest('/ajax-mis-compras.php',GetModificarCarroResult,'POST','accion=Actualizar&Pais='+Pais);
			break;
		case 'remover':
			PonerTapa('mc_container_carro');
			PonerMensaje('tapa');
			makeRequest('/ajax-mis-compras.php',GetModificarCarroResult,'POST','accion=RemoverProducto&idProd='+idProd+'&Pais='+Pais);
			break;
		case 'cantidad':
			PonerTapa('mc_container_carro');
			PonerMensaje('tapa');
			var Cant = xGetElementById('cantidad_'+idProd).value;
			makeRequest('/ajax-mis-compras.php',GetModificarCarroResult,'POST','accion=ActualizarCantProducto&idProd='+idProd+'&Cant='+Cant+'&Pais='+Pais);
			break;
		case 'descuento':
			PonerTapa('mc_container_carro');
			PonerMensaje('tapa');
			var Codigo = xGetElementById('promocode').value;
			makeRequest('/ajax-mis-compras.php',GetModificarCarroResult,'POST','accion=AplicarCodigo&Codigo='+Codigo+'&Pais='+Pais);
			break; 
		case 'comentarios':
			var Comentarios = xGetElementById('comentario_'+idProd).value;
			if(Comentarios == ''){ xGetElementById('ic-comentarios-'+idProd).src = Images_Protocolo+':\/\/'+Images_HostName+'/'+idiomaActual+'/imagenes/ic-mc-comentarios-0.gif'; }else{ xGetElementById('ic-comentarios-'+idProd).src = '/'+idiomaActual+'/imagenes/ic-mc-comentarios-1.gif'; }
			makeRequest('/ajax-mis-compras.php',GetModificarComentariosResult,'POST','accion=GuardarComentariosProducto&idProd='+idProd+'&Comentarios='+Comentarios+'&Pais='+Pais);
			break; 
	}
}

function GetModificarComentariosResult(xmlhttp){}

function GetModificarCarroResult(xmlhttp) {
	switch (xmlhttp.readyState){
		case 1: 			
			//onLoading();
			break;
		case 2:
			//onLoaded();
			break;
		case 3:
			//onInteractive();
			break;
		case 4:
			var responseXML = xmlhttp.responseXML;
		 	var Productos = responseXML.getElementsByTagName('item');
		 	var OfreceHosting = responseXML.getElementsByTagName('mis-compras-ofrecimiento');
			var i, prodId, prodPeriodo, prodModificable, prodDesc, prodCant, prodCostoLista, prodCosto, prodComentario, icComentario;
			var HtmlString = "";
			var FeaturesDedicados,FeaturesString;

			if(Productos.length > 0){
				var confictError = false;
				// Vienen productos -----------------------------------------------
				HtmlString += '<table width="100%" cellpadding="0" cellspacing="0" id="mc_grilla_carro">\n'
				HtmlString += ' <tr>\n'
				HtmlString += '  <td align="left" valign="middle" class="mc_grilla_head"><span>Producto/Servicio</span></td>\n'
				HtmlString += '  <td align="center" valign="middle" width="100" class="mc_grilla_head">Cantidad</td>\n'
				HtmlString += '  <td align="center" valign="middle" width="90" class="mc_grilla_head">Costo Unit.</td>\n'
				HtmlString += '  <td align="center" valign="middle" width="90" class="mc_grilla_head">Costo Total</td>\n'
				HtmlString += ' </tr>\n'
				
				for (i=0; i<Productos.length; i++) {
					FeaturesString = "";
					prodId = Productos[i].getAttribute('id');
					prodPeriodo = Productos[i].getAttribute('periodo');
					if(Productos[i].getAttribute('periodo') == '1000 Años'){
						prodPeriodo = 'Único Pago';
					}
					prodCant = Productos[i].getAttribute('cantidad');
					prodModificable = Productos[i].getAttribute('modificable');
					prodCostoLista = Productos[i].getAttribute('costo_lista') * 1;
					prodCosto = Productos[i].getAttribute('costo') * 1;
					prodDesc = Productos[i].firstChild.nodeValue;
					prodCostoTotal = prodCosto * prodCant * 1;
					prodComentario = Productos[i].getAttribute('comentario');
					conficted = Productos[i].getAttribute('conflicted');
					if(prodComentario == ''){ icComentario = '0'; }else{ icComentario = '1'; }
					
					if(Productos[i].getAttribute('plan') == 'dedicado'){
						FeaturesDedicados = Productos[i].getElementsByTagName('feature');
						for (j=0; j<FeaturesDedicados.length; j++) {
							FeaturesString += '<br />- '+FeaturesDedicados[j].firstChild.nodeValue;
							if(FeaturesDedicados[j].getAttribute('tipo') == 'modelo'){ if((FeaturesDedicados[j].getAttribute('cantidad')*1) > 1){FeaturesString += ' x'+FeaturesDedicados[j].getAttribute('cantidad');}}
							if(FeaturesDedicados[j].getAttribute('tipo') == 'disco'){ FeaturesString += ' HD'; if((FeaturesDedicados[j].getAttribute('cantidad')*1) > 1){FeaturesString += ' (x'+FeaturesDedicados[j].getAttribute('cantidad')+' Discos)';}}
							if(FeaturesDedicados[j].getAttribute('tipo') == 'servicio'){ if((FeaturesDedicados[j].getAttribute('cantidad')*1) > 1){FeaturesString += ' x'+FeaturesDedicados[j].getAttribute('cantidad');}}
						}
					}
	
					prodCostoLista = FormatPrecio(prodCostoLista);
					prodCosto = FormatPrecio(prodCosto);
					prodCostoTotal = FormatPrecio(prodCostoTotal);
					 
					if(conficted > 0){
						confictError = true;
						HtmlString += ' <tr class="conflicted-item" id="fila_'+prodId+'">\n';
					}else{
						HtmlString += ' <tr id="fila_'+prodId+'">\n';
					}
					
					HtmlString += '  <td valign="middle" class="mc_grilla_cell_desc">';
					if (conficted == 0) {
						HtmlString += '    <a href="#" onclick="TogleComentario(\'' + prodId + '\'); return false;" title="Mostrar/Ocultar comentarios para este producto." class="comentarios_ic"><img id="ic-comentarios-' + prodId + '" src="'+Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/ic-mc-comentarios-'+icComentario+'.gif" alt="Escribir un comentario para este producto" border="0" /></a>\n';
					}else{
						if(conficted ==1 ) HtmlString += '<strong>( * ) Usted ya dispone de un servicio asociado a este dominio.</strong><br/>';
						if(conficted ==2 ) HtmlString += '<strong>( * ) El dominio ya esta siendo utilizado por otro usuario.</strong><br/>';
						if(conficted ==3 ) HtmlString += '<strong>( * ) Item duclicado.</strong><br/>';
						if(conficted ==4 ) HtmlString += '<strong>( * ) Dominio inválido.</strong><br/>';
					}
					HtmlString += prodDesc+FeaturesString+'<br />'+prodPeriodo+'<br /><div id="comentarios_container_'+prodId+'" class="mc_comentarios_container" style="display:none">Puede ingresar aquí un comentario para este producto:<br /><textarea name="comentario_'+prodId+'" cols="35" rows="2" class="campo" id="comentario_'+prodId+'" onchange="ModificarCarro(\'comentarios\',\''+codPaisActual+'\',\''+prodId+'\'); return false;">'+prodComentario+'</textarea></div></td>\n'
					HtmlString += '  <td valign="middle" width="95" class="mc_grilla_cell_cant">\n'
					HtmlString += '   <table width="100%" border="0" cellspacing="0" cellpadding="0">\n'
					if(prodModificable == 'S'){
						HtmlString += '    <tr>\n'
						HtmlString += '     <td align="left" valign="middle" width="38" style="padding:4px"><input name="cantidad_'+prodId+'" id="cantidad_'+prodId+'" type="text" class="campo" value="'+prodCant+'" size="2" maxlength="3" onfocus="javascript:this.select();" /></td>\n'
						HtmlString += '     <td align="right" valign="middle"><a href="#" onclick="ModificarCarro(\'cantidad\',\''+codPaisActual+'\',\''+prodId+'\'); return false;" title="Cambiar la cantidad de este producto"><img src="'+Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/bt-mc-actualizar.gif" alt="Actualizar la cantidad de este producto" class="botones_grilla_carro" /></a><br /><a href="#" onclick="ModificarCarro(\'remover\',\''+codPaisActual+'\',\''+prodId+'\'); return false;" title="Quitar este producto de Mis Compras"><img src="'+Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/bt-mc-remover.gif" alt="Quitar este producto de Mis Compras" class="botones_grilla_carro" /></a></td>\n'
						HtmlString += '    </tr>\n'
					} else {
						HtmlString += '    <tr>\n'
						HtmlString += '     <td align="center" valign="middle" width="38" style="padding:4px">'+prodCant+'</td>\n'
						HtmlString += '     <td align="right" valign="middle"><a href="#" onclick="ModificarCarro(\'remover\',\''+codPaisActual+'\',\''+prodId+'\'); return false;" title="Quitar este producto de Mis Compras"><img src="'+Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/bt-mc-remover.gif" alt="Quitar este producto de Mis Compras" class="botones_grilla_carro" /></a></td>\n'
						HtmlString += '    </tr>\n'
					}
					HtmlString += '   </table>\n'
					HtmlString += '  </td>\n'
					if(prodCostoLista == prodCosto){
						HtmlString += '  <td align="right" valign="middle" id="costounitario_'+prodId+'" width="95" class="mc_grilla_cell_costo_unit"><div>'+simboloMoneda+'&nbsp;'+prodCosto+'</div></td>\n'
					} else {
						HtmlString += '  <td align="right" valign="middle" id="costounitario_'+prodId+'" width="95" class="mc_grilla_cell_costo_unit"><div><span class="precio_lista">'+simboloMoneda+'&nbsp;'+prodCostoLista+'</span><br /><span class="su_precio">'+simboloMoneda+'&nbsp;'+prodCosto+'</span></div></td>\n'
					}
					HtmlString += '  <td align="right" valign="middle" id="costototal_'+prodId+'" width="95" class="mc_grilla_cell_costo"><span>'+simboloMoneda+'&nbsp;'+prodCostoTotal+'</span></td>\n'
					HtmlString += ' </tr>\n'
				}		
				HtmlString += '</table>\n';
				if(confictError){
					HtmlString ='<div style="border: 1px solid red; margin: 10px; padding: 5px; background-color: rgb(255, 238, 221); font-size: 12px; color: red; font-weight: bold;">Los articulos marcados con: ( * ) no pueden ser agregados a su orden de compra. Para poder continuar elimine estos articulos.</div>'+HtmlString;
				}
				// Fin vienen productos -----------------------------------------------
			}else{
				// No vienen productos -----------------------------------------------
				HtmlString += '<div class="carro_sin_compras">ATENCION..!<br />Ud. no dispone de ningún producto o servicio entre sus compras.</div>\n'
				// Fin no vienen productos -----------------------------------------------
			}
			
			xGetElementById('contenido_grilla_ajax').innerHTML = HtmlString;
			xGetElementById('subtotal').innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('sub-total')[0].firstChild.nodeValue * 1);
			var tmp = xGetElementById('descuento');
			if(tmp == null){
			}else{
				tmp.innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('descuento')[0].firstChild.nodeValue * 1);
			}
			tmp = xGetElementById('promocode');
			if(typeof(tmp) == 'undefined'){
			}else{
//				var tmp1 = responseXML.getElementsByTagName('codigo');

					tmp.value = '';


			}
			xGetElementById('total').innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('total')[0].firstChild.nodeValue * 1);
			xGetElementById('campo_total').value = responseXML.getElementsByTagName('total')[0].firstChild.nodeValue * 1;
			if((responseXML.getElementsByTagName('descuento')[0].firstChild.nodeValue * 1) > 0){
				setClass(xGetElementById('mc_grilla_div_promocode'),'mc_grilla_div_promocode_aplicado');
				setClass(xGetElementById('mc_grilla_cell_totales_descuento'),'mc_grilla_cell_totales_descuento_aplicado');
				setClass(xGetElementById('mc_grilla_cell_descuento'),'mc_grilla_cell_descuento_aplicado');
				xGetElementById('txt_decuento').innerHTML = '<img src="'+Images_Protocolo+':\/\/'+Images_HostName+'\/'+idiomaActual+'/imagenes/smile.gif" align="absmiddle" /> Descuento:';
			}else{
				setClass(xGetElementById('mc_grilla_div_promocode'),'mc_grilla_div_promocode');
				setClass(xGetElementById('mc_grilla_cell_totales_descuento'),'mc_grilla_cell_totales_descuento');
				setClass(xGetElementById('mc_grilla_cell_descuento'),'mc_grilla_cell_descuento');
				xGetElementById('txt_decuento').innerHTML = 'Descuento:';
			}

			FormatearTapa('mc_container_carro');
			
			if((Productos.length > 0) && ((responseXML.getElementsByTagName('total')[0].firstChild.nodeValue * 1) <= 0)){ // Carro con productos y Total que pagar = 0
				if(xGetElementById('bloque_terminos').style.display == 'none'){ fadeOutIn('bloque_terminos','in'); }
				EnableCodigo();
				EnableForm();
			}else if((Productos.length > 0) && ((responseXML.getElementsByTagName('total')[0].firstChild.nodeValue * 1) > 0)){ // Carro con productos y Total que pagar mayor que 0
				if(xGetElementById('bloque_terminos').style.display == 'none'){ fadeOutIn('bloque_terminos','in'); }
				EnableCodigo();
				EnableForm();
			}else if(Productos.length <= 0){ // Carro vacio...!
				if(xGetElementById('bloque_terminos').style.display != 'none'){ fadeOutIn('bloque_terminos','out'); }
				DisableCodigo();
				DisableForm();
			}

			if((OfreceHosting.length > 0) && (xGetElementById('ofrec_hosting_container').style.display == 'none')){
				
				if(responseXML.getElementsByTagName('web-hosting')[0]){
					xGetElementById('ofrec_precio_hosting').innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('web-hosting')[0].getAttribute('precio') * 1);
					xGetElementById('ofrec_periodo_hosting').innerHTML = FormatPeriodo(responseXML.getElementsByTagName('web-hosting')[0].getAttribute('periodo'));
				}
				
				if(responseXML.getElementsByTagName('reseller')[0]){
					xGetElementById('ofrec_precio_reseller').innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('reseller')[0].getAttribute('precio') * 1);
					xGetElementById('ofrec_periodo_reseller').innerHTML = FormatPeriodo(responseXML.getElementsByTagName('reseller')[0].getAttribute('periodo'));
				}
				
				if(responseXML.getElementsByTagName('dedicados')[0]){
					xGetElementById('ofrec_precio_dedicados').innerHTML = simboloMoneda+'&nbsp;'+ FormatPrecio(responseXML.getElementsByTagName('dedicados')[0].getAttribute('precio') * 1);
					xGetElementById('ofrec_periodo_dedicados').innerHTML = FormatPeriodo(responseXML.getElementsByTagName('dedicados')[0].getAttribute('periodo'));
				}
				
				fadeOutIn('ofrec_hosting_container','in');
			}
			if((OfreceHosting.length == 0) && (xGetElementById('ofrec_hosting_container').style.display != 'none')){ fadeOutIn('ofrec_hosting_container','out'); }
			FormatearTapa('mc_container_carro');
			SacarMensaje();
			SacarTapa();
			break;
	}
}


/************************************* INI LOGIN *************************************/
function displayLogin(){
	if(xGetElementById('bloque_login').style.display == 'none'){
		ToggleLoginBlock('login');
		LimpiarErrorLogin();
		LimpiarErrorOlvido();
		fadeOutIn('bloque_login','in');
	}else{
		fadeOutIn('bloque_login','out');
	}
}

function ToggleLoginBlock(destino){
	hide('chkout1_container_login_olvido_ok');
	if(destino == 'olvido'){
		LimpiarErrorLogin();
		xGetElementById('chkout1_bt_Login').disabled = true;
		xGetElementById('chkout1_btOlvido').disabled = false;
		hide('chkout1_container_login_login');
		show('chkout1_container_login_olvido');
	}
	if(destino == 'login'){
		LimpiarErrorOlvido();
		xGetElementById('chkout1_bt_Login').disabled = false;
		xGetElementById('chkout1_btOlvido').disabled = true;
		hide('chkout1_container_login_olvido');
		show('chkout1_container_login_login');
	}
}

function Loguear(Formulario){
	xGetElementById('login_form_error_desc').innerHTML = '';
	if(xGetElementById('login_form_error_container').style.display != 'none'){ hide('login_form_error_container'); }
	xGetElementById('olvido_form_error_desc').innerHTML = '';
	if(xGetElementById('olvido_form_error_container').style.display != 'none'){ hide('olvido_form_error_container'); }
	FormatearTapa('chkout1_container_login');
	PonerTapa('chkout1_container_login');
	PonerMensaje('tapa');
	if(Formulario == 'chkout1_form_Login'){
		var LoginPost = armarPost(Formulario);
		makeRequest('/ajax-login.php',GetLoginResult,'POST','account=old&'+LoginPost+'&origen=mis-compras');
	}
	if(Formulario == 'chkout1_form_Olvido'){
		makeRequest('/ajax-login.php',GetOlvidoResult,'POST',armarPost(Formulario));
		setClass(xGetElementById('usernameOlvidoChkout1'),'campo');
		setClass(xGetElementById('emailOlvidoChkout1'),'campo');
	}
}

/* LOGIN */
function LimpiarErrorLogin(){
	xGetElementById('login_form_error_desc').innerHTML = '';
	if(xGetElementById('login_form_error_container').style.display != 'none'){ hide('login_form_error_container'); }
	xGetElementById('passLoginChkout1').value = '';
	xGetElementById('usernameLoginChkout1').value = '';
	setClass(xGetElementById('passLoginChkout1'),'campo');
	setClass(xGetElementById('usernameLoginChkout1'),'campo');
}

function GetLoginResult(xmlhttp) {
	switch (xmlhttp.readyState){
		case 1: 			
			//onLoading();
			break;
		case 2:
			//onLoaded();
			break;
		case 3:
			//onInteractive();
			break;
		case 4:
			var ErrorHTML = '', i;
			var responseXML = xmlhttp.responseXML;
			var LoginStatus = responseXML.getElementsByTagName('login');
			var LoginErrors = responseXML.getElementsByTagName('loginError');
		
			if(LoginStatus[0].getAttribute('logueado') == 's'){
				fadeOutIn('bloque_login','out');
				SacarMensaje();
				SacarTapa();
				hide('mc_link_acceso_cuenta');
				xGetElementById('mc_nombre_usuario').innerHTML = LoginStatus[0].getAttribute('usuario');
				show('mc_txt_logueado');
				ModificarCarro('actualizar',codPaisActual);
			}else{
				
				if(LoginErrors.length > 0){
					for (i=0; i<LoginErrors.length; i++) {
						ErrorHTML += '- '+LoginErrors[i].firstChild.nodeValue+'<br />';
					}
					if(xGetElementById('login_form_error_container').style.display == 'none'){ fadeOutIn('login_form_error_container','in'); }
					xGetElementById('login_form_error_desc').innerHTML = ErrorHTML;
					FormatearTapa('chkout1_container_login');
					if((LoginErrors[0].getAttribute('tipo_error')) == '1'){ setClass(xGetElementById('usernameLoginChkout1'),'campoError'); xGetElementById('usernameLoginChkout1').select(); }
					if((LoginErrors[0].getAttribute('tipo_error')) == '2'){ setClass(xGetElementById('passLoginChkout1'),'campoError'); xGetElementById('passLoginChkout1').value = ''; xGetElementById('passLoginChkout1').select(); }
				}
				
				if(LoginStatus[0].getAttribute('ventana') == 'inhabilitado'){
					ErrorHTML += 'La cuenta con el usuario <strong>'+LoginStatus[0].getAttribute('usuario')+'</strong> no se encuentra operativa.<br />\n';
					ErrorHTML += 'Por favor, genere una nueva cuenta haciendo <a href="#" onclick="LimpiarErrorLogin(); xGetElementById(\'rb_bloque_new_user\').click(); return false;" tittle="Crear una nueva cuenta." >click aquí</a>\n';
					if(xGetElementById('login_form_error_container').style.display == 'none'){ fadeOutIn('login_form_error_container','in'); }
					xGetElementById('login_form_error_desc').innerHTML = ErrorHTML;
					FormatearTapa('chkout1_container_login');
				}
				SacarMensaje();
				SacarTapa();
				
			}
			
			break;
	}
}

/* OLVIDO */
function LimpiarErrorOlvido(){
	xGetElementById('olvido_form_error_desc').innerHTML = '';
	if(xGetElementById('olvido_form_error_container').style.display != 'none'){ hide('olvido_form_error_container'); }
	xGetElementById('usernameOlvidoChkout1').value = '';
	xGetElementById('emailOlvidoChkout1').value = '';
	setClass(xGetElementById('usernameOlvidoChkout1'),'campo');
	setClass(xGetElementById('emailOlvidoChkout1'),'campo');
}

function GetOlvidoResult(xmlhttp) {
	switch (xmlhttp.readyState){
		case 1: 			
			//onLoading();
			break;
		case 2:
			//onLoaded();
			break;
		case 3:
			//onInteractive();
			break;
		case 4:
			var ErrorHTML = '', i;
			var responseXML = xmlhttp.responseXML;
			var LoginStatus = responseXML.getElementsByTagName('login');
			var LoginErrors = responseXML.getElementsByTagName('loginError');
		
			if(LoginStatus[0].getAttribute('enviado') == 'y'){
				hide('chkout1_container_login_olvido');
				hide('chkout1_container_login_login');
				show('chkout1_container_login_olvido_ok');
				FormatearTapa('chkout1_container_login');
			}else{
				if(LoginErrors.length > 0){
					for (i=0; i<LoginErrors.length; i++) {
						ErrorHTML += '- '+LoginErrors[i].firstChild.nodeValue+'<br />';
					}
					if(xGetElementById('olvido_form_error_container').style.display == 'none'){ fadeOutIn('olvido_form_error_container','in'); }
					xGetElementById('olvido_form_error_desc').innerHTML = ErrorHTML;
					FormatearTapa('chkout1_container_login');
					setClass(xGetElementById('usernameOlvidoChkout1'),'campoError'); xGetElementById('usernameOlvidoChkout1').select();
					setClass(xGetElementById('emailOlvidoChkout1'),'campoError'); xGetElementById('emailOlvidoChkout1').select();
				}
			}
			
			SacarMensaje();
			SacarTapa();
			break;
	}
}
/************************************* FIN LOGIN *************************************/