﻿<!--
$(document).ready(function() {

    // Search Box Balloons Code - Register
    $(".register_balloon").click(function () {
        $(".sSrch A").removeClass("here");
        $(".register_balloon").addClass("here");
        $(".search_type").val("type_register");
        var val = $("INPUT.txt").val();
        if (val === "" || val === "Transfer A Domain" || val === "Look Up A Domain" || val === "Manage A Domain") {
            $("INPUT.txt").val("Register A Domain");
        };
        return false;
    }).click();

    // Search Box Balloons Code - Transfer  
    $(".transfer_balloon").click(function () {
        $(".sSrch A").removeClass("here");
        $(".transfer_balloon").addClass("here");
        $(".search_type").val("type_transfer");
        var val = $("INPUT.txt").val();
        if (val === "Register A Domain" || val === "" || val === "Look Up A Domain" || val === "Manage A Domain") {
            $("INPUT.txt").val("Transfer A Domain");
        };
        return false;
    });

    // Search Box Balloons Code - WHOIS    
    $(".whois_balloon").click(function () {
        $(".sSrch A").removeClass("here");
        $(".whois_balloon").addClass("here");
        $(".search_type").val("type_whois");
        var val = $("INPUT.txt").val();
        if (val === "Register A Domain" || val === "Transfer A Domain" || val === "" || val === "Manage A Domain") {
            $("INPUT.txt").val("Look Up A Domain");
        };
        return false;
    });
    // Search Box Balloons Code - Manage    
    $(".manage_balloon").click(function () {
        $(".sSrch A").removeClass("here");
        $(".manage_balloon").addClass("here");
        $(".search_type").val("type_manage");
        var val = $("INPUT.txt").val();
        if (val === "Register A Domain" || val === "Transfer A Domain" || val === "Look Up A Domain" || val === "") {
            $("INPUT.txt").val("Manage A Domain");
        };
        return false;
    });

    // Search Box Text Box Code - Focus   
    $("INPUT.txt").focus(function () {
        if ($("INPUT.txt").val() == "Register A Domain" || $("INPUT.txt").val() == "Transfer A Domain" || $("INPUT.txt").val() == "Look Up A Domain" || $("INPUT.txt").val() == "Manage A Domain") {
            $("INPUT.txt").val("");
            $("INPUT.txt").addClass("focused");
        };
        return false;
    }).blur(function () {
        if (!$("INPUT.txt").val()) {
            switch ($(".search_type").val()) {
                case "type_register":
                    $("INPUT.txt").val("Register A Domain");
                    break;
                case "type_transfer":
                    $("INPUT.txt").val("Transfer A Domain");
                    break;
                case "type_whois":
                    $("INPUT.txt").val("Look Up A Domain");
                    break;
                case "type_manage":
                    $("INPUT.txt").val("Manage A Domain");
                    break;
            }
            $("INPUT.txt").removeClass("focused");
        }

    });
    // If the user focuses the input before the event is bound, run the event now.
    if ($("INPUT.txt").is(":focus")) {
        $("INPUT.txt").focus();
    }

    $('#go').click(function() {
        var domain = $('#txtSearch').val(),
        sld,
        tld;
    
        // Choose the first domain if a comma-delimited list is passed in.
        if (domain.indexOf(",") > -1) {
            domain = domain.substring(0,domain.indexOf(","));
        }

        // Remove www. prefix, also remove invalid characters.
        domain = domain.replace(/^www\./i, '').replace(/[^a-zA-Z0-9.-]/ig, '');

        if (domain.indexOf(".") > -1)
        {
             // Special sld/tld parsing logic for .name domains
             if (/\.name$/i.test(domain)) {
                var parts = domain.split(".");
                parts = parts.slice(parts.length-1, 1);
                sld = parts.join('.');
                tld = 'name';
             }
            else {    
                sld = domain.substr(0,domain.indexOf("."));
                tld = domain.substr(domain.indexOf(".")+1);    
            }
        }
        else {
            // No period, assume entered text is sld.
            sld =  domain;  
        }
    
        if (!tld) {
            tld = 'com';
        }

        if (sld === 'RegisterADomain' || !sld) {
           return false;
        }
    
        if(domain === "TransferADomain" || domain === "LookUpADomain") {
            return false;
        }
    
        switch($('#hdnSearch').val()) {
            case "type_register":            
                window.location = "/domainsearch/register.aspx?sld=" + sld + "&tld=" + tld;                        
                break;        
            case "type_whois":            
                window.location = "/whois/Default.aspx?DomainName=" + domain;
                break;
            case "type_manage":            
                window.location = "/domains/control-panel/default.asp?sld=" + sld + "&tld=" + tld;
                break;
            default:
                window.location = "/domains/transfer.aspx?DomainName=" + domain;            
        }

        return false;
    });
    
    $('#txtSearch').keypress(function(e){
        if(e.which == 13){
            $('#go').click();
            e.preventDefault();
            return false;
        }
    });
});

//-->
