﻿//winnowing
oWinnowing = function()
{
	this.fxShowAllId=null;
	this.fxBlocker=false;
	this.fxFadeTime =720; 
	this.fxBlockerTimeout=this.fxFadeTime*2;
	this.fxVariation = document.getElementById('divImgSmall');
	if(this.fxVariation!=null)
	{
		this.fxVariation = new fx.Opacity(this.fxVariation, {duration: this.fxFadeTime});
	}
	//helper var for fx obj
	this.fx = null;
	//fx open od
	this.fxOpenId = null;//fxOpenId;
	//fx clicked
	this.fxClickedId = null;//fxClickedId;
	//filter values
	this.filter = null;//filter;
	this.wsfilterresult = null;
	//fx objects in hashtable
	this.fxHash = new Hashtable();
	//fill inn data
	this.fx = new fx.Height(document.getElementById('divWinnowingFamily'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Family',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingMaterial'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Material',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingDial'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Dial',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingDiamonds'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Diamonds',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingMovement'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Movement',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingFunction'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('Function',this.fx);
	this.fx = new fx.Height(document.getElementById('divWinnowingBraceletColor'), {duration: this.fxFadeTime});
	this.fx.hide();
	this.fxHash.put('BraceletColor',this.fx);
	this.fx = null;
}
oWinnowing.prototype.fxVariationToggler = function(){
	if(this.fxVariation!=null)
	{
		this.fxVariation.toggle();
	}
}
oWinnowing.prototype.wsfilter = function(result, request, context){
	this.wsfilterresult = result;
	jsfToggleLoad(this.wsfilterresult);
}
oWinnowing.prototype.fxBlocked = function(){
	return this.fxBlocker;
}
oWinnowing.prototype.fxBlock = function(){
	this.fxBlocker = true;
	setTimeout("oW.fxUnblock();",this.fxBlockerTimeout);
}
oWinnowing.prototype.fxUnblock = function(){
	this.fxBlocker = false;
}
oWinnowing.prototype.fxOpenId = function(id){
	this.fxOpenId = id;
}
oWinnowing.prototype.fxClickedId = function(id){
	this.fxClickedId = id;
}
oWinnowing.prototype.filter = function(aFilter){
	this.filter = aFilter;
}
oWinnowing.prototype.fx = function(fx){
	this.fx = fx;
}
oWinnowing.prototype.toggle = function(){
	if(this.fxOpenId!=null)
	{
		this.fxHash.get(this.fxOpenId).toggle();
	}
}
oWinnowing.prototype.hide = function(){
	if(this.fxOpenId!=null)
	{
		this.fxHash.get(this.fxOpenId).hide();
		this.fxOpenId = null;
	}
}
oWinnowing.prototype.hideAll = function(){
	var e = this.fxHash.keys();
	alert(this.fxHash.toString());
	/*
	for(var i=0;i<e.length;i++)
	{
		alert(this.fxHash[i]);
	}
	*/
}
function jsfFXInit()
{
	oW = new oWinnowing();
	aseantic.MOSS.Rado.WebServices.CollectionSearch.Filter(oW.wsfilter);
}
function jsfShowAll(id)
{
	if(!oW.fxBlocked())
	{
		oW.fxBlock();
		oW.fxClickedId=id;
		//hide actual openend filter
		oW.hide();
		//clear showall id
		//document.getElementById("hrefWinnowingShowAllTitle"+oW.fxShowAllId).style.visibility='hidden';
		oW.fxShowAllId=null;
		aseantic.MOSS.Rado.WebServices.CollectionSearch.RemoveFilter(oW.fxClickedId);
		document.getElementById("hrefWinnowingTitle"+oW.fxClickedId).className="WinnowingTitleEmpty";
		//toggle - use global defined var jsRef from /UserControls/Js/Default.ascx
		aseantic.MOSS.Rado.WebServices.CollectionSearch.Draw(oW.fxClickedId,unescape(jsRef).split("/")[1].toUpperCase(),jsfToStringAndToogle);
	}
}
function jsfClear()
{
	var arrObjHtml = divWinnowingMainContainer.getElementsByTagName("a");
	if(arrObjHtml.length>0)
	{
		//get href elements
		for(var i=0; i<arrObjHtml.length; i++)
		{
			if(arrObjHtml[i].id.indexOf("hrefWinnowingTitle")>-1)
			{
				//found title href
				arrObjHtml[i].className="WinnowingTitleEmpty";
			}
			else if(arrObjHtml[i].id.indexOf("Elem_")>-1)
			{
				//found element href
				arrObjHtml[i].className="WinnowingElemOff";
				document.getElementById(arrObjHtml[i].id.replace(/href/,"chk")).checked = false;
			}
		}
	}
	//reset service
	aseantic.MOSS.Rado.WebServices.CollectionSearch.Reset();
	if(oW.fxOpenId!=null)
	{
		if(!oW.fxBlocked())
		{
			oW.fxBlock();
			oW.toggle();
			oW.fxOpenId=null;
		}
		oW.fxVariationToggler();
	}
	return true;
}
function jsfSearch()
{
	if(oW.filter!=null)
	{
		aseantic.MOSS.Rado.WebServices.CollectionSearch.AddFilter(unescape(jsRef).split("/")[1].toUpperCase(),oW.fxOpenId, oW.filter.keys().toString());
		oW.filter = null;
	}
	return true;
}
function jsfToggleLoad(f)
{
	if(f!=null && f.length>0)
	{
		var arrElem = oW.fxHash.keys();
		for(var i=0; i<arrElem.length; i++)
		{
			if(f.indexOf(arrElem[i])>-1)
			{
				document.getElementById("hrefWinnowingTitle"+arrElem[i]).className="WinnowingTitleHalf";
			}
		}
	}
}
function jsfToggle(id)
{
	if(!oW.fxBlocked())
	{
		oW.fxBlock();
		oW.fxClickedId = id;
		if(oW.fxOpenId==oW.fxClickedId)
		{
			//opacity variation...
			oW.fxVariationToggler();
			//get fx obj and toggle
			oW.toggle();
			oW.fxOpenId=null;
		}
		else
		{
			if(oW.filter!=null)
			{
				aseantic.MOSS.Rado.WebServices.CollectionSearch.AddFilter(unescape(jsRef).split("/")[1].toUpperCase(),oW.fxOpenId!=null?oW.fxOpenId:oW.fxClickedId, oW.filter.keys().toString());
				oW.filter = null;
			}
			//redraw elements - use global defined var jsRef from /UserControls/Js/Default.ascx
			aseantic.MOSS.Rado.WebServices.CollectionSearch.Draw(oW.fxClickedId,unescape(jsRef).split("/")[1].toUpperCase(),jsfToStringAndToogle);
		}
	}
}
function jsfToggleHint(id,val)
{
	var oDivContainer = document.getElementById("divWinnowing"+id);
	var oHrefElem = document.getElementById("hrefWinnowing"+id+"Elem_"+val);
	var oChkElem = document.getElementById("chkWinnowing"+id+"Elem_"+val);
	var arrChkBoxes = oDivContainer.getElementsByTagName("input");
	if(oW.fxShowAllId==null)
	{
		oW.fxShowAllId = id;
		//document.getElementById("hrefWinnowingShowAllTitle"+oW.fxShowAllId).style.visibility='visible';
	}
	//init hashtable
	oW.filter = new Hashtable();
	
	oHrefElem.className=(oHrefElem.className=="WinnowingElemOff")?"WinnowingElemOn":"WinnowingElemOff";
	oChkElem.checked=!oChkElem.checked;
	if(arrChkBoxes.length>0)
	{
		//seach clicked checkboxes
		for(var i=0; i<arrChkBoxes.length; i++)
		{
			if(arrChkBoxes[i].checked)
			{
				//store values into array
				oW.filter.put(arrChkBoxes[i].value, true);
				//alert("add jsfToggleHint: "+arrChkBoxes[i].value);
			}
			else
			{
				oW.filter.remove(arrChkBoxes[i].value);
				//alert("remove jsfToggleHint: "+arrChkBoxes[i].value);
			}
		}
		//alert(oW.filter.toString());
		//handle boxes
		if(oW.filter.size()==0)
		{
			document.getElementById("hrefWinnowingTitle"+id).className="WinnowingTitleEmpty";
			//remove showall
			//document.getElementById("hrefWinnowingShowAllTitle"+oW.fxShowAllId).style.visibility='hidden';
			oW.fxShowAllId=null;
		}
		else if(oW.filter.size() == arrChkBoxes.length){document.getElementById("hrefWinnowingTitle"+id).className="WinnowingTitleFull";}
		else{document.getElementById("hrefWinnowingTitle"+id).className="WinnowingTitleHalf";}
		//register in webservice
		//alert("jsfToggleHint WS: "+oW.filter.keys().toString());
		aseantic.MOSS.Rado.WebServices.CollectionSearch.AddFilter(unescape(jsRef).split("/")[1].toUpperCase(),oW.fxOpenId, oW.filter.keys().toString());
	}
}
function jsfDebug(result, request, context)
{
	alert(result);
}
function jsfToStringAndToogle(result, request, context)
{
	//alert("function jsfToStringAndToogle\noW.fxClickedId="+oW.fxClickedId+"\noW.fxOpenId="+oW.fxOpenId);
	document.getElementById("divWinnowing"+oW.fxClickedId).innerHTML = result;
	if(oW.fxOpenId!=null)
	{
		//here we have the case of an opened div
		if(oW.filter!=null)
		{
			//look for  filter values and write it to service
			aseantic.MOSS.Rado.WebServices.CollectionSearch.AddFilter(unescape(jsRef).split("/")[1].toUpperCase(),oW.fxOpenId, oW.filter.toString());
			oW.filter = null;
			//aseantic.MOSS.Rado.WebServices.CollectionSearch.Filter(jsfDebug);
		}
		//get div obj and close it
		oW.toggle();
	}
	else
	{
		//opacity variation...
		oW.fxVariationToggler();
	}
	//get clicked fx object - and open it
	oW.fxOpenId=oW.fxClickedId;
	oW.toggle();
	//alert("function jsfToStringAndToogle\noW.fxClickedId="+oW.fxClickedId+"\noW.fxOpenId="+oW.fxOpenId);
}