
//----------------------------------------
// App constants
//----------------------------------------

var USERTIP_ACENTE = "AK";
var USERTIP_SIGORTA_SIRKET= "SK";
var USERTIP_SIGORTA_SIRKET_OZEL= "SKP";
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 USERTIP_GARANTI_HESABI= "GH";
var USERTIP_JANDARMA= "JK";
var USERTIP_ULASTIRMA_BAKANLIGI= "UBK";
var USERTIP_MILLI_REASURANS= "MRK";
var USERTIP_INTERPOL= "IK";


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_YESILKARTNO=18;


//----------------------------------------
// policeSorgu scrn usage
//----------------------------------------
function initYesilkartPoliceSorguScrn()
{
	with (document.policeSorguForm)
	{
		captcha.value="";
		if(newSorgu.value == "E"){
			yesilkartNo.value = "";
			setCheckedRadio(sorguTip,SORGUTIP_YESILKARTNO,true);
		}
		else{	
			var sorguTipVal = getCheckedRadio(sorguTip);
			
			setCheckedRadio(sorguTip,SORGUTIP_YESILKARTNO,true);
			
			if (yesilkartNo.value != ""){
				 setCheckedRadio(sorguTip,SORGUTIP_YESILKARTNO,true);		
			}
			else{
				yesilkartNo.value = "";
			}
			
			if (policeNo.value != ""){
				 setCheckedRadio(sorguTip,SORGUTIP_YESILKARTNO,true);		
			}
			else{
				if (sigortaSirketKod.type != "hidden") sigortaSirketKod.selectedIndex = -1;
				if (acenteKod.type != "hidden") acenteKod.value = "";
				policeNo.value = "";
				yenilemeNo.value = "";
			}
			
			if (plakaIlKod.value != ""){
				setCheckedRadio(sorguTip,SORGUTIP_PLAKA,true);
			}
			else{
				plakaIlKod.value = "";
				plakaNo.value = "";
			}
			
			if (motorNo.value != "") setCheckedRadio(sorguTip,SORGUTIP_MOTOR,true);
			if (typeof(sasiNo) != "undefined"){
				if (sasiNo.value != "") setCheckedRadio(sorguTip,SORGUTIP_SASI,true);
			}

			if (userTip.value == USERTIP_TRAMER || userTip.value == USERTIP_BIRLIK || userTip.value == USERTIP_HAZINE || 
				userTip.value == USERTIP_SAGLIK || userTip.value == USERTIP_GARANTI_HESABI  || userTip.value == USERTIP_EMNIYET || 
				userTip.value == USERTIP_EKSPER || userTip.value == USERTIP_JANDARMA || userTip.value == USERTIP_INTERPOL)
			{
				if (musteriAd.value != ""){ 
					setCheckedRadio(sorguTip,SORGUTIP_MUSTERI_AD_SOYAD,true);
				}
				else{
					musteriAd.value = "";
					musteriSoyad.value = "";
				}	
			}
	
			if (userTip.value == USERTIP_TRAMER || userTip.value == USERTIP_BIRLIK || userTip.value == USERTIP_HAZINE || 
				userTip.value == USERTIP_SAGLIK || userTip.value == USERTIP_GARANTI_HESABI  || userTip.value == USERTIP_EMNIYET || 
				userTip.value == USERTIP_EKSPER || userTip.value == USERTIP_JANDARMA || userTip.value == USERTIP_SIGORTA_SIRKET || 
				userTip.value == USERTIP_SIGORTA_SIRKET_OZEL || userTip.value == USERTIP_INTERPOL)
			{
				if (musteriVergiNo.value != "") {
					setCheckedRadio(sorguTip,SORGUTIP_MUSTERI_VERGI_NO,true);
				}
				else {
					musteriVergiNo.value = "";
				}
			}
			if (userTip.value == USERTIP_TRAMER || userTip.value == USERTIP_BIRLIK || userTip.value == USERTIP_HAZINE || 
				userTip.value == USERTIP_SAGLIK || userTip.value == USERTIP_GARANTI_HESABI  || userTip.value == USERTIP_EMNIYET || 
				userTip.value == USERTIP_EKSPER || userTip.value == USERTIP_JANDARMA || userTip.value == USERTIP_SIGORTA_SIRKET ||
				userTip.value == USERTIP_SIGORTA_SIRKET_OZEL || userTip.value == USERTIP_INTERPOL)
			{
				if (musteriVatandasNo.value != "") {
					setCheckedRadio(sorguTip,SORGUTIP_MUSTERI_VATANDAS_NO,true);
				}
				else {
					musteriVatandasNo.value = "";
				}
			}
		}
	}
	yesilkartPoliceSorguTipChange(policeSorguForm);
}

function checkYesilkartPoliceSorguScrn()
{
	with (document.policeSorguForm)
	{
		var sorguTipVal = getCheckedRadio(sorguTip);

 		if (sorguTipVal == SORGUTIP_YESILKARTNO)
		{		
			yesilkartNo.value = yesilkartNo.value.trim();
			if (yesilkartNo.value.length == 0) return reportError(yesilkartNo,policeYesilkartNo);
		}
		else if (sorguTipVal == SORGUTIP_POLICE_NO)
		{
			if (sigortaSirketKod.type != "hidden" && sigortaSirketKod.selectedIndex == -1)return reportError(sigortaSirketKod,policeSigortaSirketKod);
			
			acenteKod.value = acenteKod.value.trim();
			if (acenteKod.value.length == 0) return reportError(acenteKod,policeAcenteKod);
			
			policeNo.value = policeNo.value.trim();
			if (policeNo.value.length == 0) return reportError(policeNo,policePoliceNo);

			yenilemeNo.value = yenilemeNo.value.trim();
			if (yenilemeNo.value.length == 0) yenilemeNo.value = "0";
		}
		else if (sorguTipVal == SORGUTIP_PLAKA)
		{
			plakaIlKod.value = plakaIlKod.value.trim();
			if (plakaIlKod.value.length == 0) return reportError(plakaIlKod,policePlaka);
			if (isNaN(plakaIlKod.value)) return reportError(plakaIlKod,policePlakaIlKodGecersiz);

			plakaNo.value = plakaNo.value.trim();
			if (plakaNo.value.length == 0) return reportError(plakaNo,policePlaka);

			if(userTip.value != USERTIP_TRAMER)
			{
				if (!plakaGecerliMi(plakaNo))
					return reportError(plakaNo, plakaNoGecici);	
			}			
			
			if (userTip.value != USERTIP_TRAMER && plakaNo.value.length < 5) 
				return reportError(plakaNo, policePlakaNoGecersiz);

		}		
		else if (sorguTipVal == SORGUTIP_MOTOR)
		{		
			if (!motorNoGecerliMi(motorNo)) return reportError(motorNo,gecersizMotorNoIleSorgu);

			motorNo.value = motorNo.value.trim();
			if (motorNo.value.length == 0) return reportError(motorNo,policeMotorNo);
		}
		else if (sorguTipVal == SORGUTIP_SASI)
		{	
			if (!sasiNoGecerliMi(sasiNo)) return reportError(sasiNo,gecersizSasiNoIleSorgu);
			
			sasiNo.value = sasiNo.value.trim();
			if (sasiNo.value.length == 0) return reportError(sasiNo,policeSasiNo);
		}
		else if (sorguTipVal == SORGUTIP_MUSTERI_AD_SOYAD)
		{	
			musteriAd.value = musteriAd.value.trim();
			if (musteriAd.value.length == 0) return reportError(musteriAd,policeMusteriAd);			
			musteriSoyad.value = musteriSoyad.value.trim();
			if (musteriSoyad.value.length == 0) return reportError(musteriSoyad,policeMusteriSoyad);			
		}
		else if (sorguTipVal == SORGUTIP_MUSTERI_VERGI_NO)
		{	
			musteriVergiNo.value = musteriVergiNo.value.trim();
			if (isNaN(musteriVergiNo.value)) return reportError(musteriVergiNo,policeMusteriVergiNoHatali);
			else if (musteriVergiNo.value.length == 0) return reportError(musteriVergiNo,policeMusteriVergiNo);
			else if (musteriVergiNo.value.length != 10) return reportError(musteriVergiNo,policeMusteriVergiNoUzunluguHatali);
			else if (basamaklarAyni(musteriVergiNo)) return reportError(musteriVergiNo,policeMusteriVergiNoHatali);
		}
		else if (sorguTipVal == SORGUTIP_MUSTERI_VATANDAS_NO)
		{	
			musteriVatandasNo.value = musteriVatandasNo.value.trim();
			if (isNaN(musteriVatandasNo.value)) return reportError(musteriVatandasNo,policeMusteriVatandasNoHatali);
			else if (musteriVatandasNo.value.length == 0) return reportError(musteriVatandasNo,policeMusteriVatandasNo);
			else if (musteriVatandasNo.value.length != 11) return reportError(musteriVatandasNo,policeMusteriVatandasNoUzunluguHatali);
			else if (basamaklarAyni(musteriVatandasNo)) return reportError(musteriVatandasNo,policeMusteriVatandasNoHatali);
		}	
		var noc = document.getElementById("noCaptcha");
		if (noc == null || noc.value!="TRAMER") {
			captcha.value = captcha.value.trim();
			if (captcha.value.length == "0") return reportError(captcha, captchaTextRequired); 	
		}
	}
	return true;
}

function yesilkartPoliceSorguTipChange(form)
{
	var sorguTip = getCheckedRadio(form.sorguTip);
		
	if (form.sigortaSirketKod.type != "hidden") 
		form.sigortaSirketKod.disabled = true;
	
	if (form.acenteKod.type != "hidden") 
		form.acenteKod.disabled = true;
	
	form.policeNo.disabled = true;
	form.yenilemeNo.disabled = true;
	form.plakaIlKod.disabled = true;
	form.plakaNo.disabled = true;
	form.motorNo.disabled = true;
	form.yesilkartNo.disabled = true;
	
	if (form.sasiNo != null) 
		form.sasiNo.disabled = true;	
	
	if (form.musteriAd != null) {
		form.musteriAd.disabled = true;
		form.musteriSoyad.disabled = true;
	}
	
	if (form.musteriVergiNo != null) {
		form.musteriVergiNo.disabled = true;
	}
	
	if(form.musteriVatandasNo != null) {
		form.musteriVatandasNo.disabled = true;
	}
	
	/*	Secilmemis ise degerlerini sifirla		*/
	if (sorguTip != SORGUTIP_YESILKARTNO)
	{	
		form.yesilkartNo.value = "";
	}
	if (sorguTip != SORGUTIP_POLICE_NO)
	{
		if (form.sigortaSirketKod.type != "hidden") form.sigortaSirketKod.selectedIndex = -1;
		if (form.sigortaSirketKod.type != "hidden") form.acenteKod.value = "";
		form.policeNo.value = "";
		form.yenilemeNo.value = "";
	}
	if (sorguTip != SORGUTIP_PLAKA)
	{	
		form.plakaIlKod.value = "";
		form.plakaNo.value = "";
	}
	if (sorguTip != SORGUTIP_MOTOR)	form.motorNo.value = "";
	if (sorguTip != SORGUTIP_SASI){
		if (form.sasiNo != null) form.sasiNo.value = "";	
	}
	if (sorguTip != SORGUTIP_MUSTERI_AD_SOYAD)
	{	
		if (form.musteriAd != null) {
			form.musteriAd.value = "";
			form.musteriSoyad.value = "";
		}
	}
	if (sorguTip != SORGUTIP_MUSTERI_VERGI_NO)	
	{
		if (form.musteriVergiNo != null) {
			form.musteriVergiNo.value = "";
		}
	}
	if (sorguTip != SORGUTIP_MUSTERI_VATANDAS_NO) 
	{
		if(form.musteriVatandasNo != null) {
			form.musteriVatandasNo.value = "";
		}
	}
	
	if (sorguTip == SORGUTIP_YESILKARTNO)
	{	
		form.yesilkartNo.disabled = false;	
		setFocus(form.yesilkartNo);
	}
	else if (sorguTip == SORGUTIP_POLICE_NO)
	{
		if (form.sigortaSirketKod.type != "hidden") form.sigortaSirketKod.disabled = false;
		if (form.acenteKod.type != "hidden") form.acenteKod.disabled = false;
		form.policeNo.disabled = false;
		form.yenilemeNo.disabled = false;
		if (form.sigortaSirketKod.type != "hidden") setFocus(form.sigortaSirketKod);
		if (form.acenteKod.type != "hidden") setFocus(form.acenteKod);
		else setFocus(form.policeNo);
	}
	else if (sorguTip == SORGUTIP_PLAKA)
	{	
		form.plakaIlKod.disabled = false;
		form.plakaNo.disabled = false;
		setFocus(form.plakaIlKod);
	}
	else if (sorguTip == SORGUTIP_MOTOR)
	{	
		form.motorNo.disabled = false;
		setFocus(form.motorNo);	
	}
	else if (sorguTip == SORGUTIP_SASI)
	{	
		form.sasiNo.disabled = false;	
		setFocus(form.sasiNo);
	}
	else if (sorguTip == SORGUTIP_MUSTERI_AD_SOYAD)
	{	
		form.musteriAd.disabled = false;
		form.musteriSoyad.disabled = false;
		setFocus(form.musteriAd);
	}
	else if (sorguTip == SORGUTIP_MUSTERI_VERGI_NO)
	{	
		form.musteriVergiNo.disabled = false;
		setFocus(form.musteriVergiNo);
	}
	else if (sorguTip == SORGUTIP_MUSTERI_VATANDAS_NO)
	{	
		form.musteriVatandasNo.disabled = false;
		setFocus(form.musteriVatandasNo);
	}

	if (form.sigortaSirketKod.type != "hidden") setInputClass(form.sigortaSirketKod);
	setInputClass(form.policeNo     );
	setInputClass(form.policeNo     );
	setInputClass(form.yenilemeNo   );
	setInputClass(form.plakaIlKod   );
	setInputClass(form.plakaNo      );
	setInputClass(form.motorNo      );
	setInputClass(form.yesilkartNo  );
	
	if (form.sasiNo != null) setInputClass(form.sasiNo       );
	if (form.musteriAd != null) {
		setInputClass(form.musteriAd    );
		setInputClass(form.musteriSoyad );
	}
	if(form.musteriVergiNo != null) {
		setInputClass(form.musteriVergiNo    );
	}
	if(form.musteriVatandasNo != null) {
		setInputClass(form.musteriVatandasNo );
	}
	
	if (form.acenteKod.type != "hidden") 
		setInputClass(form.acenteKod);		
}

