// JavaScript Document

/* Functions that checks which product type is selected and sees if the related model dropdown has been selected
function mycheck(){
	
	if (($('model').getSelected().get('value') == '0' && $('prod').getSelected().get('value') == 'aibo')) {
		$('model').className="validate['required'] input-border";
		return false;
		}	
	else {return true;}	
}
*/
var aibo_models = new Array(
						["",""],	
						["ERS-111/H, Metallic Black","11190251"],
						["ERS-111/W, Gray Silver","11190250"],
						["ERS-210/B, Black","11190352"],
						["ERS-210/D, Orange","11190354"],
						["ERS-210/N, Gold","11190351"],
						["ERS-210/S, Silver","11190350"],
						["ERS-210/V, Sapphire Violet","11190356"],
						["ERS-210/W, White","11190353"],
						["ERS-210/W1, Everest White","11190357"],
						["ERS-111/H, Metallic Black","11190251"],
						["ERS-210/Y, Mazeran Green","11190355"],
						["ERS-210A /B, Black","11191252"],
						["ERS-210A /N, Gold","11191251"],
						["ERS-210A /S, Silver","11191250"],
						["ERS-220","11190750"],
						["ERS-220A","11191350"],
						["ERS-311, Ivory","11190450"],
						["ERS-312, Grey","11190650"],
						["ERS-7, Pearl White","11191650"],
						["ERS-7M2 /B, Pearl Black","11191850"],
						["ERS-7M2 /W, Pearl White","11191750"],
						["ERS-7M3 /B, Pearl Black","11191951"],
						["ERS-7M3 /T, Gold-like","11191952"],
						["ERS-7M3 /W, Pearl White","11191950"]);


var clie_models = new Array(
					 	["",""],	
						["PEG-N770C/E","28934050"],
						["PEG-N770C/U","28934060"],
						["PEG-NR70V/E","28936050"],
						["PEG-NX70V/E","28939650"],
						["PEG-NX73V/E","29032050"],
						["PEG-NZ90/E","28939850"],
						["PEG-NZ90/G","28939870"],
						["PEG-S300/E","28931550"],
						["PEG-S300/U","28931560"],
						["PEG-SJ22/E","29030650"],
						["PEG-SJ30/E","28937650"],
						["PEG-SJ33/E","28940050"],
						["PEG-SJ33/EL","28940052"],
						["PEG-SL10/E","28937450"],
						["PEG-T425","28934750"],
						["PEG-T625C","28934850"],
						["PEG-T675C","28937250"],
						["PEG-TG50/E","28939950"],
						["PEG-TH55/E1","29031850"],
						["PEG-TH55/E2","29031855"],
						["PEG-TJ25","29031530"],
						["PEG-TJ25/E1","29031550"],
						["PEG-TJ25/E2","29031555"],
						["PEG-TJ27/E1","29033850"],
						["PEG-TJ27/E2","29033855"],
						["PEG-TJ35/E1","29031750"],
						["PEG-TJ35/E2","29031755"],
						["PEG-TJ37/E1","29032350"],
						["PEG-TJ37/E2","29032355"],
						["PEG-UX50/E","29033350"] 
											 );

var vp_models = new Array(["",""],["VGF-AP1","28161550"],["VGF-AP1L","28161650"]);

function removeAllOptions(selectbox){
	$('#model *:checkbox').each(function(i){
						remove($(this));	   
							   });
	$('#model').empty();
	}

$(document).ready(function() {

if($('#clieform')){

/* launch the form check function and hide below sections*/
	$('#clieform').validationEngine();
	$('#form_aibo, #product, #service, #invoice, #collection, #delivery, #defect, .login, #partbuy, #delivery').css('display','none');
	
	/* Depending on the product selected, show relative sections*/
	
	$('#prod').bind("change",function(e){
		if($('#prod option:selected').val() == 'aibo'){
			$('#product, #service, #form_aibo').css('display','block');
			$('#invoice,.login').css('display','none');
			$('.login').addClass("validate[length[1,50],alphanum] input-border");	
			
			removeAllOptions($('#model'));
			
			for (i=0;i<aibo_models.length;i++){
				newopt = $('<option></option>')
							.attr('value',aibo_models[i][1])
							.html(aibo_models[i][0]);
				$('#model').append(newopt)
				}
			
			}	
		else if($('#prod option:selected').val()== 'vaio'){
			$('#product, #service, #form_aibo').css('display','block');
			$('#invoice, .login').css('display','none');
			$('.login').addClass("validate[length[1,50],alphanum] input-border");
			
			removeAllOptions($('#model'));

			
			for (i=0;i<vp_models.length;i++){
				newopt  = $('<option></option>')
								.attr('value',vp_models[i][1])
								.html(vp_models[i][0]);
				$('#model').append(newopt)
				}

			}	
		else if($('#prod option:selected').val()== 'clie'){
			$('#product, #service, .login, #form_aibo').css('display','block');
			$('#invoice').css('display','none');
			$('.login').addClass("validate[length[1,50],required] input-border");	
			
			removeAllOptions($('#model'));

			for (i=0;i<clie_models.length;i++){
				newopt  = $('<option></option>')
								.attr('value',clie_models[i][1])
								.html(clie_models[i][0]);
				$('#model').append(newopt)
				}			
			}		
		else {
			$('#product, #service,#invoice,.login,#form_aibo').css('display','none');
			$('#form_aibo').css('display','none');
			}	
		
});



	$('#model').bind("change",function(e){
			$('#serial_nr').val('');
			$('#prcode').html($('#model option:selected').val());									  
	});

	
	$('#method').bind("change",function(e){
		if($('#method option:selected').val()== 'repair'){
			/* make partbuy info not mandatory*/
			$('#partbuy').addClass("input-border");			
			$('#partbuy').css('display','none');
			$('#defect,#collection,#invoice,#delivery').css('display','block');
			$('#adr11,#symptom,#country1,#city1,#postcode1,#invoice,#delivery').addClass("validate[required] input-border");
			}	
		else if($('#method option:selected').val()== 'part'){
			/* make partbuy info mandatory*/
			/* The below does not prevent to send*/
			var partclass= "left input-border validate[required]";
			$('#partbuys').addClass(partclass);
			$('#partbuy,#delivery,#invoice').css('display','block');
			$('#defect,.login,#same1coll').css('display','none');
			/* make login info not mandatory*/
			$('.login').addClass("input-border");			
			}	
		else {
			$('#partbuy,#defect,.login,#delivery').css('display','none');
			}						
	});
	
	$('#same1').bind("click",function(e){
			if ($('#same1').attr('checked') == true){							 
				$('#adr22').val($('#adr12').val());	
				$('#adr21').val($('#adr11').val());
				$('#city2').val($('#city1').val());
				$('#postcode2').val($('#postcode1').val());
				$('#country2').val($('#country1 option:selected').val());
				$('#adr21, #adr22, #city2, #postcode2').attr('readonly','readonly')
				.attr('class','inactive');
//				$('#country2').attr('disabled','disabled');
			}else{
				$('#adr22, #adr21, #city2, #postcode2, #country2').val('');
				$('#adr21, #adr22, #city2, #postcode2').removeAttr("readonly");				
				$('#country2').removeAttr("disabled");
				$('#adr21, #city2, #postcode2, #country2').addClass("left input-border validate[required]");
				$('#adr22').addClass('left input-border');
				}
		});


	$('#same2').bind("click",function(e){
		 /* If the 3rd adress is the same as the 2nd */
			if ($('#same2').attr('checked') == true){
				$('#adr32').val($('#adr22').val());	
				$('#adr31').val($('#adr21').val());	
				$('#city3').val($('#city2').val());	
				$('#postcode3').val($('#postcode2').val());	
				$('#country3').val($('#country2 option:selected').val());
				$('#adr31, #adr32, #city3, #postcode3').attr('readonly','readonly')
				.attr('class','inactive');
				
			}else{
				$('#adr32,#adr31,#city3,#postcode3.#country3').val('');	
				$('#adr31, #adr32, #city3,#postcode3').removeAttr("readOnly");
//				$('#country3').removeAttr("disabled");
				$('#adr31, #city3, #postcode3, #country3').addClass("left input-border validate[required]");
				$('#adr32').addClass("left input-border");
				
				}
		});
	
	$('#country3').bind("change",function(e){
		if($('#method option:selected').val()== 'repair')	{							 
			$('#country3').val($('#country1').val());
			$('#country3').attr('disabled','disabled');
		}
	});
	$('#prod').bind("change",function(e){
		if($('#method option:selected').val()== 'repair')	{							 
			$('.login').css('display','block');
		}
	});	
	if($('#method option:selected').val()== 'repair' && $('#prod option:selected').val()== 'clie')
	/* make login info mandatory if clie*/
			$('.login').css('display','block');	
			$('#logintxt, #password').addClass("validate[length[1,50],alphanum,required] input-border");	
	};
});