// VARIABLES
var mEditableContent="";
aDurumDefault = new Array()
aDurumDefault["menu"] = "none"
aDurumDefault["edit"] = "none"

aDurum = new Array()
aDurum["none"] = "block"
aDurum["block"] = "none"

aBranchID = new Array()
aBranchID["none"] = "branch_open"
aBranchID["block"] = "branch_close"

aImgName = new Array()
aImgName["block"] = "branch_open"
aImgName["none"] = "branch_close"

function SHMenu(oOk){  

  ID = oOk.nodeType==1 ? oOk.parentNode.id : oOk

  nIDLength = ID.length+3

  obj = document.getElementById(ID)

	oMenu = obj.parentNode

	nMenuItemNo = oMenu.childNodes.length  

	for(i=0; i<nMenuItemNo; i++){

		objChild = oMenu.childNodes[i]

		if(objChild.nodeType==1){

			if(objChild.id.match('\\'+ID+'-')){

        //oOkChild = document.getElementById(objChild.id.replace('MI','ok'))

        oOkChild = objChild.firstChild

        sDurum = objChild.style.display ? objChild.style.display : "none"

        if(sDurum=="block")

            objChild.style.display = aDurum[sDurum]

        else

            if(objChild.id.length==nIDLength)        

			        objChild.style.display = aDurum[sDurum]        

        SHMenuChangeImg(oOkChild,sDurum)

			}

		}            

	}

  SHMenuChangeImg(oOk,aDurum[sDurum])

  //xajax_fxClick('arti')

}
function CLink(ID){

  xajax_fxClick('link')

  location.href='list.php?catID='+ID  

}
function SHMenuFindActive(ID){

  obj = fGetID('MI_'+ID).firstChild

  if(obj.tagName=="SPAN")

    obj = obj.nextSibling

  obj.style.color='#FF8000'

}
function SH(div,durum){

    fGetID(div).style.display = durum

}
function fOnOff(div){

  obj = fGetID(div)

  durum = obj.style.display

  if(durum=="none")

    obj.style.display="block"

  else

    obj.style.display="none"  

}
function SHMenuChangeImg(obj,durum){

  if(obj.tagName=="SPAN")

    obj.style.backgroundImage="url(img/alan_sol/"+aImgName[durum]+".gif)"

}
function SepeteAt(PID){

	siparis_sepeti_frame.location.href='inc/siparis_sepeti_frame.php?PID='+PID

}

function fHaberVer(PID,tip,obj){

	if(PID)

		diger_frame.location.href='inc/anasayfa/frame_gelince_haber_ver.inc.php?PID='+PID+'&t='+tip

		obj.style.display='none'

}
function fYorumDogruYanlis(ID,t){

	diger_frame.location.href='inc/urun/frame_yorum_dogru_yanlis.inc.php?ID='+ID+'&t='+t

}
function fOpsiyonSH(obj,divOn,divOff){

  SH(divOn+"Alan","block")

  //fGetID(divOn+"Img").src='img/liste_'+divOn+'Alan'+'_'+fGetID(divOn+"Alan").style.display+'.gif'

  SH(divOff+"Alan","none")

  //fGetID(divOff+"Img").src='img/liste_'+divOff+'Alan'+'_'+fGetID(divOff+"Alan").style.display+'.gif'  

  fGetID(divOn+"Alan").blur()

}
function fTakvim(obj){

    window.open('edit/single_tarih.php?obj='+obj,'','width=210,height=240,resizable=yes')

}
function fSepetAdresSame(obj){

    durum = obj.checked ? 'none' : 'block'

    obj.previousSibling.style.display = durum

}
function fSepetAdresSameTemp(obj){

    durum = obj.checked ? 'none' : 'block'

    obj = obj.parentNode.parentNode.parentNode.nextSibling

    obj.style.display = durum

    obj.nextSibling.style.display = durum        

}
function fSepetOdemeTipiHavale(){

    SH('idHavale','block')

    SH('idKrediKarti','none')

    SH('idSubmit','block')

    SH('idKrediKartiOdeme','none')

}
function fSepetOdemeTipiKrediKarti(){

    SH('idHavale','none')

    SH('idKrediKarti','block')

    SH('idSubmit','none')

}
function fSepetOdemeTipiKrediKartiSecim(obj){

    for(i=1000; i<1040; i++)

        if(fGetID('idKrediKartiTablo_'+i))

            SH('idKrediKartiTablo_'+i,"none")    

    if(fGetID('idKrediKartiTablo_'+obj.value))

        SH('idKrediKartiTablo_'+obj.value,"block")

    if(obj.value==1021){

        SH('idSubmit','block')

        SH('idKrediKartiOdeme','block')

        fGetID('idKrediKartiOdenecekTutar').innerHTML = fGetID('idKrediKartiOdenecekTutarOrjinal').value

        form_siparis_sepeti.orders_price_paid.value = fGetID('idKrediKartiOdenecekTutarOrjinal').value

        fGetID('idKrediKartiOdenecekTaksit').innerHTML = "0"

        fGetID('idKrediKartiOdenecekAylik').innerHTML = "0"

        form_siparis_sepeti.orders_price_taksit.value = "0"

    }

    else{

        SH('idSubmit','none')

        SH('idKrediKartiOdeme','none')

    }

}
function fSepetOdemeTipiKrediKartiTaksitSecim(obj,objParent){

    if(obj.value>0){

        nToplam = obj.parentNode.nextSibling.nextSibling.nextSibling.innerHTML

        nTaksit = obj.parentNode.nextSibling.innerHTML

        nAylik = obj.parentNode.nextSibling.nextSibling.innerHTML

        fGetID('idKrediKartiOdenecekTutar').innerHTML = nToplam

        document.form_siparis_sepeti.orders_price_paid.value = nToplam

        fGetID('idKrediKartiOdenecekTaksit').innerHTML = nTaksit

        fGetID('idKrediKartiOdenecekAylik').innerHTML = nAylik

        document.form_siparis_sepeti.orders_price_taksit.value = nAylik

    }

    else {

        nToplam = obj.parentNode.nextSibling.nextSibling.innerHTML

        fGetID('idKrediKartiOdenecekTutar').innerHTML = nToplam

        document.form_siparis_sepeti.orders_price_paid.value = nToplam

        fGetID('idKrediKartiOdenecekTaksit').innerHTML = "0"

        fGetID('idKrediKartiOdenecekAylik').innerHTML = "0"        

        document.form_siparis_sepeti.orders_price_taksit.value = "0"

    }

    SH('idKrediKartiTablo_'+objParent,'none')

    SH('idKrediKartiOdeme','block')

    SH('idSubmit','block')

}

////////////////////

// VARIABLES

// FUNCTIONS

function fGetID(ID){

    return document.getElementById(ID)

}
function Jump(sayfa,deger,obj){

    if(obj.options[obj.selectedIndex].value)

        eval("self.location='"+sayfa+"?"+deger+"="+obj.options[obj.selectedIndex].value+"'")

}
function 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 ShowHide(oDiv,id){

    oDiv = id ? FindObj(oDiv) : oDiv

    durum = oDiv.style.display

	oDiv.style.display = (durum == "none" || !durum) ? "block" : "none"

	return false;

}
function Dialog(sayfa,tablo,kolon,kriter,id,obj,width,height){

    sayfa = "edit/"+sayfa+".php?tablo="+tablo+"&kolon="+kolon+"&kriter="+kriter+"&id="+id

    params = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no"

    return_value = showModalDialog(sayfa,obj,params);

    return false

}
function DialogSimple(sayfa,obj,width,height){

    params = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;help:no;scroll:no;status:no"

    return_value = showModalDialog("edit/"+sayfa+".php",obj,params);

    return false

}
function Focus(obj){

    prev_back = obj.parentNode.style.backgroundColor

    obj.parentNode.style.backgroundColor = "#FFCC00"

}
function Blur(obj){

    obj.parentNode.style.backgroundColor = prev_back

}
function fFocus(obj){    

    obj.style.backgroundColor = "#FFFFC0"

}
function fBlur(obj){

    obj.style.backgroundColor = "#FFFFFF"

}
function fSil(tablo,id,obj,kriter){

	if(confirm('Kaydı silmek istediğinden eminmisin..!?')){

    	edit_frame.location.href='edit/single_sil.php?tablo='+tablo+'&kriter='+kriter+'&id='+id

        obj.removeNode(true)

    }

    else

        return false;

}
function fSilCift(tablo,id,obj,kriter){

	if(confirm('Kaydı silmek istediğinden eminmisin..!?')){

        if(confirm('SON KARARIN..!?')){

    	    edit_frame.location.href='edit/single_sil.php?tablo='+tablo+'&kriter='+kriter+'&id='+id

            obj.removeNode(true)

        }

    }

    else

        return false;

}
function fSilResim(sDir,sFileName,obj,onPath){

	var onPath = onPath

    if(confirm('Resmi silmek istediğinizden emin misiniz?')){

        edit_frame.location.href=onPath+'edit/resim_sil.php?sDir='+sDir+'&sFileName='+sFileName

        obj.removeNode(true)

    }

    else

        return false;

}
function fResimEdit(ID,no){
  window.open('edit/resim_edit_v2.php?ID='+ID+'&no='+no,'','width=350,height=200')
}
function FlashGoster(file,w,h){

    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+w+'" height="'+h+'">')

    document.write('<param name=movie value="'+file+'">')

    document.write('<param name=quality value=high>')

    document.write('<embed src="'+file+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'">')

    document.write('</embed>')

    document.write('</object>')

}
function FlashGoster9(file,w,h){

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+w+'" height="'+h+'">')

    document.write('<param name=movie value="'+file+'">')

    document.write('<param name=quality value=high>')

    document.write('<embed src="'+file+'" quality=high pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'">')

    document.write('</embed>')

    document.write('</object>')

}
function fToEditGenel(obj,sTable,sKolonValue,mKriter,sKolonKriter){

    mEditableContent = obj.innerText

    objParent = obj.parentNode

    objParent.innerHTML = "<span id=\"d_Editable\" contentEditable=true onBlur=\"fToUnEditGenel(this,'"+sTable+"','"+sKolonValue+"','"+mKriter+"','"+sKolonKriter+"')\">"+mEditableContent+"</span>"

    objParent.firstChild.focus()

}
function fToUnEditGenel(obj,sTable,sKolonValue,mKriter,sKolonKriter){    

    objParent = obj.parentNode

    mValue = obj.innerText

    mNewContent = (mEditableContent != mValue) ? mValue : mEditableContent

    if(mEditableContent != mValue)

        xajax_fxSingleEdit(sTable,sKolonValue,mValue,mKriter,sKolonKriter)    

    objParent.innerHTML = "<a href=\"#\" onClick=\"fToEditGenel(this,'"+sTable+"','"+sKolonValue+"','"+mKriter+"','"+sKolonKriter+"'); return false\" title=\"Değiştir\" class=\"AdmGenel AdmEdit\">"+mValue+"</a>"

}
function fLookup(){  
  sInput = $(this).val()
  if(sInput.length == 0)
    $('#suggestionsBox').hide();
  else
    xajax_fxSearchSuggest(sInput);
}
function fLookupFill() {
  $('#inputString').val($(this).text());
  //$('#suggestionsBox').hide();
}

function fSepeteAt(){
  $("#SSContent").html('<img src="/img/wait.gif">')
  function fGO(){
    xajax_fxSepeteAt(ID)
    $(objClone).remove()
  }
  ID = $(this).attr("dbID")
  objTable = $(this).closest("#UrunTable")
  objTablePos = $(objTable).position()  
  objSepetPos = $("#SSHolder").position()
  objClone = $(objTable).clone().css({'position':'absolute','width':objTable.width(),'border':'2px solid #FF8000','top':objTablePos.top,'left':objTablePos.left})
  $("[id=AltTD],[id=SepeteAt]",objClone).remove()
  $('body').scrollTo($("#SSHolder"), 800, { easing:'swing', axis:'y', offset:-12 } );
  $(objClone).appendTo($(objTable).parent()).animate({opacity:0.5,width:$("#SSHolder").width(),top:objSepetPos.top,left:objSepetPos.left},800,fGO);
}

$(document).ready(function(){
  $("[id=SepeteAt]").click(fSepeteAt);
  $("img[PID]","#UrunListTable").hover(function(e){
    PID = $(this).attr("PID")
    //$(this).after("<img class='imgMidiPopup'>")
    $("<img class='imgMidiPopup'>").appendTo("body")
    $(".imgMidiPopup").attr("src","img/urunler/o/"+PID+"-1.jpg")
    $(".imgMidiPopup").css("left",$(this).offset().left+45)
    $(".imgMidiPopup").css("top",$(this).offset().top)
    $(".imgMidiPopup").show()
  },
  (function(){
   $(".imgMidiPopup","body").remove()
  })
  );
  $("#inputString").keyup(fLookup);
});


