/**
* Set current page is default page of browsers
*
* @param string msg
*/
this.setHomepage = function(url, msg)
{   
    if (document.all) { 
         document.body.style.behavior='url(#default#homepage)'; 
         document.body.setHomePage(url);    
    } else if (window.sidebar) { 
        alert(msg);         
    } 
}
/*
* set cookie
*/
this.setCookie = function(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
/**
* get cookie
*/
this.getCookie = function(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
                return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}
/**
* add bookmark
*/
this.addBookmarkObj = function(title, message, errMsg) {        
    var reply = confirm(message);
    if (reply) {
        url = document.location.href;
        if(window.sidebar){    // Mozilla Firefox Bookmark 
           window.sidebar.addPanel(title, url,'');
        }else if( window.external ) {   // IE Favorite  
             window.external.AddFavorite( url, title);  
         } else if(window.opera) { // Opera 7+  
             return false; // do nothing - the rel="sidebar" should do the trick  
         } else {
             // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)  
              alert(errMsg);  
         }   
    }     
}

/**
* check min charater
*/      
this.checkCharacterQuantity = function(param , minValue) {        
    var textlength = param.length;

    if (!isNaN(minValue)) {
        if (textlength >= minValue) {
            return true;        
        } 
    }
    return false;
}

/**
* update Alternate text of media when upload
*/
this.updateAltText = function(control, target)
{
    name = $F(control);
    
    $(target).value = name.substring(0, name.lastIndexOf('.'));    
}

/**
* validate type of media when upload
*/
this.validateLogoType = function(control)
{
    if($F(control) == ""){
        alert('File empty!');
        $(control).focus();
        return false;
    } else {
        result = validateImageType(control);
        
        if(!result)
        {
            alert('File type invalid !');
            $(control).select();
        }
        
        return result;
    }
}

/**
* show light box
*/
this.showLightbox = function(control, width, height, modal){
    Lightbox.showElement(control, width, height, modal);
}

/**
* check min charater
*/ 
this.limitChars = function(obj, limit, alertmsg)
{
     var text = $F(obj); 
     var textlength = text.length;

     if(textlength > limit){
        alert(alertmsg + limit + ' characters.');
        $(obj).value = text.substr(0,limit);
     }
}

/**
* toggle control
*/ 
this.toggleContentControl = function(control, taskbar)
{
    $(control).toggle();
    $(taskbar).toggle();
    
    $(taskbar).selectedIndex = 0;
}

/**
* validate media type
*/ 
this.validateMediaType = function(control){
    value = $F(control);
    index = value.lastIndexOf(".");
    type = value.substr(index+1, value.length);
    type = type.toLowerCase();

    var data = new Array('png', 'gif', 'jpeg', 'jpg', 'bmp', 'swf', 'flv', 'mp3', 'pdf');
    
    for(i in data) {
        if(data[i] == type)
            return true;
    }        
    
    return false;
}

/**
* validate image type
*/ 
this.validateImageType = function(control){
    value = $F(control);
    index = value.lastIndexOf(".");
    type = value.substr(index+1, value.length);
    type = type.toLowerCase();
    
    var data = new Array('png', 'gif', 'jpeg', 'jpg', 'bmp');
    
    for(i in data) {
        if(data[i] == type)
            return true;
    }        
    
    return false;    
}
/**
* reset value of meta
*/ 
this.resetMetaValue = function(control) {
    $(control).enable();
    $(control).select();
}

/**
* rest default value of meta 
*/ 
this.resetGlobalMetaValue = function(control, value) {
    $(control).value = value;
    $(control).disable();
}
/**
* validate selected media
*/
this.validateSelectMedia = function(control, alertmsg) {
    if($F(control) == "")
    {
        alert(alertmsg);
        return false;
    }
    
    return true;
}