var xmlhttp = false;

		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				xmlhttp = null;
			}
		}

		if (! xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				xmlhttp = new XMLHttpRequest();
			}
			else {
			xmlhttp = false; }
		}

function chk_buscar() {

show = false ;
if (document.getElementById('sel_cid').value > 0 ) show = true;
if (document.getElementById('sel_prov').value > 0 ) show = true;

show = true ; //vinagi da se pokazva 07.07.2009

if (show) {
	document.getElementById('src').style.display='block';
	document.getElementById('buscar_but').style.display='block';
	}
else {
	document.getElementById('src').style.display='none';
	document.getElementById('buscar_but').style.display='none';
	}
return false;
}

function check_code(id2) {

val2 = document.getElementById('sms_code_'+id2).value ;

if (xmlhttp) {
	document.getElementById('tel_'+id2).innerHTML = "<img src='/loading.gif' border='0' alt='loading' />";
	document.getElementById('ver_tel_'+id2).style.display='none';
		
	xmlhttp.open('GET', '/check_code_bg.php?id=' + id2 + '&'+'code=' + val2 , false) ;
	xmlhttp.send(null);
	document.getElementById('tel_'+id2).innerHTML = "" + xmlhttp.responseText + "";
	answer = xmlhttp.responseText ;
	if (answer.match('answ_err') != null ) document.getElementById('ver_tel_'+id2).style.display='block';
  }
  
return false ;
}


function vote(id2) {
if (xmlhttp) {
	xmlhttp.open('GET', '/vote_tel.php?id=' + id2 , false) ;
	xmlhttp.send(null);
  }
}

function send_sms() {

phone = document.getElementById('phone').value ;
code = document.getElementById('code').value ;
txt = document.getElementById('txt').value ;

if (xmlhttp) {
	document.getElementById('answer').innerHTML = "<img src='/loading.gif' border='0' alt='loading' />";
	xmlhttp.open('GET', '/send_sms.php?phone=' + phone + '&'+'code=' + code + '&'+'txt=' + txt , false) ;
	xmlhttp.send(null);
	document.getElementById('answer').innerHTML = "" + xmlhttp.responseText + "";
  }
}

function sh_dif2() {
if (document.form1.fotos.checked == true) {
	document.getElementById("dif2").style.display='block';
	}
else {
	document.getElementById("dif2").style.display='none';
	}
} //func

function get_citys(elem_id_in , elem_id_out) {
	
val3 = document.getElementById(elem_id_in).value ;

if (xmlhttp) {
	/*
	document.getElementById(elem_id_out).innerHTML = "<img src='/loading.gif' border='0' alt='loading' />";
	xmlhttp.open('GET', '/get_citys.php?id=' + val3 , false) ;
	xmlhttp.send(null);
	document.getElementById(elem_id_out).innerHTML = "" + xmlhttp.responseText + "";
	*/

	var selCityIndex = document.getElementById('sel_prov2').selectedIndex;
	var selCity = document.getElementById('sel_prov2').value;
	if ((selCityIndex > 0) && (selCity != 30) && (selCity != 31) && (selCity != 32)) {
		addr = document.getElementById('sel_prov2').options[selCityIndex].text ;
		findAddr('България, ' +  addr);
		document.getElementById('map').style.display='block';
		}
	else {
		document.getElementById('map').style.display='none';
		}
	}
}

function swp(id , s) {
if (!s) s = "";
document.getElementById('img_box').innerHTML = "<img class='img_box' src='/pic.php?id=" + id + "&s=" + s + "' alt='picture' />";
}


/////////////////////////////////////////////geo begin

var map = null;
var geocoder = null;
var icon = null;
var point = null;
var marker = null;

function loader() {

	if (GBrowserIsCompatible()) {
	    map = new GMap2(document.getElementById("map"), { size: new GSize(380,250) });
        map.addControl(new GLargeMapControl());
        //map.setCenter(new GLatLng( 45.434336 , 12.338784 ), 14, G_HYBRID_MAP);
		map.setCenter(new GLatLng( 45.434336 , 12.338784 ), 14, G_NORMAL_MAP);
		geocoder = new GClientGeocoder();
		point = new GLatLng(45.434336 , 12.338784);
		
		marker = new GMarker(point, {draggable: true});
		icon = new GIcon();
		icon.iconSize = new GSize(20, 20);
		icon.shadowSize = new GSize(20, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.image = "/images/hotel_en.png";
		icon.shadow = "/images/hotel_bg.png";
		icon.infoWindowAnchor = new GPoint(5, 1);
		
		//////////////////// EVENTS ///////////////////////////////////////////////////////

		GEvent.addListener(marker, "dragend", function() {
			goToAfterMark(marker);
			});// addListener		
		
		GEvent.addListener(map, "click", function(overlay, point) {
			if (!overlay) { 
				marker.setPoint(point);
				goToAfterMark(marker);
				}
			});

		
		GEvent.addListener(map, "dragend", myMapDragEnd );

///////////////////////////// end EVENTS ///////////////////////////////////////////////
    	} // browser 
	} // end load2
///////////////////////////// functions geo /////////////////////////////////////

function createMarker(point, id , desc , price) {
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
	window.open('http://www.booking.com/searchresults.html?checkin_monthday=!today!&checkin_year_month=!c_in_ym!&checkout_monthday=!tomorrow!&checkout_year_month=!c_out_ym!&lang=bg&aid=307324&hotelids=' + id );
		});
	return marker;
	}

function fromFile() { // Add markers to the map
	var bounds = map.getBounds();
	var sw = bounds.getSouthWest();
	var ne = bounds.getNorthEast();
	if ( map.getZoom() > 13 ) {
		GDownloadUrl("/data2.php?sw=" + sw.toUrlValue() + "&ne=" + ne.toUrlValue() + "&z=" + map.getZoom() , function(data, responseCode) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
				parseFloat(markers[i].getAttribute("lng")));
				map.addOverlay( createMarker( point, parseFloat(markers[i].getAttribute("id"))  ) );
				}
			}); 
		} //if zoom >13
	}//add marker from file

function myMapDragEnd() {
	map.clearOverlays();
	fromFile();
	map.addOverlay(marker);
	marker.setPoint(map.getCenter());
	//document.getElementById("coor").value = marker.getPoint().toUrlValue();
	}

function findAddr(address) {
	if (geocoder) {
		geocoder.getLatLng( address, function(point) {
			if (!point) { 
				document.getElementById('map').style.display='none';
				document.getElementById("coor").value = '';
				} 
				else {
					if(address == 'България, ') {
						map.setCenter(point, 5); 
						document.getElementById('map').style.display='none';
						}
					else map.setCenter(point, 17);

					marker.setPoint(point);
					map.addOverlay(marker);
					fromFile();	
					}
				}// function
			); // geocoder
		}// if geocoder
	document.getElementById("coor").value = '';
	}// find_addr

function getAddress(overlay, latlng) {
	if (latlng != null) {
		address = latlng;
		geocoder.getLocations(latlng, showAddress);
		}
	}

function showAddress(response) {
	//map.clearOverlays();
	if (!response || response.Status.code != 200) {
	alert("Status Code:" + response.Status.code);
	} else {
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		marker.setPoint(point);
		document.getElementById("coor").value = marker.getPoint().toUrlValue();
		//document.getElementById("faddr").value = place.address ;
		}
	}
		///////////////////////////////// end functions /////////////////////////

/////////////////////////////////////////////geo end

function goToAfterMark(marker) {
	document.getElementById("coor").value = marker.getPoint().toUrlValue();
	//marker.setImage("http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png");
	return false;
	}

function open_map() {
document.getElementById('map_field').style.display = "block";
}

function text_phone(id) {
return "<div class='pay_field'>За да виждате телефонните номера, трябва да въведете код за абонамент <input id='sms_code_" + id + "' type='text' size='10' style='vertical-align:middle;' /><input type='button' class='but2' id='proveriBut' value='провери' onclick='check_code(" + id + "); return false;' /><br /><br />За да се абонирате за 7 дни, изпратете текст:<br /><strong>PASS</strong> на номер<sup>*</sup> <strong>1094</strong> за абонати на MTel и Globul<br /><strong>PASS</strong> на номер<sup>*</sup> <strong>1703</strong> за абонати на VIVAcom.<br /><sub>* Цена на 1 sms : 4.80лв. с включен д.д.с.</sub><br /><br /><u>Важно</u>:<br />Отговорност за достоверността на обявите носят подателите им. Информацията тук е получена и архивирана от интернет пространството.</div>";
}

function text_phoneru(id) {
return "<div class='pay_field'>Вам нужно получить код доступа. Отправьте смс с текстом <strong>GET PASS</strong> на номер <sup>*</sup> <strong>2810</strong>. Через несколько секунд вы получите ответную СМС с кодом доступа. Введите полученный код сюда: <input id='sms_code_" + id + "' type='text' size='10' style='vertical-align:middle;' /> <a href='#' onclick='check_code(" + id + "); return false;'><img src='/proverka.gif' alt='проверка' class='proverka' /></a><br /><br /><sub>* стоимость 1 смс : 295.00 руб.</sub></div>";
}

function text_password(id) {
return "<div class='pay_field'>За да получите парола, изпратете текст:<br /><strong>PASS</strong> на номер<sup>*</sup> <strong>1094</strong> за абонати на MTel и Globul<br /><strong>PASS</strong> на номер<sup>*</sup> <strong>1703</strong> за абонати на VIVAcom. <br /> и въведете получения код тук <input id='sms_code_" + id + "' type='text' size='10' style='vertical-align:middle;' /> <a href='#' onclick='check_code(" + id + "); return false;'><img src='/proverka.gif' alt='проверка' class='proverka' /></a><br /><sub>* Цена на 1 sms : 4.80лв. с включен д.д.с.</sub></div>";
}

function booking_adv_link() {
//document.location = "http://www.booking.com/index.html?aid=307324&lang=bg";
document.location = "http://eulands.com/%D1%80%D0%B5%D0%B7%D0%B5%D1%80%D0%B2%D0%B0%D1%86%D0%B8%D0%B8";
return false;
}

function getValueRadios(radioGroupName) {
	radios = document.getElementsByName(radioGroupName);
	for (i = 0; i < radios.length; i++) {
		if (radios[i].checked) return radios[i].value;
		}
	document.getElementById('err').innerHTML = ' Изберете размер.' ;
	return false;
	}

function sendOrder(code, sizetag, qnt, atras) {
	if (qnt*1 < 1) {
		document.getElementById('err').innerHTML = 'Изберете бройка.' ;
		}
	else {
		size = getValueRadios(sizetag);
		if (size) {
			document.getElementById('err').innerHTML = "<img src='/loading.gif' border='0' alt='loading' /> <font color='green'>Изчакайте ...</font>" ;
			document.location = "/addtocart.php?code="+code+"&size="+size+"&qnt="+qnt+"&atras="+atras;
			}
		}
	return false;
	}

function CheckOut(name, addr, phone, email) {

	err = '';
	
	if (!name) err = err + 'Липсва име. ';
	if (!addr) err = err + 'Липсва адрес. ';
	if (!phone) err = err + 'Липсва телефон. ';
	if (!email) err = err + 'Липсва e-mail. ';
	
	if (err != '') {
		document.getElementById('err').innerHTML = err ;
		}
	else {
		document.getElementById('err').innerHTML = "<img src='/loading.gif' border='0' alt='loading' /> <font color='green'>Изчакайте ...</font>" ;
		document.location = "/sendorder.php?name=" + name + "&addr=" + addr + "&phone=" + phone + "&email=" + email ;
		
		}
	return false;
	}


function checkInsert() {
	
	err = '';

	if (document.getElementById('cid').value == '') err = err + 'Избери раздел. ';
	if (document.getElementById('sel_prov2').value == '') err = err + 'Избери град. ';
	if ((document.getElementById('title_note').value == 'Заглавие ...') || (document.getElementById('title_note').value == '')) err = err + 'Липсва заглавие. ';
	if ((document.getElementById('text').value == 'Съдържание ...') || (document.getElementById('text').value == '')) err = err + 'Липсва съдържание. ';
	if (document.getElementById('phone').value == '') err = err + 'Липсва телефон. ';
	if (document.getElementById('code').value == '') err = err + 'Препиши нарисувания код. ';
	
	if (err != '') {
		document.getElementById('insErr').innerHTML = err ;
		return false;
		}
	else {
		document.getElementById('insErr').innerHTML = "<img src='/loading.gif' border='0' alt='loading' /> <font color='green'>Изчакайте ...</font>" ;
		return true;
		}
	}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkMobile(element) {
	var pregPatt=/\D/;
	if (element.value.match(pregPatt) || (element.value.length > 7)) {
		element.value = element.value.substr(0, element.value.length-1);
		return false;
		}
	else return true;
	}
	
function clearField(element) {
	element.value = '';
	return false;
	}
	
function setAct(value) {
	document.getElementById('act').value = value ;
	
	if (document.getElementById('act').value == value ) return true;
	else return false;
	}