var defrownum=25;
function mytable(){
this.inittable=inittable;
this.refreshTable=refreshTable;
this.rowsToDisplay = (theRows.length>defrownum)? defrownum:theRows.length;	
this.iFirst = 0;
this.showsearch=true;
this.initsort=new Array(0,1);
this.shownum=true;
this.highlight=true;
this.searchcolumn=0;
this.header="";
this.targetname="table";
this.tabrows="";
this.tabcount="";
this.footerend="";
this.iLast =this.rowsToDisplay;		
this.theColumn = new Array();
this.visCols=new Array();	
this.tableWidth=0;
this.calctablewidth=calctablewidth;
this.controlaccess=true;
this.refreshHeader=refreshHeader;
this.refreshTabRows=refreshTabRows;
this.refreshTabCount=refreshTabCount;
this.scrollTable=scrollTable;
this.scrollTo=scrollTo;
this.mySort=mySort;
}
var isMinNS6 = (navigator.appName.indexOf("Netscape") >= 0 &&
       			 document.getElementById);

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4  && !document.getElementById) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
var isMinIE55 = (isMinIE4 && navigator.appVersion.indexOf("5.5") >= 0) ? 1 : 0;
var kSort = new Array(0, 1);

var isLimited=false;
arImLoad = ["fpage2","ppage2","npage2","lpage2","yrdm2","ara2","gos2","fpage","ppage","npage","lpage","yrdm","ara","gos"];
arImList = [];
for (counter in arImLoad) {
    arImList[counter] = new Image();
    arImList[counter].src = "../images/"+arImLoad[counter] + ".gif";
}

function calctablewidth()
{
  var oldw=this.tableWidth;
  this.tableWidth =0; 
  for (j=0; j<theCols.length; j++){
    if (this.visCols[j])	this.tableWidth += theCols[j][2];
  }
  if (oldw!=0 & oldw!=null)
  { 
    carpan=oldw/this.tableWidth;
	for (j=0; j<theCols.length; j++)
	{
     if (this.visCols[j])
	 	theCols[j][2] = theCols[j][2]*carpan;
  	}
	theCols[theCols.length-1][2]=0;
	this.tableWidth =oldw;

  } 
  if (this.shownum)  this.tableWidth += 20;
}
function inittable(){
  kSort[0]=this.initsort[0];
  kSort[1]=this.initsort[1];
  this.rowsToDisplay=(theRows.length<this.rowsToDisplay+1)?theRows.length:this.rowsToDisplay;
  this.iLast=this.iFirst+this.rowsToDisplay;
  if (this.visCols.length!=theCols.length) 
  for (var i=0; i < theCols.length; i++)
  { 
    this.visCols[i]=true;
  }
  this.calctablewidth();
  for (var i=0; i < theRows.length; i++) 
  { 
	  this.theColumn[i] = new Array(0,i);
  }	   
  this.footerend="<tr><td for='maintable'><table id='tbl_footer' cellpadding=3 cellspacing=3><tr id='tr_footer'>"
  if (this.iFirst==0 & this.iLast==theRows.length)
  {
    
  }
  else
  {
		 var kodlist=new Array();
		 for (var i=0; i < theRows.length; i++) 
		 { 
		   this.theColumn[i] = new Array(0,i);
           x=theRows[i][this.searchcolumn];
		   x=innerText(x);//.toUpperCase();
		   kodlist[kodlist.length]=x;
		 }
		 if (this.showsearch) 
		 { 
		   this.footerend += "\n<TD id='td_select'>\n<select id=\"hisse\"  NAME=\"hisse\" SIZE=\"1\">";
		   kodlist.sort();
		   for (var i=0; i < theRows.length; i++) 
		   {
		      this.footerend +="<option id=\""+kodlist[i]+"\" name=\""+kodlist[i]+"\">"+kodlist[i]+"</option>";
		   }
		   this.footerend += "</select>&nbsp;<a href=\"javascript:thetable.scrollTo();\" onmouseover=\"javascript:document.images[\'ara\'].src=arImList[12].src;\" onmouseout=\"javascript:document.images[\'ara\'].src=arImList[5].src;\"><img src=../images/ara2.gif id=ara name=ara width=62 height=20 border=0 align=absbottom></TD>";
		 }	
  }
  
//  this.cekince+="\n<tr><td><BR><table border=0 cellspacing=0 cellpadding=0 align=center width=\"100%\">";
//  if (window.lastmod)
//  {
//    this.cekince+="\n<tr>\n<td align=center>"+lastmod+"</td>\n</tr>\n";
//  }	
//  if (isLimited)
//  {
//    this.cekince+="\n<tr>\n<th height=5></th></tr>";
//  }

//  this.cekince+="</table></td></tr></table>";  

  var s="newwin=window.open('"+theHlp+"','Yardım','toolbar=no,status=no,scrollbars=yes,resizable=yes,width=628,height=400,screenX=155,screenY=180,top=180,left=155'); newwin.focus();";
	

  this.tabStart="<table id='maintable' cellpadding=0 cellspacing=0 width="+this.tableWidth+">";
  this.tabStart += "<tr id='tr_caption_help'>\n<td id='td_caption_help'>\n<table id='tbl_caption_help'> \n <tr><th id='th_caption' >&nbsp;&nbsp;"+theCaption+"</th>";
  if (theHlp!=null && theHlp!="") this.tabStart += "<th id='th_help'><a href=\"javascript:void(0)\" onclick=\""+s+"\" onmouseover=\"javascript:document.images[\'helpw2k\'].src=arImList[11].src;\" onmouseout=\"javascript:document.images[\'helpw2k\'].src=arImList[4].src;\"><img id=helpw2k name=helpw2k border=0 align=middle></a></th>";
  this.tabStart += "</tr></table></td></tr>"
  
};
function refreshHeader() {		
	var str = "<tr><td id='td_header_rows' for='maintable'>" ;
	str+="<table id='tbl_header_rows' class='tbl_header_rows'>\n<tr>\n";
	
	if (this.iFirst==0 & this.iLast==0)
    {
        return str;
    }
	
	if (this.shownum)
	str="<th class='th_numrow' width=20 align=center  onmouseover=\"this.className='th_numrowover'\"  onmouseout=\"this.className='th_numrow'\">&nbsp;</th>";  
	for(k=0; k<theCols.length; k++) {
	  if(this.visCols[k])
	  {
		str += "<th valign=top class='th_colhead'  onmouseover=\"this.className='th_colheadover';\"  onmouseout=\"this.className='th_colhead' \" " ;
		if (theCols[k][2]!=0)
		   str += "width=" + theCols[k][2] ; 
		str += " align=center><a class='a_caption' href=\"javaScript:thetable.mySort(" + k + ")\">" + theCols[k][0]+ ((kSort[0]==k)?((kSort[1]==1)?"<br><img  class='img_sort' src=\"../images/up.gif\" border=0>":"<br><img class='img_sort' src=\"../images/down.gif\" border=0>"):"<br><img class='img_sort' src=\"../images/spacer.gif\" height='5px' border=0>") + "</a></th>";
	  } 	
	}
	return str;
};

function refreshTabRows() {
	var currentRows = "";
	var posit=0;
	var deger=0;
	posit=Math.floor(((this.iFirst+this.iLast)/2)/(theRows.length/(this.iLast-this.iFirst)));
	deger=this.iFirst+posit;
	for (var k=this.iFirst; k < this.iLast; k++) {
		theRec = theRows[this.theColumn[k][1]];
		currentRows += "\n<tr class='tr_datarow'";
		if (this.highlight) 
		{
    		currentRows += " onmouseover=\"this.className='tr_datarow_over'\" onmouseout=\"this.className='tr_datarow'\"";
		}
		currentRows += ">";
		if (this.shownum) 
		currentRows += "<td align=right class=exc>"+(k+1)+" </td>";
		for(l=0; l<theCols.length; l++) {
		  if(this.visCols[l])
		  {		 	
			var currentValue = (theRec[l] == "") ? "&nbsp;" : theRec[l];
			var theCell = "<td  width=" + theCols[l][2] + " class=bord nowrap='noWrap'";
			switch (theCols[l][1]) 
			{
			  case 0:
			    theCell += (" align=center>"+((theRec[l])?"<img src='check.gif'>":"&nbsp;"));
				break;
			  case 1:
			    theCell += " align=right >"+currentValue ;
			    break;	
			  case 2:
			    theCell += (" align=right >"+currentValue);
			    break;
			  case 3:	
				theCell += (" align=center>"+theCols[l][3].split("<option>")[currentValue]);
				break;
			  case 4 :		
	    		theCell += (" align=left >"+currentValue);
				break;
			  case 5  :
			       x=innerText(currentValue);	 
				   re = /,/gi;
				   x=x.replace(re,"");
				   re = /"\""/gi;
				   x=x.replace(re,"");
				   if (x=="-") 
				   {
			 	   	  theCell +=" align=right >"+currentValue +"&nbsp;<font face=symbol size=1 color=#00A000><b>=</b></font>";
				   }
			       else
				   {
				      currentValue=eval(x);
					  if (currentValue==0) 
					  	 {theCell +=" align=right >"+currentValue +"&nbsp;<font face=symbol size=1 color=#00A000><b>=</b></font>";}
					  else
					  { 
					  	if (currentValue>0) {
						   {theCell +=" align=right style=\"color: #009C00;\">"+currentValue +"&nbsp;<font face=symbol size=1 color=#009C00><b>İ</b></font>";}
					  	}
						else
						{										   							 			  									   							 			  					  
						 	{theCell +=" align=right style=\"color: #9C0000;\">"+currentValue +"&nbsp;<font face=symbol size=1 color=#9C0000><b>ß</b></font>";}
						}
					  }
				   }
			     break;	
			  default:
			    theCell += (">"+currentValue);	
			}
			currentRows += (theCell + "</td>");
		  }	
		}
		currentRows += "</tr>";
	}
	if (theFooter.length>0 & !isLimited)
	{
	   currentRows += "<tr>";
	   
	  for(l=0; l<theCols.length; l++) 
	  {
	   if(this.visCols[l])
	   {
	    if (theFooter[l])
		{
		  if (theFooter[l]!="") 
		  {
		   currentValue=theFooter[l];	
		  }
	   	  else
		  { 
		    currentValue="&nbsp;";
		  }
		}
		else
		{
		  currentValue="&nbsp;";
		}  
	    var theCell = "<th class=footer nowrap='noWrap' width=" + theCols[l][2];
		if (this.shownum & l==0) theCell+=" colspan=2";
		switch (theCols[l][1]) 
		{
		  case 0:
		    theCell += (" align=center>"+((theRec[l])?"<img src='check.gif'>":"&nbsp;"));
			break;
		  case 1:
		    theCell += (" align=right >"+currentValue);
		    break;	
		  case 2:
		    theCell += (" align=right >"+currentValue);
		    break;
		  case 3:	
			theCell += (" align=center>"+theCols[l][3].split("<option>")[currentValue]);
			break;
		  case 4 :		
		    theCell += (" align=left >"+currentValue);
			break;
		  case 5:
		    theCell += (" align=right >"+currentValue);
		    break;		  		
		  default:
		    theCell += (">"+currentValue);	
		}
		currentRows += (theCell + "</th>");
	   }	
	  }
	  //currentRows += "<td bgcolor='#D6D3CE' BACKGROUND=\"/images/scroll.gif\"></td>";
      
	} 
	currentRows +="</table for='tbl_header_rows'>";
	currentRows +="</td for='maintable'></tr for='maintable'>";
	//currentRows += "</tr>\n</table>";  
	return currentRows + ("\n");
};
function refreshTabCount() {	
	var N = this.theColumn.length;
	var st='<TD class=toplam align=center>\n';
	st+=(N > 0) ? ("["+(this.iFirst+1) + " - " + this.iLast + "] Toplam : " + N) : "Kritere Uygun Kayıt Bulunamadı";
	st+='</TD>\n';
	return st;
};

function refreshTable() {
    var N = this.theColumn.length;
	var st='<td id="td_toplam" align=center>\n';
	st+=(N > 0) ? ("["+(this.iFirst+1) + " - " + this.iLast + "] Toplam : " + N) : "Kritere Uygun Kayıt Bulunamadı";
	st+='</td>\n';
	
	
	var pagerStr=st;
	if (this.iFirst==0 & this.iLast==theRows.length)
	{
	   pagerStr+="";
	}
	else
	{
        pagerStr+="<td id='td_pager'><table id='tbl_pager'> \n<tr> \n";
        
        if (this.iFirst==0) 
        {
          pagerStr+="<td width=40 align=center><img src=../images/fpage3.gif border=0 height=17 width=20></td><td  width=40 align=center><img src=../images/ppage3.gif border=0 height=17 width=20></td>";
        }
        else
        {
          pagerStr+="<td width=40 align=center> \n<a href=\"javascript:thetable.scrollTable(-2);\"  id='firstbtn'  name='firstbtn' onmouseover=\"javascript:document.images[\'frw\'].src=arImList[7].src;\" onmouseout=\"javascript:document.images[\'frw\'].src=arImList[0].src;\"><img name=\"frw\" border=0 height=17 width=20></A></TD>\n<TD align=center width=40><a href=\"javascript:thetable.scrollTable(-1);\" onmouseover=\"javascript:document.images[\'rew\'].src=arImList[8].src;\" onmouseout=\"javascript:document.images[\'rew\'].src=arImList[1].src;\"><img name=\"rew\"  border=0 height=17 width=20></td>\n";
        }; 		
        if (this.iLast==this.theColumn.length) 
        {
          pagerStr+="<td width=40 align=center><img src=../images/npage3.gif border=0 height=17 width=20></td><td width=40 align=center><img src=../images/lpage3.gif border=0 height=17 width=20></td>";
        }
        else
        {
          pagerStr+="<td width=40 align=center><a href=\"javascript:thetable.scrollTable(1);\" name='nextbtn' onmouseover=\"javascript:document.images[\'for\'].src=arImList[9].src;\" onmouseout=\"javascript:document.images[\'for\'].src=arImList[2].src;\"><IMG name=\"for\" border=0 height=17 width=20></A></TD>\n<TD align=center width=40 style='vertical-align:middle'><A href=\"javascript:thetable.scrollTable(2);\"  onmouseover=\"javascript:document.images[\'ffor\'].src=arImList[10].src;\" onmouseout=\"javascript:document.images[\'ffor\'].src=arImList[3].src;\"><img name=\"ffor\"  border=0 height=17 width=20></A></TD>\n";
        };		
        pagerStr+="</TR>\n</table>";
        pagerStr+="</td>\n";
	}
	pagerStr+="</tr></table for='tbl_footer'></td for='maintable'></tr for='maintable'></table for='maintable'>"
	
	var myframe=document.getElementById(this.targetname);
	if (myframe) 
	{
	   	if (isMinNS4)
		{
		  var oldheight=parent.document.height;
		  myframe.document.open("text/html","replace");
		  myframe.document.write(this.tabStart +this.refreshHeader() + this.refreshTabRows() +this.footerend+ pagerStr); //this.refreshTabCount()
		  myframe.document.close();
		}
		else
		{
		  	myframe.innerHTML=this.tabStart +this.refreshHeader() + this.refreshTabRows()+this.footerend+pagerStr;
		}	
		if (isMinNS6) 
		{
		   if (document.images["for"])
			document.images["for"].src=arImList[2].src;
			if (document.images["ffor"])
			document.images["ffor"].src=arImList[3].src;
			if (document.images["rew"]) 
			{document.images["rew"].src=arImList[1].src;}
			if (document.images["frw"])
			document.images["frw"].src=arImList[0].src;
			if (document.images["helpw2k"])
			document.images["helpw2k"].src=arImList[4].src;
		}
		else
		{
			if (myframe.document.images["for"])
			myframe.document.images["for"].src=arImList[2].src;
			if (myframe.document.images["ffor"])
			myframe.document.images["ffor"].src=arImList[3].src;
			if (myframe.document.images["rew"]) 
			{myframe.document.images["rew"].src=arImList[1].src;}
			if (myframe.document.images["frw"])
			myframe.document.images["frw"].src=arImList[0].src;
			if (myframe.document.images["helpw2k"])
			myframe.document.images["helpw2k"].src=arImList[4].src;
		}
		if (isMinNS6)
		{
		  if (document.getElementById("rowcount")!=null)
		  	 document.getElementById("rowcount").value=this.rowsToDisplay;
		}
		else
		if (myframe.document.forms[0].elements["rowcount"]!=null) 
		{
		  var myinput=myframe.document.forms[0].elements["rowcount"];
          	  myinput.value=this.rowsToDisplay  ;
		  
		} 
	}
};
function innerText(str) {
	str=String(str);	 	
	while (str.indexOf("<") != -1) {
		a = str.indexOf("<");
		b = str.indexOf(">");
		str = str.substring(0,a) + str.substring(b+1,str.length);
	}
	return(str);
};
function compare(a, b) {	
	  						  
     if (a[0]=="-" & b[0]=="-") return 0;
	 if (a[0]=="-") return 1;
	 if (b[0]=="-") return -1;
     if	(a[0] < b[0]) return -kSort[1];
     if (a[0] > b[0]) return kSort[1];
     return 0;
};
function scrollTable(x) {	
	
//	if (isMinNS4) 
//	{
//	   var myframe=document.layers["table"];
//	   
//	}	
//	else
//	{
//	    if (isMinNS6) var myframe=document.getElementById("table");
//		else	var myframe=document.all.table;
//	}
//	if (isMinNS6)
//	{
//	  if (document.getElementById("rowcount")!=null)
//	  	  var myinput=document.getElementById("rowcount").value;
//	}
//	else
//	{
//		if (myframe.document.forms[0].elements["rowcount"])  
//		  var myinput=parseInt(myframe.document.forms[0].elements["rowcount"].value,10)
//		else
//		  var myinput=theRows.length;
//	}   
//	if (myinput) 
//	{
//	    if (!isNaN(myinput)) {
//			if (myinput=="" | myinput>this.theColumn.length) 
//		    {
//		       this.rowsToDisplay=Math.min(myinput,this.theColumn.length);
//	        }
//  			else {this.rowsToDisplay=(myinput==0)?Math.min(defrownum,this.theColumn.length):(myinput);}
//		}
//		else  {this.rowsToDisplay=Math.min(defrownum,this.theColumn.length);}
//	}
//	else {this.rowsToDisplay=defrownum;}
	switch (x)
	{
	 	   
	    case -3:
		   if (this.iFirst!=0) 
		   {
		   	  this.iFirst +=-1;
		   }	 
		   break;
		case -2:
		   this.iFirst = 0;
		   break;
		case 2:
		   this.iFirst = Math.min(Math.max(0,this.theColumn.length-1),this.theColumn.length-(this.theColumn.length%this.rowsToDisplay==0)?this.theColumn.length-this.rowsToDisplay:this.theColumn.length%this.rowsToDisplay);
		   break;
		case 1:
		   this.iFirst = Math.min(Math.max(0,this.iFirst += x * this.rowsToDisplay), this.theColumn.length-this.theColumn.length%this.rowsToDisplay);
		   break;
		case -1:
		   this.iFirst = Math.min(Math.max(0,this.iFirst += x * this.rowsToDisplay), this.theColumn.length-this.theColumn.length%this.rowsToDisplay);
		   break;
		case 3:
		   this.iFirst+=1;
		   break;      
	}   
	this.iLast = Math.min(parseInt(this.iFirst)+parseInt(this.rowsToDisplay),this.theColumn.length);
	this.refreshTable();
};

function scrollTo() {
    found=false;
	if (isMinNS4) 
	{
	   var myframe=document.layers["table"];
	}	
	else
	{
	    if (isMinNS6) var myframe=document.getElementById("table");
		else
	 	var myframe=document.all.table;	  
	}	
	if (isMinNS6)
	{
	  var myinput=document.getElementById("rowcount")
	}
	else
	var myinput=myframe.document.forms[0].elements["rowcount"];
	if (myinput) 
	{
	    if (!isNaN(parseInt(myinput.value,10))) {
			if (myinput.value=="" | myinput.value>this.theColumn.length) 
		    {
		       this.rowsToDisplay=Math.min(myinput.value,this.theColumn.length);
	        }
  			else {this.rowsToDisplay=(parseInt(myinput.value,10)==0)?Math.min(defrownum,this.theColumn.length):parseInt(myinput.value,10);}
		}
		else  {this.rowsToDisplay=Math.min(defrownum,this.theColumn.length);}
	}
	else {this.rowsToDisplay=defrownum;}
	if (isMinNS6)
	{
	   	var kod=document.getElementById("hisse").options[document.getElementById("hisse").selectedIndex].text;		 
	}
	else
	{
		if (isMinNS4) 
		{
		   var kod=myframe.document.forms[0].elements["hisse"].options[myframe.document.forms[0].elements["hisse"].selectedIndex].text;
		}
		else
		{
		   var kod=myframe.document.forms[0].elements["hisse"].options[myframe.document.forms[0].elements["hisse"].selectedIndex].name;  
		};
	};
	kod=kod.replace(" ","");
	for (i=0;i<theRows.length;i++)
	{
	  var mykod=theRows[i][this.searchcolumn];
	  if(mykod.indexOf(kod)!=-1)
	  { 
	    fno=i;
		found=true;
		break;
	  }
	}
	
	if (found)
	{
	  for (i=0;i<this.theColumn.length;i++)
	  {
	    if (this.theColumn[i][1]==fno)
		{
		  this.iFirst = i;
		  this.iLast = Math.min(this.iFirst+this.rowsToDisplay,this.theColumn.length);
          this.refreshTable();
		  break;
		}
	  }
	}
};

function dateToNum(dateString) {
	var dateArray = dateString.split("/");
	return dateArray[2]*10000 + dateArray[1]*100 + eval(dateArray[0]);
}

function mySort(k) {		
	var dataType = theCols[k][1];						 
	if (kSort[0] == k) {	
		kSort[1] = -kSort[1];
	}
	else {
		kSort[0] = k;	
 		if (dataType==1) 
		kSort[1] = -1;	
		else {kSort[1] = 1;	}
	}
	

	
	this.sortdatatype=dataType; 
	for (var j=0; j < this.theColumn.length; j++) 
	{ 
		var x = theRows[this.theColumn[j][1]][k];
		switch ( dataType) {
	    case 0 :
	       this.theColumn[j][0] = (x) ? 1 : 0;
	       break;
	    case 1:
		   x=innerText(x);	 
		   re = /,/gi;
		   x=x.replace(re,"");
		   re = /"\""/gi;
		   x=x.replace(re,"");
		   if (x=="-") 
		   {
	 	   	  this.theColumn[j][0] = x;
		   }
	       else
		   {
		      this.theColumn[j][0] = eval(x);
		   }
	       break;
		case 5:
		   x=innerText(x);	 
		   re = /,/gi;
		   x=x.replace(re,"");
		   re = /"\""/gi;
		   x=x.replace(re,"");
		   if (x=="-") 
		   {
	 	   	  this.theColumn[j][0] = x;
		   }
	       else
		   {
		      this.theColumn[j][0] = eval(x);
		   }
	       break;   
		case 3  :
	       this.theColumn[j][0] = eval(x);
	       break;
		case 2 :
	       if (x != "") this.theColumn[j][0] = dateToNum(x);
				else {this.theColumn[j][0] = 0;}
	       break;   
	    default :
	       this.theColumn[j][0] = innerText(x).toUpperCase();
	    }    
	}	
	this.theColumn = this.theColumn.sort(compare); 
	this.scrollTable(-2);
}



