var isNS = false;
var isIE = false;
var isMZ = false;
if (document.layers) isNS=true;
if (document.all) isIE=true;
if (window.XMLHttpRequest) isMZ = true;

var url, title, topic, folder, params;

function endecrypt_js(b,tx) {
        var ch, cd, df=1, tm="";
        //var text = document.getElementById("text").value;
        for (var i=0; i<tx.length; i++) {
            ch = tx.charCodeAt(i);
            (b) ? xd=ch+df : cd=ch-df;
            tm += String.fromCharCode(cd);
        }
        return tm;
}

function mw(s){
	    document.write (endecrypt_js(false, s));
}

function ml(s,el){
	    el.href='mailto:' +endecrypt_js(false, s);
}

function byId(id){
    if (isMZ || isIE)
		return document.getElementById(id);
	else if (isNS) 
		return document.layers[id];
	else
		return null;
}

function resizeImg(nw, id){
	var i = byId(id);
	if (!i) return;
	var h = i.height;
	var w = i.width;
	var d = parseFloat(nw/w);
	var nh = parseInt(h*d);
	i.width = nw;
	i.height = nh;
	return html = "<b>Original Size:</b> " + w + "x" + h + " [<a href='javascript:void(0);' onclick='resizeImg(" + w + ",\"ipic\");'>Set</a>]<br><b>Preview Size:</b> " + nw + "x" + nh + " [<a href='javascript:void(0);' onclick='resizeImg(" + nw + ",\"ipic\");'>Set</a>]";
}

function dist(x1,y1,x2,y2){
		var arr = showModelessDialog( "/images/ShowMapDistance.aspx?x1="+ x1 + "&y1=" + y1 + "&x2=" + x2 + "&y2=" + y2,
		document,
		"font-family:Verdana; font-size:12; status: 0; dialogWidth:220px;dialogHeight:180px;help:no" );
}
	
function prnt(){
	try {
		var win;
		var printurl = url;
		params = "";
		if (printurl.indexOf("?")>-1) {
			params = printurl.substr(printurl.lastIndexOf("?"))
			printurl = printurl.substr(0,printurl.lastIndexOf("/")+1)
		}
		win = window.open("about:blank",'PrintArticle','height=400,width=620,scrollbars=1,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
		if (!win) {
			alert('This service uses Javascript to open print page but new print window can not be open!\n Please check your browser pop-up blocker and allow pop-ups from this site!');
			return;
		}
		win.navigate(printurl + "Print_" + topic + ".aspx" + params)
		win.focus();
		//win.window.print()
	}
	catch (exception) {return}
}
function send(){
	alert("Coming soon");
	return;
	try {
		var win;
		var printurl = url;
		params = "";
		if (printurl.indexOf("?")>-1) {
			params = printurl.substr(printurl.lastIndexOf("?"))
			printurl = printurl.substr(0,printurl.lastIndexOf("/")+1)
		}
		win = window.open("about:blank",'SendArticle','height=450,width=800,scrollbars=1,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
		win.navigate(printurl + "Send_" + topic + ".aspx" + params)
		win.focus();
		//win.window.print()
	}
	catch (exception) {return}
}
function validateEmail(f) {
	emailReg=/^[^@]+@[^@]+.[a-z]{2,}$/i;
	JSemail=f.sendto.value;
	if (JSemail.search(emailReg)==-1) {
		document.forms[0].sendto.focus();
		alert('Please enter a valid email address.');
		return false;
	}
	return true;
}
function sh(){
	var	addlink = byId("addlink");
	try {
		if (addlink.style.display=="block") 
		{addlink.style.display = "none";}
	    else 
	    {addlink.style.display = "block";
		//window.scrollBy(0,10000);
		if (document.forms["addfrm"]) {
				window.scrollTo(0,1000);
				document.forms["addfrm"].elements[0].focus(0);
			}
		}
	} catch(e) {
		alert("You can not add link there");
		//window.open ("/Feedback.aspx?type=addLink");
	}
}
function Request(productid) {
	//if (confirm("This functionality will be ready soon. Do you want to make this request via our partner site Visit to Bulgaria?")) {
		d = new Date();
		var requestwin = window.open('http://get.info.bg/properties/Property_Request.asp?ProductID=' + productid +'&d=' + d.getTime(), 'requestwin', 'height=500,width=500,status=1,resizable=1,scrollbars=1');
	//}
}

function Show(ID){
var wwidth=388;
var wheight=280;
var winw = (screen.width - wwidth) / 2;
var winh = (screen.height - wheight) / 2;
//var gallery_newpwin = window.open("show_picture.html?" + ID,"gallery","resizable=1,scrollbars=0,width="+wwidth+",height="+wheight+",top=100,left="+winh);
	try
	{
		var gallery_newpwin = window.open("about:blank","gallery","resizable=1,scrollbars=0,width="+wwidth+",height="+wheight+",top=100,left="+winh);
		gallery_newpwin.focus();
		gallery_newpwin.document.write("<HTML><HEAD><title>Gallery</title></HEAD>");
		gallery_newpwin.document.write("<script>function resize(){try{var img = document.images[0];window.resizeTo(img.width+15,img.height+40);}catch(e){}window.focus();}</" + "script>");
		gallery_newpwin.document.write("<body topmargin=2 leftmargin=2 bottommargin=0 rightmargin=0 onload='resize();'>	<img src='" + ID + "'></body></HTML>");
		gallery_newpwin.document.close();
	}
	catch (e)
	{
		var gallery_newpwin = window.open("about:blank","_blank","resizable=1,scrollbars=0,width="+wwidth+",height="+wheight+",top=100,left="+winh);
		gallery_newpwin.focus();
		gallery_newpwin.document.write("<HTML><HEAD><title>Gallery</title></HEAD>");
		gallery_newpwin.document.write("<script>function resize(){try{var img = document.images[0];window.resizeTo(img.width+15,img.height+40);}catch(e){}window.focus();}</" + "script>");
		gallery_newpwin.document.write("<body topmargin=2 leftmargin=2 bottommargin=0 rightmargin=0 onload='resize();'>	<img src='" + ID + "'></body></HTML>");
		gallery_newpwin.document.close();
	}
}

function selplace(f){
	var wwidth=388;
	var wheight=280;
	var winw = (screen.width - wwidth) / 2;
	var winh = (screen.height - wheight) / 2;
	var winplace = window.open("places.aspx?code=" + f.r.value + "&type=" + f.tbl1.value,"_blank","status=1,resizable=1,scrollbars=0,width="+wwidth+",height="+wheight+",top=100,left="+winh);
	winplace.focus();
}

function Link(img){
		var ar = new Array();
		if (img=="root") {
			ar[0] = "http://www.guide-bulgaria.com";ar[1] = "Guide to Bulgaria";ar[2] = "";ar[3] = "/";
		} else {
			ar[0] = url;ar[1] = title;ar[2] = topic;ar[3] = folder;
		}
		if (isIE)  
			var arr = showModelessDialog( "/LinkToUs.asp?map=" + img, ar, "font-family:Verdana; font-size:12; status: 0; dialogWidth:500px;dialogHeight:500px;help:no" );
		else
			var arr = window.open( "/LinkToUs.asp?map=" + img +"&url=" + escape(ar[0]) + "&title=" + escape(ar[1]) + "&topic="+ escape(ar[2]) + "&folder=" + escape(ar[3]), "_blank", "width=500,height=500" );
}

function GetCookie (name) {
   var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0;
   while (i < clen) {
    var offset = i + alen;
    if (document.cookie.substring(i, offset) == arg) {
          var endstr = document.cookie.indexOf (";", offset);
          if (endstr == -1) { endstr = document.cookie.length; }
          return unescape(document.cookie.substring(offset, endstr));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
   }
   return null;
  }

function getQueryString(name) {
    var URL = document.URL;
    if (URL.indexOf("?")<0) return "";
    URL = URL.substring(URL.indexOf("?")+1);
    var params = URL.split("&");
    for (var i=0; i < params.length; i ++ ){
        var c= params[i].split("=");
        if (c[0].toLowerCase() == name.toLowerCase()) {return c[1];}
    }
    return "";
}
var advid = 1;
function ShBox(id){
    for (var i = 1; i < 11; i++) {
		var tbl = byId("t" + i);
		var cell =byId("c" + i);
		if (cell) cell.className = 'srch';
		if (tbl) tbl.style.display = 'none';
    }
	var tbl = byId("t" + id);
	var cell = byId("c" + id);
	if (tbl)
	{
	if (tbl.style.display=='none') {
		cell.className = 'srch_on';
		tbl.style.display='block';
	} else {
		cell.className = 'srch';
		tbl.style.display='none';
	}
    }
    advid = id;
	document.cookie = "box=" + id;
}
function nan (obj) {
	if (isNaN(obj.value)) {
		for (var i=0;i<obj.value.length;i++) { 
			if (isNaN(obj.value.charAt(i))) { obj.value = obj.value.replace (obj.value.charAt(i), '') }
		} 
		obj.focus(); 
	} 
}
function CountWords (text) {
	var char_count = text.length;
	var fullStr = text + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	if (fullStr.length <2) {
		word_count = 0;
	}
	return word_count;
}

function countkw(txt){
	return "chars: " + txt.length + " words: " + CountWords(txt);
}
function countds(el){
	divds.innerText = "chars: " + el.innerText.length + " words: " + CountWords(el.innerText);
}
function shmap(m){
	var ar = new Array();
	ar[0] = m;
	ar[1] = "5";
	if (isIE)  
		var arr = showModelessDialog( "/map.htm",ar,"font-family:Verdana; font-size:12; status: 0; dialogWidth:220px;dialogHeight:180px;help:no" );
	else
		var arr = window.open( "/map.htm?map=" + ar[0] +"&rad=" + ar[1], "_blank", "width=220px,height=180px" );

}
function showhide(id, idlabel) {
    var tbl = byId(id);
    var lbl = byId(idlabel);
    if (!tbl) return;
    if (tbl.style.display == "none") {
        tbl.style.display = "block";
        if (lbl) lbl.innerText = "Close Advanced Search <<";
        ShBox(advid);
    } else {
        tbl.style.display = "none";
        if (lbl) lbl.innerText = "Open Advanced Search >>";
    }
}