/******************************************************************************
 *   Author        : Hakan Serce
 *   File Name     : EndeksFormlari_ie_tr.js
 *   Created       : 25.03.2001
 *   Related Files : tr/Giris_noFrames.htm
 *   Explanation   : The scripts used to create Endeks informatios 
 *                   [forms and iframes]
 *     
 *   Related Files : tr/Giris_noFrames.htm, tr/EndeksSorguSonuclari.jsp
 *
 *     Tarih:               Yazar:                  Aciklama:
 *     ---------            ------                  ---------
 *     28.03.2001           HS                     Haz&#305;rland&#305;.
 *     10.04.2001                                  Version 1.4 
 *     09.05.2001           HS                     SPR No : 140 Problem No: 4
 *     10.04.2001                                  Version 1.6 
 *     15.05.2001           HS                     SPR No:141 Problem No:1
 *     15.05.2001                                  Version 1.7 
 *     28.05.2001           HS                     SPR No :142 Problem No:1,2
 *     30.05.2001                                  Version 1.8
 *     22.06.2001           HS                     SPR No :145 Problem No:1
 *     22.06.2001                                  Version 2.0
 *     24.12.2002           HS                    PR No :38 Problem No:1
 *     05.01.2003           HS                    PR No :40 Problem No:2
 *     07.04.2003           HS                    PR No :41 Problem No:2
 ******************************************************************************/

   var objDocument;
   var intGun, intAy, intYil;
   var strSelectedGun, strSelectedAy, strSelectedYil;
   
   var BASLANGIC_YIL = 2000; //2000 den itibaren data var!

/////////////////////////////////////////////////////////////////
/// PUBLIC FUNCTIONS
/////////////////////////////////////////////////////////////////


function createGunlukEndeks( theDoc ){
	objDocument = theDoc;
	createDate();
	putGunlukEndeksFormHeader();
	putGunSelect();
	putAySelect(0); //05.04.2003
	putYilSelect();
	putGunlukEndeksFormFooter();
	putGunlukEndeksFrame();
	//submitGunlukEndeksForm();
}

function createAylikEndeks( theDoc ){
	objDocument = theDoc;
	createDate();
	putAylikEndeksFormHeader();
	putAySelect(-1); //05.04.2003
	putYilSelect();
	putAylikEndeksFormFooter();
	putAylikEndeksFrame();
	//submitAylikEndeksForm();
}

/////////////////////////////////////////////////////////////////
/// PRIVATE FUNCTIONS
/////////////////////////////////////////////////////////////////

function createDate(){
	  datCurrent = new Date();
	  intGun = datCurrent.getDate();
	  intAy = datCurrent.getMonth() + 1;
	  intYil = datCurrent.getYear();
}

function putGunlukEndeksFormHeader(){
	strHTML = '<FORM NAME="GunlukEndeksForm" METHOD="POST" ACTION="jsp/Bulten.asp"' ;
	strHTML += ' target="GunlukEndeksIFrame" >';
	strHTML += ' <nobr><h1>Günlük Bülten ';
	strHTML += '<INPUT TYPE=HIDDEN NAME="basTarihi" VALUE="00.00.0000">';
	strHTML += '<INPUT TYPE=HIDDEN NAME="bitTarihi" VALUE="00.00.0000"> (';
	
   putHTML(strHTML);
}

function putGunlukEndeksFormFooter(){
   //strHTML = ' ) [ <a href="javascript:this.document.forms[\'GunlukEndeksForm\'].submit()"  target = "_self" class=hd> ';
   strHTML = ' ) [ <a href="javascript:submitGunlukEndeksForm()"  target = "_self" class=hd> ';
   strHTML += 'Göster &GT;&GT; </a>]</FORM></h1> </nobr>';
   putHTML(strHTML);
}

function putGunlukEndeksFrame(){
	strHTML = '<iframe frameborder=0 name="GunlukEndeksIFrame" ';
	//strHTML += ' src= "EndeksSorguSonuclari.jsp?peryot=Gunluk&gun=' + intGun + '&ay=' + intAy + '&yil=' + intYil + '"' ;
	strHTML += ' width = 700 height= 10000>';
	strHTML += ' </iframe>';
   putHTML(strHTML);
}

function putAylikEndeksFormHeader(){
	strHTML = '<FORM NAME="AylikEndeksForm" METHOD="POST" ACTION="jsp/Bulten.asp"' ;
	strHTML += ' target="AylikEndeksIFrame" >';
	strHTML += ' <nobr><h1>Ayl&#305;k Bülten ';
	strHTML += '<INPUT TYPE=HIDDEN NAME="basTarihi" VALUE="00.00.0000">';
	strHTML += '<INPUT TYPE=HIDDEN NAME="bitTarihi" VALUE="00.00.0000"> (';
	
   putHTML(strHTML);
}

function putAylikEndeksFormFooter(){
   //strHTML = ' ) [ <a href="javascript:this.document.forms[\'AylikEndeksForm\'].submit()"  target = "_self" class=hd> ';
   strHTML = ' ) [ <a href="javascript:submitAylikEndeksForm()"  target = "_self" class=hd> ';
   strHTML += 'Göster &GT;&GT; </a>]</FORM></h1> </nobr>';
   putHTML(strHTML);
}

function putAylikEndeksFrame(){
	strHTML = '<iframe frameborder=0 name="AylikEndeksIFrame" ';
	//strHTML += ' src= "EndeksSorguSonuclari.jsp?peryot=Aylik&ay=' + intAy + '&yil=' + intYil + '"' ;
	strHTML += ' width = 700 height= 10000>';
	strHTML += ' </iframe>';
   putHTML(strHTML);
}
function putGunSelect(){
	strHTML = 'Gün : <SELECT size="1" name="gun">';

	//REMINDER : 31 is used as max day for each month for simplicity
	for(intI=0; intI < 31 ; intI++){
		if( (intI+1) == intGun){
			strHTML += '<option selected>' + (intI + 1) + '</option>';
		}else{
			strHTML += '<option >' + (intI + 1) + '</option>';
		}
	}
   strHTML += '</SELECT>';
   putHTML(strHTML);
}

function putAySelect( adjustment ){  //05.04.2003, HS : Gunlukte simdiki ay,aylikta bir onceki ay gosteriliyor
	strHTML = 'Ay : <SELECT size="1" name="ay">';
	for(intI=0; intI < 12 ; intI++){
		if( (intI+1-adjustment) == intAy){
			strHTML += '<option selected>' + (intI + 1) + '</option>';
		}else{
			strHTML += '<option>' + (intI + 1) + '</option>';
		}
	}
   strHTML += '</SELECT>';
   putHTML(strHTML);
}

function putYilSelect(){
	strHTML = 'Y&#305;l : <SELECT size="1" name="yil">';
	for(intI = BASLANGIC_YIL; intI < intYil ; intI++){
		strHTML += '<option>' + intI  + '</option>';
	}
	strHTML += '<option selected>' + intYil + '</option>';
	strHTML += '</SELECT>';
	putHTML(strHTML);
}

function submitGunlukEndeksForm(){
	if( validateSubmitGunlukEndeksForm() ){
		var frmGunluk = objDocument.forms["GunlukEndeksForm"];
		var intSelectedAy = parseInt(strSelectedAy);
		var intSelectedGun = parseInt(strSelectedGun);
		if(  intSelectedAy < 10 ){
			strSelectedAy = "0" + intSelectedAy ;
		}
		if(  intSelectedGun < 10 ){
			strSelectedGun = "0" + intSelectedGun ;
		}
		
		frmGunluk.basTarihi.value = strSelectedGun + "." + strSelectedAy + "." + strSelectedYil;
		frmGunluk.bitTarihi.value = strSelectedGun + "." + strSelectedAy + "." + strSelectedYil;
		//frmGunluk.submit();

		//24.12.2002, HS
		bultenURL = "../bulten/GunlukBulten_" + strSelectedGun + "." + strSelectedAy + "." + strSelectedYil + ".html";
		objDocument.frames['GunlukEndeksIFrame'].location.href = bultenURL;
	}else{
		alert( "Seçtiğiniz tarihe ait bülten bilgileri henüz sisteme aktarılmamıştır.");
	}
}

function submitAylikEndeksForm(){
	if( validateSubmitAylikEndeksForm() ){
		var strNextAy;
		var frmAylik = objDocument.forms["AylikEndeksForm"];
		var intSelectedAy = parseInt(strSelectedAy);
		intNextYil = parseInt(strSelectedYil);

		if(  intSelectedAy < 10 ){
			strSelectedAy = "0" + intSelectedAy ;
		}
		if( intSelectedAy == 12 ){
			intNextYil = parseInt( strSelectedYil ) + 1;
			strNextAy = "01";
		}else if( intSelectedAy >= 9 ){
		    intNextAy = intSelectedAy + 1;
		    strNextAy = intNextAy;
		}else{
		    intNextAy = intSelectedAy + 1;
		    strNextAy = "0" + intNextAy;
		}
		
		frmAylik.basTarihi.value = "01" + "." + strSelectedAy + "." + strSelectedYil;
		frmAylik.bitTarihi.value = "01" + "." + strNextAy + "." + intNextYil;
		//frmAylik.submit();

		//24.12.2002, HS
		//bultenURL = "../bulten/AylikBulten_" +  ( (strSelectedAy.charAt(0) == '0' ) ? strSelectedAy.substring( 1 ) : strSelectedAy ) + "." + strSelectedYil  + ".html";

		//07.04.2003, HS
		bultenURL = "../bulten/AylikBulten_" +  strSelectedAy  + "." + strSelectedYil  + ".html";
		objDocument.frames['AylikEndeksIFrame'].location.href = bultenURL;
	}else{
		alert( "Seçtiğiniz tarihe ait bülten bilgileri henüz sisteme aktarılmamıştır.");
	}
}

//this is to improve readability
function putHTML(strHTML){
	objDocument.writeln(strHTML);
}

//validate and submit gunluk endeks for
function validateSubmitGunlukEndeksForm(){
	var frmGunlukEndeksForm = objDocument.forms[ "GunlukEndeksForm" ];
	strSelectedGun = frmGunlukEndeksForm.gun.options[ frmGunlukEndeksForm.gun.selectedIndex ].text;
	strSelectedAy = frmGunlukEndeksForm.ay.options[ frmGunlukEndeksForm.ay.selectedIndex ].text;
	strSelectedYil = frmGunlukEndeksForm.yil.options[ frmGunlukEndeksForm.yil.selectedIndex ].text;
	//alert( strSelectedGun + "," + strSelectedAy + "," + strSelectedYil + "," + intGun + "," + intAy + "," + intYil + "," + frmGunlukEndeksForm.gun.selectedIndex );
	if ( strSelectedYil > intYil ){
		return false;
	}else if ( strSelectedYil == intYil ){
		if( strSelectedAy > intAy ){
			return false;
		}else if( ( strSelectedAy == intAy ) && (strSelectedGun > intGun )){
			return false;
		}else{
			return true;
		}
	}else{
		return true;
	}
}

//validate and submit aylik endeks form
function validateSubmitAylikEndeksForm(){
	var frmAylikEndeksForm = this.document.forms[ "AylikEndeksForm" ];
	strSelectedAy = frmAylikEndeksForm.ay.options[ frmAylikEndeksForm.ay.selectedIndex ].text;
	strSelectedYil = frmAylikEndeksForm.yil.options[ frmAylikEndeksForm.yil.selectedIndex ].text;
	if ( strSelectedYil > intYil ){
		return false;
	}else if ( ( strSelectedYil == intYil ) && ( strSelectedAy >= intAy ) ){
		return false;
	}else{
		return true;
	}
}



////////////////////////////////////////////////////////
// DEBUGGING CODE
////////////////////////////////////////////////////////

//createGunlukEndeks(document);
//createAylikEndeks(document);

//document.writeln('\u01fb NSAN');

//for( intI = 0; intI < 400 ; intI ++){
//	eval("document.writeln('" + intI + " : "  + "&#" + intI + ";<br>');");
//}


