$(function() {
	$('a.lightbox').lightBox({showText:false, fixedNavigation:true, showNavigation:false}); // Select all links with lightbox class
});

function Login( userNameSelector, passwordSelector)
{
	var user = $(userNameSelector).val();
	var pass = $(passwordSelector).val();
	RemoteAuthenticate('/API/', 'http://dealers.autopointsite.com/', user, pass);
	return false;
}

function AttachClear(selector)
{
	var currentValue = $(selector).val()
	$(selector).bind('focus', function() {
		if($(selector).val() == currentValue)
		{
			$(selector).select();
		}
	});

}

function PreparePassword(selector1, selector2)
{
	$(selector1).one('focus', function() {
		$(selector1).hide();
		$(selector2).show();
		$(selector2).focus();
		$(selector2).select();
	});
}

function RemoteAuthenticate(url, target, username, password)
{                  
	var urlRemote = url + 'RemoteAuthenticate.ashx';
         var options = $.extend({}, { userName: username, password: password}, { userName: username, password: password});
         var time = (1000 * 60 * 5);
            
	$.ajax({
         	       timeout: time,
                url: urlRemote,
                cache: false,
                data: options,
                dataType: 'json',
                success: function(obj){                    
                    var items = new Array();                           
                    if(!obj.length) {
                        items.push(obj);
                    }
                    else {
                        items = obj;
                    }                    
                    if(items[0].Value.length > 0) {
                       var token = items[0].Value;
                       if (token.length > 0)
                            window.open(target + 'Login.aspx?loginToken=' + token,'_parent');
                       else 
			alert('please verify your username and/or password');
                    }
                    else 
		  {
			alert('please verify your username and/or password');
		  }
                },
                error:  function(XMLHttpRequest, textStatus, errorThrown){
		  alert('error during logon process.');
                }
            });     
}

