function showCCInfo()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert (ajaxErrMsg);
		return;
	}
	loadAccPage(true, null);
	var url = 'account_CC.php?purpose=showCCInfo&'+Math.random();
	xmlHttp.onreadystatechange = stateChanged_showCCInfo;
	xmlHttp.open('GET', url, true);
	xmlHttp.send(null);
}
function stateChanged_showCCInfo()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		if (xmlHttp.responseText.indexOf('E~X~P~I~R~E~D') != -1)
			window.location = 'login.php?m=2';
		else
			loadAccPage(false, xmlHttp.responseText);
	}
}

function validCCForm()
{
	var form = document.getElementById('CCForm');
	if (!IsCreditCardOk(form)) return false;
	saveCustCCForm(form);
}
function saveCustCCForm(form)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert (ajaxErrMsg);
		return false;
	}
	var postVars = makeCustCCPostVars(form);
	document.getElementById('statusSaveCCForm').innerHTML = '&nbsp;';
	document.getElementById('btnSaveCC').disabled = true;	
	document.getElementById('statusLoaderCC').style.display = '';
	var url = 'account_CC.php?purpose=saveCustCCForm&'+Math.random();
	xmlHttp.onreadystatechange = stateChanged_saveCustCCForm;
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', postVars.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(postVars);
}
function stateChanged_saveCustCCForm()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		document.getElementById('btnSaveCC').disabled = false;
		document.getElementById('statusLoaderCC').style.display = 'none';
		if (xmlHttp.responseText.indexOf('E~R~R~O~R') != -1)
			document.getElementById('statusSaveCCForm').innerHTML = '<font color="#FF0000">' + xmlHttp.responseText.split('HAM~JAM')[1] + '</font>';
		else
		{
			document.getElementById('statusSaveCCForm').innerHTML = xmlHttp.responseText;			
		}
		//resetAccForm();
		resetAccountCCForm();
	}
}

function makeCustCCPostVars(form)
{
	var postVars = '';
	postVars += '&CCType='+form.CCType.value;
	postVars += '&CCNumber='+form.CCNumber.value;
	postVars += '&CCMonth='+form.CCMonth.value;
	postVars += '&CCYear='+form.CCYear.value;
	postVars += '&CCOwner='+form.CCOwner.value;
	postVars += '&CCBankName='+form.CCBankName.value;
	postVars += '&CCBankPhone='+form.CCBankPhone.value;
	postVars += '&custId='+form.custId.value;
	return postVars;
}
function resetAccountCCForm()
{
	var elem = document.getElementById('CCForm').elements;
	for (var i = 0; i < elem.length; i++)
	{
		switch (elem[i].type)
		{
			case 'text':
				elem[i].value = '';
				break;
			case 'select-one':
				elem[i].options[0].selected = true;
				break;
		}
	}
}
