/*String.prototype.startsWith = function(t, i) { if (i==false) {return 
(t == this.substring(0, t.length)); } else { return (t.toLowerCase() 
== this.substring(0, t.length).toLowerCase()); } } 
String.prototype.endsWith = function(t, i) { if (i==false) { return (t 
== this.substring(this.length - t.length)); } else { return 
(t.toLowerCase() == this.substring(this.length - 
t.length).toLowerCase()); } }*/


$.fn.observe = function( callback ) {
    return this.each(function() {
        
        var form = this;
        
        $(form.elements).change(function(){
            callback.call( form );
        });
    });
};

$.fn.hasAttr = function(name) {  
   return this.attr(name) !== undefined;
};

$.fn.getTagName = function() {
   return this.length ? this.get(0).tagName : null;
};

$.fn.getOptionByText = function(text) {
    
    var ret = false;
   
    if(this.getTagName().toLowerCase() == 'select') {
        
        this.find('option').each(function(i, o) {
            
            if($(o).text() == text) {
                ret = $(o)
            }
        });
    }
   
   return ret;
};


/* ADMIN LEGACY */
function fileBrowserCallBack(field_name, url, type, win) {
    //alert(field_name +", "+ url +", "+ type +", "+ win);
    var connector = "../../filemanager/browser.html?Connector=connectors/php/connector.php";
    var enableAutoTypeSelection = true;

    var cType;
    tinyfck_field = field_name;
    tinyfck = win;

    switch (type) {
            case "image":
                    cType = "Image";
                    break;
            case "flash":
                    cType = "Flash";
                    break;
            case "file":
                    cType = "";
                    break;
    }

    if (enableAutoTypeSelection && cType) {
            connector += "&Type=" + cType;
    }

    window.open(connector, "tinyfck", "modal,width=600,height=400");
}

function openFileBrowser(input_id, type) {
    
    var connector = "/js/tiny_mce/filemanager/browser.html?Connector=connectors/php/connector.php";
    var enableAutoTypeSelection = true;

    var cType;
    //tinyfck_field = field_name;
    //tinyfck = win;

    switch (type) {
            case "image":
                    cType = "Image";
                    break;
            case "flash":
                    cType = "Flash";
                    break;
            case "file":
                    cType = "";
                    break;
    }

    if (enableAutoTypeSelection && cType) {
            connector += "&Type=" + cType;
    }


    connector += "&input_id=" + input_id;
    
    var wnd = window.open(connector, "tinyfck", "modal,width=600,height=400");
}

function setUrl(url, id) {

    $('#' + id).attr('value', url);
    $('#' + id + '_label').html(url);
}
/* /ADMIN LEGACY */


$(document).ready(function() {

    Philippe.init();
});
