

var obj;
var sadecesiklik;
function GetDataVade(siklikmi)
{  
	sadecesiklik=siklikmi;
    try
    {obj = new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e)
    {try{obj = new ActiveXObject("Microsoft.XMLHTTP");}
     catch(e1)
      {obj = null;}
    }
    if(obj!=null)
    {
			// alert(sadecesiklik);
		   obj.onreadystatechange = ProcessResponse;
		    
			if (sadecesiklik==0)
			{
				obj.open("GET", "Vade.aspx?krediKodu=" + document.getElementById('cmbKrediTuru1').value +"&siklik=1&vade=1&oSart=0",  true);
			}
			else if(sadecesiklik==1)
			{ 
				obj.open("GET", "Vade.aspx?krediKodu=" + document.getElementById('cmbKrediTuru1').value +"&siklik="+document.getElementById('cmbSiklik1').value +"&vade=x&oSart="+document.getElementById('cmbOzelSart1').value,  true);
			}
			else
			{ 
				obj.open("GET", "Vade.aspx?krediKodu=" + document.getElementById('cmbKrediTuru1').value +"&siklik="+document.getElementById('cmbSiklik1').value +"&vade="+document.getElementById('cmbVade1').value +"&oSart="+document.getElementById('cmbOzelSart1').value,  true);
			}
           obj.send(null);         
    }
    return false;
}

function ProcessResponse()
{ 
   if(obj.readyState == 4)
   {
		if(obj.status == 200)
		{ 
			if (sadecesiklik==2)//özel oran
			{
				textDoldur('numFaizOrani1','Faiz')
			}
			else if (sadecesiklik==1)
			{
				textDoldur('numFaizOrani1','Faiz')
				comboDoldur('cmbVade1','Vade');
			}
			else
			{
			combosikliksec();
			comboDoldur('cmbVade1','Vade');
			comboDoldur('cmbOzelSart1','OzelSartlar');
			textDoldur('numFaizOrani1','Faiz')
				
	        }
			
		}
		else
		{
			alert("Data erişiminde hata!" );
		}         
   }
}
function combosikliksec()
{
	var  combosiklik	 = document.getElementById('cmbSiklik1');
	//alert(combosiklik.selectedIndex);
	combosiklik.selectedIndex=0;
	
}
function textDoldur(textBoxAdi,dtAdi)
{
	var textBox	 = document.getElementById(textBoxAdi);	
	      
	var dsRoot=obj.responseXML.documentElement;  
    var dt = dsRoot.getElementsByTagName(dtAdi);
  	var val
	var tex
     
		val = dt[0].getElementsByTagName("vadeValue")
	 
	 textBox.value =val[0].firstChild.data
}
function comboDoldur(comboAdi,dtAdi)
{  
	var combo	 = document.getElementById(comboAdi);	
	// comboların içini sıfırlıyoruz.
	for (var count = combo.options.length-1; count >-1; count--)
	{combo.options[count] = null;}
	//***********************************//

	var dsRoot=obj.responseXML.documentElement;  
    var dt = dsRoot.getElementsByTagName(dtAdi);
    var optn //comboya eklenecek 
	var val
	var tex
      for (var count = 0; count < dt.length; count++)
      {
		optn = document.createElement("OPTION")// diğer notları child olarak ekleyecez
		var er
		// Checking for the tag which holds the value of the Drop-Down combo element
		val = dt[count].getElementsByTagName("vadeValue")
		{
			try
			{
				// Assigning the value to a Drop-Down Set Element
				optn.value = val[0].firstChild.data
			} 
			catch(er)
			{ 
				alert("hata" +er);
			}
		}
		// Checking for the tag which holds the Text of the Drop-Down combo element
		tex = dt[count].getElementsByTagName("vadeText")
		{
			try
			{
				// Assigning the Text to a Drop-Down Set Element
				if (comboAdi=='cmbOzelSart1')
				{
					if(tex[0].firstChild!=null)
					{
					 combo.disabled=false;;
					 optn.text = tex[0].firstChild.data
					 }
					else
					{
					//alert(combo.disabled);
					 combo.disabled=true;
					}
					
				}
				else 
				{
					optn.text = tex[0].firstChild.data
				}
			} 
			catch(er)
			{
				alert("hata");
			}
		}
		combo.options.add(optn)
    }
}



/////////////////////////////////////////////////////////////////////////
//Variable Declarations
/////////////////////////////////////////////////////////////////////////
var xmlhttp;
/////////////////////////////////////////////////////////////////////////
//fillGrid
/////////////////////////////////////////////////////////////////////////
var grid;



function fillGrid(mygrid){	
	
	grid = window.document.getElementById(mygrid);
	var krediTuru	 = document.getElementById('cmbKrediTuru1').value;
	var krediTutari	 = document.getElementById('numKrediTutari1').value;
	var vade		 = document.getElementById('cmbVade1').value;
	var faiz		 = document.getElementById('numFaizOrani1').value;
	var siklik		 = document.getElementById('cmbSiklik1').value;
	
	if (krediTutari==""){alert("Lutfen Kredi Tutari Giriniz.");return;}
	var url = "hesapGrid.aspx/getList?kt="+krediTuru+"&ktu="+krediTutari+"&v="+vade+"&f="+faiz+"&s="+siklik;
		
	if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=fillGrid_Change;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    //code for IE
    else if (window.ActiveXObject)
        {
        try
            {
            xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch(e)
            {
            try
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){}
        }
                         
        if(xmlhttp)
        {
            try
            {
            xmlhttp.onreadystatechange=fillGrid_Change;
            xmlhttp.open("GET",url,false);
            xmlhttp.send();
            ;
            }
            catch(e){alert(1);}  
        }
    } 
    
   
}
function fillGrid_Change()
{

	if(xmlhttp.readyState==4&&xmlhttp.status==200)
	{	
		//var rows=xmlhttp.responseXML.selectNodes(".//TahaSchema//TahaTable");	
		
          
		//alert(xmlhttp.responseText);
		/*
		var row = 	xmlhttp.responseXML.selectNodes(".//");	
		
		 if(row != null)
       {
			alert(row[1].text);
          var totalItems = row.length;
          for(var ctr=0; ctr <= totalItems-1; ctr++)
          {
             var item = row[ctr].text;
             alert(item);
          }
       }

		//alert(row[1].text);
		ph.innerHTML = row[1].text;*/
		//alert(xmlhttp.responseText);
		grid.innerHTML =xmlhttp.responseText;
		var rows=xmlhttp.responseXML.selectNodes(".//tr//td");	
		 if(rows != null)
       {
           if(rows.length>8)
           {
			document.getElementById('numTaksitTutari').value = rows[8].text;
		   }
		   else
		   {
		   alert("Odeme Plani Olusturulamadi.");
		   }
	   }
		document.getElementById('numFaizOrani').value=document.getElementById('numFaizOrani1').value
	}
}

//////////////////////////////////////////////
//help 

	var ka_tooltip = false;
	var ka_tooltipShadow = false;
	var ka_shadowSize = 4;
	var ka_tooltipMaxWidth = 200;
	var ka_tooltipMinWidth = 100;
	var ka_iframe = false;
	var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;
	function showTooltip(e,tooltipTxt)
	{
     //alert(tooltip_is_msie);
		
		var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
		
		if(!ka_tooltip){
			ka_tooltip = document.createElement('DIV');
			ka_tooltip.id = 'ka_tooltip';
			//ka_tooltip.style.position = 'absolute';
			ka_tooltipShadow = document.createElement('DIV');
			ka_tooltipShadow.id = 'ka_tooltipShadow';
			//ka_tooltipShadow.style.position = 'absolute';
			document.body.appendChild(ka_tooltip);
			document.body.appendChild(ka_tooltipShadow);	
			//alert();
			if(tooltip_is_msie){
				ka_iframe = document.createElement('IFRAME');
				ka_iframe.frameborder='15';
				ka_iframe.style.backgroundColor='#D60808';
				ka_iframe.src = '#'; 	
				ka_iframe.style.zIndex = 100;
				ka_iframe.style.position = 'absolute';
				document.body.appendChild(ka_iframe);
			}
			
		}
		
		ka_tooltip.style.display='block';
		ka_tooltipShadow.style.display='block';
		if(tooltip_is_msie)ka_iframe.style.display='block';
		
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX + 10;
		
		ka_tooltip.style.width = null;	// Reset style width if it's set 
		ka_tooltip.innerHTML = tooltipTxt;
		//ka_tooltipShadow.innerHTML = tooltipTxt;
		
		ka_tooltip.style.left = leftPos + 'px';
		ka_tooltip.style.top =  e.clientY + 10 + st + 'px';

		
		ka_tooltipShadow.style.left =  leftPos + ka_shadowSize + 'px';
		ka_tooltipShadow.style.top = e.clientY + 10 + st + ka_shadowSize + 'px';
		
		//alert(ka_tooltipShadow.style.top);
		if(ka_tooltip.offsetWidth>ka_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
			ka_tooltip.style.width = ka_tooltipMaxWidth + 'px';
		}
		
		var tooltipWidth = ka_tooltip.offsetWidth;		
		if(tooltipWidth<ka_tooltipMinWidth)tooltipWidth = ka_tooltipMinWidth;
		
		
		ka_tooltip.style.width = tooltipWidth + 'px';
		ka_tooltipShadow.style.width = ka_tooltip.offsetWidth + 'px';
		ka_tooltipShadow.style.height = ka_tooltip.offsetHeight + 'px';		
		
		if((leftPos + tooltipWidth)>bodyWidth){
			ka_tooltip.style.left = (ka_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
			ka_tooltipShadow.style.left = (ka_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + ka_shadowSize) + 'px';
		}
		
		//if(tooltip_is_msie){
			ka_iframe.style.left = ka_tooltip.style.left;
			ka_iframe.style.top = ka_tooltip.style.top;
			ka_iframe.style.width = ka_tooltip.offsetWidth + 'px';
			ka_iframe.style.height = ka_tooltip.offsetHeight + 'px';
		
		//}
			//alert(ka_iframe.innerHTML );
				
				
					
	}
	
	function hideTooltip()
	{
		ka_tooltip.style.display='none';
		ka_tooltipShadow.style.display='none';	
		if(tooltip_is_msie)ka_iframe.style.display='none';	
			
	}
	
	/////////////////////////////
	
	function degistir (x,y){
		if (x.style.display=='none'){
		x.style.display=''
		y.src="images/SingleMinus.gif"
		}
		else
		{
		x.style.display='none'
		y.src="images/SinglePlus.gif"
		}
	}
	
	function CheckIsNumeric()
	{   
		var AsciiCode = event.keyCode;
		//alert(AsciiCode);
		if (AsciiCode==44){}
		else{
			if ((AsciiCode < 48) || (AsciiCode > 57))
			{
			alert('Lutfen yanlizca rakam giriniz...');
			event.cancelBubble = true; 
			event.returnValue = false; 
			}
		}
	}
