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 axc1(enviar, idrecibir){
	var divrecibir=$(idrecibir);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<img src="../images/loading.gif" />';}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto;},
		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;
	if(plan!='pointer' && plan!='')
	{
		//no es pointer, es otro
		//ver si tiene el tiempo mas de un aņo
		if(tiempo!='monthly' && tiempo!='')
		{
			//tienen plan no pointer mas de un aņo
			//ocultar el div the marketing
			if(type_purchase!='marketing_package')
				$("withoutmarketing").style.display='none';
			else
				$("withoutmarketing").style.display='block';
			}
			else
			{
				$("withoutmarketing").style.display='block';
				}
		}
	else
	{
		$("withoutmarketing").style.display='block';
		}
		
		//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=2;
	//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');
	}

function show_invoice(id_partner)
{
	if($('invoice_container').style.display=='none')
	{
		//No se muestra nada
		$('invoice_container').style.display='block';
		axc('../ajax/show_invoice.php?id_partner='+id_partner,'invoice_container','bu_show');
		}
	else
	{
		$('invoice_container').style.display='none';
		}
	}

function pay(id_pay)
{
	axc1('../ajax/pay-payment.php?idpay='+id_pay,'payment_'+id_pay);
	}
	
/*=============  JQUERY    ==================*/
function delete_code(id)
{
	if(confirm('Are you sure you want to delete this item?'))
		{	
	jQuery.post('../ajax/delete_code.php',{id:id}, function(respuesta){
					//Modificar el status del Text Ad
					if(respuesta.modificar=='yes'){
							//ocultar todo los divs
							jQuery('.detail_plan_'+id).hide();
						}
					else
					{
						alert("An error ocurred please try again!!");
						return false;
						}
						
				 },'json');
				 return false;
		}
	
	}
function update_code(id)
{
	//Recuperar los parametros
	var code=jQuery("#txt_code_"+id).val();
	var discount_value=jQuery("#txt_discount_value_"+id).val();
	var discount_name=jQuery("#txt_discount_name_"+id).val();
	var discount_type=jQuery("#slt_discount_type_"+id).val();
	if(code!='' &&discount_value!='' && discount_name!='')
	{
		if(validaFloat(discount_value)){
		jQuery.post('../ajax/update_discount.php',{id:id,code:code,discount_value:discount_value,discount_name:discount_name,discount_type:discount_type}, function(respuesta){
					//Modificar el status del Text Ad
					if(respuesta.modificar=='yes'){
						//modificar el listado de planes
						jQuery("#code_discount_"+id).html(code);
						jQuery("#discount_value_"+id).html(discount_value);
						jQuery("#discount_name_"+id).html(discount_name);
						jQuery("#discount_type_"+id).html(discount_type.replace('_', ' '));
						jQuery('.detail_plan_'+id).toggle();
						//mostrar el ok
						jQuery("#rpta_plan_"+id).html("<img src='../images/v.gif' alt='success...'/>");
						}
					else
					{
						alert("An error ocurred please try again!!");
						return false;
						}
						
				 },'json');
				 return false;
			}
		else
		{
			alert("Discount Value is incorrect");
			return false;
			}
		
		}
	else
	{
		alert("Please fill al information");
		return false;
		}
	}
function validaFloat(numero)
{
	if (!/^([0-9])*[.]?[0-9]*$/.test(numero))
		return false;
	else
		return true;
	}
