function NoPostBack(url)
{
	var viewState;
	var selectArr;
	var inputArr;
	
	document.getElementById("Form1").action = url;
		
	viewState = document.getElementsByName("__VIEWSTATE");
	viewState[0].value = "";
	viewState[0].name = "_NADA";
		
	document.getElementById("Form1").submit();
	
	
}

function noPostBack(classLink)
{
	var viewState;
	viewState = document.getElementsByName("__VIEWSTATE");
	viewState[0].value = "";
	viewState[0].name = "_NADA";
	
	document.getElementById("Form1").action = "SectionListing.aspx?link="+classLink;
	document.getElementById("Form1").submit();
	
}

function CheckEnter(event, oObj) { //check for the enter key and then execute the click command of the oObj

	var key = (window.event) ? event.keyCode : event.which;
	if(key == 13)
	{
		oObj.click();
	}
}

function CheckExpand()
{
	var beforeHeight;
	var afterHeigh;
	var beforeWidht;
	var afterWidth;
	var tableCell;
	var link;
	for(i = 1; i < 32; i++)
	{
		tableCell = document.getElementById(parseInt(i));
		if(tableCell != null)
		{
			beforeHeight = tableCell.offsetHeight;
			beforeWidth = tableCell.offsetWidth;
			tableCell.style.overflow = "scroll";
			afterHeight = tableCell.scrollHeight;
			afterWidth = tableCell.scrollWidth;
			tableCell.style.overflow = "hidden";
			if(afterHeight > beforeHeight || afterWidth > beforeWidth)
			{
				link = document.getElementById('link'+i);
				link.style.display = 'block';
				link.href = 'javascript:ExpandCell("'+i+'");'; 
			}
		}
	}
}

function doNothing()
{
	//do nothing;
}

var prevCellId = "";

function CleanUpOldExpand(cellId)
{
	if(prevCellId != "")
	{
		var prevLink = document.getElementById('link'+prevCellId);
		prevLink.innerHTML = 'Expand';
		prevLink.href = 'javascript:ExpandCell("'+prevCellId+'")';
	}
	prevCellId = cellId;
}

function ExpandCell(cellId)
{
	CleanUpOldExpand(cellId);
	var cell = document.getElementById(cellId);
	var posArray = findPos(cell);
	var div = document.getElementById('expandView');
	var link = document.getElementById('link'+cellId);
	var cellWidth = parseInt(new String(document.getElementById(cellId).currentStyle['width']).replace('px',''));
	var cellHeight = parseInt(new String(document.getElementById(cellId).currentStyle['height']).replace('px',''));
	var divWidth = parseInt(new String(document.getElementById('expandView').currentStyle['width']).replace('px',''));
	var divHeight = parseInt(new String(document.getElementById('expandView').currentStyle['height']).replace('px',''));
	var cellWidthInterval = (divWidth - cellWidth)/10;
	var cellHeightInterval = (divHeight - cellHeight)/10;
	
	link.innerHTML = 'Close';
	link.href = 'javascript:CloseCell("'+cellId+'")';
	div.innerHtml = '';
	div.style.left = posArray[0];
	div.style.top = posArray[1];
	div.style.visibility = 'visible';
	document.getElementById('expandView').style['width'] = cellWidth;
	document.getElementById('expandView').style['height'] = cellHeight;
	DivExpand('expandView', cellWidth, cellHeight, cellWidthInterval, cellHeightInterval, divWidth, divHeight);
	div.innerHTML = '<table width="100%">'+document.getElementById(cellId).innerHTML + '</table>';
}

function DivExpand(div, cellWidth, cellHeight, cellWidthInterval, cellHeightInterval, divWidth, divHeight)
{
	if(cellWidth < divWidth || cellHeight < divHeight)
	{
		cellWidth = cellWidth + cellWidthInterval;
		cellHeight = cellHeight + cellHeightInterval;
		document.getElementById(div).style['width'] = cellWidth+'px';
		document.getElementById(div).style['height'] = cellHeight+'px';
		setTimeout("DivExpand('"+div+"', "+cellWidth+", "+cellHeight+", "+cellWidthInterval+","+cellHeightInterval+","+divWidth+","+divHeight+")", 15);
	}
	else
	{
		document.getElementById(div).style['width'] = divWidth+'px';
		document.getElementById(div).style['height'] = divHeight+'px';
		return false;
	}
}

function CloseCell(cellId)
{
	var div = document.getElementById('expandView');
	var link = document.getElementById('link'+cellId);
	var cellWidth = parseInt(new String(document.getElementById(cellId).currentStyle['width']).replace('px',''));	
	var cellHeight = parseInt(new String(document.getElementById(cellId).currentStyle['height']).replace('px',''));
	var divWidth = parseInt(new String(div.style.width).replace('px',''));
	var divHeight = parseInt(new String(div.style.height).replace('px',''));
	var cellWidthInterval = (divWidth - cellWidth)/10;
	var cellHeightInterval = (divHeight - cellHeight)/10;
	link.innerHTML = 'Expand';
	link.href = 'javascript:ExpandCell("'+cellId+'")';
	DivClose('expandView', divWidth, divHeight, cellWidth, cellHeight, cellWidthInterval, cellHeightInterval, divWidth, divHeight);
}

function DivClose(div, divWidth, divHeight, cellWidth, cellHeight, cellWidthInterval, cellHeightInterval, divWidthSave, divHeightSave)
{
	if(divWidth > cellWidth || divHeight > cellHeight)
	{
		divWidth = divWidth - cellWidthInterval;
		divHeight = divHeight - cellHeightInterval;
		document.getElementById(div).style.height = divHeight+'px';
		document.getElementById(div).style.width = divWidth+'px';
		setTimeout("DivClose('"+div+"', "+divWidth+", "+divHeight+", "+cellWidth+","+cellHeight+", "+cellWidthInterval+","+cellHeightInterval+","+divWidthSave+","+divHeightSave+")", 15);
	}
	else
	{
		document.getElementById(div).innerHTML = '';
		document.getElementById(div).style.visibility = 'hidden';
		document.getElementById(div).style['width'] = divWidthSave+"px";
		document.getElementById(div).style['height'] = divHeightSave+"px";
		return false;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function ViewCart()
{
	location.href = "ShoppingCart.aspx";
}

function DecrementCart()
{
	document.getElementById("cartCount").value = parseInt(document.getElementById("cartCount").value) - 1;
	document.getElementById("viewCartLink").innerHTML = document.getElementById("cartCount").value + " Item(s) in cart"
}

function GetRandom()
{
	var dte = new Date();
	var random = ''+dte.getDay()+''+dte.getFullYear()+''+dte.getHours()+''+dte.getMinutes()+''+dte.getSeconds()+''+dte.getMilliseconds();
	return(random);
}

function CheckResults(result, surveys)
{
	var resultStr = new String(result);
	if(resultStr.indexOf("Approved") >= 0)
	{
		if(surveys == "")
		{
			document.location.replace("TransactionComplete.aspx");
		}
		else {
		    alert("This previously would have redirected to the survey page, disabling for now as survey will be taken through the 'Take Survey' button instead");
			//document.location.replace("Surveys.aspx");
		}
	}
	else
	{
		document.location.replace('Checkout.aspx?error='+resultStr);
	}
}



function RefreshCart()
{
	if(document.getElementById("viewCartLink") != null)
	{
		if(document.getElementById("cartTable").style.display != null && 
			document.getElementById("cartTable").style.display.toUpperCase() != "NONE")
		{
			runPage("ShoppingCart.aspx?from=getCount&random="+GetRandom(),"GetCartVerbiage(oReq.responseText);");
		}
	}
}

function GetCartVerbiage(cartNumber)
{
	var itemStr = "Item";
	var cartNumberStr = new String(cartNumber);
	var cartNumberArr = cartNumberStr.split("|");
	var cartNumber = new String(cartNumberArr[0]);
	var cartText = new String(cartNumberArr[2]);
	var locationStr = new String(document.location.href);
	if(cartNumber != "1")
	{
		itemStr = itemStr + "s";
	}
	document.getElementById("viewCartLink").innerHTML = cartText +  "("+cartNumber+" "+itemStr+")";
	if(locationStr.indexOf("SectionListing.aspx") >= 0)
	{
		DisableRadios(cartNumberArr[1]);
	}
}

function DisableRadios(linksInCart)
{
	var disabledStr = new String(linksInCart);
	var newCheck = false;
	for(var i = 0; i < document.Form1.length; i++)
	{
		if(document.Form1.elements[i].type.toUpperCase() == "RADIO")
		{
			if(disabledStr.indexOf(document.Form1.elements[i].value) >= 0)
			{
				document.Form1.elements[i].disabled = true;
			}
			else if(!newCheck)
			{
				document.Form1.elements[i].checked = true;
				newCheck = true;
			}
		}
	}
}

