﻿// mmcs.js
makecount=70;
modelcount=70;
yearcount=70;
categorycount=70;
subcategorycount=70;
catalogRow=0;  
resultcount=200;
catcount=0;
make="";
model="";
category="";
year="";
subcategory="";
maxResults=false; 
itemCount=0;
exitSearch=false;
document.onload=fnStart();
yearChanged=false;


function fnStart() {
    //add row references 
    //grows=igtbl_getGridById('MakeGrid').Rows;
    ourInterval = setInterval('fnReady()', 500);
}

function fnReady() {
    if (typeof MakeGrid == 'undefined' || typeof ModelGrid == 'undefined') {
        return;  
     }
    else {
        clearInterval(ourInterval);
        fnLoad();
     }
}


function fnLoad() {
   fnDisplayMakes();
   document.getElementById('divSelect').onclick=function(){fnSelect();};
   document.getElementById('divCart').onclick=function(){fnShowCart();};
   document.getElementById('imgCart').onclick=function(){fnShowCart();};
   
 }

function fnSelect() {

  if (make<'.' || model<'.' || category<'.'|| subcategory<'.' || year<'(') {
        alert("Please select Make, Model, Year, Category and SubCategory first ...");
        return;
   } 
   frameMMCS=parent.frames[0]; 
   frameResults=parent.frames[1];  
  
   fnDisplayBrands();
  
   if (yearChanged==true) {
        yearChanged=false;
        fnDisplayBrands();
        
   } 
}

function fnShowCart() {
    if (parent.frames[1].itemCount==0) {
        alert("No items have been added to the Parts List. First make a selection and then click Show Parts ...")
        return; 
   }
   
   parent.document.getElementById('fraMMCS').style.visibility='hidden';
   parent.document.getElementById('fraResults').style.visibility='hidden';
   parent.document.getElementById('fraCart').style.visibility='visible';
 }

//Makes
function fnDisplayMakes(){
    make=""; 
	var SrchSQL = "Select  Distinct Make from MakeModel where Make>'0' and Code='R' order by Make";
	var SrchSQL = strReplaceAll(SrchSQL,"&","^");
	var SrchSQL = strReplaceAll(SrchSQL,"<","`");
	var db = "i";
	DBLocation="c"
     if (window.XMLHttpRequest){
        var oXMLHTTP = new XMLHttpRequest();
    } else {
         var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
    } 
    var varServer =window.location.hostname;
    var sURL = "./iCatServer.aspx";
    var param=  "sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;

    try {
        oXMLHTTP.open( "GET", sURL+'?'+param, false );
        oXMLHTTP.send(null);
       
    }
    catch (e) {
        alert("Web Service Unavailable..."+e.message);
        return;
    }
    //document.getElementById('divWaiting').style.visibility='hidden';
    dxResult=oXMLHTTP.responseText;
    //document.body.style.cursor='auto';
    makeO=fnCreateDXObject(dxResult);
    if (makeO.rowcount>0) {

        for (rr=0; rr<makeO.rowcount; rr++){
              rw=rr;
			  MakeGrid.getItem(rw).getCell(0).setValue( makeO.row[rr].Make);
	     } 
	} else {
	    alert("Error loading Makes ..." + dxResult);  
	}
   
}

function fnMakeSelected(cell) {
    row=MakeGrid.getSelectedCell().getItemIndex();
    col=MakeGrid.getSelectedCell().getColIndex(); 
    if (typeof MakeGrid.getSelectedCell().getValue()  =='undefined' || MakeGrid.getSelectedCell().getValue() <'.') { 
        MakeGrid.getItem(0).ensureVisible();
        MakeGrid.selectItem(-1); 
        return;
     }   
    make=MakeGrid.getSelectedCell().getValue() ;
    clearYears();
    clearCategories();
    clearSubCategories(); 
    fnDisplayModels(make); 
    
}
//Models
function fnDisplayModels(make){
    model="";
    if (make<'A') {
        return;
    }
    var SrchSQL = "Select Distinct Model from MakeModel where Make='" + make + "' and  (Code='R') order by Model";
  
	var db = "i";
   
    var CountSQL="";
    var SrchSQL = strReplaceAll(SrchSQL,"&","^");
	var SrchSQL = strReplaceAll(SrchSQL,"<","`");
	DBLocation="c";
	
    if (window.XMLHttpRequest){
        var oXMLHTTP = new XMLHttpRequest();
    } else {
         var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
    } 

    var varServer =window.location.hostname;
   
     var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;
    
    // Execute the request
    try {
        oXMLHTTP.open( "GET", sURL, false );
        oXMLHTTP.send(null);
    }
    catch (e) {
        alert("Web Service Unavailable..."+e.message);
        return;
    }
    //document.getElementById('divWaiting').style.visibility='hidden';
    dxResult=oXMLHTTP.responseText;
    oldmodelcount=modelcount;
    modelO=fnCreateDXObject(dxResult);
    if (modelO.rowcount>0) {
        for (rr=0; rr<modelO.rowcount; rr++){
               rw=rr;
			   ModelGrid.getItem(rw).getCell(0).setValue( modelO.row[rr].Model);
	    } 
	    //clear old models
	    for (rr=rw+1; rr<modelcount+1; rr++){
	        ModelGrid.getItem(rr).getCell(0).setValue(" ")
	    }
	    modelcount=rw;
	   
	    
    } else {
        clearModels(); 
        alert("No Models for this Make..."+make);  
    }
    //Clear Selections
    ModelGrid.getItem(0).ensureVisible();
    ModelGrid.selectItem(-1);
    document.body.style.cursor='default' ;
}  


function fnModelSelected(cell) {
    row=ModelGrid.getSelectedCell().getItemIndex();
    col=ModelGrid.getSelectedCell().getColIndex(); 
    if (typeof ModelGrid.getSelectedCell().getValue()  =='undefined' || ModelGrid.getSelectedCell().getValue() <'.') { 
        ModelGrid.getItem(0).ensureVisible();
        ModelGrid.selectItem(-1); 
        return;
     }  
    model=ModelGrid.getSelectedCell().getValue() ;
    clearCategories();
    clearSubCategories();  
    fnDisplayYears(model); 
    
}

function clearModels() {
    //clear 
     for (rr=0; rr<modelcount; rr++){
         ModelGrid.getItem(rr).getCell(0).setValue(" ");
    }
    selectedModel=' ';
    ModelGrid.getItem(0).ensureVisible();
    ModelGrid.selectItem(-1); 
}

function fnDisplayYears(){
    YearGrid.getItem(0).getCell(0).setValue('(ALL)');
    for (rr=1; rr<yearcount; rr++){
          rw=rr;
	      YearGrid.getItem(rw).getCell(0).setValue(2009-rw+1);
    	 
     } 
    //Clear Selections
    YearGrid.getItem(0).ensureVisible();
    YearGrid.selectCell(0,0);
    year="(ALL)" //YearGrid.getSelectedCell().getValue() ;
    fnDisplayCategories(year);  
    document.body.style.cursor='default' 
}

function fnYearSelected(cell) {
    row=YearGrid.getSelectedCell().getItemIndex();
    col=YearGrid.getSelectedCell().getColIndex(); 
    if (typeof YearGrid.getSelectedCell().getValue()  =='undefined' || YearGrid.getSelectedCell().getValue() <'(') { 
        YearGrid.getItem(0).ensureVisible();
        YearGrid.selectItem(-1); 
        return;
     } 
     year=YearGrid.getSelectedCell().getValue() ;
     //fnDisplayCategories(year); 
    
}

function clearYears() {
    //clear 
     for (rr=0; rr<yearcount+1; rr++){
         YearGrid.getItem(rr).getCell(0).setValue(" ");
    }
    selectedYear=0;
    YearGrid.getItem(0).ensureVisible();
    YearGrid.selectItem(-1); 
}

function fnDisplayCategories(){
    category="";
    if (make<'.' || model <'.') {
        return;
   }  
    //var SrchSQL = "Select Distinct Category from Category where Category>'0'  order by Category";
    var SrchSQL = "Select Distinct Category from VCat where Category>'0' and Make ='" + make + "' and Model='" + model + "' order by Category";
    var db = "v";
    var dblcn= "c";
    var CountSQL="";
    DBLocation="c";
    if (window.XMLHttpRequest){
        var oXMLHTTP = new XMLHttpRequest();
    } else {
         var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
    } 
    var varServer =window.location.hostname;
    var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;
  
   // Execute the request
    try {
        oXMLHTTP.open( "GET", sURL, false );
        oXMLHTTP.send(null);
    }
    catch (e) {
        alert("Web Service Unavailable..."+e.message);
        return;
    }
    
    dxResult=oXMLHTTP.responseText;
    oldcategorycount=categorycount;
    categoryO=fnCreateDXObject(dxResult);
    if (categoryO.rowcount>0) {
        for (rr=0; rr<categoryO.rowcount; rr++){
               rw=rr;
			  
			  ctg=categoryO.row[rr].Category;
			  ctg=strReplaceAll(ctg," ","_") ;
			  CategoryGrid.getItem(rw).getCell(0).setValue(categoryO.row[rr].Category);
	      	 
	    } 
	      //clear old subcategories
	    for (rr=rw+1; rr<categorycount+1; rr++){
	       CategoryGrid.getItem(rw).getCell(0).setValue(" ");
	    }
	    categorycount=rw;
	} else {
	    //alert("No Categories ...");  
	}
	categorycount=rw;
	CategoryGrid.getItem(0).ensureVisible();
    CategoryGrid.selectItem(-1);
}   

function fnCategorySelected(cell) {
    
    row=CategoryGrid.getSelectedCell().getItemIndex();
    col=CategoryGrid.getSelectedCell().getColIndex(); 
    if (typeof CategoryGrid.getSelectedCell().getValue()  =='undefined' || CategoryGrid.getSelectedCell().getValue() <'.') { 
        CategoryGrid.getItem(0).ensureVisible();
        CategoryGrid.selectItem(-1); 
        return;
    }
    category=CategoryGrid.getSelectedCell().getValue() ;
    fnDisplaySubCategories(category); 
    
}


function clearCategories() {
        if (typeof categoryO =='undefined') {
            return;
        }
         //clear 
         for (rr=0; rr<categorycount+1; rr++){
	        CategoryGrid.getItem(rr).getCell(0).setValue(' ');
	    }
	    categorycount=0;
	    oldcategorycount=0;
	    category='';
	    CategoryGrid.getItem(0).ensureVisible();
        CategoryGrid.selectItem(-1);
}

//SubCategory
function fnDisplaySubCategories(category){
    if (category<'.') {
        return;
   } 
    subcategory="";
    category = strReplaceAll(category,"&","^");
    //var SrchSQL = "Select Distinct SubCategory from Category where Category='" + category + "'  order by SubCategory";
    var SrchSQL = "Select Distinct SubCategory from VCat where Category='" + category + "' and Make ='" + make + "' and Model = '" + model + "' order by SubCategory";
    var db = "v";
    var dblcn= "c"
    var CountSQL="";
    DBLocation="c";
    SrchSQL=strReplaceAll(SrchSQL,"&","^");
    if (window.XMLHttpRequest){
        var oXMLHTTP = new XMLHttpRequest();
    } else {
         var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
    } 
    var varServer =window.location.hostname;
    var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;
   
   // Execute the request
    try {
        oXMLHTTP.open( "GET", sURL, false );
        oXMLHTTP.send(null);
    }
    catch (e) {
        alert("Web Service Unavailable..."+e.message);
        return;
    }
    //document.getElementById('divWaiting').style.visibility='hidden';
    dxResult=oXMLHTTP.responseText;
    //document.body.style.cursor='auto';
   oldsubcategorycount=subcategorycount;
   subcategoryO=fnCreateDXObject(dxResult);
    if (subcategoryO.rowcount>0) {
        for (rr=0; rr<subcategoryO.rowcount; rr++){
              rw=rr;
			  SubCategoryGrid.getItem(rw).getCell(0).setValue(subcategoryO.row[rr].SubCategory);
	   } 
	    //clear old subcategories
	    for (rr=rw+1; rr<subcategorycount+1; rr++){
	      SubCategoryGrid.getItem(rr).getCell(0).setValue(" ");
	    }
	    subcategorycount=rw;
	} else {
	    alert("No SubCategories are yet available for this Category...");  
	}
	 //Clear Selections
	 SubCategoryGrid.getItem(0).ensureVisible();
     SubCategoryGrid.selectItem(-1);
    document.body.style.cursor='default' ;
}  

function fnSubCategorySelected(cell) {
    row=SubCategoryGrid.getSelectedCell().getItemIndex();
    col=SubCategoryGrid.getSelectedCell().getColIndex(); 
    if (typeof SubCategoryGrid.getSelectedCell().getValue()  =='undefined' || SubCategoryGrid.getSelectedCell().getValue() <'.') { 
        SubCategoryGrid.getItem(0).ensureVisible();
        SubCategoryGrid.selectItem(-1); 
        return;
     } 
     subcategory=SubCategoryGrid.getSelectedCell().getValue() ;
    
}
   
function clearSubCategories() {
     //clear 
     for (rr=0; rr<subcategorycount+1; rr++){
          SubCategoryGrid.getItem(rr).getCell(0).setValue(' ');
    }
    subcategorycount=0;
    oldsubcategorycount=0;
    subcategory="";
    SubCategoryGrid.getItem(0).ensureVisible();
    SubCategoryGrid.selectItem(-1); 
} 


 //Brands
function fnDisplayBrands(){
   yearChanged=false;
   parent.frames[1].document.getElementById('divCount').innerHTML= "";
   catalog="";
   exitSearch=false;
   maxResults=false; 
   parent.frames[1].document.getElementById('selBrand').options.length=0;
   parent.frames[1].document.getElementById('selBrand').options[0] = new Option("(ALL)");
   if (make<'.' || model<'.' || category<'.'|| subcategory<'.' || year<'(') {
        alert("Please select Make, Model, Year, Category and SubCategory first ...");
        return;
   }
   parent.frames[1].make=make;
   parent.frames[1].model=model;
   parent.frames[1].category=category;
   parent.frames[1].subcategory=subcategory;
   
    strsubcategory = strReplaceAll(subcategory,"&","^");
    var SrchSQL = "Select distinct Status,[Catalog] from VCat where [Catalog]>'0'  and Category='" + category + "' and SubCategory='" + strsubcategory + "' and Make = '" + make + "' and Model = '" + model +"'";
    if (fnVal(year)>0) {
         var SrchSQL = SrchSQL + " and " + year + " >= FromYear" ;
         var SrchSQL = SrchSQL + " and " + year + " <= ToYear" ;
    } 
    var SrchSQL = SrchSQL + " order by Status,[Catalog]";
    var SrchSQL = strReplaceAll(SrchSQL,"&","^");
	var SrchSQL = strReplaceAll(SrchSQL,"<","`");
    var db = "v";
    var dblcn= "";
    var CountSQL="";
    DBLocation="c";
    if (window.XMLHttpRequest){
        var oXMLHTTP = new XMLHttpRequest();
    } else {
         var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
    } 
    var varServer =window.location.hostname;
    var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;

    // Execute the request
    try {
        oXMLHTTP.open( "GET", sURL, false );
        oXMLHTTP.send(null);
    }
    catch (e) {
        alert("Web Service Unavailable..."+e.message);
        return;
    }

    dxResult=oXMLHTTP.responseText;


    catalogO=fnCreateDXObject(dxResult);

    oldcatalogRow=catalogRow;
    catalogRow=0;  
    if (catalogO.rowcount>0) {
        for (catrow=0; catrow<catalogO.rowcount; catrow++){
               catalog= catalogO.row[catrow].Catalog; 
               newbrand=true ;
              if (maxResults==false) {
                    resultCount=fnDisplayCatDescription(); 
                    if (exitSearch==true) {
                        return;
                    }
                    
              }   
              // brand combo
              //parent.frames[1].document.getElementById('selBrand').options[catrow+1] = new Option(catalog.split("_")[0]);
              if (resultCount>0 || maxResults==true) {
                parent.frames[1].document.getElementById('selBrand').options[catrow+1] = new Option(catalog);
              }  
		 } 
		     
     }
      
    document.body.style.cursor='default' ;
      
    if (catalogRow>0) {
           parent.frames[1].document.getElementById('divMake').innerHTML=make;
           parent.frames[1].document.getElementById('divModel').innerHTML=model;
           //parent.frames[1].document.getElementById('divYear').innerHTML=year;
           parent.frames[1].document.getElementById('selYear').selectedIndex=parent.frames[0].YearGrid.getSelectedCell().getItemIndex();
          //clear old catalogRow
            for (grdRow=catalogRow; grdRow<oldcatalogRow+1; grdRow++){
                for (grdCol=0; grdCol<9; grdCol++){
                    parent.frames[1].ResultsGrid.getItem(grdRow).getCell(grdCol).setValue(' ');
               }
           }
            //Clear Selections
            parent.frames[1].ResultsGrid.getItem(0).ensureVisible();
            parent.frames[1].ResultsGrid.selectItem(-1); 
            //Change frame
             parent.document.getElementById('fraMMCS').style.visibility='hidden';
             parent.document.getElementById('fraCart').style.visibility='hidden';
             parent.document.getElementById('fraResults').style.visibility='visible';
             parent.frames[1].document.getElementById('divCount').innerHTML= "Displaying " +  catalogRow + " items."
             if ( parent.frames[1].document.getElementById('selPartType').length>0) {
                   parent.frames[1].document.getElementById('selPartType').focus(); 
            }  
              
             //Part Type ComboBox 
    		 fnDisplayPartType(); 
    } else { 
         if (fnVal(year)==0) {
           alert('No Matching results...');
         } else {
            alert('No Matching results for the year ' + year + '. Now displaying ALL years to expand the results ... ');
            parent.frames[0]. YearGrid.selectCell(0,0);
            parent.frames[0]. YearGrid.getItem(0).ensureVisible();
            parent.frames[1].document.getElementById('selYear').selectedIndex=0;
            year="(ALL)"
            yearChanged=true; 
        }    
    }
   
   
}   


function fnDisplayCatDescription(){
	    SrchSQL = "Select top " + resultcount + " * from BrandPart where (Make = '" + make + "' and Model='" + model + "'";
	    SrchSQL=SrchSQL + " and CatalogName='" + catalog + "'"
	    SrchSQL=SrchSQL + " and Display=true"
         if (fnVal(year)>0) {
             var SrchSQL = SrchSQL + " and " + year + " >= FromYear" ;
             var SrchSQL = SrchSQL + " and " + year + " <= ToYear" ;
        } 
       
        var SrchSQL=SrchSQL + " and Price>0 ) order by UID";
        
        //var db =  strReplaceAll(catalog,"&","^") ;
        var db = "v";
        var dblcn= "c";
        DBLocation="c";
	    var CountSQL="";
	   
	    var SrchSQL = strReplaceAll(SrchSQL,"&","^");
		var SrchSQL = strReplaceAll(SrchSQL,"<","`");
		
        if (window.XMLHttpRequest){
            var oXMLHTTP = new XMLHttpRequest();
        } else {
             var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
        } 
        var varServer =window.location.hostname;
       
         var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;
        
       // Execute the request
        try {
            oXMLHTTP.open( "GET", sURL, false );
	        oXMLHTTP.send(null);
        }
        catch (e) {
	        alert("Web Service Unavailable..."+e.message);
	        return;
	    }
        
        dxResult=oXMLHTTP.responseText;
        catO=fnCreateDXObject(dxResult);
        oldcatcount=catcount;
        rw=0;
       
        if (catO.rowcount>0) {
            // scan columns
	        rw=0;    
            for (rr=0; rr<catO.rowcount; rr++){
                
				
				 brand=catalog.split("_")[0] ;
				
				// Display

                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(0).setValue(catO.row[rr].Series);
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(1).setValue(catO.row[rr].Years);
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(2).setValue(catO.row[rr].Engine);
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(3).setValue(brand);  
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(4).setValue(catO.row[rr].Item);
                if (catO.row[rr].Description.length<50) {   
                    parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(5).setValue(catO.row[rr].Description + ' ' + catO.row[rr].PartDesc);  
                } else {
                    parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(5).setValue(catO.row[rr].PartDesc);  
                } 
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(6).setValue(catO.row[rr].Part);
                parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(7).setValue('$' + fnVal(catO.row[rr].Price).toFixed(2));
                
                //Mod:040210
                //alert(catO.row[rr].XRefPrice)
                if ( catO.row[rr].XRefDisplayPart >'0' ) {
                   parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(6).setValue(catO.row[rr].XRefDisplayPart); 
                }
                if ( fnVal(catO.row[rr].XRefPrice) >0  ) {
                   parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(7).setValue('$' + fnVal(catO.row[rr].XRefPrice).toFixed(2));
                }
                
                if (catO.row[rr].Description.length<50) { 
                     parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(8).setValue(catO.row[rr].Notes); 
                } else {
                     parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(8).setValue(catO.row[rr].Description + catO.row[rr].Notes); 
                } 
                
               //Mod:040210
               parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(9).setValue(catO.row[rr].SupplierCode); 
               
               if (catO.row[rr].StoreOnly=="True") {
                    parent.frames[1].ResultsGrid.getItem(catalogRow).getCell(9).setValue("StoreOnly");
               }

                catalogRow=catalogRow+1; 
                 
                if (catalogRow > resultcount-1) {
				       alert("Displaying first " + resultcount + " items. You may select a specific Year or Catalogue or Item Type to refine results...)");
				       maxResults=true;
				       return catalogRow;    
				 } 
    		                    
	         } 
	        	 
	    } 
	    return catalogRow;
}  

function fnDisplayPartType(){
	    SrchSQL = "Select distinct Item from BrandPart where (Make = '" + make + "' and Model='" + model + "'";
	   if (parent.frames[1].document.getElementById('selBrand').selectedIndex>0) {
	        SrchSQL=SrchSQL + " and CatalogName='" + catalog + "'"
	    } else {
	       SrchSQL=SrchSQL +" and (";
	        for (rr=1; rr<parent.frames[1].document.getElementById('selBrand').length; rr++){
	            catalog=parent.frames[1].document.getElementById('selBrand').options[rr].innerHTML; 
	           if (rr>1) {
	                SrchSQL=SrchSQL + " or ";
	           } 
	            SrchSQL=SrchSQL + "CatalogName='" + catalog + "'";
	        } 
	        SrchSQL=SrchSQL +")";
	        
	    }
	    SrchSQL=SrchSQL + " and Item>'  .' and Price>0 and Display=true"
         if (fnVal(year)>0) {
             var SrchSQL = SrchSQL + " and " + year + " >= FromYear" ;
             var SrchSQL = SrchSQL + " and " + year + " <= ToYear" ;
        } 
       
        var SrchSQL=SrchSQL + ") order by Item";
        
        //var db =  strReplaceAll(catalog,"&","^") ;
        var db = "v";
        var dblcn= "c";
        DBLocation="c";
	    var CountSQL="";
	   
	    var SrchSQL = strReplaceAll(SrchSQL,"&","^");
		var SrchSQL = strReplaceAll(SrchSQL,"<","`");
		
        if (window.XMLHttpRequest){
            var oXMLHTTP = new XMLHttpRequest();
        } else {
             var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
        } 
        var varServer =window.location.hostname;
       
         var sURL = "./iCatServer.aspx?sql=" + SrchSQL + "&lcn=" + DBLocation + "&db=" + db;
        
       // Execute the request
        try {
            oXMLHTTP.open( "GET", sURL, false );
	        oXMLHTTP.send(null);
        }
        catch (e) {
	        alert("Web Service Unavailable..."+e.message);
	        return;
	    }
        
        dxResult=oXMLHTTP.responseText;
        parttypeO=fnCreateDXObject(dxResult);
       
        rw=0;
        parent.frames[1].document.getElementById('selPartType').options.length=0;
        parent.frames[1].document.getElementById('selPartType').options[0] = new Option("(ALL)");
        if (parttypeO.rowcount>0) {
            // scan columns
	        rw=0;    
            for (rr=0; rr<parttypeO.rowcount; rr++){
                rw=rw+1;
				parent.frames[1].document.getElementById('selPartType').options[rw] = new Option(parttypeO.row[rr].Item);  
                                 
	         } 
    			 
	    }
	    parent.frames[1].document.getElementById('selPartType').selectedIndex=0; 
}  


function fnBeginEdit(cell)
{
    //Get the current cell value
    var v = cell.getValue();
  
}


function strReplaceAll(str,strFind,strReplace) {
	var returnStr = str;
	var start = returnStr.indexOf(strFind);
	while (start>=0)
	{
		returnStr = returnStr.substring(0,start) + strReplace + returnStr.substring(start+strFind.length,returnStr.length);
		start = returnStr.indexOf(strFind,start+strReplace.length);
	}
	return returnStr;
} 
	


function fnCreateDXObject(dxResult){
    os = new Array();
    dxr = dxResult.split("~|");
    dxf = dxr[0].split("~_");
    for (currentLne=0; currentLne<dxr.length-1; currentLne++){ 
        var o = new Object();
       
        dxc = dxr[currentLne+1].split("~_");
        //RecordCount
        o["Recordcount"]=dxf[0];
        //Fields
        for (c=1; c< dxc.length ; c++){
                o[dxf[c]]=dxc[c];
        }
        os[currentLne]=o;
    }
    var o = new Object();
    o.rowcount=dxr.length-1;
    o.colcount=dxf.length-1;
    o.row=os;
    return o;
}

function fnVal(value) {
   if ( typeof value == 'undefined') {
        return 0;
   }
   if (value == 'undefined') {
        return 0;
   }
    value=value.toString();
    if (value.substring(0,1)=='$') {
        value=value.substring(1,20);
    } 
    v=parseFloat(value);
     if (isNaN(v)) { v=0}
    return v; 
} 
	
function getText(n){
  if('textContent' in n) {
    return n.textContent;
  } else if('innerText' in n) {
    return n.innerText;
  } else {
    return n.innerHTML;
  }
}

function fnTrim(sString) {
    while (sString.substring(0,1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ') {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}      	