// JavaScript Document

function axc_0(enviar, idrecibir, btn){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {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){
	var divrecibir=$(idrecibir);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {}, 
		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_2(enviar, idrecibir, btn, id_title,title){
	var divrecibir=$(idrecibir);
	var botonsub=$(btn);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {botonsub.disabled=true;}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto; botonsub.disabled=false;
		$(id_title).innerHTML = title;dplieg(idrecibir);},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); }

function axc_3(enviar, idrecibir){
	var divrecibir=$(idrecibir);
	var prueboRequest = new Request({
		method: 'get', 
		url: enviar,
		onRequest: function() {divrecibir.innerHTML='<div style="padding:30px;"><img src="images/load_banner.gif" /></div>';}, 
		onSuccess: function(texto, xmlrespuesta){divrecibir.innerHTML = texto;plieg(idrecibir);},
		onFailure: function(){ alert('Could not complete the operation, try again later\nDetails:\n\nDatabase conection failed.');return 0;}
	}).send(); }


//====================================================================

function update_amount(){
	
	//Procesar el pago
	process();
	}

function amount_up(valor,text){
	amount=valor*30;
	$(text).value=amount.toFixed(2);
	}
	
function displaytype(type){
	if(type=='random')
	{
		//$('type_search').style.display = 'none';
		dplieg('type_search');
		/*resetear los valores*/
		document.forms[0].elements['dedicate_term'].selectedIndex = 0;
		plieg('geo_tarjeting');
	}
	else if(type=='dedicated')
	{
		//$('type_search').style.display = 'inline';
		plieg('type_search');
		}}

function show_zone(opcion){
	
	if(opcion=='all' || opcion=='search')
	{
		//$('geo_tarjeting').style.display = 'block';
		plieg('geo_tarjeting');
		}
	else if(opcion=='home' || opcion=='tips')
	{
		//$('geo_tarjeting').style.display = 'none';
		dplieg('geo_tarjeting');
		}
	}
	
function add_tarjeting(){

	//recuperar todos los valores de slect
	type_job=document.forms[0].elements['slt_type_job'].options[document.forms[0].elements['slt_type_job'].selectedIndex].value;
	
	country=document.forms[0].elements['slt_country'].options[document.forms[0].elements['slt_country'].selectedIndex].value;
	
	state=document.forms[0].elements['slt_state'].options[document.forms[0].elements['slt_state'].selectedIndex].value;

	//comparar si tdos los valores 
	if(type_job!='' && country!='' && state!='')
	{
		
		//send data for JSON
		jQuery.post('ajax/listing-geo.php',{industry:type_job,country:country,state:state}, function(respuesta){
			if(respuesta.modificar=='yes'){
				//we have the answers now we show this answers		  
			 		$('listing_position').innerHTML = respuesta.lista;
				//ahora actualizar los precios
					process();
			}

			 },'json');
			 return false;
		
		}
	else
	{
		if(type_job=='')
		{alert('Select the Type Job');}
		else if(country=='')
		{alert('Select the Country');}
		else if(state=='')
		{alert('Select the State');}
		}

	}



function removegeo(id){
	
	//send data for JSON
		jQuery.post('ajax/remove_geo.php',{id:id}, function(respuesta){
				//we have the answers now we show this answers		  
			 		$('listing_position').innerHTML = respuesta.lista;
				//ahora actualizar los precios
					process();

			 },'json');
			 return false;
	}
	
function modified_status(id,action,idrecibir){
	axc_1('ajax/modified_status.php?id='+id+'&action='+action,idrecibir);
	}
	
function delete_banner(id,div){
	//ocultar el div a ser eliminado
		dplieg(div);
	//eliminar
		axc_1('ajax/delete_banner.php?id='+id,div);
	}
	
function edit_title(id,div,title,button,div_title){
			//realizar la operacion de actualizar el nombre del campo
				axc_2('ajax/update_title.php?id='+id+'&title='+title,div,button,div_title,title);
				
	}
	
function ads_click(id_campaign,id_banner){
	
	jQuery.post('ajax/go_url.php',{campaign:id_campaign,banner:id_banner}, function(respuesta){
			 	document.location=respuesta.url;
			 },'json');
			 return false;
	
	}
	
function show_statistic(id,divrecibir){
	if($(divrecibir).style.display=='none'){
	//calcular la estadistica por mes
		plieg(divrecibir);
		axc_3('ajax/show_statics.php?id='+id,divrecibir);
	}
	else
	{
		dplieg(divrecibir);
		}
}

function details_banner(id_campaign,id_banner){
	//calcular el id a mostrar
	divrecibir='banner_details_'+id_banner;
	if($(divrecibir).style.display=='none')
	{
		//mostrar el div
		plieg(divrecibir);
		//inicializar los divs a recibir
		div_monthly='banner_monthly_'+id_banner;
		div_daily='banner_daily_'+id_banner;
		//ejecutar las consultas
		axc_3('ajax/show_daily.php?id_campaign='+id_campaign+'&id_banner='+id_banner+'&fecha=today',div_daily);
		axc_3('ajax/show_monthly.php?id_campaign='+id_campaign+'&id_banner='+id_banner,div_monthly);
		
		}
	else
	{
		//ocultar el div
		dplieg(divrecibir);
		}
	}

function show_details_daily(id_campaign,id_banner,fecha){
	axc_3('ajax/show_daily.php?id_campaign='+id_campaign+'&id_banner='+id_banner+'&fecha='+fecha,div_daily);
	}
	
function show_detail_type(value){
		do_reset();
	}
function show_detail_where(value){
	if(value=="plan_dedicated")
	{
		if($('geo_tarjeting').style.display=='none')
		{
			//mostrar el div
			plieg('geo_tarjeting');
			}
		
		//asignar el mensaje
		$('text_msg').innerHTML='With a Dedicated Banner Ad ( <span style="color:#EB0124;font-weight:bold;">160x600</span> ) shown in the Job Search and Listings Pages of the BigJobsBoard site, you will have visibility on thousands of pages serving an industry state wide.   With this ad, your banner will be shown every time a search is done and the results are viewed for the industry and state of your choice.  For greater exposure, simply choose additional states or additional industires and states to have your ad shown.  Each industry and state you select is just $2.95/Month and there are no limits on page impressions or click throughs.';
		//mostrar el mensaje
		if($('text_msg').style.display=='none')
			plieg('text_msg');
			//odificar el texto de tiempo de add
		$('time_add').innerHTML='Ad Runtime <span style="font-weight:normal;">(How long do you want to have your ad show?)</span>';
		//aparecer el combo de tiempo
		if($('slt_campaign_term').style.display=='none')
			$('slt_campaign_term').style.display='block';
		//resetear el combo de fechas
			document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;	
		//eliminar sessiones de geotargeting
			jQuery.post('ajax/delete_geo.php',{}, function(respuesta){
			 	//Modificar el Total
					jQuery("#listing_position").val(respuesta.texto);
				//Procesar el total
					process();
					
			 },'json');
			 return false;

		
		}
	
	if(value=="plan_dedicated_v")
	{
		if($('geo_tarjeting').style.display=='none')
		{
			//mostrar el div
			plieg('geo_tarjeting');
			}
		
		//asignar el mensaje
		$('text_msg').innerHTML='With a Dedicated Banner Ad ( <span style="color:#EB0124;font-weight:bold;">728x90 </span> ) shown in the Job Search and Listings Pages of the BigJobsBoard site, you will have visibility on thousands of pages serving an industry state wide.   With this ad, your banner will be shown every time a search is done and the results are viewed for the industry and state of your choice.  For greater exposure, simply choose additional states or additional industires and states to have your ad shown.  Each industry and state you select is just $2.95/Month and there are no limits on page impressions or click throughs.';
		//mostrar el mensaje
		if($('text_msg').style.display=='none')
			plieg('text_msg');
			
		//aparecer el combo de meses
		if($('slt_campaign_term').style.display=='none')
			$('slt_campaign_term').style.display='block';
		//resetear el combo de fechas
			document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;
		//odificar el texto de tiempo de add
		$('time_add').innerHTML='Ad Runtime <span style="font-weight:normal;">(How long do you want to have your ad show?)</span>';
		//eliminar sessiones de geotargeting
			jQuery.post('ajax/delete_geo.php',{}, function(respuesta){
			 	//Modificar el Total
					jQuery("#listing_position").val(respuesta.texto);
				//Procesar el total
					process();
					
			 },'json');
			 return false;
		
			
		
		}
		
	if(value=="plan_home_u" || value=='plan_home_r')
	{
		if($('geo_tarjeting').style.display!='none')
		{
			//ocultar el div
			dplieg('geo_tarjeting');
			}
		//asignar el tamaņo de la imagen a mostrar
		if(value=="plan_home_u")
			size="728x90";
		else
			size="160x600";
		//asignar el mensaje
		$('text_msg').innerHTML='With a Dedicated Home Page Ad ( <span style="color:#EB0124;font-weight:bold;">'+size+'</span> ) you get maximum exposure.  The home page of any site is always the best place to advertise as it usually receives the most traffic of any page on a site.  With most large sites, you\'ll need to pay hundreds for a home page ad.  On the BigJobsBoard, we\'re offering it out for just $9.95/Month.  This is another amazing ad deal that you won\'t find in many places on the internet.';
		//mostrar el mensaje
		if($('text_msg').style.display=='none')
			plieg('text_msg');
		//aparecer el combo de meses
		if($('slt_campaign_term').style.display=='none')
			$('slt_campaign_term').style.display='block';
		//resetear el combo de fechas
			document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;
		//eliminar sessiones de geotargeting
			jQuery.post('ajax/delete_geo.php',{}, function(respuesta){
			 	//Modificar el Total
					jQuery("#listing_position").val(respuesta.texto);
				//Procesar el total
					process();
					
			 },'json');
			 return false;		
		}
	
	if(value=="") 
	{
		//eliminar sessiones de geotargeting
			jQuery.post('ajax/delete_geo.php',{}, function(respuesta){
			 	//Modificar el Total
					jQuery("#listing_position").val(respuesta.texto);
				//resetear el total
					do_reset();
					
			 },'json');
			 return false;


		}
	}
	
function renew(id){
	//recuperar el numero de meses
	meses=document.forms['frm_renew_'+id].elements['cb_months'].options[document.forms['frm_renew_'+id].elements['cb_months'].selectedIndex].value;
	if(meses=='')
		alert("Select the number of months");
	else
	{
		document.location=meses;
		}
	}
	
function show_banner(id,div_recibir){
	
	if($(div_recibir).style.display!='none')
		dplieg(div_recibir);
	else{
		//mandamos a mostrar la imagen 
		axc_1('/ajax/show_banner.php?id_banner='+id,div_recibir);
		plieg(div_recibir);
		}
	}
	
function delete_campaign(id,div){
	//ocultar el div a ser eliminado
		dplieg(div);
	//eliminar
		axc_1('/ajax/delete_campaign.php?id='+id,div);
	}
	
function designer_detail(){
	//ver si esta mostrandose o no
	if(jQuery("#designer_banner").is(':checked')) {
			//mostrar el div con un texto
			jQuery("#designer_description").slideDown("slow");
		} else {
			//ocultar el Div
			jQuery("#designer_description").slideUp("slow");
		}
		
	//Entonces ahora llamar a la actualizacion  de precios
	process();
	}
	
//================== Funciones generales para la pagina campaigns
function do_reset()
{
	//Resetear el precio ver si esta checkeado el banners designer
	if(jQuery("#designer_banner").is(':checked'))
	{
		jQuery("#txt_amount").val('50.00');
		}
	else
	{
		jQuery("#txt_amount").val('0.00');
		//ocultar el div del designer
		dplieg('designer_description');
		}
	//ahora eliminar las sessiones de los geotargeting
		axc_0('ajax/delete_geo.php','listing_position','button');
	//resetear el combo de fechas, slt_where_display y de geotargeting
		document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;
		document.forms[0].elements['slt_type_job'].selectedIndex = 0;
		document.forms[0].elements['slt_country'].selectedIndex = 0;
		document.forms[0].elements['slt_state'].selectedIndex = 0;
		document.forms[0].elements['slt_where_display'].selectedIndex = 0;
	//ocultar area de mensajes el mensaje
		if($('text_msg').style.display!='none')
			dplieg('text_msg');
		if($('geo_tarjeting').style.display!='none')
			dplieg('geo_tarjeting');
	}
	
function process()
{
	//Recuperar los valores necesarios
	//recuperar el display_where value
	var type_display=document.forms[0].elements['slt_where_display'].options[document.forms[0].elements['slt_where_display'].selectedIndex].value;
	var time=document.forms[0].elements['slt_campaign_term'].options[document.forms[0].elements['slt_campaign_term'].selectedIndex].value;
	var designer='no';
	if(jQuery("#designer_banner").is(':checked'))
		designer='yes';
		
	//deshabilitar los botones y selects
		$('type_link').disabled=true;
		$('slt_where_display').disabled=true;
		$('slt_type_job').disabled=true;
		$('slt_country').disabled=true;
		$('slt_state').disabled=true;
		$('button').disabled=true;
		$('bsubmit').disabled=true;
		
	//Enviar los valores por post
		jQuery.post('ajax/process.php',{type_plan:type_display,time:time,designer:designer}, function(respuesta){
			 	//Modificar el Total
					jQuery("#txt_amount").val(respuesta.total);
				//activar los botones
					$('type_link').disabled=false;
					$('slt_where_display').disabled=false;
					$('slt_type_job').disabled=false;
					$('slt_country').disabled=false;
					$('slt_state').disabled=false;
					$('button').disabled=false;
					$('bsubmit').disabled=false;
			 },'json');
			 return false;
	
	}
	

