// JavaScript Document
function cnfrm(x)
{
	//var sp = /MSIE ((5\.5)|[6789])/.test(navigator.userAgent);
	//if (sp) 
	//{
	//	var obj = new Object();
	//	obj.status = false;
	//	obj.msj = x;
	//	var params = 'dialogWidth:300px;dialogHeight:100px;help:no;'
	//	params += "scroll:no;"
	//	params += "status:no;"
	//	window.showModalDialog(AFR.get_path("cnfrm.html?" + randomNumber(50000)), obj, params);
	//	return obj.status;
	//}
	//else 
	return confirm(x);
}
function defaultInputValue(e,oId,defaulText)
{
	var elem = $(oId);
	var value = elem.val();
	if(e.type=='mouseover' && value!=defaulText){elem.trigger("focus");}
	else if(e.type=='mouseover' && value==defaulText){elem.val('');elem.trigger("focus");}
	else if(e.type=='focus' && value==defaulText){elem.val('');}
	else if(e.type=='mouseout' && AFR.isNull(value)){elem.val(defaulText);elem.trigger("blur");}
	else if(e.type=='mouseout' && !AFR.isNull(value)){elem.trigger("blur");}
	else if(e.type=='blur' && AFR.isNull(value)){elem.val(defaulText);}
}
function fontSize(elem,size)
{
	$('#news_detail').removeClass();
	$('#news_detail').addClass('content_'+size);	
	$('.sirift').find('A').removeClass('over');
	$(elem).addClass('over');
}
function greElemIns(elem,html)
{
	elem = elem.parentNode;
	var div = elem.getElementsByTagName('span');
	if(div[0])
	{
		if(html!="" && html!=null){div[0].innerHTML=html;}
		else {div[0].parentNode.removeChild(div[0]);}
	}
	else
	{
		if(html!="" && html!=null)
		{
			var ndiv = document.createElement("span");
			ndiv.innerHTML=html;
			elem.appendChild(ndiv);
		}
	}
}
function set_err_msj()
{
	document.getElementById("err_msj").innerHTML="";
	document.getElementById("divErrMsj").style.display="none";
}
function err_msj(str,elem)
{
	if(typeof(elem)=="object"){greElemIns(elem,str);return;}
	document.getElementById("err_msj").innerHTML += ' - ' +str +'<br>' ;
	document.getElementById("divErrMsj").style.display="";
	document.getElementById("divErrMsj").focus();
	location.href='#err_sellect';
}
$(document).ready(function()
{
	//if(AFR.browser.ie)$.each($('a[href*=p=]'),function(i,v){linkleriajax(v);})
});
var myHistory = new Array();
function linkleriajax(v)
{
	$(v).click(function()
	{
		var self = $(this); 
		var url = self.attr('href');
		if(url.indexOf('doit=de')!=-1)
		{
			var del = cnfrm('Silmek istediğinize emin misiniz?');
			if(!del)return false;
		}
		url = url.substring(url.indexOf('?')+1, url.length);
		url = AFR.replace('&charset=1','',url);
		//$.history.add(url);
		url = AFR.get_path('ajax.php?'+url+'&charset=1');
		$.ajax({type:"GET",url:url,dataType: "html",
		   beforeSend: function(){
			 $('#centerContent').html(AFR.loading('centerContent'));
		   },
		   success: function(data){
			  data = AFR.replace('form.submit();','postForm(form);',data); 
			  data = AFR.replace('onClick="return cnfrm','onClick="return false;cnfrm',data); 
			  $('#centerContent').html(data);
			  $.each($('#centerContent').find('a[href*=p=]'),function(i,v){linkleriajax(v);})
			  $.each($('#centerContent').find('form'),function(i,v){if(AFR.isNull($(v).attr('action')))$(v).attr('action',self.attr('href'));});
		   }
		 });
		return false;
	});	
}
function postForm(form)
{
	var url = $(form).attr('action');
	url = url.substring(url.indexOf('?')+1, url.length);
	url = AFR.replace('&charset=1','',url);
	url = AFR.get_path('ajax.php?'+url+'&charset=1');
	$.each($(form).find('select'),function(i,v){$(v).replaceWith('<input type="hidden" name="'+$(v).attr('name')+'" value="'+v.value+'">');});
	$.ajax({type:"POST",url:url,dataType: "html",data: $(form).serialize(), 
		   beforeSend: function(){
			 $('#centerContent').html(AFR.loading('centerContent'));
		   },
		   success: function(data){
			  data = AFR.replace('form.submit();','postForm(form);',data); 
			  data = AFR.replace('onClick="return cnfrm','onClick="return false;cnfrm',data); 
			  $('#centerContent').html(data);
			  $.each($('#centerContent').find('a[href*=p=]'),function(i,v){linkleriajax(v);})
			  $.each($('#centerContent').find('form'),function(i,v){if(AFR.isNull($(v).attr('action')))$(v).attr('action',url);});
		   }
		 });
}


function openDialog(url, width, height) 
{
	var params = ''
	params = "left="+((screen.width/2)-(width/2))+","
	params += "top="+((screen.height/2)-(height/2));
	win=window.open(url,"asd","toolbar=0,directories=0,menubar=0,status=0,width="+width+",height="+height+",resizable=0,scrollbars=0,"+params);
	win.focus();
	return win
}
function resim_ekle(x)
{
	if(!document.getElementById("Layer_" + x))
	{
		var objBody = document.getElementsByTagName("body").item(0);
		var idiv = document.createElement("DIV");
		idiv.setAttribute('id','Layer_' + x);
		idiv.style.display = 'none';
		idiv.className='imgDivClass';
		objBody.appendChild(idiv);
	}
	openDialog("upload.php?r=" + x, 720, 430); 
}
function dosya_ekle(x)
{
	openDialog("fupload.php?r=" + x, 720, 430); 
}
function insertMyFile(opener_id,y,z)
{
	document.getElementById(opener_id).value=y;
	document.getElementById(opener_id + '_id').value=z;
}
function over_img(x)
{
	if(document.all)getMouseLoc();
	if(!document.getElementById("Layer_" + x))
	{
		var objBody = document.getElementsByTagName("body").item(0);
		var idiv = document.createElement("DIV");
		idiv.setAttribute('id','Layer_' + x);
		idiv.style.display = 'none';
		idiv.className='imgDivClass';
		objBody.appendChild(idiv);
	}
	if(!AFR.isNull($D(x+'_id').value))$D("Layer_" + x).innerHTML='<img src="/img/thm/'+$D(x+'_id').value+'">';
	if(document.getElementById("Layer_" + x).innerHTML!="" && document.getElementById("Layer_" + x).innerHTML!=null)
	{
		document.getElementById("Layer_" + x).style.left=AFR.mLoc.x + 10;
		document.getElementById("Layer_" + x).style.top=AFR.mLoc.y + 10;
		document.getElementById("Layer_" + x).style.display="block";
	}
}
$(window).mousemove(function(e){getMouseLoc(e);});
function out_img(x)
{
	document.getElementById("Layer_" + x).style.display="none";
}
function insertMyImg(opener_id,x,y,z)
{
	document.getElementById('Layer_' + opener_id).innerHTML=x;
	document.getElementById(opener_id).value=y;
	document.getElementById(opener_id + '_id').value=z;
}



/**
 * jQuery history event v0.1
 * Copyright (c) 2008 Tom Rodenberg <tarodenberg gmail com>
 * Licensed under the GPL (http://www.gnu.org/licenses/gpl.html) license.
 */
(function($) {
    var currentHash, previousNav, timer, hashTrim = /^.*#/;

    var msie = {
        iframe: null,
        getDoc: function() {
            return msie.iframe.contentWindow.document;
        },
        getHash: function() {
            return msie.getDoc().location.hash;
        },
        setHash: function(hash) {
            var d = msie.getDoc();
            d.open();
            d.close();
            d.location.hash = hash;
        }
    };

    var historycheck = function() {
        var hash = msie.iframe ? msie.getHash() : location.hash;
        if (hash != currentHash) {
            currentHash = hash;
            if (msie.iframe) {
                location.hash = currentHash;
            }
            var current = $.history.getCurrent();
            $.event.trigger('history', [current, previousNav]);
            previousNav = current;
        }
    };

    $.history = {
        add: function(hash) {
            hash = '#' + hash.replace(hashTrim, '');
            if (currentHash != hash) {
                var previous = $.history.getCurrent();
                location.hash = currentHash = hash;
                if (msie.iframe) {
                    msie.setHash(currentHash);
                }
                $.event.trigger('historyadd', [$.history.getCurrent(), previous]);
            }
            if (!timer) {
                timer = setInterval(historycheck, 100);
            }
        },
        getCurrent: function() {
            return currentHash.replace(hashTrim, '');
        }
    };

    $.fn.history = function(fn) {
        $(this).bind('history', fn);
    };

    $.fn.historyadd = function(fn) {
        $(this).bind('historyadd', fn);
    };

    $(function() {
        currentHash = location.hash;
        if ($.browser.msie) {
            msie.iframe = $('<iframe style="display:none" src="javascript:false;"></iframe>').prependTo('body')[0];
            msie.setHash(currentHash);
            currentHash = msie.getHash();
        }
    });
})(jQuery);


$(function() {
	/**
	 * The "historyadd" event is triggered whenever navigation occurs.
	 * In this demonstration, this is the result of the onclick function above.
	 * You may attach this event to as many elements as you wish.
	 */
	$('#centerContent').historyadd(function(e, currentHash, previousHash) 
											
	{
											
		$(this).html(currentHash);
	});

	/**
	 * The "history" event is triggered whenever the user presses the back button 
	 * or jumps backwards or forwards in their browser's history list.
	 * You may attach this event to as many elements as you wish
	 */
	$('#centerContent').history(function(e, currentHash, previousHash) {
		$(this).html(currentHash);
	});
	var initialHash = $.history.getCurrent();
});


