/// <reference path="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Title : The Philips Centre for health and well-being Functions
// Author : Rapp UK
//
// Description : Core functionality for standard sites developed by Rapp UK
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$(function() {
	$('a[href^=http]').click( function() {
		window.open(this.href);
		return false;
	});
});

Trace = {
    enabled: true,
    log: function(message) {
        if (window.console && this.enabled)
            console.log(message);
    }
}


Auth = {
    LastLoginResult: 'none',

    setLoginState: function() {
        if ($('#loggedin').val() == '1') {
            $('#login-link').hide();
            $('#manage-link').show();
            $('#logout-link').show();
        } else {
            $('#logout-link').hide();
            $('#manage-link').hide();
            $('#login-link').show();
        }
    },

    showForgottenPassword: function() {
        $('#fp').hide();
        $('#login').show();
    },

    showLogin: function() {
        $('#fp').show();
        $('#login').hide();
    },

    raiseAlert: function(message) {
        $('#login-message-box p').text(message);
        $('#login-message-box').fadeIn('1000');
    },

    sendPassword: function(url, emailAddress) {
        $.get(url,
            { email: emailAddress, action: 'sendpassword', ajax: 'true' },
            function(data) {
                Trace.log(data);

                switch (data) {
                    case 'success':
                        Auth.raiseAlert(data);
                    default:
                        Auth.raiseAlert(data);
                        break;
                }
            },
            'text');
    },

    validateUser: function(url, emailAddress, password) {
        //        $.get(url,
        //            { email: emailAddress, pwd: password, action: 'loginuser', ajax: 'true' },
        //            function(data) {
        //                return data;
        //            },
        //            'text');

        $.ajax({ url: url,
            async: false,
            type: 'POST',
            data: { email: emailAddress, pwd: password, action: 'validateuser', ajax: 'true' },
            success: function(data) {
                var returnFlag = false;

                switch (data) {
                    case 'success':
                        Trace.log('switch to success');
                        $('form').submit();
                        break;
                    case 'failure':
                    default:
                        Trace.log('switch to default');
                        Auth.raiseAlert(data);
                        break;
                }
            }
        });
    }
}


/* 

	Sitemap Styler v0.1
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	visit http://cssglobe.com/lab/sitemap_styler/
	
*/

this.sitemapstyler = function(){
	var sitemap = document.getElementById("sitemap")
	if(sitemap){
		
		this.listItem = function(li){
			if(li.getElementsByTagName("ul").length > 0){
				var ul = li.getElementsByTagName("ul")[0];
				ul.style.display = "none";
				var span = document.createElement("span");
				span.className = "collapsed";
				span.onclick = function(){
					ul.style.display = (ul.style.display == "none") ? "block" : "none";
					this.className = (ul.style.display == "none") ? "collapsed" : "expanded";
				};
				li.appendChild(span);
			};
		};
		
		var items = sitemap.getElementsByTagName("li");
		for(var i=0;i<items.length;i++){
			listItem(items[i]);
		};
		
	};	
};

window.onload = sitemapstyler;



/*
 * jQuery Form Example Plugin 1.4.2
 * Populate form inputs with example text that disappears on focus.
 *
 * e.g.
 *  $('input#name').example('Bob Smith');
 *  $('input[@title]').example(function() {
 *    return $(this).attr('title');
 *  });
 *  $('textarea#message').example('Type your message here', {
 *    className: 'example_text'
 *  });
 *
 * Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
 * Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
 * licenses.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
(function(a){a.fn.example=function(e,c){var d=a.isFunction(e);var b=a.extend({},c,{example:e});return this.each(function(){var f=a(this);if(a.metadata){var g=a.extend({},a.fn.example.defaults,f.metadata(),b)}else{var g=a.extend({},a.fn.example.defaults,b)}if(!a.fn.example.boundClassNames[g.className]){a(window).unload(function(){a("."+g.className).val("")});a("form").submit(function(){a(this).find("."+g.className).val("")});a.fn.example.boundClassNames[g.className]=true}if(a.browser.msie&&!f.attr("defaultValue")&&(d||f.val()==g.example)){f.val("")}if(f.val()==""&&this!=document.activeElement){f.addClass(g.className);f.val(d?g.example.call(this):g.example)}f.focus(function(){if(a(this).is("."+g.className)){a(this).val("");a(this).removeClass(g.className)}});f.change(function(){if(a(this).is("."+g.className)){a(this).removeClass(g.className)}});f.blur(function(){if(a(this).val()==""){a(this).addClass(g.className);a(this).val(d?g.example.call(this):g.example)}})})};a.fn.example.defaults={className:"example"};a.fn.example.boundClassNames=[]})(jQuery);

$(function() {
	$('.input-search input').example('Search');
});

function doReloadOmnitureTracking(val) {
    s.linkTrackVars = "None";
    s.linkTrackEvents = "None";
    s.tl(true, "o", s.pageName + ":content_carousel:" + val);
}

function omnitureTrackexitjoin(linkObj) {
	s.linkTrackVars="events,eVar3,eVar25";
	s.linkTrackEvents="event46";
	s.events="event46";
	s.eVar3="D=pageName";
	s.eVar25="D=CO:the_center:linkedin_group";
	s.tl(linkObj, "e", "D=pageName:CO:the_center:"+linkObj);
	s.linkTrackVars="None";
	s.linkTrackEvents="None";	
}
