

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function ImageUploader_PropertyUploadFileCountChange(){
	return;
    /*
    var imageUploader=getImageUploader("ImageUploader");
    for (i=imageUploader.getUploadFileCount(); i>=1; i--){
        if (imageUploader.getUploadFileHeight(i)/imageUploader.getUploadFileWidth(i) != 0.75){
            alert("This photo does not have a 4:3 ratio.\n\nSize examples:\n1600x1200\n1280x960\n1024x768\n800x600\n640x480");
            imageUploader.UploadFileRemove(i);
        }
    }*/
}

function ImageUploader_AgentUploadFileCountChange(){
	return;
	/*
    var imageUploader=getImageUploader("ImageUploader");
    for (i=imageUploader.getUploadFileCount(); i>=1; i--){
        if (imageUploader.getUploadFileWidth(i)/imageUploader.getUploadFileHeight(i) != 0.75){
            alert("This photo does not have a 3:4 ratio.\n\nSize examples:\n1200x1600\n960x1280\n768x1024\n600x800\n480x640");
            imageUploader.UploadFileRemove(i);
        }
    }*/
}


//This Progress event handler demonstrates an alternative way to 
//redirect upon upload (instead of RedirectUrl property).
function ImageUploader_PropertyProgress(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);
        */
	}
} 

function ImageUploader_AgentProgress(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")
        //var division = "bottomcontent";
        //var page = "modules/AdminProp/PropertyGenie.asp";
        //var data = "maindiv=" + division;
        //genericSubmit(page,data,null,null,division,completedSingleLoad,regularloadingstring);
        //Removed on 26-Oct-2007
        //navigateToPage('modules/agents/agentlogin.asp',fetchInputFormData('frmAgentImage'),'bottomcontent','TopOfBottom');
	}
} 

// Thumb Resize Settings
function ImageUploader_BeforePropertyUpload() {
	// Filmstrip Thumb 
	/*iu.addParam("UploadThumbnail1FitMode", "Fit");
	iu.addParam("UploadThumbnail1Width", "60");
	iu.addParam("UploadThumbnail1Height", "45");
	iu.addParam("UploadThumbnail1JpegQuality", "70");*/
	
	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "102", "66");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(1, "70");

	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "256", "174");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(2, "70");

	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "500", "333");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(3, "70");
	
	getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "140", "105");
	getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(3, "70");
}

function ImageUploader_BeforeAgentUpload() {
    //getImageUploader("ImageUploader").UploadThumbnailAdd("Fit", "105", "140");
    //Set the quality of the extra thumbnail
    //getImageUploader("ImageUploader").setUploadThumbnailJpegQuality(1, "70");
}

function ImageUploader_AfterUpload() 
{ 
	//function checkAction(actionID,compID,displayMode,formName,useCustomFunction,completionFunction,isModal)
	var PropID = document.getElementById("txtPROP_ID").value;	
	checkAction(57,152,1,"frmUpload",false,null,false);
	runImageUploader('property',PropID);
}
function runImageUploaderInPostLoad()
{
    var PropID = document.getElementById("txtPROP_ID").value;
    var property = "property";
    runImageUploader(property,PropID);

}
function runImageUploader(mode,id)
{

	//alert(1);
	//return;
	var MaxFileCount;
	var MessageMaxFileCountExceededText;
	var Action;
	var BeforeUpload;
	var Progress;
	var OutputDivision;
	var UploadFileCountChange;
	
	//Vars to use
	
	if (mode == "property"){
		if (parseInt(id) == 0) {
			id = document.getElementById("PropertyID");
		}
		//Setup property mode vars
		MaxFileCount = 10;
		MessageMaxFileCountExceededText = "You can not select more than 10 files.";
		//Action = "modules/AdminProp/propertyimageupload/propertyimageupload.asp?propertyid=" + id;
		Action = "/modules/CMS/modules/DataEntry/propertyimageupload/propertyimageupload.asp?propertyid=" + id;
		UploadFileCountChange = "ImageUploader_PropertyUploadFileCountChange";
		BeforeUpload = "ImageUploader_BeforePropertyUpload";
		AfterUpload = "ImageUploader_AfterUpload";
		Progress = "ImageUploader_PropertyProgress";
		OutputDivision = "propertyImageUploadContainer";
	}
	
	//alert("mode : " + mode + "\nid : " + id);
	
	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"); //IP c21
	//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"); // arabianescapes.com 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", "200");
	iu.addParam("MinImageHeight", "200");
	iu.addParam("DimensionsAreTooSmallText", "Size To Small");
	iu.addParam("MessageDimensionsAreTooSmallText", "Image size should be at least [MinImageWidth]x[MinImageHeight]" + " to get good quality.");
	// Aspect Ratio
	iu.addEventListener("UploadFileCountChange", UploadFileCountChange);
	// 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);

	

	//Add event handlers.
	iu.addEventListener("Progress", Progress);
	iu.addEventListener("AfterUpload", AfterUpload);


	//iu.writeHtml();
	//AJAX friendly output ;-)
	document.getElementById(OutputDivision).innerHTML = iu.getHtml();
}