var loading = '<div style="text-align:center;"><img src="css/images/ajax-loader.gif" alt="Loading" /><br />Loading...<br /><br /></div>';

$(document).ready(function(){
	jQuery('a[rel*=facebox]').facebox() 
	basketJq();
	$("#swSubmitLabel").click(function(){
		var domain = $("#domain").attr("value");
		var tld = $("#tld").attr("value");
		if(domain.length > 0 && tld.length > 0){
			$("#loadContent").css("display", "block");
			$("#loadContent").html(loading);
			var url = 'getcontent.php?request=lookup&domain=' +domain+'&tld='+tld;
			var urlWhois = 'getcontent.php?request=getWhois&domain=' +domain+'&tld='+tld;
			$.get(url, function(data){
				$("#loadContent").html(data);
			});
			
			$.get(urlWhois, function(data){
				$("#showWhois").css("display", "block");
				$("#showWhois").html(data);
				$("#whois").hide();
				initDrop();
			});
			return false;
		} else { alert("Please enter both fields."); return false; }
	});

function initDrop(){
	$("#see-whois").click(function(){
		$("#whois").toggle(500);
	});
}
		
	/*
	$(".subtab").click(function(){
		$("#content").html(loading);
		$(".subtab").removeClass("active");
		$(this).addClass("active");
		var page = "includes/" + $(this).attr("rel") + ".php";
		$.get(page, function(data){
			setTimeout(function(){$("#content").html(data)}, 500);
		});
	 $("#content").ajaxError(function(event, request, settings){
		 $(this).html(loading +"<br /><div style=\"text-align:center; color:red; font-size:110%;\"><strong>* Error requesting page " + settings.url + "</strong></div>");
	 });
	});*/
	subTabCont();
	$(".tabs").click(function(){
		$(".tabs").css("color", "#FFFFFF");
		$(this).css("color", "green");
		$(".tabs").removeClass("activetab");
		$(this).addClass("activetab");

		var myid = $(this).attr("id");
		var rel = $(this).attr("rel");
		//pass the id, to get content back
		$("#" + rel).html(loading);
		$("#" + rel).load("server-info.php", { id: myid }, function() {
			initConfigs();
		});
		return false;
	});
	
	$(".virtual-tabs").click(function(){
		$(".virtual-tabs").css("color", "#FFFFFF");
		$(this).css("color", "green");
		$(".virtual-tabs").removeClass("activetab");
		$(this).addClass("activetab");

		var myid = $(this).attr("id");
		var rel = $(this).attr("rel");
		//pass the id, to get content back
		$("#" + rel).html(loading);
		$("#" + rel).load("server-info.php", { id: myid, action: "virtual-hosting" }, function() {
			initConfigs();
		});
		return false;
	});
	
	$(".home-pages").click(function(){
		$(".home-pages").css("color", "#FFFFFF");
		$(this).css("color", "green");
		var myid = $(this).attr("id");
		var rel = $(this).attr("rel");
		//pass the id, to get content back
		$("#" + rel).html(loading);
		$("#" + rel).load("getcontent.php", { id: myid, action: "home-pages" }, function() {
			initConfigs();
		});
		return false;
	});
	
	$(".home-pages2").click(function(){
		$(".home-pages2").css("color", "#FFFFFF");
		$(this).css("color", "green");
		var myid = $(this).attr("id");
		var rel = $(this).attr("rel");
		//pass the id, to get content back
		$("#" + rel).html(loading);
		$("#" + rel).load("getcontent.php", { id: myid, action: "home-pages" }, function() {
			initConfigs();
		});
		return false;
	});
	
	$(".ajaxRequest").click(function(){
		$("#content").html(loading);
		var url = $(this).attr("href") + '?ajaxRequest=y';
		alert(url);
		$.get(url, function(data){
			alert(data);
			setTimeout(function(){$("#content").html(data)}, 500);
		});
	 $("#content").ajaxError(function(event, request, settings){
		 $(this).html(loading +"<br /><div style=\"text-align:center; color:red; font-size:110%;\"><strong>* Error requesting page " + settings.url + "</strong></div>");
	 });
	});
});

function initConfigs(){
	$(".start-config").click(function(){
		var serverID = $(this).attr("id");
		var rel = $(this).attr("rel");
		$("#" + rel).html(loading);
		$("#" + rel).load("server-info.php", { id: serverID, action: "configure" });
		return false;
	});
	
		$(".showProperties").change(function(){
			var Type = $(this).attr("value");
			$.get('show-props.php?type='+Type, function(data){
				$(".properties-show").html(data);
			});
		});

	/*$(".buy-config").click(function(){
		$(".item-price").each(function(i){
			alert($(this).attr("rel"));
		});
			//$("#" + rel).load("server-info.php", { id: serverID, action: "configure" });
		return false;
	});*/
}
	function subTabCont() {
		$(".subtab").click(function(){
			$("#content").html(loading);
			$(".subtab").removeClass("active");
			$(this).addClass("active");
			var page = $(this).attr("rel") + ".php";

			$("#mainarea").load(page+" .mainarea-inner", function() {
							subTabCont();																							
			});
		});
	}

function getPrices(){
	var str = 0;
	$(".item-price").each(function (i) {
		var myid = $(this).val();
		var url = "server-info.php?action=param-price&id="+myid;
		$.get(url, function(data){
			str += parseFloat(data);
			$("#configure-price").html(str);
			initConfigs();
		});
	});
}
		function basketJq() {
			$(".toggleDesc").click(function() {
				var descId = $(this).attr("rel");
				$("#"+descId).slideToggle();
				return false;
			});
			$(".basket-func").click(function() {
				var myid = $(this).attr("rel");
				var type = $(this).attr("rev");
				aElements = new Array('basket'+myid, 'subtotal'+myid);
				var updateStr = '<img vspace="1" src="images/icon_wait.gif" alt="Working" width="14" height="14" align="texttop" />';
				for(i=0;i<aElements.length;i++) {
					$("#"+aElements[i]).html(updateStr);
				}
				$("#right-container").load("basket.php #innerBasket", { action: type, id: myid }, function() {
					$.get("server-info.php?action=shop-price", function(data) {
						$("#headerBasket").html(data);
					});
					basketJq();	
				});
				return false;
			});

		}

