var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {

	//next = input.tabIndex+1;
	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 ( (e.keyCode>=48 && e.keyCode<=57) || (e.keyCode>=96 && e.keyCode<=109) ) {
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
			input.value = input.value.slice(0, len);
			//set focus on the next phone input ( just next input in the form ):
			input.form[(getIndex(input)+1) % input.form.length].focus();
			input.form[(getIndex(input)+1) % input.form.length].select();
		}
	}
	
	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;
		
	}
	
	return true;
}


function OnlyNumeral(e ) {
	/*-----for Mozilla only----*/
	if ( e.keyCode == 9 ) { return; }   //ignore TAB
	/*-------------------------*/
	// Make sure to use event.charCode if available
	var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

	// Ignore special keys 1102
	if ((e.ctrlKey || e.altKey || key > 57 || key < 48) && e.keyCode!=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40){
		return false;
	}
}


/*This function generates states dropdown for selected country*/
function setStateOptions( idx, state ) { 
	var state_obj = document.getElementById( 'state' );
	state_obj.options.length = 0;
	for ( var i=0; i<states[idx].length; i++ ){
		var pair=states[idx][i];
		state_obj.options[i] = new Option( pair[1], pair[0] );
		if ( state ) {
			if ( state == pair[0] ) {
				state_obj.options[i].selected="true";
			}
		}
	}
}


