var url_search_domain = '/domain/domains/search_domain';

$(document).ready(function() {
    $("#button_check_availability").click(function(){
        $('#domain_search_summary').empty();
        search_domain($('#the_domain_name').val());
    });

    if($('#ie_info_box').length != 0)
        {
            var ie_info_box_ini = 'ini_val';
            var ie_info_box_curr = 'ini_val';
            
            
            $('#ie_info_box').mousedown(function(){

                if(ie_info_box_ini == ie_info_box_curr )
                    {
                        $(this).select();
                        $('#ie_info_box').val('');
                        ie_info_box_curr = 'not_ini_val';
                    }
            });

            $('#ie_info_box').jqEasyCounter(
                {
                    'maxChars': 200,
                    'maxCharsWarning': 170
                }
            );
        }
        // eof

        //bof domain info explaination


      $('#domain_additiona_extra').click(function() {
                 if($('#domain_dialog').length )
                     {
                        $('#domain_dialog').dialog('close');
                     }



                 var $dialog = $('<div id="domain_doc_dialog" ></div>')
		.html('<p>'
                       +      'Please be aware that Website Builder products require both Domain and Hosting to work with<br/><br/><br/>'
                       +      '<span style=\'float: right;\'>'
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/hosting/choose/package/13\'><img height=\'11\' width=\'10\' src=\'/images/arrow-rt.png\'>I dont have domain & hosting</a><br/><br/>'
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/websitebuilder/choose/package/'+ $(this).val() + '\'><img height="11" width="10" src="/images/arrow-rt.png">I already own domain & hosting</a> '
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/hosting/choose/package/13\'><img height=\'11\' width=\'10\' src=\'/images/arrow-rt.png\'>I dont have domain & hosting</a><br/><br/>'
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/websitebuilder/choose/package/'+ $(this).val() + '\'><img height="11" width="10" src="/images/arrow-rt.png">I already own domain & hosting</a> '
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/websitebuilder/choose/package/'+ $(this).val() + '\'><img height="11" width="10" src="/images/arrow-rt.png">I already own domain & hosting</a> '
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/hosting/choose/package/13\'><img height=\'11\' width=\'10\' src=\'/images/arrow-rt.png\'>I dont have domain & hosting</a><br/><br/>'
                       +      '   <a style=\'font-family: Arial,Helvetica,sans-serif; color: rgb(51, 51, 51); text-decoration: none;\' href=\'/order/websitebuilder/choose/package/'+ $(this).val() + '\'><img height="11" width="10" src="/images/arrow-rt.png">I already own domain & hosting</a> '
                       +      '</span>'
                       +      '</p>')
		.dialog({
			autoOpen: false,
			title: 'IE Domain Document Requirement :',
                        dialogClass: 'domain_doc_dialog_class'
		});
		$dialog.dialog('open');
		// prevent the default action, e.g., following a link
		return false;
	});

        //eof domain info explaination


});
//eof $(document).ready(function() {



function search_domain(the_domain)
{
   $( '#domain_search_progress_sign' ).show();
        $.post(
            url_search_domain,
            {
                'the_domain' : the_domain.toLowerCase()
            },
            function(data)
            {
                $( '#domain_search_progress_sign' ).hide();
                $('#domain_search_summary').html(data);
            }
        );
    
}
//eof function search_domain

function domains_hosting_check_availability(the_domain)
{
    var url_domains_hosting = '/domain/domains_hosting/search_domain';
    $('#domain_search_summary').empty();
    $( '#domain_search_progress_sign' ).show();
    $.post(
            url_domains_hosting,
            {
                'the_domain' : the_domain.toLowerCase()
            },
            function(data)
            {
                $( '#domain_search_progress_sign' ).hide();
                $('#domain_search_summary').html(data);
            }
        );
}

/**
 * @
 */
function add_domain_to_cart(domain_id)
{
    var the_domain_id = domain_id ;
    var the_domain_regoption = $("select[name='to_order_domain_regoption["+domain_id+"]']").val() ;

    if($('#cart_summary_progress_sign').length)
        {
            $('#cart_summary_progress_sign').show();
        }

    if($("input:checkbox[name='to_order_domain["+the_domain_id+"]']").is(":checked") == true )
        {
            //if customer select domain
            $.post(
                '/order/domain/add',
                {
                    'the_domain_id' : the_domain_id,
                    'the_domain_regoption' : the_domain_regoption
                },
                function(data)
                {
                    if($('#lh_cart').length == 0)
                        {

                        }
                        else
                            {
                                $('#lh_cart').empty();
                                $('#lh_cart').html(data);
                            }
                }
            );
            //alert('the domain is ' + domain_id );
            //alert( $("select[name='to_order_domain_regoption["+domain_id+"]']").val());
        }
        else
            {
                //if customer remove domain
                $.post(
                    '/order/domain/remove',
                    {
                    'the_domain_id' : the_domain_id,
                    'the_domain_regoption' : the_domain_regoption
                    },
                    function(data)
                    {
                        if($('#lh_cart').length == 0)
                            {

                            }
                            else
                                {
                                    $('#lh_cart').empty();
                                    $('#lh_cart').html(data);
                                }
                        }
                );
                // eof $.post
            }
            //eof of  if else 


}
//eof function function (domain_id)

function add_own_domain_to_cart(domain_id)
{
    var the_domain_id = domain_id ;
    if($("input:checkbox[name='to_order_own_domain["+the_domain_id+"]']").is(":checked") == true )
        {
            //if customer select domain
            $.post(
                '/order/domain/do_attach_domain_to_product',
                {
                    'the_domain_id' : the_domain_id
                },
                function(data)
                {
                }
            );
        }
        else
            {
                //if customer remove domain
                $.post(
                    '/order/domain/do_remove_domain_from_product',
                    {
                    'the_domain_id' : the_domain_id
                    
                    },
                    function(data)
                    {
                    }
                );
                // eof $.post
        }
        //eof if 

}



function add_domain_regoption_to_cart(domain_id)
{
    var the_domain_id = domain_id ;

    if($('#cart_summary_progress_sign').length)
        {
            $('#cart_summary_progress_sign').show();
        }

    if($("input:checkbox[name='to_order_domain["+the_domain_id+"]']").is(":checked") != true )
        {
            $("input:checkbox[name='to_order_domain["+the_domain_id+"]']").attr('checked', true);
        }
    add_domain_to_cart(domain_id);

}

/*  ****************************************************************************
 *  bof domain additional fieds realated
 *  ****************************************************************************
 */

function update_category_type(select_ie_applicant_class)
{
    $.post(
        '/domain/additional_information/populate_ie_category_option',
        {
        'the_applicant_class_id' :  select_ie_applicant_class
        },
        function(data)
        {
            $("#id_category_type").empty();
            $("#id_category_type").html(data);
        }
    );
    // eof $.post
}

/*  ****************************************************************************
 *  eof domain additional fieds realated
 *  ****************************************************************************
 */



