// 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(valor,idrecibir){
	
	//enviar
	//recuperar el tipo
	if(document.getElementById('slt_type_campaign_1').checked)
		type_campaign='plan_life';
	else if(document.getElementById('slt_type_campaign_2').checked)
		type_campaign='plan_dedicate';
	else
		type_campaign='';
	
	
	if(type_campaign!='plan_life' && type_campaign!='')
	{
		type_campaign=document.forms[0].elements['slt_where_display'].options[document.forms[0].elements['slt_where_display'].selectedIndex].value;
		}
	
	
	axc_0('ajax/update_amount.php?month='+valor+'&type_campaign='+type_campaign,idrecibir,'button');
}

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;
	
	num_months=document.forms[0].elements['slt_campaign_term'].options[document.forms[0].elements['slt_campaign_term'].selectedIndex].value;
	
	
	//recuperar el tipo
	if(document.getElementById('slt_type_campaign_1').checked)
		type_campaign='plan_life';
	else if(document.getElementById('slt_type_campaign_2').checked)
		type_campaign='plan_dedicate';
	else
		type_campaign='';
		
	if((type_campaign=='plan_dedicate') && (type_campaign!=''))
	{
		type_campaign=document.forms[0].elements['slt_where_display'].options[document.forms[0].elements['slt_where_display'].selectedIndex].value;
		}
	
	//comparar si tdos los valores 
	if(type_job!='' && country!='' && state!='' && type_campaign!='plan_life')
	{
		//alert('Permiso concedido');
		//axc_0('ajax/listing-geo.php?job='+type_job+'&country='+country+'&state='+state, 'listing_position', 'bsubmit');
		
		//deshabilitar los botones hasta que se culmine
		$('button').disabled=true;
		$('bsubmit').disabled=true;
		
		//send data for JSON
		jQuery.post('ajax/listing-geo.php',{industry:type_job,country:country,state:state,month:num_months,type_campaign:type_campaign}, function(respuesta){
			if(respuesta.modificar=='yes'){
				//we have the answers now we show this answers		  
			 		$('listing_position').innerHTML = respuesta.lista;
				//ahora actualizar los precios
					$('txt_amount').value = respuesta.total;
			}
			//habilitar los botones
				$('button').disabled=false;
				$('bsubmit').disabled=false;
			 },'json');
			 return false;
		
		
		
		}
	else if((type_campaign=='plan_life') && (type_job!='' || country!='' || state!='')){
			//alert('Permiso concedido');
		//axc_0('ajax/listing-geo.php?job='+type_job+'&country='+country+'&state='+state, 'listing_position', 'bsubmit');
		
		//deshabilitar los botones hasta que se culmine
		$('button').disabled=true;
		$('bsubmit').disabled=true;
		
		//send data for JSON
		jQuery.post('ajax/listing-geo.php',{industry:type_job,country:country,state:state,month:num_months,type_campaign:type_campaign}, function(respuesta){
			if(respuesta.modificar=='yes'){
				//we have the answers now we show this answers		  
			 		$('listing_position').innerHTML = respuesta.lista;
				//ahora actualizar los precios
					$('txt_amount').value = respuesta.total;
			}
			//habilitar los botones
				$('button').disabled=false;
				$('bsubmit').disabled=false;
			 },'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)
{
	//axc_0('ajax/remove_geo.php?id='+id,'listing_position','bsubmit');
	//num of months
	num_months=document.forms[0].elements['slt_campaign_term'].options[document.forms[0].elements['slt_campaign_term'].selectedIndex].value;
	
	//recuperar el tipo
	if(document.getElementById('slt_type_campaign_1').checked)
		type_plan='plan_life';
	else if(document.getElementById('slt_type_campaign_2').checked)
		type_plan='plan_dedicate';
	else
		type_plan='';
	
	if(type_plan!='plan_life')
	{
		//recoger otro type_plan
		type_plan=document.forms[0].elements['slt_where_display'].options[document.forms[0].elements['slt_where_display'].selectedIndex].value;
		//desaparecer el mensaje de for life
		$('time_add').innerHTML='Ad Runtime <span style="font-weight:normal;">(How long do you want to have your ad show?)</span>';
		}
	//deshabilitar los botones hasta que se culmine
		$('button').disabled=true;
		$('bsubmit').disabled=true;
	
	//send data for JSON
		jQuery.post('ajax/remove_geo.php',{id:id,month:num_months,type_plan:type_plan}, function(respuesta){
				//we have the answers now we show this answers		  
			 		$('listing_position').innerHTML = respuesta.lista;
				//ahora actualizar los precios
					$('txt_amount').value = respuesta.total;
					
				//habilitar los botones
					$('button').disabled=false;
					$('bsubmit').disabled=false;
			 },'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)
{
		
	if(value=="plan_life")
	{
		if($('geo_tarjeting').style.display=='none')//si es que esta oculto
		{
			//mostrar el div
			plieg('geo_tarjeting');
			}
			
		if($('slt_display').style.display!='none')//si esta a la vista
		{
			//ocultar el combo
				dplieg('slt_display');
			}
		//asignar el mensaje
		$('text_msg').innerHTML='With a Banner Ad for Life, your ad ( <span style="color:#EB0124;font-weight:bold;">728x90</span> ) can be shown in over 3 Million ad positions in the Job Search and Listings Pages throughout the BigJobsBoard site.   You can target your ad to show in any country, state and industry.  The best part is that the ad is only $20 paid one time.  There are no limits of page impressions or click thoughs and you\'ll never have to pay again.  If you want greater exposure, simply buy more ads.  The price is right and this is the best advertising deal on the internet.';
		//mostrar el mensaje
		if($('text_msg').style.display=='none')
			plieg('text_msg');
		
		//desaparecer el combo de meses
			$('slt_campaign_term').style.display='none';
		//poner el precion de 20 dolares
			$('txt_amount').value='20.00';
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//resetear el combo de fechas
			document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;
		//resetear el combo de where_display
			document.forms[0].elements['slt_where_display'].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> <br /><br /><span style="margin-left:15px;font-weight:normal">For Life!</span>';
		}
	
	if(value=="plan_dedicate")
	{
		if($('geo_tarjeting').style.display!='none')//si es que esta mostrado
		{
			//ocultar el div
			dplieg('geo_tarjeting');
			}
		if($('slt_display').style.display=='none')//si esta oculto
		{
			//mostrar el div
				plieg('slt_display');
			}
		//asignar el mensaje
		//ocultar area de mensajes el mensaje
		if($('text_msg').style.display!='none')
			dplieg('text_msg');
		
		//aparecer el  el combo de meses
			$('slt_campaign_term').style.display='block';
		//poner el precion de 20 dolares
			$('txt_amount').value='0.00';
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//resetear el combo de fechas
			document.forms[0].elements['slt_campaign_term'].selectedIndex = 0;
		//resetear el combo de where_display
			document.forms[0].elements['slt_where_display'].selectedIndex = 0;
		
		//modificar 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>';
		}
	
	if(value=="") 
	{

		//si ya esta mostrando algo el mensaje lo desplegamos
		if($('slt_display').style.display!='none')
			dplieg('slt_display');
			
		if($('text_msg').style.display!='none')
			dplieg('text_msg');
			
		if($('geo_tarjeting').style.display!='none')
		{
			//ocultar el div
			dplieg('geo_tarjeting');
			}
		//poner el precio total en 0.00
			$('txt_amount').value='0.00';
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//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;
		
		}
		
	}
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 $10/Month and there are no limits on page impressions or click throughs.';
		//mostrar el mensaje
		if($('text_msg').style.display=='none')
			plieg('text_msg');
			
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//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;
		//actualizar el precio
			axc_0('ajax/update_amount.php?month=1&type_campaign=plan_dedicated','div_amount','button');
			
		//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>';
		}
		
	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 $20/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');
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//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;
		//actualizar el precio
			axc_0('ajax/update_amount.php?month=1&type_campaign='+value,'div_amount','button');
			
		//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>';
		
		}
	
	if(value=="") 
	{
		//si ya esta mostrando algo el mensaje lo desplegamos
		if($('text_msg').style.display!='none')
			dplieg('text_msg');
		if($('geo_tarjeting').style.display!='none')
		{
			//ocultar el div
			dplieg('geo_tarjeting');
			}
		//poner el precio total en 0.00
			$('txt_amount').value='0.00';
		//eliminar sessiones de geotargeting
			axc_0('ajax/delete_geo.php','listing_position','button');
		//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>';
		
		}
	}
	
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);
	}
