﻿function SetSelectedNumber()
{
    var series = $('input[name=Series]:checked').val().split(' ')[0];
    var prefix = $('[id$=Prefix]').val();
    var suffix = $('input[name=Suffix]:checked').val();
    
    $('.selectedNumber').val(series + ' ' + prefix + ' ' + suffix);
}

function _tooltip()
{
	$("img[title].tipme").tooltip(
    {
        tip: '#tipcontent'
        ,effect: 'slide'
    });
}

function _corners()
{
	var b = $('#bottomclose');
	var args = null;
	
	if(b.size() > 0)
	{
		args = 'top';
		b.corner('bottom');
	}
	$('.roundOne').corner(args);
}

(function($) {
    $.fn.VerticalAlign = function(opts) {
        return this.each(function() {
            var top = (($('body').height() - $('div.verticalOne').height()) / 2);
            $(this).css('top', top);
        });
    };
    $.fn.HorizontalAlign = function(opts) {
        return this.each(function() {
            var top = (($('body').width() - $('div.verticalOne').width()) / 2);
            $(this).css('left', top);
        });
    };
})(jQuery);

var resizeTimer = null;
$(window).bind('resize', function() {
//    if (resizeTimer) clearTimeout(resizeTimer);
//    resizeTimer = setTimeout($('div.verticalOne').VerticalAlign(), 0);
//    resizeTimer = setTimeout($('div.verticalOne').HorizontalAlign(), 0);
});
$(window).bind('load', function() {
//    if (resizeTimer) clearTimeout(resizeTimer);
//    resizeTimer = setTimeout($('div.verticalOne').VerticalAlign(), 0);
//    resizeTimer = setTimeout($('div.verticalOne').HorizontalAlign(), 0);
});

function pop(hide, caller, target)
{
	if(!$.browser.msie)
	{
		var a = $(caller).offset();
		
		$('#' + target).css(
		{
			top: a.top - 15
			,left: a.left + $(caller).width() + 20
		});
	}
	
	$('#' + target).css('display', (hide ? 'none' : 'block'));
}

function checkUsernameAvailability(sender, args)
{   
    args.IsValid = ($('input[id$=HiddenAvailability]').val() == 'true');
}

function checkUsernameAvailabilityInternal()
{
    var userName = $('input[id$=Email][type=text]').val();
    
    if(userName.length > 0 && $validators.is_email(userName)) 
    {
		var success = function(response)
		{
		    $('input[id$=HiddenAvailability]').val(response.toString());
		}
		
		var failure = function(ex)
		{
			alert(ex);
		}
		
		PageMethods.IsUserNameAvailable(userName, success, failure);
    }
    else
    {
        $('input[id$=HiddenAvailability]').val('true');
    }
}

function dressCheckboxes()
{
    /* see if anything is previously checked and reflect that in the view*/
	$(".checklist input:checked").parent().addClass("selected");
	
//	$(".checklist li").click(function(){
//	    if($(this).hasClass('selected'))
//	        $(this).find('a.checkbox-deselect').click();
//	    else
//	        $(this).find('a.checkbox-select').click();
//	});
	
	/* handle the user selections */
	$(".checklist .checkbox-select").click(
		function(event) {
			event.preventDefault();
			$('ul.checklist input[type=checkbox]').each(function(){
			    if ($(this).parent().hasClass("selected"))
			        $(this).parent().find("a.checkbox-deselect").click();
			});
			$(this).parent().addClass("selected");
			$(this).parent().find(":checkbox").attr("checked","checked");
		}
	);
	
	$(".checklist .checkbox-deselect").click(
		function(event) {
			event.preventDefault();
			$(this).parent().removeClass("selected");
			$(this).parent().find(":checkbox").removeAttr("checked");
		}
	);
	
	$('a#sr1').click(function(){
	    $('input[type=radio][name=AvailableSeries]:eq(0)').attr('checked',true);
	    $('input[id$=SelectSerie]').click();
	});
	
	$('a#sr2').click(function(){
	    $('input[type=radio][name=AvailableSeries]:eq(1)').attr('checked',true)
	    $('input[id$=SelectSerie]').click();
	});
	
	$('a#unsr1,a#unsr2').click(function(){
	    $('input[type=radio][name=AvailableSeries]').attr('checked',false);
	});
	
	$('a#srv1').click(function(){
	    $('input[type=radio][name=AvailableServices]:eq(0)').attr('checked',true);
	    $('input[id$=SelectService]').click();
	});
	
	$('a#srv2').click(function(){
	    $('input[type=radio][name=AvailableServices]:eq(1)').attr('checked',true);
	    $('input[id$=SelectService]').click();
	});
	
	$('a#srv3').click(function(){
	    $('input[type=radio][name=AvailableServices]:eq(2)').attr('checked',true);
	    $('input[id$=SelectService]').click();
	});
	
	$('a#unsrv1,a#unsrv2,a#unsrv3').click(function(){
	    $('input[type=radio][name=AvailableServices]').attr('checked',false);
	});
}

function setIFrameUrl(url)
{
    var frame = window.parent.document.getElementsByTagName('iframe')[0];
    frame.src = url;
}
