/**
 * Created by QingRenYanLei on 2017/4/17.
 */

function returnImageToParent(pos, image, isOwn) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    var previewPos = $('#'+pos+'_preview', frameParent.document);
    previewPos.attr('src', image);
    var inputPos = $('#'+pos, frameParent.document);
    inputPos.val(image);
}

function returnImageUrlToParent(pos, image, isOwn) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    var inputPos = $('#'+pos, frameParent.document);
    inputPos.val(image);
}

function batchUpload(file) {
    imageGroups.push(file);
}

function usedByImageGroupYes(pos,isOwn) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    var inputPos = $('#'+pos, frameParent.document);
    var oriVal = inputPos.val();
    var final = imageGroups.join('\r\n');
    if (oriVal=='' || null || undefined){
        inputPos.val(final.trim());
    }
    inputPos.val(oriVal+'\r\n'+final);
    imageGroups = [];
    closeSelf();
}

function usedByImageGroupNo() {
    imageGroups = [];
    closeSelf();
}


function closeSelf() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

function editorImageUpload(file) {
    var fs = window.parent;
    fs.uploadedImages.push(file);
}

function editorVideoUpload(response) {
    window.parent.uploadedVideo = 'disk/'+response.f_disk+'/key/'+response.f_name+'/';
}

function returnSourceToParent(response) {
    var frameParent = window.parent.frames[0];
    frameParent.mediaReceiver(response);
}

function toMediaReceiver(response,rev, isOwn) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    frameParent.mediaReceiver(response);
}

function toSiteLogoReceiver(response, isOwn, pos) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    frameParent.siteLogoReceiver(response,pos);
}

function toCategoryLogoReceiver(response, isOwn) {
    var frameParent = window.parent.frames[0];
    if (isOwn){
        frameParent = window.parent;
    }
    frameParent.categoryLogoReceiver(response);
}

function usedByVideoModel(pos,video) {
    var frameParent = window.parent;
    $('#'+pos, frameParent.document).val(video);
}