function MM_swapImgRestore() { //v3.0
  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];}
}


// -----------------------------------------------------


function AJAX() {
   var ajax = false;
   
   // Internet Explorer (5.0+)
   try {
     ajax = new ActiveXObject("Msxml2.XMLHTTP");  // yeni versiyon xmlhttp
   } catch (e) {
	   
      try {
        ajax = new ActiveXObject("Microsoft.XMLHTTP");  // eski versiyon xmlhttp
      } catch (e) {
        ajax = false;
      }
   }
   // Mozilla ve Safari
   if ( !ajax && typeof XMLHttpRequest != 'undefined' ) {
	   
     try{
        ajax = new XMLHttpRequest();
     }catch(e) {    
        ajax = false;
     }

   }
   // Diger
   if ( !ajax && window.createRequest ) {
     
	 try{
        ajax = window.createRequest();
     }catch(e) {  
        ajax = false;
     }

   }

	return ajax;
}


function getPR(web,element) {

	ajax = new AJAX();	
	if ( ajax ) {
		ajax.onreadystatechange = function () {};
		ajax.abort();
	}
		
	ajax.open('GET', "getpagerank.php?web="+ web, true);
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	ajax.setRequestHeader("Connection", "close");
	ajax.send(null);
	
    ajax.onreadystatechange = function () {
		if( ajax.readyState == 4 ) {
			document.getElementById(element).innerHTML = ajax.responseText;
			ajax = null;
        }
	}
	
}


/*
function kontrolet() {
	ajax = new AJAX();
	//var bilgi= document.kformu.epostaadresi.value;
	var dosya= 'ajaxkontrol.php?epostaadresi=';
	
	if ( ajax ) {
		ajax.onreadystatechange = function () {};
		ajax.abort();
	}
		
	ajax.open('GET', dosya + bilgi, true);
	ajax.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	ajax.setRequestHeader("Connection", "close");
	ajax.send(null);
	
    ajax.onreadystatechange = function () {
		if( ajax.readyState == 4 ) {
			document.getElementById('cevap').innerHTML = ajax.responseText;
			//function AJAX() {};
			ajax = null;
        }
	}
}
*/


// ***********************************************
// internal_request.js
// ***********************************************
/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getIlceSemt(il,ilce,semtVer){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will 		
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open("GET", 'internal_request.php?il='+ il+'&ilce='+ilce+'&semtVer='+semtVer,"false");
	//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	
	if(ilce=="") {
		document.getElementById('ilce').options.length = 0;
		document.getElementById('semt').options.length = 0;
		//document.getElementById('div_ilce').innerHTML = "Ykleniyor...";
		//document.getElementById('div_semt').innerHTML = "<select name='semt'  id='semt' onBlur=\"checkForm(this,'semtHata');\"><option value=''>--- seiniz ---</option></select>";
		if(semtVer==1) http.onreadystatechange = handleProducts_ilceSemt;
		else http.onreadystatechange = function() { handleProducts_ilce(); if(ilce=='') getIlceSemt(il,ilce,1); };
	} else { 
		document.getElementById('semt').options.length = 0;
		//document.getElementById('div_semt').innerHTML = "Ykleniyor...";
		http.onreadystatechange = handleProducts_semt;
	}
	//alert('internal_request.php?il='+ escape(il)+'&ilce='+escape(ilce));


	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//http.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");
	 //http.setRequestHeader('encoding','ISO-8859-9'); 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts_ilce(){	
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		if (http.status == 200) 
			var response = http.responseText;			
		else { alert( "Error code " + http.status);	}
			ilce = document.getElementById('ilce');
			ilcedizi = response.split("|");
			ilce.options[0] = new Option('---- seçiniz ----','');
			for(i=0;i<ilcedizi.length;i++)				
				ilce.options[ilce.options.length] = new Option(ilcedizi[i],ilcedizi[i]);
		//document.getElementById('div_ilce').innerHTML = response;
	}
	

}
function handleProducts_semt(){
	if(http.readyState == 4){ //Finished loading the response
		if (http.status == 200) 
			var response = http.responseText;			
		else { alert( "Error code " + http.status);	}	
			semt = document.getElementById('semt');
			semtdizi = response.split("|");
			semt.options[0] = new Option('---- seçiniz ----','');
			for(i=0;i<semtdizi.length;i++)				
				semt.options[semt.options.length] = new Option(semtdizi[i],semtdizi[i]);
		//document.getElementById('div_semt').innerHTML = response;
	}
}


function handleProducts_ilceSemt(){
	if(http.readyState == 4){ //Finished loading the response
		if (http.status == 200) 
			var response = http.responseText;			
		else { alert( "Error code " + http.status);	}	
			semt = document.getElementById('semt');
			semtdizi = response.split("|");
			semt.options[0] = new Option('---- seçiniz ----','');
			for(i=0;i<semtdizi.length;i++)				
				semt.options[semt.options.length] = new Option(semtdizi[i],semtdizi[i]);
		//document.getElementById('div_semt').innerHTML = response;
	}
}


function checkUser(user) {
	http.open("GET", 'ajax_user_check.php?user='+ user);
	http.onreadystatechange = handleuser;
	http.send(null);
}


function handleuser(){
	if(http.readyState == 4){ //Finished loading the response
		if (http.status == 200) 
			var response = http.responseText;
		else var response = "Error code " + http.status;
		document.getElementById('userHata').innerHTML = response;
			
	}
}


$(document).ready(function(){
		$("#il").change(function () { sonucAl($('#il').val(),'','1')  })
		$("#ilce").change(function () { sonucAl($('#il').val(),$('#ilce').val(),'')  })
		$("#semt").change(function () { 
			s = document.getElementById("semt");
			t = (s.options[s.selectedIndex].text);
			no = t.indexOf('[');
			if(no>0) {
				ilce = t.substring(no+1,t.length-1);
				 	var x=document.getElementById("ilce");
					for (i=0;i<x.length;i++) if(x.options[i].text == ilce)  x.selectedIndex = i;
			}
		})

	});


function sonucAl(il,ilce,semtVer) {
	//alert("........................................... ..." + $('#il').val());
	//$("#il option:selected").text();	
	if(ilce =="") document.getElementById('ilce').options.length = 0;
	document.getElementById('semt').options.length = 0;

	if(ilce =="")
	$.ajax({
		   type: 'GET',
		   url: 'internal_request.php',
		   data: 'il='+ $('#il').val()+'&ilce=',	   
		   success: function(sonuc) {
			 	//$('#sonuc').html(sonuc);				
				ilce = document.getElementById('ilce');
			ilcedizi = sonuc.split("|");
			ilce.options[0] = new Option('---- seçiniz ----','');
			for(i=0;i<ilcedizi.length;i++)				
				ilce.options[ilce.options.length] = new Option(ilcedizi[i],ilcedizi[i]);
				
		   }
	});
	
	if(ilce=="") semtVer = 1; else semtVer = "";
	$.ajax({
		   type: 'GET',
		   url: 'internal_request.php',
		   data: 'il='+ $('#il').val()+'&ilce='+ilce+'&semtVer='+semtVer,	   
		   success: function(sonuc) {
			 	//$('#sonuc').html(sonuc);
				
				semt = document.getElementById('semt');
			semtdizi = sonuc.split("|");
			semt.options[0] = new Option('---- seçiniz ----','');
			for(i=0;i<semtdizi.length;i++)	{
				v =(semtVer=='1')? semtdizi[i].substring(0,semtdizi[i].indexOf('  [')) : semtdizi[i];
																	
				semt.options[semt.options.length] = new Option(semtdizi[i],v);
			}
		   }
	});
		return false;

}









// ************************************************
// genel.js
// ************************************************



// form eleman ieriini kontorl edip hata id li alana hata mesaj yazyor
function checkForm(element,hata) {	
	document.getElementById(hata).innerHTML ="";
	document.getElementById(hata).style.display = 'none';
	if((element.type=="text" || element.type=="hidden") && element.value =="") {
		document.getElementById(hata).style.display = '';
		document.getElementById(hata).innerHTML = "Gerekli alanlar boş brakılamaz";
		return false;
	}
	if(element.type=="select-one" && element.selectedIndex<1) {
		document.getElementById(hata).style.display = '';
		document.getElementById(hata).innerHTML = "Gerekli alanlar boş brakılamaz";
		return false;
	}

	if(element.type=="password") {
		if(element.value.length<6) {
			document.getElementById(hata).style.display = '';
			document.getElementById(hata).innerHTML = "Şifre 6 karakterden küçük olamaz";
			return false;
		}
		if(hata=="pass2Hata" && element.value != document.getElementById('pass').value) {
			document.getElementById(hata).style.display = '';
			document.getElementById(hata).innerHTML = "Şifreler aynı değil";
			return false;
		}
	}
	if(hata=="epostaHata" && element.value!="" && !element.value.match("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$")) {
		document.getElementById(hata).style.display = '';
		document.getElementById(hata).innerHTML = "E-Posta adresi hatalı";
		return false;
	}
	// checkUser(user) fonksiyonu internal_request.js iinde	
	if(hata=="userHata" && element.value !="") { 
		if(!element.value.match('^[a-zA-Z0-9.]')) {
			document.getElementById(hata).style.display = '';
			document.getElementById(hata).innerHTML = "Üzgünüz, sadece harfler (a-z), sayılar (0-9), ve noktalar (.) kullanlabilir.";
			return false;
		} else return checkUser(element.value);
	}
	return true;
}


function checkFormAll(frm,elemanlar) {
	hata = false;	
	for(var e in elemanlar) {
		x = eval("frm."+elemanlar[e]);
		if(!checkForm(x,elemanlar[e]+'Hata')) hata = true;		
	}
	return !hata;
		
}


// formdaki alanlar alp bir string oluturuyor
// admin_ic 'e get metoduyla yolluyor
//admin.php de secme iine gsteriliyor
function formDo(frm,islem) {	
	var str="";
	for(i=0;i<frm.elements.length;i++) {
		x = frm.elements[i];
		if(x.type=='radio' && x.checked ==false) continue;		
		if(str!="") str +="&";
		str += x.name + "=" + encodeURIComponent(x.value);		
	}
	countries.loadajaxpage('admin_ic.php?'+str);
}





//***************************************************************

/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/

AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}


// *******************************************
// webtoolkit.aim.js
// *******************************************

function startCallback(info) {
	// make something useful before submit (onStart)
	document.getElementById(info).innerHTML = "<img src='loading.gif' />Dosya Yükleniyor...";
	return false;
}

function completeCallback(response) {	
	// make something useful after (onComplete)
	//document.getElementById('nr').innerHTML = parseInt(document.getElementById('nr').innerHTML) + 1;
	//document.getElementById('r').innerHTML = response;
	eval(response);
}

function checkResim(upload_field) {
	var re_text = /\.jpg|\.jpeg|\.gif|\.png/i;
    var filename = upload_field.value;
    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("sadece (jpg, jpeg,gif, png) türünde dosya gönderebilirsiniz");
        upload_field.form.reset();
        return false;
    }
	
	upload_field.form.submit.click();
	return true;
	
}

function checkVideo(upload_field) {
	var re_text = /\.mpg|\.avi|\.flv/i;
    var filename = upload_field.value;
    /* Checking file type */
    if (filename.search(re_text) == -1)
    {
        alert("sadece (mpg, avi, flv) türünde dosya gönderebilirsiniz");
        upload_field.form.reset();
        return false;
    }
	
	upload_field.form.submit.click();
	return true;
	
}

function resimVideoSil(ornek,hedef,status,bu) {
	document.getElementById(ornek).src = 'logo/bos.gif';
	document.getElementById(hedef).value = '';
	document.getElementById(status).innerHTML = '';
	document.getElementById(bu).style.display = 'none';
	
}


// user ilem de grup imine tklandnda grubu kltp bytmek (ieriini gsterip gizlemek iin)
function grupGizleGoster(g) {
	if(document.getElementById(g).style.display=='none') 
		document.getElementById(g).style.display = '';
	else document.getElementById(g).style.display = 'none';
}


// user ilemde listelenen kayitlarn sil butonun baslnca onay soruyor
function confirmDelete(ad) {
  if (confirm(ad + " kaydını gerçekten silmek istiyormusunuz?")) return true
  else return false;
}

// user ilemde listelenen grup sil butonun baslnca onay soruyor
function confirmGrupDelete(ad) {
  if (confirm(ad + " Grubunu gerçekten silmek istiyormusunuz? \n Grup silindiğinde içerisindeki kayıtlar grupsuz olarak listelenmeye devam edecektir!")) return true
  else return false;
}







function sendemail(frm){
	var tur = encodeURIComponent(frm.tur.value);	
	var ad = encodeURIComponent(frm.ad.value);
	var tel = encodeURIComponent(frm.tel.value);
	var eposta = encodeURIComponent(frm.eposta.value);
	var mesaj = encodeURIComponent(frm.mesaj.value);
	var n = encodeURIComponent(frm.n.value);
	var d = encodeURIComponent(frm.d.value);
	var aad = encodeURIComponent(frm.aad.value);
	var aeposta = encodeURIComponent(frm.aeposta.value);
	var firma = encodeURIComponent(frm.firma.value);
	var captcha = encodeURIComponent(frm.captcha.value);
	//frm.send.disabled=true; 
	//frm.send.value='Sending....';
	
    http.open('get', 'mail.php?ad='+ad+'&tel='+tel+'&eposta='+eposta+'&mesaj='+mesaj+'&n='+n+'&d='+d+'&tur='+tur+'&aad='+aad+'&aeposta='+aeposta+'&firma='+firma+'&captcha='+captcha+'&action=send');
    http.onreadystatechange = handleResponse_sendemail;
    http.send(null);
}
function handleResponse_sendemail(){	
	if(http.readyState == 4){ //Finished loading the response
		if (http.status == 200) 
			var response = http.responseText;			
		else { alert( "Error code " + http.status);	}
			alert(response);
			if(response != "Doğrulama Kodu Hatalı!") {
				jQuery(document).trigger('close.facebox'); //facebox penceresi kapatılıyor
				//document.getElementById('sendmail').innerHTML = response;
			}
	}

}


function aaa(s) {
	alert(s);
}

function yazdir() {
	window.print();
}