
$(document).ready(function() {

   $('.icotxt, .orderrcon').qtip({
      content: {
         text: false // Use each elements title attribute
      },
	   position: {
		  corner: {
			 tooltip: "topMiddle", // Use the corner...
			 target: "bottomMiddle" // ...and opposite corner
		  }
	   },

	   style: { 
		  padding: 5,
		  background: '#ffffff',
		  color: 'black',
		  border: {
			 width: 1,
			 radius: 4,
			color: '#3f8dbf'
		  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'

	   }
   });
   

   $('.two').qtip({
      content: {
         text:$('#twotxt').html() // Use each elements title attribute
      },
	   position: {
		  corner: {
			 tooltip: "topMiddle", // Use the corner...
			 target: "bottomMiddle" // ...and opposite corner
		  }
	   },

	   style: { 
		  padding: 5,
		  background: '#ffffff',
		  color: 'black',
		  border: {
			 width: 1,
			 radius: 4,
			color: '#3f8dbf'
		  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'

	   }
   });


   $('.gametip').qtip({
      content: {
         text:$('#supportedgames').html() // Use each elements title attribute
      },
	   position: {
		  corner: {
			 tooltip: "bottomMiddle", // Use the corner...
			 target: "topRight" // ...and opposite corner
		  }
	   },

	   style: { 
		  padding: 5,
		  background: '#ffffff',
		  color: 'black',
		  border: {
			 width: 1,
			 radius: 4,
			color: '#3f8dbf'
		  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'

	   }
   });



	$('.featurebtn2').each(function()   {
		if($(this).attr('id')){
		  // Create image content using websnapr thumbnail service
		  var content = '<img src="features/';
		  content += $(this).attr('id');
		  content += '.gif" alt="Loading thumbnail..." height="164" width="227" />';
		  
		  // Setup the tooltip with the content
		  $(this).qtip(
		  {
			 content: content,
			 position: {
				corner: {
				   tooltip: 'rightMiddle',
				   target: 'leftMiddle'
				}
			 },
			 style: {
				  padding: 5,
				  background: '#ffffff',
				  color: 'black',
				  border: {
					 width: 1,
					 radius: 4,
					color: '#3f8dbf'
				  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'
			 }
		  });
		}
   });

	$('.featurebtn1').each(function()  {
		if($(this).attr('id')){
		  // Create image content using websnapr thumbnail service
		  var content = '<img src="features/';
		  content += $(this).attr('id');
		  content += '.gif" alt="Loading thumbnail..." height="164" width="227" />';
		  
		  // Setup the tooltip with the content
		  $(this).qtip(
		  {
			 content: content,
			 position: {
				corner: {
				   tooltip: 'leftMiddle',
				   target: 'rightMiddle'
				}
			 },
			 style: {
				  padding: 5,
				  background: '#ffffff',
				  color: 'black',
				  border: {
					 width: 1,
					 radius: 4,
					color: '#3f8dbf'
				  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'
			 }
		  });
		}
   });

	$('.featurebtn').each(function()   {
		if($(this).attr('id')){
		  // Create image content using websnapr thumbnail service
		  var content = '<img src="features/';
		  content += $(this).attr('id');
		  content += '.gif" alt="Loading thumbnail..." height="164" width="227" />';
		  
		  // Setup the tooltip with the content
		  $(this).qtip(
		  {
			 content: content,
			 position: {
				corner: {
				   tooltip: 'bottomMiddle',
				   target: 'topMiddle'
				}
			 },
			 style: {
				  padding: 5,
				  background: '#ffffff',
				  color: 'black',
				  border: {
					 width: 1,
					 radius: 4,
					color: '#3f8dbf'
				  },
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'
			 }
		  });
		}
   });

	$('.ssimage').each(function()   {
		if($(this).attr('href')){
		  // Create image content using websnapr thumbnail service
		  var content = '<img src="';
		  content += $(this).attr('href');
		  content += '" alt="Loading thumbnail..." width="800" />';
		  
		  // Setup the tooltip with the content
		  $(this).qtip(
		  {
			 content: content,
			 position: {
				corner: {
				   tooltip: 'rightBottom',
				   target: 'bottomLeft'
				}
			 },
			 style: {
				 width: 500,
				height: 300,
				  padding: 5,
				  background: '#ffffff',
				  color: 'black',
				  border: {
					 width: 1,
					 radius: 4,
					color: '#3f8dbf'
				  },
				tip: false, // Give it a speech bubble tip with automatic corner detection
				name: 'cream'
			 }
		  });
		}
   });


	$('#rcon, #copyright, #html5').change(function(v) {
		calculatetotal();
	});

	$('#licensetype').change(function(v) {
		var type=$('#licensetype').val();

		if(type == "trial"){
			$(".showservers").hide();
			$(".orderanual").html();
			
			$("#term").attr('disabled', 'disabled');
			$('#term').append( new Option("Free",'free', true,true) );
			$('.ordercost').html('0.00');
		} else {
			$(".showservers").fadeIn('slow');
			$("#term").attr('disabled', '');
			$("#term").val(2);
			$("#term option[value='free']").remove();
			calculatetotal();
		}
	});

	$('#term, .orderquant, .orderquant2').change(function(v) {
		calculatetotal();
	});


	$('.hostingmy').keyup(function() {
		var s=$('.hostingmy').val();

		filteredValues = "~!@#$%^&*()+{}[]|\:;'/?.>,<-=` "; 
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++) {
			var c = s.charAt(i);	
			if (filteredValues.indexOf(c) == -1) returnString += c;	
		}
		$('.hostingmy').val(returnString);
	  if (this.timer) clearTimeout(this.timer);
      
      this.timer = setTimeout(function () {
		$.ajax({
		   type: "POST",
		   url: "verify.php",
		   data: "name="+returnString,
		   success: function(msg){
			 if(msg == "ok"){
				$('.hostcheck').html('');
			 } else $('.hostcheck').html('<strong>Not available</strong>');

		   }
		 });
      }, 200);
      


	});


	$('#hostregister').click(function() {
		var hostname=$('#hostname').val();
		var hosttld=$('#hosttld').val();
		var username=$('#username').val();
		var password=$('#password').val();
		var coupon=$('#coupon').val();
		var term=$('#term').val();

		if(!term || !password || !username || !hosttld || !hostname || hostname == "your_name"){
			alert("All fields required.");
			return false;
		}

		$.ajax({
		   type: "POST",
		   url: "verify.php",
			  async: false, 
		   data: "name="+hostname,
		   success: function(msg){
			 if(msg == "ok"){

				if(term == "monthly"){
					cycle="monthly";
				} else cycle="annually";		

				setorderval('1', 'billingcycle', cycle);
				setorderval('2', 'customfield[22]', hostname);
				setorderval('3', 'customfield[23]', hosttld);
				setorderval('4', 'customfield[24]', username);
				setorderval('5', 'customfield[25]', password);
				setorderval('6', 'pid', '10');
				setorderval('7', 'a', 'checkout');
				setorderval('8', 'promo', coupon);
			
				$('#orderform').attr('action', 'http://billing.gamecp.com/redirect.php');
				$('#orderform').submit();

			 } else {
				alert("Your site name is already taken.");
				return false;
			 }
		   }
		 });




	});




	$('#register').click(function() {
		var lin=parseInt($('.orderquant').val());
		var win=parseInt($('.orderquant2').val());
		var type=$('#licensetype').val();
		var term=$('#term').val();
		var coupon=$('#coupon').val();
		var rcon=$('#rcon').attr('checked');
		var copyright=$('#copyright').attr('checked');
		var html5=$('#html5').attr('checked');

		if(type == "trial"){
			setorderval('6', 'pid', '2');
		}else {
			if(!win && !lin && !rcon && !copyright && !html5){
				alert("Please select an item to order.");
				return false;
			}
			if(type == "full"){
				setorderval('2', 'configoption[23]', win);
				setorderval('3', 'configoption[10]', lin);
				setorderval('6', 'pid', '1');
			} else {
				setorderval('2', 'configoption[24]', win);
				setorderval('3', 'configoption[9]', lin);
				setorderval('6', 'pid', '3');
			}

			if(term == "monthly"){
				cycle="monthly";
			} else cycle="annually";		

			setorderval('1', 'billingcycle', cycle);
			setorderval('4', 'addons[3]', rcon);
			setorderval('5', 'addons[2]', copyright);
			setorderval('9', 'addons[6]', html5);
			setorderval('8', 'promo', coupon);
		}

		setorderval('7', 'a', 'checkout');

		$('#orderform').attr('action', 'http://billing.gamecp.com/redirect.php');
		$('#orderform').submit();

	});




	$('.orderplus').click(function() {
	  $('.orderquant').val(parseInt($('.orderquant').val())+1);
		calculatetotal();
	});
	$('.orderminus').click(function() { 
		if(parseInt($('.orderquant').val()) >= 1){ $('.orderquant').val(parseInt($('.orderquant').val())-1); }
		calculatetotal(); 
	});
	$('.orderplus2').click(function() {
	  $('.orderquant2').val(parseInt($('.orderquant2').val())+1);
		calculatetotal();
	});
	$('.orderminus2').click(function() {
		if(parseInt($('.orderquant2').val()) >= 1){ $('.orderquant2').val(parseInt($('.orderquant2').val())-1);}
		calculatetotal();
	});


	$('#livezillabox').floating({targetX:'right', targetY:'bottom'});

    $('#adminform, #clientform, #clanmode, #clientclanmode').submit(function() {
        window.open('', 'formpopup', 'width=780,height=400,resizeable,scrollbars');
        this.target = 'formpopup';
    });




	


});


function setorderval(id, name, val){
	$('#generic'+id).attr('name', name);
	$('#generic'+id).val(val);

}

function VPSDiscount(){

	var cpu=$('#cpu').val();
	var mem=$('#mem').val();
	var disc=$('#disc').val();
	var cores=$('#cores').val();

	distotal=0;

	switch(cpu){
		case "1":
			dis=10;
		break;
		case "2":
			dis=5;
		break;
		case "3":
			dis=2;
		break;
		case "4":
			dis=1;
		break;
		case "5":
			dis=0;
		break;
		case "6":
			dis=0;
		break;
		default:
			dis=0;
			cpu=0;
		break;
	}
	distotal=distotal+dis;
	switch(mem){
		case "1":
			dis=10;
		break;
		case "2":
			dis=5;
		break;
		case "3":
			dis=3;
		break;
		case "4":
			dis=2;
		break;
		case "5":
			dis=1;
		break;
		case "6":
			dis=0;
		break;
		case "7":
			dis=0;
		break;
		default:
			dis=0;
			mem=0;
		break;
	}
	distotal=distotal+dis;
	switch(disc){
		case "1":
			dis=5;
		break;
		case "2":
			dis=3;
		break;
		case "3":
			dis=2;
		break;
		case "4":
			dis=1;
		break;
		case "5":
			dis=0;
		break;
		default:
			dis=0;
			disc=0;
		break;
	}
	distotal=distotal+dis;
	switch(cores){
		case "1":
			dis=5;
		break;
		case "2":
			dis=0;
		break;
		case "3":
			dis=0;
		break;
		case "4":
			dis=0;
		break;
		default:
			dis=0;
			cores=0;
		break;
	}
	distotal=distotal+dis;



	$('.vpsdiscwrap').fadeIn();
	$('.vpstotal').html(distotal);
	$('#vpscode').html(cpu+cores+mem+disc);

}

function calculatetotal(){
	var lin=parseInt($('.orderquant').val());
	var win=parseInt($('.orderquant2').val());
	var type=$('#licensetype').val();
	var term=$('#term').val();
	var rcon=$('#rcon').attr('checked');
	var copyright=$('#copyright').attr('checked');
	var html5=$('#html5').attr('checked');

	if(term == "monthly"){
		if(type == "full"){
			var multiplyer = "15";
		} else var multiplyer = "10";
	} else {
		if(type == "full"){
			var multiplyer = "150";
		} else var multiplyer = "100";
	}
	var winlin=lin+win;
	var total=winlin*multiplyer

	if(term == "yearly"){
		var percentage=total*.15;
		total=total+percentage;
		if(percentage > 0 && parseInt(winlin) > 0){
			$(".orderanual").html("$"+percentage.toFixed(2)+" (15%) due every year");
		} else {
			$(".orderanual").html('');
		}

	} else $(".orderanual").html('');

	if(copyright) total=total+50;
	if(html5) total=total+25;
	if(rcon) total=total;


	$('.ordercost').html(total.toFixed(2));

}



function stringFilter (input) {	s = input.value; filteredValues = "~!@#$%^&*()_+{}[]|\:;'/?.>,<-=` "; var i;	var returnString = "";	for (i = 0; i < s.length; i++) {  	var c = s.charAt(i);	if (filteredValues.indexOf(c) == -1) returnString += c;	}	input.value = returnString;}

