
            /*          alert(DOM("abu").value);   yada  alert(DOM("container","container2")[1].innerHTML);
                        amacina isteyen hemen ulassin diye.           */
// Amaç:
// Bu html dosyasinda ki elementlere kolay erisim için yazilmis bir tooldur.
// Aldigi parametreyi dosya içinde arar ve buldugu ID leri parametreyle ayni olan elementleri
// bir array haline getirerek kullaniciya döndürür.
// Örnek Kullanim:
// DOM("span_element").innerHTML;
// DOM("form_element").value;
// Yada DOM("span_element", "span_element2")[0].innerHTML; seklinde olabilir
// her islem için kullanilabilir.
// DOM("div_element").style.visibity='hidden';  gibi

function multipleSelect(sl){
    var result="";
    if(! sl.options) return sl.value;
    var t= sl.options.length;
    for(var i=0, j=0; i<t ; i++){
        if(sl.options[i].selected==true){
            result += "<<"+j+">>"+sl.options[i].value+"<</"+j+">>";
            j++;
        }
    }
    //alert(result);
    return result;
}
function selectSec(dom, index){
    if(dom.options[index].selected)
              dom.options[index].selected=false;
        else dom.options[index].selected=true;
}

 function concatObj (ar1, ar2) {
        for(i in ar2){
                ar1[i] = ar2[i];
        }
        return ar1;
 }

 function getAllForm(formName){
    var arr= new Array;
//    var form = DOM(formName);
    var form = document.forms[formName];
    for(i=0;i<form.length; i++){
        if(form[i].name){// alert(form[i].name+': '+form[i].value);
        if(form[i].multiple)
            arr[form[i].name] =  multipleSelect(form[i]);
            else arr[form[i].name] = form[i].value;
      }
    }

    return arr;
 }

function FCKeditor_OnComplete( editorInstance )
{
    var oCombo = document.getElementById( 'cmbSkins' ) ;

    // Get the active skin.
    var sSkin = editorInstance.Config['SkinPath'] ;
    sSkin = sSkin.match( /[^\/]+(?=\/$)/g ) ;

    oCombo.value = sSkin ;
    oCombo.style.visibility = '' ;
}

function ChangeSkin( skinName )
{
    window.location.href = window.location.pathname + "?Skin=" + skinName + "&link=zumre_ekle" ;
}
function DOM() {
   var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
         var element = arguments[i];
         if (typeof element == 'string')
           element = document.getElementById(element);
         if (arguments.length == 1)
             return element;
         elements.push(element);
     }
   return elements;
}

        var http = getHTTPObject(); // We create the HTTP Object
        function goServer(string) {
            string=arrayToString(string);
            http.open('POST', 'serve.php'); // many server-side scripts require the Content-Type to be set:
            http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-9');
            post_text = 'string='+string+'';
            http.onreadystatechange = handleHttpResponse;                //   alert( post_text);
            http.send(kodla(post_text));
        }

         /*
         function go(string) {
            string=arrayToString2(string);
            http.open('POST', 'uye_server.php', true); // many server-side scripts require the Content-Type to be set:
            http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-9');
            post_text = 'string='+string+'';
            http.onreadystatechange = handleHttpResponse;                  //alert( kodla(post_text));
            http.send(kodla(post_text));

         }

        function handleHttpResponse() {
            if (http.readyState == 4) {                                 //    alert(coz(http.responseText));
                sonuc = stringToArray(coz(http.responseText));
                            // gelen text bölünerek vdeğişkenler elde ediliyor.
                            // değişkenler sonuc[0].. sonuc[4]e arası. Ayrıntı için libraryden stringToArray  fonksyonuna bakın.

                // Serverdan gelen scripti çalıştırıyoruz burada
            if(sonuc[1]=="err"){
            alert(sonuc[2]);
          }
                if(sonuc[3]){  eval(sonuc[3]);   }


            }//if ready
        }//handle function
        */
        function xmlSelectLoader(){
                var txt = sonuc[5];
                var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
                xmlDocument.async='false';
                xmlDocument.loadXML(txt);                       // var xmlDocument = http.responseXML;
                                                                // eğer sonu XML olarak gelseydi direk XML olarak alabilirdik.
                                                                // Ancak biz text olarak sonuç döndürdük.
                                                                // dönen textte paramtertlerin 6.sı XML olduğu için onu XML'e çevirdik
                var tagname    = xmlDocument.getElementsByTagName('item');
                var totalnum = tagname.length;
                if (totalnum>0) {
                    var box_name        = xmlDocument.getElementsByTagName('collection').item(0).getAttribute('name');                    //alert(box_name);
                    var box_name_select = document.getElementById(box_name);                    //alert(box_name_select);
                    var option_id, option_label, i;
                    clearTopicList(box_name_select);
                    for (i=0; i< totalnum; i++) {
                        option_label = tagname.item(i).getAttribute('label');
                        option_id = tagname.item(i).getAttribute('value');
                        appendOptionLast(box_name_select,option_label,option_id);
                    }
                }//if
        }

function mstr_replace(t, u, s) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += mstr_replace(t, u, s.substring(i + t.length, s.length));
  return r;
}

function coz( coded_string ){// İıŞşĞğÜüÇçÖö
    coded_string  = mstr_replace("*(i)*", "ı", coded_string);
    coded_string  = mstr_replace("*(I)*", "İ", coded_string);
    coded_string  = mstr_replace("*(s)*", "ş", coded_string);
    coded_string  = mstr_replace("*(S)*", "Ş", coded_string);
    coded_string  = mstr_replace("*(g)*", "ğ", coded_string);
    coded_string  = mstr_replace("*(G)*", "Ğ", coded_string);
    coded_string  = mstr_replace("*(u)*", "ü", coded_string);
    coded_string  = mstr_replace("*(U)*", "Ü", coded_string);
    coded_string  = mstr_replace("*(c)*", "ç", coded_string);
    coded_string  = mstr_replace("*(C)*", "Ç", coded_string);
    coded_string  = mstr_replace("*(o)*", "ö", coded_string);
    coded_string  = mstr_replace("*(O)*", "Ö", coded_string);
    return coded_string;

}

function kodla( coded_string ){   // İıŞşĞğÜüÇçÖö
    coded_string  = mstr_replace("ı", "*(i)*", coded_string);
    coded_string  = mstr_replace("İ", "*(I)*", coded_string);
    coded_string  = mstr_replace("ş", "*(s)*", coded_string);
    coded_string  = mstr_replace("Ş", "*(S)*", coded_string);
    coded_string  = mstr_replace("ğ", "*(g)*", coded_string);
    coded_string  = mstr_replace("Ğ", "*(G)*", coded_string);
    coded_string  = mstr_replace("ü", "*(u)*", coded_string);
    coded_string  = mstr_replace("Ü", "*(U)*", coded_string);
    coded_string  = mstr_replace("ç", "*(c)*", coded_string);
    coded_string  = mstr_replace("Ç", "*(C)*", coded_string);
    coded_string  = mstr_replace("ö", "*(o)*", coded_string);
    coded_string  = mstr_replace("Ö", "*(O)*", coded_string);
    return coded_string;
}



function getHTTPObject() { /*Bu fonksyon için eser sahillioğlu' na teşekkür. */
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      xmlhttp.overrideMimeType("text/xml");
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}



function arrayToString(parametreler){
    str= "";
    c=false;
    for( i=0; i < parametreler.length; i++){
    if(c) str=str+",,,";
    else c=true;
    str = str+ parametreler[i][0] + "-=>" +parametreler[i][1];
    }
    return str;
}

function stringToArray(myString){
    // Düşünülen, ajaxtan dönen parametrelerin sabit olmasıdır.
     // Bu göre ajaxtan dönen her zaman 6 parametre olur
     //             islem_tipi,,,sonuc_OK_yada_ERROR,,,sonuc_yada_error_kodu,,,donen_parametre,,,türkçe_karakterleri_kodlanmış_sonuc_metini,,,calısacak_javascript_kodu,,,scripte_iliskin_bilgi_yada_ilerde_kullanılamk_uzere_dusunulmus_alan
    // Örneğin:        sehirEkle,,,OK,,,OK,,,411,,,*(*S*)*ehir listesine *(C)*ar*(s)*amba eklenmi*(s)*tir.
    // Örnek II:    sehirEkle,,,ERROR,,,ERRSHREKLE_001,,,411,,,*(C)*ar*(s)*amba *(s)*ehiri daha *(o)*nceden eklenmi*(s)*tir.
    // Sonuc[0]=islem_tipi : küçük harflerle yazılmış kelimeler _ ile birbirinden ayrılmıştır.
    // Sonuc[1]=sonuc_kodu İstenen : İşlemin gerçekleşip gerçekleşmemesine göre OK yada ERROR olacaktır
    // Sonuc[2]=sonuc_yada_error_kodu  : ERROR verildiğinde ERROR'un numarası yada kodu olacaktır. OK sonuçlarında OK dönecektir. Yada bış alan olarak kullanılabilecektir.
    // Sonuc[3]=serverdan yükleme tamamlandığında çalışacak Javascript olacaktır. Bu bir alanı güncellemek olabilir.
    // Sonuc[4]=anlatım: serverdan kulanıcıya gelen mesajdır.
    // Sonuc[5]=donen_parametre : Herhangi bir durumda kullanılmak üzere parametre için ayrılmıştır. Örneğin seçilen şehirin ID numarasını göstermek için kullanılabilir.
    // Sonuc[6]=ilerisi için düşünülmüş boş alandır. Yada scriptlerle ilgili kullanılabilir.
    return myString.split(",,,");
}

function clearSelect(name) {
    var select_box = document.getElementById(name);
    clearTopicList(select_box);
}

function appendOptionLast(box_name_select,optlabel,optvalue) {
    var new_option = document.createElement('option');
    new_option.text = optlabel;
    new_option.value = optvalue;
    try {
        box_name_select.add(new_option, null); // standards compliant; doesn't work in I
    }
      catch(ex) {
        box_name_select.add(new_option); // IE only
      }
}
function clearTopicList(box_name) {
    while (box_name.length > 0)
       box_name.remove(0);
}
function setID(list, value){
    for(i=0; i<list.length; i++){
        if(list.options[i].value== "-1"){
            list.options[i].value=value;
            list.options[i].selected=true;
            break;
        }
    }
    return list.options[i];
}
function MM_swapImgRestore() { //v30
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
