// AI Util Func
var AIclient = window.navigator.userAgent.toLowerCase(); // Get client info
var clientInfo = {
    isMSIE  : (AIclient.indexOf('msie')!=-1),
    
    isMSIE7  : (AIclient.indexOf('msie 7.')!=-1),
    
    isGecko : ((AIclient.indexOf('gecko')!=-1) && 
                (AIclient.indexOf('spoofer')==-1)&& 
                (AIclient.indexOf('khtml')==-1) && 
                (AIclient.indexOf('netscape')==-1)),
                
    isSafari:    ((AIclient.indexOf('AppleWebKit')!=-1) && 
                (AIclient.indexOf('spoofer')==-1)),
                
    isKhtml : (window.navigator.vendor == 'KDE' || 
                ( document.childNodes && !document.all && 
                !window.navigator.taintEnabled )),
                
    isOpera : (AIclient.indexOf('opera')!=-1),
    
    isOpera7: ((AIclient.indexOf('opera')!=-1) && 
                (window.opera && document.childNodes))
}
function aidialog(url, width, height, arg, option){
    var result;
    var _ai_option = option;// || "modal=yes, center=yes, resizable=no, sroll=no, status=no, menubar=no, toolbar=no, directories=no, scrollbars=no";
    var _ai_arg = arg || "";
    var _width = width || '800px';
    var _height = height || '600px';
   
    if (clientInfo.isMSIE){
        if(_ai_option == null)
            _ai_option = "center:yes; resizable:no; scroll:no; status:no; menubar:no; toolbar:no; directories:no; scrollbars:no;"
        var _ai_width = ';dialogWidth:'+_width;
        var _ai_height = ';dialogHeight:'+_height;
        _ai_option += _ai_width + _ai_height+';';
        result = window.showModalDialog(url, _ai_arg, _ai_option);
        
    }
    else if(clientInfo.isGecko){
        if(_ai_option == null)
            _ai_option = "modal=yes, center=yes, resizable=no, scroll=no, status=no, menubar=no, toolbar=no, directories=no, scrollbars=no";
        var _ai_width = ',width='+_width;
        var _ai_height = ',height='+_height;
        _ai_option += _ai_width + _ai_height;
        //result = window.openDialog(url, "browse",_ai_option, _ai_arg);
        result = window.open(url, "browse",_ai_option);
        result.opener = window;
    }
    else{
    }
    return result;
}

function aiwindow(url, width, height, arg, option){
    var result;
    var _ai_option = option;// || "modal=yes, center=yes, resizable=no, sroll=no, status=no, menubar=no, toolbar=no, directories=no, scrollbars=no";
    var _ai_arg = new Object();
    var _width = width || '800px';
    var _height = height || '600px';

    _ai_arg = arg || null;
   
    if (clientInfo.isMSIE){
        if(_ai_option == null)
            _ai_option = "center:yes; resizable:no; scrollbars:no; scroll:no; status:no; menubar:no; toolbar:no; directories:no; "
        var _ai_width = ';width:'+_width;
        var _ai_height = ';height:'+_height;
        _ai_option += _ai_width + _ai_height+';';
    }
    else if(clientInfo.isGecko){
        if(_ai_option == null)
            _ai_option = "modal=yes, center=yes, resizable=no, scroll=no, scrollbars=no, status=no, menubar=no, toolbar=no, directories=no";
        var _ai_width = ',width='+_width;
        var _ai_height = ',height='+_height;
        _ai_option += _ai_width + _ai_height;
        
    }
    else{
    }
    result = window.open(url, "browse", _ai_option);
    result.focus();
    return result;
}

function getObject(objid, objtype, list){
    var iobj = document.getElementById(objid);
    var iobjtype = objtype || '';
    //var url = 'editor/aiutil/browser/browser.html?Type='+iobjtype+'&Connector=connectors/aspx/connector.aspx';    
    var url = 'browser/browser.aspx';//?type='+iobjtype;
    if(iobj.form.action == "Forum_Register_Member.aspx" || iobj.form.action == "Forums_Member_Repeater_Home.aspx") 
        url += '?logincheck=false';
    var result = aidialog(url,'800px', '564px');
    if(result && clientInfo.isMSIE){
        if(typeof(result) == 'string' && iobj){
            iobj.value = result;}
        else if(list && (result.length > 0 && iobj)){
            for(i=0; i<result.length; i++){
                iobj.value = result[i];}}
        else if(result.length > 0 && iobj){
            iobj.value = result[0];}
    }
    else if(result && clientInfo.isGecko){
		result.onunload = function() {
		        var val = result.returnValue;
		        if(val != null){
                    if(typeof(val) == 'string'){
                        iobj.value = val;}
                    else if(list && (val.length > 0 && iobj)){
                        for(i=0; i<result.length; i++)
                            iobj.value = result[i];}
                    else if(val.length > 0 && iobj){
                        iobj.value = val[0];}
		         }
        };
    
    }
    else if(result){
        iobj.value = val;
    }
}

function get_Image(objid, list){
    getObject(objid, 'Image', list);
}
function get_Img(objid, list){
    getObject(objid, 'Image', list);
}
function get_img(objid, list){
    getObject(objid, 'Image', list);
}
function get_Medial(objid, list){
    getObject(objid, 'Media', list);
}
function get_Flash(objid, list){
    getObject(objid, 'Flash', list);
}

function preview_doc(docid){
}
function preview_sctn(sctnid){
    var param1 = 'Section_List';
    var param2 = 's\\'+sctnid;
   __doPostBack(param1,param1);
}
function preview_rsc(rscid){
}
function view_rscs(docid, rsctype){
   var arg = null;
   var rsc = rsctype || 'All';
   if(docid){
    var url = "editor/aiutil/browser/resources.html?type=Footers&DocumentId="+docid;
    var result = aidialog(url,'800px', '600px');
   }
}

