YAHOO.namespace("example.container");
if (!YAHOO.example.container.wait) 
{

	// Initialize the temporary Panel to display while waiting for external content to load

	YAHOO.example.container.wait = 
	new YAHOO.widget.Panel("wait",  
								{ width: "240px", 
								  fixedcenter: true, 
								  close: false, 
								  draggable: false, 
								  modal: true,
		  						  zindex:4,
								  visible: false
								} 
								);

	YAHOO.example.container.wait.setHeader("Loading, please wait...");
	YAHOO.example.container.wait.setBody("<img src=\""+site_url+"images/rel_interstitial_loading.gif\"/>");
	YAHOO.example.container.wait.render(document.body);

}

function replaceAll( str, searchTerm, replaceWith)   {
   var regex = "/"+searchTerm+"/gi";
   return str.replace( eval(regex), replaceWith );
}
/* for sub_cat,brand listing start */
function makeRequestPOST(frmObj,url,responseFunction,clear)
{
	YAHOO.example.container.wait.show();
	var postData;
	postData = getformVariables(frmObj);
	/*alert(clear);
	alert(postData);*/
	if(typeof(clear) != "undefined" && clear != "")
	{
		for(c=0;c<clear.length;c++)
		{
			postData =  replaceAll( postData,clear[c], "");
		}
	}
	scroll(0,0);
	var request = YAHOO.util.Connect.asyncRequest('POST', url, eval(responseFunction), postData);
}
var callback_POST =
{
  success:function (o)
		{
		 	//alert(o.responseText);//return false;
			YAHOO.example.container.wait.hide();
			scroll(0,0);
			var content = handleHttpResponse_AjaxCommon(o);
			var content_split = content.split('||_||');
			if(content_split[0] && typeof(content_split[0]) != "undefined")	document.getElementById('category_list_div').innerHTML = content_split[0];
			if(content_split[1] && typeof(content_split[1]) != "undefined")	document.getElementById('brand_list_div').innerHTML = content_split[1];
			if(content_split[2] && typeof(content_split[2]) != "undefined")	document.getElementById('product_list_div').innerHTML = content_split[2];
			if(content_split[3] && typeof(content_split[3]) != "undefined")
			{
				var product_split = content_split[3].split('|||$|||');
				document.getElementById('slider1knob1').value = parseFloat(product_split[3]);
				document.getElementById('slider1knob2').value = parseFloat(product_split[4]);
				s1 = document.getElementById('slider1knob1').value;
				s2 = document.getElementById('slider1knob2').value;
				initslider(parseFloat(product_split[1]),parseFloat(product_split[2]),parseFloat(product_split[3]),parseFloat(product_split[4]));
			}
			if(content_split[4] && typeof(content_split[4]) != "undefined")	document.getElementById('size_list_div').innerHTML = content_split[4];
			if(document.getElementById('sub_department').value != "")
				document.title = 'Buy '+document.getElementById('department_name').value+'  '+document.getElementById('sub_department').value+' shoes at Emall Shoes Stores';
			else 
				document.title = 'Buy '+document.getElementById('department_name').value+' shoes at Emall Shoes Stores';
		},
  failure:function (o)
  {
  	alert("Response Error.");
  }
};
/* for sub_cat,brand listing end */

/* for brand listing start */
function makeRequestbrand_POST(frmObj,url,responseFunction)
{
		//YAHOO.example.container.wait.show();
		var postData;
		postData = getformVariables(frmObj);
		if(Trim(document.getElementById('brandname').value) != "")
		{
			postData += "&brandname="+Trim(document.getElementById('brandname').value);
		}
		var request = YAHOO.util.Connect.asyncRequest('POST', url, eval(responseFunction), postData);
}
var callbackbrand_POST =
{
  success:function (o)
		{
		 	//alert(o.responseText);//return false;
			//YAHOO.example.container.wait.hide();
			var content = handleHttpResponse_AjaxCommon(o);
			if(content)	document.getElementById('brand_list_div').innerHTML = content;
			document.getElementById('brandname').focus();
		},
  failure:function (o)
  {
  	alert("Response Error.");
  }
};
/* for brand listing end */

/* for product listing start */
function makeRequestproductlist_POST(val)
{
	var url = site_url+"ajax/getcategory.php";
	YAHOO.example.container.wait.show();
	var postData;
	var frmObj = document.frmcategory;
	postData = getformVariables(frmObj);
	if(val != "")
		postData += val;
	scroll(0,0);
	var request = YAHOO.util.Connect.asyncRequest('POST', url, callbackproductlist_POST, postData);
}
var callbackproductlist_POST =
{
  success:function (o)
		{
		 	//alert(o.responseText);//return false;
			YAHOO.example.container.wait.hide();
			scroll(0,0);
			var content = handleHttpResponse_AjaxCommon(o);
			var content_split = content.split('||_||');
			if(content_split[0] && typeof(content_split[0]) != "undefined")	document.getElementById('product_list_div').innerHTML = content_split[0];
			if(content_split[1] && typeof(content_split[1]) != "undefined")
			{
				var product_split = content_split[1].split('|||$|||');
				document.getElementById('slider1knob1').value = parseFloat(product_split[3]);
				document.getElementById('slider1knob2').value = parseFloat(product_split[4]);
				s1 = document.getElementById('slider1knob1').value;
				s2 = document.getElementById('slider1knob2').value;
				initslider(parseFloat(product_split[1]),parseFloat(product_split[2]),parseFloat(product_split[3]),parseFloat(product_split[4]));
			}
			//if(content)	document.getElementById('product_list_div').innerHTML = content;
		},
  failure:function (o)
  {
  	alert("Response Error.");
  }
};
function filterbybrand(val)
{
	var id = 'brand_'+val;
	if(val && document.getElementById(id))
	{
		document.getElementById(id).checked = true;
		checkbrand(document.frmcategory);
		makeRequestPOST(document.frmcategory,site_url+"ajax/getcategory.php",callback_POST);
	}
}
/* for product listing end */
function checkbrand(frmobj)
{
	document.getElementById('selsizestr').value='';
	var brandobj = frmobj["brand[]"];
	var selbrandflag = false;

	for(i=0;i<brandobj.length;i++)
	{
		if(brandobj[i].checked == true)
		{
			selbrandflag = true;
			break;
		}
	}
	if(selbrandflag)
	{
		document.getElementById('clear_brand_tr').style.display = '';
	}
	else
	{
		document.getElementById('clear_brand_tr').style.display = 'none';
	}
	setslidervalues_null();
}
function setslidervalues_null()
{
	document.getElementById('slider1knob1').value = '';
	document.getElementById('slider1knob2').value = '';
}
/* for selecting the size button start */
function selsizebtn(val)
{
	var sizestrobj = document.getElementById('selsizestr');
	if(sizestrobj && sizestrobj.value == "" && val != "")
		sizestrobj.value = val;
	else
		sizestrobj.value += ","+val;
	setslidervalues_null();
	makeRequestPOST(document.frmcategory,site_url+"ajax/getcategory.php",callback_POST);
}
/* for selecting the size button end */
/* for deselecting the size button start */
function deselsizebtn(val)
{
	var sizestrobj = document.getElementById('selsizestr');
	
	if(sizestrobj.value.indexOf(','+val) != -1)
	{
		sizestrobj.value = replaceAll( sizestrobj.value,','+val, "");
	}
	else if(sizestrobj.value.indexOf(val+',') != -1)
	{
		sizestrobj.value = replaceAll( sizestrobj.value,val+',', "");
	}
	else
	{
		sizestrobj.value = replaceAll( sizestrobj.value, val, "");
	}
	setslidervalues_null();
	makeRequestPOST(document.frmcategory,site_url+"ajax/getcategory.php",callback_POST);
}
/* for deselecting the size button end */

/* for getting the product detail start */
var prevtdid;
function makeRequestproductdetail_POST(val)
{
	var url = site_url+"ajax/getproductdetail.php";
	YAHOO.example.container.wait.show();
	if(prevtdid && prevtdid != "")
	{
		document.getElementById('td_'+prevtdid).className='';
	}
	document.getElementById('td_'+val).className='selected-product';
	prevtdid = val;
	var postData;
	postData = 'id='+val;
	var request = YAHOO.util.Connect.asyncRequest('POST', url, callbackproductdetail_POST, postData);
}
var callbackproductdetail_POST =
{
  success:function (o)
		{
		 	//alert(o.responseText);//return false;
			YAHOO.example.container.wait.hide();
			var content = handleHttpResponse_AjaxCommon(o);
			if(content)
			{
				document.getElementById('product_detail_div').innerHTML = content;
				FadeIn('product_detail_div');
			}
		},
  failure:function (o)
  {
  	alert("Response Error.");
  }
};
/* for getting the product detail end */
