// Associate-O-Matic v4.4.0



function popup(purl, pw, ph) {

	pww = pw + 30;

   	pwh = ph + 30;

	winpops = window.open('', 'imgWindow', 'width=' + pww + ',height=' + pwh);

   	winpops.document.write('<html><head><title></title></head><body style=\'cursor:pointer;\' onload=\'this.focus();\' onclick=\'window.close();\' onblur=\'window.close();\'><img alt=\'\' src=\'' + purl + '\' width=\'' + pw + '\' height=\'' + ph + '\'></body></html>');

	winpops.document.close();

}



function popupCond(msg) {

	winpops = window.open('', 'imgWindowTerms', 'width=300,height=300,resizable=1,scrollbars=yes') 

	winpops.document.write('<html><head><title></title></head><body onload=\'this.focus();\' onclick=\'window.close();\' onblur=\'window.close();\'>' + msg + '</body></html>');

	winpops.document.close();

}



function popupPricing(msg) {

	winpops = window.open('','imgWindowPricing','width=230,height=230,resizable=1,scrollbars=no') 

	winpops.document.write('<html><head><title></title></head><body onload=\'this.focus();\' onclick=\'window.close();\' onblur=\'window.close();\' style=\'cursor:pointer;\'><span class=\'aom_pdr\'>' + msg + '</span></body></html>')

	winpops.document.close();

}



function popupTerms(msg) {

	winpops = window.open('','imgWindowPricing','width=500,height=400,resizable=1,scrollbars=yes') 

	winpops.document.write('<html><head><title></title></head><body onload=\'this.focus();\' onclick=\'window.close();\' onblur=\'window.close();\' style=\'cursor:pointer;\'><span class=\'aom_pdr\'>' + msg + '</span></body></html>')

	winpops.document.close();

}



function checkVariation(msg) {

	var selection=document.Variation.elements['offerlistingid'].selectedIndex;

	if (selection=="-1") {

		alert(msg);

		document.Variation.elements['offerlistingid'].focus();

		return false;

	}

	return true;

}



function redirectSameWindow(msg) {

	if (document.Variation.elements['offerlistingid'].value != '') {

		window.open(document.Variation.elements['offerlistingid'].value, 'win');

	}

	else {

		alert(msg);

	}

}



function redirectNewWindow(msg) {

	if (document.Variation.elements['offerlistingid'].value != '') {

		location.href(document.Variation.elements['offerlistingid'].value);

	}

	else {

		alert(msg);

	}

}



function searchInside() {

	swn = document.getElementById('aom_swn').value;

	swk = document.getElementById('aom_swk').value;

	sbox = document.getElementById('aom_sbox').value;

	if (swk != sbox)

		searchinside = swk + ' ' + sbox;

	else

		searchinside = swk;

	document.getElementById('aom_sbox').value = searchinside;

	if (swn != '')

		document.getElementById('aom_swn').name = 'n';

	document.getElementById('aom_search').submit();

}



function displayDate(amz) {

	var t = new Date();

	var month = t.getMonth() + 1;

	var day = t.getDate();

	var year = t.getFullYear();

	

	if (amz=='Amazon.de' || amz=='Amazon.fr' || amz=='Amazon.co.uk') {

		month = String(month);

		day = String(day);

		if (month.length == 1)

			month = "0" + month;

		if (day.length == 1)

			day = "0" + day;

	}

	

	if (amz=='Amazon.de')

		document.write(day + '.' + month + '.' + year)

	else if (amz=='Amazon.co.uk' || amz=='Amazon.fr')

		document.write(day + '/' + month + '/' + year)

	else if (amz=='Amazon.co.jp')

		document.write(year + '&#24180;' + month + '&#26376;' + day + '&#26085')

	else

		document.write(month + '/' + day + '/' + year)

}



function enableField(id) {

	document.getElementById(id).disabled=false;

}





$(document).ready(function(){

	$("a[rel='gallery']").each(function(){

        $(this).colorbox({href:$(this).attr('caption')});

    }); 

	$("a[rel='gallery2']").each(function(){

        $(this).colorbox({href:$(this).attr('caption')});

    }); 

	

});



	

function autoList(script,parent,child,childVal,childLbl,childLbl2)

{	

	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");

	$('#'+parent+child).html($("#"+child+" option"));

	

	var parentValue = $('#'+parent).attr('value');

	$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());



	childVal = (typeof childVal == "undefined")? "" : childVal ;

	$("#"+child).val(childVal).attr('selected','selected');



	$('#'+parent).change(function(){

		

		var parentValue = $('#'+parent).attr('value');

	    $('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());

		$('#'+child).prepend("<option value='none' selected='selected'>"+childLbl+"</option>");

		

		var year = $("#year").val();

		var make = $("#make").val();

		var model = $("#model").val();

		

		mk = 0;

		vs = "Year=" + year;

		if (make!="none" && make!="make") {

			vs = vs + "&Make=" + make;

			mk = 1;

		}

				

		if (model!="none" && model!="model" && mk) {

			vs = vs + "&Model=" + model;

			md = 1;

		}

		else {

			$('#model').html('');

			$('#model').prepend("<option value='none' selected='selected'>"+childLbl2+"</option>");

			md = 0;

		}

		

		var  position = $(this).offset(); 

		$('<img src="aom/images/indicator.gif" id="spinner" />').css('position','absolute').hide().appendTo('body');

		$('#spinner').css({ top: position.top +22 , left: position.left + $(this).width() -40 }).fadeIn();

		

		

		$.getJSON(script + '?ajax=true&a=auto&' + vs, function(data){ 

		  

		  var options = '';

		  options += '<option class="sub_' + parentValue + '" value="">' + childLbl + '</option>';

    	  for (var i = 1; i < data.length; i++) {

		  	options += '<option class="sub_' + parentValue + '" value="' + data[i].optionValue + '">' + data[i].optionDisplay + '</option>';

	      }

    	  $('#'+child).html(options);

	    })

		

		$('#spinner').fadeOut(); 

		$('#'+child).focus();

		

	});

	

}




