function checkAll(p){
	
	if(typeof p != 'undefined'){
		
		if(document.form.todos[p].checked==true){
			//quinta-feira
			if(document.form.quinta[p].value!='0'){
				for(var i=0;i<document.form.quinta.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.quinta[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.quinta[p].checked=true;
				//document.form.quinta_.checked=false;
			}
			//sexta-feira
			if(document.form.sexta[p].value!='0'){
				for(var i=0;i<document.form.sexta.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.sexta[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.sexta[p].checked=true;
				//document.form.sexta_.checked=false;
			}
			//sábado
			if(document.form.sabado[p].value!='0'){
				for(var i=0;i<document.form.sabado.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.sabado[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.sabado[p].checked=true;
				//document.form.sabado_.checked=false;
			}
			//domingo
			if(document.form.domingo[p].value!='0'){
				for(var i=0;i<document.form.domingo.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.domingo[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.domingo[p].checked=true;
				//document.form.domingo_.checked=false;
			}
			//segunda-feira
			if(document.form.segunda[p].value!='0'){
				for(var i=0;i<document.form.segunda.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.segunda[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.segunda[p].checked=true;
				//document.form.segunda_.checked=false;
			}
			//terca-feira
			if(document.form.terca[p].value!='0'){
				for(var i=0;i<document.form.terca.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.terca[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.terca[p].checked=true;
				//document.form.terca_.checked=false;
			}
			if(document.form.quarta[p].value!='0'){
				for(var i=0;i<document.form.quarta.length;i++){
					if(document.form.todos[i].value.substr(1,4)==document.form.quarta[i].value.substr(0,4) && i!=p){
						document.form.todos[i].checked=false;
					}
				}
				document.form.quarta[p].checked=true;
				//document.form.terca_.checked=false;
			}
		}else{
			if(document.form.quinta[p].checked==true){
				limpaCheckQuinta();
				//document.form.quinta_.checked=true;
			}
			if(document.form.sexta[p].checked==true){
				limpaCheckSexta();	
				//document.form.sexta_.checked=true;
			}
			if(document.form.sabado[p].checked==true){
				limpaCheckSabado();
				//document.form.sabado_.checked=true;
			}
			if(document.form.domingo[p].checked==true){
				limpaCheckDomingo();
				//document.form.domingo_.checked=true;
			}
			if(document.form.segunda[p].checked==true){
				limpaCheckSegunda();
				//document.form.segunda_.checked=true;
			}
			if(document.form.terca[p].checked==true){
				limpaCheckTerca();
				//document.form.terca_.checked=true;
			}
			if(document.form.quarta[p].checked==true){
				limpaCheckQuarta();
				//document.form.terca_.checked=true;
			}
				
		}
	}else{
		//quinta-feira
			if(document.form.quinta.value!='0'){
				document.form.quinta.checked=true;
			}
			//sexta-feira
			if(document.form.sexta.value!='0'){
				document.form.sexta.checked=true;
			}
			//sabado
			if(document.form.sabado.value!='0'){
				document.form.sabado.checked=true;
			}
			//domingo
			if(document.form.domingo.value!='0'){
				document.form.domingo.checked=true;
			}
			//segunda-feira
			if(document.form.segunda.value!='0'){
				document.form.segunda.checked=true;
			}
			//terca-feira
			if(document.form.terca.value!='0'){
				document.form.terca.checked=true;
			}
			//quarta-feira
			if(document.form.quarta.value!='0'){
				document.form.quarta.checked=true;
			}
	}
}
function validaCheck(p){
	var quant=0;
	var check=0;
	if(document.form.quinta[p].value.length>1){
		quant++
		if(document.form.quinta[p].checked==true){
			check++
		}
	}
	if(document.form.quinta[p].value.length>1){
		quant++
		if(document.form.quinta[p].checked==true){
			check++
		}
	}
	if(document.form.sexta[p].value.length>1){
		quant++
		if(document.form.sexta[p].checked==true){
			check++
		}
	}
	if(document.form.sexta[p].value.length>1){
		quant++
		if(document.form.sexta[p].checked==true){
			check++
		}
	}
	if(document.form.sabado[p].value.length>1){
		quant++
		if(document.form.sabado[p].checked==true){
			check++
		}
	}
	if(document.form.sabado[p].value.length>1){
		quant++
		if(document.form.sabado[p].checked==true){
			check++
		}
	}
	if(document.form.domingo[p].value.length>1){
		quant++
		if(document.form.domingo[p].checked==true){
			check++
		}
	}
	if(document.form.domingo[p].value.length>1){
		quant++
		if(document.form.domingo[p].checked==true){
			check++
		}
	}
	if(document.form.segunda[p].value.length>1){
		quant++
		if(document.form.segunda[p].checked==true){
			check++
		}
	}
	if(document.form.terca[p].value.length>1){
		quant++
		if(document.form.terca[p].checked==true){
			check++
		}
	}
	if(document.form.quarta[p].value.length>1){
		quant++
		if(document.form.quarta[p].checked==true){
			check++
		}
	}
	// verifica se todos estão marcado e marca o checked "todos"
	if(quant==check){
		document.form.todos[p].checked=true;
	}
}
function validaRadioQuinta(v){
	//quinta-feira
	//document.form.quinta_.checked=false;
	var p='u';
	for(var i=0;i<document.form.quinta.length;i++){
		if(document.form.quinta[i].value.substr(0,4)==v){
			p = i;
		}
	}
	
	for(var i=0;i<document.form.quinta.length;i++){
		if(document.form.todos[i].value.substr(1,4)==document.form.quinta[i].value.substr(0,4) ){
			document.form.todos[i].checked=false;
		}
	}
	if(p!='u'){
		validaCheck(p);
	}
       
	
}
function validaRadioSexta(v){
	//sexta-feira
	//document.form.sexta_.checked=false;
	var p='u';
	for(var i=0;i<document.form.sexta.length;i++){
		if(document.form.sexta[i].value.substr(0,4)==v){
			p = i;
		}
	}
	for(var i=0;i<document.form.sexta.length;i++){
			if(document.form.todos[i].value.substr(1,4)==document.form.sexta[i].value.substr(0,4) ){
				document.form.todos[i].checked=false;
			}
	}
	if(p!='u'){
		validaCheck(p);
	}
}
function validaRadioSabado(v){
	//sábado
	//document.form.sabado_.checked=false;
	var p='u';
	for(var i=0;i<document.form.sabado.length;i++){
		if(document.form.sabado[i].value.substr(0,4)==v){
			p = i;
		}
	}
	for(var i=0;i<document.form.sabado.length;i++){
			if(document.form.todos[i].value.substr(1,4)==document.form.sabado[i].value.substr(0,4) ){
				document.form.todos[i].checked=false;
			}
	}
	if(p!='u'){
		validaCheck(p);
	}
}
function validaRadioDomingo(v){	
	//domingo
	//document.form.domingo_.checked=false;
	var p='u';
	for(var i=0;i<document.form.domingo.length;i++){
		if(document.form.domingo[i].value.substr(0,4)==v){
			p = i;
		}
	}
	for(var i=0;i<document.form.domingo.length;i++){
			if(document.form.todos[i].value.substr(1,4)==document.form.domingo[i].value.substr(0,4)){
				document.form.todos[i].checked=false;
			}
	}
	if(p!='u'){
		validaCheck(p);
	}
}
function validaRadioSegunda(v){
	//segunda-feira
	//document.form.segunda_.checked=false;
	var p='u';
	for(var i=0;i<document.form.segunda.length;i++){
		if(document.form.segunda[i].value.substr(0,4)==v){
			p = i;
		}
	}
	for(var i=0;i<document.form.segunda.length;i++){
			if(document.form.todos[i].value.substr(1,4)==document.form.segunda[i].value.substr(0,4) ){
				document.form.todos[i].checked=false;
			}
	}
	if(p!='u'){
		validaCheck(p);
	}
}
function validaRadioTerca(v){
	//terça-feira
	//document.form.terca_.checked=false;
	var p='u';
	for(var i=0;i<document.form.terca.length;i++){
		if(document.form.terca[i].value.substr(0,4)==v){
			p = i;
		}
	}
	for(var i=0;i<document.form.terca.length;i++){
			if(document.form.todos[i].value.substr(1,4)==document.form.terca[i].value.substr(0,4) ){
				document.form.todos[i].checked=false;
			}
	}
	if(p!='u'){
		validaCheck(p);
	}
}
/*function minDias(){
	var v     = true;
	var vDias = 0;
	qDias    = new Array(document.form.todos.length);
	
	for(var i=0;i<qDias.length;i++){
		qDias[i] = 0
	}
	
	for(var i=0;i<document.form.todos.length;i++){
		if(document.form.quinta[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.sexta[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.sabado[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.domingo[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.segunda[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.terca[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(qDias[i]==0){
			vDias = vDias+1
			msg   = document.form.todos[i].value.substr(0,1)
		}
		
	}
	
	for(var i=0;i<qDias.length;i++){
		if(qDias[i] != 0 && qDias[i] < document.form.todos[i].value.substr(0,1)){
			v = false;
			msg = document.form.todos[i].value.substr(0,1);
		}
	}
	if(v!=true || vDias==qDias.length){
		alert("Venda mínima de " + msg + " dias de qualquer bloco/camarote");
		return false;
	}else{
		return true;
	}

}*/
function minDias(){
	var v     = true;
	var vDias = 0;
	var p     = 0;
	
	qDias    = new Array(document.form.todos.length);
	
	for(var i=0;i<qDias.length;i++){
		qDias[i] = 0
	}
	
	for(var i=0;i<document.form.todos.length;i++){
		if(document.form.quinta[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.sexta[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.sabado[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.domingo[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.segunda[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(document.form.terca[i].checked){
			qDias[i] = qDias[i]+1
		}
		if(qDias[i]==0){
			vDias = vDias+1
			msg   = document.form.todos[i].value.substr(0,1)
		}
		
	}
		
	for(var i=0;i<qDias.length;i++){
		if(qDias[i] == 1 ){
			p = p + 1;
		}else if(qDias[i] >= 2){
			p = p + 2;
		} 
	}
	
	if(p < document.form.todos[0].value.substr(0,1)){
		alert("Venda mínima de " + document.form.todos[0].value.substr(0,1) + " dias de qualquer bloco/camarote");
		return false;
	}else{
		return true;
	}

}
function limpaCheckQuinta(){
	for(var i=0;i<document.form.quinta.length;i++){
		if(document.form.quinta[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.quinta[i].checked=false;
	}
}
function limpaCheckSexta(){
	for(var i=0;i<document.form.sexta.length;i++){
		if(document.form.sexta[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.sexta[i].checked=false;
	}
}
function limpaCheckSabado(){
	for(var i=0;i<document.form.sabado.length;i++){
		if(document.form.sabado[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.sabado[i].checked=false;
	}
}
function limpaCheckDomingo(){
	for(var i=0;i<document.form.domingo.length;i++){
		if(document.form.domingo[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.domingo[i].checked=false;
	}
}
function limpaCheckSegunda(){
	for(var i=0;i<document.form.segunda.length;i++){
		if(document.form.segunda[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.segunda[i].checked=false;
	}
}
function limpaCheckTerca(){
	for(var i=0;i<document.form.terca.length;i++){
		if(document.form.terca[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.terca[i].checked=false;
	}
}
function limpaCheckQuarta(){
	for(var i=0;i<document.form.quarta.length;i++){
		if(document.form.quarta[i].checked==true){
				document.form.todos[i].checked=false;
		}
		document.form.quarta[i].checked=false;
	}
}


