﻿jQuery.fn.initDialog = function(option) {
    return this.dialog(option).parent().appendTo(jQuery("#aspnetForm"));
}

jQuery.fn.openDialog = function() {
    return this.dialog('open');
}

jQuery.fn.openCustomDialog = function() {
    this.parent().appendTo(jQuery("#aspnetForm"));
    this.parent().find('.ui-dialog-titlebar').remove();
    return this.dialog('open');
}

jQuery.fn.closeDialog = function() {
	return this.dialog('close');
}

jQuery.fn.removeDialog = function() {
    this.remove();
}

jQuery.format = function(source, params) {
    if (arguments.length == 1)
        return function() {
            var args = jQuery.makeArray(arguments);
            args.unshift(source);
            return jQuery.format.apply(this, args);
        };
    if (arguments.length > 2 && params.constructor != Array) {
        params = jQuery.makeArray(arguments).slice(1);
    }
    if (params.constructor != Array) {
        params = [params];
    }
    jQuery.each(params, function(i, n) {
        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
    });
    return source;
};

jQuery.fn.InitWatermark = function(key, colorText){
    this.Watermark(key, colorText);
    var txtbox = this;
    $j('form').submit(function() {
        if(txtbox.val() == key){
            txtbox.val('');
        }
    });
    
    return this;
};

jQuery.fn.InitTinyMCE = function(){
	return this.tinymce({
		width: '680',
		mode : 'none',

		// Location of TinyMCE script
		script_url : '../Scripts/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1: "forecolor,backcolor,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect",
		theme_advanced_buttons3: "",//"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,charmap",
		theme_advanced_buttons2: "",//"bullist,numlist,|,outdent,indent,|,anchor,image,|,cleanup,help,code,preview",
		theme_advanced_buttons4 : "",//"insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
		
	});
	
}

/**
* 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
*
*/
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
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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;
    }
};
