/**************************************************************************/
//	<<<<<<<<<<<<<<	[VERSION 1.0]	>>>>>>>>>>>>>>
//	<summary>
//		Created By		:	Asif Ahmed
//		Company			:	WebonRetail
//		Creation Date	:	05th June 2009
//		Date Modified	:	30 September 2009
//		Dependencies	:	None
//		Website			:	www.WebonRetail.com; 
//		Email			:	asif.ahmed01@gmail.com
//		Copyright (c) 2009 WebonRetail Private Limited. All rights reserved.
//	</summary>
/**************************************************************************/

//==============	Begin Modal Popup Extender Code	=====================//
	var DisableLayer = "PopUpLayer"; 
	var TopLayer;
	
	var lobjTimeout_FadeOutModelPopUpExtender = "NON";
	var lobjTimeout_opacity;

	function HideModelPopUpExtender()
	{
			window.document.getElementById(DisableLayer).style.visibility ='hidden';
			window.document.getElementById(TopLayer).style.visibility ='hidden';
			
			window.document.getElementById(TopLayer).style.left = -5000 + "px";
			window.document.getElementById(TopLayer).style.top = -5000 + "px";
			
			window.document.getElementById(DisableLayer).style.width = 0 + "px";
			window.document.getElementById(DisableLayer).style.height = 0 + "px";

			window.document.getElementById(TopLayer).style.width = "auto";
			window.document.getElementById(TopLayer).style.height = "auto";
	}
	function ShowModelPopUpExtender(TopLayerID)
	{
		var LayerWidth, LayerHeigt;
		var LayerLeftPosition, LayerTopPosition;

		var clientWindowInnerWidth = window.document.body.clientWidth;
		var clientWindowInnerHeight = window.document.body.clientHeight

		// set global variables//
		TopLayer = TopLayerID;
		
		LayerWidth = parseInt(window.document.getElementById(TopLayer).offsetWidth); 
		//=====JavaScript Browser Detection for Remove Close button Space======//
		if (navigator.appName == "Microsoft Internet Explorer")	{
			LayerHeigt = parseInt(window.document.getElementById(TopLayer).offsetHeight) - 4;
		} else	{
			LayerHeigt = parseInt(window.document.getElementById(TopLayer).offsetHeight);
		}
		window.document.getElementById(TopLayer).style.width = LayerWidth + "px";
		window.document.getElementById(TopLayer).style.height = LayerHeigt + "px";

		if(window.document.getElementById(DisableLayer).offsetParent)	{
			window.document.getElementById(DisableLayer).style.width = 100 + "%";
			window.document.getElementById(DisableLayer).style.height = 100 + "%";			
			if(window.document.getElementById(DisableLayer).offsetParent.scrollWidth > 0)	{
				clientWindowInnerWidth = window.document.getElementById(DisableLayer).offsetParent.scrollWidth;
			}
			if(window.document.getElementById(DisableLayer).offsetParent.scrollHeight > 0)	{
				clientWindowInnerHeight = window.document.getElementById(DisableLayer).offsetParent.scrollHeight;
			}
		}
		window.document.getElementById(DisableLayer).style.width = clientWindowInnerWidth + "px";
		window.document.getElementById(DisableLayer).style.height = clientWindowInnerHeight + "px";

		LayerLeftPosition =  Math.floor((clientWindowInnerWidth - LayerWidth) / 2);
		LayerTopPosition =  Math.floor((clientWindowInnerHeight - LayerHeigt) / 2);
		if(AA_getDocHeight() > (AA_GetScrollPosition()[1] + window.document.getElementById(TopLayer).offsetHeight + 20))	{
			LayerTopPosition = AA_GetScrollPosition()[1] + 20;
		}	else	{
			LayerTopPosition = AA_getDocHeight() - (window.document.getElementById(TopLayer).offsetHeight + 20);
		}
		if(LayerLeftPosition < 1) { LayerLeftPosition = 0; }
		if(LayerTopPosition < 1) {	LayerTopPosition = 0; }
		window.document.getElementById(TopLayer).style.left = LayerLeftPosition + "px";
		window.document.getElementById(TopLayer).style.top = LayerTopPosition + "px";

		window.document.getElementById(DisableLayer).style.visibility ='visible';
		window.document.getElementById(TopLayer).style.visibility ='visible';
		
		
		FadeInModelPopUpExtender();
	}
//==============	End Modal Popup Extender Code	=====================//
	function FadeOutModelPopUpExtender()
	{
		if(lobjTimeout_FadeOutModelPopUpExtender == "NON")
		{
			window.clearTimeout(lobjTimeout_FadeOutModelPopUpExtender);
			window.clearTimeout(lobjTimeout_opacity);
			opacity(TopLayer, 100, 0, 1000);
			opacity(DisableLayer, 80, 0, 1000);
			lobjTimeout_FadeOutModelPopUpExtender = setTimeout("ChackOpacityModelPopUpExtender()", 1000);
		}
	}
	function ChackOpacityModelPopUpExtender()
	{
		var object = document.getElementById(DisableLayer).style; 
		if(object.opacity <= 2 || object.MozOpacity <= 2 || object.KhtmlOpacity <= 2 || object.filter <= 2 )
		{
			HideModelPopUpExtender();
			//clearTimeout();
			window.clearTimeout(lobjTimeout_FadeOutModelPopUpExtender);
			window.clearTimeout(lobjTimeout_opacity);
			lobjTimeout_FadeOutModelPopUpExtender = "NON";
		}
	}
	function FadeInModelPopUpExtender()
	{
		changeOpac(0, TopLayer)
		changeOpac(0, DisableLayer)
		opacity(TopLayer, 0, 100, 1000);
		opacity(DisableLayer, 0, 80, 1000);
	}
//==============	Begin Fade Effect Function	=====================//
	function opacity(id, opacStart, opacEnd, millisec) {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				lobjTimeout_opacity = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				lobjTimeout_opacity = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	}
	//change the opacity for different browsers
	function changeOpac(opacity, id) {
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
//==============	End Fade Effect Function	=====================//
//==============	Begin Navigation Hover Function	=====================//
	function navigationHover()
	{
		var e = document.getElementsByTagName("a");
		var href, id, lstrFileName, URLFileName, winLocation, ext;
		for(var i=0;i<e.length;i++){
			href = e[i].getAttribute('href');
			winLocation = window.location.href;
			lstrFileName = href.substr(href.lastIndexOf("/") + 1, href.length).toLowerCase();
			URLFileName = winLocation.substr(winLocation.lastIndexOf("/") + 1, winLocation.length).toLowerCase();
			ext = URLFileName.substr(URLFileName.lastIndexOf(".") + 1, URLFileName.length).toLowerCase();
			if(ext == '.htm' || ext == '.html')	URLFileName = "";
			if(((URLFileName.indexOf(lstrFileName) != -1) || ((URLFileName.indexOf('default.htm') != -1 || URLFileName.indexOf('default.html') != -1 || URLFileName.indexOf('index.htm') != -1 || URLFileName.indexOf('index.html') != -1) && URLFileName.length == 0)) && e[i].className.indexOf('link_Menu_Wor') != -1)	{
				e[i].className = e[i].className.replace("link_Menu_Wor","link_Menu_Hover_Wor ");
				e[i].href = "javascript:void(0)";
				break;
			}
		}
	}
//==============	End Navigation Hover Function	=====================//
//==============	Begin Function Get Scroll Position	=====================//
function AA_GetScrollPosition ()	
{
	//Get Scrollbar top position 
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)		{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	//Get Scrollbar left position 
	var ScrollLeft = document.body.scrollLeft;
	if (ScrollLeft == 0)	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	return [ScrollLeft, ScrollTop];
}
//alert('Scroll Left Position = ' + GetScrollPosition()[0] + '\n\n\n Scroll Top Position = ' + GetScrollPosition()[1]);
//==============	End Function Get Scroll Position	=====================//
//==============	Begin Function Get Document Height	=====================//
function AA_getDocHeight() {
    var b = document.body, e = document.documentElement;
    var esh = 0, eoh = 0, bsh = 0, boh = 0;
    if (e) {
        esh = e.scrollHeight;
        eoh = e.offsetHeight;
    }
    if (b) {
        bsh = b.scrollHeight;
        boh = b.offsetHeight;
    }
	if(boh <= 0) boh = Math.max(esh, eoh, bsh, boh);
	return boh;
    //return Math.max(esh, eoh, bsh, boh);
}
//==============	End Function Get Document Height	=====================//
//==============	Begin Function Get Document Width	=====================//
function AA_getDocWidth() {
    var b = document.body, e = document.documentElement;
    var esw = 0, eow = 0, bsw = 0, bow = 0;
    if (e) {
        esw = e.scrollWidth;
        eow = e.offsetWidth;
    }
    if (b) {
        bsw = b.scrollWidth;
        bow = b.offsetWidth;
    }    
    return Math.max(esw, eow, bsw, bow);
}
//==============	End Function Get Document Width	=====================//
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
