﻿var curBusCard = 0;
var HLP_SHOW_POS_MOUSE = 0;
var HLP_SHOW_POS_CENTER = 1;
var HLP_SHOW_POS_V_MOUSE_H_CENTER = 2;
var HLP_SHOW_POS_V_MOUSE_ABOVE_H_CENTER = 3;

function ShowImg(obj)
{
	obj.style.visibility = 'visible';
}




function ShowLarge(obj)
{
    var largeSrc = obj.src.replace ("_thumb", "");
    document.getElementById("largeImg").src = largeSrc;
}




function ToggleCats()
{
    var div = document.getElementById(cbId);
    var lnk = document.getElementById(ctLnk);
    
    var curDisp = div.style.display;
    div.style.display = (curDisp == "none") ? "block" : "none";
    lnk.innerHTML = (lnk.innerHTML == "Hide ^") ? "Show v" : "Hide ^";
    SetCookie("cCB", (div.style.display == "none") ? false : true, false);
}




function ShowHideBusiness(show, id)
{
    if (curBusCard > 0)
    {
        var old = document.getElementById("bc" + curBusCard);
        old.style.display = "none";
    }
    curBusCard = id;
    var div = document.getElementById("bc" + id);
    div.style.display = show ? "block" : "none";
    
    if (show == true)
    {
        var height = GetWindowSize(false);
        var posY = FindPosY(div);
        var objHeight = FindHeight(div);
        var bottom = posY + objHeight;
        if (bottom > (height - 25))
        {
            var delta = bottom - height;
            var newPos = posY - delta;
            //alert (posY + ", " +  delta + ", " + newPos);
            div.style.marginTop = ((delta * -1) - 50) + 'px';
        }
        else
        {
            div.style.marginTop = '0px';
        }
    }
}




function SetCookie(name, value, isSession) 
{
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	
	var newCookie = name + "=" + value + "; "
	if (isSession == false)
		newCookie += "expires=" + expDate.toGMTString();
	document.cookie = newCookie;
}




function GetCookie(name) 
{
	var allCookies = String(document.cookie);	
	var cookieStart = allCookies.indexOf(name);
	if(cookieStart != -1) 
	{
		cookieStart = cookieStart + name.length + 1;
		var cookieEnd = allCookies.indexOf(";", cookieStart);
		if(cookieEnd = -1) cookieEnd = allCookies.length
			return allCookies.substring(cookieStart, cookieEnd);
	} 
	else 
	{
		return false;
	}
}




function GetWindowSize(getWidth) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth + ', Height = ' + myHeight);
  if (getWidth) 
    return myWidth
  else
    return myHeight
  
}




function FindPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
    {
        while(1) 
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if(obj.x)
    {
        curleft += obj.x;
    }
    return curleft;
}




function FindPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
    {
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if(obj.y)
    {
        curtop += obj.y;
    }
    return curtop;
}



function FindHeight(obj)
{
    return (obj.offsetHeight);
}



function FindWidth(obj)
{
    return (obj.offsetWidth);
}



function CountChars(max, e, tgtId)
{
    var tgt = document.getElementById(tgtId);
    //alert (tgt.id);
    var data = e.value;
    data = data.replace("\r", "");
    data = data.replace("\n", "");
    var chrs = max - data.length;
    if (chrs < 0)
    {
      tgt.innerHTML = (chrs * -1) + " character" + ((chrs == -1) ? "" : "s") + " too many";
    }
    else
    {
      tgt.innerHTML = chrs + " character" + ((chrs == 1) ? "" : "s") + " left";
    }

}



function Mtf(e)
{
	var p = '\u006d\u0061\u0069\u006c\u0074\u006f\u003a';
	void(top.location = p + e);
	return false;
}


function ShowHelp (e, text, showPos, width)
{
    var posx = 0;
    var posy = 0;
    if (width == null)
    {
        width = 250;
    }
    switch (showPos)
    {
		case HLP_SHOW_POS_MOUSE:
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
			    //Moz
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
			    //IE
				posx = e.clientX;
				posy = FindPosY(e.srcElement) + FindHeight(e.srcElement);;
			}
			break;
			
		case HLP_SHOW_POS_CENTER:
			//Get screen dims
			var winWidth = GetWindowSize(true);
			var winHeight = GetWindowSize(false);
			posx = (winWidth / 2);
			posy = (winHeight / 2) - 85; //100-15
			break;
			
		case HLP_SHOW_POS_V_MOUSE_H_CENTER:
			var winWidth = GetWindowSize(true);
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
			    //Moz
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
			    //IE
				posy = FindPosY(e.srcElement) + FindHeight(e.srcElement);
			}
			posx = (winWidth / 2);
			break;
			
		case HLP_SHOW_POS_V_MOUSE_ABOVE_H_CENTER:
			var winWidth = GetWindowSize(true);
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
				posy = e.pageY - 250;
			}
			else if (e.clientX || e.clientY)
			{
				posy = e.clientY - 250;
			}
			posx = (winWidth / 2);
			break;
    }

    var helpObj = document.getElementById("helpBox");
    var helpInner = document.getElementById("helpBoxInner");
    helpObj.style.display = 'block';
    helpInner.innerHTML = text;
    helpObj.style.left = (posx - (width / 2)) + "px";
    helpObj.style.top = (posy + 15) + "px";
    helpObj.style.width = width + "px";
    helpInner.style.width = (width - 5) + "px";
    

}



function HideHelp()
{
    var helpObj = document.getElementById("helpBox");
    helpObj.style.display = 'none';

}