

function ofertaAjax(idproduct, quantity) {
	var elementos = document.getElementsByName('delete');
	for (x = 0; x < elementos.length; x++) {
		borrar=ajaxCart;
		borrar.remove(elementos[x].value);
	}


	addProduct=ajaxCart;
	addProduct.add(null,idproduct,null,null,null,quantity,null);
if(x==1){	
for(a=0;a<2;a++){
		// expand/collapse management
		$a('#block_cart_collapse').click(function(){
				ajaxCart.collapse();
		});
		$a('#block_cart_expand').click(function(){
				ajaxCart.expand();
		});
		ajaxCart.overrideButtonsInThePage();
		ajaxCart.refresh();

}
}

if(x==2){
	ajaxCart.updateProductQuantity(idproduct, quantity);
	ajaxCart.collapse();
}

document.getElementById('boton').innerHTML='';

document.getElementById('esspromo').value='2';


}




function mostrarEmpresa(combo){
	var div=document.getElementById("datos_empresa");
	var lab=document.getElementById("documento");
	var firstname=document.getElementById("customer_firstname");
	var lastname=document.getElementById("customer_lastname");
	var nif=document.getElementById("address2");
	var company=document.getElementById('company');
	
    if(combo[combo.selectedIndex].value=="J"){
		lab.innerHTML="CIF";
		dhtml.showAndBlock(div);
		nif.value='';
		company.value="";
		firstname.value='';
		lastname.value='';
	}else{
		document.getElementById('combo_tipo_empresa').value='-';
		dhtml.hideAndUnblock(div);
		lab.innerHTML="DNI/NIF/NIE";
		nif.value='';
		company.value="";
	
	}

}


function botonRenovarOver(){
	var renovar=document.getElementById('renovar');
	renovar.src='img/renovar_over.png';	
}

function botonRenovar(){

	var renovar=document.getElementById('renovar');
	renovar.src='img/renovar.png';	
}

function botonComprarOver(){
	var renovar=document.getElementById('comprar');
	renovar.src='img/comprar_over.png';	
}

function botonComprar(){
	var renovar=document.getElementById('comprar');
	renovar.src='img/comprar.png';	
}
function botonDemoOver(){
	var renovar=document.getElementById('demo');
	renovar.src='img/demo_over.png';	
}

function botonDemo(){
	var renovar=document.getElementById('demo');
	renovar.src='img/demo.png';	
}


function cambiarTipo(combo){
        var div=document.getElementById("datos_empresa");
        var lab=document.getElementById("documento");
        var address2=document.getElementById('address2');
        var company=document.getElementById('company');
	if(combo[combo.selectedIndex].value=="J"){
	document.getElementById('combo_tipo_empresa').value='-';	
	company.value="";
              address2.value='';
		 lab.innerHTML="CIF";
                dhtml.showAndBlock(div);
        }else{
                
		 address2.value='';
		dhtml.hideAndUnblock(div);
                lab.innerHTML="DNI/NIF/NIE";
        }
}



function cambiarTipoPersona(combo){

}



function desaparecer(){
	var boton=document.getElementById('boton');
	boton.style.display='none';
}


function cual(id) {

	var sec = id.split("_");
	var cual = sec[0];
	var op = sec[1];
	var total = document.getElementById(sec[0] + '_total');

	sumar(cual, op, total);

}

function nuevoAjax() {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
} 


function userExist(usuario, onreg){

	var onreg= document.getElementById('password').value;
	var usuario= document.getElementById('user').value;

	
	ajax = nuevoAjax();
	ajax.open("POST", "ajaxUser.php", true);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {

			renovacion(ajax.responseText);
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("usuario="+usuario+"&onreg="+onreg);
	
}




function updatePrice(id_product, quantity, min, max,sufijo) {

	ajax = nuevoAjax();
	ajax.open("POST", "ajaxPrices.php", true);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {

		actualizarSpan(id_product, ajax.responseText);
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id_product="+id_product+"&quantity="+quantity+"&max="+max+"&min="+min+"&sufijo="+sufijo);
}

function actualizarSpan(id_product, precio){
	
	var si=document.getElementById('ampliacion');
	if(si==null){
	span=document.getElementById(id_product + "_price");
       	span.innerHTML=precio+" €";
	}
	else{
	
	var pepe=buscar_cantidad(id_product, null);
	//alert(pepe);
	}
	}




function sumar(cual, op, total){
	
	if(op=='mas' && total.value<99){
		total.value++;
		
	}
	
	if(op=='menos' && total.value>1){
		total.value--;
	}
	
}
function soloNumeros(evt){

	if(window.event){// IE
	keynum = evt.keyCode;
	}else{
	keynum = evt.which;
	}
	if(keynum>47 && keynum<58){
	return true;
	}else{
	return false;
	}
	}






function reenviar_consultas(){
	formu=document.getElementById('formulario');
	usuario=document.getElementById('usuario').value;
	if(usuario!=''){
		consulta=new AjaxQuery();
		consulta.object="Licencia";
		consulta.method="reenviar";
		consulta.callback="vuelta_consultas"
			consulta.usuario=usuario;
		ajax=new AjaxClient();
		ajax.execute(consulta);
	}else{
		alert('Introduzca el nombre de usuario para reenviarle las claves.');
		formu.usuario.focus();
		
	}
	}

	function vuelta_consultas(datos){
		if(datos==true){
			document.getElementById('licencia_no_enviada').style.display='none';
			document.getElementById('licencia_enviada').style.display='';
		
		}
		else{
			document.getElementById('licencia_enviada').style.display='none';
			document.getElementById('licencia_no_enviada').style.display='';
		}
		info_box();
		
	}









function show_help(){
	document.getElementById('table_help').style.display='';
	document.getElementById('show_help').style.display='none';
	
	info_box();

}




function show_password(){
	formu.password.disabled=false;
	document.getElementById('passwordTDInfo').style.display='';
	formu=document.getElementById('formulario');
	document.getElementById('onregTR').style.display="none";
	formu.onreg.value="";
	formu.password.style.backgroundColor='white';
	formu.password.focus();
	document.getElementById('showOnreg').style.display='';
	document.getElementById('showPassword').style.display='none';
	document.getElementById('helpOnreg').style.display='none';
	info_box();
}


function show_onreg(){
	formu=document.getElementById('formulario');
	document.getElementById('onregTR').style.display="";
	document.getElementById("helpOnreg").style.display="";
	document.getElementById('showOnreg').style.display='none';
	document.getElementById('showPassword').style.display='';
	formu.password.disabled=true;
	formu.password.value="";
	formu.password.style.backgroundColor='gray';
	document.getElementById('passwordTDInfo').style.display='none';
	formu.onreg.focus();
	info_box();
	
	}

	function popup(tipo){
             opciones="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=420";
             if(tipo!="youtube.html")opciones="toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,width=500,height=280";
             window.open(tipo,"Ayuda", opciones);
	}



	function de_agente_js(checkbox){

		consulta=new AjaxQuery();
		consulta.object="Licencia";
		consulta.method="de_agente";
		consulta.callback="vuelta_agente";	
		if(checkbox.checked)de_agente='N';
		else de_agente='S';
		consulta.de_agente=de_agente;
		ajax=new AjaxClient();
                ajax.execute(consulta);


	}


	function vuelta_agente(datos){

	}


	function buscar(formu){
		send=true;
		if(formu.usuario.value==''){
			formu.usuario.style.backgroundColor="#FF6969";
			send=false;
		}
		if(formu.password.disabled==false){
			if(formu.password.value==''){
				formu.password.style.backgroundColor="#FF6969";
				send=false;
			}
		}else{
			if(formu.onreg.value==''){
				formu.onreg.style.backgroundColor="#FF6969";
				send=false;
			}
		}
		if(send){
	    	consulta=new AjaxQuery();
	    	consulta.object="Licencia";
	    	consulta.method="buscar";
	    	consulta.callback="vuelta";
	    	consulta.usuario=formu.usuario.value;
	    	consulta.password=formu.password.value;
	    	if(formu.password.disabled==true)consulta.password=formu.onreg.value;
	    	ajax=new AjaxClient();
	    	ajax.execute(consulta);
		}
	}

	function infoboxspacer(){
	    var el = document.getElementById("field");
	    var x = el.offsetHeight;
		return x+32;
		}
	
	
	
	function info_box(){
	}


	function vuelta(datos){
		if(datos!='ERROR'){
		document.getElementById('field').innerHTML=datos;
		var alt=infoboxspacer();
		ajaxCart.overrideButtonsInThePage();
		alt=alt+53;
		

		
		document.getElementById('eset_footer').style.width="715px";
		document.getElementById('identitycontent1').className='';
		
		$a('#identity1').removeClass('identity');
		$a('#identitytop1').removeClass('identitytop');
		$a('#identityfooter1').removeClass('identityfooter');
		info_box();
		
		}else{
			
			document.getElementById('error').style.display='';
			info_box();
		}
	}

	function reenviar(lic){
		usuario=document.getElementById('usuario').value;
		consulta=new AjaxQuery();
		consulta.object="Licencia";
		consulta.method="reenviar";
		if(!lic)consulta.callback="vuelta2";
		else consulta.callback="vueltaLicencia"
			consulta.usuario=usuario;
		ajax=new AjaxClient();
		ajax.execute(consulta);
	
		}

		function vuelta2(datos){

		var cuadro=document.getElementById("reenvioClaves");
			if(datos){
				document.getElementById('ReenvioClaves').style.display='none';
				document.getElementById('ReenvioClavesOK').style.display='';
			}
				
		}
		
		
		function vueltaLicencia(datos){
	
					document.getElementById('ReenvioLIC').style.display='none';
					document.getElementById('ReenvioLICOK').style.display='';
									
			}
		
		
		
		
		

		function reenviarPDF() {
			usuario=document.getElementById('usuario').value;
			consulta=new AjaxQuery();
			consulta.object="Licencia";
			consulta.method="reenviarPDF";
			consulta.callback="vueltaPDF"
			consulta.usuario=usuario;
			ajax=new AjaxClient();
			ajax.execute(consulta);
		}
		
		
		function vueltaPDF(datos){
		
		document.getElementById("ReenvioPDF").style.display='none';
		document.getElementById("ReenvioPDFOK").style.display='';
		}
		function showOptions(select){
			if(document.getElementById('action').value=='false'){
			selected=select.split('_');
			box=selected[0];
			version=selected[1];
			opened=document.getElementById('open').value;
			document.getElementById('action').value='true';
					if(opened=='none'){
						 document.images[version+'_flecha'].src='themes/eset/img/principal/flecha_abajo.png';
						  document.getElementById(version+'_enlace').style.color='#07c7a1';
						$a('#'+box).slideToggle('slow', function() {
							  $a('#'+version).fadeIn('slow',function(){
									document.getElementById('action').value='false';
							  });
						  });
						  document.getElementById('open').value=select;
					}else{

					var	action=true;
						opened=document.getElementById('open').value;
						opened=opened.split('_');
						box_open=opened[0];
						version_open=opened[1];
						  document.images[version_open+'_flecha'].src='themes/eset/img/principal/flecha.png';
						  document.getElementById(version_open+'_enlace').style.color='#006366'; 
						$a('#'+version_open).fadeOut('slow', function() {
							  document.getElementById('open').value=select;
							  $a('#'+box_open).slideToggle('slow',function(){
									
								  document.images[version+'_flecha'].src='themes/eset/img/principal/flecha_abajo.png';
								  document.getElementById(version+'_enlace').style.color='#07c7a1';
								  $a('#'+box).slideToggle('slow', function() {
									  $a('#'+version).fadeIn('slow',function(){
							
											document.getElementById('action').value='false';
											
									  });
								  });
								  
							  });
						  });
					 
					}
			
			}
				  
				  
		}
		function searchLicense(formu){


			consulta=new AjaxQuery();
	
			consulta.object="Licencia";
			consulta.method="buscarmd5";
			consulta.callback="searchLicensereturn"
			consulta.usuario=formu.usuario.value;
			consulta.password=formu.password.value;
			ajax=new AjaxClient();
			ajax.execute(consulta);

		}

		function searchLicensereturn(data){
		    document.location.href='renovacion/'+data;
		}
		
		

