﻿var xax = null;
var bna = false;
var idf = 1;
var aay = new Array(itp + 2);
var bss = false;
var blo = true;
var bhf = false;
var xao = null;
var asc = new Array();
var inp = 1;
var iad = 0;
var iat = 0;
var iady = 0;
var iaty = 0;
var pat = "none";
var axd = new Array();
var iop  = 4;
var icx1b = 0;
var icx2b = 0;
var ifs = ipw / 10;
var btm = false;
var ifn=0;

var tustakim=256;


var icx1 = ipw;
var icx2 = 0;



var bIkon = false;

var mFold;
var capturedpage;

var _Ntimer;
var nCount = 0;
var totCount = 0;

var mMh = 5;
var bBuyutec = false;
var notes;
var _insCol = new Array();
var _insID = 0;
var _inErase = null;
var _inbErase = false;
var _inStk = null;
var _inbSave = false;
var _inStoke = null;

var _nFDrag = false;

var _pCount = 0;
var _pSayfaYeri = 0;
var _pBoy = 0;
var _pEklenen = 0;
var _ptR;

var _zbZoomed = false;
var _zmZoomDeger;
var _zmVP;
var _zmHP;
var _zbCP;
var _zbMM;
var _zbDM = false;

function onHC(sender) {
    SetCursor("1");
    mMh = 0;
}
function offHC(sender) 
{
    if (bna) {
        SetCursor(_inbErase ? "3" : "2");
        mMh = 0;}
    else {
        SetCursor(_zbZoomed ? "5" : "4");
        mMh = 8;
    }
}
function SetPageTurn(control, userContext, rootElement) {
    ppc = control;
    pcc = control.content;
    xmc = pcc.findName("MainCanvas");
    xcr = pcc.FindName("cursor");
    xep = pcc.findName("evenPageCanvas");
    xop = pcc.findName("oddPageCanvas");
    xpb = pcc.findName("pageBrowser");
    xse = pcc.findName("shadowOnEvenPage");
    dda = pcc.createFromXaml("<DrawingAttributes Color='Black' Width='3' Height='3'/>");

    xmb = pcc.findName("MenuBar");
    xpc = rootElement.findName("PageCanvas");
    
    SetNavigationManager();
    SetMenuBar();
    onResized(0);
    pcc.onFullScreenChange = onResized;
    var lm = window.location.href;
var idf = 1213;

    if (lm.indexOf('P=') > 0)
        idf = lm.substring(lm.indexOf('P=') + 2);
    jumpToPage(idf  - 2);
    onResized(0);
    for (var i = 0; i < aay.length; i++)
        aay[i] = false;    
    AyracBas(pcc);
}
function $ogf(sender, eventArgs) {
    gT2.focus();
    gT1.focus();
    var l1 = gT1.value;
    gT1.value = "";
    gT1.value = l1;
}

function onResized(sender) {
    var liw;
    var lih;
    if (window.innerWidth) {
        liw = window.innerWidth - 60;
    } else
        liw = ppc.clientWidth - 60;
    if (window.innerHeight) {
        lih = window.innerHeight - 72;
        document.getElementById("SilverlightControlHost").style.height = window.innerHeight + "px";
    }
    else
        lih = ppc.clientHeight - 72;
    if (pcc.FullScreen)
    {
        liw = pcc.ActualWidth - 60;
        lih = pcc.ActualHeight - 72;     
    }
    _ponResize(liw + 60, lih + 10);

    xmc.Width = liw + 60;
    xmc.Height = lih + 72;

    if (!bss) {
        bss = true;

        var lsgk = pcc.findName("SagKenar");
        var lslk = pcc.findName("SolKenar");
        xcr["Canvas.Left"] = ipw;
        xpc.width = ipw * 2; //*dOran;
        xpc.height = iph;
        xse["Canvas.Left"] = xep["Canvas.Left"] = xse.width = xop.width = xep.width = ipw;
        pcc.findName("SagKenarImage").Height = pcc.findName("SolKenarImage").Height = xse.height = xop.height = xep.height = iph;

        lslk["Canvas.Left"] = -15;
        lsgk["Canvas.Left"] = (ipw * 2) - 5;
    } else {
        var lsgt = pcc.findName("B32");
        var lslt = pcc.findName("B31");
        var izo = 1;
        lsgt["Canvas.Top"] = lslt["Canvas.Top"] = (lih - 32) / 2
        lsgt["Canvas.Left"] = liw + 19;
        if ((liw / (ipw * 2)) < lih / iph)
            izo = liw / (ipw * 2);
        else
            izo = lih / iph;
        xCenter = ((liw / 2) - (ipw * 2) / 2) + 30;
        yCenter = ((lih / 2) - (iph / 2)) + 5;
        _zFmakezoom(izo, xCenter, yCenter, true);
        
        if (xax) {
            if (xax.name == "_x7") {
                xax["Canvas.Left"] = ppc.clientWidth - 220;
                xax["Canvas.Top"] = ppc.clientHeight - 80;
                if (pcc.FullScreen) {
                    pcc.findName("_x7_back").visibility = "collapsed";
                }
            }
            else {
                xax["Canvas.Left"] = ((liw + 60) - xax.Width) / 2;
                xax["Canvas.Top"] = ((lih + 72) - xax.Height) / 2;
            }
        }      
    }
}

function bookmarksite(title,url){
    if (document.all)
        window.external.AddFavorite(url,title);
    else if (window.sidebar)
        window.sidebar.addPanel(title,url,"")
}
function IncDecZoom(ty) {
    if (ty) {
        var ior = ppc.clientWidth / ipw;
        if (inp - 1 != itp) {
            _zFmakezoom(ior, -587, 411, true);
            _zFloadbig(ior, 2, 0);
            SetCursor("5");
        }
        else {
            _zFmakezoom(ior, 800, 411, true);
            _zFloadbig(ior, 1, 0);
            SetCursor("5");
        }
        _zbZoomed = true;
    }
    else {
        onResized("MainCanvas");
        SetCursor("4");
        _zbZoomed = false;
    }
}
function ButtonAction(sender) {
    switch (sender.name) {
        case "B3":
            CreateXAML("_x8");
            break;
        case "B4":
            bna = _inbErase = !_inbErase;
            OpenNote(); 
            break;
        case "B5":
            if (!_inbErase)
                bna = !bna;
            _inbErase = false;
            OpenNote(); 
            break;
        case "B6":
            if (blo) notEkle(sender);
            else CreateXAML("_x2");
            break;
        case "B9":
            putBookmark(sender);
            break;
        case "B12":
            AddSearch(sender);
            break;
        case "B14":
            jumpToPage(-1);
            break;
        case "B15":
            var lmp = window.location.href.lastIndexOf("/");
            lmp = window.location.href.lastIndexOf("/", lmp - 1);
            var lm = window.location.href.substring(0, lmp + 1);
            location.replace(lm); 
            break;
        case "B18":
            var lu = location.href + "?P=" + inp;
            var lt = document.title + " Page " + (inp == 1 ? 1 : (inp - 1));
            if (window.sidebar) { // Mozilla Firefox Bookmark
                window.sidebar.addPanel(lt, lu, "");
            }
            else if (window.external) 
            {
                var le = document.createElement('a');
                le.setAttribute('href', lu);
                le.setAttribute('title', lt);
                le.setAttribute('rel', 'sidebar');
                le.onclick = function() {
                    window.external.AddFavorite(le.href, le.title);
                    return false;
                }
                document.body.appendChild(le);
                le.click();
            }
            else if (window.opera && window.print) { // Opera Hotlist                
                var le = document.createElement('a');
                le.setAttribute('href', lu);
                le.setAttribute('title', lt);
                le.setAttribute('rel', 'sidebar');
                le.click();
                return false;
            }
            else {
                alert('Sitemizi Favorilerinize eklemek için ' + ((navigator.userAgent.toLowerCase().indexOf('mac') != -1) ? 'Command/Cmd' : 'CTRL') + ' + D ye basınız.');
            }
            SendLog(4, inp);
            break;
        case "B21":
            if (blo) CreateXAML("_x6"); else CreateXAML("_x2"); 
            break;
        case "B22":      
        case "B23":
        case "B24":
            var llp = inp - 2;
            var lrp = inp - 1;
            if (inp == 1) llp = lrp = 0;
            
            if (sender.name == "B22") {
                mP = llp;
                SendLog(7, (llp + 1));
            }
            else if (sender.name == "B23") {
            mP = lrp;
                SendLog(7, (lrp + 1));
            }
            else {
                mP = (inp == 1) ? lrp : llp + "-" + lrp;
                SendLog(7, (llp + 1));
                SendLog(7, (lrp + 1));
            }
            window.open("pr.aspx?" + mP);
            break;
        case "B27":
            pcc.FullScreen = !pcc.FullScreen;
            if (pcc.findName("_x7_back") != null) {
                pcc.findName("_x7_back").visibility = "collapsed";
            } 
            break;
        case "B29":
            jumpToPage(-1);
            var lxh= new XMLHttpRequest();
            lxh.open("POST", "lo.aspx", true);
            lxh.send(null);
            lxh = null;

            blo = false;
            for (var i = 1; i < totCount + 1; i++) {
                if (pcc.FindName("_x9" + i) != null)
                    xCc(pcc.FindName("_x9" + i));
            }

            if (_insCol != null) {
                for (var i = 0; i < _insCol.length; i++) {

                    var lin = pcc.FindName("page" + i + "ip");
                    if (lin) lin.strokes.clear();
                }
            }
            _insCol = new Array();
            alert("Sistemden başarıyla çıkış yaptınız");
            break;
        case "B30":

            CreateXAML("_x0");
            break;
        case "B32":
            ifn = 1;
            _NbeginPageAnimation("finishTurn"); 
            break;
        case "B31":
            if (pat == "none") {
                mFold = 1;
                icx1 = ipw - ifs;
                icx1 = ifs;
                if (inp < itp)
                    _NbeginPageAnimation("hideFold");
                else
                    onAnimationComplete("hideFold");
            } 
            break;
        case "B33":
            CreateXAML("_x0");
            break;
    }
}
function OpenNote() {
    if (bna) {
        _NbeginPageAnimation("gizleB");
    } else {
        _NbeginPageAnimation("gizleA");
        SendLog(5, inp);
    }
    offHC();
}
function addOddPages(i, j) {
    var los = "<Canvas x:Name='page" + i + "' Canvas.ZIndex='" + j + "' xmlns='http://schemas.microsoft.com/client/2007' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Background='#FFFFFFFF' Width='" + ipw + "' Height='" + iph + "'>";
    los = los + "<Canvas.RenderTransform>";
    los = los + "<TransformGroup>";
    los = los + "<RotateTransform x:Name='page" + i + "Rotate' CenterX='0' CenterY='" + iph + "' Angle='0'/>";
    los = los + "<TranslateTransform x:Name='page" + i + "Translate' X='0' Y='0'/>";
    los = los + "</TransformGroup>";
    los = los + "</Canvas.RenderTransform>";
    los = los + "<Canvas.Clip>";
    los = los + "<PathGeometry>";
    los = los + "<PathFigure>";
    los = los + "<LineSegment x:Name='page" + i + "Size' Point='0, " + iph + "'/>";
    los = los + "<LineSegment x:Name='page" + i + "Point1' Point='0, " + iph + "'/>";
    los = los + "<LineSegment x:Name='page" + i + "Point2' Point='0, " + iph + "'/>";
    los = los + "<LineSegment x:Name='page" + i + "Point3' Point='0, " + iph + "'/>";
    los = los + "<LineSegment x:Name='page" + i + "Point4' Point='0, " + iph + "'/>";
    los = los + "</PathFigure>";
    los = los + "</PathGeometry>";
    los = los + "</Canvas.Clip>";
    los = los + "<Canvas x:Name='mc" + i + "' Canvas.ZIndex='99' Width='" + (ipw / 10) + "' Height='" + (ipw / 10) + "' Background='#00000000' Canvas.Top='" + (iph - (ipw / 10)) + "'/>"
    los = los + "<Canvas Canvas.Left='" + (ipw - 235) / 2 + "' Canvas.Top='" + (iph - 24) / 2 + "' Canvas.ZIndex='1'>";
    los = los + "<Canvas.Resources>";
    los = los + "<Storyboard x:Name='ProgStory" + i + "' RepeatBehavior='Forever'>";
    los = los + "<DoubleAnimationUsingKeyFrames BeginTime='00:00:00' Storyboard.TargetName='rectangle" + i + "' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)'>";
    los = los + "<SplineDoubleKeyFrame KeyTime='00:00:00' Value='0'/>";
    los = los + "<SplineDoubleKeyFrame KeyTime='00:00:01.5000000' Value='270'/>";
    los = los + "</DoubleAnimationUsingKeyFrames>";
    los = los + "</Storyboard>";
    los = los + "</Canvas.Resources>";
    los = los + "<Rectangle Width='235' Height='24' Stroke='#FF000000' RadiusX='3' RadiusY='6'>";
    los = los + "<Rectangle.Fill>";
    los = los + "<LinearGradientBrush EndPoint='0.5,1' StartPoint='0.5,0'>";
    los = los + "<GradientStop Color='#FFD6FDD3' Offset='0'/>";
    los = los + "<GradientStop Color='#FF1DFD0D' Offset='1'/>";
    los = los + "</LinearGradientBrush>";
    los = los + "</Rectangle.Fill>";
    los = los + "</Rectangle>";
    los = los + "<Rectangle x:Name='rectangle" + i + "' Width='35' Height='21' Stroke='#FF000000' StrokeThickness='0' RadiusX='4' RadiusY='16' Canvas.Top='2' RenderTransformOrigin='0.5,0.5' Canvas.Left='-38'>";
    los = los + "<Rectangle.RenderTransform>";
    los = los + "<TransformGroup>";
    los = los + "<ScaleTransform ScaleX='1' ScaleY='1'/>";
    los = los + "<SkewTransform AngleX='0' AngleY='0'/>";
    los = los + "<RotateTransform Angle='0'/>";
    los = los + "<TranslateTransform X='0' Y='0'/>";
    los = los + "</TransformGroup>";
    los = los + "</Rectangle.RenderTransform>";
    los = los + "<Rectangle.Fill>";
    los = los + "<LinearGradientBrush SpreadMethod='Pad' EndPoint='2.229,0.542' StartPoint='-1.143,0.542'>";
    los = los + "<GradientStop Color='#33FFFFFF' Offset='0'/>";
    los = los + "<GradientStop Color='#99FDFDFD' Offset='0.5'/>";
    los = los + "<GradientStop Color='#33FDFDFD' Offset='1'/>";
    los = los + "</LinearGradientBrush>";
    los = los + "</Rectangle.Fill>";
    los = los + "</Rectangle>";
    los = los + "</Canvas>";
    los = los + "<Canvas Canvas.ZIndex='2'>";
    los = los + "<Image x:Name='Page" + i + "Image' Height='" + iph + "' Width='" + ipw + "' Stretch='Fill' Canvas.ZIndex='1'/>";
    for (var ia = 0; ia < 9; ia++) {
        var ya = Math.floor(ia / 3);
        los = los + "<Image x:Name='Page" + i + "m" + ia + "' Height='" + iph / 3 + "' Width='" + ipw / 3 + "' Canvas.Left='" + (ia - (ya * 3)) * (ipw / 3) + "' Canvas.Top='" + ya * (iph / 3) + "' Stretch='Fill' Canvas.ZIndex='" + (ia + 2) + "'/>";
    }
    los = los + "<Canvas x:Name='Page" + i + "Canvas' Canvas.ZIndex='11'>"
    los = los + "</Canvas>";
    los = los + "</Canvas>";
    los = los + "<InkPresenter x:Name='page" + i + "ip' Width='" + ipw + "' Height='" + iph + "' Canvas.Left='0' Canvas.Top='3' Canvas.ZIndex='3'/>";
    los = los + "<Rectangle Height='1000' Width='20' Opacity='0.6' x:Name='page" + i + "FoldShadow' Canvas.ZIndex='4'>";
    los = los + "<Rectangle.RenderTransform>";
    los = los + "<TransformGroup>";
    los = los + "<RotateTransform x:Name='page" + i + "FoldShadowRotate' CenterX='0' CenterY='0' Angle='0'/>";
    los = los + "<TranslateTransform x:Name='page" + i + "FoldShadowTranslate' X='0' Y='0'/>";
    los = los + "</TransformGroup>";
    los = los + "</Rectangle.RenderTransform>";
    los = los + "<Rectangle.Fill>";
    los = los + "<LinearGradientBrush StartPoint='0,0' EndPoint='1,0'>";
    los = los + "<GradientStop Color='#00000000' Offset='0'/>";
    los = los + "<GradientStop Color='#FF000000' Offset='1'/>";
    los = los + "</LinearGradientBrush>";
    los = los + "</Rectangle.Fill>";
    los = los + "</Rectangle>";
    los = los + "</Canvas>";

    var lnop = pcc.createFromXaml(los);
    var lmC = lnop.FindName("mc" + i);
    lmC.addEventListener("mouseLeftButtonDown", oddPageMouseDown);
    lmC.addEventListener("mouseLeftButtonUp", oddPageMouseUp);
    lmC.addEventListener("mouseMove", oddPageMouseMove);
    lmC.addEventListener("mouseLeave", oddPageMouseLeave);
    lmC.addEventListener("mouseEnter", oddPageMouseEnter);

    pcc.findName("oddPageCanvas").children.add(lnop);
    lnop.findName("ProgStory" + i).begin();
}
function addEvenPages(i, j)
{
    var les = "<Canvas x:Name='page" + i + "' Canvas.ZIndex='" + j + "' xmlns='http://schemas.microsoft.com/client/2007' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Background='#FFFFFFFF' Width='" + ipw + "' Height='" + iph + "'>";
    les = les + "  <Canvas.Clip>";
    les = les + "    <PathGeometry>";
    les = les + "      <PathFigure>";
    les = les + "        <LineSegment Point='0,0'/>";
    les = les + "        <LineSegment x:Name='page" + i + "Size' Point='0, " + iph + "'/>";
    les = les + "        <LineSegment x:Name='page" + i + "Point1' Point='" + ipw + ", " + iph + "'/>";
    les = les + "        <LineSegment x:Name='page" + i + "Point2' Point='" + ipw + ", " + iph + "'/>";
    les = les + "        <LineSegment x:Name='page" + i + "Point3' Point='" + ipw + ", 0'/>";
    les = les + "        <LineSegment Point='0,0'/>";
    les = les + "      </PathFigure>";
    les = les + "    </PathGeometry>";
    les = les + "  </Canvas.Clip>";
    les = les + "  <Canvas Canvas.Left='" + (ipw - 235) / 2 + "' Canvas.Top='" + (iph - 24) / 2 + "' Canvas.ZIndex='1'>";
	les = les + "  	<Canvas.Resources>";
	les = les + "  		<Storyboard x:Name='ProgStory" + i  + "' RepeatBehavior='Forever'>";
	les = les + "  			<DoubleAnimationUsingKeyFrames BeginTime='00:00:00' Storyboard.TargetName='rectangle" + i  + "' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)'>";
	les = les + "  				<SplineDoubleKeyFrame KeyTime='00:00:00' Value='0'/>";
	les = les + "  				<SplineDoubleKeyFrame KeyTime='00:00:01.5000000' Value='270'/>";
	les = les + "  			</DoubleAnimationUsingKeyFrames>";
	les = les + "  		</Storyboard>";
	les = les + "  	</Canvas.Resources>";
	les = les + "  		<Rectangle Width='235' Height='24' Stroke='#FF000000' RadiusX='3' RadiusY='6'>";
	les = les + "  		<Rectangle.Fill>";
	les = les + "  			<LinearGradientBrush EndPoint='0.5,1' StartPoint='0.5,0'>";
	les = les + "  				<GradientStop Color='#FFD6FDD3' Offset='0'/>";
	les = les + "  				<GradientStop Color='#FF1DFD0D' Offset='1'/>";
	les = les + "  			</LinearGradientBrush>";
	les = les + "  		</Rectangle.Fill>";
	les = les + "  	</Rectangle>";
	les = les + "  	<Rectangle x:Name='rectangle" + i  + "' Width='35' Height='21' Stroke='#FF000000' StrokeThickness='0' RadiusX='4' RadiusY='16' Canvas.Top='2' RenderTransformOrigin='0.5,0.5' Canvas.Left='-38'>";
	les = les + "  		<Rectangle.RenderTransform>";
	les = les + "  	        <TransformGroup>";
	les = les + "  	            <ScaleTransform ScaleX='1' ScaleY='1'/>";
	les = les + "  	            <SkewTransform AngleX='0' AngleY='0'/>";
	les = les + "  	            <RotateTransform Angle='0'/>";
	les = les + "  	            <TranslateTransform X='0' Y='0'/>";
	les = les + "  	        </TransformGroup>";
	les = les + "  	    </Rectangle.RenderTransform>";
	les = les + "  		<Rectangle.Fill>";
	les = les + "  			<LinearGradientBrush SpreadMethod='Pad' EndPoint='2.229,0.542' StartPoint='-1.143,0.542'>";
	les = les + "  				<GradientStop Color='#33FFFFFF' Offset='0'/>";
	les = les + "  				<GradientStop Color='#99FDFDFD' Offset='0.5'/>";
	les = les + "  				<GradientStop Color='#33FDFDFD' Offset='1'/>";
	les = les + "  			</LinearGradientBrush>";
	les = les + "  		</Rectangle.Fill>";
	les = les + "  	</Rectangle>";
	les = les + "  </Canvas>";    
    les = les + "<Canvas Canvas.ZIndex='2'>";
    les = les + "<Image x:Name='Page" + i + "Image' Height='" + iph + "' Width='" + ipw + "' Stretch='Fill' Canvas.ZIndex='1'/>";
    for (var ia = 0; ia < 9; ia++) {
        var ya = Math.floor(ia / 3);
        les = les + "<Image x:Name='Page" + i + "m" + ia + "' Height='" + iph / 3 + "' Width='" + ipw / 3 + "' Canvas.Left='" + (ia - (ya * 3)) * (ipw / 3) + "' Canvas.Top='" + ya * (iph / 3) + "' Stretch='Fill' Canvas.ZIndex='" + (ia + 2) + "'/>";
    }
    les = les + "<Canvas x:Name='Page" + i + "Canvas' Canvas.ZIndex='11'>"
	les = les + "</Canvas>";
	les = les + "</Canvas>";
	if (i > 0)
	{
	    les += "  <Rectangle x:Name='page" + i  + "Shadow' Height='" + iph + "' Width='30' Opacity='0.2' Canvas.ZIndex='5'>";
        les +=    "    <Rectangle.Fill>";
        les +=    "      <LinearGradientBrush StartPoint='0,0' EndPoint='1,0'>";
        les +=    "        <GradientStop Color='#BBFFFFFF' Offset='0'/>";
        les +=    "        <GradientStop Color='#00FFFFFF' Offset='1'/>";
        les +=    "      </LinearGradientBrush>";
        les +=    "    </Rectangle.Fill>";
        les +=    "  </Rectangle>";
	}
	les = les + "  <InkPresenter x:Name='page" + i + "ip' Width='" + ipw + "' Height='" + iph + "' Canvas.ZIndex='4'/>";
    les = les + "</Canvas>";
       
    var lnep = pcc.createFromXaml(les);
    xep.children.add(lnep);
    pcc.findName("ProgStory"+ i).begin();
}
function SendLog(lt1, ld1) {

    var lxh = new XMLHttpRequest();
    lxh.open("POST", "sd.aspx?tp=" + lt1 + "&dt=" + ld1, true);
    lxh.send(null);
    lxh = null;
}
function SetCursor (lmc) {
    xcr.source = "m/_C" + lmc + ".png";
    xcr.tag = lmc;
}
function sOf(e) {
    for (var a = 0; a < asc.length; a++) {
        if (asc[a].bf && asc[a] != e)
            asc[a].lostfocus();
    }
    bhf = true;
    xao = e;
}

function sCP(e) {
    gT1.focus();
    if (typeof (gT1.selectionStart) == 'number') {
        var lst = gT1.selectionStart;
        var len = gT1.selectionEnd;
        gT1.value = gT1.value.substr(0, lst + e)
        + "~" + gT1.value.substr(len + e, gT1.value.length);
        gT1.value = gT1.value.replace("\r\n", "¨");
        gT1.value = gT1.value.replace("|", "");
        gT1.value = gT1.value.replace("~", "|");
        var lPos = gT1.value.indexOf("|");
        gT1.setSelectionRange(lPos, lPos);
    } else if (document.selection) {
        var lsa = document.selection.createRange();
        lsa.move("character", e);
        lsa.text = "~";
        if (gT1.value.indexOf("~") == -1) {
            sa = document.selection.createRange();
            sa.move("character", -1);
            sa.text = "~";
        }
        gT1.value = gT1.value.replace("\r\n", "¨");
        gT1.value = gT1.value.replace("|", "");
        gT1.value = gT1.value.replace("~", "|");
        lsa.collapse(true);
        lsa.moveStart("character", gT1.value.indexOf("|"));
        lsa.select();
    }
}
function fObj(PN, TI) {
    var lfr = null;
    for (var i = 0; i < asc.length; i++) {
        if (asc[i].bf && asc[i].pn == PN) {
            if (asc[i].ti == 0)
                lfr = asc[i];
            else if (asc[i].ti == TI + 1) {
                lfr = asc[i];
                break;
            }
        }
    }
    return lfr;
}

function kdown(e) {
    if (xao) {
        var e_ = e || window.event;
        var kC = e_.keyCode > 0 ? e_.keyCode : e_.charCode
        if (kC == 9) // TAB
        {
            var bV = false;
            var mi = -1;
            var mObjA = fObj(xao.pn, xao.ti);
            if ((xao.pn % 2) == 1)
                var mObjB = fObj(xao.pn + 1, -1);
            else
                var mObjB = fObj(xao.pn - 1, -1);
            if (mObjA) {
                if (mObjA.ti == 0 && mObjB)
                    mObjA = mObjB;
                mObjA.setfocus();
            }
            return false;
        }
        else if (kC == 27) // ESC
            CheckClose();
        else
            actKey(kC);
    }
    else actKey(window.event.keyCode);
}

function kup(e) {
    if (xao) {
        var e_ = e || window.event;
        var kC = e_.keyCode > 0 ? e_.keyCode : e_.charCode;
        sCP(kC == 39 ? 1 : 0);
        xao.keydown(kC);
    }
}
var isCtrl = false;
function actKey(e) {
    if (e == 17) { isCtrl = true; return; }
    if (isCtrl == true)
    {
        switch (e) {
            case 83: //ctrl s
                ButtonAction(pcc.FindName("B21"));
                break;
            case 71: //ctrl g
                ButtonAction(pcc.FindName("B12"));
                break;
            case 80: //ctrl p
                ButtonAction(pcc.FindName("B24"));
                break;
            case 88: //ctrl x
                ButtonAction(pcc.FindName("B29"));
                break;
            case 68: //ctrl d
                ButtonAction(pcc.FindName("B18"));
                break;
            case 49: //ctrl 1 yardım
                CreateXAML("_x0");
                break;
            default:
                return false;
                break;
        }
        isCtrl = false;
        return false;
    }
    switch (e) {
        case 33:
            jumpToPage((inp < itp) ? inp : ((itp % 2 == 0) ? itp - 1 : itp));
            break;
        case 34:
            jumpToPage((inp - 4 > -2) ? inp - 4 : -1);
            break;
        case 36:
            jumpToPage(-1);
            break;
        case 35:
            jumpToPage((itp % 2 == 0) ? itp - 1 : itp);
            break;
        case 107:
            IncDecZoom(1);
            break;
        case 109:
            IncDecZoom(0);
            break;
        case 37:
            if (!bhf) leftRightArrow(120);
            break;
        case 39:
            if (!bhf) leftRightArrow(-120);
            break;
        case 38:
           upDownArrow(120);
            break;
        case 40:
           upDownArrow(-120);
            break;
    }   
}
function upDownArrow(val) {
    SetCursor("6");
    xpc.RenderTransform.children.GetItem(1).y = xpc.RenderTransform.children.GetItem(1).y + val;
    SetCursor("4");
}
function leftRightArrow(val) {
    SetCursor("6");
    xpc.RenderTransform.children.GetItem(1).x = xpc.RenderTransform.children.GetItem(1).x + val;
    SetCursor("4");
}
function CreateXAML(file) {
    //if (_zbZoomed) {_zbZoomed = !_zbZoomed; onResized("MainCanvas"); }
    if (pcc.FullScreen) pcc.FullScreen = false;
    
    if (pcc.FindName(file) != null) {
        xCc(pcc.FindName(file));
        xax = null;
    }
    if (pcc.FindName(file) == null) {
        var mDown = new XMLHttpRequest();
        mDown.open("GET", "m/" + file + ".jpg", false);
        mDown.send(null);
    }
    if (mDown.readyState == 4 && mDown.status == 200) {
        if (xax && (xax.Name.substr(0, 3) != "_x9" && xax.Name != "_x7")) {
            if (pcc.FindName(xax.Name + "_close") != null) pcc.FindName(xax.Name + "_close").begin();
            xax = null;
        }
        var resText;
        if (file == "_x9") {
          
            file = "_x9" + nCount;
            resText = mDown.responseText.replace(/_x9%d/g, "_x9" + nCount);
            
        }
        else
        {
            resText = mDown.responseText;
        }
        var XAMLObj = pcc.CreateFromXAML(resText);
        xmc.children.add(XAMLObj);
        var NewObj = XAMLObj.FindName(file);
        var f = (file.substr(2, 1) == "0") ? 20 : file.substr(2, 1);
        SetPageObject(NewObj, xmc, Number(f) * -1);
       NewObj["Canvas.Left"] = (xmc.Width - NewObj.Width) / 2;
        NewObj["Canvas.Top"] = (xmc.Height - NewObj.Height) / 2;
        
        xax = NewObj;
        if (file == "_x8") {
            var w = xax["Canvas.Left"];
            xax["Canvas.Left"] = -xax.Width;
            xax.findName("double3")["Value"] = w;
        }
        pcc.FindName(file + "_open").begin();
    }
    mDown = null;
}
function xCc(sender) {
     var name = (sender.name.substr(0, 3)=="_x9")?sender.name.substr(0, 4):sender.name.substr(0, 3);
     xmc.children.remove(pcc.findname(name + "_back"));
     xao = null;
 
 }

function GetFormData(bcl, lfn, pn) {
    var mStr = "?";
    for (var i = 0; i < asc.length; i++) {
        var mObj = asc[i];
        if (mObj.fn == lfn && mObj.pn == pn) {
            var mType = mObj.obj.Tag.charAt(0);
            if (mType == "E" || mType == "F") {
                if (!bcl)
                    mStr += mObj.name + "=" + mObj.che + "&"
                else {
                    var prm = mObj.obj.Tag.split("|");
                    mObj.che = !(prm[1] == "0");
                    mObj.select();
                }

            }
            else if (mType == "H") {
                if (!bcl)
                    mStr += mObj.name + "=" + mObj.getstr() + "&"
                else {
                    var prm = mObj.obj.Tag.split("|");
                    mObj.sv = prm[4];
                    mObj.yaz();
                }
            }
        }
    }
    if (lfn == "_x6")
        mStr += "URL=" + location.href + "?P=" + (inp - 2) + "&";
    else if (lfn.substr(0, 3) == "_x9") {
        for (var i = 1; i < totCount + 2; i++) {
            if (lfn == "_x9" + i) {
                var note = pcc.findname("_x9" + i);
                
                var id = pcc.findname("_x9" + i + "id").text;
                var tarih = pcc.findname("_x9" + i + "tarih").text;
                
                mStr += "pnum=" + (inp) + "&" + "l=" + note["Canvas.Left"] + "&t=" + note["Canvas.Top"] + "&id=" + id + "&i=" + i + "&tarih=" + tarih + "&mUser=" + mUser + "&";
            }
        }
    }
    return mStr.substr(0, mStr.length - 1);
}
function CheckClose() {
    if (xax) {
        if (xax.name == "_x2" || xax.name == "_x8" || xax.name == "_x0" || xax.name == "_x6" || xax.name == "_x7") {
         pcc.FindName(xax.Name + "_close").begin();
         if (xax.name == "_x2") {
             if (inp >= ifr)
                 jumpToPage(-1);
         }
        }
    }
  
}
function getCookie(lcn) {
    if (document.cookie.length > 0) {
        var lcs = document.cookie.indexOf(lcn + "=");
        if (lcs != -1) {
            lcs = lcs + lcn.length + 1;
            var lce = document.cookie.indexOf(";", lcs);
            if (lce == -1) lce = document.cookie.length;
            return unescape(document.cookie.substring(lcs, lce));
        }
    }
    return "";
}

function setCookie(lcn, lva, lpd) {
    var led = new Date(); led.setDate(led.getDate() + lpd);
    document.cookie = lcn + "=" + escape(lva) +
    ((lpd == null) ? "" : ";expires=" + led.toGMTString());
}

function notVarmi(number) {
   
    var lxh = new XMLHttpRequest();
    lxh.open("GET", "check.aspx?pn=" + number + "&username=" + mUser, false);
    lxh.send(null);
     var a = lxh.responseText;

            if (a && a != "2") {
                var brr = a.split("#");
                totCount = brr.length - 1;
         
                for (var i = 0; i < totCount; i++) {
                    var arr = brr[i].split("|");
                   
                    
                    nCount = arr[0];
                    CreateXAML("_x9");

                    var back = pcc.findName("_x9" + nCount);

                    back["Canvas.Left"] = arr[3];
                    back["Canvas.Top"] = arr[4];
                    
                    pcc.findName("tb_x9" + nCount + "_6").Text = arr[2];

                    pcc.findName("_x9" + nCount + "tarih").Text = arr[5];
                    pcc.findName("_x9" + nCount + "id").Text = arr[1];
                    
                }
            }
            lxh = null;
      

   
}
function Git(type) {
    pcc.findname("_sgit").visibility = "collapsed";
     var s=0;
     switch (type){
         case 5: //kutuya yazılan
             var text = pcc.findname("tb_x7_1").text;
             no = (text.substr(text.length - 1, text.length) == "|" ? text.substr(0, text.length - 1) : text);
             if (no != "") {
                 var n = 2 * parseInt(no) + 1;
                 if (n > itp) n = itp - 1;
                 s = (n % 2 == 0) ? n - 1:n;
             }
             break;
         case 2: // 1 sayfa geri
            s = (inp < itp) ? inp : ((itp % 2 == 0) ? itp - 1 : itp);
            s = itp - s-2;
             break;
        case 1: // 1 sayfa ileri
            s = (inp - 4 > -2) ? inp - 4 : -1;
            s = itp  -s - 2;
            break;
        case 3:
  	    s =-1;
           
            break;
        case 4:
          s = (itp % 2 == 0) ? itp - 1 : itp;
            break;
     }
     if (s != 0)
         jumpToPage(itp-s-2);
	     
     pcc.findname("tb_x7_1").text = (s == -1 || s == "")? "" : (Math.floor(s/2)).toString();
}


function putBookmark(sender)
{
  var lsn= inp;
  if (aay[lsn] != false)
  {
      var k = sender.findname("a"+lsn);
      if (k != null) xpc.children.remove(k);
      aay[lsn] = false;
     
     var name="lsn"+lsn;
     document.cookie = name +'=; expires=Thu, 01-Jan-70 00:00:01 GMT;'; 
      
      for (var i=1; i<itp+2; i++)
          {
         
            if(sender.findName("a"+i)!=null)
            {  
            if (sender.findName("a"+i)["Canvas.Top"]> k["Canvas.Top"])
            sender.findName("a"+i)["Canvas.Top"]=sender.findName("a"+i)["Canvas.Top"]-23;
            }
            
          }     
      
  }
  else  
  {
        aay[lsn] = true;
         var ct = 0;
         if (inp-1 == itp)
         {
          ct = pcc.findName("SolKenar")["Canvas.Left"];
          deger = -30;
         }
         else 
         {
          ct = pcc.findName("SagKenar")["Canvas.Left"];
          deger = 7; 
         }
          
          
         var top = 0;
          
         for (var i=1; i<itp+2; i++)
         {
            if(sender.findName("a"+i)!=null)sender.findName("a"+i)["Canvas.Left"]=ct+deger;
         }
             
          
         for (var i=1; i<itp+2; i++)
         {
            if(sender.findName("a"+i)!=null)
            {
            if (top < sender.findName("a"+i)["Canvas.Top"])
                 top=sender.findName("a"+i)["Canvas.Top"];
            }
          }
          
          var cLeft = ct;
          var cTop =top+23;
          //var sn =(lsn!=1)?(lsn-2)+"-"+(lsn-1):"Kapak";
          var sn = (lsn != itp + 1) ? (itp - lsn) : "Kapak";
          
          var ay = pcc.createFromXaml('<Canvas x:Name="a' + lsn + '" Canvas.Left="' + cLeft + '" Canvas.Top="' + cTop + '" MouseEnter="onHC" MouseLeave="offHC" MouseLeftButtonDown="goToPage" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Image Source="m/_a.png"/><TextBlock Width="89" Height="25" Text="' + sn + '" TextWrapping="Wrap" Foreground="#FFFFFFFF" FontSize="10" Canvas.Left="5" Canvas.Top="2"/></Canvas>');
          xpc.children.add(ay);
          setCookie('lsn'+lsn,lsn,365);
  }
}


function goToPage(sender,eventArgs)
{
    var ct = pcc.findName("SagKenar")["Canvas.Left"]; 
    var s = sender.name;
    var s = s.substring(1,s.length);
    for (var i=1; i<itp; i++)
        {
        if (i==s) sender["Canvas.Left"]=ct;
        else
        { 
            if(sender.findName("a"+i)!=null)sender.findName("a"+i)["Canvas.Left"]=ct+7;
        }
    }

    jumpToPage(parseInt(s)-2);
}


function AddSearch(sender)
{
    if (pcc.FindName("_x7") != null)
    {
         xCc(pcc.FindName("_x7"));
         xax =null;
    } 
    CreateXAML("_x7"); 
   
    if (pcc.FullScreen)
    {
        xax["Canvas.Left"]= pcc.ActualWidth - 225;
        xax["Canvas.Top"] = pcc.ActualHeight - 85;      
    }
    else {
        xax["Canvas.Left"] = ppc.clientWidth - 220; //pcc.ActualWidth-200;//1470;
        xax["Canvas.Top"] = ppc.clientHeight - 80;      
    }    
} 
function notEkle(sender,eventArgs)
{
    if (totCount<5) {
        ++nCount;
        ++totCount;
        CreateXAML("_x9");
        pcc.findName("tb_x9" + nCount + "_6").Text = "";
        var dates = new Date();
        var tarih = dates.getDate() + "." + (dates.getMonth()+1) + "." + dates.getFullYear() + " " + dates.getHours() + ":" + dates.getMinutes();
        pcc.findName("_x9" + nCount + "tarih").Text = tarih;
    }
    
}

function AyracBas(pcc)
{
    var ltp=0;
    var lcl = pcc.findName("SolKenar")["Canvas.Left"]-30;

    for (var i = itp + 2; i>-1; i--)
    {
        var lsn = getCookie("lsn"+i);
        if (lsn!="")
        {
            var sn = (lsn != itp+1) ? (itp- lsn) : "Kapak";
            var lxy = pcc.createFromXaml('<Canvas x:Name="a' + lsn + '" Canvas.Left="' + lcl + '" Canvas.Top="' + ltp + '" MouseEnter="onHC" MouseLeave="offHC" MouseLeftButtonDown="goToPage" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Image Source="m/_a.png"/><TextBlock Width="89" Height="25" Text="' + sn + '" TextWrapping="Wrap" Foreground="#FFFFFFFF" FontFamily="Verdana" FontSize="10" Canvas.Left="5" Canvas.Top="1"/></Canvas>');
            xpc.children.add(lxy);

            aay[i] = true;
            ltp = ltp + 23;
        }
        else aay[i] = false;
    }
}
function goU(lse) 
{
    var lmi=false;
    var lvl = 400;
    if (lse.name == "_btnUp") 
    {
        if (lse.findName('_canvas')["Canvas.Top"] < 0) 
        {
            lmi = true; 
        } 
    }
    else 
    {
        if (lse.findName('_canvas')["Canvas.Top"] > -ict) 
       {
            lmi = true;
            lvl = -400;
       }
    }
    if (lmi)
    {
        lse.findName("_toWhere").to = lse.findName("_toWhere").to + lvl;
        lse.findName("_goA").Begin();
	}
}
function ClickIt(sender, eventArgs) 
{
    var ltm = sender.name.replace("na", "ta");
    n = parseInt(sender.findName(ltm).text);
    n = itp - (2*n) -2;
    jumpToPage((n % 2 == 0) ? n - 1 : n);
    pcc.FindName(xax.Name + "_close").begin();
    SetCursor(_zbZoomed ? "5" : "4");
}