function limitText(obj, id, maxText){
	if(obj.value.length > maxText){
		obj.value = obj.value.substring(0,maxText);
	}else{
		oid = document.getElementById(id);
		oid.innerHTML = maxText - obj.value.length + " characters left";
	}
}

function checkQty(obj){
	if(isNaN(obj.value)){
		obj.value = 1;
	}
}

function printpage() {
	window.print();  
}

function unusedexpandMe(obj){
	if(obj.className == '' || obj.className == 'openbar'){
		obj.className = 'closebar';
		$("#topminibox").hide();
		$("#opentext").show();
		$("#closetext").hide();
	}else{
		obj.className = 'openbar';
		$("#topminibox").show();
		$("#closetext").show();
		$("#opentext").hide();
	}
}

function hideMe(ddID, id){
	$("#" + ddID).val('');
	$("#" + id).removeClass("class", "showme");
	$("#" + id).addClass("class", "hideme");
	$("#" + id).hide();
}

function expandMe(obj, id){
	if(obj.selectedIndex == 0){$("#" + id).hide();return;}else{$("#" + id).show();}
	if($("#" + id).attr("class") == '' || $("#" + id).attr("class") == 'showme'){
		$("#" + id).removeClass("class", "showme");
		$("#" + id).addClass("class", "hideme");
	}else{
		$("#" + id).removeClass("hideme");
		$("#" + id).addClass("showme");
	}
}

function clearMe(obj){
	if(obj.value == "Search"){obj.value = "";}
}

function openPrintBatteryPage(url){
	window.open('/desktopmodules/web105_onlineshop/printbatterypage.aspx?' + url);
}

function openPrintPowerSportPage(url){
	window.open('/desktopmodules/web105_onlineshop/printpowersportpage.aspx?' + url);
}

function openPrintPowerSportTablePage(url){
	window.open('/desktopmodules/web105_onlineshop/printpowersporttablepage.aspx?' + url);
}

function openPrintBatteryTablePage(url){
	window.open('/desktopmodules/web105_onlineshop/printbatterytablepage.aspx?' + url);
}

function openEmailBatteryPage(url){
	window.open('/desktopmodules/web105_onlineshop/emailbatteryfriend.aspx?url=' + url);
}

function getBrand(obj, idBrand, btnID){
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
	id = obj.options[obj.selectedIndex].value;
	$.get('/desktopmodules/web105_onlineshop/OtherBrandLoader.ashx?random=' + randomNumber() + '&id=' + id, function(data) {																											
	    $("#" + idBrand).html(data);
		if(document.getElementById(idBrand).options.length > 1){
			$("#" + btnID).removeClass("button_gohide");
			$("#" + btnID).addClass("button_go");
		}
	});
}

function getSize(obj, btnID){
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");

	if(obj.selectedIndex > 0){
		$("#" + btnID).removeClass("button_gohide");
		$("#" + btnID).addClass("button_go");
	}
}

function getOldMake(obj, idMake, idModel, idYear, idCC, btnID){
	id = obj.options[obj.selectedIndex].value;
	$.get('/desktopmodules/web105_onlineshop/MakeLoader.ashx?random=' + randomNumber() + '&id=' + id, function(data) {
	    $("#" + idMake).html(data);
	});
	$("#" + idModel).html('<option>Select Model</option>');
	$("#" + idYear).html('<option>Select Year</option>');
	if($("#" + idCC)){$("#" + idCC).html('<option>Select CC</option>');}
	//hide cc
	if(id==1 || id==2 || id==3 || id==5){	
		$("#divCC").removeClass("showme");
		$("#divCC").addClass("hideme");
	}else{
		$("#divCC").removeClass("hideme");
		$("#divCC").addClass("showme");
	}
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
}

function getMake(obj, idMake, idModel, idYear, idCC, btnID){
	id = obj.options[obj.selectedIndex].value;
	$.get('/desktopmodules/web105_onlineshop/MakeLoader.ashx?random=' + randomNumber() + '&id=' + id, function(data) {
	    $("#" + idMake).html(data);
	});
	$("#" + idModel).html('<option>Select Model</option>');
	$("#" + idYear).html('<option>Select Year</option>');
	if($("#" + idCC)){$("#" + idCC).html('<option>Select CC</option>');}
	
	//hide cc
	if(id==1 || id==2 || id==3 || id==5){	
		$("#divCC").removeClass("showme");
		$("#divCC").addClass("hideme");
	}else{
		$("#divCC").removeClass("hideme");
		$("#divCC").addClass("showme");
	}
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
}


function getOldModel(idVehicle, idMake, idModel, idYear, idCC, btnID){
	$.get('/desktopmodules/web105_onlineshop/ModelLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&cc=' + $('#' + idCC + ' option:selected').text(), function(data) {
	    $("#" + idModel).html(data);
	});
	$("#" + idYear).html('<option>Select Year</option>');
	if($("#" + idCC)){$("#" + idCC).html('<option>Select CC</option>');}
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
}

function getModel(idVehicle, idMake, idModel, idYear, idCC, btnID){
	obj = document.getElementById(idVehicle);
	id = obj.options[obj.selectedIndex].value;
	if(id==1 || id==2 || id==3 || id==5){	
		$.get('/desktopmodules/web105_onlineshop/ModelLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&cc=' + $('#' + idCC + ' option:selected').text(), function(data) {
			$("#" + idModel).html(data);
		});
		$("#" + idYear).html('<option>Select Year</option>');
		//if($("#" + idCC)){$("#" + idCC).html('<option>Select CC</option>');}
		$("#" + btnID).removeClass("button_gohide");
		$("#" + btnID).removeClass("button_go");
		$("#" + btnID).addClass("button_gohide");
	}
}

function getCCModel(idVehicle, idMake, idModel, idYear, idCC, btnID){	
	$.get('/desktopmodules/web105_onlineshop/ModelLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&cc=' + $('#' + idCC + ' option:selected').text(), function(data) {
		$("#" + idModel).html(data);
	});
	$("#" + idYear).html('<option>Select Year</option>');
	//if($("#" + idCC)){$("#" + idCC).html('<option>Select CC</option>');}
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
}

function getOldCC(idVehicle, idMake, idModel, idCC){
	if($("#divCC").attr("class") == 'showme'){
		$.get('/desktopmodules/web105_onlineshop/CCLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&model=' + $('#' + idModel + ' option:selected').text(), function(data) {																																																												
			$("#" + idCC).html(data);
		});
	}
}

function getCC(idVehicle, idMake, idModel, idCC){
	if($("#divCC").attr("class") == 'showme'){
		$.get('/desktopmodules/web105_onlineshop/CCLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&model=' + $('#' + idModel + ' option:selected').text(), function(data) {																																																								
			$("#" + idCC).html(data);
		});
	}
}

function getFitmentYear(idVehicle, idMake, idModel, idYear, idCC, btnID){
	$("#" + btnID).removeClass("button_gohide");
	$("#" + btnID).removeClass("button_go");
	$("#" + btnID).addClass("button_gohide");
	
	if($("#" + idCC)){
		if($('#' + idCC + ' option:selected').text() != "Select CC"){
			$.get('/desktopmodules/web105_onlineshop/YearLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&cc=' + $('#' + idCC + ' option:selected').text() + '&model=' + $('#' + idModel + ' option:selected').text(), function(data) {
				$("#" + idYear).html(data);
				$("#" + btnID).removeClass("button_gohide");
				$("#" + btnID).addClass("button_go");
			});
		}else{
			$.get('/desktopmodules/web105_onlineshop/YearLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&model=' + $('#' + idModel + ' option:selected').text(), function(data) {
				$("#" + idYear).html(data);
				$("#" + btnID).removeClass("button_gohide");
				$("#" + btnID).addClass("button_go");
			});
		}
	}else{
		$.get('/desktopmodules/web105_onlineshop/YearLoader.ashx?random=' + randomNumber() + '&id=' + $("#" + idVehicle).val() + '&make=' + $('#' + idMake + ' option:selected').text() + '&model=' + $('#' + idModel + ' option:selected').text(), function(data) {
			$("#" + idYear).html(data);
			$("#" + btnID).removeClass("button_gohide");
			$("#" + btnID).addClass("button_go");
		});
	}
}

function randomNumber(){
	return Math.floor(Math.random()*11);
}

function submitSearch(idVehicle, idMake, idModel, idYear, iCC, hiddenMake, hiddenModel, hiddenYear, hiddenCC){
	var vehicleValue = $('#' + idVehicle).val();
	var makeValue = $('#' + idMake).val();
	var modelValue = $('#' + idModel).val();
	var yearValue = $('#' + idYear).val();
	var ccValue = $('#' + iCC).val();
	var message = "";
	if(vehicleValue == "" || vehicleValue == "Select Vehicle Type"){message += "Vehicle type is required";alert(message);return false;}
	if(makeValue == "" || makeValue == "Select Make"){message += "Make is required"; alert(message);return false;}
	if(modelValue == "" || modelValue == "Select Model"){message += "Model is required"; alert(message);return false;}
	if((yearValue == "" && $('#' + idYear + ' option').length > 1) || (yearValue == "Select Year" && $('#' + idYear + ' option').length > 1)){message += "Year is required"; alert(message);return false;}
	if($('#' + iCC)){
		if((ccValue == "" && $('#' + iCC + ' option').length > 1) || (ccValue == "Select CC" && $('#' + iCC + ' option').length > 1) ){
			message += "Vehicle cc is required"; alert(message);return false;
		}
	}

	$('#' + hiddenMake).val(makeValue);
	$('#' + hiddenModel).val(modelValue);
	if(yearValue != "Select Year"){$('#' + hiddenYear).val(yearValue); }
	if(ccValue != "Select CC"){$('#' + hiddenCC).val(ccValue);}
	
	return true;
}

function submitSearchBrand(idBrand, idOtherBrand, hiddenOtherBrand){
	var brandValue = $('#' + idBrand).val();
	var otherBrandValue = $('#' + idOtherBrand).val();
	var message = "";
	if(brandValue == "" || brandValue == "Select a Brand"){message += "Brand is required";}
	if(otherBrandValue == "" || otherBrandValue == "Select PartNo"){message += "PartNo is required";}
	if(message != ""){alert(message);return false;}
	$('#' + hiddenOtherBrand).val(otherBrandValue);
	return true;
}

function submitSearchSize(idSize){
	var sizeValue = $('#' + idSize).val();
	var message = "";
	if(sizeValue == "" || sizeValue == "Select Size"){message += "Size is required";}
	if(message != ""){alert(message);return false;}
	btn.className = "button_go";
	return true;
}

function changeRidImage(obj, srcImg){
	obj.src = '/Portals/2/Skins/Powersport/Images/motorcycletypes/' + srcImg;
}
