﻿// JScript FileMe.img_Facebook

var ETKIN_JLib = {


    f_WhichBrowser:function()
    {
         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;
    },
    //*************************************************************************************************
    MyGetElementById:function(sControlID)
    {
        return document.all ? document.all[sControlID] : document.getElementById(sControlID);
    },
    //*************************************************************************************************
    XBrowserAddHandler:function(target,eventName,handlerName)
    {
        try
        {
            if ( target.addEventListener )
            {
                target.addEventListener(eventName, handlerName, false);
            } 
            else if ( target.attachEvent )
            {
                target.attachEvent("on" + eventName, handlerName);        
            }
            else
            {
                target["on" + eventName] = handlerName;
            }        
        }
        catch(err)
        {
            alert(err);
        }
    },
    //*************************************************************************************************
    MyDoPostBack:function(sSender,sArgument)
    {
        __doPostBack(sSender,sArgument);
    },
    //*************************************************************************************************
    MyMsgBoxShow:function(sMessage)
    {
        if(sMessage!=null)
        {
            alert(sMessage);
        }
        else
        {
            alert('Error: There is no message to show');
        }
    },
    //*************************************************************************************************
    f_MyMsgBoxShow:function(sMessage)
    {  
        try
        {
            alert(sMessage);
        }
        catch(err)
        {

        }
        finally
        {
            return false;      
        }
     },
     //************************************************************************************************
     ReloadPage:function()
     {
        window.location.href=window.location.href;
     },     
     //*************************************************************************************************
     ChangeWindowLocation:function(URL)
     {
       window.location.href = new String(URL);
     },
     //*************************************************************************************************
     ChangeParentWindowLocation:function(url)
     {
        var goUrl = new String(url);
        window.parent.location.href = goUrl;
     },
    //*************************************************************************************************    
    f_MyConfirm:function(s)
    {
      var newstring =new String(s);
      if (confirm(newstring)) 
      {
          return true;
      }
      return false;
    },
     //*************************************************************************************************
    ShowDateTime:function(sLblID)
    {
        try
        {
            var TimeLabel = ETKIN_JLib.MyGetElementById(sLblID);
            
            Stamp= new Date();
            var Hours;
            var Minutes;
            var Seconds;
            var MyTime;
            Hours = Stamp.getHours();
            Minutes = Stamp.getMinutes();
            Seconds = Stamp.getSeconds();
            if(Seconds.length == 0)
                Seconds = "0" + Seconds;
            MyTime = Stamp.toLocaleTimeString() + " " + (Hours>11 ? 'pm' : 'am');
            
            TimeLabel.innerHTML = Stamp.toLocaleString(); 
        }
        catch(Err)
        {

        }
        setTimeout("ETKIN_JLib.ShowDateTime('" + sLblID + "')",1000);
    },
    //*************************************************************************************************
    f_ClearText:function(sText)
    {
        var oReturn = new String();
        var aToBeCleaned = new Array("'","\"","!","+","$","%","&","/","?","-","_","{","}","[","]","<",">","|","#",",",";","*","\\",".","=","(",")","|",":");
        var iCnt = 0;
        try
        {
            for(var i=0;i<sText.length;i++)
            {
                iCnt = 0;
                for(var z=0;z<aToBeCleaned.length;z++)
                {
                    if(sText.substr(i,1) == aToBeCleaned[z])
                    {
                         iCnt += 1;
                    }
                }
                if(iCnt == 0)
                {
                    oReturn += sText.substr(i,1);
                }
            }
        }
        catch(Err)
        {
            alert(err);
            oReturn = '';
        }
    return oReturn;
    },
    //*************************************************************************************************
    f_MyTrim:function(sText)
    {
        var oReturn = '';
        var sDeger = new String(sText);
        for (var i=0;i<sText.length;i++)
        {   
            if(sDeger.charCodeAt(i) != 32)//(Bosluk ise)
            {
                //oReturn += String.fromCharCode(sDeger.charCodeAt(i));
                oReturn += sDeger.substr(i,1);
            }
        }
        return oReturn;
    },
    //*************************************************************************************************
    f_MyLeftTrim:function(sText)
    {
        var oReturn = '';
        var sDeger = new String(sText);
        var iBas=0;
        for (var i=0;i<sText.length;i++)
        {   
            if(sDeger.charCodeAt(i) == 32)//(Bosluk ise)
            {
                iBas+=1;
            }
            else
            {
                break;
            }
        }
     oReturn  = sText.substr(iBas,sText.length-iBas);
     return oReturn;
    },
    //*************************************************************************************************
    f_MyRightTrim:function(sText)
    {
        var oReturn = '';
        var sDeger = new String(sText);
        var iBas=0;
        for (var i=sText.length-1;sStr.length-1>=0;i--)
        {   
            if(sDeger.charCodeAt(i) == 32)//(Bosluk ise)
            {
                iBas+=1;
            }
            else
            {
                break;
            }
        }
     oReturn  = sText.substr(iBas,sText.length-iBas);
     return oReturn;
    },
    //*************************************************************************************************
    f_Text_ToUpperCase:function(sText)
    {
        if(sText!=null | sText=='')
        {
            return new String(sText).toUpperCase();
        } 
    },
    //*************************************************************************************************
    f_Text_ToLowerCase:function(sText)
    {
        if(sText!=null | sText=='')
        {
            return new String(sText).toLowerCase();
        } 
    },
    //*************************************************************************************************
    f_FindPos:function(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];
    },
    //*************************************************************************************************
    f_FindPos_1:function(obj) 
    {  
        var objTemp = obj;
        var objTemp1 = obj;
        var oDiv = null;

        try
        {
            if (objTemp.offsetParent) 
            {
               while (objTemp = objTemp.offsetParent) 
	            {
                    if(objTemp.tagName=='DIV')
                    {
                        if(oDiv==null)
                        {
                            if(ETKIN_JLib.MyGetElementById(objTemp.id).style.position == 'absolute')
                            {
                            oDiv = objTemp;
                            break;
                            } 
                        }
                    }
	            } 
            }
            
            if(oDiv==null)
            {
                var curleft = curtop = 0;
                if (objTemp1.offsetParent) 
                {
	                curleft = objTemp1.offsetLeft
	                curtop = objTemp1.offsetTop
	                while (objTemp1 = objTemp1.offsetParent) 
	                {
		                curleft += objTemp1.offsetLeft;
		                curtop += objTemp1.offsetTop;
	                }
                }
            }
            else
            {
                var curleft = curtop = 0;
                if (objTemp1.offsetParent) 
                {
                   while (objTemp1 = objTemp1.offsetParent) 
	                {
                        if(objTemp1.tagName=='DIV')
                        {
                            if(ETKIN_JLib.MyGetElementById(objTemp1.id).style.position != 'absolute')
                            {
                            curleft += objTemp1.offsetLeft;
	                        curtop += objTemp1.offsetTop;
                            } 
                        }
                        else
                        {
                            curleft += objTemp1.offsetLeft;
	                        curtop += objTemp1.offsetTop;
                        }
	                } 
                }
            }

        }
        catch(err)
        {
            curleft = 0;
            curtop = 0;

        }
    return [curleft,curtop];
    },
    //*************************************************************************************************
    ModalPopUp_Show:function(sPanelID)
    { 
        
        var sBrowser = this.f_WhichBrowser();
        
        var oPanel = ETKIN_JLib.MyGetElementById(sPanelID);
        oPanel.style.visibility = 'visible';
              
        oPanel.style.zIndex = 0;
        oPanel.style.position = 'absolute';
        oPanel.style.top = document.documentElement.scrollTop+'px';
        oPanel.style.left = document.documentElement.scrollLeft+'px';
        if(document.documentElement.scrollHeight<500)
        {oPanel.style.height = '1000px';}
        else
        {oPanel.style.height = document.documentElement.scrollHeight+'px';}
        oPanel.style.width = document.documentElement.scrollWidth+'px';
        oPanel.setAttribute("align","center");
        oPanel.style.verticalAlign = 'middle';
        oPanel.style.backgroundColor = 'silver';
        oPanel.style.visibility = 'visible';
        oPanel.style.display = 'block';
        oPanel.style.overflow = 'auto';
        if(sBrowser=='IE'){
            oPanel.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=100)");
        }
        else{
            oPanel.style.opacity = '.9';
        }
        
        
        
     },
     //*************************************************************************************************
    ModalPopUp_Close:function(sPanelID){
        var oPanel = ETKIN_JLib.MyGetElementById(sPanelID);
        if(oPanel)
        {
            oPanel.style.visibility = 'hidden';
            oPanel.style.display = 'none';
        }
    },
    //*************************************************************************************************
    OpenPopUpWindow:function(sURL,bResize,bScroll,bStatus,iWidth,iHeight) 
    {
        var NewWindow;
        try
        {
            NewWindow = window.open(sURL,'new_window','resizable=' + (bResize==true ? 'yes' : 'no') + ',scrollbars=' + (bScroll==true ? 'yes' : 'no') + ',status=' + (bStatus==true ? 'yes' : 'no') + ',width=' + iWidth + ' ,height=' + iHeight);
            NewWindow.focus();
//            NewWindow.moveTo(350,100);
        }
        catch(err)
        {
            alert(err);
        }
    },
    OpenPopUpWindow_2:function(sURL,bResize,bScroll,bStatus,iWidth,iHeight) 
    {
        try
        {
           var NewWindow;
           NewWindow = window.open(sURL,'','resizable=' + (bResize==true ? 'yes' : 'no') + ',scrollbars=' + (bScroll==true ? 'yes' : 'no') + ',status=' + (bStatus==true ? 'yes' : 'no') + ',width=' + iWidth + ' ,height=' + iHeight);
           NewWindow.focus();
//           NewWindow.moveTo(350,200);
        }
        catch(err)
        {
            alert(err);
        }
    },
    //*************************************************************************************************
    PopUpWindow_Kapat : function ()
    {
        window.close();
    },
    //***************************************************************************************************
    PopUpWindow_Kapat_2 : function ()
    {
        window.parent.close();
    },
    //*************************************************************************************************
    f_IsAnyRadioChecked:function(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;
    },
    //*************************************************************************************************
    f_IsAnyRadioChecked_1:function(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;
    },
    //**********************************************************************************************
    SetChecked_GivenRadio:function(sAttr_Name,sAttr_Value,sRadioID)
    {
        
        var aInputs = document.getElementsByTagName('INPUT');
        for(var i=0;i<aInputs.length; i++)
        {
            if (aInputs[i].type =='radio')
            {
                if(aInputs[i].getAttribute(sAttr_Name)==sAttr_Value)
                {
                    aInputs[i].checked=false;
                }
            }
        }
        
        var MyRadio = ETKIN_JLib.MyGetElementById(sRadioID);
        MyRadio.checked=true;
    },
    //*************************************************************************************************
    f_IsAnyCheckboxChecked:function(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;
    },
    //*************************************************************************************************
    f_NumericTextbox:function(sTextboxId,iMin,iMax,sDefaultValue,sSpr)
    {
        var oTxt;
        var sDeger;
        var bNumeric = new Boolean();
        try
        {
            oTxt = ETKIN_JLib.MyGetElementById(sTextboxId);
            sDeger = new String(oTxt.value);
            bNumeric = ETKIN_JLib.f_IsNumeric(oTxt.value,sSpr);
            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 = ETKIN_JLib.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);
    return bNumeric;
    },
    //*************************************************************************************************
    f_IsNumeric:function(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;
    },
    //*************************************************************************************************
    f_GetFormElements_TagName_Type:function (sTagName,sType)
    {
	    var aElements;
        aElements = document.getElementsByTagName(sTagName);
	    var aReturnElements = new Array();
	    var iIndex = 0;
	    for(var i=0;i<aElements.length;i++)
	    {
		    if(sType!='')
		    {
			    if (aElements[i].type==sType)
			    {
				    aReturnElements[iIndex] = aElements[i];
				    iIndex += 1;
			    }	
		    }
		    else
		    {
		        aReturnElements[iIndex] = aElements[i];
		        iIndex += 1;
		    }
	    }
	    return aReturnElements;
    },
    //*************************************************************************************************
    f_SetVisibility_ColsOfTable : function(sTableID,sChkAttr,sChkVal,bVisible)
    {
        var tablo;
        var row;
        var cell;
        try
        {
            tablo = this.MyGetElementById(sTableID);
            for(var i=0;i<tablo.rows.length;i++)
            {
                row = tablo.rows[i];
                for(var z=0;z<row.cells.length;z++)
                {
                    cell = row.cells[z];
                    cell.style.visibility = (bVisible==true ? 'visible' : 'hidden');
                    cell.style.display = (bVisible==true ? 'block' : 'none');         
                }
                
                for(var z=0;z<row.cells.length;z++)
                {
                    cell = row.cells[z];
                    if(sChkAttr!='' && sChkVal!='')
                    {
                        if(cell.getAttribute(sChkAttr))
                        {
                            if(cell.getAttribute(sChkAttr) == sChkVal)
                            {
                                cell.style.visibility = (bVisible==true ? 'visible' : 'hidden');
                                cell.style.display = (bVisible==true ? 'block' : 'none');
                            }
                            else
                            {
                                cell.style.visibility = (bVisible==true ? 'hidden' : 'visible');
                                cell.style.display = (bVisible==true ? 'none' : 'block');
                            }
                        }
                    }                    
                }
            }
        }
        catch(err)
        {
            alert('f_SetVisibility_ColsOfTable : ' + err);
        }
    },
    //*************************************************************************************************
    f_SetVisibility_RowsOfTable : function(sTableID,iStartRowIndex,sChkAttr,sChkVal,bVisible)
    {
        var tablo;
        var row;
        var cell;
        var iIndex = iStartRowIndex;
        try
        {
            tablo = this.MyGetElementById(sTableID);
            for(var i=iIndex;i<tablo.rows.length;i++)
            {
                row = tablo.rows[i];
                row.style.visibility = (bVisible==true ? 'visible' : 'hidden');
                row.style.display = (bVisible==true ? 'block' : 'none');  
                if(sChkAttr!='' && sChkVal!='')
                {
                    if(row.getAttribute(sChkAttr))
                    {
                        if(row.getAttribute(sChkAttr) == sChkVal)
                        {
                            row.style.visibility = (bVisible==true ? 'visible' : 'hidden');
                            row.style.display = (bVisible==true ? 'block' : 'none');
                        }
                        else
                        {
                            row.style.visibility = (bVisible==true ? 'hidden' : 'visible');
                            row.style.display = (bVisible==true ? 'none' : 'block');
                        }
                    }
                }
            }
        }
        catch(err)
        {
            alert('f_SetVisibility_RowsOfTable : ' + err);
        }
        
    },
    //*************************************************************************************************
    Set_ObjectVisibility : function(sObjectID,bVisible,bAuto)
    {
        var oObjcet;
        try
        {
            
            oObjcet = this.MyGetElementById(sObjectID);
            if(bAuto==true){
                bVisible = (oObjcet.style.visibility == 'visible' ? false : true);
            }
            
            oObjcet.style.visibility = (bVisible==true ? 'visible' : 'hidden');
            oObjcet.style.display = (bVisible==true ? 'block' : 'none');            
        }
        catch(err)
        {
            alert('f_Set_ObjectVisibility : ' + err);
        }
        
    },
    //*************************************************************************************************
    f_CreateHtmlTable:function(iCols,iRows,iCellSpacing,iCellPadding,iBorder,iCellWidth,iCellHeight)
    {
        var oTablo;
        var row;
        var cell;
        try
        {
            oTablo = document.createElement('table');
            oTablo.cellSpacing = iCellSpacing;
            oTablo.cellPadding = iCellPadding;
            for (var j=0; j<iRows; j++) 
            {
                var row = document.createElement("tr");
                oTablo.appendChild(row);
                for (var i=0; i<iCols; i++) 
                {
                    var cell = document.createElement("td");
                    cell.style.border = "1px solid silver";
                    cell.style.width = iCellWidth;
                    cell.style.height = iCellHeight;
                    cell.innerHTML = '';
                    row.appendChild(cell);
                 }
             }
        }
        catch(err)
        {
            alert('f_CreateHtmlTable : ' + err);
            return null;
        }
    return oTablo;
    },
    //*************************************************************************************************
    f_GetXmlHttpObject:function()
    {
        var sBrowser = ETKIN_JLib.f_WhichBrowser();
        var xmlHTTP;
        if(sBrowser=='IE')
        {
            xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
        }
        else if(sBrowser=='NN')
        {
            xmlHTTP = new XMLHttpRequest();
        }
        else
        {
            xmlHTTP = null;
        }

    return xmlHTTP; 
    },
    //*************************************************************************************************
    f_GetXmlHttpObject_1:function()
    {
        var xmlHTTP=null;
        try
        {
            xmlHTTP=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
             try
             {
                xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch(oc)
             {
                xmlHTTP=null;
             }
        }
        if(!xmlHTTP&&typeof XMLHttpRequest!="undefined")
        {
         xmlHTTP=new XMLHttpRequest();
        }
    return xmlHTTP;
    },
    //*************************************************************************************************
    f_MakeRequest_By_XmlHttp:function(sMethod,sURL,bXmlContent)
    {
        var xmlHTTP;
        var sBrowser = ETKIN_JLib.f_WhichBrowser();
        var XmlDoc;
        try
        {
            if(sBrowser=='IE')
            {
                xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
                xmlHTTP.open(sMethod,sURL,false);
                xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
                xmlHTTP.send ();
                XmlDoc = new ActiveXObject("Msxml2.DOMDocument");
                XmlDoc.loadXML(xmlHTTP.responseText);
                alert(xmlHTTP.responseText);
            }
            else if(sBrowser=='NN')
            {
                xmlHTTP = new XMLHttpRequest();
                xmlHTTP.open(sMethod,sURL,false);
                xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
                xmlHTTP.send(null);
                alert(xmlHTTP.responseText);
                XmlDoc = xmlHTTP.responseText
            }
        }
        catch(err)
        {
            alert(err);
            XmlDoc = null;
        }
      return XmlDoc;  
    },
    //*************************************************************************************************
    GetTicket_KrncWs_Login:function()
    {
        var sBrowser = ETKIN_JLib.f_WhichBrowser();
        var xmlHTTP;
        var XmlDoc;
        xmlHTTP = ETKIN_JLib.f_GetXmlHttpObject();
        xmlHTTP.open("POST", "http://xml.intraturkey.com/krnc_ws/ws/login.asmx", false)
        xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
        xmlHTTP.setRequestHeader("SoapAction", "http://karincasoft.com/KRNC_WS/Login/gfGet_AuthorizationTicket")

        var SOAP;

        SOAP = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
        SOAP += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
        SOAP += "<soap:Body>";
        SOAP += "<gfGet_AuthorizationTicket xmlns=\"http://karincasoft.com/KRNC_WS/Login\">";
        SOAP += "<sTurop></sTurop>";
        SOAP += "<sUser></sUser>";
        SOAP += "<sPass></sPass>";
        SOAP += "</gfGet_AuthorizationTicket>";
        SOAP += "</soap:Body>";
        SOAP += "</soap:Envelope>";
        try{xmlHTTP.send(SOAP);}
        catch(err){alert(err);}
        alert(xmlHTTP.responseText);
    },
    //***************************************************************************************
    SetSrc_To_Image : function (sImgId,sSrc)
    {
        var Img = null;
        try
        {
            Img = this.MyGetElementById(sImgId);
            if(Img){
                Img.setAttribute('src',sSrc);
            }
        }
        catch(err)
        {
            if(Img){
                Img.setAttribute("src",'');
            }
        }
    }
    

}

