var Mozilla = (window.Event != null);
var IS_IE4 = (navigator.appVersion.indexOf("MSIE 4") != -1);
var IS_IE50 = (navigator.appVersion.indexOf("MSIE 5.0") != -1);
var IS_IE = (navigator.appVersion.indexOf("MSIE") != -1);
var is_Flash = false;
var is_FlashVersion = 0;
var InternetConnection = 0;

var CurrentForm = 1;

var	FocusObject = null;
var	Path;

if (document.getElementById("CountrySelectSpan")) document.getElementById("CountrySelectSpan").innerHTML = '<select id="CountrySelect" class="ArticleText" onchange="ChangeCountry()"><option value="">Select ...</option><option value="AUClick">Australia</option><option value="BEClick">Belgium</option><option value="BRClick">Brazil</option><option value="CAClick">Canada</option><option value="DKClick">Denmark</option><option value="EGClick">Egypt</option><option value="ECClick">Ecuador</option><option value="FIClick">Finland</option><option value="FRClick">France</option><option value="DEClick">Germany</option><option value="INClick">India</option><option value="HKClick">Hong Kong</option><option value="FRClick">Luxembourg</option><option value="SIClick">Malaysia</option><option value="NLClick">Nederlands</option><option value="NZClick">New Zealand</option><option value="DKClick">Norway</option><option value="PEClick">Peru</option><option value="PLClick">Poland</option><option value="DKClick">Sweden</option><option value="SIClick">Singapore</option><option value="TRClick">Turkey</option><option value="UKClick">United Kingdom</option><option value="USClick">United States</option></select>';
if (document.getElementById("CountrySelectSpan2")) document.getElementById("CountrySelectSpan2").innerHTML = '<select id="CountrySelect" class="ArticleText" onchange="ChangeCountry()"><option value="">Select ...</option><option value="AU">Australia</option><option value="BE">Belgium</option><option value="BR">Brazil</option><option value="CA">Canada</option><option value="DK">Denmark</option><option value="EG">Egypt</option><option value="EC">Ecuador</option><option value="FI">Finland</option><option value="FR">France</option><option value="DE">Germany</option><option value="IN">India</option><option value="HK">Hong Kong</option><option value="FR">Luxembourg</option><option value="SI">Malaysia</option><option value="NL">Nederlands</option><option value="NZ">New Zealand</option><option value="DK">Norway</option><option value="PE">Peru</option><option value="PL">Poland</option><option value="DK">Sweden</option><option value="SI">Singapore</option><option value="TR">Turkey</option><option value="UK">United Kingdom</option><option value="US">United States</option></select>';

function ChangeCountry()
{
	Country = document.getElementById("CountrySelect").value;
	if (Country.indexOf("Click") != -1)
	    document.location.href = eval('javascript:document.getElementById("' + Country + '")');
	else
	    document.location.href = "Localized/" + Country + ".html";
}

function IsNumeric(Value)
{
  var loop;

	if (Value == "")
	    return(false);
	for (loop=0; loop<Value.length; loop++)
	{
		if ((Value.charAt(loop) < "0") || (Value.charAt(loop) > "9"))
			return(false);
	}
	return(true);
}

function IsTelephoneNumber(Value)
{
	var loop;

	if (Value == "")
		return(false);
	
	for (loop=0; loop<Value.length; loop++)
	{
		if (((Value.charAt(loop) < "0") || (Value.charAt(loop) > "9")) && (Value.charAt(loop) != " ") && (Value.charAt(loop) != "-"))
			return(false);
	}

	return(true);
}

function IsEmail(email)
{
	invalidchars = " /:,;";
	
	if (email == "")
		return(false);
	
	for (i=0; i<invalidchars.length; i++)
	{
		badchar = invalidchars.charAt(i);
		if (email.indexOf(badchar, 0) > -1)
			return(false);
	}
	
	atPos = email.indexOf("@", 1);
	
	if (atPos == -1)
		return(false);
	
	periodpos = email.indexOf(".", atPos);
	
	if (periodpos == -1)
		return(false);
	
	if (periodpos+3 > email.length)
		return(false);
	
	return(true);
}

function Highlight(string, text)
{
	var strLength = string.length;
	
	txtLength = text.length;

	if ((strLength == 0) || (txtLength == 0))
		return string;

	LowerString = string.toLowerCase();
	
	var i = LowerString.indexOf(text);

	if ((! i) && (text != LowerString.substring(0,txtLength)))
		return string;
	
	if (i == -1)
		return string;

	var newstr = string.substring(0, i) + "<u>" + string.substring(i, i + txtLength) + "</u>";

	if ((i + txtLength) < strLength)
		newstr += Highlight(string.substring(i + txtLength, strLength), text);

	return newstr;	
}

function UpdateDiv(DivID, innerHTML)
{
	if (myGetElementById(DivID))
		myGetElementById(DivID).innerHTML = innerHTML;
	else
		alert("Cant find " + DivID);
}

function HideDiv(DivID)
{
	myGetElementById(DivID).style.display = "none";
}

function ShowDiv(DivID)
{
	myGetElementById(DivID).style.display = "";
}

function GetObject(ObjectName)
{
	return(myGetElementById(ObjectName));
}

function myGetElementById(ElementId)
{
  if (document.getElementById) return(document.getElementById(ElementId));
  else return(document.all(ElementId));
}

function SetFocus(ObjectName)
{
	if (document.all)
	{
		if (document.all[ObjectName])	
			document.all[ObjectName].focus();
	}
	else if (document.getElementById)
	{
		if (document.getElementById(ObjectName))
			document.getElementById(ObjectName).focus();
	}
	return(true);
}

/* ------------------------------------------------------------------------------------------------- */

function ReadCookie()
{
	if ((window.navigator.cookieEnabled) && (document.cookie != ""))
		CurrentForm = eval(GetCookieValue("GB_CF", CurrentForm));
}

/* ------------------------------------------------------------------------------------------------- */

function WriteCookie()
{
	var	Cookie1 = "";
	var expireDate;

	if (window.navigator.cookieEnabled)
	{
		expireDate = new Date;
		expireDate.setMinutes(expireDate.getMinutes()+5);
		document.cookie = "GB_CF=" + CurrentForm + "; path=/; expires=" + expireDate.toGMTString();
	}
}

/* ------------------------------------------------------------------------------------------------- */

function GetCookieValue(CookieName, DefaultValue)
{
	var	Value;
	
	if (document.cookie != "")
	{
		DocumentCookie = document.cookie.split("; ");
		for (i=0; i<DocumentCookie.length; i++)
		{
			items = DocumentCookie[i].split(",");
			for (u=0; u<items.length; u++)
			{
				if (CookieName == items[u].split("=")[0])
				{
					Value = UnProtectCookie(items[u].split("=")[1]);
					return(Value);
				}
			}
		}
	}
	return(DefaultValue);
}

/* ------------------------------------------------------------------------------------------------- */

function CookieVal(cookieName, DefaultValue)
{
	if (document.cookie != "")
	{
		thisCookie = document.cookie.split("; ");
		for (i=0;i<thisCookie.length;i++)
		{
			if (cookieName == thisCookie[i].split("=")[0])
			{
				return(thisCookie[i].split("=")[1]);
			}
		}
	}
	return(DefaultValue);
}

/* ------------------------------------------------------------------------------------------------- */

function ProtectCookie(CookieValue)
{
	CookieValue = CookieValue.replace(/;/g, "<<SEMI>>");
	return(CookieValue);
}

/* ------------------------------------------------------------------------------------------------- */

function UnProtectCookie(CookieValue)
{
	CookieValue = CookieValue.replace(/<<SEMI>>/g, ";");
	return(CookieValue);
}

/* ------------------------------------------------------------------------------------------------- */

function HideMenus()
{
	if ((MenuObject = myGetElementById("AWMEL0")))
		MenuObject.style.display = "none";
	if ((MenuObject = myGetElementById("AWMEL11")))
		MenuObject.style.display = "none";
}

function ShowMenus()
{
	if ((MenuObject = myGetElementById("AWMEL0")))
		MenuObject.style.display = "";
	if ((MenuObject = myGetElementById("AWMEL11")))
		MenuObject.style.display = "";
}

function ListMenus()
{
	var coll = document.getElementsByTagName("DIV");
	
 	for (i=0; i<coll.length; i++)
	{
		if (coll[i].id.indexOf("AWMEL") != -1)
			alert(coll[i].id);
	}
}

var PageReady = false;
window.onload = function() { PageReady = true;}

function MenuClick(MainMenu, SubMenu)
{
	var	NewPage;

	switch (MainMenu)
	{
		case 1 :
			document.location.href = Path + "/index.htm";
			break;
		case 2 :
			document.location.href = Path + "/features.htm";
			break;
		case 3 :
			document.location.href = Path + "/download.htm";
			break;
		case 4 :
			if (! PageReady)
				return;
			LaunchShop();
			break;
		case 5 :
			if (! PageReady)
				return;
			switch(SubMenu)
			{
				case 1 :
					setTimeout('FurtherInformation("systemhound 2009 Documentation", "http://www.systemhound.com/wiki", "systemhound", 800)', 500);
					break;
				case 2 :
					setTimeout('FurtherInformation("systemhound 2009 FAQ", "http://www.systemhound.com/wiki/index.php/FAQ_systemhound", "systemhound", 800)', 500);
					break;
				case 3 :
					setTimeout('FurtherInformation("systemhound 2009 Community", "http://www.systemhound.com/community/index.php", "systemhound", 800)', 500);
					break;
				case 4 :
					CurrentForm = 2;
					WriteCookie();
					document.location.href = Path + "/contact.htm";
					break;
			}
			break;
		case 6 :
			switch(SubMenu)
			{
				case 1 :
					CurrentForm = 1;
					WriteCookie();
					document.location.href = Path + "/contact.htm";
					break;
				case 2 :
					CurrentForm = 2;
					WriteCookie();
					document.location.href = Path + "/contact.htm";
					break;
				case 3 :
					CurrentForm = 3;
					WriteCookie();
					document.location.href = Path + "/contact.htm";
					break;
			}
			break;
		case 8 :
			switch(SubMenu)
			{
				case 1 :
					document.location.href = Path + "/comments.htm";
					break;
				case 2 :
					document.location.href = Path + "/case_studies.htm";
					break;
				case 3 :
					document.location.href = Path + "/about_us.htm";
					break;
			}
			break;
		case 7 :
			document.location.href = Path + "/news.htm";
			break;
		case 9 :
			document.location.href = Path + "/pricing.htm";
			break;
	}
}

function CheckReferrer()
{
	var Newpath;
	
	if (document.location.href.indexOf("?Contact!") != -1)
	{
		Newpath = Path + "/index.htm";
		myMessageBox("Error", "Failed to send your message to systemhound. Please try again and if the error persists email us directly at support@systemhound.com", Newpath);
	}
	else if (document.location.href.indexOf("?Contact") != -1)
	{
		Newpath = Path + "/index.htm";
		myMessageBox("Thank you", "Thanks for contacting us at systemhound, we will respond to your question shortly.", Newpath);
	}
}

function myMessageBox(MessageText, SubText, Target)
{
	var	HTML;
	
	HTML = '<DIV STYLE="position: absolute; left: ' + (((window.document.body.scrollLeft + window.document.body.scrollWidth) / 2) - 200) + 'px; top: ' + (window.document.body.scrollTop + 100) + 'px; height: 120px; width: 400px; padding: 1em; z-index:201">';
	HTML = HTML + '<table width="400" border="0" cellpadding="2" cellspacing="0" bgcolor="#6699CC"><tr><td><table width="400" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF"><tr><td colspan="3"><img src="Images/9002.jpg"></td></tr><tr><td colspan="3" align="center"><B>' + MessageText + '</B></td></tr><tr><td colspan="3" align="center"><span class="PageNumber">' + SubText + '</span></td></tr><tr><td colspan="3" align="center"><INPUT TYPE="BUTTON" onClick="HideMessage(\'' + Target + '\')" STYLE="width:50px" VALUE="OK"></td></tr></table></td></tr></table></DIV>';
	myGetElementById("Message").innerHTML = HTML;
	myGetElementById("Message").style.display = "";

	if (! Mozilla) myGetElementById("Mask").style.filter = 'alpha(opacity=20)';
	else myGetElementById("Mask").style.opacity = '0.2';
	myGetElementById("Mask").style.display = "block";
	myGetElementById("Mask").style.width = MaxWidth() + 'px';
	myGetElementById("Mask").style.height = MaxHeight() + 'px';
	myGetElementById("Mask").style.top = "0px";
	myGetElementById("Mask").style.left = "0px";
	HideMenus();
}

function MaxWidth()
{
	Width = screen.width;
	if (document.body.scrollWidth > Width)
		Width = document.body.scrollWidth;
	return(Width);
}

function MaxHeight()
{
	Height = screen.height;
	if (document.body.scrollHeight > Height)
		Height = document.body.scrollHeight;
	return(Height);
}

function HideMessage(Target)
{
	HideDiv("Message");
	HideDiv("Mask");
	ShowMenus();
	if (Target != "")
		document.location.href = Target;
	else if (FocusObject)
	{
		FocusObject.focus();
		if (FocusObject.select) FocusObject.select();
	}
}

function LaunchDemo()
{
	setTimeout('FurtherInformation("systemhound 2009 Demo", Path + "/Demo/Index.htm", "systemhound", 850)', 500);
}

function LaunchShop()
{
	setTimeout('FurtherInformation("systemhound 2009 Store", "http://www.systemhound.com/store/store.php", "systemhound", 825)', 500);
}

function FurtherInformation(ApplicationName, Page, Manufacturer, WindowWidth)
{
    ShowExternalPage(Page, true, WindowWidth);
}

function ShowExternalPage(PageRef, doHideMessage, WindowWidth)
{
	window.open(PageRef, "", "width=" + WindowWidth + ",height=600,resizable=yes,scrollbars=yes");
	if (doHideMessage) HideMessage('');
}

if ((document.location.href.indexOf("/helpdesk/") != -1) || (document.location.href.indexOf("/Localized/") != -1) || (document.location.href.indexOf("/Documents/") != -1))
	Path = '..';
else
	Path = '.';