// JavaScript Document
// Felipe Gregorio - fgregorio@gmail.com

var is_ie = navigator.appName.toLowerCase().indexOf('explorer') != - 1 ;				
var site_nome = 'Novo Promocionais' ;
var site_url  = 'http://www.novopromocionais.com.br' ;

function link(url){
	top.location = url ;
}
function div_preenche(div_id,html_conteudo){
	document.getElementById(div_id).innerHTML = 'carregando...' ;
	document.getElementById(div_id).innerHTML = html_conteudo ;
}
function carrinho_add(form_obj){
	with ( form_obj ){
		if ( ! ( elements.qtd.value + 0 ) >= 1 ) {
			alert('informe uma quantidade') ;
			elements.qtd.focus();
		}
		else {
			submit() ;
		}
	}
}
function favoritos_add(){
	document.all ? window.external.AddFavorite(site_url,site_nome) : sidebar.addPanel(site_nome, site_url, '');
}
function popup(p_url,p_largura,p_altura,extra){
	x = window.open(p_url,'p','width='+p_largura+',height='+p_altura + ( extra ? ',' + extra : '' ) + ',resizable=yes,scrollbars=1') ;
	try {
		x.focus() ;
	}
	catch(e) { 
		alert('por favor, desabilite o bloqueador de pop-ups para visualizar esta janela')  ;
	}
}
function show_hide(obj_id){
	document.getElementById(obj_id).style.display = document.getElementById(obj_id).style.display == 'none' ? 'block' : 'none' ;
}
function apenas_numeros(obj){
	obj.value = obj.value.replace( /[a-z- ._]/ig , '' ) ;
}
function next_object(quantos_bytes,obj_atual,obj_next){
	if ( parseInt(obj_atual.value.length) == quantos_bytes ){
		obj_next.focus();		
	}
}
function indique_valida(form_obj){
	with ( form_obj ){
		if ( elements.seu_nome.value == ""  ){
			alert('digite seu nome') ;
		}
		else if ( ! elements.seu_email.value.isEmail() ){
			alert('digite seu email corretamente');
		}
		else if ( elements.nome_amigo.value == "" ){
			alert('digite o nome do seu amigo');
		}
		else if ( ! elements.email_amigo.value.isEmail() ){
			alert('digite o email do seu amigo corretamente');
		}
		else {
			return true ;
		}
		return false ;
	}
}
function cadastro_valida(form_obj){
	quais_erros = '' ;	
	/*        : NOME
	: E-MAIL
	: TELEFONE
	: EMPRESA
	: CIDADE
	*/
	with (form_obj){
		if ( elements.cadastro_nome.value == '' ) {
			quais_erros += '<p>digite seu nome</p>' ;
		}
		if ( ! elements.cadastro_email.value.isEmail() ) {
			quais_erros += '<p>e-mail inválido</p>' ;
		}
		if ( elements.cadastro_ddd.value == '' ) {
			quais_erros += '<p>digite seu ddd</p>' ;
		}
		if ( elements.cadastro_telefone.value == '' ) {
			quais_erros += '<p>digite seu telefone</p>' ;
		}
		if ( elements.cadastro_empresa.value == '' ) {
			quais_erros += '<p>digite o nome da empresa</p>' ;
		}
		if ( elements.cadastro_cidade.value == '' ) {
			quais_erros += '<p>digite a cidade</p>' ;
		}
		if ( quais_erros.length > 0 ){
			document.getElementById('cadastro-msg').className = 'erro' ;
			document.getElementById('cadastro-msg').innerHTML = '<p><b>erros encontrados ...</b></p>' + quais_erros ;
			return false ;
		}
		else {	
			return true ;
		}
	}	
	return false ;
}

/*
**************************************
* String.isCPF Function v1.0         *
* Autor: Carlos R. L. Rodrigues      *
* BEGIN 							 *
**************************************
*/
String.prototype.isCPF = function(){
	var c = this;
	if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false;
	if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false;
	for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
	if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
	if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	return true;
};

String.prototype.isCNPJ = function(){
	return true ;
};

function busca_valida(obj_form){
	if ( obj_form.elements.procura.value != '' ){
		return true ;	
	}
	return false ;
}

function set_cor(_cor_id){
	obj_combo = document.getElementById('cor_id') ;
	for ( var i = 0 ; i < obj_combo.options.length ; i ++ ){
		if ( obj_combo.options[i].value == _cor_id ){
			obj_combo.options[i].selected = true ;
		}	
	}	
}


/*
**************************************
* BY JSFROMHELL www.jsfromhell.com   *
* END 								 *
**************************************
*/

/*
PROTOTYPES ...
*/

String.prototype.isEmail = function(){
	return new RegExp(/.@./ig).test(this) ;
};

String.prototype.isData = function(){
	return true ;
};