


  jQuery.fn.hint = function () {
    return this.each(function (){
      // get jQuery version of 'this'
      var t = jQuery(this);
      // get it once since it won't change
      var title = t.attr('title');
      var tatitle = t.attr('tatitle');


      // only apply logic if the element has the attribute
      if (title) {
        // on blur, set value to title attr if text is blank
        t.blur(function (){ //alert('hi ' + t.val());
          if (t.val() == '') {
            t.val(title);
            t.addClass('blur');
          }
        });
        // on focus, set value to blank if current value
        // matches title attr
        t.focus(function (){
          if (t.val() == title) {
            t.val('');
            t.removeClass('blur');
          }
        });

        // clear the pre-defined text when form is submitted
        t.parents('form:first()').submit(function(){
            if (t.val() == title) {
                t.val('');
                t.removeClass('blur');
            }
        });

        // now change all inputs to title
        t.blur();
      }


      // only apply logic if the element has the attribute
      if (tatitle) {
        // on blur, set value to title attr if text is blank
        t.blur(function (){
          if (t.val()=='') {
            t.val(tatitle);
            t.addClass('blur');
          }
        });
        // on focus, set value to blank if current value
        // matches title attr
        t.focus(function (){
          if (t.val() == tatitle) {
            t.val('');
            t.removeClass('blur');
          }
        });

        // clear the pre-defined text when form is submitted
        t.parents('form:first()').submit(function(){
            if (t.val() == tatitle) {
                t.val('');
                t.removeClass('blur');
            }
        });

        // now change all inputs to title
        t.blur();
      }
    });
  }

  jQuery.fn.check = function() {
    return this.each(function() {
      this.checked = true;
   });
  };

  jQuery.fn.clear = function() {
    return this.each(function() {
      this.checked = false;
   });
  };

  $(document).ready(function() {
    // Hints
    $('input[title!=""]').hint();
    $('textarea[tatitle!=""]').hint();


    // Index Page Submit
    $('#submit').click( function() {
      // Check keywords/phrases
      if ( ($('#ta').val()=='' || $('#ta').val()==$('#ta').attr('tatitle')) && $('#file').val()=='') {
        alert('Please input up to 250 keywords/phrases.  Upload them from a file or input them manually into the textarea.');
        $('#ta').focus();
        return false;
      }

      // Check extensions
      var somethingchecked=0;
      $("input[@class='tld']").each( function() {
        if ($(this).attr('checked')) { // true or false
          somethingchecked=1;
        }
      });

      if (somethingchecked==0 && ($('#tlds').val()=='' || $('#tlds').val()==$('#tlds').attr('title')) ) {
        alert('Please select your required extensions');
        $('#com').focus();
        return false;
      }

      // Check security code
      if ($('#security_code').val()=='' || $('#security_code').val()==$('#security_code').attr('title')) {
        alert('Please input the security code');
        $('#security_code').focus()
        return false;
      }

      return(true);
    });


    // Checkboxes
    $('#sall').click( function() {
      $("input[@class='tld']").check();
    });

    $('#call').click( function() {
      $("input[@class='tld']").clear();
    });

    // Domain Checkboxes
    $('#sdom').click( function() {
      $("input[@class='domaincheck']").check();

      // Add all to output
    });

    $('#cdom').click( function() {
      $("input[@class='domaincheck']").clear();

      // Remove all from output
    });

    //$("input[@class='domaincheck']").change( function() {
      //if ($(this).attr('checked')) {
        // Update output
        //var str = $("form[@name=checkdomainform]").serialize();
        //alert(str);

        /*$.post("domaincheck.php", str, function(xmlData) {*/


        /*}, "xml");*/


        //alert($(this).attr('name'));
      //}
    //});


    // Help
    $('#inputquestion').click( function () {
      $("#inputhelp").removeClass("donotshow");
    });
    $('#closeinputhelp').click( function () {
      $("#inputhelp").addClass("donotshow");
    });

    $('#outputquestion').click( function () {
      $("#outputhelp").removeClass("donotshow");
    });
    $('#closeoutputhelp').click( function () {
      $("#outputhelp").addClass("donotshow");
    });

    $('#submitquestion').click( function () {
      $("#submithelp").removeClass("donotshow");
    });
    $('#closesubmithelp').click( function () {
      $("#submithelp").addClass("donotshow");
    });

    $('#pricequestion').click( function () {
      $("#pricehelp").removeClass("donotshow");
    });
    $('#closepricehelp').click( function () {
      $("#pricehelp").addClass("donotshow");
    });

    $('#parkedquestion').click( function () {
      $("#parkedhelp").removeClass("donotshow");
    });
    $('#closeparkedhelp').click( function () {
      $("#parkedhelp").addClass("donotshow");
    });

    $('#domainsquestion').click( function () {
      $("#domainshelp").removeClass("donotshow");
    });
    $('#closedomainshelp').click( function () {
      $("#domainshelp").addClass("donotshow");
    });


    $('#closemessageblock').click( function () {
      $("#messageblock").addClass("donotshow");
    });
    $('#closeerrorblock').click( function () {
      $("#errorblock").addClass("donotshow");
    });



    function show(page, which) {
      temp_str = '#' + which;

      if (page==1) {
        $("#input").addClass("donotshow");
        $("#output").addClass("donotshow");
        $("#register").addClass("donotshow");
      }
      else {
        $("#about").addClass("donotshow");
        $("#help").addClass("donotshow");
        $("#signup").addClass("donotshow");
        $("#account").addClass("donotshow");
        $("#links").addClass("donotshow");
      }
      $(temp_str).removeClass("donotshow");

      temp_str = '#s' + which;

      if (page==1) {
        $("#sinput").removeClass("here");
        $("#soutput").removeClass("here");
        $("#sregister").removeClass("here");
      }
      else {
        $("#sabout").removeClass("here");
        $("#shelp").removeClass("here");
        $("#ssignup").removeClass("here");
        $("#saccount").removeClass("here");
        $("#slinks").removeClass("here");
      }

      $(temp_str).addClass("here");
    }


    // Panels
    $('#sinput').click( function() {
      show(1, 'input');
      $("#leftholder").height(442);

      // Remove href call
      return false;
    });

    $('#sregister').click( function() {
      show(1, 'register');
      $("#leftholder").height(743);
      return false;
    });

    $('#soutput').click( function() {
      show(1, 'output');
      $("#leftholder").height(713);
      return false;
    });

    $('#sabout').click( function() {
      show(2, 'about');
      $("#leftholder").height(713);

      // Remove href call
      return false;
    });

    $('#shelp').click( function() {
      show(2, 'help');
      $("#leftholder").height(1343);

      return false;
    });

    $('#slinks').click( function() {
      show(2, 'links');
      $("#leftholder").height(713);

      return false;
    });

    $('#ssignup').click( function() {
      show(2, 'signup');
      $("#leftholder").height(713);
      return false;
    });

    $('#saccount').click( function() {
      show(2, 'account');
      $("#leftholder").height(713);
      return false;
    });

    $('#footerlinks').click( function() {
      if ($("#slinks").length) {
        show(2, 'links');
        $("#leftholder").height(713);

        return false;
      }
    });

    $('#footercontact').click( function() {
      if ($("#sabout").length) {
        show(2, 'about');
        $("#leftholder").height(713);

        return false;
      }
    });

    $('#footerabout').click( function() {
      if ($("#sabout").length) {
        show(2, 'about');
        $("#leftholder").height(713);

        return false;
      }
    });






    // Select a Country
    $("#countries").change(function() {

      var cc = $("#countries").val();
      $("#stateSelect").load("util_getstates.php", {Country: cc});
    });


    // Login Box Submit
    $('#lbSubmit').click( function() {
      var emailadd = $('#lbEmail').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#lbEmail').focus();
        return false;
      }

      if ( $('#lbPassword').val()=='' || $('#lbPassword').val().length <6) {
        alert('Please input your password');
        $('#lbPassword').focus();
        return false;
      }

      return true;
    });


    // Login Submit
    $('#loginSubmit').click( function() {
      var emailadd = $('#loginEmail').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#loginEmail').focus();
        return false;
      }

      if ( $('#loginPassword').val()=='' || $('#loginPassword').val().length <6) {
        alert('Please input your password');
        $('#loginPassword').focus();
        return false;
      }

      return true;
    });


    // Domain Selection Submit
    $('#domainselectsubmit').click( function() {
      var somethingchecked=0;
      $("input[@class='domaincheck']").each( function() {
        if ($(this).attr('checked')) { // true or false
          somethingchecked=1;
        }
      });

      if (somethingchecked==0 ) {
        alert('Please select one or more domains');
        return false;
      }

      return true;
    });


    // Registration Submit
    $('#registersubmit').click( function() {
      if (!$('#terms').attr('checked')) { // true or false
        alert('Please agree to the terms and conditions');
        $('#terms').focus();
        return false;
      }

      return true;
    });


    // Nameserver Submit
    $('#nameserversubmit').click( function() {
      if ( $('#ns1').val()=='' ) {
        alert('Please input the first nameserver');
        $('#ns1').focus();
        return false;
      }
      if ( $('#ns2').val()=='' ) {
        alert('Please input the second nameserver');
        $('#ns2').focus();
        return false;
      }


      return true;
    });



    // Select a Country
    $("#countries").change(function() {
      var cc = $("#countries").val();
      $("#stateSelect").load("util_getstates.php", {Country: cc});
    });



    // New Contact Submit

    $('#newcontactsubmit').click( function() {
      // Check contact person
      if ( $('#txtName').val()=='' ) {
        alert('Please input the contact person');
        $('#txtName').focus();
        return false;
      }

      // Check company name
      if ( $('#txtCompany').val()=='' ) {
        alert('Please input the company name or n/a');
        $('#txtCompany').focus();
        return false;
      }


      // Check address1
      if ( $('#txtAddress1').val()=='' ) {
        alert('Please input the first line of the address');
        $('#txtAddress').focus();
        return false;
      }

      // Check city
      if ( $('#txtCity').val()=='' ) {
        alert('Please input the city');
        $('#txtCity').focus();
        return false;
      }

      // Check country
      if ( $('#countries').val()=='null' ) {
        alert('Please select a country');
        $('#countries').focus();
        return false;
      }

      // Check state
      if ( $('#txtState').val()=='' ) {
        alert('Please select a state');
        $('#txtState').focus();
        return false;
      }

      // Check zip
      if ( $('#txtZip').val()=='' ) {
        alert('Please input the zip / postcode');
        $('#txtZip').focus();
        return false;
      }

      // Check telephone
      if ( $('#txtTelcc').val()=='' || $('#txtTelNo').val()=='') {
        alert('Please input the phone number');
        $('#txtTelcc').focus();
        return false;
      }

      // Check email address
      var emailadd = $('#txtEmailAddr').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#txtEmailAddr').focus();
        return false;
      }


      return(true);
    });




    // Signup Page Submit
    $('#signupsubmit').click( function() {
      // Check company name
      if ( $('#comp').val()=='' ) {
        alert('Please input your company name or n/a');
        $('#comp').focus();
        return false;
      }

      // Check contact person
      if ( $('#name').val()=='' ) {
        alert('Please input the contact person');
        $('#name').focus();
        return false;
      }

      // Check address1
      if ( $('#address1').val()=='' ) {
        alert('Please input the first line of your address');
        $('#address').focus();
        return false;
      }

      // Check city
      if ( $('#city').val()=='' ) {
        alert('Please input your city');
        $('#city').focus();
        return false;
      }

      // Check country
      if ( $('#countries').val()=='null' ) {
        alert('Please select a country');
        $('#countries').focus();
        return false;
      }

      // Check state
      if ( $('#stateSelect').val()=='' ) {
        alert('Please select a state');
        $('#stateSelect').focus();
        return false;
      }

      // Check zip
      if ( $('#zip').val()=='' ) {
        alert('Please input your zip / postcode');
        $('#zip').focus();
        return false;
      }

      // Check telephone
      if ( $('#telnocc').val()=='' || $('#telno').val()=='') {
        alert('Please input your phone number');
        $('#telnocc').focus();
        return false;
      }

      // Check email address
      var emailadd = $('#username').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#username').focus();
        return false;
      }



      // Check password1
      if ( $('#passwd').val()=='' || $('#passwd').val().length <6) {
        alert('Please input your password');
        $('#passwd').focus();
        return false;
      }

      // Check password2
      if ( $('#confirmpasswd').val()=='' ) {
        alert('Please confirm your password');
        $('#confirmpasswd').focus();
        return false;
      }

      // Check passwords
      if ( $('#confirmpasswd').val() != $('#passwd').val() ) {
        alert('Passwords are not the same');
        $('#confirmpasswd').focus();
        return false;
      }


      // Check terms
      if ( !$('#agree').attr('checked') ) {
        alert('Please read and agree to the terms');
        $('#agree').focus();
        return false;
      }


      return(true);
    });


    // Add funds submit
    $('#fundssubmit').click( function() {
      // Check
      if ( $('#fundamount').val()=='' ) {
        alert('Please input the amount you want to add');
        $('#fundamount').focus();
        return false;
      }

      return (true);
    });

    // Forgot password submit
    $('#forgotpasswordsubmit').click( function() {
      // Check
      var emailadd = $('#email').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#email').focus();
        return false;
      }

      return (true);
    });

    // Contact Us submit
    $('#contactussubmit').click( function() {
      if ( $('#cuname').val()=='' ) {
        alert('Please input name');
        $('#cuname').focus();
        return false;
      }

      // Check email address
      var emailadd = $('#cuemail').val();
      if ( emailadd=='' || !isEmailAddr(emailadd) ) {
        alert('Please input a valid email address');
        $('#cuemail').focus();
        return false;
      }

      if ( $('#cucomments').val()=='' ) {
        alert('Please input your comments');
        $('#cucomments').focus();
        return false;
      }

      return(true);
    });



    function isEmailAddr(email) {
          var result = false;
          var theStr = new String(email);
          var index = theStr.indexOf("@");
          if (index > 0) {
            var pindex = theStr.indexOf(".",index);
            if ((pindex > index+1) && (theStr.length > pindex+1))
              result = true;
          }
          return result;
    }



    // PriceTable
    if ($("#pricetable").length) // Make sure it exists first
      $("#pricetable").tablesorter(  );




  });



  $(function(){
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
        $('.ns').disableTextSelect();
  });