function hideValue(what, def)
{
	if(trim(what.value) == def)
	{
		what.value = "";
	}
	return;
}

function showValue(what, def)
{
	if(trim(what.value) == '')
	{
		what.value = def;
	}
	return;
}

// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value )
{
	return LTrim(RTrim(value));
	
}

function loadImages(path, pics)
{
	pics_arr = pics.split(',');
	for(i=0; i < pics_arr.length; i++)
	{
		eval('c' + i + ' = new Image();');
		eval('c' + i + '.src = path + "' + pics_arr[i] + '";');
	}
}

function changeBgck(what, img)
{
	document.getElementById(what).style.backgroundImage = "url('"+img+"')";
	//document.getElementById(what).style.backgroundPosition = 'middle';
}

function preloadImages(img_array)
{
	pics_array = img_array.split(',');
	for(i = 0; i < pics_array.length; i++)
	{
		eval("c"+i+" = new Image; c"+i+".src = pics_array[i];");
	}
}

var timer_id;
var direction=0;
var curr = 0;
function scroll_iframe(frm,inc,dir)
{
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm])
  {
    if (direction == 0)
    {
    	curr += inc;
    	window.frames[frm].scrollBy(0, inc);
    	if(curr >= window.frames[frm].document.body.offsetHeight)
    	{
    		direction = 1;
    		curr = window.frames[frm].document.body.offsetHeight;
    	}
    }
    else if (direction == 1)
    {
    	curr -= inc;
    	window.frames[frm].scrollBy(0, -inc);
    	if(curr <= 0)
    	{
    		direction = 0;
    		curr = 0;
    	}
    }
    //else window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 5);
  }
}

function stopScroll()
{
	if (timer_id) clearTimeout(timer_id);
}

function change_class(tid, cfg)
{
	if(cfg == 1) newclass = 'admin_button';
	else if(cfg == 2) newclass = 'admin_button_over';
	
	//var dtarget = document.getElementById(tid);
	
	tid.className = newclass;
}

Array.prototype.in_array = function ( obj )
{
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ )
	{
		if ( this[x] == obj ) return x;
	}
	return false;
}

function checkForm(formname, fields_array, errors_array)
{
	eval("var reg = document." + formname + ";");
	
	for(var i = 0; i < fields_array.length; i++)
	{
		eval("var curr_field = reg." + fields_array[i] + ";");
		if(trim(curr_field.value) == '')
		{
			alert(errors_array[i]);
			curr_field.focus();
			return false;
		}
	}
	reg.submit();
}

var upl_pics = 1;
function setNewPicField(formname, curr)
{
	if(curr == upl_pics)
	{
		upl_pics++;
		
		var targetTD = document.getElementById('pics_td');
		
		var add = document.createElement('div');
		add.setAttribute('style', 'float:left;');
		add.style.cssFloat = 'left';
		add.style.float = 'left';
		add.style.whiteSpace = 'nowrap';
		add.style.padding = '10px';
		add.style.border = '#000000 1px solid';
		add.style.margin = '5px 5px 5px 0px';
		add.style.width = 270 + 'px';
		addHTML = '<b>Снимка '+upl_pics+':</b><br/>';
		addHTML += '<input type="file" name="pic'+upl_pics+'" class="t1" onchange="setNewPicField(\'' + formname + '\', '+upl_pics+');"/><br/>';
		addHTML += '<b>Заглавие на снимка '+upl_pics+':</b><br/><input type="text" class="t1" name="pic_title'+upl_pics+'"/><br/>';
		addHTML += '<b>Текст на снимка '+upl_pics+':</b><br/><textarea cols="0" rows="0" class="t3" name="pic_text'+upl_pics+'"></textarea>';
		add.innerHTML = addHTML;
		
		targetTD.appendChild(add);
		
		eval("document." + formname + ".upl_pics.value = upl_pics;");
	}
}

function setSuggestionNewPicField(formname, curr)
{
	if(curr == upl_pics)
	{
		upl_pics++;
		
		var targetTD = document.getElementById('pics_td');
		
		var add = document.createElement('div');
		add.style.position = 'static';
		add.style.cssFloat = 'left';
		add.style.styleFloat = 'left';
		add.style.padding = '10px';
		add.style.border = '#cacaca 1px solid';
		add.style.margin = '5px 5px 5px 0px';
		add.style.width = 220 + 'px';
		addHTML = '<b>Снимка '+upl_pics+':</b><br/>';
		addHTML += '<input type="file" name="pic'+upl_pics+'" class="t1" onchange="setSuggestionNewPicField(\'' + formname + '\', '+upl_pics+');"/>';
		add.innerHTML = addHTML;
		
		targetTD.appendChild(add);
		
		eval("document." + formname + ".upl_pics.value = upl_pics;");
	}
}

function getCountries(formname, country_id_field, continent_id, location_id_field, exeption)
{
	var pars = 'doit=1&continent_id=' + continent_id;
	if(exeption == 2) pars += '&offers=1';
	if(exeption == 3) pars += '&recipes=1';
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_countries.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + country_id_field + ";");
			sel.options.length = 0;
			
			if(exeption == 2 || exeption == 3) sel.options[0] = new Option('Всички', '');
			else sel.options[0] = new Option('-- избери --', '');
			
			for(var i = 0; i < result.length; i++)
			{
				if(result[i] && trim(result[i]) != '')
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
			
			getLocations(formname, location_id_field, country_id_field, ' ', exeption);
		}
	});
}

function getLocations(formname, location_id_field, country_id_field, type_id, exeption)
{
	eval("var country_id = document." + formname+ "." + country_id_field + ".value;");
	var pars = 'doit=1&country_id=' + country_id + '&type_id=' + type_id;
	if(exeption == 2) pars += '&offers=1';
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_locations.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + location_id_field + ";");
			sel.options.length = 0;
			
			if(exeption == 2) sel.options[0] = new Option('Всички', '');
			else sel.options[0] = new Option('-- избери --', '');
			
			var start = 0;
			
			for(var i = start; i < result.length; i++)
			{
				if(result[i] && trim(result[i]) != '')
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
			
			if(exeption == 1)
			{
				sel.options[(i + 1)] = new Option('Друго', '0');
			}
		}
	});
}

function getCountriesWeather(formname, country_id_field, continent_id_field, location_id_field, exeption)
{
	
	var continent_id = document.getElementById(continent_id_field).value;
	
	var pars = 'doit=1&continent_id=' + continent_id;
	if(exeption == 2) pars += '&offers=1';
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_countries_weather.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + country_id_field + ";");
			sel.options.length = 0;
			
			if(exeption == 2) sel.options[0] = new Option('Всички', '');
			else sel.options[0] = new Option('-- избери --', '');
			
			if(transport.responseText != '')  {
				for(var i = 0; i < result.length; i++)
				{
					if(result[i] && trim(result[i]) != '')
					{
						var new_res_array = result[i].split(',');
						
						sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
					}
				}
			}
			getLocationsWeather(formname, location_id_field, country_id_field, ' ', exeption);
		}
	});
}


function getLocationsWeather(formname, location_id_field, country_id_field, type_id, exeption)
{
	eval("var country_id = document." + formname+ "." + country_id_field + ".value;");
	var pars = 'doit=1&country_id=' + country_id + '&type_id=' + type_id;
	if(exeption == 2) pars += '&offers=1';
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_locations_weather.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + location_id_field + ";");
			sel.options.length = 0;
			
			if(exeption == 2) sel.options[0] = new Option('Всички', '');
			else sel.options[0] = new Option('-- избери --', '');
			
			var start = 0;
			
			if(transport.responseText != '') {
				for(var i = start; i < result.length; i++)
				{
					if(result[i] && trim(result[i]) != '')
					{
						var new_res_array = result[i].split(',');
						
						sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
					}
				}
				
				if(exeption == 1)
				{
					sel.options[(i + 1)] = new Option('Друго', '0');
				}
			}
		}
	});
}

function customLocation(formname, what)
{
	eval("var reg = document." + formname + ";");
	
	if(parseInt(trim(what.value)) == 0)
	{
		document.getElementById('custom_location_div').style.display = 'block';
		reg.custom_location.focus();
	}
	else
	{
		document.getElementById('custom_location_div').style.display = 'none';
	}
}

function epTab(tarray, tid)
{
	for(var i = 1; i <= tarray; i++)
	{
		if(document.getElementById('tab' + i + '_mid'))
		{
			if(i == tid)
			{
				document.getElementById('tab' + i + '_left').className = 'selected_left';
				document.getElementById('tab' + i + '_mid').className = 'selected';
				document.getElementById('tab' + i + '_right').className = 'selected_right';
				
				if(document.getElementById('edit_div' + i))
				{
					document.getElementById('edit_div' + i).style.display = '';
				}
				else if(document.getElementById('bulgaria_div' + i))
				{
					document.getElementById('bulgaria_div' + i).style.display = '';
				}
			}
			else
			{
				document.getElementById('tab' + i + '_left').className = 'left';
				document.getElementById('tab' + i + '_mid').className = '';
				document.getElementById('tab' + i + '_right').className = 'right';
				
				if(document.getElementById('edit_div' + i))
				{
					document.getElementById('edit_div' + i).style.display = 'none';
				}
				else if(document.getElementById('bulgaria_div' + i))
				{
					document.getElementById('bulgaria_div' + i).style.display = 'none';
				}
			}
		}
	}
}

function epFiltersTab(tarray, tid)
{
	for(var i = 1; i <= tarray; i++)
	{
		if(document.getElementById('tab' + i + '_mid'))
		{
			if(i == tid)
			{
				document.getElementById('tab' + i + '_left').className = 'left';
				document.getElementById('tab' + i + '_mid').className = '';
				document.getElementById('tab' + i + '_right').className = 'right';
				
				if(document.getElementById('edit_div' + i))
				{
					document.getElementById('edit_div' + i).style.display = '';
				}
				else if(document.getElementById('bulgaria_div' + i))
				{
					document.getElementById('bulgaria_div' + i).style.display = '';
				}
			}
			else
			{
				document.getElementById('tab' + i + '_left').className = 'selected_left';
				document.getElementById('tab' + i + '_mid').className = 'selected';
				document.getElementById('tab' + i + '_right').className = 'selected_right';
				
				if(document.getElementById('edit_div' + i))
				{
					document.getElementById('edit_div' + i).style.display = 'none';
				}
				else if(document.getElementById('bulgaria_div' + i))
				{
					document.getElementById('bulgaria_div' + i).style.display = 'none';
				}
			}
		}
	}
}

var continents_count = 0;
function getContinentCountries(num, continent_id, rewrite)
{
	for(var i = 1; i <= continents_count; i++)
	{
		if(i == num)
		{
			document.getElementById('contlist_tab_' + i).className = 'selected';
			
			var pars = 'doit=1&continent_id=' + continent_id + '&rewrite=' + rewrite;
			
			new Ajax.Updater('countries_container', 'http://www.myplanet.bg/ajax/get_countries_list.php', {method: 'post', postBody: pars, evalScripts: true});
		}
		else document.getElementById('contlist_tab_' + i).className = '';
	}
}

function digitCheck(what)
{
	var chk = /[^0-9\.]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Непозволен символ! Разрешени са само цифри и . (използва се за десетична запетая)!" );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function numberCheck(what)
{
	var chk = /[^0-9]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Непозволен символ! Разрешени са само цифри!" );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

var ismoving = 0;

function setMargin(tel, margin)
{
	tel.style.marginLeft = margin + 'px';
}

function moveRight(pc)
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 448;
	var cmp = 75;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) <= 0 && ExtractNumber(tel.style.marginLeft) > -((parseInt(pc) - Math.ceil(parseInt(cm) / parseInt(cmp)))) * parseInt(cmp)) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i >= ExtractNumber(tel.style.marginLeft) - parseInt(cmp); i--)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function moveLeft()
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 448;
	var cmp = 75;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) < 0) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i <= ExtractNumber(tel.style.marginLeft) + parseInt(cmp); i++)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function moveContinentsRight(pc)
{
	var tel = document.getElementById('contlist');
	var cw = tel.style.width;
	var cm = 598;
	var cmp = 149;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) <= 0 && ExtractNumber(tel.style.marginLeft) > -((parseInt(pc) - Math.ceil(parseInt(cm) / parseInt(cmp)))) * parseInt(cmp)) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i >= ExtractNumber(tel.style.marginLeft) - parseInt(cmp); i--)
		{
			if(i > -430) {
				setTimeout("setMargin(document.getElementById('contlist'), " + i + ")", (timer * speed));
				timer++;
				ismoving = 1;
			}
						
		}
		ismoving = 0;
	}
}

function moveContinentsLeft()
{
	var tel = document.getElementById('contlist');
	var cw = tel.style.width;
	var cm = 598;
	var cmp = 149;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) < 0) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i <= ExtractNumber(tel.style.marginLeft) + parseInt(cmp); i++)
		{
			if(i < 0 ) {
				setTimeout("setMargin(document.getElementById('contlist'), " + i + ")", (timer * speed));
				timer++;
				ismoving = 1;
			}
					}
		ismoving = 0;
	}

}

function setHiddenArrivals(atype, continent_id, country_id, location_id, country_name)
{
	var trg = document.getElementById('hidden_arrivals');
	var arvls = document.getElementById('arrivals');
	var arvls_count = parseInt(arvls.value);
	
	if(location_id.checked)
	{
		if(!document.getElementById(continent_id + '_' + country_id))
		{
			arvls_count++;
			arvls.value = arvls_count;
			
			var ndc = document.createElement('input');
			ndc.id = continent_id + '_' + country_id;
			ndc.name = 'arvls_' + arvls_count;
			ndc.type = 'hidden';
			
			if(atype == 1) ndc.value = continent_id + ',' + country_id + ',' + location_id.value;
			else if(atype == 2)
			{
				ndc.value = continent_id + ',' + country_id;
				
				var cf_innerhtml = document.createElement('div');
				cf_innerhtml.id = country_name;
				cf_innerhtml.className = 'div_def';
				cf_innerhtml.style.width = 150 + 'px';
				cf_innerhtml.style.paddingRight = 10 + 'px';
				cf_innerhtml.innerHTML = '<a href="javascript:getCountriesAirlines(\'2\', \'countries_list\', \'' + continent_id + '\');" title="премахни">' + country_name + '</a>';
				
				document.getElementById('destinations_add').appendChild(cf_innerhtml);
			}
			
			trg.appendChild(ndc);
		}
		else
		{
			if(atype == 1)
			{
				document.getElementById(continent_id + '_' + country_id).value += ',' + location_id.value;
			}
		}
	}
	else
	{
		if(atype == 1)
		{
			document.getElementById(continent_id + '_' + country_id).value = document.getElementById(continent_id + '_' + country_id).value.replace(',' + location_id.value, '');
		}
		else if(atype == 2)
		{
			document.getElementById(continent_id + '_' + country_id).value = document.getElementById(continent_id + '_' + country_id).value.replace(',' + country_id, '');
		
			document.getElementById('destinations_add').removeChild(document.getElementById(country_name));
		}
		
		var aarr = document.getElementById(continent_id + '_' + country_id).value.split(',');
		
		if((atype == 1 && aarr.length == 2) || (atype == 2 && aarr.length == 1))
		{
			var tname = document.getElementById(continent_id + '_' + country_id).name;
			var tname_num = parseInt(tname.replace('arvls_',''));
			
			trg.removeChild(document.getElementById(continent_id + '_' + country_id));
			
			if(tname_num == arvls_count)
			{
				arvls_count--;
				arvls.value = arvls_count;
			}
		}
	}
}

function getCountriesAirlines(atype, countries_field, continent_id)
{
	var pars = 'doit=1&continent_id=' + continent_id;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_countries.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			document.getElementById(countries_field).innerHTML = '';
			
			if(transport.responseText != '')
			{
				var arvls = document.getElementById('arrivals');
				var arvls_count = parseInt(arvls.value);
				
				var result = transport.responseText.split('|');
				
				for(var i = 0; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					var cfchk = 0;
					if(document.getElementById(continent_id + '_' + new_res_array[0])) cfchk = 1;
					
					var cf_innerhtml = document.createElement('div');
					cf_innerhtml.className = 'div_def';
					cf_innerhtml.style.width = 150 + 'px';
					cf_innerhtml.style.paddingRight = 10 + 'px';
					cf_innerhtml.innerHTML = '<input type="checkbox" class="checkbox" value="" ' + (cfchk == 1 ? 'checked="checked"' : '') + ' name="location_id[]" onclick="setHiddenArrivals(\'' + atype + '\', \'' + continent_id + '\',\'' + new_res_array[0] + '\',this,\'' + new_res_array[1] + '\')"/> ' + new_res_array[1];
					
					document.getElementById(countries_field).appendChild(cf_innerhtml);
				}
			}
		}
	});
}

var arvls_array_help = Array();
function setHiddenArrivalsOffers(continent_id, country_id, location_id, country_name, location_name)
{
	var trg = document.getElementById('hidden_arrivals');
	var arvls = document.getElementById('arrivals');
	var arvls_count = parseInt(arvls.value);
	
	if(document.getElementById('location_chbx_' + location_id) && document.getElementById('location_chbx_' + location_id).checked)
	{
		if(!document.getElementById(continent_id + '_' + country_id + '_' + location_id))
		{
			arvls_count++;
			arvls.value = arvls_count;
			
			arvls_array_help[arvls_count] = continent_id + ',' + country_id + ',' + location_id + ',' + location_name;
			
			var ndc = document.createElement('input');
			ndc.id = continent_id + '_' + country_id + '_' + location_id;
			ndc.name = 'arvls_' + arvls_count;
			ndc.type = 'hidden';
			ndc.value = continent_id + ',' + country_id + ',' + location_id;
			
			var cf_innerhtml = document.createElement('div');
			cf_innerhtml.id = location_name + '_' + location_id;
			cf_innerhtml.className = 'div_def';
			cf_innerhtml.innerHTML = '<a href="javascript:removeLocationsOffers(\'' + continent_id + '\',\'' + country_id + '\',\'' + location_id + '\',\'' + location_name + '\',\'0\');" title="премахни">' + location_name + '</a>';
			
			if(!document.getElementById(country_id + '_sc'))
			{
				var cfmain_innerhtml = document.createElement('div');
				cfmain_innerhtml.id = country_id + '_sc';
				cfmain_innerhtml.className = 'div_def full dpt5';
				cfmain_innerhtml.innerHTML = '<div class="div_def" style="padding-right:5px;">' + country_name + ' -</div>';
				
				cfmain_innerhtml.appendChild(cf_innerhtml);
				
				document.getElementById('destinations_add').appendChild(cfmain_innerhtml);
			}
			else
			{
				for(var c = 1; c <= arvls_count; c++)
				{
					var arvls_el = arvls_array_help[c];
					
					if(arvls_el)
					{
						var arvls_split = arvls_el.split(',');
						if(arvls_split[1] == country_id)
						{
							cf_innerhtml.innerHTML = cf_innerhtml.innerHTML + ', ';
							break;
						}
					}
				}
				
				cfmain_innerhtml = document.getElementById(country_id + '_sc');
				cfmain_innerhtml.appendChild(cf_innerhtml);
			}
			
			trg.appendChild(ndc);
		}
	}
	else
	{
		if(document.getElementById(continent_id + '_' + country_id + '_' + location_id))
		{
			document.getElementById(continent_id + '_' + country_id + '_' + location_id).value = document.getElementById(continent_id + '_' + country_id + '_' + location_id).value.replace(',' + location_id, '');
			
			if(document.getElementById(location_name + '_' + location_id))
			{
				document.getElementById(country_id + '_sc').removeChild(document.getElementById(location_name + '_' + location_id));
			}
			
			var aarr = document.getElementById(continent_id + '_' + country_id + '_' + location_id).value.split(',');
			
			if(aarr.length == 2)
			{
				var tname = document.getElementById(continent_id + '_' + country_id + '_' + location_id).name;
				var tname_num = parseInt(tname.replace('arvls_',''));
				
				trg.removeChild(document.getElementById(continent_id + '_' + country_id + '_' + location_id));
				
				if(tname_num == arvls_count)
				{
					arvls_array_help.splice(arvls_count, 1);
					arvls_count--;
					arvls.value = arvls_count;
				}
			}
		}
	}
}

function getCountriesOffers(countries_field, continent_id, continent_name)
{
	if(document.getElementById('continent_chbx_' + continent_id))
	{
		if(document.getElementById('continent_chbx_' + continent_id).checked)
		{
			var pars = 'doit=1&continent_id=' + continent_id;
			
			new Ajax.Request('http://www.myplanet.bg/ajax/get_countries.php', {method: 'post', postBody:pars, onSuccess: function(transport)
				{
					if(transport.responseText != '')
					{
						var arvls = document.getElementById('arrivals');
						var arvls_count = parseInt(arvls.value);
						
						var result = transport.responseText.split('|');
						
						var cfcontinent_main_innerhtml = document.createElement('div');
						cfcontinent_main_innerhtml.id = 'continent_' + continent_id + '_countries_list';
						cfcontinent_main_innerhtml.className = 'div_def dpt5 dpb5 dpl5';
						cfcontinent_main_innerhtml.style.border = '#cacaca 1px solid';
						cfcontinent_main_innerhtml.style.width = 450 + 'px';
						
						var cfcontinent_innerhtml = document.createElement('div');
						cfcontinent_innerhtml.className = 'div_def';
						cfcontinent_innerhtml.style.width = 140 + 'px';
						cfcontinent_innerhtml.style.paddingRight = 10 + 'px';
						cfcontinent_innerhtml.innerHTML = continent_name + ':';
						cfcontinent_main_innerhtml.appendChild(cfcontinent_innerhtml);
						
						for(var i = 0; i < result.length; i++)
						{
							var new_res_array = result[i].split(',');
							
							var cfchk = 0;
							if(document.getElementById(continent_id + '_' + new_res_array[0])) cfchk = 1;
							
							var cf_innerhtml = document.createElement('div');
							cf_innerhtml.className = 'div_def';
							cf_innerhtml.style.width = 140 + 'px';
							cf_innerhtml.style.paddingRight = 10 + 'px';
							cf_innerhtml.innerHTML = '<input type="checkbox" class="checkbox" id="country_chbx_' + new_res_array[0] + '" value="" ' + (cfchk == 1 ? 'checked="checked"' : '') + ' name="country_id[]" onclick="getLocationsOffers(\'\locations_list\',\'' + continent_id + '\',\'' + new_res_array[0] + '\',\'' + new_res_array[1] + '\',0)"/> ' + new_res_array[1];
							
							cfcontinent_main_innerhtml.appendChild(cf_innerhtml);
						}
						
						document.getElementById(countries_field).appendChild(cfcontinent_main_innerhtml);
					}
				}
			});
		}
		else
		{
			var pars = 'doit=1&continent_id=' + continent_id;
			
			new Ajax.Request('http://www.myplanet.bg/ajax/get_countries.php', {method: 'post', postBody:pars, onSuccess: function(transport)
				{
					if(transport.responseText != '')
					{
						var result = transport.responseText.split('|');
						
						for(var i = 0; i < result.length; i++)
						{
							var new_res_array = result[i].split(',');
							
							if(document.getElementById('country_chbx_' + new_res_array[0]))
							{
								document.getElementById('country_chbx_' + new_res_array[0]).checked = false;
							}
							
							setTimeout("getLocationsOffers('locations_list', " + continent_id + ", " + new_res_array[0] + ", '" + new_res_array[1] + "', 1)", 150);
						}
					}
				}
			});
			
			document.getElementById(countries_field).removeChild(document.getElementById('continent_' + continent_id + '_countries_list'));
		}
	}
}

function getLocationsOffers(locations_field, continent_id, country_id, country_name, remove)
{
	if(document.getElementById('country_chbx_' + country_id) || remove == 1)
	{
		if(document.getElementById('country_chbx_' + country_id) && document.getElementById('country_chbx_' + country_id).checked)
		{
			var pars = 'doit=1&country_id=' + country_id + '&type_id= ';
			
			new Ajax.Request('http://www.myplanet.bg/ajax/get_locations.php', {method: 'post', postBody:pars, onSuccess: function(transport)
				{
					if(transport.responseText != '')
					{
						var arvls = document.getElementById('arrivals');
						var arvls_count = parseInt(arvls.value);
						
						var result_l = transport.responseText.split('|');
						
						var cfcountry_main_innerhtml = document.createElement('div');
						cfcountry_main_innerhtml.id = 'country_' + country_id + '_locations_list';
						cfcountry_main_innerhtml.className = 'div_def dpt5 dpb5 dpl5';
						cfcountry_main_innerhtml.style.border = '#cacaca 1px solid';
						cfcountry_main_innerhtml.style.width = 450 + 'px';
						
						var cfcountry_innerhtml = document.createElement('div');
						cfcountry_innerhtml.className = 'div_def';
						cfcountry_innerhtml.style.width = 140 + 'px';
						cfcountry_innerhtml.style.paddingRight = 10 + 'px';
						cfcountry_innerhtml.innerHTML = country_name + ':';
						cfcountry_main_innerhtml.appendChild(cfcountry_innerhtml);
						
						for(var a = 0; a < result_l.length; a++)
						{
							var new_res_array = result_l[a].split(',');
							
							var cfchk = 0;
							if(document.getElementById(country_id + '_' + new_res_array[0])) cfchk = 1;
							
							var cf_innerhtml = document.createElement('div');
							cf_innerhtml.className = 'div_def';
							cf_innerhtml.style.width = 140 + 'px';
							cf_innerhtml.style.paddingRight = 10 + 'px';
							cf_innerhtml.innerHTML = '<input type="checkbox" class="checkbox" id="location_chbx_' + new_res_array[0] + '" value="" ' + (cfchk == 1 ? 'checked="checked"' : '') + ' name="location_id[]" onclick="setHiddenArrivalsOffers(\'' + continent_id + '\',\'' + country_id + '\',\'' + new_res_array[0] + '\',\'' + country_name + '\',\'' + new_res_array[1] + '\');"/> ' + new_res_array[1];
							
							cfcountry_main_innerhtml.appendChild(cf_innerhtml);
						}
						
						document.getElementById(locations_field).appendChild(cfcountry_main_innerhtml);
						
						if(!document.getElementById(country_id + '_sc'))
						{
							var cfmain_innerhtml = document.createElement('div');
							cfmain_innerhtml.id = country_id + '_sc';
							cfmain_innerhtml.className = 'div_def full dpt5';
							cfmain_innerhtml.innerHTML = '<div class="div_def" style="padding-right:5px;">' + country_name + ' -</div>';
							
							document.getElementById('destinations_add').appendChild(cfmain_innerhtml);
						}
					}
				}
			});
		}
		else
		{
			var pars = 'doit=1&country_id=' + country_id + '&type_id= ';
			
			new Ajax.Request('http://www.myplanet.bg/ajax/get_locations.php', {method: 'post', postBody:pars, onSuccess: function(transport)
				{
					if(transport.responseText != '')
					{
						var result_l = transport.responseText.split('|');
						
						for(var a = 0; a < result_l.length; a++)
						{
							var new_res_array_l = result_l[a].split(',');
							
							setTimeout("removeLocationsOffers(" + continent_id + ", " + country_id + ", " + new_res_array_l[0] + ", '" + new_res_array_l[1] + "', 1)", 150);
						}
					}
				}
			});
			
			if(document.getElementById('country_' + country_id + '_locations_list'))
			{
				document.getElementById(locations_field).removeChild(document.getElementById('country_' + country_id + '_locations_list'));
			}
			
			if(document.getElementById(country_id + '_sc'))
			{
				document.getElementById('destinations_add').removeChild(document.getElementById(country_id + '_sc'));
			}
		}
	}
}

function removeLocationsOffers(continent_id, country_id, location_id, location_name, remove)
{
	if(document.getElementById('location_chbx_' + location_id) || remove == 1)
	{
		if(document.getElementById('location_chbx_' + location_id))
		{
			document.getElementById('location_chbx_' + location_id).checked = false;
		}
		
		setHiddenArrivalsOffers(continent_id, country_id, location_id, '', location_name);
	}
}

var ismoving = 0;

function moveGalleryRight(pc)
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 448;
	var cmp = 75;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) <= 0 && ExtractNumber(tel.style.marginLeft) > -((parseInt(pc) - Math.ceil(parseInt(cm) / parseInt(cmp)))) * parseInt(cmp)) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i >= ExtractNumber(tel.style.marginLeft) - parseInt(cmp); i--)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function moveGalleryLeft()
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 448;
	var cmp = 75;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) < 0) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i <= ExtractNumber(tel.style.marginLeft) + parseInt(cmp); i++)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function setBigImage(bimage, imgname)
{
	var wtime = 450; //millisec
	var it_div = document.getElementById('fullimg');
	var it = document.getElementById('bimage');
	
	//speed for each frame 
	var speed = Math.round(wtime / 100); 
	var timer = 0;
	
	for(i = 100; i >= 0; i--)
	{ 
      setTimeout("changeOpac(" + i + ",'fullimg'," + 100 + ", document.getElementById('bimage') , '" + bimage + "', '" + imgname + "', " + wtime + ")",(timer * speed)); 
      timer++;
  }
}

function moveGrandGalleryRight(pc)
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 584;
	var cmp = 73;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) <= 0 && ExtractNumber(tel.style.marginLeft) > -((parseInt(pc) - Math.ceil(parseInt(cm) / parseInt(cmp)))) * parseInt(cmp)) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i >= ExtractNumber(tel.style.marginLeft) - parseInt(cmp); i--)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function moveGrandGalleryLeft()
{
	var tel = document.getElementById('gallery_items');
	var cw = tel.style.width;
	var cm = 584;
	var cmp = 73;
	
	//speed for each frame 
	var speed = Math.round(300 / 100); 
	var timer = 0;
	
	if(ExtractNumber(tel.style.marginLeft) < 0) // && ismoving == 0
	{
		for(i = ExtractNumber(tel.style.marginLeft); i <= ExtractNumber(tel.style.marginLeft) + parseInt(cmp); i++)
		{
			setTimeout("setMargin(document.getElementById('gallery_items'), " + i + ")", (timer * speed));
			timer++;
			ismoving = 1;
		}
		ismoving = 0;
	}
}

function setGrandBigImage(bimage, imgname)
{
	var wtime = 450; //millisec
	var it_div = document.getElementById('fullimg');
	var it = document.getElementById('bimage');
	
	//speed for each frame 
	var speed = Math.round(wtime / 100); 
	var timer = 0;
	
	for(i = 100; i >= 0; i--)
	{ 
      setTimeout("changeOpac(" + i + ",'fullimg'," + 100 + ", document.getElementById('bimage') , '" + bimage + "', '" + imgname + "', " + wtime + ")",(timer * speed)); 
      timer++;
  }
}

function opacity(id, opacStart, opacEnd, millisec)
{ 
	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0;
	
	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
	    for(i = opacStart; i >= opacEnd; i--) { 
	        setTimeout("changeOpac(" + i + ",'" + id + "'," + opacEnd + ")",(timer * speed)); 
	        timer++;
	    }
	} else if(opacStart < opacEnd) { 
	    for(i = opacStart; i <= opacEnd; i++) 
	        { 
	        setTimeout("changeOpac(" + i + ",'" + id + "'," + opacEnd + ")",(timer * speed)); 
	        timer++; 
	    }
	}
} 

//change the opacity for different browsers 
function changeOpac(opacity, id, opacEnd, it, bimage, imgname, wtime)
{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if(opacity == 15 && it != '')
	{
		it.src = bimage;
		if(document.getElementById('bimage_link'))
		{
			document.getElementById('bimage_link').href = 'javascript:showBigGallery(\'http://www.myplanet.bg/thumb_asp.php?p=600-'+imgname+'-1\',\''+it.alt+'\');';
		}
		
		if(it.complete)
		{
			it.onload = function()
			{
				//speed for each frame 
				var speed = Math.round(wtime / 100); 
				var timer = 0;
			  
			  for(i = 0; i <= 100; i++) 
			  { 
			      setTimeout("changeOpac(" + i + ",'fullimg'," + 0 + ", '', '', '', '')",(timer * speed)); 
			      timer++; 
			  }
			};
		}
	}
	
	//if(opacity == 0 && opacEnd == 0 && object) document.body.removeChild(document.getElementById(id));
}

function shiftOpacity(id, millisec)
{ 
	//if an element is invisible, make it visible, else make it ivisible 
	if(document.getElementById(id).style.opacity == 0)
	{ 
		opacity(id, 0, 100, millisec); 
	}
	else
	{ 
		opacity(id, 100, 0, millisec); 
	}
}

function ExtractNumber(value)
{
	var n = parseInt(value);
	return n == null || isNaN(n) ? 0 : n;
}

function closePic()
{
	if(document.getElementById('showPreview')) 
	{
		document.body.removeChild(document.getElementById('showPreview'));
		document.body.removeChild(document.getElementById('showPreviewPic'));
		
		//enable scroll
		//var elementBody = document.getElementsByTagName('html');
		//elementBody[0].style.overflow = '';
		//elementBody[0].onselectstart = function() {return true;};
	}
}

function showBigGallery(img, txt)
{
	//opera fix
	var agt = navigator.userAgent.toLowerCase();
  var is_opera = (agt.indexOf("opera") != -1);
	//if(is_opera) txt = url.decode(txt);
	
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showPreview';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	//dl.style.height = parseInt(document.getElementById('allover').offsetHeight) + 40 + 'px';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	//dl.style.top = scrollHeight+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//pic div
	pl = document.createElement('div');
	pl.id = 'showPreviewPic';
	pl.style.cssText = 'float:left;';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-250+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-305px';
	pl.style.padding = '10px 5px 10px 14px';
	pl.style.width = '610px';
	//pl.style.height = '645px';
	pl.style.textAlign = 'center';
	pl.style.zIndex = 1001;
	pl.style.backgroundImage = 'url(\'http://www.myplanet.bg/images/default/spinner.gif\')';
	pl.style.backgroundPosition = 'center';
	pl.style.backgroundRepeat = 'no-repeat';
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showPreviewPicClose';
	cl.style.cssText = 'float:left;';
	cl.style.width = '610px';
	//cl.style.border = 'red 1px solid';
	cl.style.backgroundColor = '#FFFFFF';
	cl.style.textAlign = 'left';
	cl.style.padding = '10px 0px 10px 0px';
	cl_in = '<div style="float:left;width:500px;color:#2f5b77;font-size:12px;">' + base64_decode(txt) + '</div>';
	cl_in += '<div style="float:right;width:90px;text-align:left;"><a href="javascript:closePic();" style="text-decoration:none;color:#666666;white-spacing:nowrap;">Затвори <img src="http://www.myplanet.bg/images/default/close.gif" alt="Затвори" style="vertical-align:middle;border:0px;"/></a></div>';
	cl.innerHTML = cl_in;
	
	//pic
	pic_div = document.createElement('div');
	pic_div.style.cssText = 'float:left;';
	pic_div.style.width = '600px';
	//pic_div.style.height = '600px';
	
	pic = document.createElement('img');
	pic.id = 'imagePreview';
	pic.src = img;
	pic.setAttribute('alt', '');
	pic.setAttribute('border', '0');
	
	pic_div.appendChild(pic);
	pl.appendChild(pic_div);
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	//disable scroll
	//var elementBody = document.getElementsByTagName('html');
	//elementBody[0].style.overflow = 'hidden';
	//elementBody[0].onselectstart = function() {return false;};
}

function showBigGalleryCompetitions(img, title, txt)
{
	//opera fix
	var agt = navigator.userAgent.toLowerCase();
  var is_opera = (agt.indexOf("opera") != -1);
	//if(is_opera) txt = url.decode(txt);
	
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showPreview';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	//dl.style.height = parseInt(document.getElementById('allover').offsetHeight) + 40 + 'px';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	//dl.style.top = scrollHeight+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//pic div
	pl = document.createElement('div');
	pl.id = 'showPreviewPic';
	pl.style.cssText = 'float:left;';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-250+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-305px';
	pl.style.padding = '10px 5px 10px 14px';
	pl.style.width = '610px';
	//pl.style.height = '645px';
	pl.style.textAlign = 'center';
	pl.style.zIndex = 1001;
	pl.style.backgroundImage = 'url(\'http://www.myplanet.bg/images/default/spinner.gif\')';
	pl.style.backgroundPosition = 'center';
	pl.style.backgroundRepeat = 'no-repeat';
	
	//title div
	ct = document.createElement('div');
	ct.style.cssText = 'float:left;';
	ct.style.width = '610px';
	//cl.style.border = 'red 1px solid';
	ct.style.backgroundColor = '#FFFFFF';
	ct.style.textAlign = 'left';
	ct.style.padding = '10px 0px 10px 0px';
	ct_in = '<div style="float:left;width:610px;color:#2f5b77;font-size:12px;">' + base64_decode(title) + '</div>';
	ct.innerHTML = ct_in;
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showPreviewPicClose';
	cl.style.cssText = 'float:left;';
	cl.style.width = '610px';
	//cl.style.border = 'red 1px solid';
	cl.style.backgroundColor = '#FFFFFF';
	cl.style.textAlign = 'left';
	cl.style.padding = '10px 0px 10px 0px';
	cl_in = '<div style="float:left;width:500px;color:#2f5b77;font-size:12px;">' + base64_decode(txt) + '</div>';
	cl_in += '<div style="float:right;width:90px;text-align:left;"><a href="javascript:closePic();" style="text-decoration:none;color:#666666;white-spacing:nowrap;">Затвори <img src="http://www.myplanet.bg/images/default/close.gif" alt="Затвори" style="vertical-align:middle;border:0px;"/></a></div>';
	cl.innerHTML = cl_in;
	
	//pic
	pic_div = document.createElement('div');
	pic_div.style.cssText = 'float:left;';
	pic_div.style.width = '600px';
	//pic_div.style.height = '600px';
	
	pic = document.createElement('img');
	pic.id = 'imagePreview';
	pic.src = img;
	pic.setAttribute('alt', '');
	pic.setAttribute('border', '0');
	
	pic_div.appendChild(pic);
	pl.appendChild(ct);
	pl.appendChild(pic_div);
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	//disable scroll
	//var elementBody = document.getElementsByTagName('html');
	//elementBody[0].style.overflow = 'hidden';
	//elementBody[0].onselectstart = function() {return false;};
}

function closeBox(eval_script)
{
	if(document.getElementById('showMessage')) 
	{
		document.body.removeChild(document.getElementById('showMessage'));
		document.body.removeChild(document.getElementById('showMessageBox'));
		
		eval(eval_script);
		
		//enable scroll
		var elementBody = document.getElementsByTagName('html');
		elementBody[0].style.overflow = '';
		//elementBody[0].onselectstart = function() {return true;};
	}
}

function showBigBox(targetURL, twidth, theight, txt)
{
	//opera fix
	var agt = navigator.userAgent.toLowerCase();
  var is_opera = (agt.indexOf("opera") != -1);
	//if(is_opera) txt = Url.decode(txt);
	
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showMessage';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	//dl.style.height = parseInt(document.getElementById('allover').offsetHeight) + 40 + 'px';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0 + 'px';
	//dl.style.top = scrollHeight+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1800;
	
	//content div
	pl = document.createElement('div');
	pl.id = 'showMessageBox';
	pl.style.cssText = 'float:left;';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-150+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-' + (twidth + 30)/2 +'px';
	pl.style.padding = '10px 15px 10px 15px';
	pl.style.width = twidth + 'px';
	//pl.style.height = theight + 45 + 'px';
	pl.style.textAlign = 'center';
	pl.style.zIndex = 1801;
	pl.style.backgroundImage = 'url(\'http://www.myplanet.bg/images/default/spinner.gif\')';
	pl.style.backgroundPosition = (twidth + 30) / 2 - 12 + 'px 200px';
	pl.style.backgroundRepeat = 'no-repeat';
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showBoxContentClose';
	cl.style.cssText = 'float:left;';
	cl.style.width = twidth + 'px';
	//cl.style.border = 'red 1px solid';
	cl.style.backgroundColor = '#FFFFFF';
	cl.style.textAlign = 'left';
	cl.style.padding = '10px 0px 10px 0px';
	cl_in = '<div style="float:left;padding-left:5px;width:' + (twidth - 105) + 'px;font-size:12px;">' + txt + '</div>';
	cl_in += '<div style="float:right;width:80px;text-align:left;"><a href="javascript:closeBox(\'\');" style="text-decoration:none;color:#666666;white-spacing:nowrap;">Затвори <img src="http://www.myplanet.bg/images/default/close.gif" alt="Затвори" style="vertical-align:middle;border:0px;"/></a></div>';
	cl.innerHTML = cl_in;
	
	//content
	content_div = document.createElement('div');
	content_div.style.cssText = 'float:left;';
	content_div.style.width = twidth + 'px';
	//content_div.style.height = theight + 'px';
	content_div.id = 'contentBox';
	
	pl.appendChild(content_div);
	pl.appendChild(cl);
	
	var pars = '';
	new Ajax.Updater('contentBox', targetURL, {method:'get', postBody:pars, evalScripts:true});
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	//disable scroll
	var elementBody = document.getElementsByTagName('html');
	elementBody[0].style.overflow = 'hidden';
	//elementBody[0].onselectstart = function() {return false;};
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowW, windowH;
	if (self.innerHeight) {	// all except Explorer
		windowW = self.innerWidth;
		windowH = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowW = document.documentElement.clientWidth;
		windowH = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowW = document.body.clientWidth;
		windowH = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowH){
		pageHeight = windowH;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowW){	
		pageWidth = windowW;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowW,windowH) 
	return arrayPageSize;
}

function winWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if( document.documentElement && document.documentElement.clientWidth )
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function winHeight()
{
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' )
  {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && document.documentElement.clientHeight )
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight )
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollX()
{
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfX = window.pageXOffset;
  }
  else if( document.body && document.body.scrollLeft )
  {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && document.documentElement.scrollLeft )
  {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function sendPM(from_id, to_id)
{
	var reg = document.pmform;
	
	if(trim(reg.message.value) == '')
	{
		alert('Въведете текст на съобщението.');
		reg.message.focus();
		return false;
	}
	
	var pars = 'from_id=' + from_id + '&to_id=' + to_id + '&message=' + reg.message.value;
	new Ajax.Updater('pmholder', 'http://www.myplanet.bg/modules/users/send_pm.php', {method: 'post', postBody:pars});
}

function sendPMfriends(from_id)
{
	var reg = document.pmform;
	
	if(trim(reg.to_id.value) == '')
	{
		alert('Изберете до кого ще изпратите съобщението.');
		reg.to_id.focus();
		return false;
	}
	if(trim(reg.message.value) == '')
	{
		alert('Въведете текст на съобщението.');
		reg.message.focus();
		return false;
	}
	
	var pars = 'from_id=' + from_id + '&to_id=' + reg.to_id.value + '&message=' + reg.message.value;
	new Ajax.Updater('pmholder', 'http://www.myplanet.bg/modules/users/send_pm.php', {method: 'post', postBody:pars});
}

function friendRequest(from_user, to_user)
{
	var pars = 'from_id=' + from_user + '&to_id=' + to_user;
	new Ajax.Request('http://www.myplanet.bg/modules/users/friends_rq.php', {method: 'post', postBody:pars, onSuccess:function(transport)
		{
			var result = transport.responseText;
			
			alert(result);
			
			if(document.getElementById('frh' + to_user)) document.getElementById('frh' + to_user).style.display = 'none';
		}
	});
}

function fixLoginUser(what)
{
	if(trim(what.value) == 'Потребителско име') what.value = '';
	else if(trim(what.value) == '') what.value = 'Потребителско име';
}

function fixLoginPass(what)
{
	if(trim(what.value) == 'Парола') what.value = '';
	else if(trim(what.value) == '') what.value = 'Парола';
}

function setEmoticon(formname, fieldname, symbol)
{
	eval("var reg = document." + formname + ";");
	if(reg)
	{
		eval("var txt_field = reg." + fieldname + ";");
		if(txt_field)
		{
			ntext = ' ' + symbol + ' ';
			if (txt_field.createTextRange && txt_field.caretPos)
			{
				var caretPos = txt_field.caretPos;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + ntext + ' ' : caretPos.text + ntext;
				txt_field.focus();
			}
			else
			{
				txt_field.value  += ntext;
				txt_field.focus();
			}
		}
	}
}

function loadWeather(from_id, to_div, cid) {
	var id = document.getElementById(from_id).value;
	var country_id = document.getElementById(cid).value;
	
	var pars = 'location_id=' + id + '&country_id=' + country_id;
	
	if(id != 0) {
		document.getElementById(to_div).style.display = '';
		document.getElementById(to_div).innerHTML = '<center><span style="font-size:12px; color:#000">Зарежда...</span></center>';
	}
	else {
		document.getElementById(to_div).style.display = 'none';	
	}
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_weather.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText;
			document.getElementById(to_div).innerHTML = result;
		}
	});
	
}

function valid_email(email)
{
	var chk = /^[^@]{1,64}@[^@]{1,255}$/g;
	if ( !email.match ( chk ) )
	{
		return false;
	}
	
	email_array = email.split("@");
	local_array = email_array[0].split(".");
	for (var i = 0; i < local_array.length; i++)
	{
		var chk = /^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/g;
		if ( !local_array[i].match ( chk ) )
		{ 
			return false;
		}
	}
	
	var chk = /^\[?[0-9\.]+\]?$/g;
	if ( !email_array[1].match ( chk ) )
	{
		domain_array = email_array[1].split(".");
		if(domain_array.length < 2) return false;
		for (var i = 0; i < domain_array.length; i++)
		{
			if(domain_array[i].length < 2) return false;
			
			var chk = /^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/g;
			if ( !domain_array[i].match ( chk ) ) return false;
		}
	}
	return true;
}

function checkInviteFriendForm()
{
	var reg = document.inviteform;
	
	if(trim(reg.email.value) == '')
	{
		alert('Моля, веъведете e-mail на приятеля, който искате да поканите.');
		reg.email.focus();
		return false;
	}
	if(!valid_email(trim(reg.email.value)))
	{
		alert('Моля, веъведете валиден e-mail адрес.');
		reg.email.focus();
		return false;
	}
	
	reg.submit();
}

function expandCollapse(did)
{
	var tdiv = document.getElementById(did);
	
	if(tdiv)
	{
		if(tdiv.style.display == '') Effect.BlindUp(did);
		else Effect.BlindDown(did);
	}
}

function checkComment()
{
	var reg = document.commentform;
	
	if(trim(reg.comment.value) == '')
	{
		alert('Въведете коментар.');
		reg.comment.focus();
		return false;
	}
	//else if(trim(reg.verify_code.value) == '')
	//{
	//	alert('Въведете кодът за сигурност.');
	//	reg.verify_code.focus();
	//	return false;
	//}
	
	var pars = 'do=1&type='+reg.type.value+'&material_id=' + reg.material_id.value + '&comment=' + reg.comment.value; // + '&verify_code=' + reg.verify_code.value;
	new Ajax.Request('http://www.myplanet.bg/ajax/put_comment.php', {method:'post', postBody:pars, onSuccess:function(transport)
		{
			if(trim(transport.responseText) != '')
			{
				alert(transport.responseText);
				return false;
			}
			else
			{
				//document.getElementById('verify_code_image').src = 'http://www.myplanet.bg/captcha.php';
				reg.reset();
				expandCollapse('write_comment_holder');
				
				getComments(reg.type.value, reg.material_id.value, 1);
				
				updateCommentsCount(reg.type.value, reg.material_id.value);
			}
		} });
}

function getComments(type, material_id, pageID)
{
	var pars = 'do=1&type=' + type + '&material_id=' + material_id + '&pageID=' + pageID;
	new Ajax.Updater('comments_holder', 'http://www.myplanet.bg/ajax/get_comments.php', {method:'post', postBody:pars, evalScripts:true});
}

function updateCommentsCount(type, material_id)
{
	var pars = 'do=1&type=' + type + '&material_id=' + material_id;
	new Ajax.Updater('comments_count', 'http://www.myplanet.bg/ajax/get_comments_count.php', {method:'post', postBody:pars, evalScripts:true});
}

function submitOnEnter(myfield, submit_function, e)
{
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
		eval(submit_function);
		return false;
	}
	else return true;
}

function vote_competition(uid,cid)
{
	document.getElementById("spinner_"+uid).innerHTML = '<img src = "http://www.myplanet.bg/images/default/spinner.gif" style="margin-top:2px; margin-left:2px;" />';
	var update_field = 'votes_text_' + uid;
	var pars = 'uid='+uid+'&cid='+cid;
	new Ajax.Updater(update_field, 'http://www.myplanet.bg/ajax/post_vote.php', {method:'post', postBody:pars, evalScripts:true , onSuccess:function(transport) {
	document.getElementById("spinner_"+uid).innerHTML = '<img src = "http://www.myplanet.bg/images/default/gray_vote.gif"/>';
	}});
}

function setMyPlacesTypeDate(formname)
{
	eval("var reg = document." + formname + ";");
	
	if(reg.type_id.value != 2)
	{
		document.getElementById('place_period_from').style.display = 'block';
		document.getElementById('place_period_to').style.display = 'block';
	}
	else
	{
		document.getElementById('place_period_from').style.display = 'none';
		document.getElementById('place_period_to').style.display = 'none';
	}
}

function showNews(news_id)
{
	if(news_id == parent_news_id) return false;
	
	if(document.getElementById('news_link_' + news_id) && document.getElementById('news_link_' + parent_news_id))
	{
		document.getElementById('news_link_' + news_id).className = 'newspaging_selected';
		document.getElementById('news_link_' + parent_news_id).className = 'newspaging_default';
		
		$('news_box_' + parent_news_id).fade();
		$('news_box_' + news_id).appear();
		
		parent_news_id = news_id;
	}
}

function showNextNews()
{
	var current_news_pos = news_id_array.in_array(parent_news_id);
	
	if(current_news_pos >= 0)
	{
		if(news_id_array[(current_news_pos + 1)] != undefined && news_id_array[(current_news_pos + 1)] != '') news_id = news_id_array[(current_news_pos + 1)];
		else news_id = news_id_array[0];
		
		if(document.getElementById('news_link_' + news_id) && document.getElementById('news_link_' + parent_news_id))
		{
			document.getElementById('news_link_' + news_id).className = 'newspaging_selected';
			document.getElementById('news_link_' + parent_news_id).className = 'newspaging_default';
			
			$('news_box_' + parent_news_id).fade();
			$('news_box_' + news_id).appear();
			
			parent_news_id = news_id;
		}
	}
}

function showPrevNews()
{
	var current_news_pos = news_id_array.in_array(parent_news_id);
	
	if(current_news_pos >= 0)
	{
		if(news_id_array[(current_news_pos - 1)] != undefined && news_id_array[(current_news_pos - 1)] != '') news_id = news_id_array[(current_news_pos - 1)];
		else news_id = news_id_array[(news_id_array.length - 1)];
		
		if(document.getElementById('news_link_' + news_id) && document.getElementById('news_link_' + parent_news_id))
		{
			document.getElementById('news_link_' + news_id).className = 'newspaging_selected';
			document.getElementById('news_link_' + parent_news_id).className = 'newspaging_default';
			
			$('news_box_' + parent_news_id).fade();
			$('news_box_' + news_id).appear();
			
			parent_news_id = news_id;
		}
	}
}

function showTravelNotes(tn_id)
{
	if(tn_id == parent_tn_id) return false;
	
	if(document.getElementById('tn_link_' + tn_id) && document.getElementById('tn_link_' + parent_tn_id))
	{
		document.getElementById('tn_link_' + tn_id).className = 'newspaging_selected';
		document.getElementById('tn_link_' + parent_tn_id).className = 'newspaging_default';
		
		$('tn_box_' + parent_tn_id).fade();
		$('tn_box_' + tn_id).appear();
		
		parent_tn_id = tn_id;
	}
}

function showNextTravelNotes()
{
	var current_tn_pos = tn_id_array.in_array(parent_tn_id);
	
	if(current_tn_pos >= 0)
	{
		if(tn_id_array[(current_tn_pos + 1)] != undefined && tn_id_array[(current_tn_pos + 1)] != '') tn_id = tn_id_array[(current_tn_pos + 1)];
		else tn_id = tn_id_array[0];
		
		if(document.getElementById('tn_link_' + tn_id) && document.getElementById('tn_link_' + parent_tn_id))
		{
			document.getElementById('tn_link_' + tn_id).className = 'newspaging_selected';
			document.getElementById('tn_link_' + parent_tn_id).className = 'newspaging_default';
			
			$('tn_box_' + parent_tn_id).fade();
			$('tn_box_' + tn_id).appear();
			
			parent_tn_id = tn_id;
		}
	}
}

function showPrevTravelNotes()
{
	var current_tn_pos = tn_id_array.in_array(parent_tn_id);
	
	if(current_tn_pos >= 0)
	{
		if(tn_id_array[(current_tn_pos - 1)] != undefined && tn_id_array[(current_tn_pos - 1)] != '') tn_id = tn_id_array[(current_tn_pos - 1)];
		else tn_id = tn_id_array[(tn_id_array.length - 1)];
		
		if(document.getElementById('tn_link_' + tn_id) && document.getElementById('tn_link_' + parent_tn_id))
		{
			document.getElementById('tn_link_' + tn_id).className = 'newspaging_selected';
			document.getElementById('tn_link_' + parent_tn_id).className = 'newspaging_default';
			
			$('tn_box_' + parent_tn_id).fade();
			$('tn_box_' + tn_id).appear();
			
			parent_tn_id = tn_id;
		}
	}
}

function voteForSurvey(survey_id)
{
	var reg = document.survey;
	var rchecked = 0;
	for(var i = 0; i < reg.answer.length; i++)
	{
		if(reg.answer[i].checked)
		{
			rchecked = 1;
			var rchecked_value = reg.answer[i].value;
		}
	}
	
	if(rchecked == 0)
	{
		alert('Моля, изберете отговор от анкетата.');
		return false;
	}
	
	var pars = 'ar=1&survey_id=' + survey_id + '&answer_id=' + rchecked_value;
	new Ajax.Updater('survey_info', 'http://www.myplanet.bg/modules/right_menu/survey.php', {method: 'post', postBody: pars, evalScripts: true});
}

function viewSurveyResults(survey_id)
{
	var pars = 'ar=1&survey_id=' + survey_id + '&vresult=1';
	new Ajax.Updater('survey_info', 'http://www.myplanet.bg/modules/right_menu/survey.php', {method: 'post', postBody: pars, evalScripts: true});
}

function participateSurvey(survey_id)
{
	var pars = 'ar=1&survey_id=' + survey_id + '&participate=1';
	new Ajax.Updater('survey_info', 'http://www.myplanet.bg/modules/right_menu/survey.php', {method: 'post', postBody: pars, evalScripts: true});
}

function sendReservation()
{
	var reg = document.reservationsform;
	
	var pars = 'do=1';
	if(reg.hotel_id) pars += '&hotel_id='+reg.hotel_id.value;
	if(reg.excursion_id) pars += '&excursion_id='+reg.excursion_id.value;
	if(reg.excursion_main_type) pars += '&excursion_main_type='+reg.excursion_main_type.value;
	pars += '&rname='+reg.reservation_name.value+'&remail='+reg.reservation_email.value+'&rtel='+reg.reservation_tel.value+'&rtext='+reg.reservation_text.value+'&verify_code='+reg.verify_code.value;
	new Ajax.Request('http://www.myplanet.bg/ajax/send_reservation.php', {method:'post', postBody:pars, onSuccess:function(transport)
		{
			var res = transport.responseText;
			if(res == 'verification_error')
			{
				alert('Не сте въвели правилен идентификационен код.');
				reg.verify_code.focus();
			}
			else
			{
				alert('Вашето запитване беше изпратено успешно.');
				
				reg.reset();
				expandCollapse('send_reservation_holder');
			}
		} });
}

var Utf8 = {
 
 // public method for url encoding
 encode : function (string) {
  string = string.replace(/\r\n/g,"\n");
  var utftext = "";
 
  for (var n = 0; n < string.length; n++) {
 
   var c = string.charCodeAt(n);
 
   if (c < 128) {
    utftext += String.fromCharCode(c);
   }
   else if((c > 127) && (c < 2048)) {
    utftext += String.fromCharCode((c >> 6) | 192);
    utftext += String.fromCharCode((c & 63) | 128);
   }
   else {
    utftext += String.fromCharCode((c >> 12) | 224);
    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
    utftext += String.fromCharCode((c & 63) | 128);
   }
 
  }
 
  return utftext;
 },
 
 // public method for url decoding
 decode : function (utftext) {
  var string = "";
  var i = 0;
  var c = c1 = c2 = 0;
 
  while ( i < utftext.length ) {
 
   c = utftext.charCodeAt(i);
 
   if (c < 128) {
    string += String.fromCharCode(c);
    i++;
   }
   else if((c > 191) && (c < 224)) {
    c2 = utftext.charCodeAt(i+1);
    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    i += 2;
   }
   else {
    c2 = utftext.charCodeAt(i+1);
    c3 = utftext.charCodeAt(i+2);
    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
    i += 3;
   }
 
  }
 
  return string;
 }
}

var Url = {
 
 // public method for url encoding
 encode : function (string) {
  return escape(this._utf8_encode(string));
 },
 
 // public method for url decoding
 decode : function (string) {
  return this._utf8_decode(unescape(string));
 },
 
 // private method for UTF-8 encoding
 _utf8_encode : function (string) {
  string = string.replace(/\r\n/g,"\n");
  var utftext = "";
 
  for (var n = 0; n < string.length; n++) {
 
   var c = string.charCodeAt(n);
 
   if (c < 128) {
    utftext += String.fromCharCode(c);
   }
   else if((c > 127) && (c < 2048)) {
    utftext += String.fromCharCode((c >> 6) | 192);
    utftext += String.fromCharCode((c & 63) | 128);
   }
   else {
    utftext += String.fromCharCode((c >> 12) | 224);
    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
    utftext += String.fromCharCode((c & 63) | 128);
   }
 
  }
 
  return utftext;
 },
 
 // private method for UTF-8 decoding
 _utf8_decode : function (utftext) {
  var string = "";
  var i = 0;
  var c = c1 = c2 = 0;
 
  while ( i < utftext.length ) {
 
   c = utftext.charCodeAt(i);
 
   if (c < 128) {
    string += String.fromCharCode(c);
    i++;
   }
   else if((c > 191) && (c < 224)) {
    c2 = utftext.charCodeAt(i+1);
    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    i += 2;
   }
   else {
    c2 = utftext.charCodeAt(i+1);
    c3 = utftext.charCodeAt(i+2);
    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
    i += 3;
   }
 
  }
 
  return string;
 }
}

function clubTabs(id) {
	document.getElementById('all_clubs').style.display = 'none';
	document.getElementById('my_clubs').style.display = 'none';
	document.getElementById('new_club').style.display = 'none';
	document.getElementById(id).style.display = '';
}

function getTourismLocation(formname, location_id, tourism_id_field, offers)
{
	var pars = 'doit=1&location_id=' + location_id + '&offers=' + offers;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_tourism_by_location.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + tourism_id_field + ";");
			sel.options.length = 0;
			sel.options[0] = new Option('Всички', '');
			
			if(trim(transport.responseText) != '')
			{
				var start = 0;
				
				for(var i = start; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
		}
	});
}

function getHolidayLocation(formname, location_id, holiday_id_field, country_id)
{
	var pars = 'doit=1&country_id=' + country_id + '&location_id=' + location_id;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_holidays_by_location.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + holiday_id_field + ";");
			sel.options.length = 0;
			sel.options[0] = new Option('Всички', '');
			
			if(trim(transport.responseText) != '')
			{
				var start = 0;
				
				for(var i = start; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
		}
	});
}

function getExcursionCategoryLocation(formname, location_id, category_id_field, country_id)
{
	var pars = 'doit=1&country_id=' + country_id + '&location_id=' + location_id;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_excursion_categories_by_location.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + category_id_field + ";");
			sel.options.length = 0;
			sel.options[0] = new Option('Всички', '');
			
			if(trim(transport.responseText) != '')
			{
				var start = 0;
				
				for(var i = start; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
		}
	});
}

function getHotelCategoryLocation(formname, location_id, category_id_field)
{
	var pars = 'doit=1&location_id=' + location_id;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_hotel_categories_by_location.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + category_id_field + ";");
			sel.options.length = 0;
			sel.options[0] = new Option('Всички', '');
			
			if(trim(transport.responseText) != '')
			{
				var start = 0;
				
				for(var i = start; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
		}
	});
}

function setFilterOptions(formname, location_id, tourism_id_field, holiday_id_field)
{
	getTourismLocation(formname, location_id, tourism_id_field, 1);
	
	getHolidayLocation(formname, location_id, holiday_id_field);
}

function setFilterOptionsAbroad(formname, location_id, category_id_field, holiday_id_field, country_id)
{
	getExcursionCategoryLocation(formname, location_id, category_id_field, country_id);
	
	getHolidayLocation(formname, location_id, holiday_id_field, country_id);
}

function setFilterOptionsLodging(formname, location_id, tourism_id_field, hotel_category_id_field, offers)
{
	getTourismLocation(formname, location_id, tourism_id_field, offers);
	
	getHotelCategoryLocation(formname, location_id, hotel_category_id_field);
}

function setFilterOptionsRecipes(formname, country_id, category_id_field)
{
	var pars = 'doit=1&country_id=' + country_id;
	
	new Ajax.Request('http://www.myplanet.bg/ajax/get_recipes_categories_by_location.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			var snew_res = 0;
			eval("var sel = document." + formname + "." + category_id_field + ";");
			sel.options.length = 0;
			sel.options[0] = new Option('Всички', '');
			
			if(trim(transport.responseText) != '')
			{
				var start = 0;
				
				for(var i = start; i < result.length; i++)
				{
					var new_res_array = result[i].split(',');
					
					sel.options[(i+1)] = new Option(new_res_array[1], new_res_array[0]);
				}
			}
		}
	});
}

function convertWord(type, content) {
    switch (type) {
        // Gets executed before the built in logic performes it's cleanups
        case "before":
            // do nothing
            break;

        // Gets executed after the built in logic performes it's cleanups
        case "after":
            content = content.replace(/<(!--)([\s\S]*)(--)>/gi, "");
            break;
    }

    return content;
}
