function checklogin()
{

	if (document.loginfrm.username.value == '')
	{
		alert("Por favor digite seu email!");
		document.loginfrm.username.focus();
		return;
		}
	
	checkmail = document.loginfrm.username.value

	if ((checkmail.indexOf('@') < 0) || ((checkmail.charAt(checkmail.length-4) != '.') && (checkmail.charAt(checkmail.length-3) != '.'))) 
	{
			
		alert("O email digitado é inválido!");
		document.loginfrm.username.focus();
		return;
		}

	if (document.loginfrm.password.value == '')
	{
		alert("Por favor preencher sua senha!");
		document.loginfrm.password.focus();
		return;
		}

	document.loginfrm.submit();

}

function checkloginbox()
{

	if (document.loginbox.username.value == '')
	{
		alert("Por favor digite seu email!");
		document.loginbox.username.focus();
		return;
		}
	
	checkmail = document.loginbox.username.value

	if ((checkmail.indexOf('@') < 0) || ((checkmail.charAt(checkmail.length-4) != '.') && (checkmail.charAt(checkmail.length-3) != '.'))) 
	{
			
		alert("O email digitado é inválido!");
		document.loginbox.username.focus();
		return;
		}

	if (document.loginbox.password.value == '')
	{
		alert("Por favor preencher sua senha!");
		document.loginbox.password.focus();
		return;
		}

	document.loginbox.submit();

}



function contactval()
{

	if (document.contactform.name.value == '')
	{
		alert("Por favor digite seu nome!");
		document.contactform.name.focus();
		return;
		}

	if (document.contactform.phone.value == '')
	{
		alert("Por favor preencher seu telefone de contato!");
		document.contactform.phone.focus();
		return;
		}

	if (document.contactform.email.value == '')
	{
		alert("Por favor digite seu email!");
		document.contactform.email.focus();
		return;
		}
	
	checkmail = document.contactform.email.value

	if ((checkmail.indexOf('@') < 0) || ((checkmail.charAt(checkmail.length-4) != '.') && (checkmail.charAt(checkmail.length-3) != '.'))) 
	{
			
		alert("O email digitado é inválido!");
		document.contactform.email.focus();
		return;
		}

	

	if (document.contactform.comments.value == '')
	{
		alert("Por favor preencher o campo comentários!");
		document.contactform.comments.focus();
		return;
		}


	document.contactform.submit();


}



function updfields()
{


var frm = document.upd_account;

	if (frm.name.value == '')
	{
		alert("Por favor digite seu Nome!");
		frm.name.focus();
		return;
		}

	if (frm.email.value == '')
	{
		alert("Por favor digite seu email!");
		frm.email.focus();
		return;
		}
	
	checkmail = frm.email.value

	if ((checkmail.indexOf('@') < 0) || ((checkmail.charAt(checkmail.length-4) != '.') && (checkmail.charAt(checkmail.length-3) != '.'))) 
	{
			
		alert("O email digitado é inválido!");
		frm.email.focus();
		return;
		}

	if (frm.phone.value == '')
	{
		alert("Por favor digite seu Telefone!");
		frm.phone.focus();
		return;
		}

	if (frm.password.value != '')
	{


		if (frm.password1.value == '')
		{
		alert("Por favor confirme sua Senha!");
		frm.password1.focus();
		return;
		}

		if (frm.password.value != frm.password1.value)
		{
		alert("As senhas não são iguais!");
		frm.password1.focus();
		return;
		}
	}


	document.upd_account.submit();

}


function checkad()
{

var frm = document.postad;
	

	if (frm.categoryID.value == 0)
	{
		alert("Selecione a Categoria!");
		frm.categoryID.focus();
		return;
		}

	if (frm.Title.value == '')
	{
		alert("Digite o Título de seu Anúncio!");
		frm.Title.focus();
		return;
		}

	if (frm.Description.value == '')
	{
		alert("Digite seu Anúncio!");
		frm.Description.focus();
		return;
		}

	
	if ((frm.Description.value.length < 3) || (frm.Description.value.length > 300))
	{

	mesg = "Seu texto contem " + frm.Description.value.length + " caracteres\n"
	mesg = mesg + "O número máximo permitido é de 300\n"
	mesg = mesg + "Por favor reveja seu anúncio."
	alert(mesg);

	frm.Description.focus();

	return;
	}


document.postad.submit();


}




function checkPaidAd()
{

var frm = document.postpaid;
	

	if (frm.categoryID.value == 0)
	{
		alert("Selecione a Categoria!");
		frm.categoryID.focus();
		return;
		}

	if (frm.Title.value == '')
	{
		alert("Digite o Título de seu Anúncio!");
		frm.Title.focus();
		return;
		}

	if (frm.Description.value == '')
	{
		alert("Digite seu Anúncio!");
		frm.Description.focus();
		return;
		}

	
	if ((frm.Description.value.length < 3) || (frm.Description.value.length > 250))
	{

	mesg = "Seu texto contem " + frm.Description.value.length + " caracteres\n"
	mesg = mesg + "O número máximo permitido é de 250\n"
	mesg = mesg + "Por favor reveja seu anúncio."
	alert(mesg);

	frm.Description.focus();

	return;
	}


document.postpaid.submit();


}



function UplImages()
{
var frm = document.postpaidimg;
document.postpaidimg.submit();
}



function checkregistration()
{

var frm = document.registration;

	if (frm.name.value == '')
	{
		alert("Por favor digite seu Nome!");
		frm.name.focus();
		return;
		}

	if (frm.email.value == '')
	{
		alert("Por favor digite seu Email!");
		frm.email.focus();
		return;
		}

			checkmail = frm.email.value

			if ((checkmail.indexOf('@') < 0) || ((checkmail.charAt(checkmail.length-4) != '.') && (checkmail.charAt(checkmail.length-3) != '.'))) 
			{
			
			alert("O email está incorreto!");
			frm.email.focus(); 
			return;

			}

	//if (frm.phone.value == '')
	//{
	//	alert("Por favor digite seu Telefone!");
	//	frm.phone.focus();
	//	return;
	//	}

	if (frm.password.value == '')
	{
		alert("Por favor digite uma senha!");
		frm.password.focus();
		return;
		}

	if (frm.password1.value == '')
	{
		alert("Por favor confirme sua senha!");
		frm.password1.focus();
		return;
		}

	if (frm.password.value != frm.password1.value)
	{
		alert("As senhas não são iguais!");
		frm.password.focus();
		return;
		}

	if (!frm.check1.checked){
		alert("Você não selecionou os termos de uso!");
		return;
		}

	document.registration.submit();


}




function checkPayment()
{
	var frm = document.postpayment;
	var ccNumb
			
	ccNumb = frm.number.value;
												
	if(frm.cctype.value == "")
	{
		alert("Tipo de cartão é obrigatório!");
		frm.cctype.focus();
		return;
	}
			
	if(frm.cardholder.value == "")
	{
		alert("Nome no cartão é obrigatório!");
		frm.cardholder.focus();
		return;
	}

	if(frm.number.value == "")
	{
		alert("Número do cartão é obrigatório!");
		frm.number.focus();
		return;
	}
			
	if(frm.strocardmm.value == "")
	{
		alert("Data de expiração é obrigatória!");
		frm.strocardmm.focus();
		return;
	}
			
	if(frm.strocardyy.value == "")
	{
		alert("Data de expiração é obrigatória!");
		frm.strocardyy.focus();
		return;
	}
			
	if(frm.strOcardCVN.value == "")
	{
		alert("Código de Segurança é obrigatório!");
		frm.strOcardCVN.focus();
		return;
	}
			
			
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit

	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
  	temp = "" + sCCN.substring(j, j+1);
  	if (valid.indexOf(temp) == "-1"){bNum = false;}
	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
  	/*alert("Not a Number");*/bResult = false;
	}

	// Determine if it is the proper length 
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  	bResult = false;
	} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  	if(len >= 15){  // 15 or 16 for Amex or V/MC
    	for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      	calc = parseInt(iCCN) % 10;  // right most digit
      	calc = parseInt(calc);  // assure it is an integer
      	iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      	i--;  // decrement the count - move to the next digit in the card
      	iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      	calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      	calc = calc *2;                                 // multiply the digit by two
      	// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      	// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      	switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      	}                                               
    	iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    	iTotal += calc;  // running total of the card number as we loop
  	}  // END OF LOOP
  	if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    	bResult = true;  // This IS (or could be) a valid credit card number.
  	} else {
    	bResult = false;  // This could NOT be a valid credit card number
    	}
  	}
	}
	// change alert to on-page display or other indication as needed.
	if(bResult) {
  	document.postpayment.submit(); // In this document,  submit the form called notify
	}
	if(!bResult){
  	alert("Número de Cartão Inválido!");
  	frm.number.focus();
  	return;
	}
	
	document.postpayment.submit();
}


function changeclass(cname1,cname2,cname3,cname4) { 

	var NAME1 = document.getElementById(cname1)
	var NAME2 = document.getElementById(cname2) 
	var NAME3 = document.getElementById(cname3) 
	var NAME4 = document.getElementById(cname4) 
 
	NAME1.className="active"
	NAME2.className="inactive"
	NAME3.className="inactive"
	NAME4.className="inactive"
}


function validatesearch(){

	var NAME1 = document.getElementById("item1")  //InfoAnglo
	var NAME2 = document.getElementById("item2")  //Classificados
	var NAME3 = document.getElementById("item3")  //Diretório
	var NAME4 = document.getElementById("item4")  //Vídeos
	var KEYWORD = document.getElementById("keyword")

	if (KEYWORD.value == ''){
  	alert("Digite algo para procurar!");
  	KEYWORD.focus();
	return;
	}

	if (NAME1.className == "active"){

	}

	if (NAME2.className == "active"){
	window.location = "classifieds-search.asp?keyword=" + KEYWORD.value
	}

	if (NAME3.className == "active"){

	}

	if (NAME4.className == "active"){

	}


}

function updfieldsDIR(){

	var frm = document.upd_directory;

												
	if(frm.categoryID.value == "0")
	{
		alert("Categoria é Obrigatória!");
		frm.categoryID.focus();
		return;
	}

	if(frm.company.value == "")
	{
		alert("Nome da Empresa é Obrigatório!");
		frm.company.focus();
		return;
	}

	if(frm.phone.value == "")
	{
		alert("Telefone é Obrigatório!");
		frm.phone.focus();
		return;
	}

	if(frm.address.value == "")
	{
		alert("Endereço é Obrigatório!");
		frm.address.focus();
		return;
	}

	if(frm.city.value == "")
	{
		alert("Cidade é Obrigatório!");
		frm.city.focus();
		return;
	}

	if(frm.state.value == "")
	{
		alert("Estado é Obrigatório!");
		frm.state.focus();
		return;
	}

	if(frm.zip.value == "")
	{
		alert("Código Postal é Obrigatório!");
		frm.zip.focus();
		return;
	}

	if(frm.country.value == "")
	{
		alert("País é Obrigatório!");
		frm.country.focus();
		return;
	}

	document.upd_directory.submit();

}



