/**
	PERFECT FIT LOGIN WIDGET
	Date: 01/19/2012
	Author: Mike R. Frank, PERFECT FIT HEALTH, LLC.
	Description:
	
	Provides a login box for Patients / Clients to access their sent workouts using a workout code.
**/

function loadScript(url, callback)
{
    // adding the script tag to the head as suggested before
   var head = document.getElementsByTagName('head')[0];
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url;

   // then bind the event to the callback function 
   // there are several events for cross browser compatibility
   script.onreadystatechange = callback;
   script.onload = callback;

   // fire the loading
   head.appendChild(script);
}

var jqueryLoaded = function( ) {
	loadScript( "http://www.perfectfitpro.com/pfitprov3/api/login_widget/jquery.perfectfitlogin.js", pfitPluginLoaded ) ;
};

var pfitPluginLoaded = function( ) {
	if( !ignore_initialization ) {
		initialize( ) ;
	}
};

if (typeof jQuery == 'undefined') {  
    loadScript( "http://www.perfectfitpro.com/pfitprov3/api/login_widget/jquery.js", jqueryLoaded ) ;
} else {
    loadScript( "http://www.perfectfitpro.com/pfitprov3/api/login_widget/jquery.perfectfitlogin.js", pfitPluginLoaded ) ;
}

var ignore_initialization = false ;

/**
	Initialize Login Box
**/
function initialize( ) {
	$(document).ready(function(){
		$('#pfit-login').pfitLogin({
			type:'both', // patient, provider, both			
			width:250,
			showErrors: true,
			stylesheet: 'http://www.perfectfitpro.com/pfitprov3/api/login_widget/perfectfit.css',
			patientButtonLabel: "Go",
			patientWorkoutCodeInstructions: "Enter Workout Code",
			providerButtonLabel: "Go",
			providerLoginInstructions: "Enter Login ID",
			postUrl: "http://www.perfectfitpro.com/",
			displayTitle: "pfp"
		});
	});	
}
