function manageXitiTitle(p)
{
    p = trimString(p);
    var name = getXtPageName(p);
    var r = /!|=|,|;|:|§|!|µ|%|@|£|²|°|'|<|>|\"|&|#|{|}|\$|\[|\]|\*|\?|\+|\~|}|{|\^|\\|\|/g;
    return updateXtPageName(p, name.replace(r, "-").replace(/\s/g, "_"));
}
var objURL = new Object();

	   window.location.search.replace(new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),function( $0, $1, $2, $3 ){objURL[ $1 ] = $3;});

	   
var sendPagechecked = false;
var removedchecked = false;
	   
	   
	   
	   function SendPage(input){
		   if (sendPagechecked == false)
		   {
				 var appendURL = input;

				 //Added by Anu to fixed the filter comma Mantis bug
				//input = input.replace(/,/gi,'\\,');
				 input = encodeURIComponent(input);
				 var newQS = "";

				 var oldQS = window.location.search.substring(1);

				 var fUpdated = false;

				 if (objURL["f"] == "")

				 {

						  delete objURL["f"];

				 }

				 for (var strKey in objURL){

						  if (strKey == 'f')

						  {

									objURL['f']+= "~!" + input;

							 fUpdated = true;

						  }

						  else

						  {

						  }

				 }

				 if (!fUpdated)

				 {

						  objURL["f"] = input;

				 }
				//		  objURL["logURL"] = "false";

				 for (var strKey in objURL){

						  if (newQS != "")

						  {

									newQS += "&" + strKey +"="+objURL[strKey];

						  }

						  else

						  {

									newQS += strKey +"="+objURL[strKey];

						  }


				 }

				 for (var strKey in objURL){

				 }

				 var newURL = window.location.href.split("?")[0] + "?" + newQS
				//add for xiti
				 var filterName = input.split("%3A");
				 
				 var filterCat;

				 for(var strKey in title)
            {
                 var titleName = strKey.split("/")[1];

				if (titleName == filterName[0])
                {
                    
					filterCat = title[strKey];

                }
            }

	var xtpage=	filterCat +"::"+filterName[1];
	var elLi = document.getElementById('youSelectedList');
	filterName[1] = manageXitiTitle(decodeURIComponent(filterName[1]));
	pageStatClickMarker(varPageName,varPreviewCheck,filterCat +"::"+filterName[1]);

	//End for xiti
					 window.location = newURL;
				sendPagechecked = true;

				 return false;
		   }
	   }


	   function RenderYouHaveSelected(){

				 var fVal ;

				 var elLi = document.getElementById('youSelectedList');

				 elLi.innerHTML = "";

				 for (var strKey in objURL){

						  if (strKey == 'f')

						  {
									fVal = decodeURIComponent(objURL[strKey].replace(/\+/gi,'%20').replace(/\%5C%2C/gi,'%2C')).split("~!");

						  }

				 }
				var checkFilter = 0;
				 if (fVal)

				 {

						  for (i=0;i<fVal.length ;i++ )

						  {

									var filterVal = fVal[i].split(":");

									for (var strKey in title )

									{

											  var titleName = strKey.split("/")[1];

											  if (titleName == filterVal[0])

											  {
														checkFilter = 1;
														
														//fVal[i] = fVal[i].replace(/\\/gi,'\\\\');
														//fVal[i] = fVal[i].replace(/\"/gi,'\\"');
														
														fVal[i] = escape(fVal[i]);
														elLi.innerHTML += "<li><a href='#' onclick='return removeFilter(\""+fVal[i]+"\")'>"+title[strKey] + " : " + filterVal[1] +"</a>";

											  }

									}

						  }

						if (checkFilter == 1)
					 {
							document.getElementById("youSelected").style.display = "block"
					 }
					 else
					 {
						 document.getElementById("youSelected").style.display = "none"
					 }
				 }
				 else

				 {

						   document.getElementById('youSelected').style.display = 'none';

				 }

	   }


	   function removeFilter(input)

	   {
		   input = unescape(input);
		   if (removedchecked == false)
		   {
			   var newQS = "";

				 var oldQS = window.location.search.substring(1);

				 decodeURIComponent(oldQS);

				 var fUpdated = false;

				 for (var strKey in objURL){

						  if (strKey == 'f')

						  {

									 updatedF = "";

									 var newFVal = decodeURIComponent(objURL['f'].replace(/\+/gi,'%20').replace(/\%5C%2C/gi,'%2C')).split('~!');
									//fVal = unescape(objURL[strKey].replace(/\+/gi,'%20')).split("~!");

									 var isDel = false;

									 for (i=0;i<newFVal.length ;i++ )

									 {

											  if (input == 'all')

											  {

													  //updatedF = "";
														var newvar = true;
														var tmpF;
														for (var strKey1 in title)
														{
															//alert(strKey1 + " \n" + newFVal[i].split(":")[0]);
															if (strKey1.split("/").length == 2)
															{
																if (strKey1.split("/")[1]!= newFVal[i].split(":")[0] )
																{
																	//alert("here");
																	tmpF=encodeURIComponent(newFVal[i]);
																}
																else
																{
																	//alert("not here");
																	newvar= false;
																}
															}
															else
															{
																newvar= false;
															}

															
														}	
														//alert(newFVal[i] + "and bol is " + newvar);
														if(newvar)
														{
															if (updatedF == "")	
															{
																updatedF+= tmpF;
															}
															else
															{
																updatedF+= "~!" + tmpF;
															}
														}
													  //add for Xiti
													  pageStatClickMarker(varPageName,varPreviewCheck,varRemoveAll);

													  //end of Xiti
											  }

											  else

											  {

												   //add for Xiti
													 var filterName = newFVal[i].split(":"); 
		
														filterName[1] = manageXitiTitle(filterName[1]);
														pageStatClickMarker(varPageName,varPreviewCheck,varRemove+"::"+filterName[1]);

													  //end of Xiti
													   if ( newFVal[i] == input && !isDel)

													   {

																 isDel = true;

													   }

													   else

													   {

																 if (updatedF == "")

																 {

																		  updatedF +=  encodeURIComponent(newFVal[i]);

																 }

																 else

																 {

																		  updatedF += "~!"+ encodeURIComponent(newFVal[i]);

																 }

													   }

											  }

									 }

									  objURL["f"] = updatedF;

									  if (objURL["f"] == "")

									  {

											  delete objURL["f"];

									  }

						  }

						  else

						  {

						  }

				 }

				 if (!fUpdated)

				 {

				 }
				 //objURL["logURL"] = "false";
				 for (var strKey in objURL){

						  if (newQS != "")

						  {

									newQS += "&" + strKey +"="+objURL[strKey];

						  }

						  else

						  {

									newQS += strKey +"="+objURL[strKey];

						  }

						  

				 }

				 for (var strKey in objURL){

				 }

				 var newURL = window.location.href.split("?")[0] + "?" + newQS

				 window.location = newURL;

				 removedchecked = true;

				 return false;
		   }

	   }

//	   window.onload  = RenderYouHaveSelected;

function hideFilterLink()
{
	var fVal = new Array();
	for (var strKey in objURL){
	  if (strKey == 'f')
				fVal = decodeURIComponent(objURL[strKey].replace(/\+/gi,'%20').replace(/\%5C%2C/gi,'%2C')).split("~!");
	 }		
	//fVal = encodeURIComponent(fVal);
	if (fVal.length>0)//checking for filter existance
	{
		var arrfVal //= new Array();
		for (var fValURLCnt=0;fValURLCnt<fVal.length;fValURLCnt++ )
		{
			arrfVal = '';// = new Array();
			fVal[fValURLCnt]=encodeURIComponent(fVal[fValURLCnt]);
			arrfVal = fVal[fValURLCnt];//.split('%2C');
			if(arrfVal.indexOf('%3A')>-1)//checking for : per filter
			{
					var arrCategory = arrfVal.split('%3A');
				var arrLIs,i,j,categoryVal,startFrom_currentCat,strLength_currentCat,aLinkNode,startFrom_CatExist,strLength_CatExist,categoryName,currentCategory,len;
				var flagcatexist = true;
				var arrULs = document.getElementById('linksContainer').getElementsByTagName('UL');
				for (i=0;i<arrULs.length ;i++ )//start scanning all UL tags
				{
					arrLIs = arrULs[i].getElementsByTagName('LI');
					for (j=0;j<arrLIs.length ;j++)// start scanning all Li tags
					{
						flagcatexist = true;
						for (aLinkNode=0;aLinkNode<arrLIs[j].childNodes.length; aLinkNode++) // start searcing for anchor tag in LI
						{
							if (arrLIs[j].childNodes[aLinkNode].nodeName =='A')
							{
								categoryVal = arrLIs[j].childNodes[aLinkNode].getAttributeNode("onclick").value;
								if(categoryVal.indexOf('\'F')>-1) //check for 'F
								{
									startFrom_currentCat = categoryVal.indexOf('F',0);
									strLength_currentCat = (categoryVal.indexOf(':',0)) - (categoryVal.indexOf('F',0));
										startFrom_CatExist = arrfVal.indexOf('F',0);
										strLength_CatExist = (arrfVal.indexOf('%3A',0)) - (arrfVal.indexOf('F',0));
										if((categoryVal.substr(startFrom_currentCat,strLength_currentCat)) != (arrfVal.substr(startFrom_CatExist,strLength_CatExist))) // check for category code
									{
										flagcatexist = false;
									}
									else  
									{
										endto = categoryVal.indexOf("')");
										startfrom = categoryVal.indexOf(":")+1;
										categoryName =encodeURIComponent(categoryVal.substr(startfrom,endto-startfrom));
											currentCategory = arrfVal.substr((arrfVal.indexOf('%3A',0)+3),arrfVal.length);
										if (currentCategory==categoryName) // check for category name
										{
											arrLIs[j].style.display = 'none';
										}
									}

								}//end of check for 'F
							}
							if(!flagcatexist)
								break;
						}// end searcing for anchor tag in LI
						
						if(!flagcatexist)
							break;
					}//end scanning all Li tags
					visibleLIs = false;
					for (j=0;j<arrLIs.length;j++)// start scanning all Li tags
					{
						if (arrLIs[j].style.display != 'none')
							visibleLIs = true;

							if (j==arrLIs.length-1)
							{
								if (visibleLIs == false)
								{
									arrLIs[j].parentNode.parentNode.style.display="none";
								}
							}
					}//end scanning all li tags
				}//end scanning all UL tags
			}
		}
	}// end for loop per filter
}
