
function open_login() {
	  if (document.getElementById('login_area').style.display == 'none') {
		  $("#password_reminder").hide("fast");
		  $("#suscribtion_area").hide("fast");
		  $("#login_area").slideDown("fast");
	  } else {
		  $("#login_area").hide("fast");
	  }
}

function open_pswreminder() {
	  $("#suscribtion_area").hide("fast");
	  $("#login_area").hide("fast");
	  $("#password_reminder").show("fast");
}

function open_suscribtion() {
	  if (document.getElementById('suscribtion_area').style.display == 'none') {
		  $("#login_area").hide("fast");
		  $("#password_reminder").hide("fast");
		  $("#suscribtion_area").slideDown("fast");
	  } else {
		  $("#suscribtion_area").hide("fast");
	  }
}

function photo_slideshow_pos() {
	if (document.getElementById('dp_photoslideshow').style.display == 'none') {
		  $("#dp_photoslideshow").show("fast");
	  } else {
		  $("#dp_photoslideshow").hide("fast");
	  }
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function ClearInputIf (inputID, string) {
	if (document.getElementById(inputID).value==string) {
		document.getElementById(inputID).value='';
	}
}

function perform_google_search(current_site) {
	object_to_search=document.getElementById("google_search");
		if (object_to_search.value.length>0) {
			window.location='http://www.google.com/search?as_sitesearch='+current_site+'&q='+object_to_search.value+'&sa=Go';
	}
}

function perform_magazine_search(area) {
	
	var search_field, base_url;
	
	switch(area) {
		case 'magazine':
		  search_field='mag_search';
		  base_url='/magazine/search/';
		  break;
		case 'dptv':
		  search_field='dptv_search';
		  base_url='/DPTV/';
		  break;
	}

	object_to_search=document.getElementById(search_field);
		if (object_to_search.value.length>0) {
			window.location=base_url+object_to_search.value;
	}
}

function perform_poster_search() {
	object_to_search=document.getElementById("poster_search");
		if (object_to_search.value.length>0) {
			window.location='/shop/posters/'+object_to_search.value;
	}
}

function set_rate_choice(choice) {
	if (choice=='positive') {
		document.getElementById("type_of_vote").value=choice;
	} else {
		if (choice=='negative') {
			document.getElementById("type_of_vote").value=choice;
		} else {
			document.getElementById("type_of_vote").value='undefined';
		}
	}
}

function jump_to_url (id_to_fetch) {
	url_to_jump=document.getElementById(id_to_fetch).value;
	window.location=url_to_jump;
}

function filtrate_events_keyword () {
	var keyword=document.getElementById('events_keyword').value;
	var city=document.getElementById('search_city').value;
	
	var type=document.getElementById('search_type').value;

	var redirection;

	redirection = (keyword.length>0)
		? '/events/search/'+keyword+'/?in='+city+'&t='+type
		: '/events/search/?in='+city+'&t='+type;

		window.location=redirection;
}

function filtrate_events2 () {
	var keyword=document.getElementById('events_keyword').value;
	var city=document.getElementById('search_city').value;
	var from=document.getElementById('start_date').value;
	var to=document.getElementById('end_date').value;

	if (keyword!='Keyword' && keyword.length>0) {
		window.location='/events/search/'+keyword+'/?in='+city+'&from='+from+'&to='+to;
	} else {
		window.location='/events/search/?in='+city+'&from='+from+'&to='+to;
	}
}

function filtrate_events(cat, city) {
		
	var from=document.getElementById('start_date').value;
	var to=document.getElementById('end_date').value;

	if (from.length > 9 && to.length > 9) {
		if (cat!='') {
			if (city!='') {
				window.location='/events/'+cat+'/'+city+'/?from='+from+"&to="+to;
			} else {
				window.location='/events/'+cat+'/?from='+from+"&to="+to;
			}
	
		} else {
			if (city!='') {
				window.location='/events/'+city+'/?from='+from+"&to="+to;
			} else {
				window.location='/events/?from='+from+"&to="+to;
			}
		}
	}
}

function final_poster_price(base_price) {
	var postage = document.getElementById('postage_options').value;
	var new_final_price = parseFloat(base_price) + parseFloat(postage);
	
	//WP
	if (document.buy_poster_form) {
		document.buy_poster_form.amount.value = new_final_price;
	}
	
	//PP
	if (document.buy_poster_form_pp) {
		document.buy_poster_form_pp.amount.value = new_final_price;
	}
	
	fetch_address();
	
	$("#price_to_pay").hide("fast");
	$("#price_to_pay").html("<b>&pound;"+new_final_price.toFixed(2)+"</b>");
	$("#price_to_pay").show("medium");
}

function fetch_address() {
	// WP fields
	if (document.buy_poster_form) {
		document.buy_poster_form.MC_delivery_name.value=document.buy_poster_form.delivery_name.value;
		document.buy_poster_form.MC_delivery_address.value=document.buy_poster_form.delivery_address.value;
		document.buy_poster_form.MC_delivery_pcode.value=document.buy_poster_form.delivery_pcode.value;
		document.buy_poster_form.MC_delivery_city.value=document.buy_poster_form.delivery_city.value;
		document.buy_poster_form.MC_delivery_country.value=document.buy_poster_form.delivery_country.value;
	}
	
	// PP fields
	if (document.buy_poster_form_pp) {
		var customString;
		customString = document.buy_poster_form.delivery_name.value+'***'+document.buy_poster_form.delivery_address.value+'***'+document.buy_poster_form.delivery_pcode.value+'***'+document.buy_poster_form.delivery_city.value+'***'+document.buy_poster_form.delivery_country.value;
		document.buy_poster_form_pp.custom.value=customString;
	}
}

function settype(type) {
	document.buy_poster_form.poster_type_chosen.value = type;
}

function openWin(compId){
	if(winOpen){
		winOpen.focus();
	} else {
		winOpen = window.open('/win/enter_address/'+compId, 'address', 
		'width=470,height=350,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes,screenx=400,screeny=500')
	}
}
