
var ip_ENC = "";
var ip_KEY1 = "";
var ip_KEY2 = "";
var ip_ENC_embed = "";

var ip_UseUnicode = "false";

var ip_UniqueFile = true;

var ip_TotalUploadSize = 51200; 
var ip_UnitUploadSize = 10240; 
var ip_MaxFileCount = 128; 

var ip_ShowThumbnailWidth = 180;
var ip_ShowThumbnailHeight = 136;

var ip_UseThumbnailList = "true";

var ip_ShowCartThumbnailWidth = 86;
var ip_ShowCartThumbnailHeight = 65;

var ip_ModalWidth = 820;
var ip_ModalHeight = 690;
var ip_ModalMVSU = 'InnoPU.html';

var ip_WaterMarkPath = ""; 

var ip_WaterMarkWhere = "";

var ip_WaterMarkTransparency = 0;

var ip_WaterMarkApplyOriginal = true;

var ip_WaterMarkApplyThumbnail = true;

var ip_UseSaveThumbnail = true;

var ip_OnlyThumbnail = "false";

var ip_SaveThumbnailSize = new Array();

var ip_SaveThumbnailQuality = 80;
var ip_SaveThumbnailQualityApplySize = 1024*1024*100;

var ip_EmbedMode = false;
var ip_InputName = "image_file";
var ip_InputType = "array";
var ip_ActionFilePath = "";

var ip_SendForm = "";

var ip_Cab = "InnoPU5.cab";
var ip_Version = "5,3,11,2137";

var ip_isActivePU = false;
var ip_isActiveAP = false;
var ip_isActiveAPwrap = false;

function LoadInnoPU()
{
    var strID = "InnoPU";
	var tStr = '';
	var codeMSG = ' codebase="' + ip_Cab + '#version=' + ip_Version + '" ';
    var errMSG = ' onerror="InnoPULoadError()" ';

	tStr += '<object id="' + strID + '" classid="CLSID:6115352E-C05B-4054-A712-C82B3734938D" ' + codeMSG + errMSG + ' width="1" height="1">';
	tStr += '<param name="Enc" value="' + ip_ENC + '"></param>';
	tStr += '<param name="Key1" value="' + ip_KEY1 + '"></param>';
	tStr += '<param name="Key2" value="' + ip_KEY2 + '"></param>';
	tStr += '<param name="Language" value="en"></param>';
	tStr += '</object>';

	document.writeln(tStr);

	////////////////////
    var bAvailable = false;
    var APObject = document.getElementById(strID);
    if (typeof(APObject) == 'object')
    {
        if (APObject.readyState == 4)
        {
            if (APObject.object != null)
            {
                bAvailable = true;
            }
        }
    }

    if (bAvailable)
    {
		ip_isActivePU = true;
    }
    else
    {
        APObject.onreadystatechange = lsn_LoadInnoPU;
    }
    ////////////////////
}

function InnoPULoadError()
{
    alert("Click on this infomation bar to reveal a drop down menu.\nClick on [Install ActiveX Control].");
	document.location.href = 'install_pu.html?goto=';
}

function lsn_LoadInnoPU()
{
	if (ip_isActivePU)
		return;

	var strID = "InnoPU";

	////////////////////
    var bAvailable = false;
    var APObject = document.getElementById(strID);
    if (typeof(APObject) == 'object')
    {
        if (APObject.readyState == 4)
        {
            if (APObject.object != null)
            {
                bAvailable = true;
            }
        }
    }

    if (bAvailable)
    {
		ip_isActivePU = true;
    }
    else
    {
        //
    }
    ////////////////////
}

function isReadyInnoAP()
{
	if (ip_isActiveAPwrap)
		return;

	var strID = "wrapInnoAP";
	var tStr = GetInnoAPInitMulti(ip_TotalUploadSize, ip_UnitUploadSize, ip_MaxFileCount, 0, 1, 1, strID);

	document.body.insertAdjacentHTML('BeforeEnd', tStr);

	ip_isActiveAPwrap = true;

	////////////////////
    var bAvailable = false;
    var APObject = document.getElementById(strID);
    if (typeof(APObject) == 'object')
    {
        if (APObject.readyState == 4)
        {
            if (APObject.object != null)
            {
                bAvailable = true;
            }
        }
    }

    if (bAvailable)
    {
		ip_isActiveAP = true;
    }
    else
    {
        APObject.onreadystatechange = lsn_isReadyInnoAP;
    }
    ////////////////////
}

function lsn_isReadyInnoAP()
{
	if (ip_isActiveAP)
		return;

	var strID = "wrapInnoAP";

	////////////////////
    var bAvailable = false;
    var APObject = document.getElementById(strID);
    if (typeof(APObject) == 'object')
    {
        if (APObject.readyState == 4)
        {
            if (APObject.object != null)
            {
                bAvailable = true;
            }
        }
    }

    if (bAvailable)
    {
		ip_isActiveAP = true;
    }
    else
    {
        //
    }
    ////////////////////
}

function ShowInnoPU()
{
	document.InnoPU.MainViewSkinURL = ip_ModalMVSU;
	document.InnoPU.ShowThumbnailSize(ip_ShowThumbnailWidth, ip_ShowThumbnailHeight);
	var ret = document.InnoPU.DoModal(ip_ModalWidth, ip_ModalHeight);

	if (ret == 1)
	{
		if (ip_EmbedMode == false)
		{
			try
			{
				eval('OnInnoPUComplete()');
			}
			catch (ex) { }
		} else {
			// EmbedMode
			var z = document.InnoPU.ResponseData;
			var dupleExcept_b = false;
			var dupleExcept = '';

			if (z.length > 0)
			{
				var zArr = z.split('|');

				for (var i = 0; i < zArr.length; i++ )
				{
					if (ip_UniqueFile)
					{
						dupleExcept_b = false;
						for (var j = 0; j < document.InnoAP.GetCount; j++) {
							if (zArr[i] == document.InnoAP.GetFileName(j)) {
								dupleExcept_b = true;
								dupleExcept += GetNameFromPath(zArr[i]) + "\n";
								break;
							}
						}
					}

					if (dupleExcept_b == false)
						document.InnoAP.AddFile(zArr[i]);
				}

				if (dupleExcept)
				{
					alert('The following files are already included : ' + "\n\n" + dupleExcept);
				}
			}
		}
	} else if (ret == 2) {
		ShowInnoPU();
	}
}

function doShowInnoPU(_sizetype)
{
    if (ip_isActivePU == false) {
        alert('InnoPU - Please install the photo upload component first.');
        return;
    }

    isReadyInnoAP();

    if (ip_isActiveAP == false) {
        alert('InnoPU - Please run the additional function of the photo upload component.');
        return;
    }

	setModalSizeInnpPU(_sizetype);

	ShowInnoPU();
}

function setModalSizeInnpPU(_type)
{
	if (_type == 'small')
	{
		ip_ModalWidth = 820;
		ip_ModalHeight = 690;
	} else if (_type == 'medium') {
		ip_ModalWidth = 1000;
		ip_ModalHeight = 768;
	} else if (_type == 'big') {
		ip_ModalWidth = 1182;
		ip_ModalHeight = 930;
	} else if (_type == 'fullscreen') {
		ip_ModalWidth = window.screen.width;
		ip_ModalHeight = window.screen.height;
	}
}

function setThumbSizeInnoPU(_type)
{
	if (_type == 'bigger')
	{
        ip_ShowThumbnailWidth = 400;
        ip_ShowThumbnailHeight = 301;
	} else if (_type == 'big') {
        ip_ShowThumbnailWidth = 180;
        ip_ShowThumbnailHeight = 136;
	} else if (_type == 'normal') {
		ip_ShowThumbnailWidth = 139;
        ip_ShowThumbnailHeight = 105;
	}
}

function GetNameFromPath(path)
{
	var mark = '';
	var pos = '';

	if ((pos = path.lastIndexOf("\\")) != -1)
		mark = "\\";

	return path.substr(pos+1);
}
