var win = null;
function NewWindow(mypage,myname,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(mypage,myname,settings)
}
function updatePType(toggle) {
	if (toggle == 1) {
		if (document.forms[0].pvtype.value > '') {
			document.forms[0].pt1.checked = false;
			document.forms[0].pt2.checked = true;
		}
	} else if (toggle == 2) {
		if (document.forms[0].existing_option.value > '') {
			document.forms[0].pt1.checked = true;
			document.forms[0].pt2.checked = false;
		}
	}
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	return true;
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length) {
		if(arr[index] == ele) {
			found = true;
		} else {
			index++;
		}
		return found;
	}
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1) {
		if (input.form[i] == input) {
			index = i;
		} else {
			i++;
		}
	}
	return index;
}

function checkUserName(uName,type) {
	NewWindow("checkuser.html?un="+uName+"&type="+type,"chkuser",300,150,"no");
}

function updateModel(ctrlnumber) {
	var cname1 = '';
	var cname2 = '';
	if (ctrlnumber == 1) {
		cname1 = 'vehicle_make';
		cname2 = 'vehicle_model';
		cname3 = 'model1';
	} else {
		cname1 = 'vehicle_make2';
		cname2 = 'vehicle_model2';
		cname3 = 'model2';
	}
	
	if (document.getElementById(cname1).value == 45) {
		// Make model a select
		document.getElementById(cname3).innerHTML = "<select name='"+cname2+"'><option value='Citycom 300i'>Citycom 300i</option><option value='DD 50'>DD 50</option><option value='Fiddle 50'>Fiddle 50</option><option value='Fiddle II 50'>Fiddle II 50</option><option value='Fiddle II 125'>Fiddle II 125</option><option value='HD 125'>HD 125</option><option value='HD 200'>HD 200</option><option value='Jet Euro 50'>Jet Euro 50</option><option value='Mio 50'>Mio 50</option><option value='RS 50'>RS 50</option><option value='RV 250'>RV 250</option><option value='SYMBA 110'>SYMBA 110</option><option value='Symply 50'>Symply 50</option></select>";
	} else {
		// Make model a text box
		document.getElementById(cname3).innerHTML = "<input type='text' name='vehicle_model' size='30'>";		
	}
}