function goTo(Url)
{
        location.href = Url;
}

function openPicture(ID)
{
        var m_nTop    = (screen.height/2)-375/2;
        var m_nLeft   = (screen.width/2)-500/2;;
        window.open('/gallery/?imageID=' + ID,'simpleGallery',"width=100,height=100,status=no,toolbar=0,menubar=0,location=0,scrollbars=0,top="+m_nTop+",left="+m_nLeft);
}

function resetForm(frmSrc,Message)
{
        if(confirm(Message))
        {
                frmSrc.reset();
        }
}

function sendForm(frmSrc,Message)
{
        passIt = true;
        for(i = 0; i < frmSrc.elements.length; i++)
                if(frmSrc.elements[i].value == "")
                        passIt = false;

        if(!passIt)
        {
                alert(Message);
        }
        else
        {
                frmSrc.submit();
        }
}

function replaceText(fldSrc,Text)
{
        fldSrc.value = replaceString(fldSrc.value, Text, "");
}

function replaceString(sString, sReplaceThis, sWithThis)
{
        if (sReplaceThis != "" && sReplaceThis != sWithThis)
        {
                var counter = 0;
                var start = 0;
                var before = "";
                var after = "";

                while (counter<sString.length)
                {
                        start = sString.indexOf(sReplaceThis, counter);

                        if (start == -1)
                        {
                                break;
                        }
                        else
                        {
                                before = sString.substr(0, start);
                                after = sString.substr(start + sReplaceThis.length, sString.length);
                                sString = before + sWithThis + after;
                                counter = before.length + sWithThis.length;
                        }
                }
        }

        return sString;
}

function showBigImage(File)
{
        myWin= open("", "displayWindow", "width=100,height=100,status=yes,toolbar=0,menubar=0,location=0,scrollbars=0");

         myWin.document.open();

         myWin.document.write("<html><head><title>Просмотр изображения");
         myWin.document.write("</title></head><body style='margin:0;'>");
         myWin.document.write("<img src='/images/upload/" + File + "' onload='self.resizeTo(this.width,this.height+50);focus();'>");
         myWin.document.write("</body></html>");
         myWin.document.close();
}


function showMap()
{
        myWin= window.open("/map.php", "displayWindow", "width=700,height=680,status=yes,toolbar=0,menubar=0,location=0,scrollbars=0");
}

function printBigImage(File)
{
        myWin= open("", "displayWindow", "width=100,height=100,status=yes,toolbar=0,menubar=0,location=0,scrollbars=0");

         myWin.document.open();

         myWin.document.write("<html><head><title>Просмотр изображения");
         myWin.document.write("</title></head><body style='margin:0;'>");
         myWin.document.write("<img src='/images/upload/" + File + "' onload='self.resizeTo(this.width,this.height+50);focus();'>");
         myWin.document.write("</body></html>");
         myWin.document.close();
		 myWin.print();
		 myWin.close();
}

$(function()
{
	$("img[align='left']").attr("align", "").addClass("fleft");
	$("img[align='right']").attr("align", "").addClass("fright");
	$("p:has(img.fleft)").addClass("hasImg");
	
	$(".text .op").map(function(){
		$(this).wrap($("<a />").attr({
			"target": "_blank",
			"href": $(this).attr("src")
		}));
	});

/*	$(".text img").mouseover(function(){
		$(this).wrap($("<div class='wrapImg' />").css({
			position: "relative"
		}));
		var bigImg = $("<img class='doubleImg' />");
		bigImg.attr("src", $(this).attr("src")).css({
			top: 0,
			left: 0,
			margin: "0 !important",
			border: "2px outset #878787",
			position: "absolute"
		});
		$(this).after(bigImg);
		var t = this;
		$(bigImg).mouseout(function(){
			$(t).unwrap();
			$(this).remove();
		});
		delete bigImg, t;
	})/*.map(function(){
		var newImg = $("<img />")
			.attr({
				"src": $(this).attr("src"),
				"class": $(this).attr("class")
			})
			.width($(this).width())
			.height($(this).height())
		;
		for(i in this.style){
			if(/^[0-9]+$/.test(i) && this.style[i] != "width" && this.style[i] != "height"){
				newImg.css(this.style[i], this.style[this.style[i]]);
			}
		}
		$(this).after(newImg);
		$(this).remove();
	})*/;
}
);

