function mais(f) {
	var form = "form"+f;
	if(IsNumeric(document.getElementById(form).qtd.value)) {
		val = parseInt(document.getElementById(form).qtd.value);
		val++;
		document.getElementById(form).qtd.value = val;
	} else {
		document.getElementById(form).qtd.value = 0;
	}
	/*	document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='"+f+"' name='"+f+"' value='" + val +"'>"; 
		document.getElementById(form).submit(); */
		
}
function menos(f) {
	var form = "form"+f;
	if(IsNumeric(document.getElementById(form).qtd.value)) {
		val = parseInt(document.getElementById(form).qtd.value);
		if (val > 0) {
			val--;
			document.getElementById(form).qtd.value = val;
		}
	} else {
		document.getElementById(form).qtd.value = 0;
	}
/*	document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='"+f+"' name='"+f+"' value='" + val +"'>"; 
		document.getElementById(form).submit(); */
}
function add(c) {
	var form = "cabmed";
	field = document.getElementById(c);
	if(IsNumeric(field.value)) {
		val = parseInt(field.value);
		val++;
		field.value = val;
	} else {
		field.value = 0;
	}
}
function enc(c){
	return;
	var form = "cabmed";
	field = document.getElementById(c);
	if(IsNumeric(field.value) && field.value>0) {
		document.getElementById(form).art.value = c;
		document.getElementById(form).pagina.value = "cabmed.php";
		document.getElementById(form).submit();
	}
}
function dim(c) {
	var form = "cabmed";
	field = document.getElementById(c);
		val = parseInt(field.value);
		if(val >0)val--;
		field.value = val;
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
function subMMr(f) {
	form = 'form'+f;
	tag = "r"+f;
	document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='"+tag+"' name='"+tag+"' value='r'>"; 
	document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='pagina' name='pagina' value='cabmed.php'>"; 
		document.getElementById(form).submit();
}
function subMr(f) {
	form = "form"+f;
	tag = "r"+f;
	document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='"+tag+"' name='"+tag+"' value='r'>"; 
	document.getElementById(form).submit();
}
function voltar(p, f) {
	window.location = "http://www.natalrecheio.com/"+p;
}
function subM (f){
	return false;
	if (f == 'fimenc'){
		document.getElementById(f).pagina.value = "index.php";
		document.getElementById(f).submit();		
	}
	else if (f == 'cabmed'){
		document.getElementById(f).pagina.value = "cabmed.php";
		document.getElementById(f).submit();		
	}
	else if(f == 'confelr') {
		valid = true;
		myForm = document.getElementById(f);
		if(document.getElementById(f).novocli){
			if (myForm.novocli.value='1') {
				if(checkValid(myForm.designacaoSocialF, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.moradaF, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.cpostalF, myForm, 'cp1')==false) valid = false;		
				if(checkValid(myForm.cpostal2F, myForm, 'cp2')==false) valid = false;
				if(checkValid(myForm.localidadeF, myForm, 'text')==false) valid = false;		
				if(valid == false) return valid;
			}
		}
		document.getElementById(f).pagina.value = "fimenc.php";
		document.getElementById(f).submit();
	}
	else if(f == 'confeme') {
		valid = true;
		myForm = document.getElementById(f);
		if(document.getElementById(f).novocli){
			if (myForm.novocli.value='1') {
				if(checkValid(myForm.designacaoSocialF, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.moradaF, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.cpostalF, myForm, 'cp1')==false) valid = false;		
				if(checkValid(myForm.cpostal2F, myForm, 'cp2')==false) valid = false;
				if(checkValid(myForm.localidadeF, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.moradaE, myForm, 'text')==false) valid = false;
				if(checkValid(myForm.cpostalE, myForm, 'cp1')==false) valid = false;		
				if(checkValid(myForm.cpostal2E, myForm, 'cp2')==false) valid = false;
				if(checkValid(myForm.localidadeE, myForm, 'text')==false) valid = false;
				if(valid == false) return valid;
			}
		}else {
			if(checkValid(myForm.moradaE, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.cpostalE, myForm, 'cp1')==false) valid = false;		
			if(checkValid(myForm.cpostal2E, myForm, 'cp2')==false) valid = false;
			if(checkValid(myForm.localidadeE, myForm, 'text')==false) valid = false;
			if(valid == false) return valid;
		}
		document.getElementById(f).pagina.value = "fimenc.php";
		document.getElementById(f).submit();
	}
	else if (f== 'pagamento') {
		pag = 'confeme.php';
		valid = true;
		myForm = document.getElementById(f);
		if(myForm.visa.checked == true) {
			colorGray('lbltransferencia');
			colorGray('lblcheque');
			colorGray('lblbanco');
			colorGray('lblnrCheque');
			if(checkValid(myForm.nome, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.nrCartao, myForm, 'ccred')==false) valid = false;
			if(checkValid(myForm.validade, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.codigo, myForm, 'inteiro')==false) valid = false;
			if(valid == false) return valid;
		}
		else if(myForm.cheque.checked == true) {
			colorGray('lbltransferencia');
			colorGray('lblvisa');
			colorGray('lblnome');
			colorGray('lblnrCartao');
			colorGray('lblvalidade');
			colorGray('lblcodigo');
			if(checkValid(myForm.nrCheque, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.banco, myForm, 'text')==false) valid = false;
			if(valid == false) return valid;
		}
		else if(myForm.transferencia.checked == true) {
			colorGray('lblcheque');
			colorGray('lblvisa');
		}
		else {
			colorRed('lbltransferencia');
			colorRed('lblcheque');
			colorRed('lblvisa');
			return false;
		}
		document.getElementById(f).pagina.value = pag;
		document.getElementById(f).submit();
	}
	else if (f== 'entrega') {
		valid = true;
		myForm = document.getElementById(f);
		if(myForm.levantaLoja.checked == true) {
			pag = 'confelr.php';
			colorGray('lbllevantaLoja');
			colorGray('lbllevantaMorada');
			colorGray('lblnome');
			if(checkValid(myForm.lojaCli, myForm, 'inteiro')==false) return false;
		}
		else if(myForm.levantaMorada.checked == true) {
			pag = 'condentrega.php';
			colorGray('lbllevantaLoja');
			colorGray('lbllevantaMorada');
			colorGray('lojaCli');
			if(checkValid(myForm.nome, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.telefone, myForm, 'telefone')==false) valid = false;
			if(checkValid(myForm.morada, myForm, 'text')==false) valid = false;
			if(checkValid(myForm.cpostal, myForm, 'cp1')==false) valid = false;
			if(checkValid(myForm.cpostal2, myForm, 'cp2')==false) valid = false;
			if(checkValid(myForm.localidade, myForm, 'text')==false) valid = false;
			if(valid == false) return valid;
		}
		else {
			colorRed('lbllevantaLoja');
			colorRed('lbllevantaMorada');
			return false;
		}
		document.getElementById(f).pagina.value = pag;
		document.getElementById(f).submit();
	}
	else if(f== 'formcli') {
		//document.getElementById(f).pagina = "entrega.php";
		valid = true;
		myForm = document.getElementById(f);
		if(checkValid(myForm.nrInterno, myForm, 'inteiro')==false) valid = false;
		if(checkValid(myForm.nif, myForm, 'nif')==false) valid = false;
		if(checkValid(myForm.email, myForm, 'email')==false) valid = false;
		if(checkValid(myForm.lojaCli, myForm, 'inteiro')==false) valid = false;
		if(valid == false) return valid;
		document.getElementById(f).pagina.value = "entrega.php";
		document.getElementById(f).submit();
	}
	else if(f== 'condentrega') {
		document.getElementById(f).pagina.value = "pagamento.php";
		document.getElementById(f).submit();
	}
	else if(f== 'nencomenda') {
		//document.getElementById(f).pagina = "entrega.php";
		valid = true;
		myForm = document.getElementById(f);
		if(checkValid(myForm.nome, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.email, myForm, 'email')==false) valid = false;
		if(checkValid(myForm.telemovel, myForm, 'telefone')==false && checkValid(myForm.telefone, myForm, 'telefone')==false) valid = false;
		if(valid == false) return valid;
		document.getElementById(f).pagina.value = "nencomenda.php";
		document.getElementById(f).submit();
	}
	else if (f=='fimcabmed') {
		valid = true;
		myForm = document.getElementById(f);
		if(checkValid(myForm.nome, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.email, myForm, 'email')==false) valid = false;
		if(checkValid(myForm.nif, myForm, 'nif')==false) valid = false;
		if(checkValid(myForm.telemovel, myForm, 'telefone')==false && checkValid(myForm.telefone, myForm, 'telefone')==false) valid = false;
	
		if(myForm.cli.checked == false && myForm.ncli.checked == false) {
			valid = false;
			colorRed('lblcli');
			colorRed('lblncli');
		}
		else {
			colorGray('lblcli');
			colorGray('lblncli');
		}
		if(valid == false) return valid;
		document.getElementById(f).pagina.value = "fimcabmed.php";
		document.getElementById(f).submit();
	}
	else if(f=='formncli') {
		valid = true;
		myForm = document.getElementById(f);
		if(checkValid(myForm.nif, myForm, 'nif')==false) valid = false;
		if(checkValid(myForm.designacaoSocial, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.actividade, myForm, 'inteiro')==false) valid = false;
		if(checkValid(myForm.morada, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.cpostal, myForm, 'cp1')==false) valid = false;		
		if(checkValid(myForm.cpostal2, myForm, 'cp2')==false) valid = false;
		if(checkValid(myForm.localidade, myForm, 'text')==false) valid = false;		
		if(checkValid(myForm.telefone, myForm, 'telefone')==false) valid = false;	
		if(checkValid(myForm.email, myForm, 'email')==false) valid = false;
		if(checkValid(myForm.lojaCli, myForm, 'inteiro')==false) valid = false;
		if(valid == false) return valid;
		document.getElementById(f).pagina.value = "entrega.php";
		document.getElementById(f).submit();
	}
	else if(f=='sejacli') {
		valid = true;
		myForm = document.getElementById(f);
		if(checkValid(myForm.nif, myForm, 'nif')==false) valid = false;
		if(checkValid(myForm.designacaoSocial, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.actividade, myForm, 'inteiro')==false) valid = false;
		if(checkValid(myForm.morada, myForm, 'text')==false) valid = false;
		if(checkValid(myForm.cpostal, myForm, 'cp1')==false) valid = false;		
		if(checkValid(myForm.cpostal2, myForm, 'cp2')==false) valid = false;
		if(checkValid(myForm.localidade, myForm, 'text')==false) valid = false;		
		if(checkValid(myForm.telefone, myForm, 'telefone')==false) valid = false;	
		if(checkValid(myForm.email, myForm, 'email')==false) valid = false;
		if(checkValid(myForm.lojaCli, myForm, 'inteiro')==false) valid = false;
		if(valid == false) return valid;
		document.getElementById(f).pagina.value = "sejacli.php";
		document.getElementById(f).submit();
	}
	else if(f== 'termos') {
		valid = true;
		myForm = document.getElementById(f);
		if((document.getElementById('termos').ncli.checked == true || document.getElementById('termos').cli.checked == true) && document.getElementById('termos').cond.checked == true) {
			if (document.getElementById('termos').ncli.checked == true) {
				document.getElementById(f).innerHTML = document.getElementById(f).innerHTML + "<input type=hidden id='cliente' name='cliente' value='false'>";	
			}
			if (document.getElementById('termos').cli.checked == true) {
				document.getElementById(f).innerHTML = document.getElementById(f).innerHTML + "<input type=hidden id='cliente' name='cliente' value='true'>";
			}
			document.getElementById(f).submit();
		} else {
			if(document.getElementById('termos').cli.checked == false && document.getElementById('termos').ncli.checked == false) {
				colorRed('lblcli');
				colorRed('lblncli');
			}
			else {
				colorGray('lblcli');
				colorGray('lblncli');
			}
			if(document.getElementById('termos').cond.checked == false) colorRed('lblcond');
			else colorGray('lblcond');
			return false;
			document.getElementById('termAlert').style.visibility='visible';
		}
	} else {
		form = "form"+f;
		if(IsNumeric(document.getElementById(form).qtd.value)) {
			val = parseInt(document.getElementById(form).qtd.value);
			if(val==0) val=1;
		} else {
			val = 1;
		}
		document.getElementById(form).innerHTML = document.getElementById(form).innerHTML + "<input type=hidden id='"+f+"' name='"+f+"' value='" + val +"'>"; 
		document.getElementById(form).submit();
	}
}
function openDet(f) {
	var strLocation = "detalhe.php?&ref=" + f;
	alert(strLocation);
    window.navigate(strLocation);
}
function checkCli(chk) {
	if(chk.name == 'ncli') {
		if (chk.checked) document.getElementById('termos').cli.checked = false;
	}
	if(chk.name == 'cli') {
		if (chk.checked) document.getElementById('termos').ncli.checked = false;
	}
}
function checkCliM(chk) {
	if(chk.name == 'ncli') {
		if (chk.checked) document.getElementById('fimcabmed').cli.checked = false;
	}
	if(chk.name == 'cli') {
		if (chk.checked) document.getElementById('fimcabmed').ncli.checked = false;
	}
}
function activaCheque(){
	document.getElementById('pagamento').nrCheque.disabled=false;
	document.getElementById('pagamento').banco.disabled=false;
	document.getElementById('pagamento').nrCheque.focus();
}
function desactivaCheque(){
	document.getElementById('pagamento').nrCheque.value = '';
	document.getElementById('pagamento').nrCheque.disabled=true;
	document.getElementById('pagamento').banco.value = '';
	document.getElementById('pagamento').banco.disabled=true;
	colorGray('lblbanco');
	colorGray('lblnrCheque');
}
function activaVisa(){
	document.getElementById('pagamento').nome.disabled=false;
	document.getElementById('pagamento').nrCartao.disabled=false;
	document.getElementById('pagamento').validade.disabled=false;
	document.getElementById('pagamento').codigo.disabled=false;
	document.getElementById('pagamento').nome.focus();
}
function desactivaVisa(){
	document.getElementById('pagamento').nome.value='';
	document.getElementById('pagamento').nome.disabled=true;
	document.getElementById('pagamento').nrCartao.value='';
	document.getElementById('pagamento').nrCartao.disabled=true;
	document.getElementById('pagamento').validade.value='';
	document.getElementById('pagamento').validade.disabled=true;
	document.getElementById('pagamento').codigo.value='';
	document.getElementById('pagamento').codigo.disabled=true;
	colorGray('lblnome');
	colorGray('lblnrCartao');
	colorGray('lblvalidade');
	colorGray('lblcodigo');
}
function checkPagamento(chk) {
	if(chk.name == 'transferencia') {
		if (chk.checked) {
			document.getElementById('pagamento').visa.checked = false;
			document.getElementById('pagamento').cheque.checked = false;
			desactivaCheque();
			desactivaVisa();
		 //	activaTransferencia();	
		}else {
		//	desactivaTransferencia();	
		}
	}
	if(chk.name == 'visa') {
		if (chk.checked) {
			document.getElementById('pagamento').cheque.checked = false;
			document.getElementById('pagamento').transferencia.checked = false;
			desactivaCheque();
		//	desactivaTransferencia();
			activaVisa();
		} else {
			desactivaVisa();	
		}
	}
	if(chk.name == 'cheque') {
		if (chk.checked) {
			document.getElementById('pagamento').transferencia.checked = false;
			document.getElementById('pagamento').visa.checked = false;
			activaCheque();
		//	desactivaTransferencia();
			desactivaVisa();
		} else {
			desactivaCheque();	
		}
	}
}
function checkEntrega(chk) {
	if(chk.name == 'levantaMorada') {
		if (chk.checked) {
			document.getElementById('entrega').levantaLoja.checked = false;
			activaMorada();
			desactivaLoja();
		}else {
			desactivaMorada();	
		}
	}
	if(chk.name == 'levantaLoja') {
		if (chk.checked) {
			document.getElementById('entrega').levantaMorada.checked = false;
			desactivaMorada();
			activaLoja();
		} else {
			desactivaLoja();	
		}
	}
}
function activaMorada(){
	document.getElementById('entrega').nome.disabled=false;
	document.getElementById('entrega').morada.disabled=false;
	document.getElementById('entrega').cpostal.disabled=false;
	document.getElementById('entrega').cpostal2.disabled=false;
	document.getElementById('entrega').telefone.disabled=false;
	document.getElementById('entrega').localidade.disabled=false;
	document.getElementById('entrega').nome.focus();
}
function desactivaMorada(){
	document.getElementById('entrega').nome.value = '';
	document.getElementById('entrega').nome.disabled=true;
	document.getElementById('entrega').morada.value = '';
	document.getElementById('entrega').morada.disabled=true;
	document.getElementById('entrega').cpostal.value = '';
	document.getElementById('entrega').cpostal.disabled=true;
	document.getElementById('entrega').cpostal2.value = '';
	document.getElementById('entrega').cpostal2.disabled=true;
	document.getElementById('entrega').localidade.value = '';
	document.getElementById('entrega').localidade.disabled=true;
	document.getElementById('entrega').telefone.value = '';
	document.getElementById('entrega').telefone.disabled=true;
	
}
function activaLoja(){
	document.getElementById('entrega').lojaCli.disabled=false;
	document.getElementById('entrega').lojaCli.focus();
}
function desactivaLoja(){
	document.getElementById('entrega').lojaCli.selectedIndex = 0;
	document.getElementById('entrega').lojaCli.disabled=true;
}
// Form Validitons
function checkValidationInteiro(formInput) {
    if (typeof(formInput) != "object") return(false);
    if (stringEmpty(formInput.value)) return false;
	if (!IsNumeric(formInput.value)) return false;
    return true;
}
function checkValidationNif(formInput) {
    if (typeof(formInput) != "object") return(false);
    if (stringEmpty(formInput.value)) return false;
	if (!IsNumeric(formInput.value)) return false;
	if (!IsValidNif(formInput.value)) return false;
    return true;
}
function checkValidationEmail(formInput) {
    if (typeof(formInput) != "object")return(false);
    if (stringEmpty(formInput.value)) return false;
    else if (noAtSign( formInput.value )) return false;
    else if (nothingBeforeAt(formInput.value)) return false;
    else if (noLeftBracket(formInput.value)) return false;
    else if (noRightBracket(formInput.value)) return false;
    else if (noValidPeriod(formInput.value)) return false;
    else if (noValidSuffix(formInput.value)) return false;
    else return true;
    var objType = typeof(formInput.focus);
    if (objType == "object" || objType == "function") formInput.focus();
    return (false);
}
function colorRed (lbl){
	document.getElementById('msgerr').style.display='block';
	document.getElementById(lbl).style.color='#FF0000';
}
function colorGray(lbl) {
	document.getElementById(lbl).style.color='#525A5A';
}
function checkValid (formField, form, type) {
	label = 'lbl'+formField.name
	if(type == 'ccred') {
		if ( valVisa ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'email') {
		if ( checkValidationEmail ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'inteiro') {
		if ( checkValidationInteiro ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'text'){
		if(formField.value.length<1) colorRed(label);
		else {
			colorGray(label);
			return true;
		}
	}
	if(type == 'nif') {
		if ( checkValidationNif ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'cp1') {
		if ( IsValidCp1 ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'cp2') {
		if ( IsValidCp2 ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
	if(type == 'telefone') {
		if ( IsValidTelefone ( formField ) == true ) {
		  colorGray(label);
		  return true;
		} else colorRed(label);
	}
    return ( false );
}
function IsValidTelefone(formField) {
		if ( formField.value.length == 9) {
			if ( checkValidationInteiro ( formField ) == true ) return true;
		}
		return false;
}
function IsValidCp1(formField) {
		if ( formField.value.length == 4) {
			if ( checkValidationInteiro ( formField ) == true ) return true;
		}
		return false;
}
function IsValidCp2(formField) {
		if ( formField.value.length == 3) {
			if ( checkValidationInteiro ( formField ) == true ) return true;
		}
		return false;
}
function IsValidNif(formField) {
	if ( formField.length == 9) {
		var tot;
		var arr = new Array();
		arr = formField.split("");
		tot = arr[0]*9+arr[1]*8+arr[2]*7+arr[3]*6+arr[4]*5+arr[5]*4+arr[6]*3+arr[7]*2;
		mod = tot % 11;
		chkD = 11 - mod;
		if(chkD >9) chkD = 0;
		if (arr[8] == chkD) return true;
		else return false;
    } else return ( false );
}
function stringEmpty (formField) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( formField.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign (formField) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if (formField.indexOf ('@', 0) == -1) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt (formField) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( formField.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noLeftBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
    if ( formField.indexOf ( '[', 0 ) == -1 && formField.charAt (formField.length - 1) == ']') {
        return ( true )
    } else {
        return ( false );
    }
}

function noRightBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
    if (formField.indexOf ( '[', 0 ) > -1 && formField.charAt (formField.length - 1) != ']') {
        return ( true );
    } else {
        return ( false );
    }
}

function noValidPeriod (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf ( '@', 0 ) > 1 && formField.charAt (formField.length - 1 ) == ']')
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if (formField.indexOf ( '.', 0 ) == -1)
        return ( true );

    return ( false );
}

function noValidSuffix(formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf('@', 0) > 1 && formField.charAt(formField.length - 1) == ']') {
        return ( false );
    }

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = formField.length;
    var pos = formField.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 4 ) {
        return ( true );
    } else {
        return ( false );
    }
}
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

function valVisa(cn){
	return isValidCreditCard('Visa', cn.value);
}
function isValidCreditCard(type, ccnum) {
   if (type == "Visa") {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "MC") {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "Disc") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "AmEx") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } else if (type == "Diners") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split("-").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}
