// Just a stub function we'll tell ajaxObject to call when it's done
// callback functions get responseText, and responseStat respectively
// in their arguments.
function fin(responseTxt,responseStat) {
  //alert(responseStat+' - '+responseTxt);
}

// create a new ajaxObject, give it a url it will be calling and
// tell it to call the function "fin" when its got data back from the server.
//var test1 = new ajaxObject('http://someurl.com/server.cgi',fin);
//    test1.update();
               
// create a new ajaxObject, give it a url and tell it to call fin when it
// gets data back from the server.  When we initiate the ajax call we'll
// be passing 'id=user4379' to the server.           
//var test2 = new ajaxObject('http://someurl.com/program.php',fin);
//    test2.update('id=user4379');
               
// create a new ajaxObject but we'll overwrite the callback function inside
// the object to more tightly bind the object with the response hanlder.


// create a new ajaxObject and pass the data to the server (in update) as
// a POST method instead of a GET method.
//var test4 = new ajaxObject('http://someurl.com/postit.cgi', fin);
//   test4.update('coolData=47&userId=user49&log=true','POST'); 


function ajaxObject(url, callbackFunction) {
	var that=this;     
  	this.updating = false;
  	this.abort = function() {
    	if (that.updating) {
      		that.updating=false;
      		that.AJAX.abort();
      		that.AJAX=null;
    	}
	}
	this.update = function(passData,postMethod) {
    	if (that.updating) { 
			return false;
		}
    	that.AJAX = null;                         
    	if (window.XMLHttpRequest) {             
      		that.AJAX=new XMLHttpRequest();             
    	} else {                                 
      		that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    	}                                             
    	if (that.AJAX==null) {                             
      		return false;                               
    	} else {
      		that.AJAX.onreadystatechange = function() { 
        		if (that.AJAX.readyState==4) {             
          			that.updating=false;               
          			that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);       
          			that.AJAX=null;                                         
        		}                                                     
      		}                                                       
      		that.updating = new Date();                             
      		if (/post/i.test(postMethod)) {
        		var uri=urlCall+'?'+that.updating.getTime();
        		that.AJAX.open("POST", uri, true);
        		that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        		that.AJAX.send(passData);
      		} else {
        		var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());
        		that.AJAX.open("GET", uri, true);                             
        		that.AJAX.send(null);                                         
      		}             
      		return true;                                             
    	}                                                                           
  	}
  	var urlCall = url;       
  	this.callback = callbackFunction || function () { };
}

function showProductList(baseurl,cid,maxcatid,maxproductId,maxsysid,yes){

link= baseurl+'product.php?cid='+cid+'&page='+yes;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			
			document.getElementById('product').innerHTML = result;  
			document.getElementById('product').style.display = "block";
			
			if(document.getElementById('productPage')!=null){
			 document.getElementById('productPage').style.display = "none";
			}
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('part')!=null){
		    document.getElementById('part').style.display = "none";
		    }
			
			 Shadowbox.deact();
             Shadowbox.init();
			
		
	}

}
function showProductDetails(baseurl,cid,categoryId,pcId,yes){
if(pcId=="" || categoryId==""){
	link= baseurl+'product_details.php?cid='+cid+'&page='+yes;;
}else{
link= baseurl+'product_details.php?cid='+cid+'&catId='+categoryId+'&pcId='+pcId+'&page='+yes;;
}
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			
			document.getElementById('product').innerHTML = result;  
			document.getElementById('product').style.display = "block";
			
			if(document.getElementById('productPage')!=null){
			 document.getElementById('productPage').style.display = "none";
			}
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('part')!=null){
		    document.getElementById('part').style.display = "none";
		    }
			
		
			 Shadowbox.deact();
             Shadowbox.init();
            
		
	}

}
function showIndustryProductDetails(baseurl,cid,categoryId,yes){

link= baseurl+'industry_product_details.php?cid='+cid+'&catId='+categoryId+'&page='+yes;
	var linkComp = link.split("?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
		    document.getElementById('product').innerHTML = result;  
			document.getElementById('product').style.display = "block";
			
			if(document.getElementById('productPage')!=null){
			 document.getElementById('productPage').style.display = "none";
			}
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('part')!=null){
		    document.getElementById('part').style.display = "none";
		    }
		
			 Shadowbox.deact();
             Shadowbox.init();
            
		
	}

}

function showShoppingCart(baseurl,maxcatid){

link= baseurl+'cart.php';
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			//hide other product
			var i;
			for(i=0;i<=maxcatid;i++){
				if(document.getElementById('ProductCat'+i)!=null){
				document.getElementById('ProductCat'+i).style.display = "none";
				}
			}
			
			document.getElementById('shoppingCart').innerHTML = result;  
			document.getElementById('shoppingCart').style.display = "block";
			
			//hide system details
			document.getElementById('mySystem').style.display = "none";
			
			 //hide breadcrumbs
			 if(document.getElementById('rightNav')!=null){
		    document.getElementById('rightNav').style.display = "none";
		    }
			//hide product details
			if(document.getElementById('viewproduct')!=null){
		      document.getElementById('viewproduct').style.display = "none";
			 }
			
			 Shadowbox.deact();
             Shadowbox.init();
			
		
	}

}

function showSystemProductDetails(baseurl,cid,categoryId,pcId,yes){

link= baseurl+'system_product_details.php?cid='+cid+'&catId='+categoryId+'&pcId='+pcId+'&page='+yes;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			
			document.getElementById('viewproduct').innerHTML = result;  
			document.getElementById('viewproduct').style.display = "block";
			document.getElementById('viewproduct'+cid).style.display = "block";
			
			if(document.getElementById('ProductCat'+categoryId)!=null){
		    document.getElementById('ProductCat'+categoryId).style.display = "none";
			}
			if(document.getElementById('ProductSystem'+categoryId)!=null){
			 document.getElementById('ProductSystem'+categoryId).style.display = "none";
			}
			if(document.getElementById('viewproductNav')!=null){
			 //document.getElementById('viewproductNav').style.display = "none";
			}
			//hide cart
			 document.getElementById('shoppingCart').style.display = "none";
			 //hide system details
			 document.getElementById('mySystem').style.display = "none";
		
			 Shadowbox.deact();
             Shadowbox.init();
            
		
	}

}
function showMySystem(baseurl,maxcatid,maxsysid){

link= baseurl+'system.php?action=systempage';
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			//hide other product
			var i;
			for(i=0;i<=maxcatid;i++){
				if(document.getElementById('ProductCat'+i)!=null){
				document.getElementById('ProductCat'+i).style.display = "none";
				}
			}
			var k;
			for(k=0;k<=maxsysid;k++){
				if(document.getElementById('ProductSystem'+k)!=null){
				document.getElementById('ProductSystem'+k).style.display = "none";
				}
			}
			document.getElementById('mySystem').innerHTML = result; 
			document.getElementById('mySystem').style.display = "block";
			
			
			document.getElementById('shoppingCart').style.display = "none";
			
			if(document.getElementById('viewproduct')!=null){
		      document.getElementById('viewproduct').style.display = "none";
			 }
			
			 //hide breadcrumbs
		    document.getElementById('rightNav').style.display = "none";
		   
			 Shadowbox.deact();
             Shadowbox.init();
			
		
	}

}

function showSystemProductList(baseurl,cid,maxcatid,maxproductId,id,parentId){

link= baseurl+'system_product_list.php?cid='+cid+'&id='+id+'&parentId='+parentId;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			//hide other product
			var i;
			for(i=0;i<=maxcatid;i++){
				if(document.getElementById('ProductCat'+i)!=null){
				document.getElementById('ProductCat'+i).style.display = "none";
				}
			}
			
			//hide product Details
			var j;
			for(j=0;j<=maxproductId;j++){
				if(document.getElementById('viewproduct'+j)!=null){
				document.getElementById('viewproduct'+j).style.display = "none";
				}
			}
			
			document.getElementById('product'+cid).innerHTML = result;  
			document.getElementById('product'+cid).style.display = "block";
		
			document.getElementById('ProductCat'+cid).style.display = "block";
			//hide cart
			//document.getElementById('shoppingCart').style.display = "none";
			//hide system details
			//document.getElementById('mySystem').style.display = "none";
	     
		
			// Shadowbox.deact();
           // Shadowbox.init();
			
		
	}

}	
function ShowSystemCategory(baseurl,cid,id,parentId){

	link= baseurl+'system_process.php?cid='+cid+'&id='+id+'&parentId='+parentId;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('result'+cid).innerHTML = result;  
		    document.getElementById('result'+cid).style.display = "block";
            document.getElementById('showCat'+cid).style.display = "none";
            document.getElementById('HideCat'+cid).style.display = "block";
            
                 // for internet explorer
        if( document.getElementById('result'+cid).innerHTML==""){
            document.getElementById('result'+cid).style.display = "none";
        } 
         
			// Shadowbox.deact();
          //   Shadowbox.init();
            
		}

	}
function GetStateList(baseurl,countryId){

   link= baseurl+'process.php?cid='+countryId;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('mySystem').innerHTML = result;  
		    document.getElementById('mySystem').style.display = "block";
		    document.getElementById('entry_state').style.display = "none";
            
         
			// Shadowbox.deact();
            // Shadowbox.init();
            
		}

}
function ShowSystem(baseurl,cid){
	link= baseurl+'sys_process.php?cid='+cid;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('systemResult'+cid).innerHTML = result;  
			 document.getElementById('systemResult'+cid).style.display = "block";
            document.getElementById('showSystem'+cid).style.display = "none";
            document.getElementById('HideSystem'+cid).style.display = "block";
            
                 // for internet explorer
        if( document.getElementById('systemResult'+cid).innerHTML==""){
            document.getElementById('systemResult'+cid).style.display = "none";
        } 
         
			 Shadowbox.deact();
             Shadowbox.init();
            
		}

	}	
function HideSystem(baseurl,cid){
	link= baseurl+'sys_process.php?cid='+cid;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('systemResult'+cid).innerHTML = result;  
			document.getElementById('systemResult'+cid).style.display = "none";
            document.getElementById('showSystem'+cid).style.display = "block";
            document.getElementById('HideSystem'+cid).style.display = "none";
            
			 Shadowbox.deact();
             Shadowbox.init();
		}

}

function showSysProductList(baseurl,cid,maxsysid,maxproductId,maxcatid){

link= baseurl+'system_product.php?cid='+cid;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			
			document.getElementById('productPage').innerHTML = result; 
			 document.getElementById('productPage').style.display = "block"; 
			document.getElementById('product').style.display = "none";
			
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('part')!=null){
		    document.getElementById('part').style.display = "none";
		    }
			
			 Shadowbox.deact();
             Shadowbox.init();
			
		
	}

}

function ShowPartCategory(baseurl,cid,id){
	link= baseurl+'part_process.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultPart'+cid).innerHTML = result;  
			 document.getElementById('resultPart'+cid).style.display = "block";
            document.getElementById('showCatPart'+cid).style.display = "none";
            document.getElementById('HideCatPart'+cid).style.display = "block";
            
              // for internet explorer
        if( document.getElementById('resultPart'+cid).innerHTML==""){
            document.getElementById('resultPart'+cid).style.display = "none";
        } 
         
			 Shadowbox.deact();
             Shadowbox.init();
            
		}

	}	
	
function HidePartCategory(baseurl,cid,id){
	link= baseurl+'part_process.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultPart'+cid).innerHTML = result;  
			document.getElementById('resultPart'+cid).style.display = "none";
            document.getElementById('showCatPart'+cid).style.display = "block";
            document.getElementById('HideCatPart'+cid).style.display = "none";
            
			 Shadowbox.deact();
             Shadowbox.init();
		}

	}

function showPartProductList(baseurl,cid,yes,maxPartCatId,maxPartId){

link= baseurl+'part_product.php?cid='+cid+'&page='+yes;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('part').innerHTML = result;  
			document.getElementById('part').style.display = "block";
			
			if(document.getElementById('productPage')!=null){
			 document.getElementById('productPage').style.display = "none";
			}
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('product')!=null){
		    document.getElementById('product').style.display = "none";
		    }
			 
			 Shadowbox.deact();
             Shadowbox.init();
		
		
	}

}
function showPartDetails(baseurl,cid,categoryId,yes){

link= baseurl+'part_details.php?cid='+cid+'&catId='+categoryId+'&page='+yes;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('part').innerHTML = result;  
			document.getElementById('part').style.display = "block";
			
			if(document.getElementById('productPage')!=null){
			 document.getElementById('productPage').style.display = "none";
			}
			
		    if(document.getElementById('partPage')!=null){
		    document.getElementById('partPage').style.display = "none";
		    }
		     if(document.getElementById('product')!=null){
		    document.getElementById('product').style.display = "none";
		    }
			 Shadowbox.deact();
             Shadowbox.init();
            
		
	}

}
var  currentBanner1=0; 

function PreviousImage(imageCount,productId){
  if(imageCount!=1){
   currentBanner1--;
    if(currentBanner1 < 0 ){
     currentBanner1=imageCount-1;
   }
   
  
  	for(var i=0; i<imageCount;i++){
  
  	document.getElementById('banner'+i+"-"+productId).style.display= "none";
  	}
  	
  	if(document.getElementById('banner'+currentBanner1+"-"+productId)!=""){
          document.getElementById('banner'+currentBanner1+"-"+productId).style.display= "block";
    }
  }else{
   currentBanner1=1;
  } 

}
function NextImage(imageCount,productId){
 if(imageCount!=1){
  	currentBanner1++;
  	
  	if(currentBanner1 >= imageCount){
     currentBanner1=0;
   }
  	for(var i=0; i<imageCount;i++){
  	document.getElementById('banner'+i+"-"+productId).style.display= "none";
   }
	
  	if(document.getElementById('banner'+currentBanner1+"-"+productId)!=""){
      document.getElementById('banner'+currentBanner1+"-"+productId).style.display= "block";
    }
    }else{
    currentBanner1=1;
    }
  } 
 function CountProductViews(productId,task){

   link='product_view.php?productId='+productId+'&task='+task;
 
	var linkComp = link.split( "?");
		var result;
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
           result = responseTxt
        
			// we'll do something to process the data here.
			//result = responseTxt
			//alert(result);
			
		

		}
}
 function ShowLeftmenu(search_industry_id,search_min_id,search_max_id,search_viscosity_id){
	
	   link='leftprocess.php?id='+search_industry_id+"minId="+ search_min_id+"&maxId="+search_max_id+"viscosity="+search_viscosity_id;
		var linkComp = link.split( "?");
				
			var result;
			
					
			var obj = new ajaxObject(linkComp[0], fin);

			obj.update(linkComp[1],"GET");

			obj.callback = function (responseTxt, responseStat) {
	           
				result = responseTxt
				
				document.getElementById('waterMark').innerHTML = result;  
				document.getElementById('waterMark').style.display = "block";
				
			
			

			}
	} 	
			
function ChangeProductOrder(dropid,productid,systemid,memberid){

   link='change_order.php?dropid='+dropid+'&productid='+productid+'&systemid='+systemid+'&memberid='+memberid;
     
   var linkComp = link.split( "?");
		
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
       
			result = responseTxt
			//alert(result);
			location.reload(true) ;

		}
}	
