﻿// Pass true or false to show or hide the given element
function SS_ShowElement(Element, State){
	Element=SS_GetElement(Element);
	if (Element){
		if (State){
	    	Element.style.visibility="visible";
		} else {
	    	Element.style.visibility="hidden";
		}
	}
}


// Toggles an element as visible/hidden
function SS_ToggleElement(Element){
	Element=SS_GetElement(Element);
	if (Element){
		SS_ShowElement(Element, Element.style.visibility=="hidden");
	}
}


// Either show or hide the element based on if there is content within it
function SS_ShowElementOnContent(Element){
	Element=SS_GetElement(Element);
	if (Element){
		SS_ShowElement(Element, Element.innerHTML.length>0);
	}
}


// Return the left of the given element in relation to it's parent container
function SS_GetElementX(Element){
	Element=SS_GetElement(Element);
	if (Element){
		return Element.offsetLeft;
	}
	return 0;
}


// Return the top of the given element in relation to it's parent container
function SS_GetElementY(Element){
	Element=SS_GetElement(Element);
	if (Element){
		return Element.offsetTop;
	}
	return 0;
}



// Return the absolute left of the given element in relation to the page
function SS_GetElementAbsoluteX(Element){
	var CurrX=0;
	Element=SS_GetElement(Element);
	if (Element){
		CurrX+=Element.offsetLeft;
		while (Element.offsetParent!=null){
			Element=Element.offsetParent;
			CurrX+=Element.offsetLeft;
		}
	}
	return CurrX;
}



// Return the absolute top of the given element in relation to the page
function SS_GetElementAbsoluteY(Element){
	var CurrY=0;
	Element=SS_GetElement(Element);
	if (Element){
		CurrY+=Element.offsetTop;
		while (Element.offsetParent!=null){
			Element=Element.offsetParent;
			CurrY+=Element.offsetTop;
		}
	}
	return CurrY;
}


// Return the width of the given element
function SS_GetElementW(Element){
	Element=SS_GetElement(Element);
	if (Element){
		return Element.offsetWidth;
	}
	return 0;
}


// Return the height of the given element
function SS_GetElementH(Element){
	Element=SS_GetElement(Element);
	if (Element){
		return Element.offsetHeight;
	}
	return 0;
}


// Return the opacity of the given element between 0-100
// Return 100 if undefined
function SS_GetElementOpacity(Element){
	Element=SS_GetElement(Element);
	if (Element){
		if (Element.style.opacity!="" && Element.style.opacity!=null){
			return parseInt(Element.style.opacity*100);
		}
	}
	return 100;
}


// Set the left of the given element in relation to it's containing element
function SS_SetElementX(Element, X){
	Element=SS_GetElement(Element);
	if (Element){
		if (X!=null){
			Element.style.left=X+"px";
		} else {
			Element.style.left=null;
		}
	}
}



// Set the top of the given element in relation to it's containing element
function SS_SetElementY(Element, Y){
	Element=SS_GetElement(Element);
	if (Element){
		if (Y!=null){
			Element.style.top=Y+"px";
		} else {
			Element.style.top=null;
		}
	}
}



// Set the width of the given element
function SS_SetElementW(Element, W){
	Element=SS_GetElement(Element);
	if (Element){
		if (W!=null){
			Element.style.width=W+"px";
		} else {
			Element.style.width=null;
		}
	}
}


// Set the height of the given element
function SS_SetElementH(Element, H){
	Element=SS_GetElement(Element);
	if (Element){
		if (H!=null){
			Element.style.height=H+"px";
		} else {
			Element.style.height=null;
		}
	}
}


// Set the opacity of the given element between 0-100
function SS_SetElementOpacity(Element, Opacity){
	Element=SS_GetElement(Element);
	if (Element){
		if (Element.style.width){
			SS_SetElementW(Element, SS_GetElementW(Element)); // IE requires a width for setting opacity
		}
    	Element.style.visibility=(Opacity==0?"hidden":"visible");
	    Element.style.filter="alpha(opacity="+Opacity+")";
		Element.style.MozOpacity=Opacity/100;
		Element.style.KhtmlOpacity=Opacity/100;
		Element.style.opacity=Opacity/100;
	}
}


// Set the x, y of the given element
function SS_SetElementPosition(Element, X, Y){
	SS_SetElementX(Element, X);
	SS_SetElementY(Element, Y);
}



// Set the w, h of the given element
function SS_SetElementSize(Element, W, H){
	SS_SetElementW(Element, W);
	SS_SetElementH(Element, H);
}


// Dim the given element and disable its controls
// The element must have an ID
function SS_MaskElement(Element){
	Element=SS_GetElement(Element);
	if (Element){
		if (Element.id){
			var NewNode=null;
			NewNode=document.createElement("div");
			NewNode.id="MASK_"+Element.id;
			NewNode.style.backgroundColor="#000000";
			NewNode.style.border="1px dashed red";
			NewNode.style.position="absolute";
			SS_SetElementW(NewNode, SS_GetElementW(Element));
			SS_SetElementH(NewNode, SS_GetElementH(Element));
			SS_SetElementOpacity(NewNode, "30");
			Element.parentNode.insertBefore(NewNode, Element);
		}
	}
}


// Remove the mask added when using SS_MaskElement
// The element must have an ID as well as a previously created mask
function SS_UnMaskElement(Element){
	Element=SS_GetElement(Element);
	if (Element){
		if (Element.id){
			var ElementMask=SS_GetElement("MASK_"+Element.id);
			if (ElementMask!=null){
				ElementMask.parentNode.removeChild(ElementMask);
			}
		}
	}
}
