
//----------------------------------------
// App constants
//----------------------------------------

var USERTIP_ACENTE = "AK";
var USERTIP_SIGORTA_SIRKET= "SK";
var USERTIP_HAZINE= "HK";
var USERTIP_EKSPER= "EK";
var USERTIP_BIRLIK= "BK";
var USERTIP_MUSTERI= "MK";
var USERTIP_TRAMER= "TK";
var USERTIP_EMNIYET= "EMK";
var USERTIP_SAGLIK= "SBK";

var SORGUTIP_POLICE_NO = 0;	
var SORGUTIP_PLAKA = 1;
var SORGUTIP_MOTOR = 2;
var SORGUTIP_SASI = 3;
var SORGUTIP_MUSTERI_AD_SOYAD = 4;
var SORGUTIP_MUSTERI_VERGI_NO = 5;
var SORGUTIP_MUSTERI_VATANDAS_NO = 6;
var SORGUTIP_OTORIZASYON_NO = 7;
var SORGUTIP_ONAYNO = 8;
var SORGUTIP_BELGE = 10;
var SORGUTIP_SIGORTASIRKET = 11;
var SORGUTIP_POLICEBASLAMATARIHI=12;
var SORGUTIP_EKTURU=13;
var SORGUTIP_EKBASLAMATARIHI=14;
var SORGUTIP_HATAKODU=15;
var SORGUTIP_SBMNO = 19;

var HATA_RAPOR_KONTROL_TARIH = new Date(2004,08,30,0,0,0,0);
var OTORIZASYON_KONTROL_TARIH = new Date(2004,09,31,0,0,0,0);

var OTORIZASYON_SORGUTIP_REFERANS_NO = 0;	
var OTORIZASYON_TALEP_EDEN = 1;
var OTORIZASYON_TALEBE_KONU_OLAN = 2;

var otorizasyon_sonuc_ack_max = 0;
var log_app_ack_max = 0;
var log_app_sql_max = 0;
var acente_edit_ack_max = 0;

var RAPOR_OK0006_TUR_1 = 1;
var RAPOR_OK0006_TUR_2 = 2;
var RAPOR_OK0006_TUR_3 = 3;

var RAPOR_GK0009_ADETSEL = 0;
var RAPOR_GK0009_PRIMSEL = 1;

var RAPOR_SIRALAMA_SIRKET_ADI = 1;
var RAPOR_SIRALAMA_POLICE_ADET = 2;	
var RAPOR_SIRALAMA_ADET_SIRALI = 3;
var RAPOR_SIRALAMA_PRIM_SIRALI = 4;	
var RAPOR_SIRALAMA_HATA_ORAN_SIRALI = 5;	

// simulasyon kontrol tarihleri
var DEVIR_KONTROL_TARIHI = new Date(2004,12,31,0,0,0,0);
var FESIH_KONTROL_TARIHI = new Date(2004,12,31,0,0,0,0);

var PLAKASORGUTIP_TC = 0;
var PLAKASORGUTIP_VERGI = 1;
var PLAKASORGUTIP_SASI = 2;
var PLAKASORGUTIP_SIRKET = 3;
var PLAKASORGUTIP_MOTOR = 4;

var KIMLIKTIP_TC = 0;
var KIMLIKTIP_VERGI = 1;

var URUN_TRAFIK = 100;
var URUN_ZKYTMS = 110;

function flipCheckboxValue(cBox)
{	
	with (document.yetkiForm)
	{
		if(cBox.checked == true)
		{
			cBox.value="E";
		}
		else 
		{
			if(cBox.checked == false)
			cBox.value="H";
		}
	}
}
function setCheckboxValue(cBox)
{	
	with (document.menuForm)
	{
		if(cBox.checked == true)
		{
			cBox.value="E";
		}
		else 
		{
			if(cBox.checked == false)
			cBox.value="H";
		}
	}
}
//----------------------------------------
function setYetkiUsr()
{
	with (document.yetkiForm)
	{
		usr.value = userType.value;
	}
}
function setUsr()
{
	with (document.menuForm)
	{
		usr.value = userType.value;
	}
}
// ----------------------------------
function checkChangePasswordFormScrn()
{
	with (document.changePasswordForm)
	{
		if(yeniPassword.value != yeniPasswordTekrar.value  )	
		{
			alert("Sifre tekrariniz yanlis. Lütfen yeni sifrenizi bir daha giriniz.");
			with (document.changePasswordForm)
			{
				yeniPassword.value = "";
				yeniPasswordTekrar.value = "";
			}
			return false;
		}
		// SBM Sifre Standartlari kontrolleri
		// passwordRules.js dosyasindan okunuyor
		return checkMyPassword(yeniPassword.value, user.value)
		/*if(yeniPassword.value.length < 6 || yeniPassword.value.length > 20 )	
		{
			alert("Sifre bilgisi en az 6 en fazla 20 karakterden olusabilir. Lütfen bu kapsamda bir sifre bilgisi tanimlayiniz.");
			with (document.changePasswordForm)
			{
				eskiPassword.value = "";
				yeniPassword.value = "";
				yeniPasswordTekrar.value = "";
			}
			return false;
		}*/
		
	}	
	return true;
}

function initChangePasswordScrn()
{
	with (document.changePasswordForm)
	{
		eskiPassword.value = "";
		yeniPassword.value = "";
		yeniPasswordTekrar.value = "";	
		setFocus(eskiPassword);	
	}
}

function initAcenteChangePasswordScrn()
{
	with (document.changePasswordForm)
	{
		yeniPassword.value = "";
		yeniPasswordTekrar.value = "";	
		setFocus(yeniPassword);	
	}
}

function checkAcenteChangePasswordFormScrn()
{
	with (document.changePasswordForm)
	{
		if(yeniPassword.value.length < 6 || yeniPassword.value.length > 20 )	
		{
			alert("Sifre bilgisi en az 6 en fazla 20 karakterden olusabilir. Lütfen bu kapsamda bir sifre bilgisi tanimlayniz.");
			with (document.changePasswordForm)
			{
				yeniPassword.value = "";
				yeniPasswordTekrar.value = "";
			}
			return false;
		}
		if(yeniPassword.value != yeniPasswordTekrar.value  )	
		{
			alert("Sifre tekrariniz yanlis. Lütfen yeni sifrenizi bir daha giriniz.");
			with (document.changePasswordForm)
			{
				yeniPassword.value = "";
				yeniPasswordTekrar.value = "";
			}
			return false;
		}
	}	
	return true;
}

String.prototype.tokenize = tokenize;

function tokenize()
{
     var input     = "";
     var separator = " ";
     var trim      = "";
     var ignoreEmptyTokens = true;

     try {
       String(this.toLowerCase());
     }
     catch(e) {
       window.alert("Tokenizer Usage: string myTokens[] = myString.tokenize(string separator, string trim, boolean ignoreEmptyTokens);");
       return;
     }

     if(typeof(this) != "undefined")
       {
          input = String(this);
       }

 //    if(typeof(tokenize.arguments[0]) != "undefined")
       {
          separator = String(tokenize.arguments[0]);
       }

 //    if(typeof(tokenize.arguments[1]) != "undefined")
       {
          trim = String(tokenize.arguments[1]);
       }

 //    if(typeof(tokenize.arguments[2]) != "undefined")
       {
          if(!tokenize.arguments[2])
            ignoreEmptyTokens = false;
       }

     var start = 0;
     var end = 0;
     var token = new Array();
     for(var i=0; i<input.length+1; i++)
       {
          if(input.slice(start, i).indexOf(separator) != -1)
            {
               end = i - separator.length;
               token[token.length] = input.slice(start, end);
               start = i;
            }
          else
            {
               if(i == input.length)
                 token[token.length] = input.slice(start);
            }
       }

    if(trim)
      for(var i=0; i<token.length; i++)
        {
          while(token[i].slice(0, trim.length) == trim)
            token[i] = token[i].slice(trim.length);
          while(token[i].slice(token[i].length-trim.length) == trim)
            token[i] = token[i].slice(0, token[i].length-trim.length);
        }

    var finalToken = new Array();
    if(ignoreEmptyTokens)
      {
         for(var i=0; i<token.length; i++)
           if(token[i] != "")
             finalToken[finalToken.length] = token[i];
      }
    else
      {
         finalToken = token;
      }

     return finalToken;
}
function beginMenu() {
	stm_bp("p0",[1,2,3,0,1,3,0,1,100,"",0,"",0,0,1,2,"000000","#7D9395","",3,1,1,"#465657"]);
}

function endMenu() {
	stm_ep(); 
}

function itemMenu(title,url,arrow) {
	stm_ai("p0i0",[0,title,"","",0,0,0,url,"_top","Menu","","","",0,0,0,(arrow==1?'../img/menu/arrow_r.gif':""),(arrow==1?'../img/menu/arrow_r.gif':""),7,7,0,0,0,"#7D9395",0,"#465657",0,"","",0,0,0,0,"","","#FFFFFF","#FFC210","bold 11px Verdana","bold 11px Verdana",0,0]);
}
function menuBuild(input)
{
	//stm_bm(["TramerMenu",400,"menu/","blank.gif",0,"","",0,0,0,0,500,1,1,1,""]/*,this*/);
	var tokens = new Array();
	tokens = input.tokenize(";", "", false);
	for (j=0; j<tokens.length; j++)
	{
		if(tokens[j] == "beginMenu()")
		{
			beginMenu(); 
		}
		else 
		{
			if(tokens[j] == "endMenu()")
			{
				endMenu(); 
			}
			else
			{
				var locTokens = tokens[j].tokenize("'","",false);
				if(locTokens[4] == ",1)")
				{
					itemMenu(locTokens[1] , locTokens[3],1);
				}
				else
				{ 
					itemMenu(locTokens[1] , locTokens[3]);
				}
			}
		}
	}
	//stm_em();
}
function initDuyuruCevapKaydetForm()
{
	with (document.duyuruCevapKaydetForm)
	{

	}
}
function checkDuyuruBilgiGirisScrn()
{
	with (document.duyuruBilgiGirisForm)
	{
		tarih.value = tarih.value.trim();
		if (tarih.value.length == 0) return reportError(tarih,tarihDegeriBos);
		if(duyuruReferansNo.value.length == 0)	return reportError(duyuruReferansNo,duyuruReferansNoBos);
		if(konu.selectedIndex == -1) return reportError(konu,konuBos);
		if(iletildigiKurum.selectedIndex == -1)
		{
			return reportError(iletildigiKurum,iletildigiKurumBos);
		}
		if(dataFile.value.length == 0)	return reportError(dataFile,dataFileBos);	
		if(cevapBekleniyorMu.checked == true)
		{
			if(gerekenTarih.value.length == 0)	return reportError(gerekenTarih,gerekenTarihBos);
		}
		//cevap tarihi, duyuru tarihi'den k???k olamaz
		if(gerekenTarih.value.length != 0 && tarih.value.length != 0){
			var trhCevap = new Date(gerekenTarih.value.substring(6,10),gerekenTarih.value.substring(3,5)-1,gerekenTarih.value.substring(0,2),0,0,0,0);			
			var trhDuyuru = new Date(tarih.value.substring(6,10),tarih.value.substring(3,5)-1,tarih.value.substring(0,2),0,0,0,0);			
			if(compareDateObjects(trhCevap, trhDuyuru) == -1)
				return reportError(gerekenTarih, cevapTarihiDuyuruTarihindenBuyuktur);
		}

		var today = new Date();
		var d1 = new Date(tarih.value.substring(6,10), tarih.value.substring(3,5)-1, tarih.value.substring(0,2),0,0,0,0);
		if (compareDateObjects(d1, today) == 1) return reportError(tarih, duyuruTarihiSistemTarihindenBuyukOlamaz);
	}
	return true;
}
function checkDuyuruGirisVisibilityOfIletildigiKurumDetay(){
	with (document.duyuruBilgiGirisForm){			
		var bDisable = getComboCode(iletildigiKurum) != '504';
		iletildigiKurumDetayi.disabled = bDisable;
		if( !bDisable){
			iletildigiKurumDetayi.focus();
		}
	}
}
function checkDuyuruGirisVisibilityOfBilgiVerilenKurumDetay(){
	with (document.duyuruBilgiGirisForm){
		var bDisable = getComboCode(bilgiVerilenKurumlar) != '504';
		bilgiVerilenKurumDetayi.disabled = bDisable;
		if( !bDisable){
			bilgiVerilenKurumDetayi.focus();
		}
	}
}
function initDuyuruBilgiGirisForm()
{
	var myDate = new Date();	
	with (document.duyuruBilgiGirisForm){
		if(tarih.value == "")tarih.value=formatDate(myDate,Date.defaultFormat);
		iletildigiKurum.value = "999";
		duyuruReferansNo.value = "";
		ilgili.value = "";
		duyuruIcerigi.value = "";
		iletildigiKurumDetayi.value = "";
		cevapBeklenmiyor();
		gerekenTarih.value = "";
		dataFile.value = null;
	}
}
function checkCevapBekleniyorMu()
{
	with (document.duyuruBilgiGirisForm){
	
		if(cevapBekleniyorMu.checked == true)cevapBekleniyor();
		if(cevapBekleniyorMu.checked == false)cevapBeklenmiyor();
	}
}
function cevapBekleniyor()
{
	with (document.duyuruBilgiGirisForm){
			gerekenTarih.disabled=false;
			tarihImg2.disabled=false;
			cevapBekleniyorMu.value="Evet";
	}
}
function cevapBeklenmiyor()
{
	with (document.duyuruBilgiGirisForm){
			gerekenTarih.disabled=true;
			gerekenTarih.value="";
			tarihImg2.disabled=true;
			cevapBekleniyorMu.value="Hayýr";
	}
}
function saveDuyuruDocument()
{
	with (document.duyuruBilgiGirisForm){


	}
}

//----------------------------------------
// logon scrn usage
//----------------------------------------
function initLogonScrn()
{
	setFocus(document.logonForm.userCode);
}

function checkLogonScrn()
{
	with (document.logonForm) {
		userCode.value = userCode.value.trim();
		if (userCode.value.length == 0) return reportError(userCode,logonUserCode);

		userPass.value = userPass.value.trim();
		if (userPass.value.length == 0) return reportError(userPass,logonUserPass);
	}
	return true;
}

//----------------------------------------
// upload scrn usage
//----------------------------------------
function initUploadScrn()
{
	setFocus(document.uploadForm.bilgiTarih);
}

function checkUploadScrn()
{
	with (document.uploadForm) {
		bilgiTarih.value = bilgiTarih.value.trim();
		if (bilgiTarih.value.length == 0) return reportError(bilgiTarih,uploadBilgiTarih);
		if (!checkDate(bilgiTarih.value)) return reportError(bilgiTarih,uploadBilgiTarihGecersiz);

		dataFile.value = dataFile.value.trim();
		if (dataFile.value.length == 0) return reportError(dataFile,uploadBilgiFile);
	}
	return true;
}

//----------------------------------------
// registration scrn usage
//----------------------------------------
function initRegisterScrn()
{
	setRegisterUserTip();
	setFocus(document.registerForm.userTip);
}

function checkRegisterScrn()
{
	with (document.registerForm) {
		email.value = email.value.trim();
		if (email.value.length == 0) return reportError(email,registerEmail);

		if (userTip.value == USERTIP_ACENTE)
		{
			acenteKod.value = acenteKod.value.trim();
			if (acenteKod.value.length == 0) return reportError(acenteKod,registerAcenteKod);
			
			ticaretSicilNo.value = ticaretSicilNo.value.trim();
			if (ticaretSicilNo.value.length == 0) return reportError(ticaretSicilNo,registerTicaretSicilNo);
		}
		else
		{
			eksperSicilKod.value = eksperSicilKod.value.trim();
			if (eksperSicilKod.value.length == 0) return reportError(eksperSicilKod,registerEksperSicilKod);
		
			vatandasNo.value = vatandasNo.value.trim();
			if (vatandasNo.value.length == 0) return reportError(vatandasNo,registerVatandasNo);
		}
	}
	return true;
}

function setRegisterUserTip()
{
	if (document.registerForm.userTip.value == USERTIP_ACENTE)
	{
		document.getElementById("div_eksper").style.display = "none";
		document.getElementById("div_acente").style.display = "";
		document.getElementById("div_ack2").style.display = "";
		// document.div_eksper.style.display = "none";
		// document.div_acente.style.display = "";
	}
	else
	{
		document.getElementById("div_eksper").style.display = "";
		document.getElementById("div_acente").style.display = "none";
		document.getElementById("div_ack2").style.display = "none";
		//document.div_acente.style.display = "none";
		//document.div_eksper.style.display = "";
	}			
}

//----------------------------------------
// forgotpassword scrn usage
//----------------------------------------
function initForgotPasswordScrn()
{
	setFocus(document.forgotPasswordForm.userCode);
}

function checkForgotPasswordScrn()
{
	with (document.forgotPasswordForm) {
		userCode.value = userCode.value.trim();
		if (userCode.value.length == 0) return reportError(userCode,forgotPasswordUserCode);
	}
	return true;
}


function initAcenteSorguScrn()
{
	with (document.acenteSorguForm)
	{
	 
	}
}

function checkAcenteSorguScrn()
{
	with (document.acenteSorguForm)
	{ 
	
	}
	return true;
}

//----------------------------------------
// acenteEdit scrn usage
//----------------------------------------
function initAcenteEditScrn()
{
	with (document.acenteForm)
	{ 
		acente_edit_ack_max = kalanAlan.value;
		if (newAcente.value == "E"){
			if (ilce.selectedIndex == -1) sehir.selectedIndex = -1;
			if (acenteKod.type != "hidden") setFocus(acenteKod);
			else setFocus(ticaretSicilNo);
		}
		else{			
			if (sehir.value == "") sehir.selectedIndex = -1;
			kalanAlan.value = acente_edit_ack_max - kalanAlan.value.length;
		}
	}
}

function checkAcenteEditScrn()
{
	with (document.acenteForm) {
		acenteKod.value = acenteKod.value.trim();
		if (acenteKod.value.length == 0) return reportError(acenteKod,acenteAcenteKod);
		
		ticaretSicilNo.value = ticaretSicilNo.value.trim();
		if (ticaretSicilNo.value.length == 0) return reportError(ticaretSicilNo,acenteTicaretSicilNo);

		unvan.value = unvan.value.trim();
		if (unvan.value.length == 0) return reportError(unvan,acenteUnvan);
		
		userEmail.value = userEmail.value.trim();
		if (userEmail.value.length > 0){
			if (emailCheck(userEmail.value) == false){
				setFocus(userEmail);
				return false;
			}
		}	
		telefonNo.value = telefonNo.value.trim();
		if (telefonNo.value.length < 10) return reportError(telefonNo,telefonNoUzunlukHatali);

		faxNo.value = faxNo.value.trim();
		if (faxNo.value.length < 10) return reportError(faxNo,faxNoUzunlukHatali);
	}
	return true;
}

function ilChangeAcenteEditScrn()
{
	with (document.acenteForm) {
		refresh.value="E";
		ilce.selectedIndex = -1;
		submit();
	}
	return false;
}
function acenteEditScrnAckCountLetters(form)	     
{
	form.kalanAlan.value = CheckLen(form.adres,acente_edit_ack_max);
}

//----------------------------------------
// sigortaEdit scrn usage
//----------------------------------------
function initSigortaEditScrn()
{

}

function checkSigortaEditScrn()
{
	return true;
}

//----------------------------------------
// Log scrn usage
//----------------------------------------
function initLogSorguScrn()
{
	with (document.logForm) {
		if (newSorgu.value == "E"){
			basTarih.value = "";
			bitTarih.value = "";
			logKey.selectedIndex = 0;
		}
		setFocus(basTarih);
	}
}

function checkLogSorguScrn()
{
	with (document.logForm) {
		basTarih.value = basTarih.value.trim();
		if (basTarih.value.length == 0) return reportError(basTarih,logTarih);
		if (!checkDate(basTarih.value)) return reportError(basTarih,logTarihGecersiz);
		
		bitTarih.value = bitTarih.value.trim();
		if (bitTarih.value.length == 0) return reportError(bitTarih,logTarih);
		if (!checkDate(bitTarih.value)) return reportError(bitTarih,logTarihGecersiz);

		var d1 = new Date(basTarih.value.substring(6,10),basTarih.value.substring(3,5),basTarih.value.substring(0,2),0,0,0,0);
		var d2 = new Date(bitTarih.value.substring(6,10),bitTarih.value.substring(3,5),bitTarih.value.substring(0,2),0,0,0,0);
		if (dateDiff(d1,d2) > 3) return reportError(bitTarih,logTarihKuralHatali);
		if (compareDateObjects(d1,d2) == 1) return reportError(bitTarih,logTarihBitisHatali);
	}	
	return true;
}

function initLogAppEditScrn()
{
	with (document.logAppForm)
	{ 
	   setFocus(logAppAdi);
	   log_app_ack_max = kalanAlanAck.value;
	   log_app_sql_max = kalanAlanSql.value;
	}
	logAppEditScrnChangeCalDurum(document.logAppForm);
}

function checkLogAppEditScrn()
{	
	with (document.logAppForm) {
		logAppAdi.value = logAppAdi.value.trim();
		if (logAppAdi.value.length == 0) return reportError(logAppAdi,logAppAdiAdiHata);
	}
	return true;
}

function logAppEditScrnChangeCalDurum(form)
{
	if (form.logAppCalDurum.value == 0){
		document.getElementById("div_script1").style.display = "none";
		document.getElementById("div_script2").style.display = "none";
	}
	else{
		document.getElementById("div_script1").style.display = "";
		document.getElementById("div_script2").style.display = "";
	}
	return true; 
}

function logAppEditScrnAckCountLetters(form)	     
{
	form.kalanAlanAck.value = CheckLen(form.logAppAck,log_app_ack_max);
}
function logAppEditScrnSqlCountLetters(form)	     
{
	form.kalanAlanSql.value = CheckLen(form.logAppSql,log_app_sql_max);
}

function logAppAskForDelete(form)	     
{
//	return confirmProcess(logAppAdiDeleteConfirm);
}

//var REPORT_DONEM_GENEL_TARIH = "- Son Liste -";
//duyuru giris screen usage
//----------------------------------------

function initDuyuruBilgiGirisForm()
{
	var myDate = new Date();	
	with (document.duyuruBilgiGirisForm)
	{
		if (newSorgu.value == 'E'){
			tarih.value = formatDate(myDate,Date.defaultFormat);
			duyuruReferansNo.value = "";
			konu.selectedIndex = -1;
			ilgili.value = "";
			duyuruIcerigi.value = "";
			iletildigiKurum.value = "999";
			iletildigiKurumDetayi.value = "";
			gerekenTarih.value = "";
			dataFile.value = null;
			cevapBeklenmiyor();
		}
		setFocus(duyuruReferansNo);
	}
}
function checkCevapBekleniyorMu()
{
	with (document.duyuruBilgiGirisForm){	
		if(cevapBekleniyorMu.checked == true)cevapBekleniyor();
		if(cevapBekleniyorMu.checked == false)cevapBeklenmiyor();
	}
}
function cevapBekleniyor()
{
	with (document.duyuruBilgiGirisForm){
		gerekenTarih.disabled=false;
		tarihImg2.disabled=false;
		cevapBekleniyorMu.value="Evet";
	}
}
function cevapBeklenmiyor()
{
	with (document.duyuruBilgiGirisForm){
		gerekenTarih.disabled=true;
		gerekenTarih.value="";
		tarihImg2.disabled=true;
		cevapBekleniyorMu.value="Hay?r";
	}
}
function saveDuyuruDocument()
{
	with (document.duyuruBilgiGirisForm){
	}
}

function initDuyuruSorguScrn()
{
	with (document.duyuruSorguForm)
	{
		if (newSorgu.value == 'E'){
			tarih.value = "";
			tarihFiltre.value = "";			
			duyuruReferansNo.value = "";
			konu.selectedIndex = 0;
			//iletildigiKurum.value = "999";
			gerekenTarih.value = "";
			cevapDurumu.selectedIndex = 0;
		}
		setFocus(tarih);
	}
}

function checkDuyuruSorguScrn()
{
	with (document.duyuruSorguForm)
	{
		if (konu.selectedIndex == -1) return reportError(konu,duyuruKonuHata);
		if (tarih.value.trim() != ""){
			if (tarihFiltre.selectedIndex == -1) return reportError(tarihFiltre,gerekenTarihFiltreBos);
		}
		if (cevapDurumu.selectedIndex == -1) return reportError(cevapDurumu,gerekenCevapDurumuBos);
	}	
	return true;
}

//----------------------------------------
// hatal?poli?e Sorgu scrn usage
//----------------------------------------
function initHataliPoliceSorguScreen(userTip)
{
	with (document.hataliPoliceForm)
	{
		if(newSorgu.value == "E"){
			setCheckedRadio(sorguTip,SORGUTIP_POLICE_NO,true);				
		}	
	
		if(userTip.value != USERTIP_TRAMER)
		{
			document.getElementById("pbt0").style.display = "none";		
			document.getElementById("pbt1").style.display = "none";		
			document.getElementById("pbt2").style.display = "none";		
			document.getElementById("pbt5").style.display = "none";	
			document.getElementById("pbt6").style.display = "none";		
			document.getElementById("pbt7").style.display = "none";
			document.getElementById("pbt8").style.display = "none";
			document.getElementById("et0").style.display = "none";			
			document.getElementById("et1").style.display = "none";			
			document.getElementById("et2").style.display = "none";
			document.getElementById("et3").style.display = "none";				
		}
		else
		{
			document.getElementById("pbt0").style.display = "";	
			document.getElementById("pbt1").style.display = "";			
			document.getElementById("pbt2").style.display = "";
			document.getElementById("pbt5").style.display = "";	
			document.getElementById("pbt6").style.display = "";	
			document.getElementById("pbt7").style.display = "";	
			document.getElementById("pbt8").style.display = "";				
			document.getElementById("et0").style.display = "";
			document.getElementById("et1").style.display = "";			
			document.getElementById("et2").style.display = "";
			document.getElementById("et3").style.display = "";		
				
		}	
		hataliPoliceSorguTipChange(userTip);	
	}
}
function checkHataliPoliceSorguScreen()
{
	with (document.hataliPoliceForm)
	{
		var sorguTipi = getCheckedRadio(sorguTip);

		if(sorguTipi == SORGUTIP_POLICE_NO) {
			yenilemeNo.value = yenilemeNo.value.trim();
			if (yenilemeNo.value.length == 0) yenilemeNo.value = "0";
			
			//kullan?c? sigorta ?irketi kullan?c?s? ise acente kodu poli?e no yenileme no sahalar?n? girmek zorunda
			if(userTip.value == USERTIP_SIGORTA_SIRKET){	
				if(acenteKod.value.length == 0 || policeNo.value.length == 0 || yenilemeNo.value.lenght == 0)
					return reportError(policeNo,sirketKoduSorgulamasiEksikGiris);	
			}
			//kullan?c? acente kullan?c?s? ise poli?e no yenileme no sahalar?n? girmek zorunda
			else if(userTip.value == USERTIP_ACENTE){
				if(policeNo.value.length == 0 || yenilemeNo.value.lenght == 0)
					return reportError(policeNo,sirketKoduSorgulamasiEksikGiris);				
			}
			//kullan?c? tramer kullan?c?s? ise t?m sahalar? girmek zorunda
			else if(userTip.value == USERTIP_TRAMER){
				if(sigortaSirketKod.selectedIndex == -1 || acenteKod.value.length == 0 || policeNo.value.length == 0 || yenilemeNo.value.lenght == 0)
					return reportError(policeNo,sirketKoduSorgulamasiEksikGiris);							
			}
		}
		
		else if(sorguTipi == SORGUTIP_POLICEBASLAMATARIHI)
		{
			if(matIfade.selectedIndex == -1)
				return reportError(policeBasTrhBir, policeBaslamaTrhSorgulamasiEksikBilgi);
			
			if(matIfade.selectedIndex == 0 && (policeBasTrhBir.value.length == 0 || policeBasTrhIki.value.length == 0))
			    return reportError(policeBasTrhBir, policeBaslamaTrhSorgulamasiEksikBilgi);
			
			if((matIfade.selectedIndex != 0 && matIfade.selectedIndex != -1) && policeBasTrhBir.value.length == 0)
		  		return reportError(policeBasTrhBir, policeBaslamaTrhSorgulamasiEksikBilgi);

			//police baslama tarihi 1, police ba?ama tarihi2'den b?y?k olamaz
			if(policeBasTrhBir.value.length != 0 && policeBasTrhIki.value.length != 0){
				var policeBaslamaTarihiBir = new Date(policeBasTrhBir.value.substring(6,10),policeBasTrhBir.value.substring(3,5)-1,policeBasTrhBir.value.substring(0,2),0,0,0,0);			
				var policeBaslamaTarihiIki = new Date(policeBasTrhIki.value.substring(6,10),policeBasTrhIki.value.substring(3,5)-1,policeBasTrhIki.value.substring(0,2),0,0,0,0);			
				if(compareDateObjects(policeBaslamaTarihiBir, policeBaslamaTarihiIki) == 1)
					return reportError(policeBasTrhBir, polBasTrhBirBuyukPolBasTrhIki);
			}

			//poli?e ba?ama tarih aral?klar? ge?erli mi?
		    if(checkDate(!policeBasTrhBir.value) || (policeBasTrhIki.value.length != 0 && !checkDate(policeBasTrhIki.value)))
		    	return reportError(policeBasTrhBir, policeBaslamaTarihiHatali);

			//sadece poli?e ba?ama tarihleri ile sorgulama yap?amaz. ?rket kodu veya hata kodu se?ilmelidir.
			if(polBasTrhSigortaSirketKod.selectedIndex==-1 && polBasTrhHataKodu.selectedIndex == -1)
				return reportError(policeBasTrhBir, sirketVeyaHataKoduSecilmeli);
		}
		
		else if(sorguTipi == SORGUTIP_HATAKODU)
		{
			if(hataKodu.selectedIndex == -1)
				return reportError(hataKodu, hataKoduEksik);
			//kullan?c? tramer kullan?c?s? de?l ise ?irket acente sahalar?n? girmek zorundad?r.
			if(userTip.value == USERTIP_SIGORTA_SIRKET){
				if(hataKoduAcenteKod.value.length == 0)
					return reportError(hataKodu, hataKoduSorgulamasiEksikBilgi);
			}
		}
		
		else if(sorguTipi == SORGUTIP_BELGE){
			if(belgeNo.value.length == 0)
				return reportError(belgeNo, belgeNoEksik);
		}
		
		else if(sorguTipi == SORGUTIP_EKTURU){
			if(ekTuru.selectedIndex == -1)
				return reportError(ekTuru, ekTuruEksik);			
			if(ekBasTrh.value.length == 0)
				return reportError(ekBasTrh, ekTuruSorgulamasiEksikBilgi);
			if(!checkDate(ekBasTrh.value)) 
				return reportError(ekBasTrh, ekBaslangicTarihiHatali);
		}
		
		else if (sorguTipi == SORGUTIP_PLAKA)
		{
			if((plakaIlKod.value.length != 0 && plakaNo.value.length == 0) || (plakaIlKod.value.length == 0 && plakaNo.value.length != 0) || 									(plakaIlKod.value.length == 0 && plakaNo.value.length == 0))
				return reportError(plakaIlKod, plakaAlanlariTamGirilmemis );
		}
		
		else if(sorguTipi == SORGUTIP_MOTOR){
			if (!motorNoGecerliMi(motorNo)) return reportError(motorNo,gecersizMotorNoIleSorgu);
			
			if(motorNo.value.length == 0)
				return reportError(motorNo, motorNoEksik);
		}
		
		else if(sorguTipi == SORGUTIP_SASI){
			if (!sasiNoGecerliMi(sasiNo)) return reportError(sasiNo,gecersizSasiNoIleSorgu);
			
			if(sasiNo.value.length == 0)
				return reportError(sasiNo, sasiNoEksik);
		}
	}
	return true;
}

function matematikselIfadeChanged()
{
	with (document.hataliPoliceForm)
	{
		if(matIfade.selectedIndex == 0){
			policeBasTrhIki.disabled=false;
			policeBasTrhIki.value = "";
			document.getElementById("pbt6").style.display = "";		
		}
		else{ 
			policeBasTrhIki.disabled=true;
			policeBasTrhIki.value = "";
			document.getElementById("pbt6").style.display = "none";		
		}			
	}
	return true;
}

function hataliPoliceSorguTipChange()
{
	with (document.hataliPoliceForm)
	{
		var sorguTipi = getCheckedRadio(sorguTip);
		
		tumSahalariDisableYap();
		tumSahalariTemizle(sorguTip);

		document.getElementById("sir1").style.display = "none";			
		document.getElementById("sir2").style.display = "none";
		document.getElementById("sir3").style.display = "none";	
		document.getElementById("pbt1").style.display = "none";		
		document.getElementById("pbt2").style.display = "none";			
		document.getElementById("pbt5").style.display = "none";	
		document.getElementById("pbt6").style.display = "none";		
		document.getElementById("pbt7").style.display = "none";	
		document.getElementById("pbt8").style.display = "none";	
		document.getElementById("hk1").style.display = "none";		
		document.getElementById("hk2").style.display = "none";		
		document.getElementById("bn1").style.display = "none";			
		document.getElementById("bn2").style.display = "none";	
		document.getElementById("bn3").style.display = "none";						
		document.getElementById("et1").style.display = "none";			
		document.getElementById("et2").style.display = "none";
		document.getElementById("et3").style.display = "none";				
				
		if(sorguTipi == SORGUTIP_POLICE_NO)
		{
			if (sigortaSirketKod.type != "hidden") sigortaSirketKod.disabled = false;
			if (acenteKod.type != "hidden") acenteKod.disabled = false;		
			document.getElementById("sir1").style.display = "";			
			document.getElementById("sir2").style.display = "";
			document.getElementById("sir3").style.display = "";
			policeNo.disabled=false;
			yenilemeNo.disabled=false;			
		}
		
		else if(sorguTipi == SORGUTIP_POLICEBASLAMATARIHI)
		{
			if (polBasTrhSigortaSirketKod.type != "hidden") polBasTrhSigortaSirketKod.disabled = false;
			if (polBasTrhAcenteKod.type != "hidden") polBasTrhAcenteKod.disabled = false;					
			document.getElementById("pbt1").style.display = "";			
			document.getElementById("pbt2").style.display = "";
			document.getElementById("pbt5").style.display = "";	
			document.getElementById("pbt7").style.display = "";		
			document.getElementById("pbt8").style.display = "";	
			policeBasTrhBir.disabled=false;
			matematikselIfadeChanged();
			matIfade.disabled=false;
			polBasTrhSigortaSirketKod.disabled=false;
			polBasTrhAcenteKod.disabled=false;
			polBasTrhHataKodu.disabled=false;
		}
		
		else if(sorguTipi == SORGUTIP_HATAKODU)
		{
			if (hataKoduSigortaSirketKod.type != "hidden") hataKoduSigortaSirketKod.disabled = false;
			if (hataKoduAcenteKod.type != "hidden") hataKoduAcenteKod.disabled = false;		
			document.getElementById("hk1").style.display = "";			
			document.getElementById("hk2").style.display = "";
			hataKoduSigortaSirketKod.disabled=false;
			hataKoduAcenteKod.disabled=false;
			hataKodu.disabled=false;
		}
		
		else if(sorguTipi == SORGUTIP_BELGE)
		{
			if (belgeNoSigortaSirketKod.type != "hidden") 
				belgeNoSigortaSirketKod.disabled = false;
			
			document.getElementById("bn1").style.display = "";
			document.getElementById("bn3").style.display = "";	
			
			//Tramer kullan???de?l ise bu sahay?g?remez
			if(userTip.value != USERTIP_TRAMER){
				document.getElementById("bn2").style.display = "none";
				belgeNoHataKodu.disabled=true;
			}	
			else{
				document.getElementById("bn2").style.display = "";
				belgeNoHataKodu.disabled=false;
			}
			belgeNo.disabled=false;
			belgeNoSigortaSirketKod.disabled=false;
			belgeNoAcenteKod.disabled = false;
			
		}
		
		else if(sorguTipi == SORGUTIP_EKTURU)
		{
			if (ekTuruSigortaSirketKod.type != "hidden") ekTuruSigortaSirketKod.disabled = false;
			document.getElementById("et1").style.display = "";			
			document.getElementById("et2").style.display = "";
			document.getElementById("et3").style.display = "";	
			ekTuru.disabled=false;
			ekBasTrh.disabled=false;	
			ekTuruHataKodu.disabled=false;
			ekTuruSigortaSirketKod.disabled=false;

		}
		
		else if (sorguTipi == SORGUTIP_PLAKA)
		{	
			plakaIlKod.disabled = false;
			plakaNo.disabled = false;
		}

		else if (sorguTipi == SORGUTIP_MOTOR)
		{	
			motorNo.disabled = false;
		}

		else if (sorguTipi == SORGUTIP_SASI)
		{	
			sasiNo.disabled = false;	
		}

		if (acenteKod.type != "hidden") setInputClass(acenteKod);
		if (sigortaSirketKod.type != "hidden") setInputClass(sigortaSirketKod);
		setInputClass(policeNo     );
		setInputClass(yenilemeNo   );
		setInputClass(plakaIlKod   );
		setInputClass(plakaNo      );
		setInputClass(motorNo      );
		setInputClass(belgeNo      );
		setInputClass(sasiNo       );
		setInputClass(hataKodu     );
		setInputClass(ekTuru       );
		setInputClass(ekBasTrh     );
		setInputClass(matIfade    );
		setInputClass(policeBasTrhBir );
	}
	
}

function tumSahalariDisableYap()
{
	with (document.hataliPoliceForm)
	{
		sigortaSirketKod.disabled=true;
		acenteKod.disabled=true;
		policeNo.disabled=true;
		yenilemeNo.disabled=true;
		policeBasTrhBir.disabled=true;
		policeBasTrhIki.disabled=true;
		ekTuru.disabled=true;
		ekBasTrh.disabled=true;
		plakaIlKod.disabled=true;
		plakaNo.disabled=true;
		belgeNo.disabled=true;
		motorNo.disabled=true;
		sasiNo.disabled=true;
		hataKodu.disabled=true;
		matIfade.disabled=true;
		polBasTrhSigortaSirketKod.disabled=true;
		polBasTrhAcenteKod.disabled=true;
		polBasTrhHataKodu.disabled=true;
		ekTuruHataKodu.disabled=true;
		ekTuruSigortaSirketKod.disabled=true;
		belgeNoSigortaSirketKod.disabled=true;
		belgeNoHataKodu.disabled=true;
		belgeNoAcenteKod.disabled = true;
		hataKoduSigortaSirketKod.disabled=true;
		hataKoduAcenteKod.disabled=true;
		
	}
}

function tumSahalariTemizle(sorguTip)
{
	with (document.hataliPoliceForm)
	{
		if (sorguTip != SORGUTIP_POLICE_NO){
			sigortaSirketKod.selectedIndex = -1;
			acenteKod.value="";
			policeNo.value="";
			yenilemeNo.value="";
		}
		
		if(sorguTip != SORGUTIP_POLICEBASLAMATARIHI) {
			policeBasTrhBir.value="";
			policeBasTrhIki.value="";
			matIfade.selectedIndex=2;
			polBasTrhSigortaSirketKod.selectedIndex=-1;
			polBasTrhAcenteKod.value="";
			polBasTrhHataKodu.value="";			
		}
		
		if(sorguTip != SORGUTIP_EKTURU) {
			ekTuruHataKodu.value="";
			ekTuruSigortaSirketKod.value="";
			ekTuru.value="";
			ekBasTrh.value="";		
		}
		
		if(sorguTip != SORGUTIP_HATAKODU) {
			hataKodu.selectedIndex=-1;
			hataKoduSigortaSirketKod.selectedIndex=-1;
			hataKoduAcenteKod.value="";			
		}	
			
		if(sorguTip != SORGUTIP_PLAKA) {
			plakaIlKod.value="";
			plakaNo.value="";		
		}
		
		if(sorguTip != SORGUTIP_MOTOR) {
			motorNo.value="";
		}
		
		if(sorguTip != SORGUTIP_SASI) {
			sasiNo.value="";
		}
		
		if(sorguTip != SORGUTIP_BELGE) {
			belgeNo.value="";
			belgeNoSigortaSirketKod.value="";
			belgeNoHataKodu.selectedIndex=-1;
			belgeNoAcenteKod.value="";		
		}								
	}
}


//-----------------------------------------------------------------------------------------------
// kimlik sorgulama
//-----------------------------------------------------------------------------------------------

function checkKimlikSorguScrn()
{
	with(document.kimlikSorguForm)
	{
		var st = getCheckedRadio(sorguTip);
		
		TCkimlikNumarasi.value = TCkimlikNumarasi.value.trim();
		vergiKimlikNumarasi.value = vergiKimlikNumarasi.value.trim();

		if(st == KIMLIKTIP_TC){
				if (TCkimlikNumarasi.value.length == 0) return reportError(TCkimlikNumarasi,tcKimlikNoGirilmemis);
				if (isNaN(TCkimlikNumarasi.value)) return reportError(TCkimlikNumarasi,tcKimlikNoHatali);
				if (TCkimlikNumarasi.value.length != 11)	return reportError(TCkimlikNumarasi,tcKimlikNoGecersiz);
		}
		else{
				if (vergiKimlikNumarasi.value.length == 0) return reportError(vergiKimlikNumarasi,vergiKimlikNoGirilmemis);
				if (isNaN(vergiKimlikNumarasi.value)) return reportError(vergiKimlikNumarasi,vergiKimlikNoHatali);
				if (vergiKimlikNumarasi.value.length != 10)	return reportError(vergiKimlikNumarasi,vergiKimlikNoGecersiz);
		}		
	}
}
function initKimlikSorguScrn()
{
	with(document.kimlikSorguForm)
	{
		setCheckedRadio(sorguTip,KIMLIKTIP_TC,true);
	}
	kimlikSorguTipChanged();
}

function kimlikSorguTipChanged()
{
	with(document.kimlikSorguForm)
	{
		var st = getCheckedRadio(sorguTip);

		kimlikAlanlariniSil();
		kimlikAlanlariniDisableYap();

		if(st == KIMLIKTIP_TC){
			TCkimlikNumarasi.disabled = false;
		}
		else{
			vergiKimlikNumarasi.disabled = false;
		}
		setInputClass(vergiKimlikNumarasi);	
		//setInputClass(TCkimlikNumarasi);
	}
}

function kimlikAlanlariniSil()
{
	with(document.kimlikSorguForm)
	{
		vergiKimlikNumarasi.value = "";
		TCkimlikNumarasi.value = "";
	}
}
function kimlikAlanlariniDisableYap()
{
	with(document.kimlikSorguForm)
	{
		vergiKimlikNumarasi.disabled = true;
		TCkimlikNumarasi.disabled = true;
	}
}

function basamaklarAyni(kimlikNo)
{
	for(var i=0; i<(kimlikNo.value.length)-1 ; i++)
	{
		if(kimlikNo.value.charAt(i) != kimlikNo.value.charAt(i+1))
			return false;
	}
	return true;
}

function setInputClass(x) {
	if (x.disabled) {
		x.className = "DisabledInput";
	} else {
		x.className = "clsInputText";
	}
}

function plakaGecerliMi(plakaNo) 
{
	var upperCasePlaka = plakaNo.value.toUpperCase();
	var bMatch = false;
	var hataliSahaValues = kontrolEdilecekPlaka;
	plakaNo.value = plakaNo.value.toUpperCase();
	for (var i=0; !bMatch && i < hataliSahaValues.length;i++)
	{
		var straDeger = hataliSahaValues[i];
		bMatch = (straDeger == plakaNo.value);
	}
	if(bMatch){		
		return false;
	}
		
	return true;
}

function motorNoGecerliMi(motorNo)
{
	var motorNoUpper = motorNo.value.toUpperCase();
	var bMatch = false;
	var hataliSahaValues = kontrolEdilecekMotor;
	
	for (var i=0; !bMatch && i < hataliSahaValues.length;i++)
	{
		var straDeger = hataliSahaValues[i];
		bMatch = (straDeger == motorNoUpper);
	}
	if(bMatch){		
		return false;
	}
	return true;    	    
}

function sasiNoGecerliMi(sasiNo)
{
	var sasiNoUpper = sasiNo.value.toUpperCase();
	var bMatch = false;
	var hataliSahaValues = kontrolEdilecekSasi;
	
	for (var i=0; !bMatch && i < hataliSahaValues.length;i++)
	{
		var straDeger = hataliSahaValues[i];
		bMatch = (straDeger == sasiNoUpper);
	}
	if(bMatch){		
		return false;
	}
	return true;    	    
}