$(document).ready(function(){ 
  //new jQuery external link functionality
  $('a[href*=skinit.com]').click(function() {
    var link = $(this).attr('href')
    $('<div id="external" />').load('/includes/dialog/external.html').dialog({
     modal:true,
     title:'WARNING: External Link',
     height: 'auto',
     buttons: {
       'Continue': function() {
         $('#external').dialog('close');
         $('#external').remove();
         location.replace(link);
       },
       'Cancel': function() {
         $('#external').dialog('close');
         $('#external').remove();
         return false;
       }
     }
    });
    $('.ui-dialog-buttonpane button:first').addClass('expected');  
		return false;
	});
    
  initFeedback();

  $(".buttons a").bind("click", function() {
     $(".buttons li").each(function(){
       val = $(this).text();
       $(this).empty().append("<span>" + val + "</span>");
     });// buttons li each
   });//buttons a bind
   
   
  $("#login_form form").submit(function() {
    $("span.error").remove();
    $(":input.error").removeClass("error");
    $(":text, :password").each(function() {
      if (this.value.match(/^\s?$/)) {
        $(this).addClass("error");
      }
    });
    
    var msg = "An error has occured."
    
    var un = $("#username.error").length
    var ps = $("#password.error").length
    
    if (un == 1 && ps ==1) {
      msg = "Please enter your username and password."
    } else if (un == 1) {
      msg = "Please enter your username."
    } else if (ps == 1) {
      msg = "Please enter your password."
    }
    
    if ($(".error").length > 0) {
      $("#login_form form").after("<span class='error'>" + msg + "</span>");    
    }

    $(":input.error:eq(0)").focus();
    return($(".error").length <= 0);
  }); 
      
});

function BrowserCheck() {
  var b = BrowserDetect.browser;
  var v = BrowserDetect.version;
  

  if (b == "Safari"){
    return true;
  } else if (b == "Mozilla" && v > 1){
    return true;
  } else if (b == "Firefox" && v > 1){
    return true;
  } else if (b == "Explorer" && v >= 5.5){
    return true;
  }
  else {
    return false;
  }
}

function checkCookies() {
  $.cookie('testcookie','enabled');
  var isCookie = $.cookie('testcookie');
  if(!isCookie){
    document.write(
		'<div id="browser_warning" class="page_error"><div><p>Your browser\'s cookie functionality is turned off. Please turn it on.</p></div></div>')
  }
}

// true position thanks to PPK (http://www.quirksmode.org/js/findpos.html)
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
  
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};  
  
function initFeedback() {
	var feedback = $(
		'<div class="alpha-shadow"><div><p>Please wait...</p></div></div>'
	).hide().appendTo('body');
	
	$("a.feedback, .buttons a").click(function(){
		// the position of my popup
		var left = feedback[0].offsetLeft;
		var top = feedback[0].offsetTop;

  	// get the position of the clicked element
    var realPos = findPos(this);
    X = realPos[0]
    Y = realPos[1]
    
	   // position popup based on position of clicked element
		left = X - 75;
		top = Y - 50;
		feedback.css({
			left: left + 'px',
			top: top + 'px'
		});
		setTimeout(function(){
	    feedback.show();
		},0);
  });
}

function clearUsername() {
  $(":radio").click(function(){
    $("input#newUsername").val("")
  });
} 


//jquery dimensions plugin

(function($){$.dimensions={version:'@VERSION'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return this.is(':visible')?this[0]['client'+name]:num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});var val=this.is(':visible')?this[0]['offset'+name]:num(this,name.toLowerCase())
+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')
+num(this,'padding'+torl)+num(this,'padding'+borr);return val+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}
return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))
offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;};})(jQuery);


//jquery dialog plugin
;(function($){$.ui=$.ui||{};$.fn.extend({dialog:function(options,data){var args=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof options=="string"){var dialog=$.data(this,"ui-dialog")||$.data($(this).parents(".ui-dialog:first").find(".ui-dialog-content")[0],"ui-dialog");dialog[options].apply(dialog,args);}else if(!$(this).is(".ui-dialog-content"))
new $.ui.dialog(this,options);});}});$.ui.dialog=function(el,options){this.options=options=$.extend({},$.ui.dialog.defaults,options&&options.modal?{resizable:false}:{},options);this.element=el;var self=this;$.data(this.element,"ui-dialog",this);$(el).bind("setData.dialog",function(event,key,value){options[key]=value;}).bind("getData.dialog",function(event,key){return options[key];});var uiDialogContent=$(el).addClass('ui-dialog-content');if(!uiDialogContent.parent().length){uiDialogContent.appendTo('body');}
uiDialogContent.wrap(document.createElement('div')).wrap(document.createElement('div'));var uiDialogContainer=uiDialogContent.parent().addClass('ui-dialog-container').css({position:'relative'});var uiDialog=this.uiDialog=uiDialogContainer.parent().hide().addClass('ui-dialog').css({position:'absolute',width:options.width,height:options.height,overflow:'hidden'});var classNames=uiDialogContent.attr('className').split(' ');$.each(classNames,function(i,className){if(className!='ui-dialog-content')
uiDialog.addClass(className);});if(options.resizable&&$.fn.resizable){uiDialog.append('<div class="ui-resizable-n ui-resizable-handle"></div>').append('<div class="ui-resizable-s ui-resizable-handle"></div>').append('<div class="ui-resizable-e ui-resizable-handle"></div>').append('<div class="ui-resizable-w ui-resizable-handle"></div>').append('<div class="ui-resizable-ne ui-resizable-handle"></div>').append('<div class="ui-resizable-se ui-resizable-handle"></div>').append('<div class="ui-resizable-sw ui-resizable-handle"></div>').append('<div class="ui-resizable-nw ui-resizable-handle"></div>');uiDialog.resizable({maxWidth:options.maxWidth,maxHeight:options.maxHeight,minWidth:options.minWidth,minHeight:options.minHeight});}
uiDialogContainer.prepend('<div class="ui-dialog-titlebar"></div>');var uiDialogTitlebar=$('.ui-dialog-titlebar',uiDialogContainer);var title=(options.title)?options.title:(uiDialogContent.attr('title'))?uiDialogContent.attr('title'):'';uiDialogTitlebar.append('<span class="ui-dialog-title">'+title+'</span>');uiDialogTitlebar.append('<a href="#" class="ui-dialog-titlebar-close"><span>X</span></a>');this.uiDialogTitlebarClose=$('.ui-dialog-titlebar-close',uiDialogTitlebar).hover(function(){$(this).addClass('ui-dialog-titlebar-close-hover');},function(){$(this).removeClass('ui-dialog-titlebar-close-hover');}).mousedown(function(ev){ev.stopPropagation();}).click(function(){self.close();return false;}).keydown(function(ev){var ESC=27;ev.keyCode&&ev.keyCode==ESC&&self.close();});var l=0;$.each(options.buttons,function(){l=1;return false;});if(l==1){uiDialog.append('<div class="ui-dialog-buttonpane"></div>');var uiDialogButtonPane=$('.ui-dialog-buttonpane',uiDialog);$.each(options.buttons,function(name,value){var btn=$(document.createElement('button')).text(name).click(value);uiDialogButtonPane.append(btn);});}
if(options.draggable&&$.fn.draggable){uiDialog.draggable({handle:'.ui-dialog-titlebar',start:function(){self.activate();}});}
uiDialog.mousedown(function(){self.activate();});uiDialogTitlebar.click(function(){self.activate();});options.bgiframe&&$.fn.bgiframe&&uiDialog.bgiframe();this.open=function(){options.modal&&overlay.show(self,options.overlay);uiDialog.appendTo('body');var wnd=$(window),doc=$(document),top=doc.scrollTop(),left=doc.scrollLeft();if(options.position.constructor==Array){top+=options.position[1];left+=options.position[0];}else{switch(options.position){case'center':top+=(wnd.height()/2)-(uiDialog.height()/2);left+=(wnd.width()/2)-(uiDialog.width()/2);break;case'top':top+=0;left+=(wnd.width()/2)-(uiDialog.width()/2);break;case'right':top+=(wnd.height()/2)-(uiDialog.height()/2);left+=(wnd.width())-(uiDialog.width());break;case'bottom':top+=(wnd.height())-(uiDialog.height());left+=(wnd.width()/2)-(uiDialog.width()/2);break;case'left':top+=(wnd.height()/2)-(uiDialog.height()/2);left+=0;break;default:top+=(wnd.height()/2)-(uiDialog.height()/2);left+=(wnd.width()/2)-(uiDialog.width()/2);}}
top=top<doc.scrollTop()?doc.scrollTop():top;uiDialog.css({top:top,left:left});uiDialog.show();self.activate();var openEV=null;var openUI={options:options};this.uiDialogTitlebarClose.focus();$(this.element).triggerHandler("dialogopen",[openEV,openUI],options.open);};this.activate=function(){var maxZ=0;$('.ui-dialog:visible').each(function(){maxZ=Math.max(maxZ,parseInt($(this).css("z-index"),10));});overlay.$el&&overlay.$el.css('z-index',++maxZ);uiDialog.css("z-index",++maxZ);};this.close=function(){options.modal&&overlay.hide();uiDialog.hide();var closeEV=null;var closeUI={options:options};$(this.element).triggerHandler("dialogclose",[closeEV,closeUI],options.close);};if(options.autoOpen)
this.open();};$.extend($.ui.dialog,{defaults:{autoOpen:true,bgiframe:false,buttons:[],draggable:true,height:200,minHeight:100,minWidth:150,modal:false,overlay:{},position:'center',resizable:true,width:300}});var overlay={$el:null,events:$.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),function(e){return e+'.ui-dialog-overlay';}).join(' '),show:function(dialog,css){if(this.$el)return;this.dialog=dialog;this.selects=this.ie6&&$('select:visible').css('visibility','hidden');var width=this.width();var height=this.height();this.$el=$('<div/>').appendTo(document.body).addClass('ui-dialog-overlay').css($.extend({borderWidth:0,margin:0,padding:0,position:'absolute',top:0,left:0,width:width,height:height},css));$('a, :input').bind(this.events,function(){if($(this).parents('.ui-dialog').length==0){dialog.uiDialogTitlebarClose.focus();return false;}});$(document).bind('keydown.ui-dialog-overlay',function(e){var ESC=27;e.keyCode&&e.keyCode==ESC&&dialog.close();});$overlay=this.$el;function resize(){$overlay.css({width:width,height:height}).css({width:overlay.width(),height:overlay.height()});};$(window).bind('resize.ui-dialog-overlay',resize);dialog.uiDialog.is('.ui-draggable')&&dialog.uiDialog.data('stop.draggable',resize);dialog.uiDialog.is('.ui-resizable')&&dialog.uiDialog.data('stop.resizable',resize);},hide:function(){$('a, :input').add([document,window]).unbind('.ui-dialog-overlay');this.ie6&&this.selects.css('visibility','visible');this.$el=null;$('.ui-dialog-overlay').remove();},height:function(){var height;if(this.ie6&&($(document.body).height()<$(window).height())&&!(document.documentElement.scrollTop||(this.dialog.uiDialog.offset().top
+this.dialog.uiDialog.height())>$(window).height())){height=$(window).height();}else{height=$(document).height();}
return height+'px';},width:function(){var width;if(this.ie6&&($(document.body).width()<$(window).width())&&!(document.documentElement.scrollLeft||(this.dialog.uiDialog.offset().left
+this.dialog.uiDialog.width())>$(window).width())){width=$(window).width();}else{width=$(document).width();}
return width+'px';},ie6:$.browser.msie&&$.browser.version<7,selects:null};})(jQuery);