﻿/*Resize metodu buradan kaldirildi. ihtiyac duyan scriptler icerisinde tanimlanmali!*/
/*setHiddenHeight metoduda ilgili scripte gitmeli!*/
function _fo(id){
if(id==window || id==document || id==document.body) return id;
if(!id) return null;
if(id && id.tagName) return id;
if(id.indexOf) while(id.indexOf("$")!=-1) id=id.replace("$","_");
return (document.getElementById)?document.getElementById(id):document.all[id];
}
function _foEventDoc(obj,eventName) {
    obj=_fo(obj);
    if(obj) return obj;
    if(eventName=="resize" || eventName=="load" || eventName=="scroll") return window;
    return (window.attachEvent)? document.body : window ;
}


function RunDOMEvent(domobj,eventattribute,catchexception) {
domobj=_fo(domobj);
if(domobj && domobj.getAttribute(eventattribute)) 
    { 
    var evalscript=domobj.getAttribute(eventattribute)+"";
    evalscript=evalscript.replace("function anonymous()","");
    if(catchexception){
        try {eval(evalscript); } catch(e) {}
        }
    else 
        eval(evalscript);
    }
}

function SortArrayByValue(v1,v2) {
    return ((v1 < v2) ? -1 : ((v1 > v2) ? 1 : 0));
}
function SortArrayByValueDesc(v1,v2) {
    return ((v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0));
}

function BrowserTypeObj() {
    this.isIE	        = document.all;
    this.isIE7	        = this.isIE && window.XMLHttpRequest && window.ActiveXObject;
    this.isIE6	        = this.isIE && document.implementation;
    this.isgteIE6	    = this.isIE7 || this.isIE6;
    this.isIE5	        = this.isIE && window.print && !this.isgteIE6;
    this.isIEDOM2	    = this.isIE5 || this.isgteIE6;
    this.isIE4	        = this.isIE && !this.isIEDOM2 && navigator.cookieEnabled;
    this.isIE3	        = this.isIE && !this.isIE4 && !this.isIEDOM2;
    this.isNS	        = navigator.mimeTypes && !this.isIE;
    this.isNS3	        = this.isNS && !navigator.language;
    this.isNS4	        = document.layers;
    this.isNS6	        = document.getElementById && !this.isIE;
    this.isNS7	        = this.isNS6;
    this.isNS71	        = document.designMode;
    this.isNSDOM2	    = this.isNS6;
    this.isDOM2	        = this.isIEDOM2 || this.isNSDOM2;
    this.mustAlphaLoader=((this.isIE6 || this.isIE5) && !window.opera && !this.isIE7);
    this.VMLSupportable=(/MSIE/.test(navigator.userAgent) && !window.opera);
    return this;
}
window.BrowserType=new BrowserTypeObj();
function LngVal(key,defaultVal) {
    if(!key || !window.Lng) return defaultVal;
    if(key.substr(0,5)=="{Lng@" && key.substr(key.length-1,1)=="}")
        key=key.substr(5,key.length-6);
    if(defaultVal && !window.Lng.Value[key]) return defaultVal;
    return window.Lng.Value[key];
}
function fixPng(img,mtd)
{
  if(!mtd) mtd='image';
  img.style.visibility = "visible";  
  img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='"+mtd+"', src='" + img.src + "')";
  img.src = "./NetcadUI.axd?.Type=UIResource&Image=blank.gif";
  
}
function RemoveElement(obj) {
    if(!obj) return;
    if(obj.parentNode)
       obj.parentNode.removeChild(obj);
}  

function CopyToClipboardObj(obj) {
if(_fo(obj)) 
    { 
        if(_fo(obj).textContent)
            CopyToClipboard(_fo(obj).textContent);
        else if(_fo(obj).innerText)
            CopyToClipboard(_fo(obj).innerText)
    }
}
function CopyToClipboard(Str) {
    if(window.clipboardData) window.clipboardData.setData("text",Str);
    //add firefox
}

//for netcad webbrowser command
function SendNetcadCommand(cmd) {
    _fo('_NetcadCommand').value=cmd;
    _fo('_NetcadCommand').click();
}
    
/*Nesne Bilgileri*/
function getHeight(Obj,IsOffset) {
    try{  return IsOffset?_fo(Obj).offsetHeight:_fo(Obj).clientHeight; } catch (e){} return 0;
}
function getWidth(Obj,IsOffset) {
    try{  return IsOffset?_fo(Obj).offsetWidth:_fo(Obj).clientWidth; } catch (e){} return 0;
}

function getTop(obj) {
var lScroll=0;
if(obj.offsetParent && obj.offsetParent.nodeName.toLowerCase() != 'body' && obj.offsetParent.scrollTop)
    lScroll=obj.offsetParent.scrollTop;
return (obj.offsetParent)?obj.offsetTop+getTop(obj.offsetParent)-lScroll:obj.offsetTop;
}

function getLeft(obj) {
var lScroll=0;
if(obj.offsetParent && obj.offsetParent.nodeName.toLowerCase() != 'body' && obj.offsetParent.scrollLeft)
    lScroll=obj.offsetParent.scrollLeft;
return (obj.offsetParent)?obj.offsetLeft+getLeft(obj.offsetParent)-lScroll:obj.offsetLeft;
}
function SetRefHeight(obj,refobj,maxheight) {
var h=getHeight(refobj,true);
if(h && h>maxheight) h=maxheight;
if(h && _fo(obj)) _fo(obj).style.height=h+"px";

}

function SetScrollToViewDOM(scrollItem,scrollItemParent) {
    scrollItem=_fo(scrollItem);
    if(scrollItem)            {
        if(scrollItemParent)
            scrollItemParent=_fo(scrollItemParent);
        if(!scrollItemParent)
            scrollItemParent=scrollItem.offsetParent?scrollItem.offsetParent:scrollItem.parentElement;
        if(scrollItem.offsetTop>scrollItemParent.offsetHeight){
			    scrollItemParent.scrollTop = scrollItem.offsetTop - scrollItemParent.offsetHeight + scrollItem.offsetHeight + 2 ;
		    }
		    if(scrollItem.offsetTop<scrollItemParent.scrollTop)
		    {
			    scrollItemParent.scrollTop = 0;	
		    }
		}
}
//for netGrid ()
function setHiddenHeight(hdObj,Obj) {
    try{  _fo(hdObj).value=getHeight(Obj); } catch (e){}
}
function isVisible(obj) {
    while (obj.nodeName.toLowerCase() != 'body' && 
        obj.style.display.toLowerCase() != 'none' && 
        obj.style.visibility.toLowerCase() != 'hidden') {
      obj = obj.parentNode;
    }
    if (obj.nodeName.toLowerCase() == 'body') {
      return true;
    } else {
      return false;
    }
}
/*Genel*/
function CleanArray(array) {
var rtn=new Array(); 
for(var key in array) 
if(key!=null && array[key]!=null)
    rtn[key]=array[key];
return rtn;
}

function CheckBoxCheckContainer(containerDiv,ignoreAttrigute,isChecked) {
containerDiv=_fo(containerDiv);
if(!containerDiv)
    return;
var inputs=containerDiv.getElementsByTagName("INPUT");
for(var i=0;i<inputs.length;i++)
        if(inputs[i].getAttribute("type")=="checkbox" || inputs[i].getAttribute("type")=="CHECKBOX") {
        if(ignoreAttrigute && inputs[i].getAttribute(ignoreAttrigute))
                continue;
             if(isChecked==-1)
                inputs[i].checked=!inputs[i].checked;//invert
             else if(isChecked)
                inputs[i].checked=true;
             else
                inputs[i].checked=false;
             try{
                    if(inputs[i].onclick) 
                        inputs[i].onclick();
                } catch (e) {}
    }
}

/*Event iptali*/
function CancelEvent(e) {
if(!e && window.event) e=window.event;
if(!e) return;
if(e.preventDefault) e.preventDefault(); 
else { e.cancelBuble=true; e.returnValue=false;} 
}

/*Fare yonetimi*/
function getMouseXY(e,noScroll) {
    this.x=0;
    this.y=0;
    this.button=-1;
    this.Clone=function() {
        var rtn=new getMouseXY(0);
        rtn.x=this.x;
        rtn.y=this.y;
        rtn.button=this.button;
        return rtn;
    }
        
    if(e==0) return;
    if(!e && window.event) e=window.event;
    if(!e) { return;}
    

    if(e.pageX) {
        mouseX=e.pageX;
        mouseY=e.pageY;
    }
    else {
        mouseX=e.x;
        mouseY=e.y;
    }
    if(!noScroll) {
        var dEl=document.documentElement;
        var bEl=document.body;
        if(dEl && dEl.scrollTop) mouseY+=dEl.scrollTop; 
        else if(bEl && bEl.scrollTop) mouseY+=bEl.scrollTop; 
        
        if(dEl && dEl.scrollLeft) mouseX+=dEl.scrollLeft;
        else if(bEl && bEl.scrollLeft) mouseX+=bEl.scrollLeft;
    }
    this.x=mouseX;
    this.y=mouseY;
    this.button=0;
    //1 left, 2right, 3 middle
    if (e.which == null){
        if(e.button)
            this.button =(e.button < 2) ? 1 :((e.button == 4 || e.button == 3) ? 3 : 2);
        }
    else if(e.which != null ) 
        this.button= (e.which < 2) ? 1 : ((e.which == 2) ? 3 : 2);
    
    return this;
}

//mouseover out
function _ItemOver(item,styleparent) {
    if(item.getAttribute("Status")=="Disabled"
        || item.getAttribute("Status")=="Selected")
        return;
    if(styleparent.indexOf("att:")!=-1)
        styleparent=item.getAttribute(styleparent.replace("att:",""));
    var over=_fo(styleparent+"_StyleOver")
    item.className=over.className;
    item.style.cssText=over.style.cssText;
}

function _ItemOut(item,styleparent) {
    if(item.getAttribute("Status")=="Disabled"
        || item.getAttribute("Status")=="Selected")
        return;
    if(styleparent.indexOf("att:")!=-1)
        styleparent=item.getAttribute(styleparent.replace("att:",""));
    var active=_fo(styleparent+"_Style"+item.getAttribute("Status"));
    item.className=active.className;
    item.style.cssText=active.style.cssText;
}

function _MouseOver(objID,over) {
var obj=(objID.tagName)?objID:_fo(objID);
if(!obj) return;
if(!obj.getAttribute('DefaultClass'))
    obj.setAttribute('DefaultClass',obj.className)
if(over) {
    if(!obj.getAttribute('LastClass'))
        obj.setAttribute('LastClass',obj.className);
    var ocss=obj.getAttribute('OverClass');
    if(ocss && ocss!=obj.className) {
        obj.setAttribute('LastClass',obj.className);
        obj.className=ocss;
    }
}
else 
    obj.className=obj.getAttribute('LastClass'); 
}

/*Form Yonetimi*/
function getMyForm() {
    var myForm=(window.theForm)?window.theForm:null;
    if(!myForm) myForm= document.forms['form1'];
    if (!myForm) myForm = document.form1;
    return myForm;
}
function getParentForm(obj) {
    if(!obj) return getMyForm();
    if(obj.tagName=="FORM") return obj;
    var myForm=obj;
    while(myForm.tagName && myForm.tagName!="FORM")
        myForm=myForm.parentNode;
    if(myForm==obj) return getMyForm();
    return myForm;
}

/*Event Yonetimi*/
function addEvent(obj,eventname,eventfunction) {
    obj=_foEventDoc(obj,eventname);
    if (obj.addEventListener) {
            obj.addEventListener(eventname, eventfunction, true);
      } else if(obj.attachEvent) {
            obj.attachEvent("on" + eventname, eventfunction);
      }
      //else set?
}
function  removeEvent(obj,eventname,eventfunction) {
    obj=_foEventDoc(obj,eventname);
    if (obj.removeEventListener) {
            obj.removeEventListener(eventname, eventfunction, true);
      } else if(obj.detachEvent) {
            obj.detachEvent("on" + eventname, eventfunction);
      }
      //else set?
}
function  sendEvent(obj,e,eventname) {
    obj=_foEventDoc(obj,eventname);
    if (document.createEvent) {
        obj.dispatchEvent(e);
      } else if(obj.fireEvent) {
        obj.fireEvent(e.eventType, e);
      }
      //else eval?
}
//formats
String.prototype.zf = function(l) { return '0'.string(l - this.length) + this; }
String.prototype.string = function(l) { var s = '', i = 0; while (i++ < l) { s += this; } return s; }
Number.prototype.zf = function(l) { return this.toString().zf(l); }
Date.prototype.IsDate=function() { return true; }
Date.prototype.format = function(f)
{
    if (!this.valueOf())
    return ' ';

    var d = this;

    return f.replace(/(yyyy|mmmm|aaaa|mmm|aaa|mm|aa|dddd|gggg|ddd|ggg|dd|gg|hh|tt|nn|kk|ss|a\/p)/gi,
            function($1)
                {
                    switch ($1.toLowerCase())
                        {
                        case 'yyyy': return d.getFullYear();
                        case 'mmmm': return gsMonthNames[d.getMonth()];
                        case 'aaaa': return gsMonthNames[d.getMonth()];
                        case 'mmm': return gsMonthNames[d.getMonth()].substr(0, 3);
                        case 'aaa': return gsMonthNames[d.getMonth()].substr(0, 3);
                        case 'mm': return (d.getMonth() + 1).zf(2);
                        case 'aa': return (d.getMonth() + 1).zf(2);
                        case 'dddd': return gsDayNames[d.getDay()];
                        case 'gggg': return gsDayNames[d.getDay()];
                        case 'ddd': return gsDayNames[d.getDay()].substr(0, 3);
                        case 'ggg': return gsDayNames[d.getDay()].substr(0, 3);
                        case 'dd': return d.getDate().zf(2);
                        case 'gg': return d.getDate().zf(2);
                        case 'hh': return ((h = d.getHours() % 12) ? h : 12).zf(2);
                        case 'tt': return ((h = d.getHours() % 12) ? h : 12).zf(2);
                        case 'nn': return d.getMinutes().zf(2);
                        case 'kk': return d.getMinutes().zf(2);
                        case 'ss': return d.getSeconds().zf(2);
                        case 'a/p': return d.getHours() < 12 ? 'a' : 'p';
                        }
                }
            );
}

function RoundDouble(Value,Round) { return (Math.round(Value*Round)/Round); }
function FormatNumber(nStr,Round) {
    if(Round && nStr) nStr=RoundDouble(nStr,Round);
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function FormatDate(DateValue,format) {
    var dt;
    if(DateValue.IsDate && DateValue.IsDate()) {
        dt=DateValue;
    }
    else {
        dt=new Date();
        dt.setTime(Date.parse(DateValue));
    }
    return dt.format(format);
}
/*Show Center Window -  Dialog*/
function ShowWindow(url,width,height,resizeable,noreturn) {
    if(!width)  width=350;
    if(!height) height=450;
    var w2=width,h2=height;
    if(w2.toString().indexOf("px")==-1) w2+="px";
    if(h2.toString().indexOf("px")==-1) h2+="px";
    var lWParams="width="+w2+",height="+h2+",scrollbars="+resizeable+",resizable="+resizeable;
    if(window.external && window.external.IsWebContent) {
        window.external.ShowWindow(url, "", "", lWParams);
        return;
    }
    
    var w=window.open(url,"",lWParams);
    w.opener=window;
    var left=(screen.availWidth-width)/2;
    var top=(screen.availHeight-height)/2;
    try{
    w.moveTo(left,top);
    w.focus();
    }
    catch (e){}
    
    if(!noreturn)
        return false;
}
function ShowDialog(url,width,height,resizeable,noreturn) {
    if(!width)  width=350;
    if(!height) height=450;
    if(window.external && window.external.IsWebContent) {
        ShowWindow(url,width,height,resizeable,noreturn);
        return;
        }
    if(!window.showModalDialog) {
        ShowWindow(url,width,height,resizeable,noreturn);
        return;
        }
    try{
        if(width.toString().indexOf("px")==-1) width+="px";
        if(height.toString().indexOf("px")==-1) height+="px";
    
        var rtn=window.showModalDialog(url,"","dialogWidth:"+width+";dialogHeight:"+height+",resizable:"+resizeable+";");
    }
    catch (e){ return; }
    if(!noreturn)
        return rtn;
}
////*************************************************************////
////* Parametre Stringi Parse eder.Array Value degerine atanir. *////
////* .Net sınıf karsiligi ile ayni calisir.                    *////
////*************************************************************////
/*for .Net ParameterParser Class*/
function ParameterParser(ParseString,SplitterChar,EqualChar) {
    this.___IsNCParameterParser=true;
    this.Splitter=SplitterChar;
    this.Equal = EqualChar;
    if(!this.Splitter) this.Splitter=";";
    if(!this.Equal) this.Equal=":";
    this.Value=new Array();
    this.Parse = function (ParameterString) {
            this.Value=new Array(); /*| add bind parameter!?*/
            if(!ParameterString) return;
            if(ParameterString.indexOf("{")==0) {
                this.Value=eval('tempjson='+ParameterString);
                return;
            }
            var notinString = "_SPLITTER_";
            while (ParameterString.indexOf(notinString) > -1)
                notinString = "_" + notinString+"_";
            while (ParameterString.indexOf(this.Splitter + this.Splitter) > -1)
                ParameterString = ParameterString.replace(this.Splitter + this.Splitter, notinString);
            var inTypes = ParameterString.split(this.Splitter);
            for (var i = 0; i < inTypes.length; i++)
                if (inTypes[i])
                {
                    var spIndex = inTypes[i].indexOf(this.Equal);
                    var tParamName = "";
                    var tParamValue = "";
                    if (spIndex > -1)
                    {
                        tParamName = inTypes[i].substr(0,spIndex);
                        spIndex++;
                        tParamValue = (inTypes[i].length - spIndex>0)?inTypes[i].substr(spIndex, inTypes[i].length - spIndex):"";
                    }
                    else
                        tParamName = inTypes[i];
                   while (tParamName.indexOf(notinString) > -1)
                            tParamName = tParamName.replace(notinString, this.Splitter);
                   while (tParamValue.indexOf(notinString) > -1)
                        tParamValue = tParamValue.replace(notinString, this.Splitter);
                    this.Value[tParamName] = tParamValue;
                }
    }
    
    this.SetInputValues = function (IncludeInputPattern,idAttribute,parentObject) {
        this._AddInputValues(parentObject?parentObject:document,IncludeInputPattern,idAttribute,true);
    }
    
    this.AddInputValues = function (IncludeInputPattern,idAttribute,parentObject) {
        this._AddInputValues(parentObject?parentObject:document,IncludeInputPattern,idAttribute);
    }
    this._AddInputValues = function (parentObject,IncludeInputPattern,idAttribute,setDom) {
        if(IncludeInputPattern==null) 
            return;
            //client uzerinde serialize.
            //.net Callback islemlerinde her browserda post edemiyor.
           //document yerine bir panel kullanımıda sağlanmalı!
           var inputs=parentObject.getElementsByTagName("INPUT");
            for(var i=0;i<inputs.length;i++)
            if(inputs[i].id && inputs[i].id.indexOf(IncludeInputPattern)!=-1 ) {
                if(inputs[i].getAttribute("type")=="button" || inputs[i].getAttribute("type")=="BUTTON" ) 
                    continue
                    var idsIn=idAttribute?inputs[i].getAttribute(idAttribute):inputs[i].id;
                if(inputs[i].getAttribute("type")=="checkbox" || inputs[i].getAttribute("type")=="CHECKBOX") {
                        if(setDom) {
                            inputs[i].checked=(this.Value[idsIn]=="1" || this.Value[idsIn]=="true");
                            if(this.Value[idsIn+"___Value"])
                                inputs[i].value=this.Value[idsIn+"___Value"];
                        }
                        else {
                            this.Value[idsIn]=inputs[i].checked?"1":"0";
                            if(inputs[i].value && inputs[i].value!="")
                                this.Value[idsIn+"___Value"]=inputs[i].value;
                            }
                        continue;
                }
                if(setDom)
                    inputs[i].value=this.Value[idsIn];
                else if(inputs[i].value && inputs[i].value!="")
                    this.Value[idsIn]=inputs[i].value;
            }
            
            inputs=document.getElementsByTagName("SELECT");
            for(var i=0;i<inputs.length;i++)
                if(inputs[i].id && inputs[i].id.indexOf(IncludeInputPattern)!=-1 &&  inputs[i].value && inputs[i].value!="") {
                var idsIn=idAttribute?inputs[i].getAttribute(idAttribute):inputs[i].id;
                 if(setDom)
                    inputs[i].value=this.Value[idsIn];//to selected index??
                 else
                    this.Value[idsIn]=inputs[i].value;
            }
    }
    

    this.ToString =function() {
        var rtn=new Array();
        var k=0;
        this.Value.AAA=function(){};
        for(var key in this.Value) 
        if(this.Value[key]!=null && typeof(this.Value[key])!="function")
            {
            var lVal=this.Value[key];
            rtn[k++]=key;
            rtn[k++]=this.Equal;
            if(lVal.substr)
                for(var j=0;j<lVal.length;j++)
                    if(lVal.substr(j,1)==this.Splitter) {
                        lVal=lVal.substr(0,j)+this.Splitter+lVal.substr(j,lVal.length-j);
                        j++;
                        }
            rtn[k++]=lVal;
            rtn[k++]=this.Splitter;
           }
       return rtn.join('');
    }
    this.Parse(ParseString);
        
}

