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 openInfo(File)
{

var xx=(screen.height/2)-250;
var yy=(screen.width/2)-250;

        myWin= open(File, "displayWindow", "top="+xx+",left="+yy+",width=500,height=500,status=yes,toolbar=0,menubar=0,location=0,scrollbars=0");
}



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();
}

var currentPix = 0;

function setImage(lnkObj,numPix,Uri,file)
{

	for(i = 1;i<=10;i++)
	{
		try
		{
			document.getElementById("lnk"+i).className = 'smallLink';
		}
		catch(e) {}
	}

	document.getElementById("lnk"+numPix).className = 'smallLinkActive';
	currentPix = numPix
	obj = document.getElementById("prevCell");
	obj.style.cursor = 'hand';
	obj.style.background = 'url("/images/upload/' + file + '")';
	obj.onclick = function() { location.href='/projects/' + Uri + '/'; }
}

function setNext()
{
	if(currentPix < 10)
	{
		num = currentPix+1;
		link = document.getElementById("lnk"+num);
		uri = document.getElementById("uri"+num).value;
		file = document.getElementById("file"+num).value;
		setImage(link,num,uri,file);
	}
}

function setPrev()
{
	if(currentPix > 1)
	{
		num = currentPix-1;
		link = document.getElementById("lnk"+num);
		uri = document.getElementById("uri"+num).value;
		file = document.getElementById("file"+num).value;
		setImage(link,num,uri,file);
	}

}
