

var isIE;
var completeTable;
var completeField;
var autorow;
var req;

var productListed=false;
//
function initRequest(url) {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        isIE = true;
        return new ActiveXObject("Microsoft.XMLHTTP");
        ;
    }
}

//gets the element id by cross browser compatibility
function cpGetElementById(s) {
    var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
    return o == null ? false : o;
}

///shows the product list
function doList(id) {
    if (!productListed){
          clearTables();
    var url = "listProduct.jsp?id=" + id;
    var req = initRequest(url);
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                parseMessages(id, req.responseText);
              if (isIE){
                        document.getElementById("image"+id).src="/images/raiselayer.gif";
                       // document.getElementById("image"+id).style.visibility="visible";
                        }
                  else
                         cpGetElementById("image"+id).src="/images/raiselayer.gif"

            } else if (req.status == 204) {
                clearTables();
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
        productListed=true;
        }

   else
        {
            var changed=false;
            for (i=1; i<=4; i++)
                {
                    if (cpGetElementById(id).innerHTML !=""){
                        changed=true;
                        break;
                        }
                }
          if (changed){
               for (i=1; i<=4; i++)
                {
                  cpGetElementById(id).innerHTML ="";
                     if (isIE)
                           document.images("image"+i).src="/images/lowerlayer.gif";
                  else
                         cpGetElementById("image"+i).src="/images/lowerlayer.gif"
                }
            }
         productListed=false;
        }
}


//this function gets a crossplatform document object
function parseMessages(id, responseXML) {
    cpGetElementById(id).innerHTML = responseXML;
}

//this function clears the sub product list
function clearTables()
{
    for (i = 1; i < 5; i++)
    {
        cpGetElementById(i).innerHTML = "";
         if (isIE)
            {
            document.images("image"+i).src="/images/lowerlayer.gif";
                }
       else
           cpGetElementById("image"+i).src="/images/lowerlayer.gif"
    }
}

/////Th section shows the EFT Screen
////////////////////////////////////////////////////////////
function showEFT() {
    var url = "js/HavaleOdeme.jsp";
    var req = initRequest(url);
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                cpGetElementById("havaleDiv").innerHTML= req.responseText;
            } else if (req.status == 204) {
             clearError();
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
}
function showCC() {   
    var url = "js/KrediOdeme.jsp";
    var req = initRequest(url);
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                cpGetElementById("havaleDiv").innerHTML= req.responseText;
            } else if (req.status == 204) {
             clearError();
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
} 

//-----------------------------------------------------------------------------------
//This function selects the categories in uyelik3.jsp when when the defned sector is selected
//-------------------------------------------------------------------------------
 function retrieveSecondOptions(){
  var firstBox = document.getElementById('sectorSelect'); 
    selectedOption = firstBox.options[firstBox.selectedIndex].value; 
    //get the (form based) params to push up as part of the get request
    url="/AjaxUtilities.do?opcode=1&sector="+selectedOption;
     var req = initRequest(url);    
   req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
	          //change the options();
	          //but before all clear the options
				clearOptions("categorySelect");		
	          textToSplit = req.responseText;	      
	          returnElements=textToSplit.split("||");
	          for ( var i=0; i<returnElements .length; i++ )
	          			{
	          			if (returnElements[i]!=""){
	             			valueLabelPair = returnElements[i].split(";")
	             			document.getElementById('categorySelect').options[i] = new Option(valueLabelPair[1], valueLabelPair[0]);	             			
	             			}
          				}	           
            } else if (req.status == 204) {
            clearOptions();
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);
  }
  
  //-----------------------------------------------------------------------------------
//This function selects the Taxcenters in uyelik3.jsp when when the defned city is selected
//---------------------------------------------------------------------------------------
 function retrieveTaxCenters(x){   
   var firstBox = document.getElementById('taxcity');
    
    //Nothing selected
    if(firstBox.selectedIndex==0){
      return;
    }
    selectedOption = firstBox.options[firstBox.selectedIndex].value;
    //get the (form based) params to push up as part of the get request
    url="AjaxUtilities.do?opcode=2&city="+selectedOption;
     var req = initRequest(url);    
   req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
	          //change the options();
	          //but before all clear the options
	          clearOptions("taxcenterid");	
	          textToSplit = req.responseText;
	          returnElements=textToSplit.split("||");
	          for ( var i=0; i<returnElements .length; i++ )
	          			{
	          			if (returnElements[i]!=""){
	             			valueLabelPair = returnElements[i].split(";")
	             			document.getElementById('taxcenterid').options[i] = new Option(valueLabelPair[1], valueLabelPair[0]);	             			
	             			}
          				}                     
            } else if (req.status == 204) {
            clearOptions();
            }
        }
    };    
    req.open("GET", url, true);
    req.send(null);
  }
 //------------------------------------------------//helper method to clearr the options
function  clearOptions(id)
{
var optionName=cpGetElementById(id);
for (i=optionName.options.length-1;i>=0; i-- )
	{
	optionName.options[i]=null;
	}
}//--------------------------------------------------- 
//-----------------------------------------etc etc
function printDoc()
{
win = window.open("/js/sozlesme.jsp?print=true");
}
//----------------------------------------------print the son sozlesme
function printAnlasma()
{
win = window.open("/js/SonSozlesme.jsp");
}
function showCategories(){    
     var firstBox = document.getElementById('sectorid'); 
    id = firstBox.options[firstBox.selectedIndex].value; 
    var url = "/AjaxUtilities.do?opcode=1&sector=" + id;
    var req = initRequest(url);
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.status == 200) {
		                //do the stuff here
		      textToSplit = req.responseText;
		  sreturnElements=textToSplit.split("||")
          
          //Process each of the elements 	
          for ( var i=0; i<returnelements .length; i++ ){
             valueLabelPair = returnElements[i].split(";")
             document.getElementById('categoryid').options[i] = new Option(valueLabelPair[0], valueLabelPair[1]);
          }                       	
            } else if (req.status == 204) {
                clearTables();
            }
        }
    };
    req.open("GET", url, true);
    req.send(null);      
 }