function Trim(str)
{  
	while(str.charAt(0) == (" "))
  {  
		str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  
		str = str.substring(0,str.length-1);
  }
  return str;
}

function RemoveFriendPopup(UserViewMode, StyleProfileID, FriendID)
{
	showPopWin('popups/delete_friends.php?UserViewMode='+UserViewMode+"&StyleProfileID="+StyleProfileID+"&FriendID="+FriendID,420,420,null);
}

function RemoveFriend(UserViewMode, StyleProfileID, FriendID)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return;
  } 

	window.top.document.getElementById("ThumperDiv").style.display = '';

	var url="../ajax_calls/style_profile_friends_tab.php";
	url=url+"?UserViewMode="+UserViewMode;
	url=url+"&StyleProfileID="+StyleProfileID;
	url=url+"&process=5";
	url=url+"&FriendID="+FriendID;

	xmlHttp.onreadystatechange = DisplaySearchFriendsPopup;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function DisplaySearchFriendsPopup()
{	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{			
			ResponseText = xmlHttp.responseText;
			
			if (ResponseText == 9006)
			{
				window.location.href = "error_page.php";
				return;
			}
			
			var arr=ResponseText.split("****");
			window.top.document.getElementById("StyleProfilesTabs").innerHTML = "";		
			window.top.document.getElementById("StyleProfilesTabs").innerHTML = arr[0];		
			window.top.document.getElementById("ThumperDiv").style.display = 'none';
			window.top.document.getElementById("TotalNumberPage").value=arr[1];

			var head = window.top.document.getElementsByTagName('head').item(0);
			var old  = window.top.document.getElementById('lastLoadedCmds');
			if (old) 
			{
				head.removeChild(old);
			}

			var script = window.top.document.createElement('script');
			script.src = 'scripts/slider/slider.js';
			script.type = 'text/javascript';
			script.defer = true;
			script.id = 'lastLoadedCmds';

			void(head.appendChild(script));	
			window.top.hidePopWin(window.top.callback_friends(),false);
			//alert(document.getElementById('click_type').value);
	}	
}

function RefineSearchFriendsTab(UserViewMode, StyleProfileID, Mode, WildCard)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return;
  } 

	document.getElementById("ThumperDiv").style.display = '';

	var url="ajax_calls/style_profile_friends_tab.php";
	url=url+"?UserViewMode="+UserViewMode;
	url=url+"&StyleProfileID="+StyleProfileID;
	url=url+"&Mode="+Mode;
	url=url+"&WildCard="+WildCard;

	xmlHttp.onreadystatechange = DisplaySearchFriends;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function DisplaySearchFriends()
{	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{			
			ResponseText = xmlHttp.responseText;
			
			if (ResponseText == 9006)
			{
				window.location.href = "error_page.php";
				return;
			}
			
			var arr=ResponseText.split("****");

			document.getElementById("StyleProfilesTabs").innerHTML = "";		
			document.getElementById("StyleProfilesTabs").innerHTML = arr[0];		
			document.getElementById("ThumperDiv").style.display = 'none';
			document.getElementById("TotalNumberPage").value=arr[1];

			var head = document.getElementsByTagName('head').item(0);
			var old  = document.getElementById('lastLoadedCmds');
			if (old) 
			{
				head.removeChild(old);
			}

			var script = document.createElement('script');
			script.src = 'scripts/slider/slider.js';
			script.type = 'text/javascript';
			script.defer = true;
			script.id = 'lastLoadedCmds';

			void(head.appendChild(script));	
			//alert(document.getElementById('click_type').value);
	}	
}

function SetUpItemSearch(UserViewMode, StyleProfileID, VisibilityType, CategoryID, SubCategoryID)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return;
  } 

	document.getElementById("ThumperDiv").style.display = '';

	var url="ajax_calls/style_profile_items_tab.php";
	url=url+"?UserViewMode="+UserViewMode;
	url=url+"&StyleProfileID="+StyleProfileID;
	url=url+"&VisibilityType="+VisibilityType;
	url=url+"&CategoryID="+CategoryID;
	url=url+"&SubCategoryID="+SubCategoryID;

	xmlHttp.onreadystatechange = DisplaySearch;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function SetUpLookSearch(UserViewMode, StyleProfileID, VisibilityType)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return;
  } 

	document.getElementById("ThumperDiv").style.display = '';
	var url="ajax_calls/style_profile_looks_tab.php";
	url=url+"?UserViewMode="+UserViewMode;
	url=url+"&StyleProfileID="+StyleProfileID;
	url=url+"&VisibilityType="+VisibilityType;

	xmlHttp.onreadystatechange = DisplaySearch;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ClearSPSearchBox()
{
	if((document.getElementById('SearchTextSPWithin').value=='                    No matches found.          ') || document.getElementById('SearchTextSPWithin').value=='                Two Characters Minimum                ') 
	{ 
		document.getElementById('SearchTextSPWithin').value=''; 
		document.getElementById('SearchTextSPWithin').style.color = "black";
	}
}

function SetUpSearch(TabName, UserViewMode, StyleProfileID)
{
	var SearchDescription = false;
	var SearchPrivateTags = false;

	var SearchText = (document.getElementById("SearchTextSPWithin").value);
	SearchText = Trim(SearchText);
	
	var length = SearchText.length;
	
	if((SearchText == '') || (SearchText == '                    No matches found.          ') || (SearchText == '                Two Characters Minimum                ') || (length <= 1))
	{ 
		document.getElementById("SearchTextSPWithin").value='                Two Characters Minimum                ';
		Blink('SearchTextSPWithin,#37C1F4,5');
		return; 
	}	
	
	if(document.getElementById("SearchDescription").checked == true)
	{
		SearchDescription = true;
	}
	if (UserViewMode == 1)	
	{
		if(document.getElementById("SearchPrivateTags").checked == true)
		{
			SearchPrivateTags = true;
		}
	}

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
  {
		alert ("Your browser does not support AJAX!");
		return;
  } 

	document.getElementById("ThumperDiv").style.display = '';
	switch (TabName)
	{
		case "Items":											
			var url="ajax_calls/style_profile_items_tab.php";
			break;

		case "Looks":											
			var url="ajax_calls/style_profile_looks_tab.php";
			break;
	}

	url=url+"?UserViewMode="+UserViewMode;
	url=url+"&StyleProfileID="+StyleProfileID;
	url=url+"&SearchText="+SearchText;

	if (SearchDescription == true)
	{
		url=url+"&SearchDescription=1";
	}
	if (SearchPrivateTags == true)
	{
		url=url+"&SearchPrivateTags=1";
	}

	xmlHttp.onreadystatechange = DisplaySearch;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function DisplaySearch()
{	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{			
		ResponseText = xmlHttp.responseText;
		
		if (ResponseText == 9006)
		{
			window.location.href = "error_page.php";
			return;
		}
		
		var arr=ResponseText.split("****");

		document.getElementById("StyleProfilesTabs").innerHTML = "";		
		document.getElementById("StyleProfilesTabs").innerHTML = arr[0];	

		if(arr[2]=="1")
		{
			document.getElementById('SearchTextSPWithin').style.color = 'red';				 
			document.getElementById('SearchTextSPWithin').value ="                    No matches found.          ";
			//document.getElementById('txtsearch').disabled=true;
			Blink('SearchTextSPWithin');
		}
		else 
		{
				document.getElementById('SearchTextSPWithin').style.color = '#252525';
				//document.getElementById('SearchText').value ="";
		}
		
		document.getElementById("TotalNumberPage").value=arr[1];
		document.getElementById("ThumperDiv").style.display = 'none';

		var head = document.getElementsByTagName('head').item(0);
		var old  = document.getElementById('lastLoadedCmds');

		if (old) 
		{
			head.removeChild(old);
		}

		var script = document.createElement('script');
		script.src = 'scripts/slider/slider.js';
		script.type = 'text/javascript';
		script.defer = true;
		script.id = 'lastLoadedCmds';

		void(head.appendChild(script));	
	}	
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
