// Başarı' ya özel

var sKeysPressed = ""
function fKeyPress(){
	sKeysPressed += event.keyCode
}


function fAL(){
	//if(sKeysPressed == sKeys)
		window.open('_admin_login.php','adminlogin','width=100, height=165');
}

// ÜST MENU için ALTMENÜ açma/kapama
var objAktif
var objImg
var objAra
var nHaberlerPage = 1
var aMargin = new Array()
aMargin[1] = "0"
aMargin[2] = "97"
aMargin[3] = "181"
aMargin[4] = "310"
aMargin[5] = "510"
aMargin[6] = "662"
function fAltMenuOn(no,objSelf){
  fAltMenuOff()
  id = "d_MenuUstAltMenu_"+no
  obj = fGetID(id)
  if(obj){
    objImg = fGetID("d_MenuUstAltMenuAraImg")
    objAra = fGetID("d_MenuUstAltMenuAraTD")    
    obj.style.display = "block"    
    objAra.style.background = 'url("img/genel/fon_altmenu.gif")'
    objImg.width = objSelf.firstChild.width
    objImg.style.margin = "0px 0px 0px "+aMargin[no]+"px"
    //alert(objImg.style.margin)
    objImg.style.display = "block"
    objAktif = obj
  }
}

function fAltMenuOff(){
  //obj = "d_MenuUstAltMenu_"+no
  if(objAktif){
    objAktif.style.display = "none"    
    objImg.style.display = "none"
    objAra.style.background = ""
  }
}

// Anasayfadan Admin Sayfası açma
function fOpenAdminPage(key,sString){
  window.open('admin/index.php?b='+key+sString,'AdminPage','width=960,height=700,resizable=yes,scrollbars=yes')
}

// Karşılaştırma Ürün Seçimi
var nSecili = 0
var bSubmit = false
function fpKarsilastirma(obj){
  nDiff = obj.checked ? 1 : -1;
  nSecili = nSecili+nDiff
  sDurum = nSecili>0 ? "block" : "none"
  bDisabled = nSecili<4 ? false : true
  fGetID('d_KarsilastirmaOzellikler').style.display = sDurum
	n = document.FormKarsilastirma.PID.length
	for(i=0; i<n; i++)
    if(document.FormKarsilastirma.PID[i].checked!=true)
		  document.FormKarsilastirma.PID[i].disabled = bDisabled
}

// Karşılaştırma Özellik Tümü Seçimi
function fpCheckAll(obj){
  bCheck = obj.checked ? true : false;
	n = document.FormKarsilastirmaOzellikler.COL.length
	for(i=0; i<n; i++)
		document.FormKarsilastirmaOzellikler.COL[i].checked = bCheck
}

// Karşılaştırma Submit
function fpKarsilastirmaSubmit(){
  document.FormKarsilastirmaOzellikler.PIDS.value = ""
	n = document.FormKarsilastirma.PID.length
	for(i=0; i<n; i++)
    if(document.FormKarsilastirma.PID[i].checked)
		  document.FormKarsilastirmaOzellikler.PIDS.value += document.FormKarsilastirma.PID[i].value+","
      
	n = document.FormKarsilastirmaOzellikler.COL.length
	for(i=0; i<n; i++)
    if(document.FormKarsilastirmaOzellikler.COL[i].checked)
		  bSubmit = true
  if(bSubmit == true)
    document.FormKarsilastirmaOzellikler.submit()
  else
    alert("Lütfen karşılaştırma kriteri belirleyiniz")
}

function fAksesuarCheck(obj){
  if(obj.options[obj.selectedIndex].value==4)
    fGetID('d_AksesuarKategori').style.display='block'
  else{
    fGetID('d_AksesuarKategori').childNodes[1].firstChild.selectedIndex = 0
    fGetID('d_AksesuarKategori').style.display='none'
  }
}

////////////////////

// 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 fHide(sID){  
  obj = typeof(sID)=="object" ? sID : fGetID(sID)
  obj.style.display='none'
}
function fShow(sID){
  obj = typeof(sID)=="object" ? sID : fGetID(sID)
  obj.style.display='block'
}

function fEnable(ID){
  fGetID(ID).disabled = false
  fGetID(ID).className = ""
}

function fDisable(ID){
  fGetID(ID).disabled = true
  fGetID(ID).className = "disabled"
}

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 fSil(sUpdTable,sUpdKriterValue,sUpdKriterColumn){  
	if(confirm('Kaydı silmek istediğinizden emin misiniz?')){
    xajax_fxSil(sUpdTable,sUpdKriterValue,sUpdKriterColumn)
  }
  else
    return false;
}

function fSilResim(sDir,sFileName,obj,onPath){
	var onPath = onPath
  if(confirm('Resmi silmek istediğinizden emin misiniz?')){
    url = '/admin/edit/resim_sil.php?sDir='+sDir+'&sFileName='+sFileName
    //alert(url)
    edit_frame.location.href = url
    obj.removeNode(true)
  }
  else
      return false;
}

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('<param name=wmode value=transparent>')
    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+'" wmode="transparent">')
    document.write('</embed>')
    document.write('</object>')
}

function fFileSelect(obj){
  obj.style.backgroundColor='#00FF00'
}

function fESEventSet(){
  $("span[dbDATA]").attr("contentEditable",true).click(fToEdit);
  $("span[dbDATA]").blur(fFromEdit);
  $("span[dbDATA]").keypress(function(e){if(e.keyCode==27 | e.keyCode==13){$(this).blur()}});
  $("span[dbSDATA]").click(fToSelect);
  $("span[dbSDATA] select").change(fFromSelect);
  $("span[id='EditImg']").click(fToEditIMG);
  $("img[dbDATA]").click(fDurumEdit);
  $("img[dbDATA]").attr("align","absmiddle");
  $("img[dbSDATA]").click(fSil);
  $("img[dbSDATA]").attr("align","absmiddle");  
}

function fMenu(){
  ID = $(this).attr("bid")
  $('#SubMenuHolder span').hide()
  $('#SubMenuHolder').show()
  $('#Sub'+ID).show()
}

function fMenuHide(){
  $(this).hide()
  $('#SubMenuHolder').hide()
}

function fMenuUrun(){
  sDiv = $(this).attr('tab')
  $('#UrunMainHolder #Menu div').removeClass('aktif')
  $('#UrunMainHolder #Right div[tab]').hide()
  $('#UrunMainHolder #Right #'+sDiv).show()
  $(this).addClass('aktif')
}

function fIMGOrta(){
  $('#UrunMainHolder #Left #Thumbs div').removeClass("aktif")
  sSRC = $(this).children(0).attr("src").replace("thumb","orta")
  $(this).addClass("aktif")
  $('#UrunMainHolder #Left div[id=Orta]').html("<img src='"+sSRC+"'>")
}

function fIMGBig(){
  sSRC = $(this).children(0).attr("src").replace("orta","buyuk")
  $('#BigImg').html("<img src='"+sSRC+"'>")
  $('#BigImgHolder').show()
  $("#MainTable").addClass("BigIMG");
}

function fVideo(){
  w = 300
  h = 200
  file = "/img/urun/buyuk/"+$(this).attr("dbid")+"_v.swf"
  sContent = '<div><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+'">'
  sContent+= '<param name=movie value="'+file+'">'
  sContent+= '<param name=quality value=high>'
  sContent+= '<param name=wmode value=transparent>'
  sContent+= '<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+'" wmode="transparent">'
  sContent+= '</embed>'
  sContent+= '</object></div>'
  //alert(sContent)
  $('#BigImg').html(sContent)
  $('#BigImgHolder').show()
  $("#MainTable").addClass("BigIMG");
}

function fIMGBigClose(obj){
  $("#MainTable").removeClass("BigIMG");
  $(obj).hide()
}

function fHaberler(){
  sParent = $(this).attr("ID")
  if(sParent=="right"){
    nHaberlerPage++;
    $("#left").show()
  }
  else
    nHaberlerPage--  
  xajax_fxHaberler(nHaberlerPage,sParent)
}

function fTelefonumuBulOpenClose(bMenu){
  sClass = $('#Butonlar #Bul').attr('class')
  if(sClass=="DL" || bMenu){    
    $('#MainTable').addClass('BigIMG')
    $('#Butonlar #Bul').addClass('aktif')
    $('#Butonlar #Haberler').removeClass('aktif')
    $('#TelefonumuBulHolder').slideDown('slow')
  }
  else{
    $('#MainTable').removeClass('BigIMG')
    $('#Butonlar #Bul').removeClass('aktif')
    $('#Butonlar #Haberler').addClass('aktif')
    $('#TelefonumuBulHolder').slideUp('slow')
  }
}

function fTelefonumuBulKriterOpenClose(){
  ID = $(this).attr('dbid')
  if($("#Grup #"+ID).attr('class')=="DN"){
    $(this).html("&#9650;")
    $("#Grup #"+ID).removeClass("DN")
  }
  else{
    $(this).html("&#9660;")
    $("#Grup #"+ID).addClass("DN")
  }
}

function fTelefonumuBulKriterCheck(){
  ID = $(this).attr("dbid")
  sel = $(this).attr("selected")
  if(sel=="false"){
    sel_new = "true"
    $(this).addClass("aktif")
    $(this).children("input").attr("checked",true)
  }
  else{
    sel_new = "false"
    $(this).removeClass("aktif")
    $(this).children("input").attr("checked",false)
  }
  $(this).attr("selected",sel_new)
  
  var $checked = $("#TelefonumuBulHolder #Grup ul li[selected='true']");
  var aID = new Array()
  $checked.each(function(){aID.push($(this).attr('dbid'))})
  sIDs = aID.join(',')
  //alert(ID)
  xajax_fxTelefonumuBul(sIDs)
}

function fTelefonumuBulAddEvents(){
  $('div[id=add]').click(fToKarsilastir);
  $('div[id=add]').html("<img src='/img/page/add.gif'>");
  $('div[id=add]').attr("title","Karşılaştırmaya Ekle");
  $('div[id=thumb]').click(fTelefonumuBulUrunOzet);
}

function fTelefonumuBulUrunOzet(){
  /*
  ID = $(this).parent().attr("id").replace("Urun_","")
  location.href('/urun.php?ID='+ID)
  */
  $('div[id=ozet]').hide()
  ID = $(this).parent().attr("id").replace("Urun_","")
  if(!$('#Urun_'+ID).hasClass('off')){
    xajax_fxTelefonumuBulUrunOzet(ID)
  }
}
function fTelefonumuBulUrunOzetClose(){
  $('div[id=ozet]').hide()
}

function fToKarsilastir(){
  $obj = $(this).parent()
  $objClone = $obj.clone()
  $objClone.children("[id=add]").html("<img src='/img/page/remove.gif' title='Karşılaştırma Listemden Çıkar'>")
  $objClone.children("[id=add]").click(fFromKarsilastir)
  $objTo = $('#TelefonumuBulHolder #KarsilastirHolder  div[id=Results]')
  $objTo.append($objClone)
  $('#p_KarsilastirmaIDs').val($('#p_KarsilastirmaIDs').val()+","+$objClone.attr("id"))
  $('#KarsilastirHolder #Results p').hide();
  if($objTo.children("div").length>1)
    $('#formKarsilastir').slideDown('slow');
  if($objTo.children("div").length==4)
    $('#TelefonumuBulHolder > #Results div[id=add]').hide()    
  $obj.hide('slow')
}

function fFromKarsilastir(){
  $obj = $(this).parent()
  ID = $obj.attr("id")
  $('#TelefonumuBulHolder #Results #'+ID).show('slow')
  $objTo = $('#TelefonumuBulHolder #KarsilastirHolder  div[id=Results]');
  $obj.remove()
  if($objTo.children("div").length<1)
    $('#KarsilastirHolder #Results p').show();
  if($objTo.children("div").length<2)
    $('#formKarsilastir').slideUp('slow');

  if($objTo.children("div").length<4)
    $('#TelefonumuBulHolder > #Results div[id=add]').show()
  $('#p_KarsilastirmaIDs').val($('#p_KarsilastirmaIDs').val().replace(","+ID,""))
}

function fBSMenu(){
  $('#d_BS_Holder #d_UserMenu div').removeClass("aktif")
  $(this).addClass("aktif")
}

function fLookup(){
  sInput = $(this).val()
  if(sInput.length == 0)
    $('#TabbedHolder [id=SearchSuggestBox]').hide();
  else
    xajax_fxSearchSuggest(sInput);
}

$(document).ready(function(){
  $('#MainUrunlerHolder [id=img]').supersleight()
  $('#Menu a[href="#"]').mouseover(fMenu)
  $('#SubMenuHolder span').mouseleave(fMenuHide)
  $('#HaberlerContentHolder #Left img,#HaberlerContentHolder #Right img').click(fHaberler)
  $('#SubMenuHolder span div').hover(function(){$(this).addClass('aktif')},function(){$(this).removeClass('aktif')})
  $('#UrunMainHolder #Menu div').click(fMenuUrun)
  $('#UrunMainHolder #Left #Orta').click(fIMGBig)
  $('#UrunMainHolder #Left #Thumbs div[id=Thumb]').click(fIMGOrta)
  $('#UrunMainHolder #Left #Thumbs div[id=ThumbVideo]').click(fVideo)
  $('#TelefonumuBulHolder #Grup b').click(fTelefonumuBulKriterOpenClose)
  $('#TelefonumuBulHolder #Grup ul li').click(fTelefonumuBulKriterCheck)
  $('#TelefonumuBulHolder #Grup ul li').attr("selected","false")
  $('#TelefonumuBulHolder #Grup ul li').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')})
  $('#TabbedHolder #Butonlar #Bul').click(fTelefonumuBulOpenClose)  
  $('#d_BS_Holder #d_UserMenu div').click(fBSMenu)
  $("#formUrunArama #p_keyword").keyup(fLookup);
  fTelefonumuBulAddEvents()
  //fESEventSet()
}
);
