
var ItemID;


//function loadImagePopup(filename) {
//popup = window.open("", "imagepopup", "width=560,height=420,scrollbars=0,menubar=0,resizable=0,status=0,location=0,toolbar=0");
//popup.document.write("<html><head><script type='text/javascript' src='../../imageuploadmodule.js'><script></head><body><div name='ImageUploadContainer'></div><script>runImageUploader(' + filename + ');<script></body></html>"); 
//}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


//This Progress event handler demonstrates an alternative way to 
//redirect upon upload (instead of RedirectUrl property).
function ImageUploader_Progress(Status, Progress, ValueMax, Value, StatusText){
	if (Status=="COMPLETE")	{   
	    //var page = "modules/AdminProp/Upload.asp"
        //var data = "maindiv=" + division
        //genericSubmit(page,data,null,null,division,completedSingleLoad,regularloadingstring);
        //window.location="modules/AdminProp/Areas.asp"
        //alert("done")
        //Removed on 26-Oct-2007
        /*
        var division = "bottomcontent";
        var page = "modules/AdminProp/PropertyGenie.asp";
        //var data = "maindiv=" + division;
        var data = fetchInputFormData('frmUpload');
        var postLoad = "window.location.hash = 'TopOfBottom'";
        genericSubmit(page,data,null,postLoad,division,completedSingleLoad,regularloadingstring);
        */
	}
	
} 

// Thumb Resize Settings
function ImageUploader_BeforeUpload() {
	
	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "160", "140");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(1, "70");

	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "580", "450");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(2, "70");

}


function ImageUploader_AfterUpload() 
{ 
	// CALL TO FRAMEWORK	
	//call function to load save and show new images with parameters (ItemID + '_160x140.jpg',  ItemID + '_580x450.jpg')
	
	
	//alert('upload done');
	
	document.getElementById("txtTempSImgPath").value = ItemID + '_160x140.jpg';
	document.getElementById("txtTempLImgPath").value = ItemID + '_580x450.jpg';
	
//	alert(document.getElementById("imgStock").src);
	
	document.getElementById("imgStock").src = '/modules/stock/images/temp/' + ItemID + '_160x140.jpg';
	
	//clears thicktab content
	document.getElementById('ImageUploadContainer').innerHTML = '';
	
	// removes thickbox
	tb_remove();
}

function runImageUploaderInPostLoad()
{

}

function runImageUploader(id)
{

	//return;
	var MaxFileCount;
	var MessageMaxFileCountExceededText;
	var Action;
	var BeforeUpload;
	var Progress;
	var OutputDivision;
	var UploadFileCountChange;
	
	//Vars to use
	
	ItemID = id;

	//Setup property mode vars
	MaxFileCount = 1;
	MessageMaxFileCountExceededText = "You can not select more than 1 file.";
	Action = "/modules/Stock/imageupload/imageupload.asp?Guid=" + id;
	BeforeUpload = "ImageUploader_BeforeUpload";
	AfterUpload = "ImageUploader_AfterUpload";
	Progress = "ImageUploader_Progress";
	OutputDivision = "ImageUploadContainer";

	var iu = new ImageUploaderWriter("ImageUploader",538,400);

	// Use Java only
	iu.javaAppletEnabled = true;
	iu.activeXControlEnabled = false;

	//For Java applet only path to directory with JAR files should be specified (without file name).
	iu.javaAppletCodeBase = "/include/commoncomponents/imageuploader/";
	iu.javaAppletCached = true;
	iu.javaAppletVersion = "2.5.4.0";

	// ... initialize params as described in the next topic ...

	// License Key
	
	//iu.addParam("LicenseKey", "6983-5928-7832-6631-80774"); //Demo?
	//iu.addParam("LicenseKey", "8645-6101-6980-7407"); //URL c21
	//iu.addParam("LicenseKey", "5578-7528-9998-5871"); //  arabianescapes.com
	//iu.addParam("LicenseKey", "6376-9203-9867-7887"); // arabianescapes.expertalliance.co.za
//	iu.addParam("LicenseKey", "7223-5976-5591-9191-82167"); // EA Live Server
//	iu.addParam("LicenseKey", "5894-5778-9570-5525-91391"); // EA Live Server New
	iu.addParam("LicenseKey", "8900-6000-6180-8308-57766"); // EA Live Server New - S.A


	// Append the form with total file size to the upload. This form containes the other values to POST
	// iu.addParam("AdditionalFormName", "Form1");

	//iu.addParam("PaneLayout", "ThreePanes");
	iu.addParam("FolderView", "Thumbnails");
	//iu.addParam("ShowButtons", "false");
	iu.addParam("FolderPaneHeight", "-1");


	// Configure appearance and behaviour.
	iu.addParam("PaneLayout", "TwoPanes");
	iu.addParam("ShowDebugWindow", "true");
	iu.addParam("ShowDescriptions", "false");
	iu.addParam("ShowDescriptions", "false");
	iu.addParam("AllowAutoRotate", "true");
	//iu.addParam("TreePaneBackgroundColor", "#e4ab01");
	//iu.addParam("FolderPaneBackgroundColor", "#e4ab01");
	//iu.addParam("UploadPaneBackgroundColor", "#e4ab01");
	
	
	//kelvin
	iu.addParam("BackgroundColor", "#000000");
		
	iu.addParam("TreePaneBackgroundColor", "#FFFFFF");
	iu.addParam("FolderPaneBackgroundColor", "#FFFFFF");
	iu.addParam("UploadPaneBackgroundColor", "#FFFFFF");

	//Configure custom buttons.
	iu.addParam("ButtonSendImageFormat",
				"Width=34;Height=20;UrlNormal=/include/commoncomponents/imageuploader/send_off.gif;UrlPressed=/include/commoncomponents/imageuploader/send_on.gif;UrlDisabled=/include/commoncomponents/imageuploader/send_off.gif");
	iu.addParam("ButtonSelectAllImageFormat",
				"Width=52;Height=20;UrlNormal=/include/commoncomponents/imageuploader/select_off.gif;UrlPressed=/include/commoncomponents/imageuploader/select_on.gif;UrlDisabled=/include/commoncomponents/imageuploader/select_off.gif");
	iu.addParam("ButtonDeselectAllImageFormat",
				"Width=64;Height=20;UrlNormal=/include/commoncomponents/imageuploader/deselect_off.gif;UrlPressed=/include/commoncomponents/imageuploader/deselect_on.gif;UrlDisabled=/include/commoncomponents/imageuploader/deselect_off.gif");
	    
	//Configure pane item styling.
	iu.addParam("PreviewThumbnailActiveColor", "#E4AB01");
	iu.addParam("PreviewThumbnailBorderColor", "#eeeeee");
	//end kelvin


	// Restrictions
	// File Count
	iu.addParam("MaxFileCount", MaxFileCount.toString());
	iu.addParam("MessageMaxFileCountExceededText", MessageMaxFileCountExceededText);
	// Size
	iu.addParam("MinImageWidth", "10");
	iu.addParam("MinImageHeight", "10");
	iu.addParam("DimensionsAreTooSmallText", "Size To Small");
	iu.addParam("MessageDimensionsAreTooSmallText", "Image size should be at least [MinImageWidth]x[MinImageHeight]" + " to get good quality.");
	// Other
	iu.addParam("UploadSourceFile", "false");
	iu.addParam("AllowRotate", "false");

	//This is used to setup image thumbnail refit sizes to specified dimensions
	iu.addEventListener("BeforeUpload", BeforeUpload);

	// Redirect to URL
	iu.addParam("Action", Action);
	
	//filetypes
	iu.addParam("FileMask", "*.jpg;*.jpeg;*.jpe;*.bmp;*.gif");

	//Add event handlers.
	iu.addEventListener("Progress", Progress);
	iu.addEventListener("AfterUpload", AfterUpload);
	
	
	//original output
	//iu.writeHtml();

	//AJAX friendly output ;-)
	document.getElementById(OutputDivision).innerHTML = iu.getHtml();
}
