//htmlutility.js
var m_CustomCubaTemplate = false;

//'HelveticaNeue-CondensedBold','Arial Narrow',Helvetica,Arial,sans-serif;

function NavigatePage(iPageId, bForceReload)
{
	if(bForceReload)
	{
		window.location.href = "Default.aspx?iPageId=" + iPageId + "&bShowThumbs=" + m_bShowThumbs + 
		"&SizeOR=" + m_ShrinkSiteOvR + "&admin=" + m_AdminMode + "&bNoSound=" + m_bNoSound + "#" +iPageId;
	}
	else if(iPageId > 0)
	{					
		LoadPageAsync(iPageId);	
		show("RightNavSpacer");
		show("LeftNavSpacer");
	}	
}

//debug
function a(sP1, sP2, sP3)
{
	GetE("DebugText").style.display = "inline";	
	GetE("DebugText").value += sP1;
	GetE("DebugText").scrollTop = GetE("DebugText").scrollHeight+20;

	
	GetE("DebugHtml").style.display = "inline";	
	GetE("DebugHtml").innerHTML += sP1;	
	
	if(sP2 != null)
	{
		GetE("DebugText").value += " -- " + sP2;
	}

	if(sP3 != null)
	{
		GetE("DebugText").value += " -- " + sP3;
	}	
	
	GetE("DebugText").value += "\n";		
}

function CenterSite()
{
	var iWinWidth = f_clientWidth();
	var iWinHeight = f_clientHeight();
	
	iAreaW = gw("PageDiv") + m_CenterSiteOffset;
	iAreaH = gh("PageDiv");
	
	var iNewHeight = (iWinHeight/2) - gh("PageDiv")/2;
	var iNewWidth = (iWinWidth/2) - iAreaW/2;
	
	if(iWinHeight > iAreaH +10)
	{
		st("PageDiv",iNewHeight);
		st("OutPageDiv", iNewHeight);
	}
    if ((iWinWidth > iAreaW + 10) || ((m_CenterSiteOffset > 0) && gl("PageDiv") > 10 && (iWinWidth < (iAreaW + 10)))) {
        if (iNewWidth > 10) {
            sl("PageDiv", iNewWidth);
            sl("OutPageDiv", iNewWidth);
        }
        else {
            sl("PageDiv", 10);
            sl("OutPageDiv", 10);
        }

    }		
	
	if(get("StatusFloatingDiv") !=null)
	{
		//GetE("StatusFloatingDiv").style.left = iNewWidth/2 - parseFloat(GetE("StatusFloatingDiv").style.width)/2;
		//GetE("StatusFloatingDiv").style.top = iNewHeight/2 - parseFloat(GetE("StatusFloatingDiv").style.height)/2;
	}
}

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() {
	
	if(window.innerHeight > 0)
	{
		return window.innerHeight;		
	}
	else
	{
		return document.body.clientHeight;
	}		
}

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;
}

function GetE(sId)
{
	return document.getElementById(sId);
}

function get(sId)
{
	return document.getElementById(sId);
}

function gw(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	return pi(oElement.style.width);
}

function gh(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	return pi(oElement.style.height);
}

function gt(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	return pi(oElement.style.top);
}

function gl(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	return pi(oElement.style.left);
}

function gb(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	return pi(oElement.style.bottom);
}

function togdisplay(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	if(shown(oElement))
	{
		hide(oElement);
	}
	else
	{
		show(oElement);
	}
}

function exists(oElement) {

	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}

    var bExists = false;
    if (typeof oElement != "undefined" && oElement != null) {
        bExists = true;
    }
    return bExists;
}

function shown(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	if(oElement.style.display != "none")
	{
		return true;
	}
	else
	{
		return false;
	}
}

function hide(oElement,bV) {

    if (!exists(oElement)) {
        return false;
    }
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	if(typeof oElement != "undefined" && oElement != null)
	{	
		if(bV)
		{
			oElement.style.visibility = "hidden";
		}
		else
		{
			oElement.style.display = "none";
		}		
	}
}

function show(oElement,bV) {

    if (!exists(oElement)) {
        return false;
    }
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	if(bV)
	{
		oElement.style.visibility = "visible";
	}
	else
	{
		oElement.style.display = "inline";
	}
}

function SetL(oElement, iValue)
{
	oElement.style.left = iValue;	
}

function SetT(oElement, iValue)
{
	oElement.style.top = iValue;	
}

function st(oElement, iValue) {
    if (!exists(oElement)) {
        return false;
    }

	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	iValue = parseFloat(iValue);
	
	oElement.style.top = fixN(iValue);	
}

function fixN(iValue) {
    if (isNaN(iValue)) {
        return 0;
    }
    else {
        return parseFloat(iValue);
    }
}

function sl(oElement, iValue) {
    if (!exists(oElement)) {
        return false;
    }

	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	iValue = parseFloat(iValue);

	oElement.style.left = fixN(iValue);	
}

function sr(oElement, iValue)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	iValue = parseFloat(iValue);
	
	oElement.style.right = iValue;	
}

function sb(oElement, iValue) {
    if (typeof oElement == "string") {
        oElement = GetE(oElement);
    }
    iValue = parseFloat(iValue);

    oElement.style.bottom = iValue;
}

function sh(oElement, iValue, bIsImg) {
    if (!exists(oElement)) {
        return false;
    }

	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	iValue = parseFloat(iValue);

	oElement.style.height = fixN(iValue);

	if (bIsImg) oElement.height = fixN(iValue);	
}

function sw(oElement, iValue, bIsImg) {
    if (!exists(oElement)) {
        return false;
    }

	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	iValue = parseFloat(iValue);

	oElement.style.width = fixN(iValue);	
	
	if(bIsImg) oElement.width = fixN(iValue);	
}

function sz(oElement, iValue)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	iValue = parseFloat(iValue);
	
	oElement.style.zIndex = iValue;		
}

function gz(oElement)
{
	if(typeof oElement == "string")
	{
		oElement = GetE(oElement);
	}
	
	return parseFloat(oElement.style.zIndex)
}

function sdim(oE, itop, ileft, iw, ih, bIsImg, zIn)
{
	if(itop != null && itop != undefined) st(oE,itop);
	if(ileft != null && ileft != undefined) sl(oE,ileft);
	if(iw != null && iw != undefined) sw(oE,iw, bIsImg);
	if(ih != null && ih != undefined) sh(oE,ih, bIsImg);
	if(zIn != null && zIn != undefined) sz(oE,zIn);
}

function SetH(oElement, iValue)
{
	oElement.style.height = iValue;	
	
}

function SetW(oElement, iValue)
{
	oElement.style.width = iValue;	
}

function ValueInArray(sValue, oArrayToSearch, argStrict) 
{
	
   for(var i=0; i<oArrayToSearch.length;i++)
   {
		//alert("in here--" +sValue + "--" + oArrayToSearch[i]);
		if(sValue == oArrayToSearch[i])
		{
			return true;
		}
   }
   
   return false;
} 

function DoSpecialStuffForIphone()
{
	if(DetectIphoneOrIpod())
	{
		show("LeftNav",true);
		show("RightNav",true);		
		get("PageTitleTd").noWrap = false;
	}	
}

function pi(sString)
{
	return parseFloat(sString);
}
