// JavaScript Document
function Get(ID){
	return document.getElementById(ID);
}

function Toogle(Element){
	if(Element.src.indexOf('-over') != -1){
		Element.src = Element.src.substr(0, Element.src.indexOf('-over')) + Element.src.substr(Element.src.indexOf('-over')+5, Element.src.length);
	} else {
		Element.src = Element.src.substr(0, Element.src.lastIndexOf('.')) + '-over' + Element.src.substr(Element.src.lastIndexOf('.'), Element.src.length);
	}
}

function Backend(Action, QueryString){
	document.location.href = BasePath + 'backend/action.php?Action=' + Action + '&' + QueryString;
}

function Submit(Action){
	if(Action.length > 0) Get('Action').value = Action;
	
	Get('ShopForm').submit();
}

function Basket(){
	$.ajax({
		url: BasePath + 'backend/action.php?Action=Shop-Basket',
		type:'POST',
		data:{'Trays':$('#Trays').val(),'Design':$('#Design').val()},
		dataType:'HTML',
		cache: false,
		success: function(Content){
			$("#LeftColumn").html(Content);
		}
	});
}

function Show(ID){
	Get(ID).className = 'Show';
}

function Hide(ID){
	Get(ID).className = 'Hide';
}

function Etikett(){
	$('#Cover').css({'width':$('#Holder').width() + 'px', 'height':$('#Holder').height() + 'px'});
}

function Check(){
	var Option;
	var Value;
	
	Count = 0;
	CountFirstThree = 0;
	Options = new Array();	
	
	for(A=0; A<3; A++){
		$('#Attribute' + A + ' option').removeAttr('disabled');
		
		Option = $('#Attribute' + A).val();
		if(Option == 'X') Option = '';
		if(Option.length > 0) Options.push(Option);
		if(Option.length == 0) $('#Value' + A).val('');
		
		Value = $('#Value' + A).val();
		
		if(Option.length > 0 && Value.length > 0){ 
			Count++;
			CountFirstThree++;
		}
	}
		
	for(A=3; A<7; A++){
		$('#Attribute' + A + ' option').removeAttr('disabled');
		
		if(CountFirstThree < 3){
			$('#Attribute' + A).val('X');
			$('#Value' + A).val('');
		} else {
			
			Option = $('#Attribute' + A).val();			
			if(Option == 'X') Option = '';
			if(Option.length > 0) Options.push(Option);
			if(Option.length == 0) $('#Value' + A).val('');
			Value = $('#Value' + A).val();
			
			if(Option.length > 0 && Value.length > 0) Count++;
		}
	}

	
	for(O=0; O<Options.length; O++){
		for(A=0; A<7; A++){
			if($('#Attribute' + A).val() == Options[O]) continue;
			$('#Attribute' + A + ' option[value=\'' + Options[O] + '\']').attr('disabled', 'disabled');
		}
	}

	for(A=0; A<7; A++){
		if(A<Count) $('#Dot' + A).attr('src', 'images/dot-active.gif');
		else $('#Dot' + A).attr('src', 'images/dot.gif');
	}
	
	if(CountFirstThree < 3){
		Get('MoreFields').className = 'Hide';
		Get('MoreCount').innerHTML = TextAmount1  + (3-CountFirstThree) + (3-CountFirstThree == 1 ? TextAmount2Single : TextAmount2Multiple);
		
		Get('Help1').className = 'Show';
		Get('Help2').className = 'Hide';
		
	} else {
		Get('MoreFields').className = 'Show';
		Get('MoreCount').innerHTML = TextReady;
		
		Get('Help1').className = 'Hide';
		Get('Help2').className = 'Show';
	}
		
}

function ChangeBottleLayout(To) {
	Get('BottleSWFHolder').innerHTML = '<a href="javascript:void(0);" title="Learn more about VIEW" onclick="javascript:Etikett(); Show(\'Cover\'); Show(\'Etikett\');"><img src="images/bottle.jpg" /></a>';	
	Get('BottleSWFHolder').innerHTML = '<img src="images/design-bottles/'+ To +'.jpg" />';	
}
