// JavaScript Document
function MarkReceived($url,tradeId)
{
	if(confirm("Are you sure to mark this game as received?"))
	{
		location.href = $url+"?action=markReceived&tradeId="+tradeId;
	}
}

function CheckStateZipBox(form, selectedCountry)
{
	if(selectedCountry == "US")
	{
		form.txtZipCode.disabled = false;
		form.txtState.disabled = false;
	}
	else
	{
		form.txtZipCode.disabled = true;
		form.txtState.disabled = true;
		form.txtZipCode.value="";
		form.txtState.selectedIndex = 0;
	}
}

function CheckAddress(form)
{
	if(form.chkAddress.checked)
	{
		if (form.txtAddress.value.length<1)
		{
			alert("You have not entered your mailing address. Please enter your mailing address.");
			form.chkAddress.checked = false;
			form.txtAddress.focus();
			return false;
		}
		else if(form.txtAddress.value.length<5)
		{
			alert("The mailing address that you've entered is too short ");
			form.chkAddress.checked = false;
			form.txtAddress.focus();
			return false;
		}
	}
	else
	{
//		form.Submit.disabled = true
		return false;
	}
}

function SubmitRegForm2(form)
{
	if (form.chkAddress.checked)
	{
		if (form.chkAgree.checked == false)
		{
			alert("You have to agree to our terms and conditions before proceeding");
		}
		else
		{
			form.submit();
		}
	}
	else
	{
		alert ("You have to check that your address is correct.");		
		return false;
	}
	return false;
}

function SubmitProfileUpdateForm(form)
{
	if (form.chkAddress.checked)
	{
		form.submit();
	}
	else
	{
		alert ("You have to check that your address is correct.");		
		return false;
	}
	return false;
}


function SubmitGameForm(form, action)
{
	form.action = action;
	form.submit();
}


function CheckProceedButton(form, chkBox)
{
	if(chkBox.checked)
	{
		
		form.Submit.disabled = false;
	}
	else
	{
		form.Submit.disabled = true;
	}
}


function SubmitGameForm1(form)
{
	var valid = false;
	var gameName = form.txtGameName.value;
	if(gameName.length<1)
	{
		return false;
	}
	for(i=0;i<form.txtAcceptableGame.length;i++)
	{
		if(form.txtAcceptableGame[i].value.length>0)
		{
			valid = true;
		}
		form.txtAcceptableGame[i].name = form.txtAcceptableGame[i].name+"[]";
	}
	if(valid)
	{
		form.action = "submitgame.php";
	}
	return valid;
}

function CheckDateFormat(date)
{
	alert(date);
	alert(date.search("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})"));
}

function CalculateSaving()
{
	var totalGame = document.getElementById("txtTotalGame").value;
	var avgCost = document.getElementById("txtAvgCost").value;
	var nonNumeric = /\D/;
	error = "";
	if (totalGame.match(nonNumeric) || avgCost.match(nonNumeric))
	{
		error = "Please provide valid information for calculation.\r\n";
		if (totalGame.match(nonNumeric))
		{
			error += "No. of games should be integer number.\r\n";
		}
		if (avgCost.match(nonNumeric))
		{
			error += "Please provide integer value in average cost.\r\n";
		}
	}
	if (error.length > 0)
	{
		alert (error);
		return;
	}
	var totalBuyingCost = new String(totalGame * avgCost);
	var transactionCost = new String(12 * 9.99);
	var totalTradingCost = new String(transactionCost);
	var saving = new String(totalBuyingCost - totalTradingCost);
	document.getElementById("txtTotalBuyingCost").value = "$" + totalBuyingCost;
	document.getElementById("txtTransactionCost").value = "12 X 9.99 = $" + transactionCost.substring(0, transactionCost.indexOf(".") + 3);
	document.getElementById("txtSaving").value = "$" + saving.substring(0, saving.indexOf(".") + 3);
}


function ToggleDivDisplay(divid, updown){
	var oDiv=document.getElementById(divid);
	var oUpDown=document.getElementById(updown);
//	var pUpDown=oUpDown.src;
	
	var pDisplay=oDiv.style.display;

	oDiv.style.display='none';
	
	if(pDisplay=='none')
		oDiv.style.display='block';
	
}
