
function loadMainPage() {
	var args = loadMainPage.arguments;
//	alert(args[0]);
	
	if(args[2]) {
		value = $('#' + args[2]).val();
		target = args[2] + '=' + value;
		
		// Check if we got more POST vars in our function arguments.
		
		if(args[1]) {
			args[1] = args[1] + '&' + target;
		} else {
			args[1] = target;
		}
		// alert(args[1]);
	}
	
	if(args[3]) {
		var parameters1 = $('input').serialize();
		var parameters2 = $('textarea').serialize();
		var parameters3 = $('select').serialize();
		//alert(parameters3);
		var params = parameters1 + '&' + parameters2 + '&' + parameters3;
		
		if(args[1]) {
			args[1] = args[1] + '&' + params;
		} else {
			args[1] = params;
		}
		//alert(args[1]);
	}

	$.ajax({
		url: args[0],
		type: 'POST',
		dataType: 'html',
		data: args[1],
		timeout: 50000,
		error: function(){
			alert('Error loading XML document');
		},
		success: function(xml){
			$('#content').html(xml);
		}
	});
	
}


function loadPage() {
	var args = loadPage.arguments;
//	alert(args[4]);
//	alert('hejsan');
	
	if(args[2]) {
		value = $('#' + args[2]).val();
		target = args[2] + '=' + value;

		// Check if we got more POST vars in our function arguments.
		
		if(args[1]) {
			args[1] = args[1] + '&' + target;
		} else {
			args[1] = target;
		}
		// alert(args[1]);
	}
	
	if(args[3]) {
		var parameters1 = $('input').serialize();
		var parameters2 = $('textarea').serialize();
		var parameters3 = $('select').serialize();
		var params = parameters1 + '&' + parameters2 + '&' + parameters3;
		
		if(args[1]) {
			args[1] = args[1] + params;
		} else {
			args[1] = params;
		}
	}

	$.ajax({
		url: args[0],
		type: 'POST',
		dataType: 'html',
		data: args[1],
		timeout: 50000,
		error: function(){
			alert('Error loading XML document');
		},
		success: function(xml){
			var updateDiv = '#' + args[4];
			$(updateDiv).html(xml);
		}
	});
	
}

function checkLicenseStatus() {
	var args = checkLicenseStatus.arguments;
	
	var status = $('#' + args[0]).val();
	
	switch(status) 
	{
		case "Aktiv":
			var objRef = document.getElementById("content_4");
			objRef.innerHTML = "<input class='namn' type='text' name='l_expiredate' value='' >";
			
			break;
	
		case "Stoppad":
			// Skapa ett stopp datum till licensen
			
			var datum = new Date();
			
			var year = datum.getFullYear();
			var month = LeadingZero( datum.getMonth()+1 );
			var day = LeadingZero( datum.getDate() );
			
			var nyttDatum = year + "-" + month + "-" + day;
			
		//	alert(nyttDatum);
			
			var objRef = document.getElementById("content_4");
			objRef.innerHTML = "<input class='namn' type='text' name='l_expiredate' value='" + nyttDatum + "' >";
	
			break;
		
		default:
		
			break;
	}
	
}




function loginTest() {
//	var obj = $('#loginForm');
//	var score = $(obj[@username]).value;
//	alert(score);
	username = $("#username");
	password = $("#password");
	
	loadMainPage('login.php', 'username=' + username.val() + '&password=' + password.val());

}

function LeadingZero(nr) {
	if(nr < 10) nr = "0" + nr;
	return nr;	
}





function ShowLicenseData() {
	var args = ShowLicenseData.arguments;
	
	var w = 350;
	var h = 250;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	settings = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=no,toolbar=no';
	my_window = window.open("", "mywindow1", settings);
	
//	my_window = window.open ("", "mywindow1","status=1,width=350,height=150,top=\'wint\',left=\'winl\',resizable=0");
	
	if (window.focus) {my_window.focus()};
	
	if(args[0]=='Server') licensTyp = "Lockbee - Serverlicens";
	if(args[0]=='Vanlig') licensTyp = "Lockbee - Licens";

	my_window.document.write('<html>');
	my_window.document.write('<head>');
	my_window.document.write('<title>Price</title>');
	my_window.document.write('<style type=\'text/css\' media=\'screen\'>@import \'_css/main.css\';</style>');
	my_window.document.write('</head>');
	
	my_window.document.write('<body>');
	
	my_window.document.write("<div id=\'textMargin\' ");
	my_window.document.write('<H3>' + licensTyp + ' ' + args[1] + '</H3><br /><br />'); 
	
	activeGB = args[2] - args[4];
	historyGB = args[3] - args[5];
	
	totalActive = args[2];
	totalHistory = args[3];
	my_window.document.write('Total Aktiv kapacitet: ' + totalActive + ' GB<br />'); 
	my_window.document.write('Total Historik kapacitet: ' + totalHistory + ' GB<br />'); 
	my_window.document.write('<br />'); 
	my_window.document.write('StartPris: ' + args[6] + ' kr<br />'); 
	my_window.document.write('M&aring;nadsPris: ' + args[7] + ' kr / m&aring;n<br />'); 
	my_window.document.write('<br />'); 
	my_window.document.write('<hr />'); 	
	my_window.document.write('Aktiv: ' + activeGB + ' GB<br />'); 
	my_window.document.write('Historik: ' + historyGB + ' GB<br />'); 
	my_window.document.write('Extra Aktiv: ' + args[4] + ' GB<br />'); 
	my_window.document.write('Extra Historik: ' + args[5] + ' GB<br />'); 
	my_window.document.write('<br />'); 
	my_window.document.write('</div>'); 
	my_window.document.write('</body>'); 
	my_window.document.write('</html>'); 
	
	my_window.document.close();
				
}
