// JavaScript Document
function geraRandom() {
	var randomnumber = Math.floor(Math.random()*100)	
	return randomnumber;
}

function mudaModelo(page) {
	$('#conteudo').block();
	$.ajax({
		type: "POST",
		cache: false,
		url: "../includes/modelos_"+ page +".php",
		data: "kill=" + geraRandom(),
		success: function(dados){
			$("#cntr_modelos").html(dados);
			$('#conteudo').unblock();
		}
	});
}

function mudaModeloCat(page) {
	$('#conteudo').block();
	$.ajax({
		type: "POST",
		cache: false,
		url: "../includes/modelos_catalogo_"+ page +".php",
		data: "kill=" + geraRandom(),
		success: function(dados){
			$("#cntr_modelos").html(dados);
			$('#conteudo').unblock();
		}
	});
}

function mudaTecido(id) {
	$('#conteudo').block();
	$.ajax({
		type: "POST",
		cache: false,
		url: "../includes/tecidos_"+ id +".php",
		data: "kill=" + geraRandom(),
		success: function(dados){
			$("#cntr_tecidos").html(dados);
			$('#conteudo').unblock();
		}
	});
}

function openModelo() {
	openWindow(580,430,'../modelos/modelo_virtual.php','modelo');
}

function printProduto(modelo,secao) {
	openWindow(417,425,'../modelos/print_produtos.php?m='+modelo+'&s='+secao+'','printProduto');
}

function printModelo(id) {
	openWindow(417,500,'../modelos_catalogo/print_modelos.php?id='+id,'printProduto');
}

function zoomModelo(id) {
	a       = 100;
	l       = 100;
	theTop  = 50;
	theLeft = 50;
	f       = '../modelos_catalogo/zoom_modelos.php?id='+id;
	n       = 'zoomModelo';
	
	var features= 'height='+a+',width='+l+',top='+theTop+',left='+theLeft+",scrollbars=yes";
	theWin=window.open(f,n,features);
	theWin.focus();
}

function openWindow(l,a,f,n) {
	var theTop=(screen.height/2)-(a/2);
	var theLeft=(screen.width/2)-(l/2);
	
	var features= 'height='+a+',width='+l+',top='+theTop+',left='+theLeft+",scrollbars=yes";
	theWin=window.open(f,n,features);
	theWin.focus();
}

function changePopSize(img) {
	var largura = img.width + 11;
	var altura = img.height + 87;
	window.resizeTo(largura,altura);
	window.focus();
}

//VALIDA CAMPOS DO FORMULARIO
function validaForm(form) {
		//theform = document.getElementById('forms');
		theform = form;
		if (document.all || document.getElementById) {
			
			var label = '';
			var errors = 0;
			
			for (i = 0; i < theform.length; i++) {
			var formElement = theform.elements[i];
				if (true) {
					if(theform.elements[i].type != 'button' && theform.elements[i].type != undefined && theform.elements[i].type != 'hidden' && theform.elements[i].disabled != true) {
						
						if (formElement.alt == 'required' || formElement.title == 'required') {
							if (!formElement.value) {
								errors++;
							}
						}
						
					}
				}
			}
		}
		if (errors == 0) {
			return true;
		} else {
			alert('Os campos marcados com asterisco sao obrigatórios');
			return false;
		}
}
