var ajxSpanAdi, ajaxInitFunc;

function ajax (data , spanAdi , dosyaAdi , initFunc) 
{
	try{
		ajxSpanAdi = spanAdi;
		ajaxInitFunc = initFunc;
		xmlhttpUTF8 = CreateXmlHttpReqUTF8(ajaxCevap);
		XmlHttpGETUTF8(xmlhttpUTF8, dosyaAdi +"?"+ data );
	}catch( e ){ alert( "ajax : \n"+e.description); }
}

function ajaxCevap()
{
	try{
		if ( xmlhttpUTF8.readyState == 4 )
		{
			var output = xmlhttpUTF8.responseText;
			document.getElementById(ajxSpanAdi).innerHTML = output;
			var jscode = "";
			var parts = output.match(/<script[^>]*>(.|\n|\t|\r)*?<\/script>/gi);
			
			if(parts){
				for(i=0;i<parts.length;i++){
					jsSrc = parts[i].match(/src=\"[^\"]*/gi);
					
					jscode = parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
					
					output = output.replace(parts[i], "");
					
					var script = document.createElement("script");
					script.type = 'text/javascript'; 
					script.lang = 'javascript';
					if( jsSrc != null ) script.src = jsSrc.toString().replace("src=\"", "") ;
					script.text = jscode;
					document.getElementsByTagName('head')[0].appendChild(script);
				}
			}
			if( ajaxInitFunc != true){
				if( typeof initSub != "undefined" && initSub != null ) initSub();
			} else{
				if( typeof initSub2 != "undefined" && initSub2 != null ) initSub2();
			}
		}
	}catch( e ){ alert( "ajaxCevap : \n"+e.description); }
}

function sayfaGoster(baslik, sayfa)
{
	try{
		data = "baslik="+baslik;
		data += "&sayfa="+sayfa;
		myxmlhttp = CreateXmlHttpReqUTF8(CheckAvailXmlHttpHandler);
		XmlHttpGETUTF8(myxmlhttp, "ajax/StatikSayfa.php?"+ data );
	}catch( e ){ alert( "sayfaGoster : \n"+e.description); }
}

function CheckAvailXmlHttpHandler()
	{
		try{
			if ( myxmlhttp.readyState == 4 )
				document.getElementById("sayfaGovdesi").innerHTML = myxmlhttp.responseText;		
		}
		catch( e ){ alert(e.description); }
	}

function GirisKontrolEt()
{
	try{
		d = document.mainForm;
		hata ="";
		if (d.email.value == "") hata += "Lütfen E-mail adresinizi giriniz...\n";
		if (d.sifre.value == "") hata += "Lütfen şifrenizi giriniz...";
		if (hata=="")
		{
			data = "email=" + d.email.value;
			data += "&sifre=" + d.sifre.value;
			data += "&islem=giris";
			ajax(data,"spnUserMenu","ajax/GirisKontrolEt.php");
		}
		else
			alert (hata);
	}catch( e ){ alert( "GirisKontroEt : \n"+e.description); }
}	

function sifreUnuttumMailiGonder()	
{
	try{
		d = document.mainForm;
		if (d.email.value != "") {
			data = "email=" + d.email.value;
			data += "&islem=sifreUnuttumMailiGonder";
			ajax(data,"spnUserMenu","ajax/GirisKontrolEt.php");		
		}
		else
			alert ('Lütfen E-mail adresinizi giriniz...');
	}catch( e ){ alert( "GirisKontroEt : \n"+e.description); }
}

function shnTrim( tI ) {
	try {
		// definition of regular expression
		if( typeof tI == "undefined" || tI == null ) return "";

		tLRegExp =/^[ ]*/;
		tRRegExp =/[ ]*$/;
		tI = tI.replace(tLRegExp, "");
		tI = tI.replace(tRRegExp, "");
		return tI;
	}
	catch ( tE ) { // catch the error
		alert("shnStrToNumber \n : " + tE.description);
	}
}

function shnStrToNumber( shnValue, hasNotFormat)
{
	try{
		if( typeof shnValue == 'undefined' )  return 0;
		else
		{
			shnValue = shnTrim( shnValue.toString() );
			if( shnValue == "" )  return 0;
		}
	
		if( hasNotFormat != 1 )
			shnValue = parseFloat( shnSetUnformattedNumber( shnValue ) );
	
		shnValue = ( !isNaN( shnValue ) ? parseFloat( shnValue ) : 0);
	
		return shnValue;
	}catch( e ){ alert( "shnStrToNumber : \n"+e.description); }
}

/***********************************************************************/
/* INTEGER WITHOUT SIGN CONTROL */
/***********************************************************************/
function shnIsUnsignInteger(shnValue) {
	if (shnValue.length==0) {
		return false;
	}
	try {
		// definition of regular expression
		shnIsUnsignIntegerRegExp=/^[0-9]*$/;
		return shnIsUnsignIntegerRegExp.test(shnValue);
	}
	catch ( shnErr ) { // catch the error
		return false;
	}
}

/***********************************************************************/
/* TEXT CONTROL */
/***********************************************************************/
function shnIsText(shnIsTextInput)
{
	try
	{
		if (shnIsTextInput.length==0) return false;
		// definition of regular expression
		shnIsStringRegExp = /^[a-zA-Z0-9 \.:\-@_öÖşŞğĞüÜçÇıİ]+$/;
		return shnIsStringRegExp.test(shnIsTextInput);
	}
	catch (shnIsTextError)
	{ // catch the error
		return false;
	}
}

function hesapla()
{
	try{
		d = document.mainForm;
		vize = shnTrim(d.vize.value);
		soruSayisi = d.NotDers.value;
		soruPuani = 100 / soruSayisi;
		almasiGereken = Math.round( 100 / 70 * ( 50- 30*vize/100));
		gerekliNet = Math.round(almasiGereken / soruPuani)+1;
		if ( vize != "" ){
			vize = shnStrToNumber( shnTrim(d.vize.value),1);
			if (( vize >= 0 ) && ( vize <= 100 )){			
					if ((vize>=0) && (vize<=40))  durum="Çok çalışmanız gerekiyor.";
					if ((vize>=41) && (vize<=50)) durum="Daha fazla çalışmanız gerekiyor.";
					if ((vize>=51) && (vize<=60)) durum="Risktesiniz. Biraz daha çalışmanız gerekiyor.";
					if ((vize>=61) && (vize<=80)) durum="İyi durumdasınız.";
					if ((vize>=81) && (vize<=100)) durum="Başarılısınız.";
				document.getElementById('spnGerekenFinalNotu').innerText = almasiGereken;
				document.getElementById('spnFinalDurumu').innerText = durum;
				document.getElementById('spnGerekliNet').innerText = gerekliNet;
				document.getElementById('spnSoruSayisi').innerText = soruSayisi;
			}
			else
				alert ("Lütfen 0-100 arası bir değer giriniz...");
		}
			else
				alert ("Lütfen 0-100 arası bir değer giriniz...");
	}catch( e ){ alert( "hesapla : \n"+e.description); }
}

function shnUpper(shnUpperInput) {
	try {
		shnUpperInput=shnUpperInput.replace(/[i]/g,"İ");
		shnUpperInput=shnUpperInput.replace(/ı/g,"I");
		shnUpperInput=shnUpperInput.replace(/ş/g,"Ş");
		shnUpperInput=shnUpperInput.replace(/ü/g,"Ü");
		shnUpperInput=shnUpperInput.replace(/ğ/g,"Ğ");
		shnUpperInput=shnUpperInput.replace(/ö/g,"Ö");
		shnUpperInput=shnUpperInput.replace(/ç/g,"Ç");
		return shnUpperInput.toUpperCase();
	}
	catch (shnUpperError) {
		alert("shnUpper: \n: "+shnUpperError.description);
	}
}

function shnIsString(shnIsStringInput, _hasReturn) {
	try {
		if (shnIsStringInput.length==0) {
			return false;
		}
		// definition of regular expression
		shnIsStringRegExp=/^[a-zA-Z \.öÖşŞğĞüÜçÇıİ]+$/;
		return shnIsStringRegExp.test(shnIsStringInput);
	}
	catch (shnIsStringError)
	{ // catch the error
		if(_hasReturn == 1) return false;
		else
		{
			alert("shnIsString: \n "+shnIsStringError.description);
			return false;
		}
	}
}

function shnIsEmail(shnIsEmail_input) 
{
	try {
		shnIsEmail_reg_exp=/^[\w-]+(\.?[\w-]+)*@\w+(\.?[\w-]+)*(\.\w{2,3})+$/;
		return shnIsEmail_reg_exp.test(shnIsEmail_input);
	}catch( e ){ return false; }
}

function OneriElestiriMailiGonder (){
	try{
		d = document.mainForm;
		hata ="";
		if (d.OneriAdSoyad.value == "") hata += "Lütfen adınızı ve soyadınızı giriniz...\n";
		if (d.oneriEmail.value == "") hata += "Lütfen e-mail adresinizi giriniz...\n";
			else if (!(shnIsEmail(d.oneriEmail.value))) hata+= "Lütfen geçerli bir e-mail adresi giriniz";
		if (d.oneriMesaj.value == "") hata += "Lütfen mesajınızı giriniz...";
		if (hata=="")
		{
			data  = 'adSoyad=' + d.OneriAdSoyad.value;
			data += '&email=' + d.oneriEmail.value;
			data += '&mesaj=' + d.oneriMesaj.value;
			ajax(data ,'spnOneriElestiri','ajax/getir/OneriElestiriMailiGonder.php');
		}
		else
			alert (hata);
	}catch( e ){ alert( "OneriElestiriMailiGonder : \n"+e.description); }
}

function UyeKaydet (){
	try{
		d = document.mainForm;
		hata ="";
		if (d.uyeKayitAdSoyad.value == "") hata += "Lütfen adınızı ve soyadınızı giriniz...\n";
		if (d.uyeKayitEmail.value == "") hata += "Lütfen e-mail adresinizi giriniz...\n";
			else if (!(shnIsEmail(d.uyeKayitEmail.value))) hata+= "Lütfen geçerli bir e-mail adresi giriniz\n";
		if (d.uyeKayitBolum.value == "") hata += "Lütfen bölümünüzü seçiniz...\n";
		if (d.uyeKayitSinif.value == "") hata += "Lütfen sınıfınızı seçiniz...\n";
		if (d.uyeKayitSehir.value == "") hata += "Lütfen şehirinizi giriniz...\n";
		if (hata=="")
		{
			data  = 'adSoyad=' + d.uyeKayitAdSoyad.value;
			data += '&email=' + d.uyeKayitEmail.value;
			data += '&bolum=' + d.uyeKayitBolum.value;
			data += '&sinif=' + d.uyeKayitSinif.value;
			data += '&sehir=' + d.uyeKayitSehir.value;
			data += '&uyelikTuru=' + d.uyelikTuru.value;
			data += '&okuduguyil=' + d.okuduguyil.value;
			data += '&yardimciyayin=' + d.yardimciyayin.value;
			data += '&kursagidiyormu=' + d.kursagidiyormu.value;
			data += '&bizenasilulastiniz=' + d.bizenasilulastiniz.value;
			data += '&oneriMesaj=' + d.onerimesaj.value;
			ajax(data ,'spnUyeKayit','ajax/getir/UyeKaydet.php');
		}
		else
			alert (hata);
	}catch( e ){ alert( "UyeKaydet : \n"+e.description); }
}	

function denemeSinavi ()
{
	try {
		denemeSinavi = window.open('denemesinavi/index.php','denemeSinavi','toolbar=no,location=no,menubar=no,resizable=no,scrollbars=no,width=1010,height=710,top=0,left=0');
	//	denemeSinavi.focus();
	}catch( e ){ alert( "denemeSinavi : \n"+e.description); }
}
function dersleriListele2()
{
	try{			
		hata = "";
		d = document.mainForm;
		if (d.bolum2.value=="") hata += "Lütfen bölümü seçiniz...\n";
		if (d.sinif2.value=="") hata += "Lütfen sınıf seçiniz...";
		if (hata == "")	
			ajax('bolumAdi='+document.mainForm.bolum2.options[document.mainForm.bolum2.selectedIndex].text+'&sinifKodu='+document.mainForm.sinif2.value+'&dersKodu='+document.mainForm.bolum2.value+document.mainForm.sinif2.value,'spnUniteler','ajax/getir/BolumDersleriGetir.php');
		else
			alert (hata);
	}catch( e ){ alert( "dersleriListele2 : \n"+e.description); }			
}

function dersleriListele4()
{
	try{
		hata = "";
		d = document.mainForm;
		if (d.bolum4.value=="") hata += "Lütfen bölümü seçiniz...\n";
		if (d.sinif4.value=="") hata += "Lütfen sınıf seçiniz...";
		if (hata == "")	
			ajax('bolumAdi='+document.mainForm.bolum4.options[document.mainForm.bolum4.selectedIndex].text+'&sinifKodu='+document.mainForm.sinif4.value+'&dersKodu='+document.mainForm.bolum4.value+document.mainForm.sinif4.value,'spnUniteler','ajax/getir/BolumDersleriGetir.php');
		else
			alert (hata);		
	}catch( e ){ alert( "dersleriListele4 : \n"+e.description); }		
}

function geriSay1( tarih ) 
{
	try{
		var eventdate = new Date( tarih );
		d = new Date();
		count=Math.floor((eventdate.getTime()-d.getTime())/1000);
		if(count<=0) return;
		document.getElementById('_secs1').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_mins1').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_hours1').innerHTML=count%24;
		count=Math.floor(count/24);
		document.getElementById('_days1').innerHTML=count%365;
		count=Math.floor(count/365);
		setTimeout("geriSay1('"+eventdate+"')",1000);	
	}catch( e ){  }
}

function geriSay2( tarih ) 
{
	try{
		var eventdate = new Date( tarih );
		d = new Date();
		count=Math.floor((eventdate.getTime()-d.getTime())/1000);
		if(count<=0) return;
		document.getElementById('_secs2').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_mins2').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_hours2').innerHTML=count%24;
		count=Math.floor(count/24);
		document.getElementById('_days2').innerHTML=count%365;
		count=Math.floor(count/365);
		setTimeout("geriSay2('"+eventdate+"')",1000);	
	}catch( e ){ }
}

function geriSay3( tarih ) 
{
	try{
		var eventdate = new Date( tarih );
		d = new Date();
		count=Math.floor((eventdate.getTime()-d.getTime())/1000);
		if(count<=0) return;
		document.getElementById('_secs3').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_mins3').innerHTML=count%60;
		count=Math.floor(count/60);
		document.getElementById('_hours3').innerHTML=count%24;
		count=Math.floor(count/24);
		document.getElementById('_days3').innerHTML=count%365;
		count=Math.floor(count/365);
		setTimeout("geriSay3('"+eventdate+"')",1000);	
	}catch( e ){ }
}

function uyelikTuruSec()
{
	try{
		d = document.mainForm;
		if (d.uyelikTuru.value == "A")
			document.getElementById ('aof').style.height = 170;
			document.getElementById ('aof').innerHTML = 'aof';
		if ((d.uyelikTuru.value == "S") || (d.uyelikTuru.value == "K"))
		{
			document.getElementById ('aof').style.height = 0;
			document.getElementById ('aof').innerHTML = "";
		}
	
	}catch( e ){ alert( "uyelikTuruSec : \n"+e.description); }
}

function uyelikDegisti()
{
	try{
		d = document.mainForm;
		secilen = d.uyelikTuru.value;
		if (secilen == "A")
		{
			d.uyeKayitBolum.disabled = false;
			d.uyeKayitSinif.disabled = false;
			d.okuduguyil.disabled = false;
		}
		else
		{
			d.uyeKayitBolum.disabled = true;
			d.uyeKayitSinif.disabled = true;
			d.okuduguyil.disabled = true;
		}
	}catch( e ){ alert( "uyelikDegisti : \n"+e.description); }
}

function sifreDegistirIslemi(){
	try{
		d = document.mainForm;
		_sifre = d.sifre.value;
		_sifreTekrar = d.sifreTekrar.value;
		if ( ( shnTrim(_sifre) == shnTrim(_sifreTekrar) ) && ( shnTrim(_sifreTekrar)!="" ) && ( shnTrim(_sifre)!="" ) ) 
		{
			data = 'sifre=' + _sifre;
			ajax(data ,'spnSifreDegistir','ajax/getir/SifreDegistirKaydet.php');
		}
		else
			alert ("Lütfen geçerli bir şifre giriniz...");
	}catch( e ){ alert( "uyelikDegisti : \n"+e.description); }
}