/**
 * Function for display List of products
 * based on subcategory with pagewise
 * if pageid is not given than default is 1
 */

function populate_product(subcatid,pageid) {
	var divResult;
	divResult = 'div_products';
	
	if(pageid==undefined){
		pageid = 1;
	}

	Aj = new Ajax.Request('populate_product.php',   
	{     
	method:'post',     
	parameters: "subcatid=" + subcatid + "&pageid=" + pageid ,
	onLoading: function(){
		//$(divResult).innerHTML = "Please wait..." ; 				
	},
	onSuccess: function(transport)
                    {       
                    //msg.innerHTML = transport.responseText || _txt_noreply;
                    arrResult = transport.responseText.split('~');
                    $(divResult).innerHTML = arrResult[0] ;
                    
                    //Generate Page combo
                    page_combo(arrResult[1],subcatid,pageid);

                    },     
   onFailure: function()
                    { 
                     $(divMessage).innerHTML = "Error on execution" ;
                    }
    });    
   
   return true;	
}

///////
//Function for populate index product
function populate_index_product() {
	var divResult;
	divResult = 'div_products';
	
	Aj = new Ajax.Request('populate_index_product.php',   
	{     
	method:'post',     
	parameters: "id=1" ,
	onLoading: function(){
		//$(divResult).innerHTML = "Please wait..." ; 				
	},
	onSuccess: function(transport)
                    {       
                    //msg.innerHTML = transport.responseText || _txt_noreply;
                    //alert(transport.responseText);
                    $(divResult).innerHTML = transport.responseText ;

                    },     
   onFailure: function()
                    { 
                     $(divResult).innerHTML = "Error on execution" ;
                    }
    });    
   
   return true;	
}

function populate_featured_recipe() {
	var divResult;
	divResult = 'div_recipe';
	
	Aj = new Ajax.Request('populate_featured_recipe.php',   
	{     
	method:'post',     
	parameters: "id=1" ,
	onLoading: function(){
		//$(divResult).innerHTML = "Please wait..." ; 				
	},
	onSuccess: function(transport)
                    {       
                    //msg.innerHTML = transport.responseText || _txt_noreply;
                    //alert('test');
                    $(divResult).innerHTML = transport.responseText ;

                    },     
   onFailure: function()
                    { 
                     $(divResult).innerHTML = "Error on execution" ;
                    }
    });    
   
   return true;	
}


///////


/**
 * Function for display page combo
 */
function page_combo(totalpages,subcatid,defaultpage) {
	//alert('Total Pages' + defaultpage);
	
	if (totalpages > 1){	
		var strcombo, pageno, previmg ;
		strcombo ='';
		pageno=1;
		previmg = '<img src="images/turleft.gif" alt="" height="15" width="15" border="0">';
		nextimg = '<img src="images/turright.gif" alt="" height="15" width="15" border="0">';
		spacer  = '<img src="images/spacer.gif" alt="" height="15" width="15" border="0">';
		
		//For Previous Page
		if(defaultpage >=2) {
			pageno = defaultpage - 1
			//strcombo += pageno + ' &lt; ' ;
			strcombo += '&nbsp;<a href="#" onclick="populate_product(' + subcatid + ',' + pageno +');" />' + previmg + '</a>&nbsp;';
		}	
		
		strcombo += '<select name="selectpage" size="1" onchange="populate_product(' + subcatid + ',this.value);" >' ;	
		for(i=1 ; i <= totalpages; i++ ) {
			if(defaultpage ==i){
				isDefault = ' selected="selected" ' ;
			}
			else {
				isDefault ='' ;
			}			
			strcombo += '<option ' + isDefault + ' value="' + i + '">' + i + '</option>\n';
		}
		strcombo += '</select>' ; 
		
		//For Next Page
		if(totalpages >=2 && defaultpage < totalpages  ) {
			pageno = eval(defaultpage) +1 ;
			//strcombo += ' &gt; ' + pageno ;
			strcombo += '&nbsp;<a href="#" onclick="populate_product(' + subcatid + ',' + pageno +');" />' + nextimg + '</a>';
		}
		else {
			strcombo += spacer + '&nbsp;' ;
		}
		
		document.getElementById('page_combo').innerHTML = strcombo ;
	}
}
