// Password checking: 2 password fields mut be equal, min 6 chars length

function passIsEqual( pass1ID, pass2ID ) {
	var pass1 =  document.getElementById( pass1ID );
	var pass2 =  document.getElementById( pass2ID );
	if( pass1.value == pass2.value ) {
		return true;
	}
	return false;
}

// Input is not empty
function isNotEmptyField( idElem ) {
	if( document.getElementById( idElem ) ) {
		if( document.getElementById( idElem ).value != "" && document.getElementById( idElem ).value != "0" ) {
			return true;
		}
		//document.getElementById( idElem ).focus();
	}
	return false;
}

// Value is higher than (integer)
function higherThan( idElem, indexInt ) {
	if( document.getElementById( idElem ) ) {
		if( document.getElementById( idElem ).value.length > indexInt ) {
			return true;
		}
		//document.getElementById( idElem ).focus();
	}
	return false;
}

// Value is equal (integer)
function equalAs( idElem, indexInt ) {
	if( document.getElementById( idElem ) ) {
		if( document.getElementById( idElem ).value.length == indexInt ) {
			return true;
		}
		//document.getElementById( idElem ).focus();
	}
	return false;
}

// Radio or checkbox is selected
function isChecked( idElem ) {
	if( document.getElementById( idElem ) ) {
		if( document.getElementById( idElem ).checked ) {
			return true;
		}
	}
	alert('Option not checked');
	return false;
}

// Radio or checkbox is selected
function isCheckedMarketing( idElem ) {
	if( document.getElementById( idElem ) ) {
		if( document.getElementById( idElem ).checked ) {
			return true;
		}
	}
	alert('You can only enter the competition if you agree with the competition terms. Please tick the checkbox underneath the form and try again.');
	return false;
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	else
	countfield.value = maxlimit - field.value.length;
}

// Valid e-mail
function isValidEmail( elem ) {
	str = document.getElementById(elem).value;
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

// Set focus on input
function setFocus( idElem ) {
	document.getElementById( idElem ).focus();
}

// Clear inputvalue
function clearValue( idElem ) {
	document.getElementById( idElem ).value = '';;
}


function setCSSChange( idElem, colorChange ) {
	//document.getElementById( idElem ).style.border = '1px solid #CC0000';;
	document.getElementById( 'l_'+idElem ).style.color = colorChange;;
}




function getObj(name){
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}


var elementList = new Array();
var nameList 	= new Array();

function addElementToListEmpty( element, ename ) {
	elementList[elementList.length] = element;
	nameList[nameList.length] 	= ename;
}

var varErrorString = '';

function validateForm() {
	varErrorString = "";
	var myErrorArray = new Array();
	var myErrorArrayPointer = 0;
	for(var i=0;i<elementList.length;i++) {
		setCSSChange( elementList[i], "#000" );
		if( !isNotEmptyField( elementList[i] ) ) {
			varErrorString = varErrorString + 'Field "' +nameList[i]+ ' is required!\n';
			// dodaj error do listy
			myErrorArray[myErrorArrayPointer] = elementList[i];
			myErrorArrayPointer++;
		}
	}
	if( varErrorString =='' ) {
		return true;
	}
	for(var i=0;i<myErrorArrayPointer;i++) {
		setCSSChange( myErrorArray[i], "#CC0000" );
	}
	setFocus( myErrorArray[0] );
	alert("Please fill in all fileds listed below:\n"+varErrorString);
	return false;
}


var zmienionoUprawnienia = false;

function uprawnieniaZmieniono() {
	if( !zmienionoUprawnienia ) {
		pokazButtony();
	}
	zmienionoUprawnienia = true;
}

function wylaczPrzekierowanie() {
	zmienionoUprawnienia = false;
}


function pokazButtony() {
	document.getElementById('btns-1').style.display='block';
	document.getElementById('btns-2').style.display='block';
}


function sprawdzZmianyUprawnien() {
	if( zmienionoUprawnienia ) {
		//if( confirm( "Czy zapisac zmiany?" ) ) {
		//document.forms[0].submit();
		//self.location.reload();
		//}
	}
}

function isNumeric(expression) {
	var nums = "0123456789";
	if (expression.length==0)
	return false;
	for (var n=0; n < expression.length; n++)
	{
		if(nums.indexOf(expression.charAt(n))==-1)
		return false;
	}
	return true;
}

function sendRegister() {

	var how_heard = document.getElementById('register-form_how_heard').value;
	var name = document.getElementById('register-form_name').value;
	var email = document.getElementById('register-form_email').value;
	var type = document.getElementById('event_type').value;
	if (type == 1){
		var quantity = document.getElementById('register-form_quantity').value;
	} else {
		var quantity_male = document.getElementById('register-form_quantity_male').value;
		var quantity_female = document.getElementById('register-form_quantity_female').value;
		var quantity = quantity_male+quantity_female;
	}

	if (how_heard != '' && name != '' && email != '' && quantity != '' && quantity != 0) {
		if (!isValidEmail(email))
		{
			alert ('Not valid email!');
			return false;
		}
		if (!isNumeric(quantity))
		{
			alert ('Not valid quantity!');
			return false;
		}
		document.getElementById('register-form').submit();
		return true;
	}
	alert ('You have to fill all fields!');
	return false;
}

function changeCategory(country) {
	var select = document.getElementById('subject-select').value;
	if (select != "") {
		document.location.href=country+'/life_in/ask_expert_list/'+select+'.html';
		return;
	}
	alert ('You have to select a subject!');
}

function selectExpert(country) {
	var select = document.getElementById('expert-select').value;
	if (select != "") {
		document.location.href=country+'/life_in/ask_expert/'+select+'.html';
		return;
	}
	alert ('You have to select an expert!');
}

function selectListing(num, sub_url) {
	var select = document.getElementById('listing-change'+num).value;
	if (select != "") {
		document.location.href=sub_url+'/listings/details/'+select+'.html';
		return;
	}
	alert ('You have to select category!');
}

function selectEvent() {
	var select = document.getElementById('event-change').value;
	if (select != "") {
		document.location.href='/whats_on/register/'+select+'.html';
		return;
	}
	alert ('You have to select event!');
}

function allValidChars(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		continue;
		parsed = false;
		break;
	}
	return parsed;
}

function isValidEmail(email, required) {
	if (required==undefined) {   // if not specified, assume it's required
		required=true;
	}
	if (email==null) {
		if (required) {
			return false;
		}
		return true;
	}
	if (email.length==0) {
		if (required) {
			return false;
		}
		return true;
	}
	if (! allValidChars(email)) {  // check to make sure all characters are valid
		return false;
	}
	if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
		return false;
	} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
		return false;
	} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
		return false;
	} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
	} else if (email.indexOf(".") == email.length) {  // . must not be the last character
		return false;
	}
	return true;
}

function scrollAnswer( answerID ) {
	document.getElementById('answer_'+answerID).style.display = "block";
}
function hideAnswer( answerID ) {
	document.getElementById('answer_'+answerID).style.display = "none";
}

function scrollWinners( winnerID ) {
	document.getElementById('winners_'+winnerID).style.display = "block";
}
function hideWinners( winnerID ) {
	document.getElementById('winners_'+winnerID).style.display = "none";
}

function clickBrowseFile(pic)
{
	document.getElementById(pic).click();
}

var pic_input = 2;
function ViewNextPicInputs()
{
	if (pic_input < 5)
	{
		document.getElementById('pic_inputs-'+pic_input).style.display = "block";
		pic_input++;
	}
	else
	{
		document.getElementById('pic_inputs-5').style.display = "block";
		document.getElementById('morePictures').style.display = "none";
	}
}

function galeria( img, w, h ){
	opcje = "height="+ h +",width="+ w +",scrollbars=no,resizable=no,menubar=no";
	w = window.open("/img.php?img=" + img, "", opcje, true);
	w.focus ();
}



/* FORUM */

function forumGaleria( tematID, imgID ) {
	newwindow=window.open( '/forum/galeria/' + tematID +'.html?img='+imgID, 'forum_img', 'height=700,width=780,scrollbars=auto,resizable=yes,menubar=no,top=0,left=0' )
	if (window.focus) {newwindow.focus()}
	return false;
}

function forumUser( userID ) {
	newwindow=window.open( '/forum/user/' + userID +'.html', 'forum_img', 'height=200,width=400,scrollbars=auto,resizable=yes,menubar=no,top=0,left=0' )
	if (window.focus) {newwindow.focus()}
	return false;
}



function startForumTimeout() {
	setTimeout( "getBacLocation()", 2000 );
}


function getBacLocation() {
	history.back();
	//document.location.reload();
}
/*
function doPopup(strona) {
newwindow=window.open( '/popup/'+strona+'.html','preview','height=525,width=691,scrollbars=yes');
if (window.focus) {newwindow.focus()};
}

function doPopupAskExpert(qid) {
newwindow=window.open( '/popup_ask_expert/'+qid+'.html','preview','height=525,width=675,scrollbars=yes');
if (window.focus) {newwindow.focus()};
}
*/
function doPopup(strona) {
	newwindow=window.open( 'http://www.expatica.com/popup/'+strona+'.html','preview','height=525,width=425,scrollbars=yes, resizable=no');
	if (window.focus) {newwindow.focus()};
}

function doPopupAskExpert(qid) {
	newwindow=window.open( 'http://www.expatica.com/popup_ask_expert/'+qid+'.html','preview','height=525,width=408,scrollbars=yes,resizable=no');
	if (window.focus) {newwindow.focus()};
}

function doPopupWhyRegister() {
	newwindow=window.open( 'http://www.expatica.com/popup/why_register.html','preview','height=180,width=408,scrollbars=no,left=330,top=400, resizable=no');
	if (window.focus) {newwindow.focus()};
}

function doPopupGeneral(url) {
	newwindow=window.open(url,'preview','height=15,width=325,scrollbars=no, resizable=no');
	if (window.focus) {newwindow.focus()};
}

var previewFields = new Array();

function showPreview( template ) {
	newwindow=window.open( '/templates/popup/'+template,'preview','height=500,width=520,scrollbars=yes');
	if (window.focus) {newwindow.focus()};
}


function performShow() {
	for( var i=0; previewFields[i]; i++ ) {
		var source = document.getElementById( previewFields[i] );
		if( source ) {
			var dest = newwindow.document.getElementById( previewFields[i]+"_add" );
			dest.innerHTML = source.value;
		}
	}
}

var ocena = 0;

function SetVal(value){
	if (ocena == 0)
	ocena = value;
	else
	ocena = 0;
}
function ocenaRefresh(value) {
	if (ocena > 0) return;
	if (value > 0)
	{
		document.getElementById('vote_1').src = "../../../images/star_full.gif";
	}
	if (value > 1)
	{
		document.getElementById('vote_2').src = "../../../images/star_full.gif";
	}
	if (value > 2)
	{
		document.getElementById('vote_3').src = "../../../images/star_full.gif";
	}
	if (value > 3)
	{
		document.getElementById('vote_4').src = "../../../images/star_full.gif";
	}
	if (value > 4)
	{
		document.getElementById('vote_5').src = "../../../images/star_full.gif";
	}
}

function ocenaEmpty() {
	if (ocena > 0) return;
	document.getElementById('vote_1').src = "../../../images/star_empty.gif";
	document.getElementById('vote_2').src = "../../../images/star_empty.gif";
	document.getElementById('vote_3').src = "../../../images/star_empty.gif";
	document.getElementById('vote_4').src = "../../../images/star_empty.gif";
	document.getElementById('vote_5').src = "../../../images/star_empty.gif";
}

function changeContact() {
	var id = document.getElementById('reaction-form_why').value;

	var values = new Array(
	'',
	'Positive or negative, we welcome your feedback. If your feedback pertains to a specific part of Expatica please be as accurate as possible in telling us which part.',
	'Write your comments in the large space provided. Be sure to tell us which article you\'re writing about. There is no limit to the length of your message. If you do not wish your submission to be considered for publication as a Letter to the Editor, please uncheck the box at the bottom.',
	'If you encountered a problem with some part of the Expatica web site, please tell us as much as possible about the problem so that we can solve it quickly. Include details about your operating system, browser type and version, and exactly what you were doing when you encountered the problem. If possible, please paste the contents of any error messages you encountered into your message.',
	'If you\'re having difficulty operating some part of Expatica or need help understanding what something is or how something works, tell us in as much detail as possible and we\'ll do our best to help.',
	'Got a question about one of our Expat Nights? Fill in the form and you\'ll receive a reply shortly.',
	'Ask your question about Expatica DATE! below and you\'ll receive a reply shortly.',
	'Have a question or problem with the Expatica Passport? Fill in the form below and you\'ll receive a reply shortly. If you have an Expatica Passport, please be sure to include the number printed on the face of the card.',
	'For questions about Expatica\'s marketing activities or to contact Expatica\'s marketing department, fill in the form below.',
	'If your question concerns advertising on Expatica, please tell us as much about yourself as possible so that we may be well prepared when we contact you. If you wish to be contacted by telephone, be sure to include your telephone number and when you prefer to be called.',
	'For billing inquiries, use the form below to contact Expatica\'s Office Manager.',
	'' );

	document.getElementById('select-info').innerHTML = values[id];
}




/* AJAX */


var actualLink;
var actualContainer;

function loadAjaxPage( linkURL, containerID ) {
	actualLink = linkURL;
	actualContainer = containerID;
	$.ajax({
		url: linkURL,
		success: function(msg){
			$("#"+containerID).html( msg );
		}
	});
}

function loadAjaxPagePrint( linkURL, containerID ) {
	//	alert(linkURL);
	actualLink = linkURL;
	actualContainer = containerID;
	$.ajax({
		url: linkURL,
		success: function(msg){
			$("#"+containerID).html( msg );
			window.print();
		}
	});
}

function loadAjaxPageK_OLD( linkURL, containerID ) {
	actualLink = linkURL;
	actualContainer = containerID;
	$(".hider").fadeIn(400, function() {
		$.ajax({
			url: linkURL,
			success: function(msg){
				$("#"+containerID).html( msg );
			}
		})
	});
}

function loadAjaxPageK( linkURL, containerID ) {
	actualLink = linkURL;
	actualContainer = containerID;
	$.ajax({
		url: linkURL,
		success: function(msg){
			$(".hider").fadeIn(500, function() {
				$("#"+containerID).html( msg );
			});
		}
	})
}

function reloadPage( pageNum ) {
	advAJAX.get({
		url: actualLink+'?strona='+pageNum,
		onSuccess : function(obj) { if( obj.responseText.length > 1 ) {  document.getElementById(actualContainer).innerHTML = obj.responseText; } }
	});
}


function getFullArticle( url, type ) {
	loadAjaxPagePrint('/ajax/get_whole_article.html?url='+url+'&type='+type, 'inner_text_content');
}

function wyswietlHeadlines( typ, limit ) {
	loadAjaxPage('/ajax/headlines.html?typ='+typ+'&limit='+limit, 'headlines');
}

function wyswietlLeisure( typ, limit ) {
	loadAjaxPage('/ajax/leisure.html?typ='+typ+'&limit='+limit, 'ajax-leisure');
}
function wyswietlSurvLeisure( typ, limit ) {
	loadAjaxPage('/ajax/surv_leisure.html?typ='+typ+'&limit='+limit, 'ajax-leisure');
}

function wyswietlLeisureList( typ, limit, page ) {
	loadAjaxPage('/ajax/leisure_list.html?typ='+typ+'&limit='+limit+'&page='+page, 'ajax-leisure');
}
function wyswietlEntLeisureList( typ, limit, page ) {
	loadAjaxPage('/ajax/ent_leisure_list.html?typ='+typ+'&limit='+limit+'&page='+page, 'ajax-leisure');
}
function wyswietlSurvLeisureList( typ, limit, page ) {
	loadAjaxPage('/ajax/surv_leisure_list.html?typ='+typ+'&limit='+limit+'&page='+page, 'ajax-leisure');
}

function wyswietlMostPopular( typ, limit, box_w ) {
	loadAjaxPage('/ajax/most_popular.html?typ='+typ+'&limit='+limit+'&box_w='+box_w, 'ajax-most_popular');
}

function wyswietlMostPopularHR( typ, limit, box_w ) {
	loadAjaxPage('/ajax/most_popular_hr.html?typ='+typ+'&limit='+limit+'&box_w='+box_w, 'ajax-most_popular');
}

function wyswietlWeather( opcja ) {
	loadAjaxPage('/ajax/weather.html?opcja='+opcja, 'ajax-weather');
}

function wyswietlFeatureChanger() {
	wyswietlFeature();
}

var showFeatureOpcja = 0;
function wyswietlFeature( opcja ) {
	if( typeof( opcja ) == "undefined" ) {
		opcja = showFeatureOpcja+1;
		if( opcja > 4 ) {
			opcja = 0;
		}
	}
	showFeatureOpcja = opcja;
	loadAjaxPageK('/ajax/main_feature.html?nr='+opcja, 'ajax-main_feature');
}

function wyswietlAllTags( opcja ) {
	loadAjaxPage('/ajax/all_tags.html?&opcja='+opcja, 'ajax-tags');
}

function wyswietlTags(dzial, url, opcja, limit ) {
	loadAjaxPage('/ajax/tags.html?dzial='+dzial+'&url='+url+'&opcja='+opcja+'&limit='+limit, 'ajax-tags');
}

function wyswietlEvents( typ, limit ) {
	loadAjaxPage('/ajax/events.html?typ='+typ+'&limit='+limit, 'ajax-events');
}

function wyswietlCalendar( typ, limit, year, month ) {
	loadAjaxPage('/ajax/calendar.html?typ='+typ+'&limit='+limit+'&year='+year+'&month='+month, 'ajax-events');
}

function wyswietlCalendarDay( typ, limit, date ) {
	loadAjaxPage('/ajax/calendar.html?typ='+typ+'&limit='+limit+'&date='+date, 'ajax-events');
}

function wyswietlCalendarBox( year, month ) {
	loadAjaxPage('/ajax/calendar_box.html?year='+year+'&month='+month, 'ajax-calendar');
}

function wyswietlNewspapers( limit, newspaper ) {
	loadAjaxPage('/ajax/newspapers.html?limit='+limit+'&newspaper='+newspaper, 'ajax-newspaper');
}

function wyswietlExpert( opcja, limit ) {
	var path = '/ajax/expert.html?opcja='+opcja+'&limit='+limit ;
	if (arguments[2]){
		path += '&expert='+arguments[2];
	}
	loadAjaxPage(path, 'ajax-ask_expert');
}

function wyswietlReactForm(dzial, url, limit, mtype ) {
	loadAjaxPage('/ajax/reactions.html?dzial='+dzial+'&url='+url+'&typ=form&limit='+limit+'&materialTyp='+mtype, 'ajax-reactions');
}

function ukryjReactForm(dzial, url, limit, mtype ) {
	loadAjaxPage('/ajax/reactions.html?dzial='+dzial+'&url='+url+'&limit='+limit+'&materialTyp='+mtype, 'ajax-reactions');
}

function showExpertForm() {
	loadAjaxPage('/ajax/expert_form.html?typ=form', 'ajax-expert_form');
}

function hideExpertForm() {
	loadAjaxPage('/ajax/expert_form.html?typ=no', 'ajax-expert_form');
}

function updateWhatsOnCalendar(url) {
	loadAjaxPage('/ajax/whats-on-calendar.html?'+ url);
}

function showSendToAFriend(url, title) {
	loadAjaxPage('/ajax/send_to_a_friend.html?url='+url+'&title='+title+'&typ=form', 'ajax-send_to_a_friend');
}

function showSendSuggestion(url, title) {
	loadAjaxPage('/ajax/send_suggestion.html?url='+url+'&title='+title+'&typ=form', 'ajax-send_to_a_friend');
}

function changeEvent() {
	var select = document.getElementById('event-change').value;
	loadAjaxPage('/ajax/change_event.html?select='+select, 'ajax-register');
}

function doRegionalHeadlines(limit, country, ids) {
	var select = document.getElementById('change-regional').value;
	loadAjaxPage('/ajax/change_regional.html?limit='+limit+'&select='+select+'&country='+country+'&ids='+ids, 'ajax-regional');
}


function doRate(link, url) {

	if (ocena == 0)
	{
		alert ('You have to select rate!');
		return false;
	}
	loadAjaxPage('/ajax/rate_article.html?link='+link+'&url='+url+'&rating='+ocena, 'ajax-rating');
}

function sendExpert() {
	var first_name = document.getElementById('expert-form_first_name').value;
	var last_name = document.getElementById('expert-form_last_name').value;
	var email = document.getElementById('expert-form_mail').value;
	//	var pass = document.getElementById('expert-form_pass').value;
	//	var pass_2 = document.getElementById('expert-form_pass_2').value;
	var company = document.getElementById('expert-form_company').value;
	var func = document.getElementById('expert-form_function').value;
	var industry = document.getElementById('expert-form_industry').value;
	var suggest_industry = document.getElementById('expert-form_suggest_industry').value;
	var country = document.getElementById('expert-form_country').value;
	var short_cv = document.getElementById('short_cv').value;

	if (email != '' && !isValidEmail(email))
	{
		email = 'error';
	}
	/*	if (pass != '' && pass != pass_2)
	{
	pass = 'error';
	}
	*/ $.ajax({
	type: "POST",
	url: '/ajax/expert_form.html?typ=send',
	data:  "first_name="+first_name+"&last_name="+last_name+"&email="+email+"&company="+company+"&func="+func+"&industry="+industry+"&suggest_industry="+suggest_industry+"&country="+country+"&short_cv="+short_cv,
	success: function(msg){
		$("#ajax-expert_form").html(msg);
	}
	});
	return;
}


function wyslijReaction(dzial, url, limit, materialID, materialTyp) {
	var user = document.getElementById('reaction-form_user').value;
	var email = document.getElementById('reaction-form_mail').value;
	var tresc = document.getElementById('reaction-form_content').value;
	var logged = document.getElementById('reaction-form_logged').value;
	if (document.getElementById('reaction-form_check1').checked == true){
		var copy = document.getElementById('reaction-form_check1').value;
	}
	else
	{
		var copy = '';
	}
	if (document.getElementById('reaction-form_check2').checked == true){
		var notify = document.getElementById('reaction-form_check2').value;
	}
	else
	{
		var notify = '';
	}
	var token = document.getElementById('reaction-form_token').value;

	if (email != '' && !isValidEmail(email))
	{
		email = 'error';
	}
	$.ajax({
		type: "POST",
		url: '/ajax/reactions.html?dzial='+dzial+'&url='+url+'&typ=send&limit='+limit+'&materialID='+materialID+'&materialTyp='+materialTyp,
		data:  "user="+user+"&email="+email+"&logged="+logged+"&tresc="+tresc+"&copy="+copy+"&notify="+notify+"&token="+token,
		success: function(msg){
			$("#ajax-reactions").html(msg);
		}
	});
	return;
}

function wyslijContactUs() {
	var why = document.getElementById('reaction-form_why').value;
	var user = document.getElementById('reaction-form_user').value;
	var email = document.getElementById('reaction-form_mail').value;
	var tresc = document.getElementById('reaction-form_content').value;
	if (document.getElementById('reaction-form_check1').checked == true){
		var copy = document.getElementById('reaction-form_check1').value;
	}
	else
	{
		var copy = '';
	}
	if (document.getElementById('reaction-form_check2').checked == true){
		var notify = document.getElementById('reaction-form_check2').value;
	}
	else
	{
		var notify = '';
	}
	var token = document.getElementById('reaction-form_token').value;
	if (email != '' && !isValidEmail(email))
	{
		email = 'error';
	}
	$.ajax({
		type: "POST",
		url: '/ajax/contact_us.html?typ=send',
		data:  "why="+why+"&user="+user+"&email="+email+"&tresc="+tresc+"&copy="+copy+"&notify="+notify+"&token="+token,
		success: function(msg){
			$("#ajax-contact_us").html(msg);
		}
	});
	return;
}

function sendQuestion()
{
	var user = document.getElementById('question-form_user').value;
	var email = document.getElementById('question-form_email').value;
	var tresc = document.getElementById('question-form_content').value;
	var expert = document.getElementById('question-form_expert').value;
	var country_id = document.getElementById('question-form_country_id').value;

	if (expert.length == 0)
	{
		alert ('You have to select an expert!');
		return false;
	}

	if (tresc != '' && user != '' && email != '')
	{
		if (!isValidEmail(email))
		{
			alert ('Not valid email!');
			return false;
		}
		$.ajax({
			type: "POST",
			url: '/ajax/send_question.html?expert='+expert,
			data:  "user="+user+"&email="+email+"&tresc="+tresc+"&country_id="+country_id,
			success: function(msg)
			{
				$("#ajax-send_question").html(msg);
			}
		});
		
		return;
	}
	
	alert ('You have to fill all fields!');
}



function wyslijSendToAFriend(url, title) {
	var yourName = document.getElementById('send_to_friend-form_your_name').value;
	var yourEmail = document.getElementById('send_to_friend-form_your_email').value;
	var recName = document.getElementById('send_to_friend-form_recipient_name').value;
	var recEmail = document.getElementById('send_to_friend-form_recipient_email').value;
	var message = document.getElementById('send_to_friend-form_message').value;

	if (yourEmail != '' && !isValidEmail(yourEmail))
	{
		yourEmail = 'error';
	}
	if (recEmail != '' && !isValidEmail(recEmail))
	{
		recEmail = 'error';
	}
	$.ajax({
		type: "POST",
		url:  '/ajax/send_to_a_friend.html?url='+url+'&title='+title+'&typ=send',
		data:  "yourName="+yourName+"&yourEmail="+yourEmail+"&recName="+recName+"&recEmail="+recEmail+"&message="+message,
		success: function(msg){
			$("#ajax-send_to_a_friend").html(msg);
		}
	});
	return;
}

function changeCountry(country) {
	loadAjaxPage('/ajax/load_cities.html?country='+country, 'cities');
}

function sendNewsletter() {
	var email = document.getElementById('newsletter-form_email').value;
	var selected = document.getElementById('selected').value;
	if (document.getElementById('newsletter-checkbox_1').checked == true){
		var check_1 = 1;
	} else {
		var check_1 = 0;
	}
	if (document.getElementById('newsletter-checkbox_2').checked == true){
		var check_2 = 1;
	} else {
		var check_2 = 0;
	}
	if (document.getElementById('newsletter-checkbox_3').checked == true){
		var check_3 = 1;
	} else {
		var check_3 = 0;
	}
	if (document.getElementById('newsletter-checkbox_4').checked == true){
		var check_4 = 1;
	} else {
		var check_4 = 0;
	}
	if (email != '' && !isValidEmail(email))
	{
		email = 'error';
	}

	loadAjaxPage('/ajax/send_newsletter.html?typ=send&selected='+selected+'&email='+email+'&check_1='+check_1+'&check_2='+check_2+'&check_3='+check_3+'&check_4='+check_4, 'ajax-newsletter');
	//document.location = 'http://new_expatica.nextborn.com/be/ajax/send_newsletter.html?typ=send&email='+email+'&check_1='+check_1+'&check_2='+check_2+'&check_3='+check_3+'&check_4='+check_4;

}

function sendLoggedNewsletter() {
	document.getElementById('send_btn').disabled = true;
	$('#send_btn').val('Please wait...');
	$('#loading_txt').html('<img src="/images/loader.gif"/>');
	var user_id = document.getElementById('newsletter-form_id').value;
	var email = document.getElementById('newsletter-form_email').value;
	var daily_be = 0;
	var daily_fr = 0;
	var daily_de = 0;
	var daily_nl = 0;
	var daily_es = 0;
	var daily_ch = 0;
	var daily_uk = 0;
	var daily_lu = 0;
	var daily_ru = 0;
	var weekly_be = 0;
	var weekly_fr = 0;
	var weekly_de = 0;
	var weekly_nl = 0;
	var weekly_es = 0;
	var weekly_ch = 0;
	var weekly_uk = 0;
	var weekly_lu = 0;
	var weekly_ru = 0;
	var whatson_be = 0;
	var whatson_fr = 0;
	var whatson_de = 0;
	var whatson_nl = 0;
	var whatson_es = 0;
	var whatson_ch = 0;
	var whatson_uk = 0;
	var whatson_lu = 0;
	var whatson_ru = 0;
	var expatica_hr = 0;
	if (document.getElementById('daily_be').checked == true) daily_be = 1;
	if (document.getElementById('daily_fr').checked == true) daily_fr = 1;
	if (document.getElementById('daily_de').checked == true) daily_de = 1;
	if (document.getElementById('daily_nl').checked == true) daily_nl = 1;
	if (document.getElementById('daily_es').checked == true) daily_es = 1;
	if (document.getElementById('daily_ch').checked == true) daily_ch = 1;
	if (document.getElementById('daily_uk').checked == true) daily_uk = 1;
	if (document.getElementById('daily_lu').checked == true) daily_lu = 1;
	if (document.getElementById('daily_ru').checked == true) daily_ru = 1;

	if (document.getElementById('weekly_be').checked == true) weekly_be = 1;
	if (document.getElementById('weekly_fr').checked == true) weekly_fr = 1;
	if (document.getElementById('weekly_de').checked == true) weekly_de = 1;
	if (document.getElementById('weekly_nl').checked == true) weekly_nl = 1;
	if (document.getElementById('weekly_es').checked == true) weekly_es = 1;
	if (document.getElementById('weekly_ch').checked == true) weekly_ch = 1;
	if (document.getElementById('weekly_uk').checked == true) weekly_uk = 1;
	if (document.getElementById('weekly_lu').checked == true) weekly_lu = 1;
	if (document.getElementById('weekly_ru').checked == true) weekly_ru = 1;

	if (document.getElementById('whatson_be').checked == true) whatson_be = 1;
	if (document.getElementById('whatson_fr').checked == true) whatson_fr = 1;
	if (document.getElementById('whatson_de').checked == true) whatson_de = 1;
	if (document.getElementById('whatson_nl').checked == true) whatson_nl = 1;
	if (document.getElementById('whatson_es').checked == true) whatson_es = 1;
	if (document.getElementById('whatson_ch').checked == true) whatson_ch = 1;
	if (document.getElementById('whatson_uk').checked == true) whatson_uk = 1;
	if (document.getElementById('whatson_lu').checked == true) whatson_lu = 1;
	if (document.getElementById('whatson_ru').checked == true) whatson_ru = 1;

	if (document.getElementById('expatica_hr').checked == true) expatica_hr = 1;

	if (email != '' && !isValidEmail(email)) email = 'error';

	var selected = document.getElementById('selected').value;
	var page_url = '/ajax/send_newsletter.html?typ=send&selected='+selected+'&user_id='+user_id+'&email='+email+'&daily_be='+daily_be+'&daily_fr='+daily_fr+'&daily_de='+daily_de+'&daily_nl='+daily_nl+'&daily_es='+daily_es+'&daily_ch='+daily_ch+'&daily_uk='+daily_uk+'&daily_lu='+daily_lu+'&daily_ru='+daily_ru+'&weekly_be='+weekly_be+'&weekly_fr='+weekly_fr+'&weekly_de='+weekly_de+'&weekly_nl='+weekly_nl+'&weekly_es='+weekly_es+'&weekly_ch='+weekly_ch+'&weekly_uk='+weekly_uk+'&weekly_lu='+weekly_lu+'&weekly_ru='+weekly_ru+'&whatson_be='+whatson_be+'&whatson_fr='+whatson_fr+'&whatson_de='+whatson_de+'&whatson_nl='+whatson_nl+'&whatson_es='+whatson_es+'&whatson_ch='+whatson_ch+'&whatson_uk='+whatson_uk+'&whatson_lu='+whatson_lu+'&whatson_ru='+whatson_ru+'&expatica_hr='+expatica_hr;
	$.ajax({
		url: page_url,
		success: function(msg){
			document.getElementById('send_btn').disabled = false;
			$('#send_btn').val('Submit');
			$('#loading_txt').html('');

			$("#ajax-newsletter").fadeIn(500, function() {
				$("#ajax-newsletter").html( msg );
			});
		}
	})
}
function sendNotLoggedNewsletter() {

	var selected = document.getElementById('selected').value;
	var email = document.getElementById('newsletter-form_email').value;
	
	if (email != '' && isValidEmail(email)) {
		document.getElementById('setemail_btn').disabled = true;
		
		$('#setemail_btn').val('Please wait...');
		var page_url = '/ajax/send_notloggednewsletter.html?email='+email+'&selected='+selected;
		$.ajax({
			url: page_url,
			success: function(msg){
				document.getElementById('setemail_btn').disabled = false;
				$('#setemail_btn').val('Submit');
				$("#choose_checks").html( msg );
			}
		})
	}else {
		$("#notlogged_res").html( 'Please enter a valid email!' );
	}
}

function sendNewsletterLogged() {
	var email = document.getElementById('newsletter-form_email').value;
	if (email == '' || !isValidEmail(email))
	{
		email = 'error';
	}
	loadAjaxPage('/ajax/newsletter.html?email='+email, 'ajax-newsletter');

}

function wyslijShareSite() {
	var yourName = document.getElementById('send_to_friend-form_your_name').value;
	var yourEmail = document.getElementById('send_to_friend-form_your_email').value;
	var recName = document.getElementById('send_to_friend-form_recipient_name').value;
	var recEmail = document.getElementById('send_to_friend-form_recipient_email').value;
	var message = document.getElementById('send_to_friend-form_message').value;

	if (yourEmail != '' && !isValidEmail(yourEmail))
	{
		yourEmail = 'error';
	}
	if (recEmail != '' && !isValidEmail(recEmail))
	{
		recEmail = 'error';
	}
	$.ajax({
		type: "POST",
		url: '/ajax/share_this_site.html?typ=send',
		data:  "yourName="+yourName+"&yourEmail="+yourEmail+"&recName="+recName+"&recEmail="+recEmail+"&message="+message,
		success: function(msg){
			$("#ajax-share_site").html(msg);
		}
	});
	return;
}

function wyslijSendSuggestion(url, title) {
	var yourName = document.getElementById('send_suggestion-form_your_name').value;
	var yourEmail = document.getElementById('send_suggestion-form_your_email').value;
	var message = document.getElementById('send_suggestion-form_message').value;

	if (yourEmail != '' && !isValidEmail(yourEmail))
	{
		yourEmail = 'error';
	}
	$.ajax({
		type: "POST",
		url: '/ajax/send_suggestion.html?url='+url+'&title='+title+'&typ=send',
		data:  "yourName="+yourName+"&yourEmail="+yourEmail+"&message="+message,
		success: function(msg){
			$("#ajax-send_to_a_friend").html(msg);
		}
	});
	return;
}

function submitSignup() {

	var yourEmail = document.getElementById('signup-form_your_email').value;
	var pass = document.getElementById('signup-form_pass').value;
	var pass_2 = document.getElementById('signup-form_pass_2').value;
	//var token = document.getElementById('signup-form_token').value;
	//var recaptcha_response_field = $("input[@name='recaptcha_response_field']").val();
	//var recaptcha_challenge_field = $("input[@name='recaptcha_challenge_field']").val();
	if (yourEmail != '' && !isValidEmail(yourEmail))
	{
		document.getElementById('signup-form_your_email').value = 'error';
	}
	if (pass != '' && pass != pass_2)
	{
		document.getElementById('signup-form_pass').value = 'error';
	}
	document.getElementById('form-profile').submit();
}

function submitWhatson() {
	document.getElementById('form-upload').submit();
}


function sendNewPassword() {
	var email = document.getElementById('forgot-form_email').value;
	if (email == '' || !isValidEmail(email))
	{
		alert('Invalid e-mail!');
		return;
	}
	loadAjaxPage('/ajax/forgot_pass.html?email='+email, 'ajax-forgot_pass');

}

function sendNewUserPassword() {
	var email = document.getElementById('forgot-form_email').value;
	if (email == '' || !isValidEmail(email))
	{
		alert('Invalid e-mail!');
		return;
	}
	loadAjaxPage('/ajax/forgot_user_pass.html?email='+email, 'ajax-forgot_pass');

}

function sendDatingPassword() {
	var email = document.getElementById('forgot-form_email').value;
	if (email == '' || !isValidEmail(email))
	{
		document.getElementById('forgot-form_email').value = "error";
	}
	document.getElementById('forgot-form').submit();

}

function resetPassword() {
	var pass = document.getElementById('reset-form_pass').value;
	var pass_2 = document.getElementById('reset-form_pass_2').value;
	if (pass != pass_2)
	{
		document.getElementById('reset-form_pass').value = "error";
	}
	document.getElementById('reset-form').submit();

}

function sendBusinessSuggestion() {
	var yourEmail = document.getElementById('send_suggestion-form_your_email').value;
	var company = document.getElementById('send_suggestion-form_company').value;
	var category = document.getElementById('send_suggestion-form_category').value;
	var city = document.getElementById('send_suggestion-form_city').value;

	if (yourEmail != '' && !isValidEmail(yourEmail))
	{
		yourEmail = 'error';
	}
	$.ajax({
		type: "POST",
		url: '/ajax/send_listings_suggestion.html?typ=send',
		data:  "yourEmail="+yourEmail+"&company="+company+"&category="+category+"&city="+city,
		success: function(msg){
			$("#ajax-send_suggestion").html(msg);
		}
	});
	return;
}



function submitProfile() {
	var companyEmail = document.getElementById('signup-form_company_email').value;
	if (companyEmail != '' && !isValidEmail(companyEmail))
	{
		document.getElementById('signup-form_company_email').value = 'error';
	}
	document.getElementById('form-profile').submit();
}


function showCat(cat) {
	loadAjaxPage('/ajax/show_cat.html?cat='+cat, 'ajax-cat_'+cat);
}


var chosenListingCity = 0;
var chosenListingCategory = 0;
var chosenListingCityWO = 0;
var chosenListingCategoryWO = 0;
var chosenListingPlaceShowOnMap = 0;
var wo = 0;

function showMapResults(cat) {
	chosenListingCategory = cat;
	getListingsList();
}
// analogous for Whats On section
function showMapResultsWO(cat) {
	chosenListingCategoryWO = cat;
	getListingsListWO();
}


var lastMapSize = "";
function resizeMap( sizeName ) {
	switch( sizeName ) {
		case "big":
		if( lastMapSize != "big" ) {
			$("#google-api-map").css( "width", "470px" );
			$("#show_places").css( "display", "block" );
			$("#listspace").css( "display", "none" );
		}
		break;
		case "small":
		if( lastMapSize != "small" ) {
			$("#google-api-map").css( "width", "370px" );
			$("#show_places").css( "display", "none" );
			$("#listspace").css( "display", "block" );
		}
		break;
	}
	lastMapSize = sizeName;
	map.checkResize();
	map.returnToSavedPosition();
}


function getListingsList() {
	GEvent.addListener(map, "click", function(overlay, point) {
		if (overlay){
			if( overlay.openInfoWindowHtml ) {
				overlay.openInfoWindowHtml(overlay.infowindow);
			}
		} else if (point) {}
	});
	getMarkers( '/ajax/listings_xml/'+chosenListingCategory+'/'+chosenListingCity+'.html', map);
}
// analogous for Whats On section
function getListingsListWO() {
	GEvent.addListener(map, "click", function(overlay, point) {
		if (overlay){
			if( overlay.openInfoWindowHtml ) {
				overlay.openInfoWindowHtml(overlay.infowindow);
			}
		} else if (point) {}
	});
	wo = 1;

	getMarkers( '/ajax/whats_on_xml/'+chosenListingCategoryWO+'/'+chosenListingCityWO+'.html', map);
}

var markery;
var punkty;
function getMarkers(url) {
	if (GBrowserIsCompatible()) {
		map.clearOverlays();
		GDownloadUrl(url, function(data,responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("m");
			markery = new Array();
			punkty = new Array();
			var lajer = '';
			var counter = 0;
			for (var i = 0; i < markers.length; i++) {
				if( markers[i].getAttribute("la") != '0' && markers[i].getAttribute("ln") != '0' && markers[i].getAttribute("la") != '' && markers[i].getAttribute("ln") != '' ) {
					punkty[counter]  = new GLatLng(parseFloat(markers[i].getAttribute("la")),parseFloat(markers[i].getAttribute("ln")));
					markery[counter] = new GMarker(punkty[counter]);
					var nazwa = markers[i].getAttribute("n");
					var id = markers[i].getAttribute("i");
					var adres = markers[i].getAttribute("a");
					var url = markers[i].getAttribute("url");
					if(wo==1){
						markery[counter].infowindow = '<div id="chmurka"><h3><a href="/whats-on/event/'+url+'.html">'+nazwa+'</a></h3>'+nl2br(adres)+'</div>';
					}
					else{
						markery[counter].infowindow = '<div id="chmurka"><h3><a href="/listings/search.html?id='+id+'">'+nazwa+'</a></h3>'+nl2br(adres)+'</div>';
					}
					map.addOverlay(markery[counter]);
					lajer += '<li><a href="#" onclick="showOnlyThisListing('+counter+'); return false;" >'+nazwa+'</a></li>';
					if( chosenListingPlaceShowOnMap == id ) {
						var searchedPlace = counter;
					}
					counter++;
				}
			}
			var bounds = new GLatLngBounds;
			for (var i=0; i<punkty.length; i++) {
				bounds.extend(punkty[i]);
			}
			map.setZoom(map.getBoundsZoomLevel(bounds)-1);
			map.setCenter(bounds.getCenter());
			map.savePosition();
			if( chosenListingPlaceShowOnMap ) {
				showOnlyThisListing( searchedPlace );
				chosenListingPlaceShowOnMap = 0;
			} else {
				if( punkty.length > 0 ) {
					$("#place-listing-list").html(lajer);
					resizeMap("small");
				} else {
					resizeMap("big");
				}
				map.returnToSavedPosition();
			}
		});
	}
}


function showOnlyThisListing( elementToShow ) {
	if (GBrowserIsCompatible()) {
		//map.clearOverlays();
		map.setCenter(markery[elementToShow].getPoint());
		map.setZoom(16);
		map.addOverlay(markery[elementToShow]);
		markery[elementToShow].openInfoWindowHtml(markery[elementToShow].infowindow);
		//map.savePosition();
	}
}


function showMapSearchResults(type, style, detail, id) {
	loadAjaxPage('/ajax/show_map_search.html?type='+type+'&style='+style+'&detail='+detail+'&lid='+id, 'ajax-search_map');
}

function hideCat(cat) {
	loadAjaxPage('/ajax/hide_cat.html?cat='+cat, 'ajax-cat_'+cat);
}

var openedCategoryListing = 0;
function showMapCat(cat) {
	$("#category-listing-"+openedCategoryListing).css( "display", "none" );
	openedCategoryListing = cat;
	$("#category-listing-"+cat).css( "display", "block" );
}

function hideMapCat(cat) {
	loadAjaxPage('/ajax/hide_map_cat.html?cat='+cat, 'ajax-cat_'+cat);
}

function userRegister() {
	var email = document.getElementById('register-form_email').value;
	var pass = document.getElementById('register-form_pass').value;
	var pass_2 = document.getElementById('register-form_pass_2').value;
	//var recaptcha_response_field = $("input[@name='recaptcha_response_field']").val();
	//var recaptcha_challenge_field = $("input[@name='recaptcha_challenge_field']").val();
	if (email != '' && !isValidEmail(email)) {
		document.getElementById('register-form_email').value = 'error';
	}
	if (pass != '' && pass != pass_2) {
		document.getElementById('register-form_pass').value = 'error';
	}
	document.getElementById('form-register').submit();
}

function datingRegister() {
	var email = $("#register-form_email").val();
	var pass = $("#register-form_pass").val();
	var pass_2 = $("#register-form_pass_2").val();
	var recommend = $("#register-form_recommend").val();
	if (email != '' && !isValidEmail(email)) {
		$("#register-form_email").val('error');
	}
	if (pass != '' && pass != pass_2) {
		$("#register-form_pass").val('error');
	}
	if (recommend != '' && !isValidEmail(recommend)) {
		$("#register-form_recommend").val('error');
	}
	$("#form-register").submit();
}

function submitGuide() {
	var email = document.getElementById('guide-email').value;
	if (email != '' && !isValidEmail(email)) {
		document.getElementById('guide-email').value = 'error';
	}
	document.getElementById('form-survival').submit();
}

function userEditProfile() {

	var email = document.getElementById('register-form_email').value;
	var old_pass = document.getElementById('register-form_old_pass').value;
	var pass = document.getElementById('register-form_new_pass').value;
	var pass_2 = document.getElementById('register-form_new_pass_2').value;
	//var recaptcha_response_field = $("input[@name='recaptcha_response_field']").val();
	//var recaptcha_challenge_field = $("input[@name='recaptcha_challenge_field']").val();
	if (email != '' && !isValidEmail(email))
	{
		document.getElementById('register-form_email').value = 'error';
	}
	if (pass != pass_2)
	{
		document.getElementById('register-form_new_pass').value = 'error';
	}
	document.getElementById('form-edit_profile').submit();
}

function reSendNewEmail() {
	var email = document.getElementById('resend-form_email').value;
	if (email == '' || !isValidEmail(email))
	{
		alert('Bad email format!');
		return false;
	}
	document.getElementById('form_listing').submit();
}

function showResendForm() {
	$("#form-resend").css( "display", "block" );
}

function showConnectForm() {

	document.getElementById('connect-form').style.display = "block";
	document.getElementById('connect-textarea').focus();
}


function closeConnectForm() {

	document.getElementById('connect-form').style.display = "none";
}

function sendConnectForm(kogo, email) {
	var tresc = document.getElementById('connect-textarea').value;
	$.ajax({
		type: "POST",
		url: '/ajax/send_connect.html?kogo='+kogo+'&email='+email,
		data:  "tresc="+tresc,
		success: function(msg){
			closeConnectForm();
		}
	});
	return;
}

function googleSmallStart() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("google-api-map"));
		geocoder = new GClientGeocoder();
		if( inputedX != '0' && inputedY != '0' ) {
			checkInputedLocation();
		} else {
			showAddress(googleName,0);
		}
		GEvent.addListener(map,"click", function(overlay,latlng) {
			if( overlay ) {
				return;
			}
			map.clearOverlays();
			map.addOverlay(new GMarker(latlng));
			$("#signup-form_y").val(latlng.lng());
			$("#signup-form_x").val(latlng.lat());
		});
		map.enableContinuousZoom();
		//map.setMapType(G_HYBRID_TYPE); results in google api error
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		map.savePosition();
	}
}


function googleBigStart() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("google-api-map"));
		geocoder = new GClientGeocoder();
		showAddress(googleName,0);
		map.enableContinuousZoom();
		//map.setMapType(G_HYBRID_TYPE); results in google api error
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		map.savePosition();
	}
}



function showAddress(address,showIcon) {
	if (geocoder) {
		geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert(address + " not found");
			} else {
				map.setCenter(point, googleZoom);
				if( showIcon ) {
					map.clearOverlays();
					map.addOverlay(new GMarker(point));
					map.setCenter(point, 12);
					$("#signup-form_y").val(point.lng());
					$("#signup-form_x").val(point.lat());
				}
			}
		}
		);
	}
}



function doMultipleSearch() {
	var address = $("#signup-form_address").val();
	var postcode = $("#signup-form_postcode").val();
	var city = $("#signup-form_city option[@value='"+$("#signup-form_city").val()+"']").html();
	var country = $("#signup-form_country option[@value='"+$("#signup-form_country").val()+"']").html();
	if( address == '' ) {
		alert('Please fill your address.');
		return false;
	}
	var thestring = address;
	if( postcode != '' ) {
		thestring += ', '+postcode+' '+city;
	} else {
		if( city != '' ) {
			thestring += ', '+city;
		}
	}
	if( country != '' ) {
		thestring += ', '+country;
	}
	showAddress(thestring,1)
}



function checkInputedLocation() {
	var latlng = new GLatLng(inputedX, inputedY);
	map.setCenter(latlng, 13);
	map.clearOverlays();
	map.addOverlay(new GMarker(latlng));
	$("#signup-form_y").val(latlng.lng());
	$("#signup-form_x").val(latlng.lat());
}


var checkCatInterval = null;
function showChosenCategory( catID ) {
	if( !checkCatInterval ) {
		checkCatInterval = setInterval("showChosenCategory("+catID+");", 1000);
	}
	if( map ) {
		clearInterval( checkCatInterval );
		showMapResults( catID );
	}
}
// analogous for Whats On section
function showChosenCategoryWO( catID ) {
	if( !checkCatInterval ) {
		checkCatInterval = setInterval("showChosenCategoryWO("+catID+");", 1000);
	}
	if( map ) {
		clearInterval( checkCatInterval );
		showMapResultsWO( catID );
	}
}


var checkPlaceInterval = null;
function showChosenPlace( pID, catID ) {
	if( !checkPlaceInterval ) {
		checkPlaceInterval = setInterval("showChosenPlace("+pID+", "+catID+");", 1000);
	}
	if( map ) {
		clearInterval( checkPlaceInterval );
		chosenListingPlaceShowOnMap = pID;
		showMapResults( catID );
	}
}
// analogous for Whats On section
function showChosenPlaceWO( pID, catID ) {
	if( !checkPlaceInterval ) {
		checkPlaceInterval = setInterval("showChosenPlaceWO("+pID+", '"+catID+"');", 1000);
	}
	if( map ) {
		clearInterval( checkPlaceInterval );
		chosenListingPlaceShowOnMap = pID;
		showMapResultsWO( catID );
	}
}



var checkSearchInterval = null;
function showSearchResults( searchTag, searchCity, searchPhrase ) {
	if( !checkSearchInterval ) {
		checkSearchInterval = setInterval("showSearchResults('"+searchTag+"','"+searchCity+"','"+searchPhrase+"');", 1000);
	}
	if( map ) {
		clearInterval( checkSearchInterval );
		getMarkers( '/ajax/listings_xml_search/'+searchTag+'|---|'+searchCity+'|---|'+searchPhrase+'.html', map);
	}
}
// analogous for Whats On section
function showSearchResultsWO( searchTag, searchCity, searchPhrase ) {
	if( !checkSearchInterval ) {
		checkSearchInterval = setInterval("showSearchResultsWO('"+searchTag+"','"+searchCity+"','"+searchPhrase+"');", 1000);
	}
	if( map ) {
		clearInterval( checkSearchInterval );
		getMarkers( '/ajax/whats_on_xml_search/'+searchTag+'|---|'+searchCity+'|---|'+searchPhrase+'.html', map);
	}
}


function changeCityForMap( cityID ) {
	chosenListingCity = cityID;
	updateMenuStructure();
	if( chosenListingCategory ) {
		showMapResults(chosenListingCategory);
	}
}
// analogous for Whats On section
function changeCityForMapWO( cityID ) {
	chosenListingCityWO = cityID;
	if( chosenListingCategoryWO ) {
		showMapResultsWO(chosenListingCategoryWO);
	}
}


function updateMenuStructure() {
	loadAjaxPage('/ajax/map_menu/'+chosenListingCity+'.html', 'listing-update-list');
}

function nl2br( str ) {
	if(typeof(str)=="string") return str.replace(/\\n/g,"<BR>");
	else return str;
}


function updateContentLinks() {
	$('.newsroom_text a').click(function(){
		this.target = "_blank";
	});
}

function show_box_content (element_id_show, element_id_hide ) {
	document.getElementById(element_id_show).style.display = '';
	document.getElementById(element_id_hide).style.display = 'none';
}

function changePage(page) {
	//fix IE: getElementsByName don't collect divs
	//	var pages = document.getElementsByName('pager_pages');
	var pages = getElementsByName_iefix('div', 'pager_pages');

	var pages_links = document.getElementsByName('pager_links');
	for(i = 0; i < pages.length; i++ ) {
		pages[i].style.display = 'none';
		pages_links[i].style.color = '#226998';
	}

	document.getElementById('page_' + page).style.display = '';
	document.getElementById('pager_link_' + page).style.color = '#2f2f2f';
	var next_link = document.getElementById('pager_links_next');
	var prev_link = document.getElementById('pager_links_prev');
	var next_page = page + 1;
	var prev_page = page - 1;
	if (pages.length > next_page) {
		next_link.style.color = 'red';
		next_link.innerHTML = '<a href="#" onclick="changePage(' + next_page + '); return false">Next &gt;</a>';
	}else {
		next_link.innerHTML = '';
	}
	if (page == 0) {
		prev_link.innerHTML = '';
	}else {
		prev_link.innerHTML = '<a href="#" onclick="changePage(' + prev_page + '); return false">&lt; Prev</a>';
	}
	var scroll_to = document.getElementById('scroll_to').offsetTop
	window.scroll(0, scroll_to);

}

function getElementsByName_iefix(tag, name) {

	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if(att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}

var min_innerfontsize = 11;
var max_innerfontsize = 14;

function change_inner_font_size(change) {
	var current_size = document.getElementById('inner_text_content').style.fontSize.substring(0,2);
	size = change == 'enlarge' ? ++current_size : --current_size ;
	size = size > max_innerfontsize ? max_innerfontsize :  size < min_innerfontsize ? min_innerfontsize : size;
	document.getElementById('inner_text_content').style.fontSize= size + 'px';
	createCookie('innerfontsize', size, 1);

}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
          if (key==13) sendNotLoggedNewsletter();
     return (key != 13);
}