﻿// Barbaros YATKIN - 2009

//GENEL FONKSIYONLAR
function MyDoPostBack(sSender,sArgument)
{
    __doPostBack(sSender,sArgument);
}

function SetFocus(sCtlID)
{
    var ctl = MyGetElementById(sCtlID);
    if(ctl)
    {
        ctl.focus();
    }
}


function HangiBrowser()
{
     var oReturn  = '';
     var browser = new String(navigator.appName);
     try
     {
         if(browser.indexOf("Microsoft")>-1)
         {
            oReturn = 'IE';
         }
         else if(browser.indexOf("Netscape")>-1)
         {
            oReturn = 'NN'; //Netscape - Firefox
         }
         else
         {
            oReturn = '';
         }
     }
     catch (Err)
     {
        alert(Err);
        oReturn = '';
     }
return oReturn;
}

function MyGetElementById(sId)
{
    return document.all ? document.all[sId] : document.getElementById(sId);
}

function XBrowserAddHandler(target,eventName,handlerName)
{
    if ( target.addEventListener )
    {
        target.addEventListener(eventName, handlerName, false);
    } 
    else if ( target.attachEvent )
    {
        target.attachEvent("on" + eventName, handlerName);        
    }
    else
    {
        target["on" + eventName] = handlerName;
    }
      
}

function OpenPopUpWindow(sURL,iWidth,iHeight) 
{
    var YeniPencere = window.open(sURL,'yenipencere','resizable=no,scrollbars=yes,status=no,width=' + iWidth + ' ,height=' + iHeight)
}

function ClosePopUpWindow()
{
    if(window.opener)
    {
        window.close();
    }
}

function OpenshowModalDialog(sURL,iWidth,iHeight)
{
    window.showModalDialog(sURL,'modaldialog','center:yes;dialogWidth:'+iWidth+'px;dialogHeight:'+iHeight+'px;status:no;resizable:no;help:no;dialogHide:yes');
}

function CloseModalDialog()
{
    self.opener = this;
    self.close();
}

function ChangeWindowLocation(URL)
{
    window.location.href = new String(URL);
}

function f_SessionEnd_GotoLoginPage(mesaj)
{
    if(mesaj!=null)
    {
        alert(mesaj);
    }
    window.location.href = "default.aspx";
}

function f_Onayla(s)
   {
	var newstring =new String(s);
	if (confirm(newstring)) 
	{
			return true;
	}
	return false;
   }

function f_MessageBoxShow(mesaj)
{
    if(mesaj!=null)
    {
    alert(mesaj);
    }
    else
    {
    alert('Error: There is no message to show');
    }
}

function f_MessageBoxShow_1(mesaj)
{  
  alert(mesaj);
  return false;
}

function IsAnyRadioChecked(sRadioName,sMessage)
{
    var ctlName = new String(sRadioName);
    var radios = document.getElementsByName(ctlName);
    for(i=0;i<radios.length;i++)
    {
        if (radios[i].type =='radio')
        {
              if(radios[i].checked)
                return true;
        }
    }  
  alert(sMessage);
  return false;
}

function IsAnyRadioChecked_1(sAttr_Name,sAttr_Value,sMessage)
{
    
    var aInputs = document.getElementsByTagName('input');
    for(i=0;i<aInputs.length;i++)
    {
        if (aInputs[i].type =='radio')
        {
            if(aInputs[i].getAttribute(sAttr_Name)==sAttr_Value)
            {
                if(aInputs[i].checked)
                {
                    return true;    
                }
            }
        }
    }  
  alert(sMessage);
  return false;
}

function IsAnyCheckboxChecked(sAttr_Name,sAttr_Value,sMessage)
{
    
    var aInputs = document.getElementsByTagName('input');
    for(i=0;i<aInputs.length;i++)
    {
        if (aInputs[i].type =='checkbox')
        {
            if(aInputs[i].getAttribute(sAttr_Name)==sAttr_Value)
            {
                if(aInputs[i].checked == true)
                {
                    return true;    
                }
            }
        }
    }  
  alert(sMessage);
  return false;
}

function findPos_S1(obj) 
{
    var curleft = curtop = 0;
    if (obj.offsetParent) 
    {
	    curleft = obj.offsetLeft
	    curtop = obj.offsetTop
	    while (obj = obj.offsetParent) 
	    {
		    curleft += obj.offsetLeft
		    curtop += obj.offsetTop
	    }
    }
    return [curleft,curtop];
}

function f_IsNumeric(sValue,spr)
{ 
    var sayilar=new Array('0','1','2','3','4','5','6','7','8','9',spr);   
    var deger = sValue;
    var c;
    var bulundu=new Boolean();
    yenideger = '';
    try
    {
        for (var i=0;i<deger.length;i++)
        {   
            bulundu = false; 
            c=new String();
            c=deger.charAt(i);
            for (var z=0;z<sayilar.length;z++)
            {
                if(c==sayilar[z])
                {
                    bulundu = true;
                    break;
                }
            }
            if(bulundu == false)
            {
                return false;
            }
        }
    }
    catch(err)
    {
        return false;
    }
return true;
}

function f_NumericTextbox(sTextboxId,iMin,iMax,sDefaultValue)
{
    var oTxt;
    var sDeger;
    var bNumeric = new Boolean();
    try
    {
        oTxt = document.getElementById(sTextboxId);
        sDeger = new String(oTxt.value);
        bNumeric = f_IsNumeric(oTxt.value,".");
        if(bNumeric==false)
        {
            if(sDeger.length==1)
            {
            sDeger = sDefaultValue;
            }
            else
            {
            sDeger = sDeger.substr(0,sDeger.length-1);    
            }
        }
        oTxt.value = sDeger;
        if(sDeger<iMin | sDeger>iMax)
        {   
            bNumeric = f_IsNumeric(sDefaultValue,".");
            if(bNumeric==false)
            {
                sDeger = "0";
            }
            else
            {
                if(sDeger<iMin | sDeger>iMax)
                {
                    sDeger = "0";
                }
            }
        }
    }
    catch(err)
    {
        alert(err);
        sDeger = sDefaultValue;
    }
oTxt.value = (sDeger=="" ? "" : sDeger * 1);
return bNumeric;
}

function ShowProcessingPanel(sHtml)
 {
    var oDiv = document.createElement('DIV');
    oDiv.style.zIndex = 1;
    oDiv.style.position = (navigator.userAgent.indexOf('MSIE') > -1) ? 'absolute' : 'fixed';
    oDiv.style.width = document.body.clientWidth;
    oDiv.style.height = document.body.clientHeight + 100;
    oDiv.style.visibility = 'visible';
    oDiv.style.top = document.body.scrollTop;
    oDiv.style.left = 0;
    oDiv.style.textAlign = 'center';
    oDiv.style.backgroundColor = 'LightBlue';
    
    oDiv.innerHTML = sHtml;
    
    document.body.appendChild(oDiv);  
 }

function ToUpperCase_Textbox(sTxtId)
{
    var oTxt = MyGetElementById(sTxtId);
    if(oTxt)
    {
        if(oTxt.value!=null)
        {
            oTxt.value = new String(oTxt.value).toUpperCase();
        } 
    }
}

function f_ShowTblHata(sErrMsg)
{
    try
    {
        var lblHata = MyGetElementById('lblHata');
        if(!lblHata)
        {
            throw('The control named lblHata could not be found on the page');
        }
        lblHata.innerText = sErrMsg;
        
        var tblHata = MyGetElementById('tblHata');
        if(!tblHata)
        {
            throw('The control named tblHata could not be found on the page');
        }
        tblHata.rows[0].cells[0].style.height = '25px';
        tblHata.style.visibility = 'visible';
    }
    catch(Err)
    {
        alert(Err);
    }
}

function MyTrim(sStr)
{
    var oReturn = '';
    var sDeger = new String(sStr);
    for (var i=0;i<sStr.length;i++)
    {   
        if(sDeger.charCodeAt(i) != 32)//(Bosluk ise)
        {
            //oReturn += String.fromCharCode(sDeger.charCodeAt(i));
            oReturn += sDeger.substr(i,1);
        }
    }
    return oReturn;
}

function MyLeftTrim(sStr)
{
    var oReturn = '';
    var sDeger = new String(sStr);
    var iBas=0;
    for (var i=0;i<sStr.length;i++)
    {   
        if(sDeger.charCodeAt(i) == 32)//(Bosluk ise)
        {
            iBas+=1;
        }
        else
        {
            break;
        }
    }
    oReturn  = sStr.substr(iBas,sStr.length-iBas);
    return oReturn;
}

function MyRightTrim(sStr)
{
    var oReturn = '';
    var sDeger = new String(sStr);
    var iBas=0;
    for (var i=sStr.length-1;sStr.length-1>=0;i--)
    {   
        if(sDeger.charCodeAt(i) == 32)//(Bosluk ise)
        {
            iBas+=1;
        }
        else
        {
            break;
        }
    }
    oReturn  = sStr.substr(iBas,sStr.length-iBas);
    return oReturn;
}

function f_TextTemizle(sText)
{
    var oReturn = new String();
    var aTemizlenecekler = new Array("'","\"","!","+","$","%","&","/","?","-","_","{","}","[","]","<",">","|","#",",",";","*","\\",".","=","(",")","|",":");
    var iCnt = 0;
    try
    {
        for(var i=0;i<sText.length;i++)
        {
            iCnt = 0;
            for(var z=0;z<aTemizlenecekler.length;z++)
            {
                if(sText.substr(i,1) == aTemizlenecekler[z])
                {
                     iCnt += 1;
                }
            }
            if(iCnt == 0)
            {
                oReturn += sText.substr(i,1);
            }
        }
    }
    catch(Err)
    {
    oReturn = '';
    }
    
    return oReturn;
}


function f_ShowDateTime(lblID)
{
    try
    {
        
        Stamp= new Date();
        var Hours;
        var Minutes;
        var Seconds;
        var Time;
        Hours = Stamp.getHours();
        Minutes = Stamp.getMinutes();
        Seconds = Stamp.getSeconds();
        if(Seconds.length == 0)
            Seconds = "0" + Seconds;
        Time = Stamp.toLocaleTimeString() + " " + (Hours>11 ? 'pm' : 'am');
        
        var Tarih;
        Tarih = Stamp.toDateString();
        
        var saatlabel = document.getElementById(lblID);
        saatlabel.innerHTML = Tarih + " - " + Time; 
    
    }
    catch(Err)
    {

    }
    setTimeout("f_ShowDateTime('" + lblID + "')",1000);
}
    
