﻿var posData = { "left" : 0, "top" : 0, "width" : 0,"height" : 0 , "template" : {}, "photo" : [] };

var gsAgent = navigator.userAgent.toLowerCase();
var gfAppVer = parseFloat(navigator.appVersion);
var gIsOpera = gsAgent.indexOf("opera") > -1;
var gIsKHTML = gsAgent.indexOf("khtml") > -1 || gsAgent.indexOf("konqueror") > -1 || gsAgent.indexOf("applewebkit") > -1;
var gIsSafari = gsAgent.indexOf("applewebkit") > -1;
var gIsIE = ( gsAgent.indexOf("compatible") > -1 && !gIsOpera ) || gsAgent.indexOf("msie") > -1;
var gIsTT = gIsIE ? (navigator.appVersion.indexOf("tencenttraveler") != -1 ? 1 : 0) : 0;
var gIsFF = gsAgent.indexOf("gecko") > -1 && !gIsKHTML;
var gIsNS = !gIsIE && !gIsOpera && !gIsKHTML && (gsAgent.indexOf("mozilla") == 0) && (navigator.appName.toLowerCase() == "netscape");
var gIsAgentErr = !( gIsOpera || gIsKHTML || gIsSafari || gIsIE || gIsTT || gIsFF || gIsNS );

if ( gIsIE ) {
    var reIE = new RegExp( "MSIE (\\d+\\.\\d+);", "i" );
    reIE.test( navigator.userAgent );
    var gIEVer = parseFloat( RegExp[ "$1" ] );
}

function RegFilter( str ) {
    return str.replace( /([\^\.\[\$\(\)\|\*\+\?\{\\])/ig, "\\$1" ) ;
}

function Template( t, f ) {
    var cj = typeof( t ) == "string" ? t : ( t.join ? t.join( "" ) : "" );
    var gZ, ps, av = f ? f : "$", su = RegFilter( av );
    var rP =  function(p) {
        if ( !gZ ) 
            ps = ( gZ = cj.split( av ) ).concat();
        for ( var i = 1, az = gZ.length; i < az; i += 2 ) 
            ps[ i ] = p[ gZ[ i ] ];
        return ps.join( "" );
    };
    var rRE = function( p ) {
        return cj.replace( new RegExp( [ su, "(.*?)", su ].join( "" ), "ig" ), function( m, v ){return p[ v ];} );
    };
    this.toString = function() {
        return cj;
    };
    this.replace = function( p, defaultFunc ) {
        return ( defaultFunc == "parse" || !( document.all && !( /opera/i.test(navigator.userAgent ) ) ) ? rP : rRE )( p );
    };
}

function T( t, f ) {
    return new Template( t, f );
}

function S(i, win) {
    try {
        return ( win || window ).document.getElementById(i);
    }catch( e ) {
        return null;
    }
}

function GetPath(type, bMustFull) {
    var p = "";
    switch ( type ) {
        case "image":
            try {p = top.images_path;}catch(e){}
//            if(!p) p = "/images/";
              p="";
            break;
        case "js":
            try {p = top.js_path;}catch(e){}
            if(!p) p = "/js/";
            break;
        case "css":
            try {p = top.css_path;}catch(e){}
            if(!p) p = "/style/";
            break;       
        case "skin":
            try {p = top.skin_path;}catch(e){}
            if(!p) p = "0";
            break;
        case "blank":
            p = "/blank.html";
            break;
    }
    
    var mj = location.protocol;
    if ( bMustFull && type != "skin" && type != "blank" && p.indexOf( mj ) == -1 )
        p = [ mj, "//", location.host, p ].join( "" );
    return p;
}

var gd = document;

function GelTags(tag, ob) {
    return ( ob || gd ).getElementsByTagName(tag);
}

function fAddEvent(oTarget, sType, fHandler, bRemove) {
    if (!oTarget) return;
    
    if (oTarget.addEventListener) {
        bRemove ? oTarget.removeEventListener(sType, fHandler, false) : oTarget.addEventListener(sType, fHandler, false);
    } else if (oTarget.attachEvent) {
        bRemove ? oTarget.detachEvent("on" + sType, fHandler) : oTarget.attachEvent("on" + sType, fHandler);
    } else {
        oTarget["on" +sType] = bRemove ? null : fHandler;
    }
}

function fRemoveEvent(oTarget, sType, fHandler) {
    fAddEvent( oTarget, sType, fHandler, true );
}

function fPreventDefault( oEvent ) {
    if ( oEvent ) {
        if ( oEvent.preventDefault ) {
            oEvent.preventDefault();
        } else {
            oEvent.returnValue = false;
        }
    }
}

function fStopPropagation( oEvent ) {
    if ( oEvent ) {
        if ( oEvent.stopPropagation ) {
            oEvent.stopPropagation();
        } else {
            oEvent.cancelBubble = true;
        }
    }
}

function SetClass( o, v ) {
    if ( o && o.className != v )
        o.className = v;
}

function fixNonBreakSpace( s ) {
    return ( s || "" ).replace( /\xA0/ig, " " );
}

function InitAutoComplete() {}

function IsObjContainTarget( aJ, qM ) {
    if ( !aJ || !qM ) return false;
    else if ( aJ.contains ) {
        return aJ.contains( qM );
    } else if ( aJ.compareDocumentPosition ) {
        var wM = aJ.compareDocumentPosition( qM );
        return ( wM == 20 || wM == 0 );
    }
    return false;
}

function fCalcPos(obj) {
    var pos = [0, obj ? obj.offsetWidth : 0, obj ? obj.offsetHeight : 0, 0];
    for (; obj;obj = obj.offsetParent) {
        pos[3] += obj.offsetLeft;
        pos[0] += obj.offsetTop - ( obj.offsetParent ? obj.scrollTop : 0 );
    }
    pos[1] += pos[3];
    pos[2] += pos[0];
    return pos;
}

var qmPostcardSys = function( ax ) {
    this.Hx();
    this.Hd( ax );
};

qmPostcardSys.prototype.setTemplate = function( yx ) {
    var Jl= this.IX;
    var en= this.fw;
    for ( var pi in en ) {
        var pj= yx[ pi ];
        var dc= en[ pi ];
        dc.visibility= pj ? "" : "hidden";
        if ( pj ) {
            for ( var us in dc ) {
                var bo = pj[ us ];
                if( typeof( bo ) != "undefined" )
                    dc[ us ] = bo;
            }
        }
        
        this.ti( pi );
    }
        
    this.CQ( yx.zoom );
    this.yE();
        
    if ( this.pu ) this.showToolBar( true );
};

qmPostcardSys.prototype.setPhoto = function( cD, rO ) {
    window.gPostcaradData.photo[0].height = cD.height;
    window.gPostcaradData.photo[0].width = cD.width;
    if(posData["photo"])
    {
       posData["photo"].url = cD.url;
    }
    else
    {
        posData["photo"] = [];
        posData["photo"].url = cD.url;
    }
    if ( !cD || !cD.url ) return false;
    var dq = this.vw = ( new Date() ).valueOf();    
    if ( !cD.width || !cD.height ) {
        var aa = this;
        this.wc( true );
        this.Gk( {
            photoInfo: cD,
            ongetphotoinfo: function( DZ ) {
                aa.vR( DZ, dq );
            }
        } );
        return true;
    }
    
    this.vR( cD, dq );
    return true;
};

qmPostcardSys.prototype.setStamp = function( qP ) {
    if ( qP && qP.url ) {
//        this.fw[ "stamp" ].url = qP.url;
//        this.ti( "stamp" );
    }
};

qmPostcardSys.prototype.setPostmark = function( rc ) {
    if ( rc && rc.url ) {
//        this.fw[ "postmark" ].url = rc.url;
//        this.ti( "postmark" );
    }
};

qmPostcardSys.prototype.setTextContent = function( yz ) {
//    var kn= this.jI;
//    var gs= this.dE.text;
//    for ( var aR in kn ) {
//        var bo = yz[ aR ];
//        if ( typeof( bo ) == "string" ) {
//            gs.value= bo;
//            kn[ aR ]= gs.value;
//        }
//    }
//    
//    if ( !yz.defaultpos ) this.jI.defaultpos = "";
//    this.tc();
};

qmPostcardSys.prototype.getXML = function( EE ) {
    if ( !this.hq() ) return "";
    
    function fZ( rl, rj ) {
        var ao = {};
        if ( rl )
            for ( var i in rl )
                ao[ i ] = rl[ i ];
        if ( rj )
            for ( var i in rj )
                ao[ i ] = rj[ i ];
        return ao;
    }
    var en= this.fw;
    var mn= qmPostcardSys.au.gk;
    var nT= mn.hc;
    var tQ= mn.ir;
    var DR= mn.fb;
    var rv  = [
        nT.replace( fZ( en.photo, {
            DATA : tQ.replace( fZ( this.gR, {composite : "in"} ) )
            } ) )
        ];
    
    if ( !EE ) {
        var gK = [ "mask"];
        for ( var i = 0, az = gK.length; i < az; i++ ) {
            var dc = en[ gK[ i ] ];
            rv.push( nT.replace( fZ( dc, {
                DATA : tQ.replace( fZ( dc, {
                    left: 0,
                    top: 0,
                    zoomwidth: 0,
                    zoomheight: 0,
                    type: dc.url && dc.visibility != "hidden" ? "sys" : "hidden"
                    } ) )
                } ) ) );
            }
        }

rv.push( nT.replace( fZ( en.text, {
DATA : DR.replace( fZ( en.text, {
DATA : this.getTextContent()
} ) )
} ) ) );

return mn.GQ.replace( {
DATA : nT.replace( fZ( en.mask, {
DATA : rv.join( "" )
} ) )
} );
};

qmPostcardSys.prototype.getSize = function() {
var AE = this.fw[ "mask" ];
return {
width: AE.width,
height: AE.height
}
};

qmPostcardSys.prototype.getTextContent = function() {
return fixNonBreakSpace( this.zT() );
};

qmPostcardSys.prototype.showToolBar = function( cm ) {
var cQ = this.dE.toolObj;
this.pu = cm;
for ( var i in cQ )
this.mE( i, cm );
}

qmPostcardSys.prototype.Hd = function( ax ) {
this.lB( ax );
this.qH();
};

qmPostcardSys.prototype.Hx = function() {
    var zL= [ "photo", "mask"];
    var en= this.fw = {};
    for ( var i = 0, az = zL.length; i < az; i++ )
        en[ zL[ i ] ] = { left: 0, top: 0, width: 0, height: 0, url: "", color: "#000", visibility: "", images_path: GetPath("image") };

    this.gR = { left: 0, top: 0, zoomwidth: 0, zoomheight: 0, zoomrate: 1, baserate: 1, width: 0, height: 0, url: "", type: "sys", images_path: GetPath("image") };
    
    this.jI = { tiptxt: "", defaulttxt: "", defaultpos: "" };
    
    this.pu= false;
    this.tG= false;
};

qmPostcardSys.prototype.lB = function( ax ) {
var bC = this.dE = {
container : ax.container
};

bC.photo= S( "layerPhoto" );
bC.mask= S( "layerMask" );
//bC.stamp= S( "layerStamp" );
//bC.postmark= S( "layerPostmark" );
//bC.text= S( "layerText" );
bC.mover= S( "layerMover" );

bC.photoLoader= S( "loadPhoto" );

bC.rangeObj= {
photo: S( "rangePhoto" ),
text: S( "rangeText" )
};
bC.toolObj= {
photo: S( "toolPhoto" )
};

bC.img= GelTags( "img", bC.photo )[ 0 ];

bC.photoToolObj= {
arrowTop: S( "toolPhotoArrowTop" ),
arrowLeft: S( "toolPhotoArrowLeft" ),
arrowBottom: S( "toolPhotoArrowBottom" ),
arrowRight: S( "toolPhotoArrowRight" ),

zoomBase: S( "toolPhotoZoomBase" ),
zoomIn: S( "toolPhotoZoomIn" ),
zoomOut: S( "toolPhotoZoomOut" ),
zoomBar: S( "toolPhotoZoomBar" ),
zoomSlot: S( "toolPhotoZoomSlot" ),
zoomMask: S( "toolPhotoZoomMask" )
};

this.cU= {

slotHeight: bC.photoToolObj.zoomSlot.clientHeight - 
parseInt( bC.photoToolObj.zoomBar.clientHeight / 2 ),
stepHeight: 0,

rangeMin: qmPostcardSys.sU[ 0 ],
rangeMax: qmPostcardSys.sU[ 1 ],
step: qmPostcardSys.tU,
rate: 1
};

this.jc = {
onmaskclick: ax.onmaskclick,
//onstampclick: ax.onstampclick,
onpostmarkclick: ax.onpostmarkclick,
onphotoclick: ax.onphotoclick,
onuploadimg: ax.onuploadimg
};
};

qmPostcardSys.prototype.CQ = function( lq ) {
if ( !lq )
lq = {};

var eK= this.cU;

eK.rate= lq.rate|| qmPostcardSys.iV;
eK.step= lq.step|| qmPostcardSys.tU;
eK.rangeMax= lq.max|| qmPostcardSys.sU[ 1 ];
eK.stepHeight= this.wA( 
eK.rangeMin + eK.step ) * eK.slotHeight;
};

qmPostcardSys.prototype.qH = function() {
var aa= this;
var mQ= [ "photo"];
var en= this.fw;
var bC= this.dE;
var ak= bC.container;

var kX= en[ "photo" ];
var aG= this.gR;
var iK= bC.img;
var pl= bC.mover;


var iJ= false;
var nY= {};


var ix= false;
var nh= {};

function Ha() {
var wJ = iK.cloneNode( true );
wJ.style.margin = "0";

pl.innerHTML = "";
pl.appendChild( wJ );
}

function AZ( bX ) {
pl.style.cssText = [
qmPostcardSys.au.aw.replace( bX ),
qmPostcardSys.au.ub.replace( bX )
].join( "" );
}

function lH( an ) {
var aj= an.srcElement || an.target;
var jB= bC.toolObj;
for ( var i in jB )
if ( IsObjContainTarget( jB[ i ], aj ) )
return i;

var uo= fCalcPos( ak );
var vG= fCalcPos( aj );

var nu= ( an.offsetX|| an.layerX || 0 ) + vG[ 3 ] - uo[ 3 ];
var jx= ( an.offsetY || an.layerY || 0 ) + vG[ 0 ] - uo[ 0 ];

var nQ= bC.rangeObj;

for ( var i = mQ.length - 1; i >= 0; i-- ) {
var hc= mQ[ i ];
if ( nQ[ hc ] == aj )
return mQ[ i ];
var ap= en[ hc ];
var ke= ap.left;
var fF= ap.top;
if ( nu >= ke && nu <= ( ke + ap.width) && 
 jx >= fF && jx <= ( fF + ap.height) )
return mQ[ i ];
}

return null;
};

function tN( an, jy ) {
if ( !aa.hq() )
return ;


var qV = aa.fJ( "left", an.screenX - nY.nu + aG.left );
var fu = aa.fJ( "top", an.screenY - nY.jx + aG.top );

iK.style.marginLeft= qV + "px";
iK.style.marginTop= fu + "px";

AZ( {
left: ( qV+ kX.left ),
top: ( fu+ kX.top ),
visibility: jy ? "hidden" : "visibility"
} );

if ( jy ) {
aG.left= qV;
aG.top= fu;
}

aa.mE( "photo", jy ? true : false, true );
};

function tF( of ) {
    var iX = 1;
    switch( of ) {
        case "top":
            iK.style.marginTop = aG.top = aa.fJ( "top", aG.top - iX );
            break;
        case "bottom":
            iK.style.marginTop = aG.top = aa.fJ( "top", aG.top + iX );
            break;
        case "left":
            iK.style.marginLeft = aG.left = aa.fJ( "left", aG.left - iX );
            break;
        case "right":
            iK.style.marginLeft = aG.left = aa.fJ( "left", aG.left + iX );
            break;
    };
//    S("txtPosImg").value = "L:" + (aG.left - iX) + "T:" + (aG.top - iX);
};

function uu( an, jy ) {
var fu = an.screenY - nh.jx + nh.fF;
if ( fu < 0 )
fu = 0;
if ( fu > aa.cU.slotHeight )
fu = aa.cU.slotHeight;

if( !aa.nf( aa.cU.rangeMin + Math.round( 
( aa.cU.slotHeight - fu ) / aa.cU.stepHeight ) * aa.cU.step, 
false, false, jy ? null : fu ) )
aa.uJ( jy ? null : fu );
}

function vO( an ) {
if ( ak.setCapture ) {
ak.setCapture();
}
else {
window.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP );

if ( !gIsFF ) {
fPreventDefault( an );
}
else {
setTimeout( function() {
window.getSelection().removeAllRanges();
} );
}
}
}

function vm() {

if ( window.getSelection )
window.getSelection().removeAllRanges();

if ( ak.releaseCapture ) {
ak.releaseCapture();
}
else {
window.releaseEvents( Event.MOUSEMOVE | Event.MOUSEUP );
}
}

function wu( an ) {
if ( !aa.hq() )
return ;

if ( !iJ && !ix && lH( an ) == "photo" ) {
var bo = typeof( an.detail ) == "undefined" ? 
an.wheelDelta : -an.detail;
aa.sz( bo > 0 );
fPreventDefault( an );
}
}

fAddEvent( window.captureEvents ? window : ak, "mousemove", function( an ) {
if ( iJ ) {
tN( an );
}
else if ( ix ) {
uu( an );
}
} );

fAddEvent( ak, "mousemove", function( an ) {
if ( !iJ && !ix )
aa.nG( lH( an ) );
} );

fAddEvent( ak, "mouseout", function( an ) {
if ( !iJ && 
 !ix && 
 !IsObjContainTarget( ak, an.relatedTarget || an.toElement ) )
aa.nG( null );
} );

fAddEvent( ak, "drag", fPreventDefault );

fAddEvent( ak, "mousedown", function( an ) {
var hc = lH( an );

//if ( hc != "text" )
//bC.text.blur();

switch( hc ) {
case "photo":
iJ= true;
nY.nu= an.screenX;
nY.jx= an.screenY;

vO( an );
Ha();

break;
case "text":
break;
default :
var bc = aa.jc[ "on" + ( hc || "mask" ) + "click" ];
if ( typeof( bc ) == "function" )
bc.call( aa, an );
fPreventDefault( an );
break;
}
} );

fAddEvent( window.captureEvents ? window : ak, "mouseup", function( an ) {
if ( iJ ) {
iJ = false;
vm();
tN( an, true );
aa.nG( lH( an ) );
}
else if ( ix ) {
ix = false;
vm();
uu( an, true );
aa.nG( lH( an ) );

var aj= an.srcElement || an.target;
var rV= bC.photoToolObj.zoomBar;
if ( !IsObjContainTarget( rV, aj ) )
rV.firstChild.className = "mytool button_normal";

if ( !ak.setCapture ) {
bC.photoToolObj.zoomSlot.style.cursor = "pointer";
rV.style.cursor = qmPostcardSys.dA.GN.replace( {
images_path : GetPath("image")
} );
}
}
} );

fAddEvent( ak, "mousewheel", wu );

fAddEvent( ak, "DOMMouseScroll", wu );

//bC.text.onfocus = function() {
//this.setAttribute( "focused", "true" );
//if( aa.tc() )
//aa.Gz( aa.jI.defaultpos.length );
//};

//bC.text.onblur = function() {
//this.setAttribute( "focused", "false" );
//this.setAttribute( "hascontent", aa.zT() ? "true" : "false" );
//aa.tc();
//};


var DH= bC.toolObj.photo;
var bk= bC.photoToolObj;

DH.onmousedown = function( an ) {
an = an || window.event;
fStopPropagation( an );
fPreventDefault( an );
};

bk.arrowLeft.onmouseover = 
bk.arrowTop.onmouseover = 
bk.arrowRight.onmouseover = 
bk.arrowBottom.onmouseover = 
bk.zoomIn.onmouseover = 
bk.zoomOut.onmouseover = 
bk.zoomBar.onmouseover = 
bk.arrowLeft.onmouseup = 
bk.arrowTop.onmouseup = 
bk.arrowRight.onmouseup = 
bk.arrowBottom.onmouseup = 
bk.zoomIn.onmouseup = 
bk.zoomOut.onmouseup = function() {
this.firstChild.className = "mytool button_on";
};

bk.arrowLeft.onmouseout = 
bk.arrowTop.onmouseout = 
bk.arrowRight.onmouseout = 
bk.arrowBottom.onmouseout = 
bk.zoomIn.onmouseout = 
bk.zoomOut.onmouseout = 
bk.arrowLeft.onmousedown = 
bk.arrowTop.onmousedown = 
bk.arrowRight.onmousedown = 
bk.arrowBottom.onmousedown = 
bk.zoomIn.onmousedown = 
bk.zoomOut.onmousedown = function() {
this.firstChild.className = "";
};

bk.zoomBar.onmouseout = function() {
this.firstChild.className = "mytool button_normal";
};

function mA( of ) {
return function() {
if ( !aa.hq() )
return ;
for ( var i = 1; i <= 19; i++ )
setTimeout( function() {
tF( of );
}, i * 10 );
tF( of );
};
};

function xa( aN ) {
var Ax = aN == "in";
return function() {
if ( !aa.hq() )
return ;
for ( var i = 1; i <= 9; i++ )
setTimeout( function() {
aa.sz( Ax );
}, i * 10 );
aa.sz( Ax );
};
};

bk.arrowTop.onclick = mA( "top" );
bk.arrowBottom.onclick = mA( "bottom" );
bk.arrowLeft.onclick = mA( "left" );
bk.arrowRight.onclick = mA( "right" );

bk.zoomIn.onclick = xa( "in" );
bk.zoomOut.onclick = xa( "out" );

bk.zoomSlot.onmousedown = function( an ) {
    if ( !aa.hq() ) return ;
    an = an || window.event;
    aa.nf( aa.cU.rangeMin + Math.round( ( aa.cU.slotHeight - ( an.offsetY || an.layerY || 0 ) ) / aa.cU.stepHeight ) * aa.cU.step );
};

bk.zoomBar.onmousedown = function( an ) {
    if ( !aa.hq() ) return ;
    an = an || window.event;
    
    ix= true;
    nh.jx= an.screenY;
    nh.fF= parseInt( this.style.marginTop );
    
    var dA = qmPostcardSys.dA.Ho.replace( { images_path : GetPath("image") } );
    if ( ak.setCapture ) {
        ak.style.cursor = dA;
    } else {
        bk.zoomSlot.style.cursor = this.style.cursor = dA;
    }
    
    vO( an );
    fStopPropagation( an );
};
};

qmPostcardSys.prototype.vR = function( cD, rO ) {
if ( this.vw != rO )
return debug( [ "_setTimeStampPhoto timeout", this.vw, rO ] );

var aG= this.gR;
aG.left = cD.left|| 0;
aG.top= cD.top|| 0;
aG.zoomwidth= cD.zoomwidth|| cD.width,
aG.zoomheight= cD.zoomwidth|| cD.height,
aG.width= cD.width,
aG.height= cD.height,
aG.url= cD.url;
aG.type= cD.type || "sys";

this.yE( cD.rate );
this.wc( false );
}

qmPostcardSys.prototype.ti = function( kJ ) {
var au= qmPostcardSys.au;
var dc= this.fw[ kJ ];
var wk= [
au.aw.replace( dc ),
au.bT.replace( dc ),
au.qG.replace( dc ),
au.ub.replace( dc )
];
var Ag= kJ != "photo" && 
kJ != "text" && dc.url && dc.visibility == "";
var zr= top.gIEVer && top.gIEVer < 7;


if ( Ag && !zr )
wk.push( au.Bx.replace( dc ) );

var xU= this.dE[ kJ ];
xU.style.cssText = wk.join( "" );

if ( Ag && zr ) {
setTimeout( function() {
xU.style.filter = 
qmPostcardSys.au.Fe.replace( dc );
}, {
"mask": 90
//"stamp": 30,
//"postmark": 60
}[ kJ ] );
}
};

qmPostcardSys.prototype.tg = function() {
var aG= this.gR;
var ab= ( aG.type == "sys" ? GetPath("image") : "" ) + aG.url;
var lP= this.dE.img;

if ( lP.src != ab )
lP.src = ab;

lP.style.cssText= [
qmPostcardSys.au.aw.replace( aG ),
qmPostcardSys.au.bT.replace( {
width: aG.zoomwidth,
height: aG.zoomheight
} )
].join( "" );
};

qmPostcardSys.prototype.tc = function() {
var gs = this.dE.text;
if ( gs.getAttribute( "hascontent" ) == "true" ) {
SetClass( gs, "contentext" );
return false;
}
else if ( gs.getAttribute( "focused" ) == "true" ) {
gs.value = this.jI.defaulttxt;
SetClass( gs, "contentext" );
}
else {
gs.value = this.jI.tiptxt;
SetClass( gs, "contentext opa50" );
}

return true;
};

qmPostcardSys.prototype.uJ = function( nI ) {
this.dE.photoToolObj.zoomBar.style.marginTop = typeof( nI ) == "number" ? 
nI : parseInt( ( 1 - this.wA() ) * this.cU.slotHeight );
};

qmPostcardSys.prototype.zT = function() {
var kn= this.jI;
//var fb= this.dE.text;
//return ( 
//fb.value == kn.defaulttxt||
//fb.value == kn.tiptxt||
//fb.value == ""
//) ? "" : fb.value;
};

qmPostcardSys.prototype.Gz = function( jO, ki ) {
var fb= this.dE.text;
jO= jO|| 0;
ki= ki|| jO;
if ( fb.createTextRange ) {
var nP = fb.createTextRange();
nP.moveStart( "character", jO - 1 );
if ( jO == ki ) {
nP.collapse( true );
}
else {
nP.moveEnd( "character", ki - 1 );
}
nP.select();
}
else {
function vQ() {
fb.selectionStart = jO;
fb.selectionEnd   = ki;
};

if ( gIsSafari ) {
setTimeout( vQ );
}
else {
vQ();
}
}
};

qmPostcardSys.prototype.nG = function( fG ) {
var qr = this.DX;
var dA= fG == "photo" && this.hq() ? 
qmPostcardSys.dA.AQ : qmPostcardSys.dA.Fm;
var cO= this.dE.container.style;
if ( cO.cursor != dA )
cO.cursor = dA;

if ( qr == fG )
return ;

this.zs( qr, false );
this.mE( qr, false );

this.zs( fG, true );
this.mE( fG, true );

this.DX = fG;
};

qmPostcardSys.prototype.zs = function( yZ, ED, fG ) {
var nQ= this.dE.rangeObj[ yZ ];
if ( !nQ )
return ;

var EY= nQ.style;
var ho= this.dE[ fG || yZ ];

function fm( fg, bD, aJ ) {
var cO = ( aJ && aJ.style ) || EY;
if ( cO[ fg ] != bD )
cO[ fg ] = bD;
}

if ( ED == false ) {
fm( "visibility", "hidden" );
}
else {
fm( "width",ho.style.width );
fm( "height", ho.style.height );

fm( "marginLeft", parseInt( ho.style.marginLeft || 0 ) - ( gIsIE ? 0 : 2 ) );
fm( "marginTop", parseInt( ho.style.marginTop || 0 ) - ( gIsIE ? 0 : 2 ) );

fm( "visibility", "visible" );
}
};

qmPostcardSys.prototype.wc = function( cm ) {
var zz= this.tG = cm == false ? false : true;
var bC= this.dE;
bC.toolObj.photo.className = zz ? "tool opa50" : "tool";
bC.photoToolObj.zoomMask.style.visibility = 
bC.photoLoader.style.visibility = 
zz ? "visible" : "hidden";
};

qmPostcardSys.prototype.mE = function( fG, cm, kL ) {
var jB= this.dE.toolObj[ fG ];
if ( !jB )
return ;

var ho= this.dE[ fG ];
var cO= jB.style;

function fm( fg, bD, aJ ) {
if ( cO[ fg ] != bD )
cO[ fg ] = bD;
}

if ( ( kL ? cm : ( cm || this.pu ) ) == false ) {
fm( "visibility", "hidden" );
}
else {

var Aw = parseInt( ho.style.marginLeft || 0 ) - ( gIsIE ? 0 : 2 );
var AD= parseInt( ho.style.marginTop || 0 ) - ( gIsIE ? 0 : 2 );
var nR= 5;

if ( ho.clientWidth < 160 ) {
Aw -= ( jB.clientWidth - 2 + nR );
AD-= ( 1 + nR );
}

fm( "marginLeft", Aw + nR );
fm( "marginTop", AD + nR );

fm( "visibility", "visible" );
}
};

//鼠标滚轮事件
qmPostcardSys.prototype.fJ = function( aN, kz ) {
    var aR= { "left": "width", "top": "height" }[ aN ];
    var Df= "zoom" + aR;
    var tC= this.gR[ Df ];
    var zS= this.fw.photo[ aR ];
    
    if ( kz + tC < zS ) kz = zS - tC;
    
    if ( kz > 0 ) kz = 0;
    
    // 设置坐标点
    posData[aN] = parseInt(kz);
    posData["width"] = this.gR.zoomwidth;
    posData["height"] = this.gR.zoomheight;
    
//    S("txtPosImg").value = "L:" + posData["left"] + " T:" + posData["top"] + " PL:" + posData["template"].photo.left + " PT:" + posData["template"].photo.top;
    return kz;
};

qmPostcardSys.prototype.yE = function( Bf ) {
var kX= this.fw.photo;
var aG= this.gR;

var tA = kX.width/ aG.width;
var tK= kX.height/ aG.height;
var iV= tA > tK ? tA : tK;

aG.baserate= 1;
aG.zoomrate= 0; 

this.nf( Bf || this.cU.rate, aG.left == 0, aG.top == 0 );
};

qmPostcardSys.prototype.nf = function( iQ, Ez, EA, nI ) {
var aG= this.gR;
var eK= this.cU;

if ( iQ < eK.rangeMin )
iQ = eK.rangeMin;
if ( iQ > eK.rangeMax )
iQ = eK.rangeMax;

if ( iQ == aG.zoomrate )
return false;

var Fb= aG.zoomwidth;
var Fa= aG.zoomheight;
var sw= this.fw.photo.width / 2;
var sv= this.fw.photo.height / 2;

var vi= iQ * aG.baserate;
aG.zoomrate= iQ;
aG.zoomwidth= parseInt( aG.width* vi );
aG.zoomheight= parseInt( aG.height* vi );

if ( Ez ) {
aG.left= this.fJ( "left", sw - aG.zoomwidth / 2 );
}
else {
aG.left= this.fJ( "left", ( aG.left - sw ) * ( aG.zoomwidth / Fb ) + sw );
}

if ( EA ) {
aG.top= this.fJ( "top", sv - aG.zoomheight / 2 );
}
else {
aG.top= this.fJ( "top", ( aG.top - sv ) * ( aG.zoomheight / Fa ) + sv );
}

this.tg();
this.uJ( nI );

//S("txtPosImg").value = "L:" + aG.left + "T:" + aG.top;
return true;
};

qmPostcardSys.prototype.sz = function( EC ) {
return this.nf( ( EC ? this.cU.step : -this.cU.step ) + 
 this.gR.zoomrate );
};

qmPostcardSys.prototype.wA = function( iV ) {
iV= iV || this.gR.zoomrate || 1;
var cY= this.cU.rangeMin;
return ( iV - cY ) / ( this.cU.rangeMax - cY );
};

qmPostcardSys.prototype.hq = function() {
return !this.tG;
};

qmPostcardSys.prototype.Gk = function( aB ) {
var fj = arguments.callee;

function xo() {
if ( fj.gL ) {
clearInterval( fj.gL );
fj.gL = null;
}
};

function xq() {
if ( fj.ir ) {
delete fj.ir;
fj.ir = null;
}
};

function wU() {
if ( lQ.width && lQ.height ) {
xo();

aB.photoInfo.width= lQ.width;
aB.photoInfo.height= lQ.height;
aB.ongetphotoinfo( aB.photoInfo );

xq();
return true;
}

return false;
};

xo();
xq();

var aG= aB.photoInfo;
var lQ= fj.ir = new Image();
lQ.src= aG.url;

if ( !wU() )
fj.gL = setInterval( wU, 200 );
};



qmPostcardSys.sU = [ 1, 4 ];
qmPostcardSys.tU = 0.05;
qmPostcardSys.iV = 1;

qmPostcardSys.dA = {};
qmPostcardSys.dA.Fm = 'default';
qmPostcardSys.dA.JL = 'pointer';
qmPostcardSys.dA.AQ = 'move';
qmPostcardSys.dA.GN = T( 'url($images_path$openedcursor.cur),default' );
qmPostcardSys.dA.Ho = T( 'url($images_path$closedcursor.cur),default' );



qmPostcardSys.au = {};

qmPostcardSys.au.aw = T( 
'margin:$top$px 0 0 $left$px;' 
);

qmPostcardSys.au.bT = T( 
'width:$width$px;height:$height$px;' 
);

qmPostcardSys.au.qG = T(
'color:$color$;'
);

qmPostcardSys.au.ub = T(
'visibility:$visibility$;'
);

qmPostcardSys.au.Bx = T( [ 
'background:url($images_path$$url$) no-repeat;',

] );

qmPostcardSys.au.Fe = T( [
'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\x27corp\x27, src=\x27$images_path$$url$\x27)' 
] );

qmPostcardSys.au.gk = {};

qmPostcardSys.au.gk.GQ = T( [
'<postcard>',
'$DATA$',
'</postcard>',
] );

qmPostcardSys.au.gk.hc = T( [
'<layer left="$left$" top="$top$" width="$width$" height="$height$">',
'$DATA$',
'</layer>'
] );

qmPostcardSys.au.gk.ir = T( [
'<image type="$type$" composite="$composite$" left="$left$" top="$top$" ',
' zoomwidth="$zoomwidth$" zoomheight="$zoomheight$"',
' realwidth="$width$" realheight="$height$" url="$url$" />'
] );

qmPostcardSys.au.gk.fb = T( [
'<text family="$family$" size="$size$" color="$color$" lineheight="$lineheight$" >',
'<![CDATA[$DATA$]]>',
'</text>'
] );





qmPostcardSys.thumb = function( ax ) {
this.lB( ax );
this.qH();
};



qmPostcardSys.thumb.prototype.selectLabel = function( bz ) {
    var cR= this.hd;
    var be= this.eU[ bz ];
    if ( be.enabled == false ) return false;
    
    var ma= cR.ln;
    if ( ma == bz || !be ) return false;
    
    this.tz( bz );
    
    if ( this.hW.title ) this.hW.title.innerHTML = be.title;

    if ( be.dom ) be.dom.className = this.gB.styleon;
    
    if ( ma ) {
        var cF = this.eU[ ma ].dom;
        if ( cF ) cF.className = this.gB.stylenone;
    }
    
    this.pA( be.gv || 1 );
    
    if ( typeof( this.jc.uA ) == "function" ) this.jc.uA.call( this, bz, ma );
    
    return true;
};

qmPostcardSys.thumb.prototype.selectData = function( bz, gC ) {
    if( bz == "style" ){
        var oR = window.gPostcaradData;
        posData["template"] = oR.style[gC].template;
    } else if( bz == "photo") {
        var oR = window.gPostcaradData;
        posData["photo"] = oR.photo[gC];
    }
    var be= this.eU[ bz ];
    var hI= be && be.qv;
    if ( !be ) return false;

    be.hI = hI;
    be.qv = gC;

    this.uG( this.hW.container );
    if ( typeof( this.jc.uB ) == "function" ) this.jc.uB.call( this, bz, gC, hI );
    
    return true;
};

qmPostcardSys.thumb.prototype.enabledLabel = function( bz, xR ) {
var be = this.eU[ bz ];
if ( !be )
return false;

SetClass( be.dom, this.gB[ 
( be.enabled = xR || typeof( xR ) == "undefined" ? true : false ) ? 
"stylenone" : "styledisable" ] );

return true;
};

qmPostcardSys.thumb.prototype.getLabelSelectData = function( bz ) {
var be = this.eU[ bz ];
return !be ? null : be.data[ be.qv ];
};

qmPostcardSys.thumb.prototype.updateLabelData = function( bz, bq ) {
var be= this.eU[ bz ];
be.data= bq;

if ( this.hd.ln == bz )
this.tz( bz );

this.uC();
this.uH();
}

qmPostcardSys.thumb.prototype.lB = function( ax ) {
    this.DK= ( ax.config && ax.config.numperpage ) || 8;
    this.Dw= ax.imagepath;
    this.hW= ax.dom;
    this.uc= ax.msg;
    this.gB= ax.style;
    this.eU= ax.label;
    this.hd= {};
    this.jc= { uA: ax.event.onselectlabelchange, uB: ax.event.onselectdatachange };
};

qmPostcardSys.thumb.prototype.qH = function() {
var aa= this;
var cF= this.hW;
var be= this.eU;
for ( var i in be ) {
( function() {
var kF= i;
var zp= be[ kF ].dom;
if ( zp ) 
zp.onclick = function() {
aa.selectLabel( kF );
};
} )();
}

if ( cF.prevbtn )
cF.prevbtn.onclick = function() {
aa.pA( aa.hd.gv - 1 );
};

if ( cF.prevbtn )
cF.nextbtn.onclick = function() {
aa.pA( aa.hd.gv + 1 );
}

fAddEvent( cF.container, "drag", fPreventDefault );
fAddEvent( cF.container, "click", function( an ) {
var aj= an.srcElement || an.target;
aa.selectData( 
aj.getAttribute( "label" ) || aj.parentNode.getAttribute( "label" ),
parseInt( aj.getAttribute( "param" ) )
 );
} );
};

qmPostcardSys.thumb.prototype.tz = function( bz ) {
var cR= this.hd;
var be= this.eU[ bz ];

cR.ln= bz;
cR.jd= be.numperpage || this.DK;
cR.kR= 1 + parseInt( ( be.data.length - 1 ) / cR.jd );
};

qmPostcardSys.thumb.prototype.xf = function( jJ, DF ) {
return qmPostcardSys.thumb.au.bn.replace( {
images_path: GetPath("image"),
msg: jJ,
loading: DF ? "" : "none"
} );
};

qmPostcardSys.thumb.prototype.Gs = function( bz, BT, xG ) {
var bv= [];
var be= this.eU[ bz ];
var cP= be.data;
var fD= cP.length;
var az= fD > ( xG + 1 ) ? ( xG + 1 ) : fD;
var hV= qmPostcardSys.thumb.au.nz;
var ar= {
thumbnone: this.gB.thumbnone,
thumbover: this.gB.thumbover,
thumbimg: this.gB.thumbimg,
images_path : typeof( be.imagepath ) == "undefined" ? this.Dw : be.imagepath
};

if ( fD == 0 )
return this.xf( this.uc.nodata || "没有数据" );

if ( cP[ 0 ] == "loading" )
return this.xf( this.uc.loading || "数据加载中...", true );

fD --;
for ( var i = BT; i < az; i ++ ) {
var eu= fD - i;
ar.label= bz;
ar.value= eu;
ar.url= cP[ eu ].thumb;

if ( !ar.url ) {

ar.url= cP[ eu ].pre;
ar.images_path= "";
}

bv.push( hV.replace( ar ) );
}

return qmPostcardSys.thumb.au.AX.replace( {
content: bv.join( "" ),
thumbborder: be.style
} );
};

qmPostcardSys.thumb.prototype.pA = function( ee ) {
var cR = this.hd;
if ( ee >= 1 && ee <= cR.kR ) {
this.eU[ cR.ln ] .gv = cR.gv = ee;
this.uH();
this.uC();
}
};

qmPostcardSys.thumb.prototype.uH = function() {
var cF= this.hW;
var cR= this.hd;
var nF= this.gB;
var gv= cR.gv;
var kR= cR.kR;

if ( cF.curpagetxt )
cF.curpagetxt.innerHTML = gv;

if ( cF.allpagetxt )
cF.allpagetxt.innerHTML = kR;

if ( cF.prevbtn )
cF.prevbtn.className = ( cF.prevbtn.disabled = gv == 1 ) ?
nF.btndisable : nF.btnenable;

if ( cF.nextbtn )
cF.nextbtn.className = ( cF.nextbtn.disabled = gv == kR ) ?
nF.btndisable : nF.btnenable;
};

qmPostcardSys.thumb.prototype.uC = function() {
var cR= this.hd;
var jd= cR.jd;
var ru= cR.gv * jd;
var ak= this.hW.container;

ak.setAttribute( "curlabel", cR.ln );
ak.setAttribute( "startpos", ru - jd );
ak.innerHTML = this.Gs( 
cR.ln, ru - jd, ru - 1 );

this.uG();
};

qmPostcardSys.thumb.prototype.uG = function( ek ) {
ek= ek || this.hW.container;
var be= this.eU[ ek.getAttribute( "curlabel" ) ];
if ( !be )
return ;

var fD= be.data.length - 1;
var wF = ek.firstChild.childNodes;
var vu= parseInt( ek.getAttribute( "startpos" ) );

try {

var qu = wF[ fD - be.qv - vu ];
if ( qu ) {
qu.setAttribute( "select", "true" );
qu.className = this.gB.thumbon;
}
}
catch( fA ) {
}

try {

var pH = wF[ fD - be.hI - vu ];
if ( pH ) {
pH.setAttribute( "select", "false" );
pH.className = this.gB.thumbnone;
}
}
catch( fA ) {
}
};



qmPostcardSys.thumb.au = {};

/*首页模版*/
qmPostcardSys.thumb.au.AX = T( [
'<ul>$content$</ul>'
] );

qmPostcardSys.thumb.au.nz = T( [
'<li class="$thumbnone$" label="$label$" param="$value$" ',
'onmouseover="',
'if ( this.getAttribute( \x27select\x27 ) != \x27true\x27 )',
'this.className=\x27$thumbover$\x27;',
'" onmouseout="',
'if ( this.getAttribute( \x27select\x27 ) != \x27true\x27 )',
'this.className=\x27$thumbnone$\x27;',
'">',
'<img class="$thumbimg$" src="$images_path$$url$" param="$value$"/>',
'</li>'
] );

qmPostcardSys.thumb.au.bn = T( [
'<table style="width:100%;height:100%;"><tr><td align="center">',
'<img align="absmiddle" src="$images_path$ico_loading3.gif" style="display:$loading$;" />$msg$',
'</td></tr></table>'
] );

qmPostcardSys.fk = function() {
    return arguments.callee.ej;
};

qmPostcardSys.cyj = function() {
return false;
//    return arguments.callee.ej;
};

qmPostcardSys.fQ = function() {
        return arguments.callee.ej;

};

qmPostcardSys.nana = function() {
        return false;

};

qmPostcardSys.kQ = function() {
    return arguments.callee.ej || ( arguments.callee.ej = new qmActivex() );
}

qmPostcardSys.Gp = function() {
    return arguments.callee.ej;
}

qmPostcardSys.iR = function() {
    var ej = qmPostcardSys.cyj();
    if ( ej ) return ej;

    return qmPostcardSys.fk.ej = new qmPostcardSys( {
        container: S( "postcardarea" ),
        onmaskclick: function() {qmPostcardSys.fQ().selectLabel( "style" );},
//        onstampclick: function() {qmPostcardSys.fQ().selectLabel( "stamp" );},
//        onpostmarkclick: function() {qmPostcardSys.fQ().selectLabel( "postmark" );},
        onphotoclick: function() {qmPostcardSys.fQ().selectLabel( "photo" );},
        onuploadimg: function() {}
    } );
};

qmPostcardSys.Ip = function( nC ) {
    var ej = qmPostcardSys.nana();
    if ( ej ) return ej;

    var fL= 0;
    var Ah= false;
    
    return qmPostcardSys.fQ.ej = new qmPostcardSys.thumb( {
        imagepath: GetPath("image"),
        dom: {
            title: S( "thumbtitle" ),
            container: S( "mini_pic01" ),
            prevbtn: S( "thumbprev" ),
            nextbtn: S( "thumbnext" ),
            curpagetxt: S( "thumbcurpage" ),
            allpagetxt: S( "thumballpage" )
        },
        style: {
            stylenone: "left pointer",
            styleon: "left fdbody bold mouse_on",
            styledisable: "left opa50 disabled",
            thumbimg: "img",
            thumbnone: "left mouse_none",
            thumbover: "left mouse_over settingtable bd",
            thumbon: "left mouse_on attbg bd_upload",
            btnenable: "settingtable bd",
            btndisable: "settingtable bd opa50"
        },
        label: {
            style: {
                title: "选择明信片",
                data: nC.style,
                dom: S( "thumbstyle" ),
                style: "thumblabel",
                numperpage: 8
            },
            photo: {
                title: "选择图片库",
                data: nC.photo,
                dom: S( "thumbphoto" ),
                style: "thumbphoto",
                numperpage: 8
            }
//            stamp: {
//                title: "选择邮票",
//                data: nC.stamp,
//                dom: S( "thumbstamp" ),
//                style: "thumbstamp",
//                numperpage: 12
//            },
//            postmark: {
//                title: "选择邮戳",
//                data: nC.postmark,
//                dom: S( "thumbpostmark" ),
//                style: "thumbpostmark",
//                numperpage: 12
//            }
        },
        event: {
            onselectdatachange : function( bz, gC, hI ) {
                switch( bz ) {
                    case "style":
                        var cO = this.getLabelSelectData( bz );
                        if ( cO ) {
                            qmPostcardSys.fk().setTemplate( cO.template );
                            var type = cO.thumb.substring(cO.thumb.lastIndexOf("."));
                            var name = cO.thumb.substring(0,cO.thumb.lastIndexOf("_"));
                            var tp = document.getElementById("tp");
                            tp.src = name+"_m"+type;
                            this.enabledLabel( "stamp", cO.template.stamp ? true : false );
                            this.enabledLabel( "postmark", cO.template.postmark ? true : false );
                            if ( !Ah ) {
                                fL = cO.defPhoto;
                                this.selectData( "photo", fL.id );
                            }
                        }
                        break;
                    case "photo":
                        var gh = this.getLabelSelectData( bz );
                        if ( fL == -1 || !gh ) Ah = true;
                        if ( gh ) {
                            qmPostcardSys.hQ( {
                                left: fL && fL.left || 0,
                                top: fL && fL.top || 0,
                                width: gh.width,
                                height: gh.height,
                                url: gh.url,
                                rate: fL && fL.rate
                            }, this, bz );
                        }
                        fL = -1;
                        break;
//                    case "stamp":
//                        var vt = this.getLabelSelectData( bz );
//                        if ( vt ) qmPostcardSys.fk().setStamp( vt );
//                        break;
//                    case "postmark":
//                        var uZ = this.getLabelSelectData( bz );
//                        if ( uZ ) qmPostcardSys.fk().setPostmark( uZ );
//                        break;
                }
            }
        }
    } );
};

qmPostcardSys.IB = function() {
    qmPostcardSys.iR();
    qmPostcardSys.Ip( window.gPostcaradData );
    var oR = window.gPostcaradData;
    qmPostcardSys.fQ().selectLabel( "style" );
    qmPostcardSys.fQ().selectData( "style", 0 );
//    qmPostcardSys.fQ().selectData( "stamp", 0 );
//    qmPostcardSys.fQ().selectData( "postmark", 0);
//    qmPostcardSys.fk().setTextContent( { tiptxt: "点击这里填写内容 ..." } );
};

qmPostcardSys.Iv = function() {
/*
    var IQ = T( [
        '<center>',
        '<img src="$url$" />',
        '<div style="margin:8px 0 0 8px;text-align:center;font:bold 14px Verdana;">',
        '给您的好友 $myname$ 也<a class="qqmail_postcard_reply" href="http://mail.qq.com" name="$addr$">发一张明信片</a>。',
        '</div>',
        '<div style="width:0px;height:0px;overflow:hidden;display:none;">$content$</div>',
        '</center>' ] );
    var jD= GetUserInfoText( "alias" ) || "你的好友";
    var DN= GetUserInfoText( "alias" ) || "";
    var Cu= GetUserInfoText( "addr" );
    S( "subject" ).value= jD + "给你制作的明信片";
    var lK= new AJAXRequest( "/cgi-bin/postcard", "POST", 5000 );
    lK.onComplete = function( ep ) {
        var sq = ep.responseText;
        if ( sq.indexOf( "/data/" ) == 0 ) {
            qmPostcardSys.GL = IQ.replace( {
                myname: DN,
                addr: Cu,
                content: qmPostcardSys.iR().getTextContent(),
                url: sq
                } );
            DisableAll( false );
            ShowProcess( 0 );
            SetGlobalVarValue( "MYPOSTCARD", sq );
            DoProcess( "", "send" );
        } else {
            lK.onError( ep, "response error" );
        }
    };
    lK.onError = function( ep, dw ) {
        ShowProcess( 0 );
        DisableAll( false );
        var bn = "明信片生成失败" + ( typeof( ( qmPostcardSys.hQ.jv || {} ).customuploadidx ) == "number" ? "，可能不支持您上传的图片" : "" ) + "。";
        fMessageBox( bn, "dialog", true, 0, "邮件发信失败" );
    };
    
    var FL = function() {
        if ( IsDisableCtl( "sendbtn" ) ) return ;
        if ( !DoProcessCheck( "", "send" ) ) return ;
        var gk = qmPostcardSys.iR().getXML();
        if ( !gk ) return showError( "图片正在加载，未能发送" );
        DisableAll( true );
        ShowProcess( 1, 1, "正在发送明信片中..." );
        lK.content = T( 'sid=$sid$&layerxml=$xml$' ).replace( {
            sid: GetSid(),
            xml: gk
            } );
        lK.send();
    };
    
    var vM = SN( "sendbtn" );
    for ( var i = vM.length - 1; i >= 0; i-- )
        fAddEvent( vM[ i ], "click", FL );
    InitComposeForPage( "postcard", {
        nowait : true
    } );
*/
};

qmPostcardSys.Hs = function() {
    qmPostcardSys.cQ.Ie();
    qmPostcardSys.cQ.IK();
    qmPostcardSys.cQ.GX();
    qmPostcardSys.cQ.Hg();
};

qmPostcardSys.Jz = function() {
if ( arguments.callee.Bp )
return false;

arguments.callee.Bp = true;

qmPostcardSys.hJ.FZ( { 
onload : function( fC ) {
if ( !fC || !fC.length )
return qmPostcardSys.hJ.zP( [ { 
id: "nodata",
name: "",
data: []
} ] ).selectLabel( "nodata" );

var vh = qmPostcardSys.hJ.zP( fC );

function xC( jt ) {
vh.selectLabel( jt.id );
qmPostcardSys.hJ.Gl( {
albumId: jt.id,
onload: function( jN ) {
vh.updateLabelData( jt.id, jN );
}
} );
};

var vp = [ "请选择相册：" ], wW = [ null ];
for ( var i = 0, az = fC.length; i < az; i++ ) {
( function() {
var xV = fC[ i ];
vp.push( xV.name );
wW.push( function() {
xC( xV );
} );
} )();
}

S( "qzoneimgAlbum" ).onclick = function() {
var aw = fCalcPos( this );
ShowPageMenu( this, "qzoneimgAlbumMenu", aw[ 3 ], aw[ 2 ], "150px", "21px", vp, wW );
};

xC( fC[ 0 ] );
} 
} );
};

qmPostcardSys.JK = function( cm ) {
var ez = S( "userdataContainer" );
if ( IsShow( ez ) == ( cm = ( cm == false ? false : true ) ) )
return ;

var fj = arguments.callee;
var ap= fj.ap;
if ( !ap ) {
ez.style.height= "1px";
ez.style.overflow= "hidden";

Show( ez, true );

ap = fj.ap = {};
ap.height= ez.scrollHeight + 10;
ap.stepHeight= ap.height / 15; 
}

Show( ez, true );

var dq= ap.dq = ( new Date() ).valueOf();

var qs= parseInt( ez.style.height );
var vy= ap.stepHeight;
var iX= Math.floor( ( cm ? ( ap.height - qs ) : qs ) / vy );
var lC= 20;

if ( iX == 0 )
return Show( ez, cm );

for ( var i = 1; i <= iX; i++ ) {
( function() {
var bj = qs + ( cm ? 1 : -1 ) * vy * i;

if ( bj >= ap.height )
return setTimeout( function() {
if ( dq == ap.dq )
ez.style.height = ap.height + "px";
}, lC * i );

if ( bj <= 1 )
return setTimeout( function() {
if ( dq == ap.dq ) {
Show( ez, false );
ez.style.height = "1px";
}
}, lC * i );

setTimeout( function() {
if ( dq == ap.dq )
ez.style.height = bj + "px";
}, lC * i );

} )();
}
};

qmPostcardSys.hQ = function( cD, yW, BZ, bX ) {
var kA = arguments.callee.kA;
var sR = arguments.callee.sR;

if ( kA && kA != yW )
kA.selectData( sR, -1 );

arguments.callee.kA = yW;
arguments.callee.sR = BZ;
arguments.callee.jv= bX;

qmPostcardSys.fk().setPhoto( cD );
};

qmPostcardSys.uN = function() {
arguments.callee.gk = this.fk().getXML();
};

qmPostcardSys.Gv = function() {
var hb = S( "postcard_preview", top );
if( !hb ) {
InsertHTML( top.document.body, "afterBegin", T( [
'<div id="postcard_preview" class="bd_upload txt_center" style="background:#fff;position:absolute;display:none;padding:20px 10px 10px;z-index:1000;">',
'<div style="overflow:auto;"></div>',
'<div style="margin:10px 0 0 0;">',
'<input type="button" value="发送" class="btn wd1" />',
'<input type="button" value="关闭" class="btn wd1" />',
'</div>',
'</div>',
'<div  style="opacity:0.3;filter:alpha(opacity=30);background:#000;position:absolute;width:100%;height:100%;display:none;z-index:999;"></div>'
] ) );
hb = S( "postcard_preview", top );
}

var vc= hb.nextSibling;
var kK= hb.firstChild;
var vb= GelTags( "input", hb );
var IJ= vb[ 0 ];
var Hk= vb[ 1 ];

function sI( cm ) {
Show( hb, cm );
Show( vc, cm );
}

vc.onclick = Hk.onclick = function() {
sI( false );
};

IJ.onclick = function() {
SN( "sendbtn", GetMainWin() )[ 0 ].click();
sI( false );
};


var bT= qmPostcardSys.fk().getSize();
var yN= 20;
var yM= 100;
var ng= top.document.body.clientWidth- yN;
var ni= top.document.body.clientHeight- yM;

if ( bT.width > ng ) {
bT.height= bT.height * ng / bT.width;
bT.width= ng;
}

if ( bT.height > ni ) {
bT.width= bT.width * ni / bT.height;
bT.height= ni;
}

kK.style.width= bT.width;
kK.style.height= bT.height;

kK.innerHTML = T( [
'<table style="width:100%;height:100%;"><tr><td style="text-align:center;">',
'<img src="$images_path$ico_loading2.gif">',
'</td></tr></table>' ] ).replace( {
images_path : GetPath("image")
} );

hb.style.left= ( ng + yN - bT.width - 20 ) / 2;
hb.style.top= ( ni + yM - bT.height - 65 ) / 2;

sI( true );

function mt( xP ) {
if ( xP ) {
kK.innerHTML = T( [
'<img src="$src$" style="width:$width$px;height:$height$px;" />'
] ).replace( {
src: xP,
width: bT.width,
height: bT.height
} );
}
else {
GelTags( "td", kK )[ 0 ].innerHTML = "明信片生成失败";
}
}

var fU = new AJAXRequest( "/cgi-bin/postcard", "POST", 5000 );
fU.onComplete = function( ep ) {
if ( ep.responseText ) {
if ( ep.responseText.indexOf( "/data/" ) == 0 ) {
mt( ep.responseText );
}
else {
mt();
}
}
else {
mt();
}
};
fU.onError = function( ep, dw ) {
mt();
};

fU.send( T( 'sid=$sid$&layerxml=$xml$' ).replace( {
sid: GetSid(),
xml: qmPostcardSys.iR().getXML()
} ) );
};


qmPostcardSys.cQ = {};

qmPostcardSys.cQ.Ie = function() {
    /*
    var cG = false;
    var uX = S( "showtoolbarBtn" );
    var Ef= [ uX.innerHTML, uX.getAttribute( "hidetitle" ) ];
    S( "showtoolbarBtn" ).onclick = function() {
        cG = !cG;
        qmPostcardSys.fk().showToolBar( cG );
        this.innerHTML = Ef[ cG ? 1 : 0 ];
    };
    */
};

qmPostcardSys.cQ.IK = function() {
//S( "uploadimgBtn" ).onclick = function() {
//qmPostcardSys.cQ.mR();
//};

};

qmPostcardSys.cQ.GX = function() {

var uQ = S( "screensnapBtn" );
if ( uQ ) {
var aa = this;
uQ.onclick = function() {
if ( !DetectActiveX( 0, 1 ) )
return showInstallActiveXDialog();
qmPostcardSys.kQ().screenSnap( function( bH ) {
if ( bH ) {
aa.ta( /*"screensnap"*/ );
}
} );
};
}
};

qmPostcardSys.cQ.Hg = function() {
    var cG= false;
    var nl= null;
    /*
    S( "showqzoneimgBtn" ).onclick = function() {
        var jv= qmPostcardSys.hQ.jv || {};
        WaitFor( function() {
            return top.qmQzoneImg ? true : false;
            },
            function() {
                top.qmQzoneImg.select( {
                    labelIdx: jv.labelIdx,
                    listIdx: jv.listIdx,
                    scrollTop: nl,
                    onclick: function( DJ, DW, AV, AH ) {
                        qmPostcardSys.hQ( {
                            url: AV.url,
                            type: "url"
                        }, null, null, {
                            labelIdx: DJ,
                            listIdx: DW
                        } );
                    nl = AH;
                }
            } );
        } );
    };
    */
};

qmPostcardSys.cQ.ta = function( /*_aType*/CJ ) {
var aa= this;

qmPostcardSys.kQ().upload( {
fileCtrl: CJ,
config: {
window: window,
from: "postcard",
widthlimit: 540,
heightlimit: 440,
scale: "true"
},
onupload: function( CD, aB ) {
switch( CD ) {
case "start":

if ( !aa.wb() )
aa.mR( true, "loading" );
break;
case "uploading":

aa.wb( aB.percent + "%" );
break;
case "ok":

aa.mR( false );

var ar = aB.imgParam;
var aQ = {
width: parseInt( ar[ 1 ] ),
height: parseInt( ar[ 2 ] ),
url: ar[ 0 ],
thumb: ar[ 0 ],
type: "user"
};

if ( !top.gUploadImgDatas || !top.gUploadImgDatas.push )
top.gUploadImgDatas = new top.Array;

top.gUploadImgDatas.push( aQ );
qmPostcardSys.hQ( aQ, null, null, {
customuploadidx : top.gUploadImgDatas.length - 1
} );

break;
case "fail":

fMessageBox( T( [
'<div>上传自定义图片失败</div>',

] ).replace( {


} ), "dialog" );
break;
}
}
} );
};

qmPostcardSys.cQ.mR = function( cm, dw ) {

if ( cm == false )
return HideModelDialog();

var bw= this.CO.replace( {
images_path : GetPath("image")
} );
var bj= 150;

if ( dw != "loading" && qmPostcardSys.kQ().hasClipBoardImage() ) {
bw+= qmPostcardSys.cQ.CP;
bj+= 90;
}

if ( dw != "loading" && top.gUploadImgDatas && top.gUploadImgDatas.length > 0 ) {
bw+= this.CG;
bj+= 170;
}

ModelDialog( 1, "上传照片", bw, null, [ "uploadClipImageBtn" ], [ function( an ) {
aa.ta();
} ], null, bj, function() {
qmPostcardSys.kQ().stopUpload();
} );

var aa = this;
GetDialogObj( "UploadFile" ).onchange = function() {
var wv = qmPostcardSys.kQ().checkImageType( this.value, "returnerr" );
if ( wv != true )
return fMessageBox( wv, "dialog" );
aa.ta( this );
};

var zY= GetDialogObj( "uploadImgContainer" );
var ty= ( qmPostcardSys.hQ.jv || {} ).customuploadidx;
if ( zY ) {
var nz = new qmPostcardSys.thumb( {

dom: {
container: zY
},

style: {
thumbimg: "thumbimg",
thumbnone: "left thumbnone pointer",
thumbover: "left thumbover pointer settingtable bd",
thumbon: "left thumbon pointer attbg bd_upload"
},

label: {
photo: {
data: top.gUploadImgDatas,
numperpage: 99999
}
},

event: {
onselectdatachange : function( bz, gC, hI ) {
if ( gC != ty ) {
qmPostcardSys.hQ( top.gUploadImgDatas[ gC ], null, null, {
customuploadidx : gC
} );
aa.mR( false );
}
}
}
} );
nz.selectLabel( "photo" );
if ( typeof( ty ) == "number" )
nz.selectData( "photo", ty );
}
};

qmPostcardSys.cQ.wb = function( rC ) {
var tE = GetDialogObj( "uploadMsgPercent" );
if ( !tE || !IsShowModelDialog() )
return false;

tE.innerHTML = rC || "&nbsp;";

Show( GetDialogObj( "uploadClipImage" ), false );
Show( GetDialogObj( "uploadForm" ), false );
Show( GetDialogObj( "uploadMsgTable" ), true );

return true;
};

qmPostcardSys.cQ.CO = T( [
'<div style="height:110px;text-align:left;padding:0 10px;" id="uploadForm">',
'<form enctype="multipart/form-data" method="post" >',
'<span>&nbsp; &nbsp; 上传您的照片：</span>',
'<input style="margin-top:40px;" type="file" name="UploadFile" id="UploadFile" align="absmiddle" class="f_size file pointer" unselectable="on" />',
'<input type="hidden" name="sid"  value="$sid$" />',
'<input type="hidden" name="from" />',
'<input type="hidden" name="mode" />',
'<input type="hidden" name="widthlimit" />',
'<input type="hidden" name="heightlimit" />',
'<input type="hidden" name="scale" />',
'</form>',
'</div>',
'<table id="uploadMsgTable" style="width:100%;height:100%;display:none;">',
'<tr><td align=center>',
'<img src="$images_path$ico_loading2.gif" align=absmiddle />&nbsp;&nbsp;照片正在上传中...',
'<span id="uploadMsgPercent"></span>',
'</td></tr>',
'</table>',
] );

qmPostcardSys.cQ.CP = T( [
'<div style="height:90px;text-align:left;border-width:1px 0 0 0;margin:0 10px;" class="bd" id="uploadClipImage">',
'<div>',
'<div style="margin:10px 0 6px 2px;">检测到剪贴板有图片</div>',
'<input type="button" name="uploadClipImageBtn" class="wd3 btn btn_true" value="使用剪贴板照片" />',
'</div>',
'</div>',
] );

qmPostcardSys.cQ.CG = T( [
'<div style="height:170px;text-align:left;padding:0 10px;">',
'<div class="addrtitle">已上传过的照片：</div>',
'<div id="uploadImgContainer" class="bd" style="height:140px;*height:150px;overflow-y:auto;padding:5px 0 0 5px;"><div>',
'</div>',
] );

qmPostcardSys.hJ = {};

qmPostcardSys.hJ.zP = function( fC ) {
var Ar = {};

for ( var i = fC.length - 1; i >= 0; i-- ) {
var gU = fC[ i ];
Ar[ gU.id ] = {
dom: this.Gn( gU ),
data: gU.data || [ "loading" ]
};
}

return qmPostcardSys.Gp.ej = new qmPostcardSys.thumb( {
config: {
numperpage: 4
},
msg: {
nodata: "该相册暂无数据",
loading: "正在加载相册中..."
},
dom: {
container: S( "qzoneimgPhoto" ),
prevbtn: S( "qzoneimgPrev" ),
nextbtn: S( "qzoneimgNext" ),
curpagetxt: S( "qzoneimgCurpage" ),
allpagetxt: S( "qzoneimgAllpage" )
},

style: {
stylenone: "hidden",
styleon: "",
styledisable: "hidden",

thumbimg: "img",
thumbnone: "left mouse_none",
thumbover: "left mouse_over settingtable bd",
thumbon: "left mouse_on attbg bd_upload",

btnenable: "settingtable bd",
btndisable: "settingtable bd opa50"
},

label: Ar,

event: {
onselectdatachange : function( bz, gC, hI ) {
var gh = this.getLabelSelectData( bz );

if ( gh ) {
qmPostcardSys.hQ( {
url: gh.url,
type: "url"
}, this, bz );
}
}
}
} );
};

qmPostcardSys.hJ.Gn = function( jt ) {
var aO= "qzoneAlbum" + jt.id;
var ao= S( aO );
if ( !ao ) {
ao = document.createElement( "a" );
ao.innerHTML= jt.name;
ao.className= "hidden";
S( "qzoneimgAlbum" ).appendChild( ao );
}
return ao;
};

qmPostcardSys.hJ.FZ = function( aB ) {
WaitFor(
function() {
return top.qmQzoneImg ? true : false;
}, 
function() {
top.qmQzoneImg.getAlbums( {
onload : function( bH, aJ ) {
if ( !bH )
showError( "获取相册列表失败..." );
aB.onload( bH ? aJ : null );
}
} );
} );
};

qmPostcardSys.hJ.Gl = function( aB ) {
WaitFor(
function() {
return top.qmQzoneImg ? true : false;
}, 
function() {
top.qmQzoneImg.getPhotos( {
albumId: aB.albumId,
onload: function( bH, aJ ) {
if ( !bH )
showError( "获取相册数据失败..." );
aB.onload( bH ? aJ : null );
}
} );
} );
};



qmPostcardSys.Hw = function() {
var dJ = S( "postcardpreview" );
if ( !dJ )
return ;

dJ.onclick = function() {
qmPostcardSys.Gv();
};
return;

var aD = S("postcard_preview", top);
var tm = S( "postcard_preview_mask", top );
var cK = GelTags( "img", aD )[ 0 ];
var iz = GelTags( "input", aD );
function closeAll()
{
Show(aD,false)
Show(tm,false)
cK.style.height= "";
cK.src= GetPath("image") + "spacer.gif";
}
cK.onclick = tm.onclick = iz[1].onclick = closeAll;
iz[0].onclick = function()
{
SN("sendbtn")[0].click();
closeAll();
}
var topheight;
var fU = new AJAXRequest( "/cgi-bin/postcard", "POST", 5000 );
fU.onComplete = function( ep ) {
if ( ep.responseText ) {
if ( ep.responseText.indexOf( "/data/" ) == 0 ) {
Show( tm, true );
debug(cK.style.height)
cK.src = ep.responseText;
topheight = top.document.body.scrollHeight - 145;
cK.onload = function() 
{
if(cK.height >= topheight) cK.style.height = topheight ;
}
Show( aD, true );
}
else {
debug( "生成图片失败" );
}
}
else {
debug( "CGI无返回" );
}
};
fU.onError = function( ep, dw ) {
debug( "生成图片失败：" + dw );
};

function btn_click() {

fU.content = T( 'sid=$sid$&layerxml=$xml$' ).replace( {
sid: GetSid(),
xml: qmPostcardSys.iR().getXML()
} );
fU.send();
};

function btn_next_onclick() {
debug( qmPostcardSys.iR().getXML( true ), "code" );
fU.content = T( 'sid=$sid$&layerxml=$xml$' ).replace( {
sid: GetSid(),
xml: qmPostcardSys.iR().getXML( true )
} );
fU.send();
};

dJ[0].onclick = dJ[1].onclick = btn_click;
dJ[0].nextSibling.onclick = dJ[1].nextSibling.onclick = btn_next_onclick;
};

qmPostcardSys.initPagePostcardSys = function() {
    this.IB();
    this.Iv();
    this.Hs();
    this.Hw();
    this.uN();

//try {
//InitAutoComplete();
//} catch( e ) {
//OnError( e.message, location.href, "0" );
//}

//S( "to" ).focus();
};

function ErrorCallBack() {
DisableAll( false );
SetNeedCloseConform( true );
ShowProcess( 0 );
}

function ConfirmCheckBeforeClose() {
    if ( qmPostcardSys.uN.gk != qmPostcardSys.fk().getXML() ) return "content";
    return "exit";
}

function GetSendContent() {
    return qmPostcardSys.GL;
};

function encode(d){
    if (typeof encodeURIComponent == "function")
        return encodeURIComponent(d);
    else if (typeof encodeURI == "function")
        return encodeURI(d);
    else
        return escape(d);
}

//function makesynthesis(){
//    var isError = false;
//    if($('#userid').html()<1 )
//    {
//       BOX_show('fromsystem');
//       tj();
//       isError = true;
//    }
//    if($('#user_state').html()<1 && $('#userid').html()>1 )
//    {
//        sAlert('未激活用户不能制作Mini志，希望制作请去<a href="http://www.smartshe.com/my/Basicmy.aspx" target="_blank">激活</a>');
//        isError = true;
//    }
//    if(!isError)
//     webservice("http://kimiwin.smartshe.com:7473/WebService.asmx/IsState", function(obj1){minilg(obj1,username)}, '{uid:"' + $('#userid').html() + '"}');    
//    
//}

function tj()
{

}

String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function makesynthesis(){
    
    var isshow = document.getElementById("isshow").checked;
    var title = document.getElementById("mini_name").value;
    var isok = false;
    var reg = /<[^>]+>/;
    if(reg.test(title))
    {
        alert("包含非法字符");
        isok = true;
    } 
    
    if(posData["photo"].url == "http://img.smartshe.com/2009/02/26/200902260221422142.png")
    {
        alert("未上传照片");
        isok = true;
    }
    if(title.Trim() == '')
    {
        alert("Mini志的标题不能为空");
        isok = true;
    }
    if (!isok) {
        var queryStr = "l=" + posData["left"] + "&t=" + posData["top"] + "&w=" + posData["width"] + "&h=" + posData["height"] + "&pl=" + posData["template"].photo.left + "&pt=" + posData["template"].photo.top + "&murl=" + encode(posData["template"].mask.url) + "&purl=" + encode(posData["photo"].url) + "&isshow=" + isshow + "&title=" + encodeURIComponent(title);

        if (posData["template"].mask.url == "http://img.smartshe.com/2009/12/31/633978476723210000.png") {
            
            window.location.href='http://www.smartshe.com/feature/songzhufu.aspx?' + queryStr;
        }
        else {
            window.open("synthesisPhoto.aspx?" + queryStr);
        }
    }
}



