var page = new PageUrl();
var onProcess = false;


function rsQuery()
{    
    var h = 0;
    var pnl = findElement(frmQuery,'pnlResult');
    var resTable = findElement(frmQuery,'resTable');
    if (frmQuery.self.innerWidth)
	{
		//frameWidth = self.innerWidth;
        h = frmQuery.self.innerWidth;
	}
	else if (frmQuery.document.documentElement && frmQuery.document.documentElement.clientWidth)
	{
		//frameWidth = document.documentElement.clientWidth;
		h = frmQuery.document.documentElement.clientHeight;
	}
	else if (frmQuery.document.body)
	{
		//frameWidth = document.body.clientWidth;
		h = frmQuery.document.documentElement.clientHeight;
	}
    
    if (h>0)
    {
        if (pnl.offsetHeight>=h)
	    {
	        pnl.style.overflowY = "scroll";
	        resTable.style.width="94%";
	    }
	    pnl.style.height = h;
    }
}

function RunMyCommand() 
{ 
    var mapImage = findElement('MapControl1_Image'); 
    if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value; 
    if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value; 

    alert(mapImage.attributes["mapAlias"].value);
/*
    var url = "MapController.ashx?Command="+ cmdName + 
    "&Width=" + mapImage.width + 
    "&Height=" + mapImage.height + 
    "&ExportFormat=" + mapImage.exportFormat + 
    "&Ran=" + Math.random(); 

    mapImage.style.left = 0; 
    mapImage.style.top = 0; 
    mapImage.style.clip = 'rect(' + 0 + ' ' + mapImage.width + ' ' + mapImage.height + ' ' + 0 +')'; 
    mapImage.src = url; 
*/
} 

function divYukleObjOn(yukleGoster)
{
    var divbilgi = findElement(frmMapx, 'divBilgi');
    var div = findElement(frmMapx, 'divMap');
    var divYukleObj = findElement(frmMapx, 'haritayukle')
    
    if (div == null) return;
    
    if (yukleGoster)
    {
        //centerObj2Frame(frmMapx, 'yukleBilgiDiv');
        divYukleObj.style.top = div.style.top;
        divYukleObj.style.left = div.style.left;
        divYukleObj.style.width = div.offsetWidth;
        divYukleObj.style.height = div.offsetHeight;
        divYukleObj.style.visibility = 'visible';
    }
    /*
    divbilgi.style.top = div.offsetHeight-25;
    divbilgi.style.left = div.style.left+10;
    divbilgi.style.visibility = 'hidden';
    */
};

function divYukleObjOff()
{
    var div = findElement(frmMapx, 'divMap');
    var divbilgi = findElement(frmMapx, 'divBilgi');
    var divYukleObj = findElement(frmMapx, 'haritayukle')

    if (div == null) return;

    divYukleObj.style.visibility = 'hidden';
    //divbilgi.style.visibility = 'visible';
    div.style.visibility = 'visible';


};

function frmQuerySwitch()
{
    var col = parent.document.getElementById('fsContents').cols;
    colArray = col.split(",");
    if (colArray[1]==0)
        parent.document.getElementById('fsContents').cols='*,300';
    else
        parent.document.getElementById('fsContents').cols='*,0';

}

function __doPostMapResult(layer, no) {
    var uriek="/searchResult.aspx";
    if (layer!="")
        uriek += "?layer="+layer+"&ref="+no;
    parent.frmResult.document.location.href=page.getKentRehberiVirtualPath()+uriek;
}

function __doPostMap(layer, no) {
    var div = findElement(frmMapx, 'divMap');
    if (div == null) return;
    div.style.visibility = 'hidden';
    var uriek="/mapx.aspx";
    if (layer!="")
        uriek += "?layer="+layer+"&ref="+no;
    
    parent.frmMapx.document.location.href=page.getKentRehberiVirtualPath()+uriek;
}

function __doIcerik(para) {
    //window.top.newWindow('../query/icerikpopup.aspx?layer='+layer+'&id='+id,600,500);
    window.top.newWindow(page.getKentRehberiVirtualPath()+'/query/icerikpopup.aspx?'+para,600,500);
}
                
function fnFrameFormWaitThenSubmit(frameId) {
    window.setTimeout('fnFormSubmit('+frameId+');', 200);
}

function fnFormSubmit(frameId) {
    var obj = frameId.document.getElementById('form1');
    obj.submit();
}

function onLoadPreL(b)
{
    var divMap = findElement(frmMapx, 'haritayukle');    
    //var mapImage = findElement(frmMapx, 'MapControl1_Image');
    
    onProcess=b;

    if (b==true)
    {
        //mapImage.style.visibility = 'hidden';
        divMap.style.visibility = 'visible';
    }
    else
    {
        //mapImage.style.visibility = 'visible';
        divMap.style.visibility = 'hidden';
    }
};
 
function RefreshMap()
{
    if (onProcess)
        return;

    var divMap = findElement(frmMapx, 'haritayukle');    
    var mapImage = findElement(frmMapx, 'MapControl1_Image');
    if (mapImage==null) 
    {
        setTimeout('RefreshMap();',2000);
        return;
    }
    
    divMap.style.visibility = 'visible';
    //onLoadPreL(true);
    //divYukleObjOn(true);
    
    var oldhandler = mapImage.onload;
    mapImage.onload = function (mapImage) {
        this.style.visibility = ""; 
        this.onload = oldhandler; 
        divMap.style.visibility = 'hidden'; 
        onProcess=false;
        };
	        
	//if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
	//if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
                
    //var curPos = parseInt(mapImage.width/2)+"_"+parseInt(mapImage.height/2)+","+parseInt(mapImage.width/2)+"_"+parseInt(mapImage.height/2);
    if (!mapImage.mapAlias) mapImage.mapAlias = 'Map1';//mapImage.attributes["mapAlias"].value;
        if (!mapImage.exportFormat) mapImage.exportFormat = 'Gif';//mapImage.attributes["exportFormat"].value;
        this.url = "MapController.ashx?Command=GetMap" +
        "&Width=" + mapImage.width +
        "&Height=" + mapImage.height +
        "&ExportFormat=" + mapImage.exportFormat +
        "&Ran=" + Math.random();
        //"&Points=2,"  + curPos +

    if (mapImage.mapAlias) this.url += "&MapAlias=" + mapImage.mapAlias;
    
    if (mapImage.width != 0 && mapImage.height != 0)
        mapImage.src = this.url;

    //setTimeout('onLoadPreL(false);',3000);
   
};

function RefreshMap2()
{

    //divYukleObjOn(false);
    var mapImage = findElement(frmMapx, 'MapControl1_Image');
    if (mapImage == null) return;
	if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
	if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;

    var curPos = parseInt(mapImage.width/2)+"_"+parseInt(mapImage.height/2)+","+parseInt(mapImage.width/2)+"_"+parseInt(mapImage.height/2);
    if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
        if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
        this.url = "MapController.ashx?Command=GetMap" +
        "&Width=" + mapImage.width +
        "&Height=" + mapImage.height +
        "&ExportFormat=" + mapImage.exportFormat +
        "&Points=2,"  + curPos +
        "&Ran=" + Math.random();

    if (mapImage.mapAlias) 
        this.url += "&MapAlias=" + mapImage.mapAlias;
    
	// Set the source of the image to url to just change the map
	mapImage.style.left = 0;
	mapImage.style.top = 0;
	try {
	mapImage.src = this.url;
	} catch(e) { alert("ll"); }    
    
//alert(this.url);
    //divYukleObjOff();

};

function RefreshMapStart()
{

    var mapImage = findElement(frmMapx, 'MapControl1_Image');
    if (mapImage == null) return;
    //mapImage.style.visibility = 'hidden';
    
};

function nResize()
{
   setTimeout("RefreshMap();",500);
   //setTimeout("__doPostMapResult('Adornment',0);",2000);
};

function onMouseWhell()
{
    if (top.onProcess)
        return false;
    
    top.onProcess = true;    
    var mapImage = top.findElement(this, 'MapControl1_Image');
    var divMap = top.findElement(this, 'haritayukle');    
    if (mapImage == null) return;
    if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
    if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;

    mapImage.style.visibility = 'hidden';
    divMap.style.visibility = 'visible';
    
    var oldhandler = mapImage.onload;
    mapImage.onload = function (mapImage) {this.style.visibility = ""; this.onload = oldhandler; divMap.style.visibility = 'hidden'; top.onProcess=false;};

    if (!mapImage.mapAlias) mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
        if (!mapImage.exportFormat) mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
        this.url = "MapController.ashx?" +
        "Width=" + mapImage.width +
        "&Height=" + mapImage.height +
        "&ExportFormat=" + mapImage.exportFormat +
        "&Ran=" + Math.random();

    var curPos = window.event.x+"_"+window.event.y+","+window.event.x+"_"+window.event.y;
    if (event.wheelDelta >= 120)
    {
        this.url += "&Command=ZoomIn&Points=2,"+curPos;
    }
    else if (event.wheelDelta <= -120)
    {
        this.url += "&Command=ZoomOut&Points=2,"+curPos;
    } 

    if (mapImage.mapAlias) 
        this.url += "&MapAlias=" + mapImage.mapAlias;
    mapImage.src = this.url;

    return false;
};

function opWindow(id)
{
    //setTimeout("opWindow("+id+")",1400);
    
    oObj = findElement(id);
    oObjW = oObj.offsetWidth;
    oObjH = oObj.offsetHeight;
    //alert(oObjW);
    obj = findElement('Label1')
    //obj.innerText = oObjW;
    
    obj.innerText = parent.frmMapx.document.body.clientWidth;
}

function getObjWidth(id){
        oObj = findElement(id);
        //oObj.clientWidth;
        return oObj.offsetWidth;
}

function pageWidth() {
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() {
    return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function centerObj2Window(id) {
    var pw = pageWidth();
    var ph = pageHeight();
    var oObj = findElement(id);
    var oObjW = oObj.offsetWidth;
    var oObjH = oObj.offsetHeight;
    oObj.style.position = 'Relative';
    oObj.style.left = ((pw - oObjW)/2) + 'px';
    oObj.style.top = ((ph - oObjH)/2) + 'px';
}

function centerObj2Frame(frameId, id) {
    var pw = frameId.frameElement.offsetWidth;
    var ph = frameId.frameElement.offsetHeight;
    var oObj = findElement(frameId, id);
    var oObjW = oObj.offsetWidth;
    var oObjH = oObj.offsetHeight;
    oObj.style.position = 'absolute';
    oObj.style.left = ((pw - oObjW)/2);
    oObj.style.top = ((ph - oObjH)/2);
}

function findElement(id) {
	return document.getElementById(id);
}

function findElement(frameId, id) {
	return frameId.document.getElementById(id);
}

function PageUrl()
{
    var hostName = window.location.host;
    var pathName = window.location.pathname;
   
    this.urlValuePairs = new Array();
    for(var i=0; i < pathName.split("/").length; i++) 
    {
        var par = pathName.split("/")[i];
        if (par!=" ")
            this.urlValuePairs[i] = par;
    }
    
    this.getVirtualPath = function() 
    {
        var newUrl = "";
        for(var j=0; j < this.urlValuePairs.length-1; j++) 
        {
            if (j>0)
                newUrl += "/";
            newUrl += this.urlValuePairs[j];
        }
        return newUrl;
    }

    this.getKentRehberiVirtualPath = function() 
    {
        var newUrl = "http://"+hostName;
        for(var j=0; j < this.urlValuePairs.length; j++) 
        {
            if (j>0)
                newUrl += "/";
            newUrl += this.urlValuePairs[j];
            
            if (this.urlValuePairs[j].toLowerCase()=="kentrehberi")
                break;
        }
        return newUrl;
    }
        
    this.getLength = function() 
    { 
        return this.urlValuePairs.length; 
    } 
}
