// JScript File

function PortalStartup(){
  startBlink();
  LoaderFunction();
  ShowMessages();
}

function doBlink() {
  var blink = document.getElementsByTagName("BLINK")
	for (var i=0; i<blink.length; i++)
	  blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  if (document.all)
    setInterval("doBlink()",1000)
}


/* Session timeout ile ilgili işlemler. */

  // request variable
  var request_var;

  // Request object method wrapper function
  function request_object()
  {
	  // Gecko / IE7
	  if ( typeof(XMLHttpRequest) != 'undefined' )
		  return new XMLHttpRequest() ;

	  // IE6
	  try { return new ActiveXObject("Msxml2.XMLHTTP") ; } 
	  catch(e) {}

	  // IE5
	  try { return new ActiveXObject("Microsoft.XMLHTTP") ; }
	  catch(e) {}
  }

  // Call the request object method wrapper function
  request_var=request_object();
  
  if(!request_var)
  {
    alert("Bilgisayarınızdan ajax işlemleri yapılamıyor.");
  }

  function ResponseCompleted()
  {
    if (request_var==undefined) return;
    if (!request_var) return;
    if(request_var.readyState==4)
    {
      var resp=request_var.responseText;
      if (resp.substr(0,6)=='<html>') return;
      try{
        eval(resp);
      }
      catch(e){}
    }
  }
  
  function SessionManagerRedirectPage(NewUrl){
    window.open(NewUrl,"_top");
  }
  
  var SessionManagerTimeoutDislaying=false;
  
  function ShowTimeout(SessionHandlerURL){
    if (SessionManagerTimeoutDislaying) return;
    SessionManagerTimeoutDislaying = true;
    window.open(SessionHandlerURL,"SessionTimerWindow","width=300,height=300, center=yes,scrollbars=no,location=no,status=no,dependent=yes");
  }

  function CheckServerForSession(ReqUrl)
  {
    if(request_var)
    {      
      request_var.open("GET",ReqUrl,true);
      request_var.onreadystatechange=ResponseCompleted;
      request_var.send(null);
    }
  }

  
  function SessionTimer(AshxUrl, CheckState){
    var ReqUrl = AshxUrl + "?CheckState=" + CheckState;
    CheckServerForSession(ReqUrl);    
  }




/*
  History Bar ile ilgili fonksiyonlar
*/
var HistoryBars=new Array();

function RegisterHistoryBar(HistoryBarId){  
  HistoryBars.push(HistoryBarId);
}

function SetHistory(NewHistory){
  for(var i=0;i<HistoryBars.length;i++){
    var HistBar = document.getElementById(HistoryBars[i]);
    if ((HistBar!=undefined)&&(HistBar!=null)) {
      HistBar.innerHTML=NewHistory;
    }
  }
}


/*
  Navigation Bar ile ilgili fonksiyonlar
*/
var NavigationBars=new Array();

function RegisterNavigationBar(NavigationBarId){  
  NavigationBars.push(NavigationBarId);
}

function SetNavigation(NewNavigation){
  for(var i=0;i<NavigationBars.length;i++){
    var NavBar = document.getElementById(NavigationBars[i]);
    if ((NavBar!=undefined)&&(NavBar!=null)) {
      NavBar.innerHTML=NewNavigation;
    }
  }
}


// Mesaj Gösterim, Sayfa Kapatım, ClientSide Yönlendirme vesair işler.

var MessageList=new Array();
var CommandQueue=new Array();


function SetMessage(MessageId, Message, MesajTip){
  MessageList.push(new Array(MessageId, Message, MesajTip));  
}

function ExecCommand(cmd){
  CommandQueue.push(cmd);
}

function ShowMessages(){
  if (MessageList.length>0){
    var msg = MessageList.pop();
    if ((msg[0]!='')&&(msg[2].toLowerCase()!='belirsiz')){
      var MsgUrl="";
      if (appPath==undefined){
        MsgUrl = "/";
      }
      else {
        MsgUrl = appPath;
      }
      MsgUrl = MsgUrl + 'Controls/MsgGoster.aspx?MsgId='+ escape(msg[0]) + '&Msg=' + escape(msg[1]) + "&MesajTip=" + escape(msg[2]);
      showDialog(MsgUrl, ShowMessages, "left=300;top:300;height=200;width=300;location=no;statusbar=no;menubar=no;scrollbars=yes;resizable=yes;titlebar=no;");
    } 
    else {
      alert(msg[1]);
      ShowMessages();
    }
  }
  else {    
    while(CommandQueue.length >0){
      var cmd=CommandQueue.pop();
      try{
        window.eval(cmd);
      }
      catch(e){
        alert(e.message);
      }
    }
  }
} 

/* Yardım ile ilgili fonksiyonlar 
*/
function Yardim(YardimUrl){
  
  var DocUrl = window.location.href;
  var Alternate = window.location.href;
    
  var Frames = document.getElementsByTagName('IFRAME');
  if (Frames.length>0){    
    for(var i=0;i<Frames.length;i++){
      if (Frames[i].id.search(/frmWorkArea/gi)>=0){    
        DocUrl = Frames[i].contentWindow.location.href;
      }
    }
  }

  var Features = "height=580, width=900, left=0, top=0, location=no, menubar=no, resizable=yes, scrollbars=yes,status=no, toolbar=no";
    
  if ((YardimUrl==undefined)||(YardimUrl!=null)||(YardimUrl=='')){
    if (appPath!=undefined){
      window.open(appPath + "Yardim/default.aspx?URL=" + escape(DocUrl),"_blank",Features);
    }
    else {
      window.open(appPath + "Yardim/default.aspx?URL=" + escape(DocUrl),"_blank",Features);
    }
 }
 else {
    window.open(YardimUrl + "?URL=" + escape(DocUrl)+"&Alternate=" + escape(Alternate),"_blank",Features);  
 }
}
      
/*
  Menü ile ilgili fonksiyonlar...
*/
function CollapseExpand(elm){
    var prn=elm.parentNode;    
    var title=null;
    var container=null;
        
    var divs = prn.getElementsByTagName('DIV');
    for(var i=0;i<divs.length;i++){
      if ("partContainer"==divs[i].className) container = divs[i];
      if ("Title"==divs[i].className) title=divs[i];
    }
    
    if (null!=container){      
      if ("true"!=elm.getAttribute("collapsed")){
        elm.setAttribute("collapsed","true");
        elm.className="rolldn";
        container.style.visibility="hidden";
        
        var PaddingValue = title.clientHeight - parseInt(getStyle(prn,"padding-top")) - parseInt(getStyle(prn,"padding-bottom"));

        prn.style.height=PaddingValue.toString() + "px";
        prn.style.minHeight=title.style.height;
        prn.style.maxHeight=title.style.height;
        prn.style.overflow="hidden";
      }
      else {
        elm.setAttribute("collapsed","false");
        elm.className="rollup";
        container.style.visibility="visible";
        prn.style.height="auto";
        prn.style.minHeight="";
        prn.style.maxHeight="";
        prn.style.overflow="visible";
      }
    }
  }
  
/*
  Açılışla ilgili Fonksiyonlar
*/
  
function LoaderFunction(){
  try {
    eval("bodyonload();");
  }
  catch(e){
  
  }
}

function SetLanguage(LangCode){
  var eventTarget=document.getElementById('__EVENTTARGET');
  var eventArgument=document.getElementById('__EVENTARGUMENT');
  if ((eventTarget!=undefined)&&(eventTarget != null)){
    eventTarget.value = LangCode;
    document.forms[0].submit();
  }
}


function SubmitFunction(){
  try{
    eval("formonsubmit();");
    eval("form1onsubmit();");
  }
  catch(e){
  
  }
}

// Get the computed css property
function getStyle( element, cssRule )
{
  if( document.defaultView && document.defaultView.getComputedStyle )
  {
    var value = document.defaultView.getComputedStyle( element, '' ).getPropertyValue( 
      cssRule.replace( /[A-Z]/g, function( match, char ) 
      { 
        return "-" + char.toLowerCase(); 
      } ) 
    );
  }
  else if ( element.currentStyle ) var value = element.currentStyle[ RuleToProperty(cssRule) ];
  else                             var value = false;
  return value;
}

// Set a style property
function setStyle( element, cssRule, value )
{
  var original = getStyle( element, cssRule );
  if ( !element.styleHistory )            
    element.styleHistory = new Array();
  if ( !element.styleHistory[ cssRule ] ) 
    element.styleHistory[ cssRule ] = new Array();
  element.styleHistory[ cssRule ].push( original );
  element.style[ cssRule ] = value;
  return value;
}

// Undo a style property change
function undoSetStyle( element, cssRule )
{
  if ( 
    this.styleHistory && 
    this.styleHistory[ cssRule ] && this.styleHistory[ cssRule ].length 
  ) {
    var oldValue = this.styleHistory[ cssRule ].pop();
    this.style[ cssRule ] = oldValue;
  }
}

// Revert one or more style properties
function revertStyle( element, cssRules )
{
  var stylesChanged = 0;
  if( element.styleHistory )
  {
    if ( cssRules == '*' ) 
    { 
      cssRules = new Array(); 
      for( var a in element.styleHistory ) cssRules.push( a ); 
    }
    else if ( typeof cssRules != "Array" ) cssRules = Array( cssRules );

    for( var a = 0; a < cssRules.length; a++ )
    {
      var cssRule = cssRules[a];
      if ( 
        element.styleHistory[ cssRules[a] ] && 
        element.styleHistory[ cssRules[a] ][0] 
      ) {
        element.style[ cssRules[a] ] = element.styleHistory[ cssRules[a] ][0];
        element.styleHistory[ cssRules[a] ] = new Array();
        stylesChanged++;
      }
    }
  }
  return stylesChanged;
}

// Add push() and pop() if necessary
if( typeof Array.prototype.push == 'undefined' )
{
  Array.prototype.push = function( element ) { this[this.length] = element; }
}

if( typeof Array.prototype.pop == 'undefined' )
{
  Array.prototype.pop = function () 
  { 
    var last = this[this.length - 1]; this.length--; return last; 
  }
}


function RuleToProperty(txt){
  var result = txt;
  var pos=result.indexOf("-");
  
  while((-1)!=pos){  
    result = result.substr(0,pos) + result.substr(pos+1,1).toUpperCase() + result.substr(pos+2,result.length-pos-2);
    pos=result.indexOf("-");
  }
  return result;
}


window.setResult=function(value){
  if (!window.DialogParam){
    window.DialogParam = window.opener.DParam;
  }
  window.DialogParam.returnValue=value;
}


//----------------------------------------
// MODAL dialog gösterme fonksiyonları
//----------------------------------------
/*
  Kullanımı şu şekilde :
 
 1. Yöntem 
 -------------------------- 
 function DetayEkle(){
    showDialog("Detay.aspx?Id=-1",SayfayiTazele, "left=10, top=10, width=300, height=300");
 }
 
 function SayfayiTazele(){
  document.forms[0].submit();
 }
 
 
 2. Yöntem 
 -----------------------
 function DetayGoster(Id){
   ShowDialog("Detay.aspx?Id=" + (Id).toString(),null);
 }
    
 */
    window.onunload=myOnClose;

    document.ChildCloser = null;
    document.WindowCB = null;
    document.OnMouseDown=null;
    document.OnMouseUp=null;
    document.OnClick=null;
    
    function ChildClosed(){
      if (window.onfocus!=null){
        window.onfocus=null;
        document.onmousedown=document.OnMouseDown;
        document.onmouseup=document.OnMouseUp;
        document.onclick=document.OnClick;

        document.OnMouseDown=undefined;
        document.OnMouseUp=undefined;
        document.OnClick=undefined;
      }
      if (null!=document.WindowCB){       
        document.WindowCB(window.DParam.returnValue);
        document.WindowCB = undefined;
       }       
    }  
    
    function myOnClose(e){
      CheckChildWindow();
      if ((undefined!=document.Window)&&(null!=document.Window)){
        document.Window.close();
      }
    };
    
    function CheckChildWindow(){
      if (undefined!=document.Window){
        if (null!=document.Window){
          var Closed = true;
          try {
            Closed = document.Window.closed;
          }catch(e){};
            
          if (Closed){
            ChildClosed();
            document.Window = null;
            return false;  
          }
          window.setTimeout("javascript:CheckChildWindow();",200);
        }
      }      
      return false;
    };
    
    function FocusChildWindow(){
      if (undefined!=document.Window){
        if (null!=document.Window){
          var Closed = true;
          try {
            Closed = document.Window.closed;
          }catch(e){};
            
          if (!Closed){
            document.onmousedown=FocusChildWindow;
            document.onmouseup=FocusChildWindow;
            document.onclick=FocusChildWindow;
            window.onfocus = FocusChildWindow;
                 
            document.Window.focus();
          }
        }
      }
      return false;
    }

    function showDialog(URL, CB, Params){
      if (undefined==CB) CB = null;
      
      Params = SetupParams(Params);
      
      try {
        document.Window = window.open(URL,"_blank",Params,true);
      }
      catch(e){
        alert("Şu anda kullanmakta olduğunuz tarayıcı popup pencereleri bloke ediyor. Eğer windows XP kullanıyorsanız pencerenin üst kısmında yeralan sarı banda farenin sağ butonuyla tıklayın ve açılan menüden bu sitede popuplara izin ver seçeneğini seçin. Eğer google toolbar, msn toolbar gibi programlar kullanıyorsanız bu sitede işlem yaparken bu toolbar programlarının ayarlarından popup blocker özelliğini iptal ettirin.");
        return      
      }
      if (document.Window==undefined){
        alert("Şu anda kullanmakta olduğunuz tarayıcı popup pencereleri bloke ediyor. Eğer windows XP kullanıyorsanız pencerenin üst kısmında yeralan sarı banda farenin sağ butonuyla tıklayın ve açılan menüden bu sitede popuplara izin ver seçeneğini seçin. Eğer google toolbar, msn toolbar gibi programlar kullanıyorsanız bu sitede işlem yaparken bu toolbar programlarının ayarlarından popup blocker özelliğini iptal ettirin.");
        return
      }      
      if (document.Window==null){
        alert("Şu anda kullanmakta olduğunuz tarayıcı popup pencereleri bloke ediyor. Eğer windows XP kullanıyorsanız pencerenin üst kısmında yeralan sarı banda farenin sağ butonuyla tıklayın ve açılan menüden bu sitede popuplara izin ver seçeneğini seçin. Eğer google toolbar, msn toolbar gibi programlar kullanıyorsanız bu sitede işlem yaparken bu toolbar programlarının ayarlarından popup blocker özelliğini iptal ettirin.");
        return
      }
      
      try{
        var dummy = document.Window.title;
      }
      catch(e){
        alert("Şu anda kullanmakta olduğunuz tarayıcı popup pencereleri bloke ediyor. Muhtemel problem YAHOO toolbar olabilir. Başka popup blocker eklentileri de bu soruna yolaçabilmektedir. Lütfen bu sitede işlem yaparken popupblocker veya tarayıcı kapatın. Kapattıktan sonra yeni bir tarayıcıdan (blocker olmadan) sayfayı açın.");
        return
      }  
           
      window.DParam = {returnValue:""};
      document.WindowCB = CB;

      document.Window.DialogParam = window.DParam;

      document.OnMouseDown=document.onmousedown;
      document.OnMouseUp=document.onmouseup;
      document.OnClick=document.onclick;

      document.onmousedown=FocusChildWindow;
      document.onmouseup=FocusChildWindow;
      document.onclick=FocusChildWindow;

      window.onfocus = FocusChildWindow;
      window.setTimeout("javascript:CheckChildWindow();",300);
    };
    
    function SetupParams(Params){    
      if (undefined==Params){
        Params="";
      }
	    Params = Params.replace(/dialogHeight:/gi,"height=");
	    Params = Params.replace(/dialogWidth:/gi,"width=");
	    Params = Params.replace(/dialogTop:/gi,"top=");
	    Params = Params.replace(/dialogLeft:/gi,"left=");
	    //Params = Params.replace(/scrollBars:/gi,"scroll=");
	    Params = Params.replace(/:/gi,"=");
	    Params = Params.replace(/;/gi,",");
  	  
	    if (-1==Params.toLowerCase().indexOf("height")){
	      var h= window.screen.height/2; 
	      Params = "height=" + h.toString() + ((""==Params)?"":",") + Params;
	    }
	    
	    if (-1==Params.toLowerCase().indexOf("status"))	Params="status=no," + Params;
	    if (-1==Params.toLowerCase().indexOf("resizable"))	Params="resizable=yes," + Params;
	    if (-1==Params.toLowerCase().indexOf("menubar"))	Params="menubar=no," + Params;
	    if (-1==Params.toLowerCase().indexOf("toolbar"))	Params="toolbar=no," + Params;
	    
	  
	    if (-1==Params.toLowerCase().indexOf("width")){
	      var w= window.screen.width/2; 
	      Params = "width=" + w.toString() + ((""==Params)?"":",") + Params;
  	  }

	         
      Params="modal=yes, dialog=yes, dependent=yes" + ((""==Params)?"":",") + Params;
      
      return Params;
    }
    
 
 /***************************
 WorkArea management.....
 ****************************/   
   
    
var WorkAreaList= new Array();

function RegisterWorkArea(FrameId){
  WorkAreaList.push(FrameId);
}

function ShowInWorkArea(NavUrl){
  if (WorkAreaList.length == 0){
    window.open(NavUrl,"_top");  
  }
  else {
    ShowInFrame(WorkAreaList[0],NavUrl);
  }
}

function HasWorkAreaRegistered(){
  return (WorkAreaList.length>0);  
}

function ShowInWorkAreaOrPopup(NavUrl){
  if (WorkAreaList.length == 0){
    window.open(NavUrl,"_blank");  
  }
  else {
    ShowInFrame(WorkAreaList[0],NavUrl);
  }
}    


/**********************************
Portal Page Accept
**********************************/

function PortalPageAccept(TabloAdi,Referans,Baslik)
{
  showDialog("/Guvenlik/PortalPageAccept.aspx?TabloAdi="+TabloAdi+"&Referans="+Referans+"&Baslik="+Baslik,null,"dialogHeight:375px;dialogWidth:537px;center:1;resizable:no;");
}