function goToStore(iCat)
{
	var type ="";
	searchkey = document.getElementById('vKeyword').value;
	if(document.getElementById('chk')){
	if(document.getElementById('chk').checked == true){
		type = "titleandDesc";
	}else{
		type = "title";
	}
	}
	if(searchkey!= '')
	{
		window.location = SITE_URL+StName+'/search/'+type+'/'+searchkey;		
	}
	else
	{
		window.location = SITE_URL+StName+'/'+iCat;
	}
}
function StoreProducts(start,iCat)
{
	
	var ext = '';
	var type='';
	if(document.getElementById('chk')){
		if(document.getElementById('chk').checked == true){
			type = "titleandDesc";
		}else{
			type = "title";
		}
	}
	if(document.getElementById('vKeyword')){
		searchkey = document.getElementById('vKeyword').value;
		if(searchkey != '')
			document.getElementById('stokeyword').value ="";
			document.getElementById('stotype').value = "";
			ext+='&keyword='+searchkey+'&type='+type;
	}
	if(iCat !='')
		ext+='&iCateogryId='+iCat;
	var stokeyword = document.getElementById('stokeyword').value;
	var stotype = document.getElementById('stotype').value;
	if(stokeyword != '' && stotype != ''){
		ext+='&keyword='+stokeyword+'&type='+stotype;
	}	
	var url = SITE_AJAX_URL+"storeprod.php?&start="+start+"&rec_limit="+rec_limit+ext+"&iStoreId="+iStoreId;
	//alert(url);
	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=getStorePro;
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=getStorePro;
    		http.send()
    	}
  	}
}
function getStorePro()
{
	if (http.readyState == 4) 
	{	
      	isWorking = false;
    	if (http.responseText.indexOf('invalid') == -1) 
		{
			var html = '';
    		var xmlDocument = http.responseXML; 
			var totrec = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
			var start = xmlDocument.getElementsByTagName('start').item(0).firstChild.data;
			var recmsg = xmlDocument.getElementsByTagName('recmsg').item(0).firstChild.data;
			var no = xmlDocument.getElementsByTagName('iproductid').length;
			var storetype = document.getElementById('storepage').value;
			if(xmlDocument.getElementsByTagName('icat').item(0))
				var icat = xmlDocument.getElementsByTagName('icat').item(0).firstChild.data;
			else
				var icat = '';
			
			html+='<TABLE width="100%" border="0" cellspacing="5" cellpadding="0">';
			
			if(no > 0)
			{
				//document.getElementById('REC_MSG_TOP').innerHTML =recmsg;
				document.getElementById('REC_MSG_BOTTOM').innerHTML =recmsg;
				for(i=0; i<no; i++)
				{
						var iproductId = xmlDocument.getElementsByTagName('iproductid').item(i).firstChild.data;
						var prodname = xmlDocument.getElementsByTagName('prodname').item(i).firstChild.data;
						var prodcode = xmlDocument.getElementsByTagName('prodcode').item(i).firstChild.data;
						var fprice = xmlDocument.getElementsByTagName('fprice').item(i).firstChild.data;
						var fretailprice = xmlDocument.getElementsByTagName('fretailprice').item(i).firstChild.data;
						var vimage = xmlDocument.getElementsByTagName('vimage').item(i).firstChild.data;
						var hrefprod = xmlDocument.getElementsByTagName('hrefprod').item(i).firstChild.data;
						var desc = xmlDocument.getElementsByTagName('desc').item(i).firstChild.data;
						
						var iProdCat = document.getElementById('iProdCat').value;
						if(iProdCat != ''){
							var extcat = '/'+iProdCat;
						}else{
							var extcat = '';
						}
				if(STORE_PAGE !=2){
					var imagetrwidth = "45%";
				if(i%2 == 0)
				html+='<TR>';
				}else{
					var imagetrwidth = "25%";
					html+='<TR>';
				}
					
					html+='	<TD width="50%"  valign="top" >';
					html+=' <DIV class="raised"><B class="b1"></B><B class="b2"></B><B class="b3"></B><B class="b4"></B> <DIV class="boxcontent">';
					html+=' <TABLE width="95%" height="160px"  border="0" align="center" cellpadding="0" cellspacing="0">';
							html+=' <TR>';
							html+=' 	<TD width="'+imagetrwidth+'" class="right-border" align="center" valign="middle"><A href="Producto/'+hrefprod+'/'+iproductId+'/'+iStoreId+''+extcat+'"><IMG src="'+vimage+'" title="'+prodname+'" border="0" /></A>&nbsp;</TD>';
							html+=' 	<TD valign="center" >';
							html+=' 		<TABLE  width="98%" border="0" align="right" cellpadding="1" cellspacing="1">';
							html+=' 		<TR>';
							html+=' 			<TD colspan="3"><a href="Producto/'+hrefprod+'/'+iproductId+'/'+iStoreId+''+extcat+'" class="storethemelink-big">'+prodname+'</a></TD>';
							html+=' 		</TR>';
							if(storetype == '2'){
								if(desc != '-'){
								html+=' 		<TR>';
								html+=' 			<TD colspan="3">'+desc+'&nbsp;</TD>';
								html+=' 		</TR>';
								}
							}
							/*html+=' 		<TR>';
							html+=' 			<TD colspan="3">&nbsp;</TD>';
							html+=' 		</TR>';
							html+=' 		<TR>';
							html+=' 			<TD colspan="3"><a href="Producto/'+hrefprod+'/'+iproductId+'/'+iStoreId+'">'+LBL_READ_MORE+'</a></TD>';
							html+=' 		</TR>';
							<B>'+LBL_MARKET_PRICE+'</B></TD><TD valign="top" width="1%">:</TD><TD class="price-new" valign="top" width="49%"><strong>
							*/
							html+=' 		<TR>';
							html+=' 			<TD colspan="3">&nbsp;</TD>';
							html+=' 		</TR>';
							if(fretailprice != '-'){
							html+=' 		<TR>';
							html+=' 			<TD valign="top" width="50%" height="30"><strong><STRIKE>'+fretailprice+'</STRIKE></strong></TD>';
							html+=' 		</TR>';
								var priceclass= "price";
							}else{
							html+='<TR>';
								html+='<TD valign="top" height="30" width="50%">&nbsp;</TD>';
							html+='</TR>';
								var priceclass= "price-new";
							}
							
							html+=' 		<TR>';
								html+='<TD class="'+priceclass+'" width="49%" height="30" valign="top" >';
								if(fprice != '-'){
									html+='<strong>'+fprice+'</strong>';
								}else{
									html+='&nbsp;';
								}
								html+='</TD>';//class="price"
							html+=' 		</TR>';
							html+=' 		<TR>';
							html+=' 			<TD height="30"  colspan="3"><A href="Producto/'+hrefprod+'/'+iproductId+'/'+iStoreId+''+extcat+'"  class="button-small"><SPAN>'+VIEW_DETAILS+'</SPAN></A></TD>';
							html+=' 		</TR>';
							html+=' 		</TABLE>';
							html+=' 	</TD>';
							html+=' </TR>';
					html+=' </TABLE>';
					html+=' </DIV><B class="b4b"></B><B class="b3b"></B><B class="b2b"></B><B class="b1b"></B></DIV>';
					html+=' </TD>';
					
				}
					if(no == 1){
						html+=' <TD width="50%">&nbsp;';
						html+=' </TD>';
					}
					if(STORE_PAGE !=2){
					if(2%1 == 0)	
					html+=' </TR>';
					}else{
					html+=' </TR>';
					}
					html+=' </TABLE>';				
			}	
			else
			{
				//document.getElementById('REC_MSG_TOP').innerHTML = '';
				document.getElementById('REC_MSG_BOTTOM').innerHTML = '';
				html+='<TABLE width="100%" border="0" cellspacing="2" cellpadding="3" >';
				html+='<TR><TD align="center" class="omatter-bold">'+recmsg+'</TD></TR>';
				html+='</TABLE>';
			}
			document.getElementById('divstPro').innerHTML =html;
			setPagingproducts(totrec, start,icat);
		}
	}	
}

var start;
var var_limit = ''
var page_string = "";
var start_loop;
function setPagingproducts(tot_rec, start,icat)
{
	if(tot_rec == "")	
		tot_rec = 0;
		page_string = "";
		extra = "";
		num_limit = 0;
		last_rec = 0;
		if(start != '0')
		{	
			num_limit = (start-1)*rec_limit;
			var_limit = " LIMIT "+num_limit+" ,"+rec_limit; 
		}
		else 
		{
			var_limit = " LIMIT 0,"+rec_limit;
		}	
			
	
		if(start == '0')
		{
			start = '1';
		}
	tot_pages = Math.ceil(tot_rec/rec_limit) ; 
	loop_limit = ((page_limit > tot_pages) ? tot_pages : page_limit) ;
	start_loop = Math.floor(start/page_limit);
	if(start_loop != (start/page_limit))
		start_loop = start_loop * page_limit+1;
	else
		start_loop = (start_loop-1) * page_limit+1;
	
	page_string+="<div id='store-paging' class='bluematter' align='center'>";
	page_string+="<ul>";
    		
			if(start_loop>page_limit)
			{
				prev_loop = start_loop - 1;
				page_string+="<li><a href='javascript:StoreProducts(\""+prev_loop+"\",\""+icat+"\");' title=\""+LBL_PREVIOUS+"\"><b>"+LBL_PREVIOUS+"</b></a></li>";
    		}
			
			for(loop=1 ; loop<=loop_limit ; loop++)
			{	
				if(start_loop>tot_pages) break;
				if(parseInt(start_loop) == parseInt(start))
					clas = "current";
				else
					clas = "";
				page_string+="<li><a href='javascript:StoreProducts(\""+start_loop+"\",\""+icat+"\");' title=\""+start_loop+"\" class="+clas+" ><b>"+start_loop+"</b></a></li>";
				start_loop++;	
			}
			if(start_loop<=tot_pages)
			page_string+="<li><a href='javascript:StoreProducts(\""+start_loop+"\",\""+icat+"\")'; title=\""+LBL_NEXT+"\"><b>"+LBL_NEXT+"</b></a></li>";
		
	page_string+="</ul>";
	page_string+="</div>";
	document.getElementById("PAGING-BOTTOM").innerHTML = page_string;
	//document.getElementById("PAGING-TOP").innerHTML = page_string;
}
function getSubCategory(iLangId,iSubParentId){
	if(iSubParentId ==  0){
		if(document.getElementById("subcat"+iLangId)){
			if(document.getElementById("subcat"+iLangId).style.display == "none")
				document.getElementById("subcat"+iLangId).style.display="";
			else if(document.getElementById("subcat"+iLangId).style.display == ""){
				document.getElementById("subcat"+iLangId).style.display="none";
			}
		}
	}else
		if(document.getElementById("subcat"+iSubParentId)){
			if(document.getElementById("subcat"+iSubParentId).style.display == "none")
				document.getElementById("subcat"+iSubParentId).style.display="";
			else if(document.getElementById("subcat"+iSubParentId).style.display == ""){
				document.getElementById("subcat"+iSubParentId).style.display="none";
			}
		}
}
