function setBackButtonsEventHandling () {
	var as = document.getElementsByTagName ("a");
	if (window.history.length <= 1) {
		return true;
	}

	for (loop = 0; loop < as.length; loop ++) {
		if (as.item (loop).className == "backLink") {
			as.item (loop).style.display = "block";
			as.item (loop).onclick = function () {
				window.history.back ();
				return false;
			}
			as.item (loop).onmouseover = function () {
				window.status = "";
				return true;
			}
		}
	}
}


function changePicture (link, mainHref, desc, mainWidth, mainHeight, originalWidth, originalHeight, alt) {
    if (link != 'false') {
        document.getElementById ('bighref').onclick = function () {
        	showOriginalPicture( originalWidth, originalHeight, link, desc, alt );
			return false;
        }
    } else {
        document.getElementById ('bighref').onclick = function () {
        	return false;
        }
    }
    var img = '<img src="'+mainHref+'" alt="'+desc.replace(/\"/g, '&quot;')+'" title="'+desc.replace(/\"/g, '&quot;')+'" width="'+mainWidth+'" height="'+mainHeight+'" />';
    document.getElementById ('bighref').innerHTML = img;
    document.getElementById ('imageDescription').innerHTML = desc;
    return false;
}

function changePictureForGallery (url, mainHref, desc, mainWidth, mainHeight, windowWidth, windowHeight) {    
    document.getElementById ('bighref').onclick = function () {
    	openGallery(url, 1, 1, windowWidth, windowHeight );
		return false;
    }
    var img = '<img src="'+mainHref+'" alt="'+desc.replace(/\"/g, '&quot;')+'" title="'+desc.replace(/\"/g, '&quot;')+'" width="'+mainWidth+'" height="'+mainHeight+'" />';
    document.getElementById ('bighref').innerHTML = img;
    document.getElementById ('imageDescription').innerHTML = desc;
    return false;
}

var myWin;

function showOriginalPicture( width, height, link, title, alt ) {
	if( width<=0 || height<=0 ) return false;

	var winWidth, winHeight;

	if( Math.ceil(width)>Math.ceil(screen.width*0.8) ) { winWidth = Math.ceil(screen.width*0.8); }
	else { winWidth = Math.ceil(width); }
	if( Math.ceil(height)>Math.ceil(screen.height*0.8) ) { winHeight = Math.ceil(screen.height*0.8); }
	else { winHeight = Math.ceil(height); }

	winParam = 'width='+winWidth+',height='+winHeight+',';
	winParam += 'resizable=yes,';
	if( winWidth<width || winHeight<height ) winParam += 'scrollbars=yes,';
	else winParam += 'scrollbars=no,';
	winParam += 'left='+(screen.width*0.2)+',top='+(screen.height*0.2)+',screenX='+(screen.width*0.2)+',screenY='+(screen.height*0.2)+'';
    if( myWin )
    	myWin.close();
    
    myWin = window.open('about:blank', '_blank', winParam);
    myWin.document.open();
    myWin.document.clear();
    try {
    	myWin.document.title = title;
    } catch(e) {/*ie does not support document.title*/}
	myWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	myWin.document.write('<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
    myWin.document.write('<title>'+title+'</title>');
    myWin.document.write('</head><body style="margin:0px;background-color:#ebebeb;text-align:center;">');
    myWin.document.write('<img src="'+link+'" alt="'+alt+'" title="'+alt+'" onclick="window.close()" style="cursor: pointer; cursor: hand;" />');
    myWin.document.write('</body></html>');
    myWin.document.close();
    return false;
}


function setInputDefaultValue( fieldId ) {
	var reportAbuseComment = document.getElementById( fieldId );
	if( typeof reportAbuseComment=='undefined' || reportAbuseComment==null ) { return false; }
	var reportAbuseCommentDefault = document.getElementById( fieldId+'DEFAULT' );
	reportAbuseComment.value = reportAbuseCommentDefault.value;
	reportAbuseComment.onfocus = function () {
		var reportAbuseCommentDefault = document.getElementById( this.id+'DEFAULT' );
		if( reportAbuseCommentDefault.value!='' && this.value==reportAbuseCommentDefault.value ) {
			this.value = '';
			reportAbuseCommentDefault.value = '';
		}
	}
}



function initiateReportAbuse () {
	/*var reportAbuseButton = document.getElementById( 'reportAbuseButton' );
	if( typeof reportAbuseButton!='undefined' && reportAbuseButton!=null ) {
		reportAbuseButton.onclick = function() {
			var reportAbuse = document.getElementById( 'reportAbuse' );
			if( typeof reportAbuse!='undefined' && reportAbuse!=null ) {
				if( reportAbuse.style.display!='block' ) {
					reportAbuse.style.display = 'block';
				} else {
					reportAbuse.style.display = 'none';
				}
				return false;
			}
		}
	}*/
	var reportAbuseComment = document.getElementById( 'comment' );
	if( typeof reportAbuseComment=='undefined' || reportAbuseComment==null ) { return false; }
	var reportAbuseCommentDefault = document.getElementById( 'commentDEFAULT' );
	if( typeof reportAbuseCommentDefault=='undefined' || reportAbuseCommentDefault==null ) { return false; }
	reportAbuseComment.value = reportAbuseCommentDefault.value;
	reportAbuseComment.onfocus = function () {
		var reportAbuseCommentDefault = document.getElementById( 'commentDEFAULT' );
		if( reportAbuseCommentDefault.value!='' && this.value==reportAbuseCommentDefault.value ) {
			this.value = '';
			// ie resize this field after value change so we have to set old value
			this.style.width = '91%';
			reportAbuseCommentDefault.value = '';
		}
	}
}

if (w3cDOM) {
	listenEvent (window, "load", initiateReportAbuse);
}

/* Returns TRUE if pointed ad is in clipboard */
function inClipboard( id ) {
	var clipboard = getCookie( 'clipboard' );
	if( clipboard ) {
	    clipboard = "|" + clipboard;
	    if( clipboard.indexOf( '|'+id+'|' )>=0 ) {
	    	return true;
	    }
	}
	return false;	
}


function openGallery(url,top,left,width,height) {
	var p = "";
	if (top>-1) p=",top="+top;
	if (left>-1) p=p+",left="+left;
	if (width>-1) p=p+",width="+width;
	if (height>-1) p=p+",height="+height;
	window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0'+p);
}

$(function() {

if(document.getElementById('mapLon')){
var GMapLon = (document.getElementById('mapLon').value);
var GMapLat = (document.getElementById('mapLat').value);
var GMapZoom = (document.getElementById('mapZoom').value);
GMapLon = GMapLon.replace(',','.');
GMapLat = GMapLat.replace(',','.');
GMapZoom = GMapZoom.replace(',','.');


showMapAdvert(GMapLat, GMapLon, GMapZoom);
}
})



//showMapParams();