function toggleVisibility(id)
{
	var el = document.getElementById(id).style;
	if(el.display == "none")
	{
		el.display = "block";
	}
	else if(el.display == "block")
	{
		el.display = "none";
	}
}

function decideWhatToLoad(orderInfoURL)
{
	//alert(orderInfoURL);
	var loadGuestCheck = getQSParameterValue('LoadGuestCheck');
	if(loadGuestCheck == "true")
	{
		return "http://www.kudzuinteractive.com/Applications/ETG/Core/LoadGuestCheck.aspx";
	}
	else
	{
		return orderInfoURL;
	}
}

function decideWhatToLoad(orderInfoURL, etg)
{
	decideWhatToLoad(orderInforURL, etg, getQSParameterValue('SiteID'))
}

function decideWhatToLoad(orderInfoURL, etg, siteID)
{
    var signIn = etg + 'SignIn.aspx?SiteID=' + siteID
    var loadGuestCheck = getQSParameterValue('ShowCheck');
    var kudTranID = getQSParameterValue('KudTranID');
    var customerID = getQSParameterValue('CustomerID');
    var callTranID = getQSParameterValue('CallTranID');
    var noSignIn = getQSParameterValue('NoSignIn');

    // Sent from ETG to keep us from getting in a loop
    if (noSignIn == "True")
    {
		return orderInfoURL;
	}

    var currentUri = parseUri(window.location.href);
    var appPath = currentUri.protocol + "://" + currentUri.domain + currentUri.directoryPath;
	var welcomePage = appPath + orderInfoURL + '?SiteID=' + siteID;
	var url = etg + 'SignIn.aspx' + parent.location.search;
	if (parent.location.search.indexOf('SiteID') < 0)
	{
		url += '&SiteID=' + siteID;
	}
    return url += '&WelcomePage=' + welcomePage;
}

function getQSParameterValue(parameterName)
{
	var query = window.location.search.substring(1);
	if(query == null)
		return "doNothing";
	var parms = query.split('&');
	var value = "false";
	for (var i=0; i<parms.length; i++)
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			if (key.toLowerCase() == parameterName.toLowerCase())
			{
				value = val;
				break;
			}
		}
	}
	return value;
}
function enableOrdering()
{
	var divValue="<%=divValue%>";
	if (divValue==0 )
	{
		if (navigator.appName == "Netscape")
		{
			layer = window.parent.frames[0].document.getElementById("topDiv");
			if (layer)
			{
				layer.style.height="0";
				layer.style.width= "0";
				layer.style.zorder = -100;
				layer.style.zIndex = -100000;
				window.parent.frames[0].doRefresh = 0;
			}
		}
		else
		{
			layer = window.parent.frames[0].document.all.item("topDiv");
			if (layer)
			{
				layer.style.height="0";
				layer.style.width= "0";
				layer.style.zorder = -100;
				layer.style.zIndex = -100000;
				window.parent.frames[0].doRefresh = 0;
			}
		}
	}
}
function toggleOrdering()
{
		var shouldDisable = getQSParameterValue('Disable');
		if(shouldDisable == "doNothing")
			return;
		if(shouldDisable == "true")
			disableOrdering();
		else
			enableOrdering();
}
function disableOrdering()
{
		try
		{
			if (navigator.appName == "Netscape")
			{

				var frameIndex;
				for (frameIndex =0;frameIndex <= window.parent.frames.length-1; frameIndex++)
				{

				var layer = window.parent.frames[frameIndex].document.createElement('div');
				layer.name = 'topDiv';
				layer.id = 'topDiv'
				layer.style.position = 'absolute';

				layer.style.left = '0px';
				layer.style.top = '0px';

				layer.style.width = window.parent.frames[frameIndex].document.body.scrollWidth;
				layer.style.height = window.parent.frames[frameIndex].document.body.scrollHeight;
				layer.oncontextmenu = new Function("return false");

				layer.style.backgroundColor = 'transparent';

				window.parent.frames[frameIndex].document.body.appendChild(layer);
				window.parent.frames[frameIndex].doRefresh = 1;
				}
			}
			else
			{
				var frameIndex;
				for (frameIndex =0;frameIndex <= window.parent.frames.length-1; frameIndex++)
				{

				layer = window.parent.frames[frameIndex].document.getElementById("topDiv");
				if (layer)
				{
				}
				else
				{
					window.parent.frames.item(frameIndex).document.body.innerHTML =  "<DIV id='topDiv' style='position:absolute;top:0;left:0;width:0;height:0;z-index=100;background: transparent url(test.gif)' ms_positioning='FlowLayout' onClick='alert(\" Please wait while your order is being processed\")' oncontextmenu='return false' ><\/DIV> " +  window.parent.frames.item(frameIndex).document.body.innerHTML;
				}
				window.parent.frames.item(frameIndex).topDiv.style.height=window.parent.frames.item(frameIndex).document.body.scrollHeight;
				window.parent.frames.item(frameIndex).topDiv.style.width=window.parent.frames.item(frameIndex).document.body.scrollWidth;
				window.parent.frames.item(frameIndex).topDiv.style.zorder = 100;
				window.parent.frames.item(frameIndex).topDiv.style.zIndex = 100000;
				window.parent.frames[frameIndex].doRefresh = 1;
				}
			}
		}
	catch (e)
	{
		/*alert(e);*/
	}
}

// Keeps the session from timing out
function refreshSession()
{
   var xmlHttp;
   if (navigator.appName.substring(0,9) == "Microsoft")
   {
      var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   else
   {
      var xmlHttp = new XMLHttpRequest();
   }

   xmlHttp.open("GET", "http://www.kudzuinteractive.com/Menus/Refresh.aspx?xxx=" + escape(new Date()), false);
   xmlHttp.send();

   timer = setTimeout('refreshSession()', 900000);
}

/* Splits any well-formed URI into the following parts (all are optional):
----------------------
 source (since the exec() method returns backreference 0 [i.e., the entire match] as key 0, we might as well use it)
 protocol (scheme)
 authority (includes both the domain and port)
     domain (part of the authority; can be an IP address)
     port (part of the authority)
 path (includes both the directory path and filename)
     directoryPath (part of the path; supports directories with periods, and without a trailing backslash)
     fileName (part of the path)
 query (does not include the leading question mark)
 anchor (fragment)
*/
function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};

    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }

    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }

    return uri;
}

function openPrivacyDoc()
{
	var iY = 400;
	var iX = 500;
	var leftVal = (iY - screen.width) / 2;
	var topVal = (iX - screen.height) / 2;
	var stuff = "height=" + iX + ",width=" + iY + "left="+ leftVal + ",top=" + topVal + ",toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no";
	window.open('http://www.KudzuInteractive.com/Docs/PrivacyPolicy.HTM', '',stuff);
}
