var isIE=(window.navigator.appName.indexOf("Internet Explorer")!=-1?true:false);
var DisplayTR="block";
if (isIE==false)
{
	DisplayTR="table-row";
	HTMLElement.prototype.contains=function (Element) {
		if (Element==this) return true;
		if (Element==null) return false;
		return this.contains(Element.parentNode);
	};
}

function FindPositionX(Element)
{
	var CurentLeft=0;
	if (Element==null) return CurentLeft;
	if (Element.offsetParent)
	{
		while (Element.offsetParent)
		{
			CurentLeft+=Element.offsetLeft;
			Element=Element.offsetParent;
		}
	}
	else
		if (Element.x)
			CurentLeft+=Element.x;
	return CurentLeft;
}

function FindPositionY(Element)
{
	var CurentTop=0;
	if (Element==null) return CurentTop;
	if (Element.offsetParent)
	{
		while (Element.offsetParent)
		{
			CurentTop+=Element.offsetTop;
			Element=Element.offsetParent;
		}
	}
	else
		if (Element.y)
			CurentTop+=Element.y;
	return CurentTop;
}

function OnMouseOverRow(evt,Row)
{
	if (!evt) evt=window.event;
	if (Row==null) return;
	if (Row.className.lastIndexOf("_Hover")==-1)
		Row.className=Row.className+"_Hover";
}

function OnMouseOutRow(evt,Row)
{
	if (!evt) evt=window.event;
	if (Row==null) return;
	var Src=(evt.toElement?evt.toElement:evt.relatedTarget);
	if (Src==undefined) return;
	if (Row.className.lastIndexOf("_Hover")!=-1)
		Row.className=Row.className.substr(0,Row.className.lastIndexOf("_Hover"));
}

var HintMode=null;
function ShowItemHint(evt,Row)
{
	if (!evt) evt=window.event;
	var srcElement=(evt.srcElement?evt.srcElement:evt.target);
	if ((!srcElement.id)||(srcElement.id.indexOf("ProductInfo")==-1)) return;
	while ((Row!=null)&&(Row!=undefined)&&(Row.nodeName.toLowerCase()!="tr"))
		Row=Row.parentNode;
	var Hint=Row.getElementsByTagName("div")[0];
	var HintIFrame=Row.getElementsByTagName("iframe")[0]; //to hide SELECT's
	if ((HintMode!=null) && (HintMode!=Hint))
	{
		HintMode.style.display="none";
		HintMode=null;
		if(HintIFrame != null){ //to hide SELECT's
		  HintIFrame.style.display="none";
		  HintIFrame=null;
		}
	}
	for (var Index=0;Index<Row.parentNode.rows.length;Index++)
		if (Row==Row.parentNode.rows[Index]) break;
	var Container=Hint;
	while ((Container.getAttribute("isContainer")==null)&&(Container!=document.body))
		Container=Container.parentNode;
	if (Hint.style.visibility!="visible")
	{
		var HintType=1;//(Index>7?-1:1);
		var TRItems=Hint.getElementsByTagName("tr");
		switch (HintType)
		{
			case 1:
			{
				TRItems[0].style.display=DisplayTR;
				TRItems[1].style.display="none";
				TRItems[TRItems.length-2].style.display=DisplayTR;
				TRItems[TRItems.length-1].style.display="none";
				if(HintIFrame != null){ //to hide SELECT's
				  HintIFrame.style.top=FindPositionY(Row)-245+14;//+10+14;
				}
				if (Container.style.position=="relative")
					Hint.style.top=FindPositionY(Row)-345;
				else
					Hint.style.top=FindPositionY(Row)+10;
				break;
			}
			case -1:
			{
				TRItems[0].style.display="none";
				TRItems[1].style.display=DisplayTR;
				TRItems[TRItems.length-2].style.display="none";
				TRItems[TRItems.length-1].style.display=DisplayTR;
				Hint.style.top=FindPositionY(Row)-Hint.scrollHeight+10;
				break;
			}
		}
		if(HintIFrame != null){ //to hide SELECT's
		  HintIFrame.style.left=FindPositionX(Row)+10;
		  HintIFrame.style.height = Hint.offsetHeight-24;
		  HintIFrame.style.visibility="visible";
		}
		if (Container.style.position=="relative")
			Hint.style.left=FindPositionX(Row)-230;
		else
			Hint.style.left=250;
		Hint.style.visibility="visible";
	}
	if(HintIFrame != null){ //to hide SELECT's
		HintIFrame.style.display="block";
	}
	Hint.style.display="block";
	HintMode=Hint;
}

function HideItemHint(evt,Hint)
{
	var toElement=(evt.toElement?evt.toElement:evt.relatedTarget);
	if (Hint!=null)
	{
		Hint.style.display="none";
		if ((toElement!=null)&&(Hint.contains(toElement)==true)) return;
	}
	if (!evt) evt=window.event;
	if (!toElement) return;
	if (toElement==null) return;
	HintMode=null;
}

function OpenGalleryWindow(Portal,Path,Provider,TargetControl,Value)
{
	var DataProvider=window.open(Path+"?portal="+Portal+"&target="+TargetControl+"&provider="+Provider+(Value!=undefined?"&value="+encodeURI(Value):""),"DataProvider","width=700,height=600,toolbars=0,resizable=1");
	DataProvider.focus();	
	return false;
}

function OnListSubmit(evt,ID,ActualFilter)
{
	if (evt==null) evt=window.event;
	var Source=(evt.srcElement?evt.srcElement:evt.target);
	var FilterByClass=document.getElementById("FilterByClass");
	var FilterByBrand=document.getElementById(Source.id.substr(0,Source.id.lastIndexOf("_"))+"_FilterByBrandControl");
	var FilterByType=document.getElementById(Source.id.substr(0,Source.id.lastIndexOf("_"))+"_FilterByTypeControl");
	var FilterBySeason=document.getElementById(Source.id.substr(0,Source.id.lastIndexOf("_"))+"_FilterBySeasonControl");
	var FilterBySize=document.getElementById(Source.id.substr(0,Source.id.lastIndexOf("_"))+"_FilterBySizeControl");
	var FilterByIndex=document.getElementById(Source.id.substr(0,Source.id.lastIndexOf("_"))+"_FilterByIndexControl");
	if (ActualFilter==undefined)
	{
		document.getElementById("FilterParams").value=
			FilterByClass.value+";"+FilterByBrand.value+";"+FilterByType.value+";"+FilterBySeason.value+";"+FilterBySize.value+
			((FilterByIndex!=null)&&(FilterByIndex.options[FilterByIndex.selectedIndex].value!="0")?"SI"+FilterByIndex.options[FilterByIndex.selectedIndex].value:"");
	}
	else
		document.getElementById("FilterParams").value=ActualFilter;
	if (ID!=null)
	{
		if (document.forms[0].action.indexOf("alias")!=-1)
			document.forms[0].action="http://"+document.forms[0].action.substr(document.forms[0].action.lastIndexOf("?alias=")+7)+"/tabid/"+ID+"/Default.aspx";
		else
			if (document.forms[0].action.indexOf("tabid")!=-1)
				document.forms[0].action=document.forms[0].action.replace(/tabid\/\d+/,"tabid/"+ID).replace(/\?productid=\d+/,"");
			else
				document.forms[0].action=document.forms[0].action.substr(0,document.forms[0].action.lastIndexOf("/")+1)+"tabid/"+ID+"/default.aspx";
		if (document.getElementsByName("__VIEWSTATE")[0])
			document.getElementsByName("__VIEWSTATE")[0].name="__NOVIEWSTATE";
		if (document.getElementsByName("__EVENTTARGET")[0])
			document.getElementsByName("__EVENTTARGET")[0].name="__NOEVENTTARGET";
		if (document.getElementsByName("__EVENTARGUMENT")[0])
			document.getElementsByName("__EVENTARGUMENT")[0].name="__NOEVENTARGUMENT";
		document.forms[0].submit();	
	}
}

