// JavaScript Document
function isValidEmail(address) {
   if (address != '' && address.search) {
	  if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
	  else return false;
   }
   
   // allow empty strings to return true - screen these with either a 'required' test or a 'length' test
   else return true;
}
//////////////////////////////////////////////////
function isNumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) 
	  return false;
   }
   return true;
}
function $(id) {
		return document.getElementById(id);
}
//__________________________________________________________________________________________________________a
  function SendForm(action){
			var errorMsg="";

	if(action == 'AddingAdmin'){
		if ($("fullname").value=="") errorMsg +="\n -Adı Soyadı alanı";
		if ($("username").value=="") errorMsg +="\n -Kullanici Adı alani.";				
		if ($("newpass1").value=="") errorMsg +="\n -Yeni Sifre alani";
		if (document.catForm.newpass2.value=="") errorMsg +="\n -Yeni Sifre Tekrar alanı.";
		if ($("newpass1").value!=$("newpass2").value)
		{errorMsg +="\nSifre alanıyla Sifre Tekrar alanını tekrar giriniz.";}
		if (document.catForm.yetki.selectedIndex==0) errorMsg +="\n -Yetki alanı";		
		}
		if(action == 'EditingAdmin'){
		if ($("fullname").value=="") errorMsg += "\n -Adı Soyadı alanı.";
		if ($("username").value=="") errorMsg += "\n -Kullanıcı Adi alanı.";
		else	if ($("catForm").enterpass[1].checked == true){
				if ($("password").value=="") errorMsg += "\n -Şifre alanı.";
				if ($("newpass1").value=="") errorMsg += "\n -Yeni Sifre alanı.";
				if (document.catForm.newpass2.value=="") errorMsg += "\n -Yeni Sifre Tekrar alanı";
				if ($("newpass1").value!=$("newpass2").value)
				{errorMsg += "\n -Sifre alaniyla Sifre Tekrar alanini tekrar giriniz.";}
			}
		}

		if (errorMsg!="")
		{
			errorMsg ="Hata\n_____________________________\n" +
			errorMsg + "\n_____________________________\n" +
			"Lütfen yukarda alani kontrol ediniz!";		
			alert(errorMsg);
			return;
		}			
	
			$("action").value = action;
			$("catForm").submit();

           }

//__________________________________________________________________________________________________________e
	var lastTR=0;
	function Alp_Collapse(trid){
		
		if(document.getElementById(trid).style.display == 'none')
		{
			if(lastTR != 0) { document.all(lastTR).style.display = 'none'; }			
			document.getElementById(trid).style.display = '';
		}else{
			document.getElementById(trid).style.display = 'none';
		}	
		lastTR=trid;
	}
//__________________________________________________________________________________________________________Y
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}
//------------------------------------------------------------------------------------------------------------
function checkSlogan(){
	var errorMsg = ""
	if ($("slogan").value.length<=3)
			errorMsg += "Sloganınızı Giriniz.";
	if ($("kategori").value==0)
			errorMsg += "<br>Kategori Seçiminizi Yapınız";				
	if (errorMsg!="")
	{
		//alert(errorMsg);
		document.getElementById("alrtJS").style.display="";
		document.getElementById("hataMesajiJS").innerHTML=errorMsg; 
		//alert(errorMsg);
		secsJS = 6;
		StopTheClock()
		StartTheTimerJS()
		return false;
	}
	else
	{
		document.getElementById("islem").value="slogan.ekle";
		document.getElementById("mainForm").submit();
	}	
}
function checkUpform(formx){
	var errorMsg = ""
	if ($("katilimcb").checked == false)
			errorMsg += "Katılım Koşullarını Alanı Boş Geçilemez";
			
	if (errorMsg!="")
	{
		//alert(errorMsg);
		document.getElementById("alrtJS").style.display="";
		document.getElementById("hataMesajiJS").innerHTML=errorMsg; 
		//alert(errorMsg);
		secsJS = 6;
		StopTheClock()
		StartTheTimerJS()
		return false;
	}
	else
	{
		document.getElementById("katilimcb").value=1;
		document.getElementById(formx).submit();
	}	
}
function checkContact(act){
	var errorMsg = ""
	if ($("formadsoyad").value.length<=3)
			errorMsg += "Adınızı soyadınızı giriniz.";

	if (!isValidEmail($("formeposta").value) ||   $("formeposta").value == "") {
		errorMsg += "<br>Email adresinizi giriniz.";
	}
	if (!isNumeric($("formceptel2").value) ||   $("formceptel2").value == "") {
		errorMsg += "<br>Telefon numaranızı hatasız giriniz.";
	}
	if (!isNumeric($("age").value) ||   $("age").value == "") {
		errorMsg += "<br>Yaşınızı hatasız giriniz.";
	}
	if ($("formceptel1").value==0)
			errorMsg += "<br>Telefon numaranızı hatasız giriniz.";	
			
	if ($("message").value.length<=3)
			errorMsg += "<br>Mesajınızı giriniz.";
			
	if (errorMsg!="")
	{
		//alert(errorMsg);
		document.getElementById("alrtJS").style.display="";
		document.getElementById("hataMesajiJS").innerHTML=errorMsg; 
			secsJS = 6;
			StopTheClock()
			StartTheTimerJS()
			return false;
	}
	else
	{
		document.getElementById("islem").value=act;
		document.getElementById("conForm").submit();
	}	
}
//--------------------------------------------------------------------------------------------------------------
function checkTextBoxKalp(textBox, e, length, isNumeric) {

    var mLen = textBox["MaxLength"];
    if (null == mLen)
        mLen = length;

    var maxLength = parseInt(mLen);
    kalanElement = document.getElementById("kalanText")
   // if (checkItem == "isimPanel")
        kalanElement.value = 70 - textBox.value.length;
		 if (!checkSpecialKeys(e)){
		if (textBox.value.length >= maxLength)
		return false;
		}
}
function checkTextBox(textBox, e, length, isNumeric) {

    var mLen = textBox["MaxLength"];
    if (null == mLen)
        mLen = length;

    var maxLength = parseInt(mLen);
    kalanElement = document.getElementById("kalanText")
   // if (checkItem == "isimPanel")
        kalanElement.value = 160 - textBox.value.length;
		 if (!checkSpecialKeys(e)){
		if (textBox.value.length >= maxLength)
		return false;
		}
}
function checkSpecialKeys(e) {
    if (e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
        return false;
    else
        return true;
}
//----------------------------------------------------------------------------------------------------
function kapat(kapanacak){
	$(kapanacak).style.display="none";
}
function runForm(frm){
	document.getElementById(frm).submit();
}

function sendmotherForm(frm){
	var errorMsg = ""
	if ($("formadsoyad").value.length<=3)
			errorMsg += "\n- Annenizin Adı Soyadı.";	
	if ($("formeposta").value=="")
			errorMsg += "\n- Annenizin E-Posta Adresi";				
	if (errorMsg!="")
	{
		errorMsg ="Hata !\n_____________________________\n" +
		errorMsg + "\n_____________________________\n" +"\n";		
		alert(errorMsg);
	return false;
	}
	else
	{
		document.getElementById("anneForm").submit();
	}
}
///-----------------
var secs
var timerID = null
var timerRunning = false
var delay = 1000
var secsJS

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs =6;
    StopTheClock()
    StartTheTimer()
}


function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
		if ($("alrt"))
			$("alrt").style.display='none';
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
function StartTheTimerJS()
{
    if (secsJS==0)
    {
        StopTheClock()
			$("alrtJS").style.display='none';
    }
    else
    {
        self.status = secsJS
        secsJS = secsJS - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimerJS()", delay)
    }
}
//-------------------------------
function MenuGoster(katman){
   katman = document.getElementById(katman);
   katman.style.visibility = 'visible';
   }

// Menu Gizle
function MenuGizle(katman){
   katman = document.getElementById(katman);
   katman.style.visibility = 'hidden';
   }
