
/* friend browser functions */
//# - added this variable for search based on left menu - By Jeyaseelan
var searchf = "";
var searchstring = "";
var errmsg = "";
var default_err = ""
var errnavsearch = "";
var totalrecvalues = "";
//# - added for default message on 12/07/07 by Jeyaseelan
var textindent = "style='text-indent:20px'";
var MyTagsMessage = "<p "+textindent+">The tags you've created will be listed here. Help the StyleLogue community by creating relevant Tags. This will enable users to search for specific things.</p><p "+textindent+">You will be able to manage all of the tags that you have created by adding, editing, and deleting tags from your personal tag cloud.</p><p "+textindent+">Can't find products you added? Perform searches for those products by clicking on the tags within your own Tag Cloud.</p>";	
var GroupsMessage = "<p "+textindent+">Groups are special interest forums where people with similar hobbies and interests can share and discuss relevant topics. Each Group you join will be listed in this section.</p>";
var MyStartMessage = "<p "+textindent+">Once you begin voting on products, a selection of Recommended Products will be listed below.</p><p "+textindent+">These are products chosen just for you, based on ones you've expressed interest in.</p><p "+textindent+">Get started voting on products, and we'll display similarly tagged items that match your voting history.</p>";
var MyFriendsMessage = "<p "+textindent+">Add Friends now and they will be listed below! Start creating a closer connection to StyleLogue users who share common interests and similar style!</p>";

//# - Array for filenames - Detailed resources page filenames
var aCur_filenames = new Array( "mediadetails.php","groupdetails.php","detailtemplate.php" ); 
/* gets the friend record vars */
function browserec_friend( bcount, idx, nodelist )
{	
	var i = 0, j;
	brecs[bcount][idx] = new Object;
	brecs[bcount][idx].id = nodeval(nodelist[i++]);
	brecs[bcount][idx].img = nodeval(nodelist[i++]);
	brecs[bcount][idx].name = nodeval(nodelist[i++]);
	brecs[bcount][idx].rank = nodeval(nodelist[i++]);
	brecs[bcount][idx].type = nodeval(nodelist[i++]);
}

/* handles the mouseover/mouseout */
function browseover_friend( o, stat, bcount, idx )
{
	o.className = stat ? 'browseprod_sel' : 'browseprod';
//	debug( bcount, idx, brecs[bcount][idx].type );
	showpeek( o, stat, browseover_friend, browseclick_friend, bcount, idx );
}

/* handles the browseclick */
function browseclick_friend( event, o, bcount, idx )
{
	browseclick_product( event, o, bcount, idx );
}

/* outputs the friend cell */
function browsershow_friend( rec, bcount, r )
{
	if( !isdefined( rec ) ) return '';
	var obj = $('browser' + bcount);
	overfunc = 'browseover_friend';
	clickfunc = 'browseclick_friend';



	overpann = '';
//	overpann = '<div class="browseoverright"><a href="#" onclick="browseadd_friend( this, ' + bcount + ', ' + r + ')">BLOCK</a></div><div class="browseoverleft"><a href="#" onclick="browseview_friend( this, ' + bcount + ', ' + r + ')">VIEW</a></div>'
	power = rec.rank*1;
	
	if(obj.param.indexOf("onlineuser") != -1)
		power = rec.rank.split("##")[0]*1;
	var vbase = 1;
	var sp = '<div align=center>';
	// print the stars
	for( i = 0 ; i < 5 ; i++ )
	{
		//var let = vbase <= spow ? 'f' : ( vbase == spow + 1 ? 'h' : 'e' );
		var remain = 1-(vbase-power);
		if( remain > 1 || remain >= 0.5)
		{
			var let = vbase <= power ? 'f' : 'h';
			sp += '<img class=stylepower src="tool/' + ctable + '/sp_' + let + '.gif" width=12 height=12 alt="" border="0" aalign=left>';
		}
		vbase += 1;
	}
	if( sp == '<div align=center>' ) sp += '<img class=stylepower src="tool/' + ctable + '/sp_zero.gif" width=12 height=12 alt="" border="0" aalign=left>';
	sp += '</div>';
//	var rname = shrinktext( 'browseprod', 25, rec.name, '', 0 );
	var rname = rec.name;
	var imgwid = !ie ? '' : ' style="width: 102px; height: 102px"';
	//*
	var imagepath = rec.img;
	var image = getImageFullPath(imagepath);
	//# - added check box for the user to remove operation by the admin - on 18/06/07
/*	if(adminview == 1 && rec.type == "U")
		return '<td valign=top><div class=browseprod onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')" oonmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  oonmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><table cellpadding=0 cellspacing=0 border=0><tr><td class="browseimg"'+ imgwid + '><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</td></tr><tr><td><table cellpadding=0 cellspacing=0 border=0><tr><td valign=top width="2%" ><input type=checkbox id="chkUser"' + r + ' name="chkUser"' + r + ' value=' + rec.id + ' class=input  onClick="funCheckClick(this.value)" ></td><td style="text-align: center;vertical-align: top;bborder: 1px solid #0ee;font-family: Verdana;font-size: 10px;color: Black;">' + rname + '</td></tr><tr><td colspan=2 align=midle>' + sp + '</td></tr></table></td></tr></table></div>';     
*/
	//alert(document.cookie);
	if(adminview == 1 && rec.type == "U")
		return '<td valign=top><div class=browseprod oonmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  oonmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '  onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')"><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</div><p>' + rname + '</p>' + sp + '<div style="position: absolute; bottom: 0px; left: 0px;"><input type=checkbox id="chkUser"' + r + ' name="chkUser"' + r + ' value=' + rec.id + ' class=input  onClick="funCheckClick(this.value)" ></div></div>';
	else if(adminview == 2 && rec.type == "U")
	{
		var optselected = "";
		if(rec.id == default_user && default_user)
			optselected = "checked";
		  
		return '<td valign=top><div class=browseprod oonmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  oonmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '  onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')"><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</div><p>' + rname + '</p>' + sp + '<div style="position: absolute; bottom: 0px; left: 0px;"><input type=radio id="chkOption"' + r + ' name="chkOption"' + r + ' value=' + rec.id + ' class=input  onClick="funCheckClick(this.value)" '+optselected+'></div></div>';
	}
	else if(rec.type == "U" && obj.param.indexOf("onlineuser") != -1 && rec.rank.split("##")[1] == 1)
	{
		return '<td valign=top><div class=browseprod onmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  onmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '  onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')"><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</div><p>' + rname + '</p>' + sp + '<div style="position: absolute; bottom: 0px; left: 0px;"><img src="../images/onlinenow.gif" border=0></div></div>';
	}
	else if(adminview == 1 && rec.type == "G" && getbasename(window.location).indexOf('tagresourcedetails.php') == -1 )
	{
		return '<td valign=top><div class=browseprod oonmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  oonmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '  onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')"><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</div><p>' + rname + '</p>' + sp + '<div style="position: absolute; bottom: 0px; left: 0px;"><input type=checkbox id="chkGrp"' + r + ' name="chkGrp"' + r + ' value=' + rec.id + ' class=input  onClick="funCheckClick(this.value)" ></div></div>';	
	}
	else
	{ 
		return '<td valign=top><div class=browseprod onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')" onmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  onmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '><img src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">' + overpann + '</div><p>' + rname + '</p>' + sp + '</div>';
	}
/*	else if(rec.type == "U")
		return '<td valign=top><div class=browseprod onmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  onmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg" onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')" ><img src="' + rec.img + '" onload="imgmaxdim(this,100)">' + overpann + '</div><p>' + rec.name + '<br>' + sp + '</p></div>';
	else
		return '<td valign=top><div class=browseprod onclick="' + clickfunc + '(event, this, ' + bcount + ', ' + r + ')" onmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  onmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"><img src="' + rec.img + '" onload="imgmaxdim(this,100)">' + overpann + '</div><p>' + rec.name + '<br>' + sp + '</p></div>';
*/
}
//# - To close the popup when the user click checkbox - By Jeyaseelan on 18/06/07
function closepopup()
{
	window.setTimeout('nopopup()',1);
}
function browseadd_friend( o, bcount, idx )
{
	debug( 'Add ', bcount, idx, brecs[bcount][idx].name );
	o.href = 'javascript:v()';
}

function browseview_friend( o, bcount, idx )
{ 	debug( 'View ', bcount, idx, brecs[bcount][idx].name );
	o.href = 'javascript:v()';
}

/* product browser functions */
/* gets the product record vars */
function browserec_product( bcount, idx, nodelist )
{
	var i = 0, j;
	brecs[bcount][idx] = new Object;
	brecs[bcount][idx].id = nodeval(nodelist[i++]);
	brecs[bcount][idx].img = nodeval(nodelist[i++]);
	brecs[bcount][idx].name = nodeval(nodelist[i++]);
	brecs[bcount][idx].rank = nodeval(nodelist[i++]);
	brecs[bcount][idx].type = nodeval(nodelist[i++]);
	if( nodelist.length > i )
	{
		brecs[bcount][idx].user = val(nodeval(nodelist[i++]));
	}
}

function getTop(obj)
{
  var top = obj.offsetTop;
  while((obj = obj.offsetParent) != null) top += obj.offsetTop;
  return top;
}

function getLeft(obj)
{
  var left = obj.offsetLeft;
  while((obj = obj.offsetParent) != null) left += obj.offsetLeft;
  return left;
}

var peekobj = null;
var peekover = false;
var peektim = false;

function getpeek()
{
	if( peekobj == null )
	{
		peekobj = ce( 'DIV' );
		peekobj.className = 'peek';
		document.body.appendChild( peekobj );
		ajaxrequest( "peek.html", "resulttxt", peekobj, 0); 
	}
	peekobj.style.display = 'block';
	return peekobj;
}

var overobj = null;

function getover()
{
	if( overobj == null )
	{
		overobj = ce( 'DIV' );
		overobj.className = 'browseover';
		document.body.appendChild( overobj );
	}
	overobj.style.display = 'block';
	return overobj;
}

function delover()
{
	if( overobj == null ) return;
	document.body.removeChild( overobj );
	overobj = null;
}


function delpeek()
{
	if( peekobj == null ) return;
	document.body.removeChild( peekobj );
	peekobj = null;
}

function hidepeek()
{
	if( peekobj != null ) peektim = setTimeout( "delpeek();delover()", 1 );
}

function showpeek( o, stat, overfunc, clickfunc, bcount, idx )
{
	//uncomment next line to turn off peek
	//return;
//	debug( 'onlick', o.onclick );
//	debug( 'otag', o.className );
	if( bcount == -1 ) return;
	var rec = brecs[bcount][idx];

	if(rec.type == "M" || rec.type == "MED") return;
	o.onclick = null;
//	if( stat && popupwin == null)
	if( stat )
	{
		clearTimeout( peektim );
		if( peekobj == null || peekobj.idx != idx ) delpeek();
		var top = getTop(o);
		var left = getLeft(o);
		var over = getover();
		var peek = getpeek();
		var ev = new Object;
		peek.style.top = top - 20;
		peek.style.left = left- 20;
		peek.onmouseover = function() { peek.className = 'peek_over'; overfunc( o, 1, bcount, idx ); };
		peek.onmouseout = function() { peek.className = 'peek'; overfunc( o, 0, bcount, idx ); };
		peek.onmousedown = function() { clickfunc( ev, o, bcount, idx); hidepeek() };
		peek.bcount = bcount;
		peek.idx = idx;
		over.style.top = top + 1;
		over.style.left = left + 1;
		over.style.width = o.clientWidth + (ie?0:-2);
		over.style.height = o.clientHeight + (ie?1:0);
		over.onmouseover = function() { overfunc( o, 1, bcount, idx ); };
		over.onmouseout = function() { overfunc( o, 0, bcount, idx ); };
		over.onclick = function() { peekclickfunc( o, bcount, idx ) };
		over.title = o.title;
	}
	else
		hidepeek();
}

function peekclickfunc( o, bcount, idx )
{
	var rec = brecs[bcount][idx];

	var vPageName = '';
	/*
	if( rec.type == 'P' )
		vPageName = 'detailtemplate.php?dpro=' + rec.id + '&usrid=&GroupId=&tmptid=' + Math.random();
	else if( rec.type == 'G')
		vPageName = 'groupstuff.php?GroupFlag=GRP&GroupId=' + rec.id + '&gFlag=1';
	else if( rec.type == 'U')
		document.location = 'mystuff.php?usrid=' + rec.id;
	*/
	if( rec.type == 'P' )
		vPageName = 'detailtemplate.php?dpro=' + rec.id + '&usrid=&GroupId=&tmptid=' + Math.random();
	else if( rec.type == 'G' && !vGetCheckBoxFlag)
		vPageName = 'groupstuff.php?GroupFlag=GRP&GroupId=' + rec.id + '&gFlag=1';
	else if( rec.type == 'U' && !vGetCheckBoxFlag)
	{
		filename_set_cookie('mystuff.php?usrid=' + rec.id);
//		document.location = 'mystuff.php?usrid=' + rec.id;
	}
	else if( rec.type == 'MSG' )
		filename_set_cookie('mystuff.php?usrid=' + rec.cols[6] );
	else if( rec.type == 'S')
		document.location = 'mystufflist.php?lid=Style_' + rec.id + '&utype=1';
	else if( rec.type == 'GS')
		document.location = 'groupstufflist.php?GroupFlag=GRP&gFlag=1&lid=Style_' + rec.id + '&GroupId=' + rec.rank+ '&utype=1';
	else
		errorlog( 'peekclick', 'Invalid rectype "' + rec.type + '"' );
	
	vGetCheckBoxFlag = ""; //#-- variable check if checkbox is clicked or not - this variable defined in admin.js
	
	if(vPageName) filename_set_cookie(vPageName);
	
}


/* handles the mouseover/mouseout */
function browseover_product( o, stat, bcount, idx )
{
//	o.className = stat ? 'browseprod_sel' : 'browseprod';
	//# - Do not call for Media - added by Jeyaseelan on 04/08/07
//	if(bcount > 0 && idx >0)

	showpeek( o, stat, browseover_product, browseclick_product, bcount, idx );
}

/* handles the browseclick */
function browseclick_product( event, o, bcount, idx)
{
//	inspect( o.parentNode );
	var pop, pos, script;
	ptop = getTop( o );
	pleft = getLeft( o );
	script = $('browser'+bcount).detailscript;
	//# - add param to popup - added By Jeyaseelan
	var param  = $('browser'+bcount).param;
	var jpar = script.match( /\?/ ) ? '&' : '?';
	if( isdefined( script ) && script != '' )
	{
		//# - add param - Added by Jeyaseelan
		pop = popup( script + jpar + 'pid=' + brecs[bcount][idx].id+'&type=' + brecs[bcount][idx].type + '&'+param, ptop + 55, pleft + 50, 420 );
	}
}

/* outputs the product cell */
function browsershow_product( rec, bcount, r )
{
	var votedisp,image;
	if( !isdefined( rec ) ) return '';
	var obj = $('browser' + bcount);
	overfunc = 'browseover_product';
	clickfunc = 'browseclick_product';
	var clist = [ 'browseprod', 'browseprod_ugc', 'browseprod_mine' ];

	overpann = '';
//	overpann = '<div class="browseoverright"><a href="#" onclick="browseadd_friend( this, ' + bcount + ', ' + r + ')">BLOCK</a></div><div class="browseoverleft"><a href="#" onclick="browseview_friend( this, ' + bcount + ', ' + r + ')">VIEW</a></div>'
	
	nvotes = rec.rank*1 > 0 ? rec.rank : 0;
	//# - vote display for other than stylist item - added by Jeyaseelan on 19/03/07
	if(rec.type == 'S' || rec.type == 'GS'  )
		votedisp ="";
	else
		votedisp = nvotes+" votes";
	
	var imgwid = !ie ? '' : ' style="width: 102px; height: 102px"';
//	var rname = shrinktext( 'browseprod', 25, rec.name, '', 0 );
	rname = rec.name;

	if( !isdefined( rec.user ) ) rec.user = 0;
	var pclass = clist[rec.user];
	var imagepath= rec.img;

	//# - added to show the video embed tag as thumbnail for Media by Jeyaseelan on 22/03/07
	if(imagepath.indexOf('images/') != -1 || imagepath.indexOf('prod/') != -1)
	{
		var pclass = clist[rec.user];
		image = getImageFullPath(imagepath)
		if(rec.type == "M" || rec.type == "MED")
		{
			//# - Display for Media
			var mediaid = brecs[bcount][r].id;
			detailclick = "filename_set_cookie('mediadetails.php?mid="+mediaid+"')";
			imageurl = '<td valign=top><div class=' + pclass + ' onclick="' + detailclick +'" onmouseover="' + overfunc + '(this, 1, -1, -1)"  onmouseout="' + overfunc + '(this, 1, -1, -1)"><div class="browseimg"'+ imgwid + '><img class="' + pclass + '" src="' + image + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">'+ overpann + '</div><p>' + rname + '</p><b>' + votedisp + '</b></div>';
		}
		else
			imageurl = '<td valign=top><div class=' + pclass + ' onclick="' + clickfunc + '(event,this, ' + bcount + ', ' + r + ')" onmouseover="' + overfunc + '(this, 1, ' + bcount + ', ' + r + ')"  onmouseout="' + overfunc + '(this, 0, ' + bcount + ', ' + r + ')"><div class="browseimg"'+ imgwid + '><img class="' + pclass + '" src="' + rec.img + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">'+ overpann + '</div><p>' + rname + '</p><b>' + votedisp + '</b></div>';
	}
	else
	{
		$('browsecanvas'+bcount).innerHTML = '<div id="testdiv"></div>';
		var given_src="",flashvars="",detailclick="";
		//# - to get SRC From the given embed tag
		var returnstr = fungetsrc(imagepath);
		if(returnstr.indexOf("[###]") != -1)
		{
			var given_src = returnstr.split("[###]")[0];
			var flashvars = returnstr.split("[###]")[1];
		}
		else
		{
			given_src = returnstr;
		}
		//# - Check for SRC in the given embed tag
		if(given_src != "")
		{
			//# - Display for Media
			var mediaid = brecs[bcount][r].id;
			detailclick = "filename_set_cookie('mediadetails.php?mid="+mediaid+"')";
			if(flashvars == "youtube")
			{
				imageurl = '<td valign=top><div class=' + pclass + ' onclick="' + detailclick +'" onmouseover="' + overfunc + '(this, 1, -1, -1)"  onmouseout="' + overfunc + '(this, 1, -1, -1)"><div class="browseimg"'+ imgwid + '><img class="' + pclass + '" src="' + given_src + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">'+ overpann + '</div><p>' + rname + '</p><b>' + votedisp + '</b></div>';
			}
			else
			{
				//# - use the interface object to show embed tag as a thumbnail image
				imageurl = '<td valign=top ><div class=' + pclass + ' onmouseover="' + overfunc + '(this, 1, -1, -1)"  onmouseout="' + overfunc + '(this, 1, -1, -1)"><div class="browseimg" width="100" height=100><object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="100" ><param name="movie" value="../web/tool/videothumbs.swf?txtCDXML=http://youtube.com/crossdomain.xml&txtVideo='+given_src+'&txtFunc=Javascript:'+detailclick+'"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="sameDomain" /><embed src="../web/tool/videothumbs.swf?txtCDXML=http://youtube.com/crossdomain.xml&txtVideo='+given_src+'&txtFunc=Javascript:'+detailclick+'" type="application/x-shockwave-flash" wmode="transparent" width="100" height="100" allowScriptAccess="sameDomain"></embed></object>'+ overpann + '</div><p>' + rname + '</p><b>' + votedisp + '</b></div>';		
			}
		}
		else
		{
			var mediaid = brecs[bcount][r].id;
			detailclick = "filename_set_cookie('mediadetails.php?mid="+mediaid+"')";
					
			recimg = ImagePath+"/images/media/medianotfound.jpg";
			imageurl = '<td valign=top ><div class=' + pclass + ' onclick="' + detailclick +'"  onmouseout="' + overfunc + '(this, 0, -1, -1)"><div class="browseimg"'+ imgwid + '><img src="' + recimg + '" onload="imgmaxdim(this,100)" title="' + rec.name + '">'+ overpann + '</div><p>' + rname + '</p><b>' + nvotes + ' votes</b></div></td>';
		}
		
	}
	return imageurl;
}

function browsershow_tag( rec, bcount, r,total,start,end )
{
	var votedisp,imageurl="";
	if( !isdefined( rec ) ) return '';
	var obj = $('browser' + bcount);
	overfunc = 'browseover_product';
	clickfunc = 'browseclick_product';
	var clist = [ '', 'userprod', 'myprod' ];
	overpann = '';
	//# - get tag resource count
	nvotes = rec.rank*1 > 0 ? rec.rank : 0;
	
	
	//#--------------
	//# - Showing in Admin Report
	if((getbasename(document.location) == 'reports.php' || getbasename(document.location) == 'reports.php#' || getbasename(document.location) == 'reports.php#topnav') && (searchf == 'prodbrand' || searchf == 'prodretailer' || searchf == 'cpcretailer'  || searchf == 'cpcbrand' || searchf == 'producturl')) //#-- Modified by rajendran for report 
	{
		//# - Build a tagcloud	
		var vAdminReport = '';	
		var vRetCount = '';
		for( var i = (start-1) ; i < end ; i++ )
		{
			name =  unescape(brecs[bcount][i].name);//vtag( btotrecs[bcount][i], 'name' );
			id = brecs[bcount][i].id;
			vRetCount = brecs[bcount][i].img;
			vAvail = brecs[bcount][i].rank;
			vURL = brecs[bcount][i].type;
			//# - replace for < and > 
			name = name.replace("<","&lt;");
			name = name.replace(">","&gt;");
			if(name.length > 20 ) name = name.substring(0,20)+"...";
			url = "detailtemplate.php?dpro="+id;
			//# - Set cookie for getting back - commented above and added by Jeyaseelan on 14/05/07
			var setcook = "filename_set_cookie('" + url + "','backfilename')";
			if(searchf == 'producturl')
			{
				//vUrl = "'prodhandle.php?func=del&pid="+id+"'";
				vAdminReport += '<tr><td class=noresult width=16% style="text-indent:10px"><a href="javascript:'+setcook+'" title="'+unescape(brecs[bcount][i].name)+'" style="text-decoration:none">' + name + '</a></td><td class=noresult align=center><b>'+vRetCount+'</td><td class=noresult align=center><b>'+vAvail+'</td><td class=noresult align=center><div id=produrl onclick="prodhandle( event, this,'+id+',\'editurl\')" style="cursor:hand" title="Click here to edit this url"><b>'+vURL+'</b></div></td><td class=noresult align=center><b><img src="../images/icon_delete.gif" border=0 onclick="prodhandle( event, this,'+id+',\'del\')" title="Click here to remove this product" style="cursor:hand"></b></td></tr>';
			}
			else
				vAdminReport += '<tr><td class=noresult width=70% style="text-indent:10px">' + name + '</td><td class=noresult align=center><b>'+vRetCount+'</td></tr>';
		}
		//#- Set for title
		var Reporttitl  = "TOTAL PRODUCTS";
		var cpcsearchbutt="";
		if(searchf == 'cpcretailer' || searchf == 'cpcbrand')
			Reporttitl  = "NUMBER OF CLICKS";
		//if(searchf == 'cpcretailer' || searchf == 'cpcbrand' || searchf == 'prodretailer' || searchf == 'prodbrand')
		{
			cspan = 2;
			if(searchf == 'producturl')
				cspan = 8;
			cpcsearchbutt = "<tr><td colspan="+cspan+">"+getsearchcpcbox(bcount,((searchf == 'producturl')?'style="display:none"':''))+"</td></tr>";
		}	
		if(searchf == 'producturl')
		{
			var urlimg = "",availimg = "",titleimg = "";
			sortname = varrecover_s('sortname');
			sortby = varrecover_s('sortby');
			
			if(sortname == "abl")
			{
				if(sortby == "desc")
				{
					sortby = "asc"
					availimg = "arrowup_b.gif";
				}
				else if(sortby == "asc")
				{
					sortby = "desc"
					availimg = "arrowdown_b.gif"
				}
				availimg = "<img src='../images/"+availimg+"' border=0>";
					
			}
			else if(sortname == "urlstatus")
			{
				if(sortby == "desc")
				{
					sortby = "asc"
					urlimg = "arrowup_b.gif";
				}
				else if(sortby == "asc")
				{
					sortby = "desc"
					urlimg = "arrowdown_b.gif"
				}
				urlimg = "<img src='../images/"+urlimg+"' border=0>";
			}
			else if(sortname == "title")
			{
				if(sortby == "desc")
				{
					sortby = "asc"
					titleimg = "arrowup_b.gif";
				}
				else if(sortby == "asc")
				{
					sortby = "desc"
					titleimg = "arrowdown_b.gif"
				}
				titleimg = "<img src='../images/"+titleimg+"' border=0>";
			}
			vAdminReport = "<tr><td class=noresult width=30% style='text-indent:10px' onclick='sorting("+bcount+",\""+sortby+"\",\"title\")' style='cursor:hand'><b>"+titleimg+"PRODUCT</b></td><td class=noresult width=15% align=center><b>SL Count</b></td><td class=noresult width=15% align=center onclick='sorting("+bcount+",\""+sortby+"\",\"abl\")' style='cursor:hand'><b>"+availimg+"Avail</b></td><td class=noresult width=15% align=center onclick='sorting("+bcount+",\""+sortby+"\",\"urlstatus\")' style='cursor:hand'><b>"+urlimg+"URL</b></td><td class=noresult align=center><b>REMOVE</b></td></tr>" + vAdminReport;
		}
		else if(searchf == 'prodbrand' || searchf == 'cpcbrand')
		{
			
			vAdminReport = "<tr><td class=noresult width=70% style='text-indent:10px'><b>BRAND NAME</b></td><td class=noresult ><b>"+Reporttitl+"</b></td></tr>" + vAdminReport;
			
		}
		else if(searchf == 'prodretailer' || searchf == 'cpcretailer' )
		{
				vAdminReport = "<tr><td class=noresult width=70% style='text-indent:10px'><b>RETAILER NAME</b></td><td class=noresult><b>"+Reporttitl+"</b></td></tr>" + vAdminReport;
		//buttonizeall($('search'));		
				
		}
		 //return ("<table border=1 rules=all cellspacing=0 cellpadding=0 width=100%><tr><td>" +cpcsearchbutt+vAdminReport + "</td></tr></table>")
		return "<table frame=below rules=rows cellspacing=0 cellpadding=0 width=100%>" +cpcsearchbutt+vAdminReport + "</table>";
		
	}
	else
	{
		//# - Build a tagcloud	
		//# - get max and min tag resource count
		var vMax = 0, vMin = 9999999999;
		for( var iCount = (start-1) ; iCount < end ; iCount++ )
		{
			var count = parseInt(brecs[bcount][iCount].rank);//?brecs[bcount][i].rank:0;//vtag( btotrecs[bcount][i], 'count' ) * 1;
			if( count > vMax ) 
				vMax = count;
			if( count < vMin ) 
				vMin = count;
			
		}
		
		var vRetCount = '';
		for( var i = (start-1) ; i < end ; i++ )
		{
			name =  unescape(brecs[bcount][i].name);//vtag( btotrecs[bcount][i], 'name' );
			vRetCount = brecs[bcount][i].img;
			count =  parseInt(brecs[bcount][i].rank);
			count = Math.floor(7*(count-vMin)/vMax)+1;
			url =  brecs[bcount][i].img;//vtag( btotrecs[bcount][i], 'url' );// + obj.script
			//# - replace for < and > 
			name = name.replace("<","&lt;");
			name = name.replace(">","&gt;");
			var cname = 'tag' + count;
			name = splittext( cname, 250, name );
			//# - Set cookie for getting back - commented above and added by Jeyaseelan on 14/05/07
			var setcook = "filename_set_cookie('" + url + "', 'backtagfile')";
			imageurl += '<a href="#" class="tagr' + count + '" onclick="' + setcook + '"><nobr>' + name + '</nobr></a> ';
		}
		return imageurl;
	}
	
}
function getsearchcpcbox(bcount,exportoption)
{
		var vSearchVal = searchstring?searchstring:"search";
		var otop = ie ? -1 : 0;
		return "<table cellpadding=0 cellspacing=0 border=0  width=96%><tr><td align=right width=61% "+exportoption+"><a href='admin_export.php?search="+searchf+"&startrec=&maxrec=&searchkey="+((vSearchVal!="search")?vSearchVal:"")+"&fromdate="+(document.getElementById('txtFromDate')?document.getElementById('txtFromDate').value:"")+"&todate="+(document.getElementById('txtToDate')?document.getElementById('txtToDate').value:"")+"' style='text-decoration:none'><img src='../images/export.gif' border=0/><b>Export</b></a></td><td align=right><input type=text name=cpcsearch id=cpcsearch value='"+vSearchVal+"' class='searchfield' onfocus='searchclean( this ); this.select()' style='top: "+otop+"px' onkeypress='pressentersearch(event,"+bcount+")'><input type=button value=GO onclick='cpcsearch("+bcount+")'><br></td></tr></table>";
}
function pressentersearch(e,bcount)
{
		var pNumKeyCode = (window.event) ? event.keyCode : e.keyCode;
		if(pNumKeyCode == 13)
			cpcsearch(bcount)
}
function cpcsearch(bcount)
{
	var obj = $('browser' + bcount);
	//o = bcount
	var sval = document.getElementById('cpcsearch').value;
	document.getElementById('cpcsearch').value = trim(sval); //#--
	searchstring = sval;
	
	if( (sval == 'search'))
	{
		$('cpcsearch').focus();
	}
	else
	{
		//varsave( 'bs', sval );
		//get browser instance
		while( !isdefined( obj.bcount ) )
		{
			obj = obj.parentNode;
		}

		var querystring = '';

		//# - validate the value with special chars
		if( sval )
		{
		
			//# - added query string for search based on left menu - By Jeyaseelan
			querystring += "search="+searchf+"&searchkey=" + escape(sval);
	
			//browseqry( o, 'search=' + sval, 0 );
			browseqry( obj, querystring, 0 );
		
		}
		else
		{
			browseqry( obj, "search="+searchf, 0 );
		}
	
		//#-- Condition Added By Rajendran
	}
	return false;
}
function sorting(bcount,sortby,sortname)
{
	var obj = $('browser' + bcount);
	//get browser instance
	while( !isdefined( obj.bcount ) )
	{
		obj = obj.parentNode;
	}

	var querystring = '';

	//# - validate the value with special chars
	if( sortname)
	{	
		//# - added query string for search based on left menu - By Jeyaseelan
		querystring += "search="+searchf+"&sortname=" + sortname + "&sortby="+sortby;

		browseqry( obj, querystring, 0 );
	
	}
	else
	{
		browseqry( obj, "search="+searchf, 0 );
	}
	
	return false;
}

function fungetsrc(cont)
{
	if(cont.indexOf('embed') != -1 && (cont.indexOf('</embed>') != -1 || cont.indexOf('/>') != -1 ))
	{
		var newObj = document.getElementById('testdiv');
		var vStart = cont.indexOf('<embed');
		var vEnd   = (cont.indexOf('</embed>') !=-1)?cont.indexOf('</embed>'):((cont.indexOf('/>') != -1)?(cont.indexOf('/>')+3):0);
		newObj.innerHTML= cont.substring(vStart,vEnd);
		newObj.style.display = "none"
		var embed = newObj.getElementsByTagName("embed");//document.getElementsByTagName("EMBED")
		if(embed[0])
		{
			if(newObj.innerHTML.indexOf("youtube.com") != -1)
			{
				//# - Get thumbnail image for Youtube videos
				getSRC = embed[0].getAttribute("src");//"http://www.youtube.com/v/PtbjH8Tm4fM&rel=1";
				getSRC =getSRC.split("/");
				//alert(getSRC.search(//i)
				getID = getSRC[getSRC.length-1];
				getID = getID.substring(0,(getID.indexOf("&")!=-1?getID.indexOf("&"):getID.length));
				//embed[0].setAttribute("width",60)
				//embed[0].setAttribute("height",60);
				return imgpath = "http://img.youtube.com/vi/"+getID+"/default.jpg[###]youtube";
				//document.write("<img src='http://img.youtube.com/vi/"+getID+"/default.jpg'>");
			}
			else if(newObj.innerHTML.indexOf("yahoo.com") != -1)
			{
				//# - Get thumbnail image for Yahoo videos
				getSRC = embed[0].getAttribute("flashvars");//"http://www.youtube.com/v/PtbjH8Tm4fM&rel=1";
				getSRC =getSRC.split("&");
				getID = getSRC[getSRC.length-1];
				getID = getID.replace("vid=","");
				return imgpath = "http://thmg01.video.search.yahoo.com/image/"+getID+"_01[###]youtube";
				
			}
			else
			{
				if(embed[0].getAttribute("src") && embed[0].getAttribute("flashvars"))
					return embed[0].getAttribute("src")+"[###]"+embed[0].getAttribute("flashvars");
				else if(embed[0].getAttribute("src"))
					return embed[0].getAttribute("src");

			}
		}
		
		return "";
	}
	else
		return "";
	/*return "http://www.youtube.com/v/vtZ2qeOwuaI";*/
}
function browseadd_product( o, bcount, idx )
{
	debug( 'Add ', bcount, idx, brecs[bcount][idx].name );
	o.href = 'javascript:v()';
}

function browseview_product( o, bcount, idx )
{
	debug( 'View ', bcount, idx, brecs[bcount][idx].name );
	o.href = 'javascript:v()';
}


function editlist( event, o, lid )
{
	alert( 'edit list ' + lid );
}

function deletelist( event, o, lid )
{
	alert( 'del list ' + lid );
}

function listuploadphoto( event, o, lid,medType,gid )
{
	medType = isdefined(medType)?medType:1;
	if(medType == 3)
		window.location.href = "addnewmedia.php?lid="+ lid+ "&meditype="+ medType+"&GroupId="+gid;
	else
		addmedia( event, o , gid,0,lid);
	//alert( 'upload photo to list ' + lid );
}

function listuploadvideo( event, o, lid )
{
	alert( 'upload video to list ' + lid );
}

function browse_ugc_click( event, o, bcount, idx , pmResType)  //#-- Added By Rajendran
{

//	inspect( o.parentNode );
	var pop, pos, script;
	var ptop = getTop(o);
	var pleft = getLeft(o);
	script = vo_detailscript[vo_currentmode];
	var jpar = script.match( /\?/ ) ? '&' : '?';
	//# - check for media for redirect to details page rather than display popup
	if(pmResType == "recentmedia")
	{
		filename_set_cookie('mediadetails.php?mid='+brecs[bcount][idx].id)
		
	}
	else if( script != '')
	{	
//		alert(script + jpar + 'pid=' + brecs[bcount][idx].id+'&type=' + pmResType);
//		pop = popup( script + jpar + 'pid=' + brecs[bcount][idx].id+'&type=' + brecs[bcount][idx].type, ptop + 30, pleft + 30, 420 );
		pop = popup( script + jpar + 'pid=' + brecs[bcount][idx].id+'&search=' + pmResType, ptop + 30, pleft + 30, 420 );
	}
}

/* general browser functions */

function browsehidemenu( bcount )
{
	$('boptions' + bcount).style.width = 640;
	$('browsenav_'+bcount).style.width = 640;
	$('browsenav2_'+bcount).style.width = 640;
	$('browsecanvas'+bcount).style.width = 640;
	$('browseoptions'+bcount).style.width = 640;
	$('browsenav_'+bcount).style.left = 0;
	$('browsenav2_'+bcount).style.left = 0;
	$('browsecanvas'+bcount).style.left = 8;
	$('browseoptions'+bcount).style.left = 0;
	$('browsemenu'+bcount).style.width = 0;
	$('browsemenuband'+bcount).style.width = 0;
	browsecols = 6;
	browselines = 5;
	browsepag = browsecols*browselines;
}

function browseshowmenu( bcount )
{
	$('boptions' + bcount).style.width = 524;
	$('browsenav_'+bcount).style.width = 524;
	$('browsenav2_'+bcount).style.width = 524;
	$('browsecanvas'+bcount).style.width = 524;
	$('browseoptions'+bcount).style.width = 524;
	$('browsenav_'+bcount).style.left = 115;
	$('browsenav2_'+bcount).style.left = 115;
	$('browsecanvas'+bcount).style.left = 115;
	$('browseoptions'+bcount).style.left = 115;
	$('browsemenu'+bcount).style.width = 114;
	$('browsemenuband'+bcount).style.width = 114;
	browsecols = 5;
	browselines = 5;
	browsepag = browsecols*browselines;
}

//#------------- Product Count Checking
function funprodcount()
{
	setCookie("totalCount", arguments[0]);
}
//#---------

function browseshow( bcount, off )
{ 
	var l, c, i, out = '', rec, max1, max2, nav;
	var sr, er;

	nopopup();
	l = c = i = 0;
	brec[bcount] += off;
	varsave( 'idx', brec[bcount] );
	if( brec[bcount] < 0 ) brec[bcount] = 0;
	r = brec[bcount];
	
	displayfunc = eval( 'browsershow_' + $('browser'+bcount).type );
	var binc = vo_currentmode ? browselines : browsepag;
	//navigator
	sr = r + 1;
	se = r + binc;
	var binc = vo_currentmode ? browselines : browsepag;
	if( se > btotrecs[bcount] ) se = btotrecs[bcount];

	if( sr > 1 )
	{
		prev = '<td class="browseprev" onmousedown="browseshow(' + bcount + ', -' + binc + ')"></td>';
		prev2 = '<td class="browseprev" onmousedown="location=\'#topnav\'; browseshow(' + bcount + ', -' + binc + ')"></td>';
	}
	else
		prev2 = prev = '<td class="browseprev_off"></td>';

	if( se < btotrecs[bcount] )
	{
		next = '<td class="browsenext" onmousedown="browseshow(' + bcount + ', ' + binc + ')"></td>';
		next2 = '<td class="browsenext" onmousedown="location=\'#topnav\';browseshow(' + bcount + ', ' + binc + ')"></td>';
	}
	else
		next2 = next = '<td class="browsenext_off"></td>';

	//# - added for admin operation for User - on 18/06/07 by Jeyaseelan
	var vAddButton = "";
	if(adminview == 1 && isdefined(brecs[bcount][r]) && brecs[bcount][r].type == "U")
	{
		//
		vAddButton = "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td colspan=5><input type=button class=button value='Remove Selected' onclick='removeselecteduser()'></td></tr></table>";
	}
	else if(adminview == 2 && isdefined(brecs[bcount][r]) && brecs[bcount][r].type == "U")
	{
		//
		vAddButton = "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td colspan=5><input type=button class=button value='Add Default Friend' onclick='addselectedusers()'></td></tr></table>";
	}
	else if(adminview == 1 && isdefined(brecs[bcount][r]) && brecs[bcount][r].type == "G")
	{
		//
		vAddButton = "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td colspan=5><input type=button class=button value='Remove Selected' onclick='removeselectedgroups()'></td></tr></table>";
	}
	
	/*
	//#-- Product search optimization
	if($("gender")) //#-- Checking gender object is defined or not ( b'se this only available in product pages)
	{
		ajaxrequest("product_listcount.php", "funprodcount", "", 0); 
		btotrecs[bcount] = getCookie("totalCount");
		delCookie("totalCount");
	}//#--
	*/

	nav =  '<table cellpadding=0 cellspacing=0 border=0><tr>' + prev + '<td class=browsepos>' + sr + ' - ' + se + ' of ' + btotrecs[bcount] + '</td>' + next + '</tr></table>';
	nav2 =  '<table cellpadding=0 cellspacing=0 border=0><tr>' + prev2 + '<td class=browsepos>' + sr + ' - ' + se + ' of ' + btotrecs[bcount] + '</td>' + next2 + '</tr></table>';

	var loadmore = false;
	var loadidx = 0;
	//# - Set for Profile permission
	if(permission == 1)
	{
		out = '<div class=noresult>Sorry, This profile is set as private. So you cannot view this page!</div>';
	}
	else if( btotrecs[bcount] > 0 )
	{
		$('browsenav_'+bcount).innerHTML = nav;
		$('browsenav2_'+bcount).innerHTML = nav2;
		//# - added for a form tags
		var formelment = "";
		if((adminview == 1 || adminview == 2)&& isdefined(brecs[bcount][r]) && (brecs[bcount][r].type == "U" ||brecs[bcount][r].type == "G" ))
			formelment = "<form id=frmBrowse name=frmBrowse method=post>";
		out = formelment+'<table cellspacing="0" cellpadding="0" border="0">';
		var stripmode = vo_currentmode > 0 && vo_enable == 1 && vmode != 0;
		while( l < browselines && r < btotrecs[bcount] )
		{
			out += stripmode ? '<tr style="background: #F2F2F2;">' : '<tr>';
			while( c < browsecols && r < btotrecs[bcount] )
			{
				rec = brecs[bcount][r];
				if( isdefined( rec ) )
				{	
					if( rec.type == 'U' || rec.type == 'G' )
						out += browsershow_friend( rec, bcount, r );
					else if( rec.type == 'P' || rec.tyype == 'M' )
						out += browsershow_product( rec, bcount, r );
					else
						out += displayfunc( rec, bcount, r );
					//# - check for view option enablility
					var vmode = $('viewmode') != null? $('viewmode').selectedIndex : 0;

					if( stripmode )
					{
						c += 1000;
						out += '<td valign=top><div class=browse_ugc id="ugc' + r + '"><h1>' + vo_label[vo_currentmode] + '</h1></td>';
						out += '</tr><tr><td colspan=2><div class=sep></div></td>';
					}
				}
				else
				{
//						c = l = 1000;
					if( !loadmore )
					{
						loadidx = r;
						out += '<td><div class=loading>Loading...<div class=browseimg></div></td>';
						r += 1000; c += 1000; l += 1000;
					}
					else
						out += '<td><div class=browseprod><div class=browseimg></div></td>';
					loadmore = true;
				}
				c++; r++;
			}
			out += '</tr>';
			c = 0;
			l++;
		}
		out += '</table>';
	}
	else
	{
		//#---searchstring come back to mystart search string is sticky catch  on this page
		if(!searchstring && isdefined(varrecover_s( 'bs' ))) searchstring = varrecover_s( 'bs' );
		
		if((trim(searchstring) || trim(errnavsearch)) && errmsg)
		{ 
			if(trim(errnavsearch)) 
			{
				if(trim(searchstring) == "product search")
					var vShowErrMsg = errnavsearch;
				else
					var vShowErrMsg = errnavsearch + " " + searchstring;
			}
			else
			{
				if(trim(searchstring) == "product search")
					var vShowErrMsg = " from this Category";
				else
					var vShowErrMsg = searchstring;
			}
			
			
			//#-- Error message for no result found
			var vDisplayMsg = "";
			//#----
			for (var i = 0; i < vShowErrMsg.length; i++) 
			{
				
				if(vShowErrMsg.charAt(i) == "+")
					vDisplayMsg = vDisplayMsg + " ";
				else
					vDisplayMsg = vDisplayMsg + vShowErrMsg.charAt(i);
				

			}//#-- End For Loop
			
			vDisplayMsg = (vDisplayMsg.length > 20)? "<b>"+ vDisplayMsg.substring(0, 20) + "</b>" + "..." :  "<b>" + trim(vDisplayMsg) + "</b>" + ".";
			out = '<div class=noresult>'+ errmsg + trim(vDisplayMsg) +'</div>';
			
		}
		else
		{
			//# - Added for Tab Explanation - By Jeyaseeelan on 08/06/07
			var browsename = $('browser'+bcount).title;
			if(($('browser'+bcount).first == 1 && browsename == "START EXPLORING" ) || $('browser'+bcount).first == 0)
			{ 
				var textindent = "style='text-indent:20px'";
				if(browsename == "START EXPLORING")
					default_err = MyStartMessage ;
				else if(browsename == "MY FRIENDS")
					default_err = MyFriendsMessage;
				else if(browsename == "MY GROUPS")
					default_err =  GroupsMessage;
				else
					default_err = "No results were found!";
					
				out = '<div class=noresult style="width:450px;align:center;valign:middle;color:#a8a5a5">'+ default_err +'</div>';
			}
			else
			{
				default_err = "No results were found!"
				out = '<div class=noresult >'+ default_err +'</div>';
			}
			
		}
	}
	if( loadmore ) 
	{
		browseqry( $('browser'+bcount), $('browser'+bcount).param, loadidx );
	}
	
	$('browsecanvas'+bcount).innerHTML = vAddButton + out;
	if($('browser'+bcount).title) document.title = "STYLELOGUE: "+$('browser'+bcount).title.toProperCase();
	//set browser height
	maxb = 30;
	max1 = $('browsehead'+bcount).clientHeight + $('browsemenu'+bcount).clientHeight
	max2 = $('browsehead'+bcount).clientHeight + $('browseoptions'+bcount).clientHeight + $('browsecanvas'+bcount).clientHeight + 2*$('browsenav_'+bcount).clientHeight;
	$('browser'+bcount).style.height = maxb + (max1 > max2 ? max1 : max2);

	$('browsemenuband'+bcount).style.height = 50 + (max2 > max1 ? max2 - max1 + 50 : 10);
	//if( !ie )$('browsemenuband'+bcount).style.left = 1;
	//$('browsemenuband'+bcount).style.display = 'none';;


	//# - check for view option enablility
	var vmode = $('viewmode') != null? $('viewmode').selectedIndex : 0;
	if( vo_currentmode > 0 && vo_enable == 1 && vmode != 0)
	{
		function showstrips()
		{
			
			r = brec[bcount];
			l = c = i = 0;
			while( l < browselines && r < btotrecs[bcount] )
			{
				rec = brecs[bcount][r];
				if( isdefined( rec ) )
				{
					var ugc = $('ugc' + r);
					var scr = vo_script[vo_currentmode];
					var jpar = scr.match( /\?/ ) ? '&' : '?';
//					debug(scr + jpar + 'id=' + rec.id);
					ministrip( ugc, scr + jpar + 'id=' + rec.id , 'browse_ugc_click', 1 );
				}
				l++; r++;
			}
		}
		clearTimeout( striptm );
		striptm = setTimeout( showstrips, 100 );
		
	}
	
	//# - set Proper button
	buttonizeall($('browser'+bcount))
}

var striptm = null;
function resultbrowseqry( xml, obj )
{
	
	var frec, lrec, trec, recfunc, i, j;
	var reclist = ntag( xml, 'rec' );
	var bcount = obj.bcount;
	obj = $(obj.id);
//alert('testing'+reclist.length);
	frec = vtag( xml, 'firstrec' )*1;
	lrec = vtag( xml, 'lastrec' )*1;
	trec = vtag( xml, 'totrec' )*1;
	if( frec == 0 && lrec < browseqrysize-1 && trec > browseqrysize )
	{
		errorlog( 'browse', 'wrong parameter ' + frec + ', ' + lrec + ', ' + trec );
		trec = lrec + 1;
	}
	btotrecs[bcount] = trec;
	recfunc = eval( 'browserec_' + $('browser'+bcount).type );
	if( !isdefined( brec[bcount] ) ) brec[bcount] = varrecover( 'idx' );

	for( j = 0, i = frec ; i <= lrec ; i++, j++ )
	{
		var cols = ntag( reclist[j], 'c' );
		recfunc( bcount, i, cols );
	}
	
//	browseshow( obj.bcount, 0 );
	browseshow( obj.bcount, 0 , obj.noresultmessage ); //#-- Modified by Rajendran for no result message 
}

function browseqry( obj, param, start, fromstart )
{
	var script;
	obj.param = param;
	var bcount = obj.bcount;
	var categorysearch = ''; //#-- Added By Rajendran
	var gendersearch = '';
	var searchKey = "";
	//#-- Category search added for dynamic left link selection .. Added By Rajendran
	var vHeadPage = getbasename(window.location);
	vHeadPage = vHeadPage.toString().split("?");
	vHeadPage = vHeadPage[0];

	//#-----------------------------
	//nopopup();
	if( !isdefined( brecs[bcount] ) ) 
	{
		brecs[bcount] = new Array;
	}
	if( !start )
	{
		brecs[bcount] = new Array;
		btotrecs[bcount] = 0;
		brec[bcount] = 0;
	}
	var jpar = obj.script.match( /\?/ ) ? '&' : '?';
	//#--
	var browsefile = getbasename(window.location).toString().split("?")[0];

	//#-- Added By Rajendran for Showing errro Message
	if(browsefile == "products.php")
	{
		errnavsearch = getbasename(obj.script).toString().split("?")[1];
		errnavsearch = errnavsearch.split("&")[1];
		if(isdefined(errnavsearch)) 
			errnavsearch = unescape(errnavsearch.split("=")[1]);
		else
			errnavsearch = "";
	}
	else
		errnavsearch = "";
	//#--
		
	//# - browse search for browse
//	if(searchstring && browsefile == 'product_list.php') //#-- Modfied to search listing all inner search
	{
		
		
		var vEscStr = escape(searchstring);	
		var vQueryString = "";

		//#----
		for (var i = 0; i < vEscStr.length; i++) 
		{
		
			if(vEscStr.charAt(i) == "+")
				vQueryString = vQueryString + "%2B";
			else
				vQueryString = vQueryString + vEscStr.charAt(i);

		}//#-- End For Loop
		
		searchKey = "&searchkey=" + vQueryString;
		
		
	}

	if(vHeadPage == "products.php")  //#-- Changed by Rajendran
	{

		if(isdefined(varrecover_s( 'bs' )))
			searchKey = '&searchkey=' + escape(varrecover_s( 'bs' ));
		else
			searchKey = '&searchkey=';
		categorysearch = '&category=' + ((varrecover_s( 'bc' ) != 9999999999)?varrecover_s( 'bc' ):"");//(document.getElementById('category').value?varrecover_s( 'bc' ):"")
		if(varrecover_s( 'bg' ) == 'ALL')
			gendersearch = '&gender=&genderflag=1';
		else if(varrecover_s( 'bg' ))
			gendersearch = '&gender=' + ((varrecover_s( 'bg' ) != 9999999999)?varrecover_s( 'bg' ):"");
		else
			gendersearch = '&gender=' + UserGender;
		//alert(categorysearch+":"+gendersearch);
	}
	if(isdefined( varrecover_s( 'bs' )) != '' && searchKey == '&searchkey=' )
		searchKey = '&searchkey=' + escape(varrecover_s( 'bs' ));
	
	if( fromstart )
		script = obj.script + jpar + 'startrec=0&maxrec=' + (start+browseqrysize) + '&' + obj.param + searchKey + categorysearch+ ((obj.param.indexOf("gender=") == -1)?gendersearch:"");
	else
		script = obj.script + jpar + 'startrec=' + start + '&maxrec=' + (browseqrysize) + '&' + obj.param + searchKey + categorysearch+ ((obj.param.indexOf("gender=") == -1)?gendersearch:"");
	if(param.indexOf("sortname=") == -1)
	{
		script += "&sortname="+(varrecover_s('sortname')?varrecover_s('sortname'):"")+"&sortby="+(varrecover_s('sortby')?varrecover_s('sortby'):"");
	}	
	//alert(script)
	//#-- No Result Found Message Assigned to an Object
	$('browsecanvas'+bcount).noresultmessage = obj.noresultmessage;
	obj.noresultmessage = '';
	//#----------------

//	$('browseoptions'+bcount).innerHTML = 'http://10.10.10.233/stylelog/' + script;
	$('browsenav_'+bcount).innerHTML = '';
	$('browsenav2_'+bcount).innerHTML = '';
	if( !start ) $('browsecanvas'+bcount).innerHTML = '<div class=loading>Loading...</div>';
	$('browsecanvas'+bcount).bcount = bcount;

	var loc = document.location + '';
	if( loc.indexOf( 'detail_more' ) != -1 ) browsehidemenu(bcount);

	//ajaxrequest( script + '&rnd=' + Math.random(), 'resultbrowseqry', $('browsecanvas'+bcount), 1 );
	//# - added for tagcloud implementation - By Jeyaseelan
	//Modified by kamal to show admin product Brand report on 04-09-07	
	if(script.indexOf("tagcloud.php") != -1 || (script.indexOf("admin_report.php") != -1 && (searchf == 'prodbrand' || searchf == 'prodretailer'  || searchf == 'cpcretailer'  || searchf == 'cpcbrand' || searchf == 'producturl')))
	{ 
		if(adminview == 1 && script.indexOf("admin_report.php") == -1)
			browsehidemenu(bcount);

		//# - Set based on the permission  - Added by Jeyaseelan on 12/05/07
		if(permission == 1)
		{
			$('browsecanvas'+bcount).innerHTML  = '<div class=noresult>'+cpermission+'</div>';
			
		}
		else
		{	
			if(!errmsg)	errmsg = $('browsecanvas'+bcount).noresultmessage;
			//ajaxrequest( script + '&rnd=' + Math.random(), 'resulttagclouqry', $('browsecanvas'+bcount), 1 );
			
			//# - added for Browsing tagcloud 
			browseajax( script + '&rnd=' + Math.random(), 'resulttagbrowse', $('browsecanvas'+bcount), 1 );
		}
	}
	else if(script.indexOf("help_content.php") != -1)//# - added for help implementation - By Jeyaseelan on  01/03/07
		browseajax( script + '&rnd=' + Math.random(), 'resulthelp', $('browsecanvas'+bcount), 0 );
	else if((script.indexOf("admin_report.php") != -1 && obj.param.indexOf('med') == -1) || searchf == 'newuserinvite' )
	{ 
		//# - Admin reports
		if(obj.param.indexOf('brand') != -1 || obj.param.indexOf('retailer') != -1 || obj.param.indexOf('med') != -1)
		{
			browseajax( script + '&rnd=' + Math.random(), 'resultbrowseqry', $('browsecanvas'+bcount), 1 );
		}
		else
		{
			if(searchf == 'newuserinvite')
				browseajax( 'addressbook_import.php?pagecount='+ bcount +'&rnd=' + Math.random(), 'resultreports', $('browsecanvas'+bcount), 0 );
			else
				browseajax( script + '&rnd=' + Math.random(), 'resultreports', $('browsecanvas'+bcount), 0 );
		}
	}
	else
	{
		if(script.indexOf("detailprod_list.php") != -1)
			browsehidemenu(bcount);
		browseajax( script , 'resultbrowseqry', $('browsecanvas'+bcount), 1 );
	}
	
//	debug( script );
}
function resultreports(txt,obj)
{
	//# - for admin reports
	obj.innerHTML = txt?txt:"No Contents to be displayed!";
	buttonizeall( document.body );
}
function resulttagclouqry( xml, obj )
{
	var i, outtxt = "";
	var name, url, list;
	var max, min;

	obj = $(obj.id);
	//outtxt = "<table cellpadding=0 cellspacing=0 border=0> <tr><td align=right colspan=2 class=browsepos>"+list.length+" tags</td></tr><tr><td width=\"2\"></td><td>";//<p style=align:justify>
	list = ntag( xml, 'tag' )
	if( list == null || list.length == 0 )
	{ 
		if(trim(searchstring))
		{ 
			//obj.innerHTML ='<div class=noresult>' + obj.noresultmessage + '</div>';
			var vDisplayMsg = (searchstring.length > 20)? "<b>"+ searchstring.substring(0, 20) + "</b>" + "..." :  "<b>" + trim(searchstring) + "</b>" + ".";
			obj.innerHTML = '<div class=noresult>' + errmsg + vDisplayMsg + '</div>';
			return;
		}
		else
		{
			//# - Added for Tab Explanation - By Jeyaseeelan on 08/06/07
			var browsename = $('browser0').title;
			var textindent = "style='text-indent:20px'";
			
			if($('browser0').first == 0)
			{ 				
				if(browsename == "MY TAGS")
					errmsg = MyTagsMessage;
				else
					errmsg = "No Tags were found!";
				out = '<div class=noresult style="width:450px;color:#a8a5a5;">'+ errmsg +'</div>';	
			}
			else
			{
				errmsg = "No Tags were found!"
				out = '<div >'+ errmsg +'</div>';
			}
			
			obj.innerHTML = out;//'<div class=noresult>No tags were found!</div>';
			return;
		}
	}
	if( list.length > 0 )
		outtxt += "<table cellpadding=0 cellspacing=0 border=0 width=99%> <tr><td align=right class=browsepos>"+list.length+" tags found!</td></tr><tr><td></td></tr></table>";
	outtxt += "<table cellpadding=0 cellspacing=0 border=0 > ";
	outtxt += "<tr><td width=\"1\"></td><td>";//<p style=align:justify>
	
	max = 0, min = 9999999999;
	for( i = 0 ; i < list.length ; i++ )
	{
		count = vtag( list[i], 'count' ) * 1;
		if( count > max ) max = count;
		if( count < min ) min = count;
	}
	for( i = 0 ; i < list.length ; i++ )
	{
		name = vtag( list[i], 'name' );
		count = vtag( list[i], 'count' )*1;
		count = Math.floor(7*(count-min)/max)+1;
		url = vtag( list[i], 'url' );// + obj.script
		//# - replace for < and > 
		name = name.replace("<","&lt;");
		name = name.replace(">","&gt;");
		//# - add wordwrap - by jeyaseelan on 05/06/07
		name = name.wordWrap(36 , "<br/>" , true);
		//outtxt += '<a href="' + url + '" class="tagr' + count + '"><nobr>' + name + '</nobr></a> ';
		//# - Set cookie for getting back - commented above and added by Jeyaseelan on 14/05/07
		var setcook = "filename_set_cookie('" + url + "', 'backtagfile')";
		outtxt += '<a href="#" class="tagr' + count + '" onclick="' + setcook + '"><nobr>' + name + '</nobr></a> ';
	}
	outtxt += '</td></tr></table>';
	obj.innerHTML = outtxt;
}
function resulthelp(text,obj)
{
	//# - result
	//alert(obj.style.height )
	obj.style.overflow="scroll"
	obj.style.position="relative"
	obj.style.height=750
	obj.innerHTML = text;
}
var brecs = new Array, btotrecs = new Array, brec = new Array;

//refreshes the main browser
function browserefresh()
{
	var bcount = 0;
	nopopup();
	browseajax( $('browser'+bcount).url + rpar(), 'resultbrowse', $('browser'+bcount), 1 );
}

var vo_name = [];
var vo_script = [];
var vo_detailscript = [];
var vo_label = [];
var vo_currentmode = 0;
//# - Global set for view options enability- added by Jeyaseelan on 19/04/07
var vo_enable = 0;

function browseviewmode( bcount, idx )
{
	vo_currentmode = idx;
	varsave( 'currentmode', idx );
//	debug( vo_name[idx], vo_script[idx], vo_label[idx] );
	browseshow( bcount, 0 );
}

function openscrapbook( lid )
{
	if( arguments.length == 2 ) var gid = arguments[1];
	
	var bcount = 0;
	$('browsecanvas'+bcount).innerHTML = '';
	$('browsenav_'+bcount).innerHTML = '';
	$('browsenav2_'+bcount).innerHTML = '';
	//#-- Added by Rajendhran
	$('browsecanvas'+bcount).groupid = gid;
	
	sbook( lid, $('browsecanvas'+bcount) );
}

var globalEvent = null;

function browsemenusel( o, obj, opt, idx, ev )
{

	var i, script, i, j;
	if( isdefined( ev ) ) globalEvent = ev;
	o = o.childNodes[0];
	obj = $(obj);
	obj.first = idx;
	varsave( 'first', idx );
	//# - added for search - added by jeyaseelan
	searchf = opt.split("=")[1];
	errmsg = arguments[5];
	//# - This changes only for admin reports- by jeyaseelan	
	if(document.getElementById('txtFromDate'))
		document.getElementById('txtFromDate').value = "";
	if(document.getElementById('txtFromDate'))
		document.getElementById('txtToDate').value = "";
	
	var bm = o.parentNode.parentNode;
	
	for( i = 0 ; i < bm.childNodes.length ; i++ )
	{
		if( bm.childNodes[i].className == 'browseoptsel')
			bm.childNodes[i].className = 'browseopt';
	}
	o.parentNode.className = 'browseoptsel';
	o.parentNode.sel = 1;
	o.href = 'javascript:v()';
	o.blur();
	
	//#-- No Result Fount - Added by Rajendran
	if(arguments[5]) obj.noresultmessage = arguments[5];
	//#-----------------
	
	var bcount = bm.parentNode.bcount;

	var desc = '';
	var vopt = '';
	var bopt = '';
	var viewoptions = [];
	var buttonoptions = [];

	//# - check for view options - added by Jeyaseelan on 19/04/07
	vo_enable = 0;
	
	if( isdefined( o.parentNode.description ) )	desc = o.parentNode.description;
	if( isdefined( o.parentNode.viewoptions ) ) viewoptions = o.parentNode.viewoptions;
	if( isdefined( o.parentNode.buttonoptions ) ) buttonoptions = o.parentNode.buttonoptions;
	
	//# - check for viewing permission - added by Jeyaseelan on 14/05/07
	if( viewoptions.length && permission != 1)
	{
		vo_name = [];
		vo_script = [];
		vo_detailscript = [];
		vo_label = [];
		vo_currentmode = varrecover( 'currentmode' );
		vopts = ntag( viewoptions[0], "vopt" );
		//# - set for view options - added by Jeyaseelan on 19/04/07
		vo_enable = 1;
		
		vopt = '<div class=optview>View Options:<br><select id=viewmode name=viewmode onchange="browseviewmode( ' + bcount + ', this.selectedIndex )" width="200">';
		for( var i = 0 ; i < vopts.length ; i++ )
		{
			vo_name.push( vtag( vopts[i], 'name' ) );
			vo_script.push( vtag( vopts[i], 'searchscript' ) );
			vo_detailscript.push( vtag( vopts[i], 'detailscript' ) );
			vo_label.push( vtag( vopts[i], 'label' ) );
			var vsel = vo_currentmode == i ? ' selected' : '';
			vopt += '<option value="' + vtag( vopts[i], 'script' ) + '"' + vsel + '>' + vtag( vopts[i], 'name' ) + '</option>';
		}
		vopt += '</select></div>';
		//alert(vopt);
	}
	if( buttonoptions.length )
	{
		bopts = ntag( buttonoptions[0], "bopt" );
		bopt = '<div class=optview align=right>'
		for( var i = 0 ; i < bopts.length ; i++ )
		{
			bopt += '<input type=button value="' + vtag( bopts[i], 'name' ) + '" onclick="' + vtag( bopts[i], 'param' ) + '">';
		}
		bopt += '</div>';
	}
	
	if( $('browseoptions' + bcount) != null )
	$('browseoptions' + bcount).style.width=650;
	var sopt = '<div class=opt id="boptions' + bcount + '"><div class=optdescription>' + desc + '</div>' + vopt + bopt +'</div>' ;
	if( desc == '' && vopt == '' ) sopt = '&nbsp;';
	$('browseoptions' + bcount).style.display = 'block';
	$('browseoptions' + bcount).innerHTML = sopt;
//	debug( '<textarea style="width: 300px; height: 300px;">' + sopt + '</textarea>' );
	//# - Assign defalt selected index 0 for UGC in mystart page - added by Jeyaseelan
//	if(getbasename(window.location) == "mystart.php" && $('viewmode') != null )
//		$('viewmode').selectedIndex = 0;
	minh = 45;
	if( sopt != '&nbsp;' && $('boptions' + bcount).clientHeight < minh ) $('boptions' + bcount).style.height = minh;
	$('browser'+bcount).param = opt;
	buttonizeall( $('browseoptions' + bcount) );
	if( o.parentNode.command != '' )
	{
		eval( o.parentNode.command );
		return;
	}
	
	//# - Hide search for reports menu
	if($('search'+ bcount))
	{
		$('search'+ bcount).style.display = "block";
		if(obj.script.indexOf("admin_report.php") != -1 || (obj.script.indexOf("searchproduct.php") != -1 && obj.param.indexOf('newuserinvite') != -1))
		{
			//# - Showing From and To dates to apply in time frames
		 	if(obj.param.indexOf('prodbrand') != -1 || obj.param.indexOf('prodretailer') != -1 || obj.param.indexOf('message') != -1 || obj.param.indexOf('activegroups') != -1 || obj.param.indexOf("userlist") != -1 || obj.param.indexOf("newsletterlist") != -1 || obj.param.indexOf("notifymaillist") != -1 || obj.param.indexOf('cpcbrand') != -1 || obj.param.indexOf('cpcretailer') != -1 || obj.param.indexOf('med') != -1 || obj.param.indexOf('producturl') != -1)
			{
				
				$('browsehead'+ bcount).innerHTML = gettimeframes(obj.title,bcount,1)
				
			}
			else if(obj.param.indexOf('userprod') != -1 || obj.param.indexOf('newproducts') != -1)
			{
				
				$('browsehead'+ bcount).innerHTML = gettimeframes(obj.title,bcount,0)
			}
			else
			{
				$('search'+ bcount).style.display = "none";
			}
		}
		else
		{
			//#-- Changed by Rajendran for display the searched text in search box
			if(trim(searchstring)) 
				$('search'+ bcount).innerHTML =  searchproductdetail('browsesearch', document.location, searchstring);
			else
				$('search'+ bcount).innerHTML =  searchproductdetail('browsesearch');
		}
		buttonizeall($('browsehead'+ bcount));
		buttonizeall($('search'+ bcount));
	}
	//#-------------
	if( recovermode )
		browseqry( obj, opt, varrecover( 'idx' ), true );
	else
		browseqry( obj, opt, 0 );
	recovermode = false;
}
function gettimeframes(title,bcount,type)
{
	var displayfunc1 = "PopupCalendar(1)";
	var displayfunc2 = "PopupCalendar(2)";
	var otop = ie ? -1 : 0;
	disp = "visible";
	if(type == 0)
			disp = "hidden";
	return '<table border=0 cellpadding=0 cellspacing=0 width=100% align=right><tr><td width="10%" style="font-family: Arial;font-size: 20px;ffont-weight: normal;color: #B9181E;" valign="middle"><strong>' + title + '</strong></td><td id="search' + bcount + '" valign="middle" height=40 align=right><form name="frmDate" style="position: relative" onsubmit="return browsemessage(this)"><table cellpadding=0 cellspacing=0 border=0 height=27 width=90%><tr><td valign=middle width="10%" style="visibility:'+disp+'">From:&nbsp;</td><td valign=middle width="10%" style="visibility:'+disp+'"><input type="text" name="txtFromDate" id="txtFromDate" value="" maxlength="10" readonly=""></td><td valign=middle width="10%" style="visibility:'+disp+'"><img src="../images/icon_cal.gif" border="0" onClick="'+displayfunc1+'" ></td><td valign=middle width="8%">To:</td><td valign=middle width="10%"><input type="text" name="txtToDate" id="txtToDate" value="" maxlength="10" readonly=""></td><td width="8%"><img src="../images/icon_cal.gif" border="0" onClick="'+displayfunc2+'" ></td><td valign=middle width="15%"><input style="width: 100px;" type="Submit" value="GO" onclick="return datevalidate(this);" ></td></tr></table></form></td></tr></table>' ;
}
function browsesearch( o )
{
	var sval = o.search.value;
	o.search.value = trim(sval); //#--
	var category = o.category;
	var gender = o.gender;
	searchstring = sval;
	var hasdetail = isdefined(category);

	
	if( (sval == 'search' || sval == 'group search' || sval == 'user search') && !hasdetail )
	{
		o.search.focus();
	}
	else
	{
		varsave( 'bs', sval );
		//get browser instance
		while( !isdefined( o.bcount ) )
		{
			o = o.parentNode;
		}

		var querystring = '';

		if( hasdetail )
		{
			querystring += 'category=' + category.options[category.selectedIndex].value + '&';
			querystring += 'gender=' + gender.options[gender.selectedIndex].value + '&';
		}
		
		var categorysearch = "";
		var gendersearch = "";
		//#-- Checking for category search
		var vHeadPage = getbasename(window.location);
		vHeadPage = vHeadPage.toString().split("?");
		vHeadPage = vHeadPage[0];

//				if(vHeadPage == "products.php" || vHeadPage == "mystart.php")	
		if(vHeadPage == "products.php")
		{
			var categorysearch = '&category=' + category.options[category.selectedIndex].value;
			var gendersearch = '&gender=' + gender.options[gender.selectedIndex].value;
			varsave( 'bc', category.options[category.selectedIndex].value );
			varsave( 'bg', gender.options[gender.selectedIndex].value );
		}

		//# - validate the value with special chars
		if( sval )
		{
		
			//#-- Split the string by space
			var vCheck = SpiltString(sval);
			//var vCheckPattern = "/[a-z]/";
			//var vRegExp = new RegExp(vCheckPattern);
			/*if(sval.search(/[a-zA-Z]/i) == -1)
			{
				alert("Each search word must contains alphapetic!!!");
				searchstring = "";
			}
			else */
			if(vCheck && sval.length >= 2)
			{
			
				//# - added query string for search based on left menu - By Jeyaseelan
				querystring += "search="+searchf+"&searchkey=" + escape(sval) + categorysearch + gendersearch;

				//browseqry( o, 'search=' + sval, 0 );
				browseqry( o, querystring, 0 );
			}
			else
			{
				alert("Each search word should be atleast 2 characters!!!");
				searchstring = "";
				
			}
		}
		else
		{
			browseqry( o, "search="+searchf, 0 );
		}
	
		//#-- Condition Added By Rajendran
		/*
		if(stripslash(sval))
		{	
			//get browser instance
			while( !isdefined( o.bcount ) )
			{
				o = o.parentNode;
			}
			//# - validate the value with special chars
			if(stripslash(sval))
			{
				//# - added query string for search based on left menu - By Jeyaseelan
				querystring = "search="+searchf+"&searchkey="+sval
				//browseqry( o, 'search=' + sval, 0 );
				browseqry( o, querystring, 0 );
			}
			else
				alert("Please enter valid search value!!");
			
		}
		else
			alert("Please enter valid search value!!");
		*/

	}
	return false;
}

function browsemessage( o )
{
	var fromdate = o.txtFromDate.value;
	var todate = o.txtToDate.value;
	
	//alert(fromdate);
	//get browser instance
	while( !isdefined( o.bcount ) )
	{
		o = o.parentNode;
	}
	//# - added query string for search based on left menu - By Jeyaseelan
	var querystring = "search="+searchf+"&fromdate=" + fromdate+"&todate=" + todate;
	browseqry( o, querystring, 0);
		
	return false;
}
function resultbrowse( xml, obj )
{

	var lmenu, i, j, out = '', first = obj.first;
	var url = obj.url;
	var bcount = obj.bcount;
	var script = obj.script;
	var detailscript = obj.detailscript;


	
	obj = $(obj.id);
	obj.bcount = bcount;
	obj.script = script;
	obj.url = url;
	obj.detailscript = detailscript;
	
	obj.title = vtag( xml, 'title' )
	obj.stylecreateddate = vtag( xml, 'stylecreateddate' )
	obj.listdescription = vtag( xml, 'listdescription' )
	obj.type = vtag( xml, 'type' )
	
//	obj.script = vtag( xml, 'script' );
//	obj.param = '';
	var vSelFirst = "";
	if(!vSelFirst)
	 vSelFirst = first;

	var parr = new Array();

	searchscript = vtag( xml, 'searchformat' );
//	if( searchscript == '' ) searchscript = 'searchfield';
	if( searchscript == '' ) searchscript = 'searchproductdetail'; //#-- for category search

	var search = eval( searchscript + "( 'browsesearch' )" );

	var button = '';
	var buttons = ntag( xml, 'button' );
	var rssbutton = ntag( xml, 'rssbutton' );
	//# - get Display page
	var displaypage = getbasename(script).toString().split("?")[0];
	
	if( buttons.length )
	{
		//# - Looping for creating button added by Jeyaseelan to use more buttons on the header
		var butt = '',rssbutt='';
		
		for(var i=0;i<buttons.length;i++)
		{
			var bname = vtag( buttons[i], 'name' );
			var bparam = vtag( buttons[i], 'param' );

			//# - added below by jeyaseelan  on 24/04/07 - for mystuff
			if(displaypage == "mystuff_details.php" || displaypage == "groupstuff_details.php" || displaypage == "detailprod_list.php")
				butt += '<td><input class=button type=button value="' + bname + '" onclick="'+ bparam + '" title="'+bname+'"></td>';// + addproduct;
			else
				butt += '<input type=button value="' + bname + '" onclick="'+ bparam + '" title="'+bname+'">';// + addproduct;
		}
		//#-- Add by jeyaseelan		
		if(rssbutton.length > 0 )
		{
			var rname = vtag( rssbutton[0], 'name' );
			var rparam = vtag( rssbutton[0], 'param' );
			//# - added below by jeyaseelan  on 24/04/07 - for mystuff
			if(displaypage == "mystuff_details.php" || displaypage == "groupstuff_details.php" || displaypage == "detailprod_list.php")
				rssbutt = '<a href="'+ rparam + '" title="'+ rname + '" target=_blank><img src="../images/rss.gif" border=0></a>';// + addproduct;
			
		}
		//#-- End
		if(displaypage == "mystuff_details.php" || displaypage == "groupstuff_details.php" || displaypage == "detailprod_list.php" )
			button = '<table><tr>' + butt +'</tr></table>';
		else
			button = '<div class=button>' + butt +'</div>';
	}
	
	
	var desc = obj.listdescription != '' ? '<h2>' + obj.listdescription + '</h2>' : '';
	var styletitle =  obj.title.wordWrapSpace(30 , "<br/>" , true) + "<br/>" + obj.stylecreateddate;
	var stydesc = desc ;
	desc = desc.wordWrapSpace(35 , "<br/>" , true);
	if(!isdefined(rssbutt)) rssbutt = '';
	var title = '<table cellpadding=0 cellspacing=0 border=0 width=98%><tr><td><table width=98%><tr><td style="font-weight: bold;font-size: 14px;margin: 0px;color: #B9181E;" width="94%" title="">'+ styletitle + '</td><td align=right width=4%>' + rssbutt +'</td></tr></table></td></tr><tr><td><table width=100%><tr><td width=45% title="'+obj.listdescription +'">'+desc+'</td><td align=right>'+button+'</td></tr></table></td></tr></table>';
	//# - REMOVE SEARCH OPTION FOR MYSTUFF - JEYASEELAN ON 23/04/07
	if(displaypage == "mystuff_details.php" || displaypage == "groupstuff_details.php" || displaypage == "detailprod_list.php"  )
		out = '<div class="browsehead2" id="browsehead' + bcount + '"><a name="topnav"></a>' + title + '</div><div class="browsemenu" id="browsemenu' + bcount + '">';
	else
		out = '<div class="browsehead2" id="browsehead' + bcount + '"><a name="topnav"></a><h1>' + obj.title + '&nbsp;</h1>' + desc + button + '<div id="search' + bcount + '" class=search>' + search + '</div></div><div class="browsemenu" id="browsemenu' + bcount + '">';
		
	lmenu = ntag( xml, 'option' );
	var descriptions = new Array;
	var vopts = new Array;
	var bopts = new Array;
	var locations = new Array;
	var menutxt = '<br>';
	var firstavailable = 99999;
	var selected = -1;
	//# - set for Media viewing permission - added by Jeyaseelan
	//var permissionmed = 0;

	for( i = 0 ; i < lmenu.length ; i++ )
	{
		var oname = vtag( lmenu[i], 'name' );
		var opar = vtag( lmenu[i], 'param' );
		var desc = vtag( lmenu[i], 'description' );
		var rollmsg = vtag( lmenu[i], 'rollovermsg' );
		var command = vtag( lmenu[i], 'command' );
		var selitems = vtag( lmenu[i], 'selected' );
		errmsg =  vtag( lmenu[i], 'noresultmessage' );
		
		//#-- No Result Found Message - Added By Rajendran
		obj.noresultmessage = vtag( lmenu[i], 'noresultmessage' );
		//#--

		//# - set for Media viewing permission - added by Jeyaseelan
		//if(!permissionmed)
		//	var permissionmed = vtag( lmenu[i], 'permission' );
		var viewoptions = ntag( lmenu[i], 'viewoptions' );
		var buttonoptions = ntag( lmenu[i], 'buttonoptions' );
		//# - search from search field - added by jeyaseelan
		
		if( lmenu[i].attributes.length && lmenu[i].attributes[0].value == 'label' )
		{

			menutxt += '<div class="browselabel" id="brmo' + bcount + '_' + i + '">' + oname + '</div>';
		}
		else if( lmenu[i].attributes.length && lmenu[i].attributes[0].value == 'button' )
		{
			menutxt += '<div align=left>&nbsp;&nbsp;<input type="button" value="' + oname + '" onclick="' + opar + '"></div>';
		}
		else
		{
			var classname = 'browseopt';
			if( i < firstavailable ) firstavailable = i;
			if( i == first || (first == 9999 && i < first) )
			{
				first = i;
				classname = 'browseoptsel';
			}
			parr[i] = opar;
			//# - initiate default search
			if(parr[0])
				searchf = parr[0].split("=")[1];
			if( classname == 'browseoptsel' ) selected = i;

			//var titletext = rollmsg;//desc.substring(desc.indexOf('<b>')+3,desc.indexOf('</b>'));
			//titletext = titletext.replace('<strong>','');
			//titletext = titletext.replace('</strong>','');
			var over = ' onmouseover="browsemenuover(this,\'browseoptover\')" onmouseout="browsemenuover(this,\'browseopt\')"';
			menutxt +='<div class="' + classname + '" id="brmo' + bcount + '_' + i + '" title="' + rollmsg + '" ><a href="#" id="bm' + i + '" onclick="browsemenusel( this.parentNode, \'' + obj.id + '\', \'' + opar + '\', ' + i + ', event, \'' + errmsg + '\' )" ' + over + '>' + oname + '</a></div>';
		}
		if( desc != '' ) descriptions[i] = desc;
		vopts[i] = viewoptions;
		bopts[i] = buttonoptions;
		locations[i] = command;
	}
	out += menutxt + '</div><div class="browseoptions" id="browseoptions' + bcount + '"></div><div class="browsenav" id="browsenav_' + bcount + '"></div><div class="browsecanvas" id="browsecanvas' + bcount + '"></div><div class="browsenav" id="browsenav2_' + bcount + '"></div><div class=browsemenuband id="browsemenuband' + bcount + '"></div>';
	//# - set into the object for Media viewing permission - added by Jeyaseelan
	//obj.permission = permissionmed; 
	var refreshing = obj.innerHTML != '';
	if( !refreshing ) 
	{
		obj.innerHTML = out;
	}
	else
		$('browsemenu'+bcount).innerHTML = menutxt;
	obj.parr = parr;

	for( i = 0 ; i < descriptions.length ; i++ )
	{
		if( isdefined(descriptions[i]) )
			$('brmo' + bcount + '_' + i).description = descriptions[i];
	}
	for( i = 0 ; i < vopts.length ; i++ )
	{
		if( $('brmo' + bcount + '_' + i) != null )
		{
			$('brmo' + bcount + '_' + i).viewoptions = vopts[i];
			$('brmo' + bcount + '_' + i).buttonoptions = bopts[i];
			$('brmo' + bcount + '_' + i).command = locations[i];
		}
	}
	buttonizeall( obj.parentNode );
	//# - REMOVE SEARCH OPTION FOR MYSTUFF - JEYASEELAN ON 23/04/07
	if(displaypage != "mystuff_details.php" && displaypage != "groupstuff_details.php" && displaypage != "detailprod_list.php")
	{
		var sdiv = $('search'+bcount);
		var stab = sdiv.getElementsByTagName("TABLE")[0];
		sdiv.style.width = stab.clientWidth;
//		sdiv.style.right = ie ? 0 : 10;
		if( ie ) rebuttonizeall( sdiv );
	}
	var idx = varrecover( 'idx' );

	if( !refreshing && !idx )
	{
		obj.param = '';
		if( $('bm'+first) != null ) $('bm'+first).onclick();
	}
	else if ( selected == -1 && !idx )
	{
		if( $('bm'+firstavailable) != null ) $('bm'+firstavailable).onclick();
	}
	else
	{
		delete brecs[bcount];
		recovermode = true;
		$('bm'+first).onclick()
		//browseqry($('browser'+bcount), $('browser'+bcount).param, idx, true);
	}
//	browseqry( obj, parr[first], 0 );
//	buttonizeall( obj );
}
function browsemenuover( o, c )
{
	o = o.parentNode;
	if( o.className != 'browseoptsel' ) o.className = c;
}
var recovermode = false;

function browser( url, script, detailscript )
{
	var id = 'browser' + browserct;
	browseqrysize = 100;
	browsecols = 5;
	browselines = 5;
	browsepag = browsecols*browselines;
	document.write( '<div id="' + id + '" class="browser"></div>' );
	var bcount = browserct;
	mainbrowserct = bcount;
	$(id).bcount = browserct;
	$(id).script = script;
	$(id).detailscript = detailscript;
	$(id).url = url;
	$(id).first = varrecover( 'first' );
	if( $(id).first == '' ) $(id).first = 9999;
//	ajaxrequest( url + '?5', 'resultbrowse', $('browser'), 1 );
	//Added by kamalakannan on 14-09-07 for viewoption set in mystart page
	if(varbase() == 'mystart.php') {
		var optselect = varrecover('currentmode');
		varsave( 'currentmode', optselect);
	}
	function bjax()
	{
		browseajax( url + rpar(), 'resultbrowse', $(id), 1 );
	}
	setTimeout( bjax, 1 );
	browserct++;
}
function browsetagresource(script,detailscript)
{
	id = 'tagcloudmain' + browserct;
	bcount = browserct++;
	if( $(id) == null )
	{
		document.write( '<div id="' + id + '" class="browser"></div>' );
	}
	formdiv = $(id);
	formdiv.bcount = bcount;
	formdiv.script = script;
	//out = '<div class="browsehead" id="tcloudhead' + bcount + '"><h1>' + title + '</h1></div><div class="browsemenu" id="tcloudmenu' + bcount + '"><br>';
	out = '</div><div class="browsecanvas" id="tcloudcanvas' + bcount + '"><div class=loading>Loading...</div></div>';
	formdiv.innerHTML = out;
	canvas = $('tcloudcanvas'+bcount);
	canvas.bcount = bcount;
	canvas.onchange = function() { formresize( this ); };
	canvas.style.marginRight = 10;
	canvas.style.marginLeft = 10;
	//alert('test');
//	window.open( script + rpar() );
	browseajax( script + rpar(), 'resulttagbrowse', canvas, 1);
}
//var sortname = "", sortby = "";
function resulttagbrowse( xml, obj )
{
	
	var frec, lrec, trec, recfunc, i, j;
	var reclist = ntag( xml, 'rec' );
	var bcount = obj.bcount;
	obj = $(obj.id);
	frec = vtag( xml, 'firstrec' );
	lrec = vtag( xml, 'lastrec' );
	trec = vtag( xml, 'totrec' );
	//sortname = vtag( xml, 'sortname' );
	//sortby   = vtag( xml, 'sortby' );
	varsave( 'sortname',  vtag( xml, 'sortname' ) );
	varsave( 'sortby',  vtag( xml, 'sortby' ) );
	btotrecs[bcount] = trec;

	recfunc = eval( 'browserec_product');
	for( j = 0, i = frec ; i <= lrec ; i++, j++ )
	{
		var cols = ntag( reclist[j], 'c' );
		recfunc( bcount, i, cols );
	}

	browsetagshow( obj.bcount, 0, obj ); //#-- Modified by Rajendran for no result message 
}
function browsetagshow( bcount, off , obj )
{
	var l, c, i, out = '', rec, max1, max2, nav;
	var sr, er;

	//nopopup();
	l = c = i = 0;
	brec[bcount] += off;
	r = brec[bcount];

	displayfunc = eval( 'browsershow_product' );
	
	//navigator
	sr = r + 1;
	//Modified by kamal to show admin product Brand report on 04-09-07
	if((getbasename(document.location) == 'reports.php' || getbasename(document.location) == 'reports.php#' || getbasename(document.location) == 'reports.php#topnav') && (searchf == 'prodbrand' || searchf == 'prodretailer' || searchf == 'cpcretailer'  || searchf == 'cpcbrand' || searchf == 'producturl')) //#-- Modified by rajendran for report 
	{ 
		se = r + browseprodreport;
		var vPagingVar = browseprodreport;
	}
	else
	{
		se = r + browsetagpag;
		var vPagingVar = browsetagpag;		
	}
	if( se > btotrecs[bcount] ) se = btotrecs[bcount];

	if( sr > 1 )
		prev = '<td class="browseprev" onmousedown="browsetagshow(' + bcount + ', -' + vPagingVar + ')"></td>';
	else
		prev = '<td class="browseprev_off"></td>';

	if( se < btotrecs[bcount] )
		next = '<td class="browsenext" onmousedown="browsetagshow(' + bcount + ', ' + vPagingVar + ')"></td>';
	else
		next = '<td class="browsenext_off"></td>';
	
	nav = '<table cellpadding=0 cellspacing=0 border=0><tr>' + prev + '<td class=browsepos>' + sr + ' - ' + se + ' of ' + btotrecs[bcount] + '</td>' + next + '</tr></table>';
	//# - Set based on the permission  - Added by Jeyaseelan on 12/05/07
	if( permission == 1)
	{
		out = '<div class=noresult>'+cpermission+'</div>';
	}
	else if( btotrecs[bcount] > 0 )
	{
		$('browsenav_'+bcount).innerHTML = nav;
		$('browsenav2_'+bcount).innerHTML = nav;
		rec = brecs[bcount][r];
		if( isdefined(rec) )
		{
					out += browsershow_tag( rec, bcount, r ,btotrecs[bcount],sr,se);
		}
		else
		{
			browseqry( $('browser'+bcount), $('browser'+bcount).param, r );
			out += '<td class=browseprod><div class=loading>Loading more...</div></td>';
			//out += '<td class=browseprod>loading more...</td>';
		
		}
		
	}
	else
	{
	
		//#-- Error message for no result found
		var vDisplayMsg = "";
		//#---searchstring come back to mytags search string is sticky catch  on this page
		if(!searchstring && isdefined(varrecover_s( 'bs' ))) searchstring = varrecover_s( 'bs' );
		
		if(searchstring.length > 0)
		{
			//#----
			for (var i = 0; i < searchstring.length; i++) 
			{
				if(searchstring.charAt(i) == "+")
					vDisplayMsg = vDisplayMsg + " ";
				else
					vDisplayMsg = vDisplayMsg + searchstring.charAt(i);
	
			}//#-- End For Loop
			
			vDisplayMsg = (vDisplayMsg.length > 20)? "<b>"+ vDisplayMsg.substring(0, 20) + "</b>" + "..." :  "<b>" + trim(vDisplayMsg) + "</b>" + ".";
			if(getbasename(document.location) == 'reports.php') vDisplayMsg = '';
			if(searchf == 'cpcretailer' || searchf == 'prodretailer' || searchf == 'cpcbrand' || searchf == 'prodbrand' || searchf == 'producturl')
			{
					//# - Enable the search box
					cpcsearchbutt = getsearchcpcbox(bcount,((searchf == 'producturl')?'style="display:none"':''));
					errmsg = errmsg.replace("!!","");
					out = cpcsearchbutt+'<br><br><div class=noresult style="text-indent:30px">'+ errmsg + " that match <b>" +searchstring+'</b>.</div>';
			}
			else
				out = '<div class=noresult>'+ errmsg + trim(vDisplayMsg) +'</div>';
		}
		else
		{
			//# - Added for Tab Explanation - By Jeyaseeelan on 08/06/07
			var browsename = $('browser'+bcount).title;
			var textindent = "style='text-indent:20px'";
			
			if($('browser'+bcount).first == 0)
			{ 
				if(browsename == "MY TAGS")
					errmsg = MyTagsMessage;
				else
					errmsg = "No Tags were found!";
				out = '<div class=noresult style="width:450px;color:#a8a5a5;">'+ errmsg +'</div>';	
			}
			else
			{
				if(browsename == "REPORTS")
					out = '<div class=noresult>' + errmsg+ '</div>';
				else
					out = '<div class=noresult>No Tags were found!</div>';
			}
		}
			
	}
	$('browsecanvas'+bcount).innerHTML = out;
	document.title = "STYLELOGUE: "+$('browser'+bcount).title.toProperCase();;
	//set browser height
	maxb = 100;
	max1 = $('browsehead'+bcount).clientHeight + $('browsemenu'+bcount).clientHeight
	max2 = $('browsehead'+bcount).clientHeight + $('browseoptions'+bcount).clientHeight + $('browsecanvas'+bcount).clientHeight + 2*$('browsenav_'+bcount).clientHeight;
	$('browser'+bcount).style.height = maxb + (max1 > max2 ? max1 : max2);
	$('browsemenuband'+bcount).style.height = 150 + (max2 > max1 ? max2 - max1 + 50 : 10);
	//# - Enalble the button class
	buttonizeall(document.body);
}


//# - function used for display the browse url field - added by jeyaseelan
function ffselectBrowse(pmMedType)
{
	if(pmMedType == 1)
	{
		document.getElementById('btnSave').value = "Add Photo"
		document.getElementById('tdUpload').style.display = "block"
		document.getElementById('tdBrowse').style.display = "none"
	}
	else
	{
		if(pmMedType == 3)
			document.getElementById('btnSave').value = "Add Video"
		else
			document.getElementById('btnSave').value = "Add Photo"
		document.getElementById('tdUpload').style.display = "none"
		document.getElementById('tdBrowse').style.display = "block"
	}
}
//# - This is used for changing day combo while onchange month combo - added by jeyaseelan
function funGetDay(pmMonth)
 {
	var aMonthDay1 = new Array(1,3,5,7,8,10,12);
	var aMonthDay2 = new Array(4,6,9,11);
	var aMonthDay3 = new Array(0,2);
	
	if(checkmonth(pmMonth,aMonthDay2) == true)
	{
		document.getElementById('cmbDOBDay').options[31]= null
	}
	else if(checkmonth(pmMonth,aMonthDay3) == true )
	{
		document.getElementById('cmbDOBDay').options[31]= null
		document.getElementById('cmbDOBDay').options[30]= null
		//document.getElementById('cmbDOBDay').options[29]= null
	}
	else
	{
		
		old = document.getElementById('cmbDOBDay').value;
		for(var j=0;j<31;j++)
		{
			vIndex = j+1;
			document.getElementById('cmbDOBDay').options[vIndex] = new Option(vIndex,vIndex);
		}
		document.getElementById('cmbDOBDay').value = old;
	}
 }
 function checkmonth(monthIndex, monthArray)
 {
	for(var i=0;i<monthArray.length;i++)
	{
		if(monthArray[i] == monthIndex)
		{
			return true;
			break;
		}
		else
			continue;
	}
	return false;
 }
//# - Get Parent window filename and set to cookie added by kamalakannan on 28-Nov-06 at 4.30pm >
function filename_set_cookie(winlocation, pmCookieName)
{
	//# - replace & inplace of [amp] which set in for media video redirection
	
	winlocation = winlocation.replace("[amp]","&");
	var curpagename = parent.window.location;
	//# - get File name
	var currentpagename = getbasename(curpagename);
	if(!in_array( currentpagename, aCur_filenames))
	{
		pmCookieName = pmCookieName ? pmCookieName : "backfilename";
		setCookie (pmCookieName , currentpagename);
	}
	window.location.href = winlocation;
}
function setredirectloginpop()
{
	var curpagename = parent.window.location;
	//# - get File name
	var currentpagename = getbasename(curpagename);
	var pmCookieName = "redirectloginurl";
	setCookie (pmCookieName , currentpagename);
	newsigninpopup()
}
function getbasename(curpagename)
{
	curpagename = curpagename.toString().split("/");
	curpagename = curpagename[curpagename.length-1];
	//curpagename = curpagename.toString().split("?");
	//curpagename = curpagename[0];
	return curpagename;
}
//#-- Count User Click thrus
function user_click_thrus(pagename,prodid,grpid)
{
	ajaxrequest( "user_clickthrus.php?pgname="+escape(pagename)+"&pid="+prodid+"&gid="+grpid, 'clickthrus_pagename', '', 0 );
}
//#--After count redirect the page
function clickthrus_pagename(pagename)
{
	window.open(pagename);
}

var browseajaxreq = null;
function browseajax(url, callback_function, callback_param, return_xml)
{
	if( browseajaxreq != null && browseajaxreq.readyState != 4 ) 
	{
//		alert( 'abort' );
		if( !ie ) browseajaxreq.aborted = true;
		browseajaxreq.abort();
	}
	browseajaxreq = ajaxrequest(url, callback_function, callback_param, return_xml);
//	inspect( browseajaxreq );
//	alert( browseajaxreq );
//	alert( browseajaxreq.readyState );
}

var stopev = false;

function varbase()
{	
	var loc = document.location + '';
	var idx = loc.lastIndexOf( '/' );
	loc = loc.substr( idx + 1, 10000 );
	return loc;
}

function varrecover( n )
{ 
	var curvar = n;
	n = escape(varbase() + '_' + n);
	var dc = document.cookie.split( '; ' );
	for( var i = 0 ; i < dc.length ; i++ )
	{
		var tmp = dc[i].split( '=' );
		if( tmp[0] == n ) return tmp[1]*1;
	}
	//Added by kamalakannan on 14-09-07 for viewoption set in mystart page
	if(varbase() == 'mystart.php')
		return (curvar =='currentmode')?1:0;
	else
		return 0;
}


function varrecover_s( n )
{	
	var vFileName = varbase();
	vFileName = vFileName.toString().split("?");
	vFileName = vFileName[0];
//--Modified by kamalakannan on 15-09-07
	if(vFileName == 'products.php')
		n = escape(vFileName + '_' + n);
	else	
		n = escape(varbase() + '_' + n);

	var dc = document.cookie.split( '; ' );
	for( var i = 0 ; i < dc.length ; i++ )
	{
		var tmp = dc[i].split( '=' );		
		if( tmp[0] == n ) return tmp[1];
	}
	return '';
}


function vargarbage( n, lim )
{ 
	var script = n;
	script = script.substr( 0, script.indexOf( '.php' ) + 4 );
	
	var names = document.cookie.split( '; ' );
	//alert(names);
	var ct = 0;
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	for( var i = names.length-1 ; i > 0 ; i-- )
	{
		var name=names[i].substring(0,(names[i].indexOf("=", 0)));
		if( name.indexOf( script ) == 0 )
		{
			ct++;
//			alert( tmp[0] );
			if( ct > lim )
			{
//				debug( 'delete', name, script );
				//alert(name+"=; expires=" + cookie_date.toGMTString());
				document.cookie=name+"=; expires=" + cookie_date.toGMTString();
			}
		}
	}
//	alert( script + ', ' + ct );
}

function varsave( n, v )
{	
	var vFileName = varbase();
	vFileName = vFileName.toString().split("?");
	vFileName = vFileName[0];
//--Modified by kamalakannan on 15-09-07
	if(vFileName == 'products.php')
		n = escape(vFileName + '_' + n);
	else
		n = escape(varbase() + '_' + n);
	
	if( v == '' && v != 0 )
	{
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setTime ( cookie_date.getTime() - 1 );
		document.cookie = n +"=; expires=" + cookie_date.toGMTString();
	}
	else
		document.cookie = n + '=' + v;
	vargarbage( n, 6 );
}
