function toggle_group(id){
	var groupID='group_'+id;
	if(document.getElementById(groupID)){
		document.getElementById(groupID).style.display=(document.getElementById(groupID).style.display=='none')?'':'none';
	}
}

function getMovie() {
	if(document.all){
		var movieName = window['model_layout_obj'] ;
	}else{
		var movieName = window.document.getElementById('model_layout'); 
	}

	return movieName;
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
	// First make sure the movie's defined.
	if (typeof(theMovie) != "undefined") {
		// If it is, check how much of it is loaded.
		return theMovie.PercentLoaded() == 100;
	} else {
		// If the movie isn't defined, it's not loaded.
		return false;
	}
}

function zoomIn() {
	var movieName = getMovie();
	if (movieIsLoaded(movieName)) {
		movieName.Zoom(80);
	}
	return false;
}

function zoomOut() {
	var movieName = getMovie();
	if (movieIsLoaded(movieName)) {
		movieName.Zoom(120);
	}
	return false;
}

function zoomReset() {
	var movieName = getMovie();
	if (movieIsLoaded(movieName)) {
		movieName.Zoom(0);
	}
	return false;
}

function zoomScroll(){
	var movieName = getMovie();
	if (event.wheelDelta >= 0){
		movieName.Zoom(90);
	} else {
		movieName.Zoom(110);
	}
}


var Visibility=false;
function toggleReferences() {

	var movieName = getMovie();
	if (movieIsLoaded(movieName)) {
		Visibility=!Visibility;
		if(Visibility==false) { frameNumber=0 } else { frameNumber=1 }
		movieName.GotoFrame(frameNumber);
	}
	return false;
}

function clean_params(value) {
	switch (value) {
		case 0 :
		if (document.frm.idFM) {
			document.frm.idFM.options[0].selected=true;
		}
		if (document.frm.idM) {
			document.frm.idM.options[0].selected=true;
		}
		if (document.frm.idV) {
			if(document.frm.idV.options){
				document.frm.idV.options[0].selected=true;
			}else{
				document.frm.idV.value=0;
			}
		}
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;		
		case 1 :
		if (document.frm.idB) {
			document.frm.idB.options[0].selected=true;
		}
		if (document.frm.idFM) {
			document.frm.idFM.options[0].selected=true;
		}
		if (document.frm.idM) {
			document.frm.idM.options[0].selected=true;
		}
		if (document.frm.idV) {
			if(document.frm.idV.options){
				document.frm.idV.options[0].selected=true;
			}else{
				document.frm.idV.value=0;
			}
		}
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;
		case 2 :
		if (document.frm.idFM) {
			document.frm.idFM.options[0].selected=true;
		}		
		if (document.frm.idM) {
			document.frm.idM.options[0].selected=true;
		}
		if (document.frm.idV) {
			if(document.frm.idV.options){
				document.frm.idV.options[0].selected=true;
			}else{
				document.frm.idV.value=0;
			}
		}
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;
		case 3 :
		if (document.frm.idM) {
			document.frm.idM.options[0].selected=true;
		}		
		if (document.frm.idV) {
			if(document.frm.idV.options){
				document.frm.idV.options[0].selected=true;
			}else{
				document.frm.idV.value=0;
			}
		}
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;
		case 4 :
		if (document.frm.idV) {
			if(document.frm.idV.options){
				document.frm.idV.options[0].selected=true;
			}else{
				document.frm.idV.value=0;
			}
		}
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;
		case 5 :
		if (document.frm.idN) {
			document.frm.idN.options[0].selected=true;
		}
		break;
	}
}



function loadListNumbers(current_product_id) {
	new Ajax.Request('lookup.php?id='+current_product_id,
	{ 
		method:'get',
		onSuccess: function(transport){
			document.getElementById('list_numbers').innerHTML=transport.responseText;
			document.getElementById('list_numbers').style.display='';
		},
		onFailure: function(transport){
		}
	});	
}

function loadParts(motor_id){
	var tip=document.getElementById('tip').value;
	var cod=document.getElementById('cod').value;
	
	new Ajax.Request('lookup.php?motor_id='+motor_id+'&tip='+tip+'&cod='+encodeURIComponent(cod),
	{ 
		method:'get',
		onSuccess: function(transport){
			document.getElementById('list_parts').innerHTML=transport.responseText;
		},
		onFailure: function(transport){
		}
	});	
}

function search_model(model){
	if(model.length<3){
		return;
	}
	try{
		new Ajax.Request(
			'get_model.php?model=' + model,
			{
				method : 'get',
				onSuccess : function(transport) {
					try{
						var json=eval('(' + transport.responseText + ')');
						var jsonLen=json.models.length;
						if(jsonLen==0){
							set_popup('');
						}else{
							var html='';
							for(var i=0;i<jsonLen;i++){
								html+='<a href="'+json.models[i].url+'">'+json.models[i].label+'</a><br>';
							}
							
							set_popup(html);
						}
					}catch(e){
						alert('error: '+e)
						document.getElementById('cauta_model').value='';
						set_popup('');
					}
					
				},
				onFailure : function(transport) {
					document.getElementById('cauta_model').value='';
					set_popup('');
				}
			});
	}catch(eAjax){
		alert(eAjax);
	}
	
}
function set_popup(value){
	document.getElementById('search_by_model_results').innerHTML=value;
	if(value==''){
		document.getElementById('search_by_model_results').style.display='none';
	}else{
		document.getElementById('search_by_model_results').style.display='';
	}
}
function processSpitsSelection(){
		var q_1_1 = jQuery("#q_1_1").is(':checked');
		var q_1_2 = jQuery("#q_1_2").is(':checked');

		var q_2_1 = jQuery("#q_2_1").is(':checked');
		var q_2_2 = jQuery("#q_2_2").is(':checked');
		
		var q_3_1 = jQuery("#q_3_1").is(':checked');
		var q_3_2 = jQuery("#q_3_2").is(':checked');
		
		var type = "";
		if((q_1_1||q_1_2)&&(q_2_1||q_2_2)&&(q_3_1||q_3_2)){
			var image = "";
			if(q_1_1){
				if(q_2_1){
					if(q_3_1){
						image = "A1-BY-CY.gif";
						type = 4;
					} else {
						image = "A1-BY-CN.gif";
						type = 3;
					}
				} else {
					if(q_3_1){
						image = "A1-BN-CY.gif";
						type = 2;
					} else {
						image = "A1-BN-CN.gif";
						type = 1;
					}
				}
			} else {
				if(q_2_1){
					if(q_3_1){
						image = "A2-BY-CY.gif";
						type = 8;
					} else {
						image = "A2-BY-CN.gif";
						type = 7;
					}
				} else {
					if(q_3_1){
						image = "A2-BN-CY.gif";
						type = 6;
					} else {
						image = "A2-BN-CN.gif";
						type = 5;
					}
				}
			}
			var content = "<br/><img src='images/identificator_produse/tipuri/"+image+"' style='border:none' />";
			jQuery("#spit_type_container").html(content);
			window.location.href = "identificator-produse.php?type="+type;
		}
}
