/*
 * Copyright 2010-2011, Softnik Technologies
 * http://www.softnik.com/
 */


	$(function() 
	{
		$('#vercheck').button({text: true, label:"Check For Updates"});
		$("#vercheck").click(function(){window.open('lib/php/links.php?r=vercheck');});
		
		$('#logout').button({text: false, label:"Logout", icons: {primary: 'logout-button'}});
		$("#logout").click(function(){window.location = 'lib/php/login.php?logout';});
		
		$('#home').button({text: false, label:"Home Page", icons: {primary: 'home-button'}});
		$("#home").click(function(){window.open('lib/php/links.php?r=home');});
		
		$('#products').button({text: false, label:"Products", icons: {primary: 'products-button'}});
		$("#products").click(function(){window.open('lib/php/links.php?r=products');});
		
		$('#support').button({text: false, label:"Support", icons: {primary: 'support-button'}});
		$("#support").click(function(){window.open('lib/php/links.php?r=support');});
		
		$('#contact').button({text: false, label:"Contact",  icons: {primary: 'contact-button'}});
		$("#contact").click(function(){window.open('lib/php/links.php?r=contact');});
		
		$('#new').button({text: false,icons: {primary: 'ui-icon-document'}});
		$('#open').button({text: false,icons: {primary: 'ui-icon-folder-open'}})
		
		$('#adddomains').button({text: false, label:"Add Domains",icons: {primary: 'add-domains-button'}});
		$("#adddomains").click(function(){AddDomains();});
		
		$('#importdomains').button({text: false, label:"Upload Data (CSV)",icons: {primary: 'import-domains-button'}});
		$("#importdomains").click(function(){ImportDomainsFromCSV();});
		
		$('#deldomains').button({text: false, label:"Delete Domains", icons: {primary: 'del-domains-button'}});
		$("#deldomains").click(function(){DeleteDomains();});
		
		$('#bulkaction').button({text: false, label:"Bulk Action Tool", icons: {primary: 'bulk-action-button'}});
		$("#bulkaction").click(function(){DoBulkAction();});
		
		$('#config').button({text: false, label:"Whois Setup", icons: {primary: 'config-button'}});
		$("#config").click(function(){window.location = 'wconfig.php';});
		
		$('#runq').button({text: false, label:"Process Queue", icons: {primary: 'runq-button'}});
		$("#runq").click(function(){ProcessQueue();});
		
		$('#report').button({text: false, label:"Simple Reports", icons: {primary: 'report-button'}});
		$("#report").click(function(){window.location = 'report.php';});
		
		$('#admin').button({text: false, label:"User Admin", icons: {primary: 'admin-button'}});
		$("#admin").click(function(){window.location = 'admin.php';});
		
		$('#usrpwd').button({text: false, label:"User Admin", icons: {primary: 'usrpwd-button'}});
		$("#usrpwd").click(function(){UserSelfAdmin();});
		
		$('#subdomains').button({text: false, label:"Subdomain Manager", icons: {primary: 'subdomains-button'}});
		$("#subdomains").click(function(){window.location = 'subdomains.php';});
		
		$('#appsetup').button({text: false, label:"Basic App Setup", icons: {primary: 'appsetup-button'}});
		$("#appsetup").click(function(){window.location = 'appsetup.php';});
		
		$('#dates').button({text: false, label:"Important Dates", icons: {primary: 'date-column-button'}});
		$("#dates").click(function(){ShowDateGrid();});
		
		$('#http').button({text: false, label:"Home Page Info", icons: {primary: 'http-column-button'}});
		$("#http").click(function(){ShowHttpGrid();});
		
		$('#registrar').button({text: false, label:"Registrar Info", icons: {primary: 'registrar-column-button'}});
		$("#registrar").click(function(){ShowRegistrarGrid();});
		
		$('#network').button({text: false, label:"Network Info", icons: {primary: 'network-column-button'}});
		$("#network").click(function(){ShowNetworkGrid();});
		
		$('#sitepop').button({text: false, label:"Web Visibility Info", icons: {primary: 'sitepop-column-button'}});
		$("#sitepop").click(function(){ShowSitePopGrid();});
		
		$('#notes').button({text: false, label:"Domain Notes", icons: {primary: 'notes-column-button'}});
		$("#notes").click(function(){ShowNotesGrid();});
		
		$('#ipinfo').button({text: false, label:"IP Data", icons: {primary: 'ipinfo-column-button'}});
		$("#ipinfo").click(function(){ShowIPDataGrid();});
		
		$('#cdisp01').button({text: false, label:"Custom Display 01", icons: {primary: 'cdisp01-column-button'}});
		$("#cdisp01").click(function(){ShowCustomDataGrid01();});
		
		$('#cdisp02').button({text: false, label:"Custom Display 02", icons: {primary: 'cdisp02-column-button'}});
		$("#cdisp02").click(function(){ShowCustomDataGrid02();});
		
		$('#pfolio').button({text: false, label:"Domain Portfolio", icons: {primary: 'pfolio-column-button'}});
		$("#pfolio").click(function(){window.location="index.php";});
		
		$('#menu').button({text: false, label:"Main Menu", icons: {primary: 'main-menu-button'}});
		$("#menu").click(function(){window.location="menu.php";});
		
		$('#version').button({text: false, label:"Refresh", icons: {primary: 'version-button'}});
		$("#version").click(function(){LoadVersionInfo(false);});
		
		$('.toolsButton').button();
		$('.toolsButton').click(function()
		{
			var selids = jQuery("#"+domain_table_grid_id).getGridParam("selarrrow"); 
			if(selids.length == 1)
			{
				var domainname = jQuery("#"+domain_table_grid_id).getCell(selids[0], "domain"); 
				var tname = $(this).data('name');
				var turl = $(this).data('url');
				turl = turl.replace(/{{domain}}/g, domainname);
				window.open(turl);
			}
		});
		
		$('.queueButton').button();
		$('.queueAddButton').button();
		$('.queueButton').click(function()
		{
			var tname = $(this).data('name');
			var turl = "makeq.php?kill&w=" + tname;
			var request = $.ajax({type: "POST",	url: turl});
			request.done(function(msg) 
			{  
				show_queue_count();
			});
			request.fail(function(jqXHR, textStatus) {});
		});
		
		$('.queueAddButton').click(function()
		{
			var tname = $(this).data('name');
			var rdays = $("#qb-refresh-interval").val();
			if(rdays < 0 || rdays == null || rdays == "")
				rdays = 180;
			var dlimit = $("#qb-domain-limit").val();
			if(dlimit < 0)
				dlimit = "8";
			else if(dlimit == null || dlimit=="")
				dlimit = 0;
			var turl = "makeq.php?d=" + rdays + "&w=" + tname;
			if(dlimit != 0)
				turl += "&l=" + dlimit;
			var request = $.ajax({type: "POST",	url: turl});
			request.done(function(msg) 
			{  
				show_queue_count();
			});
			request.fail(function(jqXHR, textStatus) {});
		});
	});
	
	function ProcessQueue()
	{
		window.open("runq.php?v");
		/*
		var request = $.ajax({type: "POST",	url: "runq.php"});
		request.done(function(msg) 
		{  
			alert("Queue Processor Completed.");
		});
		request.fail(function(jqXHR, textStatus) {});
		*/
	}
	
	function UserSelfAdmin()
	{
		$('#dialog-user-admin').dialog('open');
		return false;
	}
	
