﻿/******************************************************************************
 *   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" target="GunlukEndeksIFrame">' ;
	strHTML += ' <nobr><h1>Tarih seçiniz : ';
	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:submitGunlukEndeksForm()"  target = "_self" class="hd"> Sonuçları Göster</a>';
   strHTML += '</h1></nobr></FORM>';
   putHTML(strHTML);
}

function putGunlukEndeksFrame(){
	strHTML = '<iframe frameborder="1" name="GunlukEndeksIFrame" width="750" height="500"></iframe>';
   putHTML(strHTML);
}

function putAylikEndeksFormHeader(){
	strHTML = '<FORM NAME="AylikEndeksForm" METHOD="POST" ACTION="jsp/Bulten.asp" target="AylikEndeksIFrame" >' ;
	strHTML += ' <nobr><h1>Aylı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:submitAylikEndeksForm()"  target = "_self" class="hd"> Sonuçları Göster</a>';
   strHTML += ' </h1></nobr></FORM>';
   putHTML(strHTML);
}

function putAylikEndeksFrame(){
   strHTML = '<iframe frameborder="1" name="AylikEndeksIFrame" width="750" height="500"></iframe>';
   putHTML(strHTML);
}
function putGunSelect(){
	strHTML = '<SELECT size="1" name="gun">';

	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 = '<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 = '<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;

		bultenURL = "http://www.polatliborsa.org.tr/bulten/GunlukBulten_" + strSelectedGun + "." + strSelectedAy + "." + strSelectedYil + ".html";
		objDocument.frames['GunlukEndeksIFrame'].location.href = bultenURL;
	}else{
		alert( "Seçtiginiz 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;

		bultenURL = "http://www.polatliborsa.org.tr/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;
	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;
	}
}


