function axc(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="../images/loading.gif" />'; botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function axc_1(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="../images/loader.gif" />'; botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); 
}

function axcountry(idrecibir, country, control, idrecibir2, control2, idrecibir3){
	axc('ajax/states.php?name='+control+'&country='+country+'&name2='+control2+'&recibir='+idrecibir2, idrecibir, 'bsubmit');
	//only USA shows cities
	$(idrecibir2).innerHTML="<select name='"+control2+"' id='"+control2+"' class='register_employer'><option value=''>Select City</option></select>";
	if(country=='United States'){
		$(idrecibir3).style.display='block';
	}
	else {
		$(idrecibir3).style.display='none';
	}
}

function mostrar_cpanel(valor,idrecibir)
{
	//alert('alerta');
	axc('../ajax/cpanel.php?domain='+valor,idrecibir,'submit');
	}
function mostrar_webmail(valor,idrecibir)
{
	//alert('alerta');
	axc('../ajax/webmail.php?domain='+valor,idrecibir,'submit');
	}
	
	
	
/*=================funcion para recalcular el total pasando todos los parametros*/	
function recalcular(plan,tiempo,total_domain_status,total_postini,cupon,idrecibir)
{
	
	
		//pasar el type_purchase
		type_purchase=document.forms[0].type_purchase.value;
		//entramos solo si esta escogido un plan
		axc_1('../ajax/recalcular.php?plan='+plan+'&tiempo='+tiempo+'&total_domain='+total_domain_status+'&type_purchase='+type_purchase+'&total_postini='+total_postini+'&cupon='+cupon,idrecibir,'bsubmit');
		//comprobamos si el tiempo esta seleccionado o no de no estar seleccionado lo ponemos como defecto 3_years
		if((tiempo=='')&((total_domain_status!=0)||(total_postini!=0)))
		{
			document.forms[0].term.selectedIndex=3;
		}
		//recalcular el postini
		//deschekear el  post_ini
		//document.forms[0].postini[1].checked=true;
		//document.getElementById('postini_add').value=0;
		//recalucular el domain status add si es mayor a cero
		if(total_domain_status!=0)
		{
			//calcular el tiempo
			if(tiempo=='')
				cantidad=1;
			if(tiempo=='3_years')
				cantidad=3;
			if(tiempo=='2_years')
				cantidad=2;
			if(tiempo=='1_year')
				cantidad=1;
			if(tiempo=='monthly')
				cantidad=1;
			//ahora actualizamos el nuevo valor agregado
			document.getElementById('domain_status_add').value=cantidad*20;
			
		}
		else
		{
			document.getElementById('domain_status_add').value=0;
			}
		//recalcular el total_postini si es mayor a cero
		if(total_postini!=0)
		{
			//calcular el tiempo
			if(tiempo=='')
				meses=12;
			if(tiempo=='3_years')
				meses=36;
			if(tiempo=='2_years')
				meses=24;
			if(tiempo=='1_year')
				meses=12;
			if(tiempo=='monthly')
				meses=1;
			//ahora calculamos el nuevo valor agregado
			document.getElementById('postini_add').value=2*meses;
			}
			else
				document.getElementById('postini_add').value=0;
		
		
		//alert('el plan: '+plan+' el tiempo:'+tiempo+' total domain:'+total_domain_status+' total postini:'+total_postini);
	}
	
	
	
	
function change_to_marketing_plan(tiempo,cupon,idrecibir)
{
	//ocultar los precios
	$('ds_1').style.display='none';
	$('ds_2').style.display='none';
	//deshabilitar el combox de planes
	document.forms[0].HostingPlan.disabled=true;
	//resetear los adds a cero
	document.getElementById('domain_status_add').value=0;
	document.getElementById('postini_add').value=0;
	//poner en no el postini
	document.forms[0].postini[1].checked=true;
	//poner al plan pro
	document.forms[0].HostingPlan.selectedIndex=4;
	//deshabilitar el select
	
	//cambiar el type_purchase
	document.getElementById('type_purchase').value='marketing_package';
	//si tiempo vacio entonces poner el tiempo en meses
	if(tiempo=='')
	{
		document.forms[0].term.selectedIndex=4;
		}
	//realizar la accion con ajax
	axc_1('../ajax/marketing_plan.php?tiempo='+tiempo+'&cupon='+cupon,idrecibir,'bsubmit');
	}

function chage_to_hosting_plan(plan,tiempo,cupon,idrecibir)
{
	//descheckear todos los checxbox
	document.forms[0].DomainType[0].checked=false;
	document.forms[0].DomainType[1].checked=false;
	document.forms[0].DomainType[2].checked=false;
	document.forms[0].DomainType[3].checked=false;
	//aparecer los precios
	$('ds_1').style.display='inline';
	$('ds_2').style.display='inline';
	//habilitar el combo de planes.
	document.forms[0].HostingPlan.disabled=false;
	//si esta vacio el plan entonces escoger el vacio
	if(plan=='' ||tiempo=='')
	{
		document.forms[0].HostingPlan.selectedIndex=0;
		document.forms[0].term.selectedIndex=0;
		}
	
	//cambiar el type purchase
	document.getElementById('type_purchase').value='Hosting_Plan';
	//reseteamos adds a cero
	document.getElementById('domain_status_add').value=0;
	document.getElementById('postini_add').value=0;
	//poner en no el postini
	document.forms[0].postini[1].checked=true;
	//cambiar el combox a la posicion default
	if(plan!='')
	{
		for (i=0; i<document.forms[0].elements['HostingPlan'].options.length; i++) {
			if (document.forms[0].elements['HostingPlan'].options[i].value == plan) {
			  document.forms[0].elements['HostingPlan'].selectedIndex = i;
			  break;
			}
 		}//end for
		if (i == document.forms[0].elements['HostingPlan'].options.length) {
    		document.forms[0].elements['HostingPlan'].selectedIndex = i - 1;
  		}
		}
	if(tiempo!='')
	{
		for (i=0; i<document.forms[0].elements['term'].options.length; i++) {
			if (document.forms[0].elements['term'].options[i].value == tiempo) {
			  document.forms[0].elements['term'].selectedIndex = i;
			  break;
			}
 		}//end for
		if (i == document.forms[0].elements['term'].options.length) {
    		document.forms[0].elements['term'].selectedIndex = i - 1;
  		}
		}
	//calcular el total
	axc_1('../ajax/hosting_plan.php?plan='+plan+'&tiempo='+tiempo+'&cupon='+cupon,idrecibir,'bsubmit');
	}
function charge_discount(codigo,idrecibir)
{
	//solo realizar la accion si el codigo es diferente al vacio
	if(codigo!='')
	{
		//mandar el codigo para ser revisado
		axc_1('../ajax/discount.php?codigo='+codigo,idrecibir,'bsubmit');
		//luego mandar a que actualize todos los parametros
		recalcular(document.forms[0].HostingPlan.options[document.forms[0].HostingPlan.selectedIndex].value,document.forms[0].term.options[document.forms[0].term.selectedIndex].value,document.getElementById('domain_status_add').value,document.getElementById('postini_add').value,codigo,'total_buy');
		
		}
		else
		{
			$(idrecibir).innerHTML='';
			//calcular de nuevo el total
			recalcular(document.forms[0].HostingPlan.options[document.forms[0].HostingPlan.selectedIndex].value,document.forms[0].term.options[document.forms[0].term.selectedIndex].value,document.getElementById('domain_status_add').value,document.getElementById('postini_add').value,codigo,'total_buy');
			}
	}
function generate_code(idrecibir)
{
	//generar codigo aleatorio
	axc_1('../ajax/generate.php',idrecibir,'bsubmit');
	}
