// JavaScript Document

function cancelAL(){
	
	var url = document.location.href;
						
	if(url.indexOf("?") > 0){
		url = url.split("?");
		
		document.location.href = url[0]+"?account"; 
	}
	
	
	
}

function hideAlerts(){
	$(".invisible").hide();
	clearInterval();
}


function changeLevels(){
	
	$(".invisible").hide();
	
	var lvl = new Array();
	var dataCorrect = true;
	var filledCorrectly = true;
	
	for(var i=0; i<4 ; i++){
		lvl[i] = Number($("#level"+(i+1)).val());
		//alert(i+": "+lvl[i]);
		if($("#level"+(i+1)).val().length == 0){
			filledCorrectly = false;
			break;
		}
	}
	
	if(0 > lvl[0] || lvl[0] > lvl[1] || lvl[1] > lvl[2] || lvl[2] > lvl[3]){ 
		dataCorrect = false;
	};
	
	if(dataCorrect && filledCorrectly){
		
		var vars = '';
		for(i=0;i<4;i++){
			if(i > 0){
				vars += '&';
			}
			vars += 'lvl'+i+'='+lvl[i];
		}
		
		//alert(vars);
		
		$.ajax({ 											// -------------------------------- AJAX
			type: "POST", 									//--------------------- type
			url: "account/ajaxDocs/ajaxChangeLevels.php",	//--------------------- url
			data: vars,
			dataType: "json",
			beforeSend: function(){							//--------------------- beforeSend
				//$("#loading").show();
				
			},
			success: function(data){ 						//--------------------- success
				//alert(data);
				if( data.error < 0 ){
					$("#alert2").show();
					setTimeout('$("#alert2").fadeOut()',5000);
					//alert(data.msg);
				}
				else{
					alert("error from ajax (ajaxChangeLevels.php): "+data.errorMsg);
				}
				
			},
			complete: function(){     						//-------------------- complete
				//$("#loading").hide();
				//setInterval('hideAlerts()', 5*1000 );
			}
		});	
		
	}
	else{
		if(!dataCorrect) { $("#alert3").show(); }
		else if(!filledCorrectly) { $("#alert1").show(); }
	}
	
	
}



function checkInput(elem){
	
	var id = $(elem).attr("id");
	$("#"+id+"ext").html($(elem).val());
}

jQuery(document).ready(function(){

	$(".haveExt").each(function(){
    	//$(this).val(0);
		$(this).keyup(function(){checkInput(this);});
		//$(this).addClass("withSuggestion");
		//$(this).blur(function(){inputSuggestionOnBlur(this);});
		//$(this).focus(function(){inputSuggestionOnFocus(this);});
    });
	

});
