this.tooltip = function(){
	xOffset = -30;
	yOffset = -50;		
	$("img.tooltip").hover(function(e){											  
		this.t = this.alt;
		width = 300;
		$("body").append('<div id="tooltip" style="width: ' + width + 'px"><div id="tooltip1"></div><div id="tooltip2"></div><div id="tooltip3" style="width: ' + parseInt(width-6) + 'px"></div><div id="tooltip4"></div><div id="tooltip5" style="width: ' + parseInt(width-10) + 'px">'+ this.t +'</div><div id="tooltip6"></div><div id="tooltip7" style="width: ' + parseInt(width-6) + 'px"></div><div id="tooltip8"></div></div>');
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.alt = this.t;		
		$("#tooltip").remove();
    });	
	$("img.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

function sendsms() {
	var nr = $("#confirm_nr").val()
	$.post("ajax.php", {confirm: nr},
		function(data){
			$("#confirm").html(data).hide();
			$("#confirm").fadeIn("fast");
		}
	)
}

function send_ns(i) {
	var s1 = $("#d"+i+"_s1").val();
	var s2 = $("#d"+i+"_s2").val();
	var s3 = $("#d"+i+"_s3").val();
	var s4 = $("#d"+i+"_s4").val();
	
	var i1 = $("#d"+i+"_i1").val();
	var i2 = $("#d"+i+"_i2").val();
	var i3 = $("#d"+i+"_i3").val();
	var i4 = $("#d"+i+"_i4").val();
	
	if(s1 == "" || s2 == "" || i1 == "" || i2 == "") {
		alert("Bent du serveriai privalo buti nurodyti!");
	} else {
		$.post("ajax.php", {savens: i, 
							ns1: s1, 
							ns2: s2, 
							ns3: s3, 
							ns4: s4, 
							ip1: i1, 
							ip2: i2, 
							ip3: i3, 
							ip4: i4},
			function(data){
				$("#dwait"+i).fadeIn("fast");
			}
		)
	}
}

function sendkey() {
	var key = $("#confirm_key").val()
	$.post("ajax.php", {activate_key: key},
		function(data){
			$("#confirm").html(data).hide();
			$("#confirm").fadeIn("fast");
		}
	)
}

function closemsg(id) {
	$.post("ajax.php", {msg_id: id, close_msg: ""},
		function(data){
			if(data == "OK") {
				$("#msgid"+id).slideUp();
			}
		}
	)
}

function vpsinc(id) {
	var men = $("#vps-inc-"+id).val()
	$.post("ajax.php", {vpsinc: id, time: men},
		function(data){
			if(data == "OK") {
				window.location.reload();
			}
		}
	)
}

function rsinc(id) {
	var men = $("#sc-inc-"+id).val()
	$.post("ajax.php", {rsinc: id, time: men},
		function(data){
			if(data == "OK") {
				window.location.reload();
			}
		}
	)
}

function dsinc(id) {
	var men = $("#ds-inc-"+id).val()
	$.post("ajax.php", {dsinc: id, time: men},
		function(data){
			if(data == "OK") {
				window.location.reload();
			}
		}
	)
}

function restart(id) {
	$('.newpass').hide();
	$.post("ajax.php", {order_id: id, command: "restart"},
		function(data){
			$('.newpass').html(data).slideDown();
		}
	)
}

function stop(id) {
	$('.newpass').hide();
	$.post("ajax.php", {order_id: id, command: "stop"},
		function(data){
			$('.newpass').html(data).slideDown();
		}
	)
}

function start(id) {
	$('.newpass').hide();
	$.post("ajax.php", {order_id: id, command: "start"},
		function(data){
			$('.newpass').html(data).slideDown();
		}
	)
}

function reinstall(id) {
	$('.newpass').hide();
	var os_id = $("#os_opt-"+id).val()
	$.post("ajax.php", {order_id: id, command: "reinstall", os: os_id},
		function(data){
			$('.newpass').html(data).slideDown();
		}
	)
}

function changeroot(id) {
	$('.newpass').hide();
	$.post("ajax.php", {order_id: id, command: "changepassword"},
		function(data){
			$('.newpass').html(data).slideDown();
		}
	)
}

function setdomain(type){
	if ((type == 1) && $("#order-domain").is(':hidden')) {
		$("#aditional").show();
		$("#order-domain").show();
		$("#use-domain").hide();
	} else if ((type == 2) && $("#use-domain").is(':hidden')) {
		$("#aditional").hide();
		$("#use-domain").show();
		$("#order-domain").hide();
		$("#order-radio").removeAttr('disabled');
	}
}

function setapi(on){
	if (on == 1) {
		$("#api_url").removeAttr("disabled");
		$("#api_key").removeAttr("disabled");
	} else if (on == 0) {
		$("#api_url").attr({"disabled": "disabled"});
		$("#api_key").attr({"disabled": "disabled"});
	}
}

function showinfo(id){
	if ($("#order-"+id).is(':hidden')) {
		$("#order-"+id).slideDown();
	} else {
		$("#order-"+id).slideUp();
	}
}

function showinfo_rs(id){
	if ($("#scorder-"+id).is(':hidden')) {
		$("#scorder-"+id).slideDown();
	} else {
		$("#scorder-"+id).slideUp();
	}
}

function showinfo_ds(id){
	if ($("#dsorder-"+id).is(':hidden')) {
		$("#dsorder-"+id).slideDown();
	} else {
		$("#dsorder-"+id).slideUp();
	}
}

function change_ns(id){
	if ($("#dns-servers-"+id).is(':hidden')) {
		$("#dns-servers-"+id).slideDown();
	} else {
		$("#dns-servers-"+id).slideUp();
	}
}

function checkdomain() {
	var domain = $("#whois-domain").val()
	var newdomain = domain.split(".");
	newdomain = newdomain[0]+".lt";
	document.getElementById('whois-domain').value = newdomain;
	$.post("ajax.php", {whois: "", ajax: "", domainname: domain},
		function(data){
			if(data == "OK") {
				$("#answer").html("Registracija galima");
				$("#order-radio").removeAttr('disabled');
			} else {
				$("#answer").html("Domeno registruoti negalima");
				$("#order-radio").attr('disabled', 'disabled');
			}
		}
	)
}

function selectbanner(id) {
	$.get("ajax.php", {banner: id},
		function(data){
			$("#banner").html(data);
		}
	)
}

function rodymas(mode) {
	switch (mode){
		case 0:
			$('#inputit').show();
			$('#selectit').hide();
			break;
		case 1:
			$('#inputit').hide();
			$('#selectit').show();
			break;
	}
};


$(document).ready(function(){
	tooltip();
});

function sethdd(a) {
	hddcost = a;
	recount();
}

function setram(a) {
	ramcost = a;
	recount();
}

function setip(a) {
	ipcost = a;
	recount();
}

function setcp(a) {
	cp = a;
	recount();
}

function nocp() {
	cp = 0;
	recount();
	$('#cpops').hide();
	$('[name=cpoption]').val(0);
	$('input[name=cpoption]:checked').removeAttr("checked");
}

function okcp() {
	recount();
	$('#cpops').show();
	$('#cpcheck').attr("checked", "checked");
}

var nuolaida = 0;

var ds = 0;

function setnuolaida(a) {
	laikas = a;
	if(laikas == 1 && ds != 1) {
		nuolaida = 0;
	} else if(laikas == 2 && ds != 1) {
		nuolaida = 0.15;
	} else if (laikas == 3) {
		if (ds == 1) { 
			nuolaida = 0;
		} else {
			nuolaida = 0.25;
		}
	} else if (laikas == 6) {
		if (ds == 1) {
			nuolaida = 0;
		} else {
			nuolaida = 0.30;
		}
	} else if (laikas == 9) {
		if (ds == 1) {
			nuolaida = 0;
		} else {
			nuolaida = 0.35;
		}
	} else if (laikas == 12) {
		if (ds == 1) {
			nuolaida = 0;
		} else {
			nuolaida = 0.5;
		}
	} else if (laikas == 18) {
		if (ds == 1) {
			nuolaida = 0;
		} else {
			nuolaida = 0.5;
		}
	} else if (laikas == 24) {
		if (ds == 1) {
			nuolaida = 0;
		} else {
			nuolaida = 0.5;
		}
	} else {
		nuolaida = 0;
	}
	recount();
}

function recount() {
	kaina = (mainamount + hddcost + ramcost + ipcost + cp) * laikas;
	if(nuolaida > 0) {
		kaina = kaina - (kaina * nuolaida);
	}
	$("#amount").html(kaina.toFixed(2));
}

function select_client(type){
	if ((type == "asmuo") && $("#asmuoblock").is(':hidden')) {
		$("#asmuoblock").show();
		$("#imoneblock").hide();
	} else if ((type == "imone") && $("#imoneblock").is(':hidden')) {
		$("#imoneblock").show();
		$("#asmuoblock").hide();
	}
}

function sbType() {
	$("div").hide();
}