/**
 * SWFObject v1.4.2: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


/***********************************************
* Show Hint script- ? Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox


var stopupload = false;
function calProgress(iTotal,iRead,dtstart)
{
    var myDate=new Date()
    dtnow=myDate.getTime();
    
    dtelapsed = parseInt((dtnow - dtstart)/1000);

    dtelapsed_sec = (dtelapsed % 60);
    dtelapsed_min = (((dtelapsed - dtelapsed_sec) % 3600) / 60);
    dtelapsed_hours = ((((dtelapsed - dtelapsed_sec) - (dtelapsed_min * 60)) % 86400) / 3600);
    // gets number of hours; assuming that we won't be going into days!
    if (dtelapsed_sec < 10) { dtelapsed_sec = "0"+dtelapsed_sec; }
    if (dtelapsed_min < 10) { dtelapsed_min = "0"+dtelapsed_min; }
    if (dtelapsed_hours < 10) { dtelapsed_hours = "0"+dtelapsed_hours; }
    var dtelapsedf = dtelapsed_hours+':'+dtelapsed_min+':'+dtelapsed_sec;

    bSpeed = 0;
    //if not yet determined
    if (dtelapsed > 0) // avoid divide by zero errors
    {
    	bSpeed = iRead / dtelapsed; // Bytes uploaded / Seconds elapsed = Bytes/Second speed
    	bitSpeed = bSpeed * 1; // bps
    	kbitSpeed = bitSpeed / 8000;
    }
    else
    {
    	kbitSpeed = bSpeed;
    }
    bSpeedf = parseInt(kbitSpeed);

    bRemaining = iTotal - iRead;
    dtRemaining = 0;
    if (bSpeed > 0) {
    	dtRemaining = bRemaining / bSpeed;
    }
    dtRemaining = parseInt(dtRemaining);
    dtRemaining_sec = (dtRemaining % 60);
    dtRemaining_min = (((dtRemaining - dtRemaining_sec) % 3600) / 60);
    dtRemaining_hours = ((((dtRemaining - dtRemaining_sec) - (dtRemaining_min * 60)) % 86400) / 3600);
    if (dtRemaining_sec < 10) {dtRemaining_sec = "0"+dtRemaining_sec;}
    if (dtRemaining_min < 10) {dtRemaining_min = "0"+dtRemaining_min;}
    if (dtRemaining_hours < 10) {dtRemaining_hours = "0"+dtRemaining_hours;}
    var dtRemainingf = dtRemaining_hours+':'+dtRemaining_min+':'+dtRemaining_sec;

    percent = parseInt(iRead * 100 / iTotal);

    showProgress(iRead+","+iTotal+","+dtRemainingf+","+dtelapsedf+","+bSpeedf+","+percent);

}
function flashProgress(params)
{
    document.getElementById('progressbar').style.display= '';
    document.getElementById('progressbar2').style.display= '';

    parts = params.split(',');

    document.getElementById('bread').innerHTML = parts[0];
    document.getElementById('itotal').innerHTML = parts[1];
    document.getElementById('dtremainingf').innerHTML = parts[2];
    document.getElementById('dtelapsedf').innerHTML = parts[3];
    document.getElementById('bspeedf').innerHTML = parts[4];

    SendDataToFlashMovie(parts[5]);
    //document.getElementById('progBar').innerHTML= "<div class='progInner' style='width: " + parts[5] + "%;'>" + parts[5] + "%</div>";
}
function FormatNumber(srcStr,nAfterDot){
    var srcStr,nAfterDot;
    var resultStr,nTen;
    srcStr = ""+srcStr+"";
    strLen = srcStr.length;
    dotPos = srcStr.indexOf(".",0);
    if (dotPos == -1){
        resultStr = srcStr+".";
        for (i=0;i<nAfterDot;i++)
        {
            resultStr = resultStr+"0";
        }
        return resultStr;
    }
    else
    {
        if ((strLen - dotPos - 1) >= nAfterDot)
        {
            nAfter = dotPos + nAfterDot + 1;
            nTen =1;
            for(j=0;j<nAfterDot;j++)
            {
                nTen = nTen*10;
            }
            resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
            return resultStr;
        }
        else
        {
            resultStr = srcStr;
            for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++)
            {
                resultStr = resultStr+"0";
            }
            return resultStr;
        }
    }
}


function clearFileQueue(id) {
    var tbody = document.getElementById(id);
    while (tbody.childNodes.length > 0) {
       tbody.removeChild(tbody.firstChild);
    }
}
function formatSize(size)
{
    var unit = 'b';
    if(size>1024) { size=size/1024; unit='Kb'; }
    if(size>1024) { size=size/1024; unit='Mb'; }
    if(size>1024) { size=size/1024; unit='Gb'; }
    size = Math.round(size*100)/100;

    return size+''+unit;
}
var storeData = new Array();
var hasFlashUploads = false;
function displayFileQueue(id,data)
{
    clearFileQueue(id);
    storeData = data;
    number = data.length;
    hasFlashUploads = number>0;
    for (i=0; i<number; i=i+1) {
       var theTableBody = document.getElementById(id);
       var newRow = theTableBody.insertRow(0);
       if (i%2!=0) { newRow.style.background='#EEE'; }
       var name = data[i]['name'];
       var size = formatSize(data[i]['size']);

       var newCell;
       newCell = newRow.insertCell(0);
       newCell.innerHTML = '<img src="'+skinWeb+'/images/file.png" border=0> ';
       newCell = newRow.insertCell(1);
       newCell.align='left';
       newCell.innerHTML = name;
       newCell = newRow.insertCell(2);
       newCell.align = 'right';
       newCell.innerHTML = size;
       newCell = newRow.insertCell(3);
       newCell.align = 'right';
       newCell.innerHTML = '<a href="#" onclick="'+"flashObj('flashUpload').removeFileAt(" + i + ');return false;"> <img src="'+skinWeb+'/images/delete.png" alt="Delete" border=0></a> <a href="#up" class=actionlink onclick="toggleFlash('+ i +');return false;">Options</a>';
    }
}
var debug      = 0;
//upload start time
var upStart    = 0;
//total bytes uploaded
var TotalBytes = 0;
//avoid repeat email sending
var FlashDone  = 0;
var ErrorDetected = 0;
function JSRecCmd(str,vars)
{
    if(str=='error')
    {
        ErrorDetected = 1;
        //if all files fail to upload,reset upload interface
        if(vars[1]==1)
        {
            document.getElementById('uploaderror').style.display='';
            document.getElementById('uperror').innerHTML=vars[0];
            resetUploadInterface();
        }
        //show errors
        alert(vars[0]);
        return '';
    }
    if(str=='ok')
    {
        //if all files are processed and some file is ok,submit email form to show links
        if(vars[1]==1&&FlashDone==0)
        {
            submitEmailForm();
            FlashDone = 1;
        }
        return '';
    }
    if(str=='start')
    {
        var myDate=new Date()
        upStart=myDate.getTime();
        calProgress(vars[0],0,upStart);
        return '';
    }
    if(str=='done'&&FlashDone==0)
    {
        calProgress(vars[0],vars[1],upStart);
        flashObj("flashUpload").removeAllFiles();
        submitEmailForm();
        FlashDone = 1;
        return '';
    }
    if(str=='up')
    {
        calProgress(vars[0],vars[1],upStart);
        return '';
    }
    if(str=='add'||str=='del'||str=='rm')
    {
        displayFileQueue('uploadlistbody',vars);
        return '';
    }
    if(!debug) return;
    for(var key in vars)
    {
        if(typeof(vars[key])=='object')
        {
            for(var subkey in vars[key])
            {
                if(debug) alert(subkey+"="+vars[key][subkey]);
            }
        }
        else
        {
            if(debug) alert(key+"="+vars[key]);
        }
    }
}
function flashObj(flashName) {
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   return (isIE) ? window[flashName] : document[flashName];
}
function buildFlashUpload(flashPath)
{
    if(typeof(flashObj('flashUpload'))=='object') return '';
    var so = new SWFObject(flashPath, "flashUpload", "0", "0", "8", "#336699",1);
    so.addParam('allowScriptAccess','always');
    so.write("flashuploadobj");
}

var flashItemId = null;
function toggleFlash(id)
{
    flashItemId = id;

    document.getElementById('flash_name').innerHTML = (storeData[id]['name']);
    document.getElementById('flash_descr').value = (storeData[id]['descr']=='null'?'':storeData[id]['descr']);
    document.getElementById('flash_password').value = (storeData[id]['pw']=='null'?'':storeData[id]['pw']);
    
    document.getElementById('flashoptions').style.display = 'block';
}
function save2Flash()
{
    //var newData = new Array();
    
    //newData[flashItemId]= {"descr":document.getElementById('flash_descr').value,"pw":document.getElementById('flash_password').value};
    storeData[flashItemId]['descr']=document.getElementById('flash_descr').value;
    storeData[flashItemId]['pw']=document.getElementById('flash_password').value;

    var fs = new Array();
    fs = custom_fields.split(',');
    for(var i=0;i<fs.length;i++)
    {
        if(is_object('flash_'+fs[i]))
        storeData[flashItemId][fs[i]]=document.getElementById('flash_'+fs[i]).value;
    }
    
    flashObj('flashUpload').saveData(storeData);
    
    document.getElementById('flashoptions').style.display = 'none';
}

function isDefined(property) {
   return (typeof property != 'undefined');
}
