/*!
**********************************************************************
@file WizardError1.js

Copyright 2003-2008 Adobe Systems Incorporated.                     
All Rights Reserved.                                                
                                                                    
NOTICE: All information contained herein is the property of Adobe   
Systems Incorporated.                                                                                                                    

***********************************************************************
*/
/*
WizardError1 for reporting any WizardError screens.
*/

function WizardError1(inSession, inTitle, inBody, buttonsArray, type, subTitle)
{
	try
	{
		if(inSession)
			this.session = inSession;
		else
		{
            this.LogError("Installer Session needs to be passed to WizardError1, trying out gWizardControl.session as alternative!");			
            //alert("Installer Session needs to be passed to WizardError1, trying out gWizardControl.session as alternative!");
			this.session = gWizardControl.session;
		    if(!this.session)
		    {
		        if(gWizardControl)
		            gWizardControl.NavQuit();
		        else
		        {
		            alert("Critical errors were found in setup");  
		        }
		    }
		}
		if (!this.errorTemplate)
		{
			var errorPathArray = new Array(this.session.GetResourcesPath(), "/common/error/error.html");
			var errorPath = _concatPaths(errorPathArray, this.session.GetDefaultProperties().platform);
			var errorContents = this.session.LoadFile(errorPath);
			this.errorTemplate = errorContents.data;	
		}

		if (!this.errorTemplate || this.errorTemplate.length <= 0)
		{
			throw "Unable to load error.html";
		}

		var systemInfo = this.session.systemInfo;
		var currentPlatform = systemInfo.Macintosh ? "Mac" : "Win";

		//correct path to css via code
		var cssURLArray;
		if(currentPlatform=="Win")
		{
		    cssURLArray =  new Array(this.session.GetResourcesPath(), "common", "error", "error_win");
		}
		else
		{
		    cssURLArray =  new Array(this.session.GetResourcesPath(), "common", "error", "error_mac");
		}
		var cssURL = "file://" + _concatPaths(cssURLArray, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_CSS",cssURL);
		
		//correct path to js via code
		var jsURLArray_1 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardButton1");
		var jsURL_1 = "file://" + _concatPaths(jsURLArray_1, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS1",jsURL_1);
		
		//correct path to js via code
		var jsURLArray_2 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardImage1");
		var jsURL_2 = "file://" + _concatPaths(jsURLArray_2, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS2",jsURL_2);

		//correct path to js via code
		var jsURLArray_3 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardWidget1");
		var jsURL_3 = "file://" + _concatPaths(jsURLArray_3, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS3",jsURL_3);

		//correct path to js via code
		var jsURLArray_4 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardReverseDisplay1");
		var jsURL_4 = "file://" + _concatPaths(jsURLArray_4, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS4",jsURL_4);

		//correct path to js via code
		var jsURLArray_5 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardAccessibilityManager1");
		var jsURL_5 = "file://" + _concatPaths(jsURLArray_5, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS5",jsURL_5);
		//END OF JS REPLACE AREA

		if(gSession.languagertl)
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_LANGUAGE_RTL","true");
		else
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_LANGUAGE_RTL","false");

		var imagefolderArray =  new Array(this.session.GetResourcesPath(), "media", "img");
		var imagefolderURL = "file://" + _concatPaths(imagefolderArray, this.session.GetDefaultProperties().platform)+"/";
		
		if(currentPlatform=="Win")
		{
			imagefolderURL = imagefolderURL.replace(/\\\\/g, "//");
			imagefolderURL = imagefolderURL.replace(/\\+/g, "/");
		}
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE_FOLDER",imagefolderURL);
		
		var myregexp_gq = new RegExp("_REPLACE_AREA_OS_PLATFORM", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp_gq,currentPlatform);
		/*this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_OS_PLATFORM",currentPlatform);g*/
		
		if(type=="error")
		{
			var imageURLArray =  new Array(this.session.GetResourcesPath(), "media", "img", "redx_big.png");
			var imageURL = "file://" + _concatPaths(imageURLArray, this.session.GetDefaultProperties().platform);
			if(currentPlatform=="Win")
			{
				imageURL = imageURL.replace(/\\+/g, "/");
			}
			//this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE","<img src='"+imageURL+"'></img>");
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE",imageURL);
		}
		else
		{
			var imageURLArray =  new Array(this.session.GetResourcesPath(), "media", "img", "yellow_exclaim_big.png");
			var imageURL = "file://" + _concatPaths(imageURLArray, this.session.GetDefaultProperties().platform);
			if(currentPlatform=="Win")
			{
				imageURL = imageURL.replace(/\\+/g, "/");
			}
			//this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE","<img src='"+imageURL+"'></img>");
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE",imageURL);
		}
		
		var imageURLArray1 =  new Array(this.session.GetResourcesPath(), "media", "img", "panel_divider.png");
		var imageURL1 = "file://" + _concatPaths(imageURLArray1, this.session.GetDefaultProperties().platform);
		if(currentPlatform=="Win")
		{
			imageURL1 = imageURL1.replace(/\\+/g, "/");
		}
		var myregexp = new RegExp("_REPLACE_AREA_RULER", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp,imageURL1);

		myregexp = new RegExp("_REPLACE_JAWS_IS_RUNNING", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp, this.session.IsJawsRunning() ? "true" : "false");

		var myregexp1 = new RegExp("_REPLACE_AREA_TITLE", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp1, inTitle);
		var myregexp2 = new RegExp("_REPLACE_AREA_SUB_TITLE", "g");
		if ((subTitle == null) || (subTitle == ""))
			subTitle = inTitle;
		this.errorTemplate = this.errorTemplate.replace(myregexp2,subTitle);
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_BODY",inBody);

		var buttonarea=null;
		var allbuttonz="";
		for(var i=0;i<buttonsArray.length;i++)
		{
			var eachWB = buttonsArray[i];
			allbuttonz+="{"
						+"label:'"
						//+inSession.localization.GetString("loc"+eachWB.label, eachWB.label)
						+eachWB.label
						+"',"
						+"left:'"+eachWB.left+"',"
						+"top:'"+eachWB.top+"',"
						+"returnCode:'"+eachWB.returnCode+"',"
						+"hotkey:'"+eachWB.hotkey+"',"
						+"defaultOption:'"+eachWB.defaultOption+"'"
							+"}";
			if(i<(buttonsArray.length-1))
			{
				allbuttonz+=",";
			}
		}
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_BUTTONZ",allbuttonz);
		return this.session.UIShowModalAlert(this.errorTemplate);
	}
	catch(ex)
	{
		alert(inBody);
	}
}

function WizardInformation(inSession, inTitle, subTitle, inBody, buttonsArray, errorBody)
{
	try
	{
		if(inSession)
			this.session = inSession;
		else
		{
            this.LogError("Installer Session needs to be passed to WizardError1, trying out gWizardControl.session as alternative!");			
            //alert("Installer Session needs to be passed to WizardError1, trying out gWizardControl.session as alternative!");
			this.session = gWizardControl.session;
		    if(!this.session)
		    {
		        if(gWizardControl)
		            gWizardControl.NavQuit();
		        else
		        {
		            alert("Critical errors were found in setup");  
		        }
		    }
		}
		if (!this.errorTemplate)
		{
			var errorPathArray = new Array(this.session.GetResourcesPath(), "/common/info/info.html");
			var errorPath = _concatPaths(errorPathArray, this.session.GetDefaultProperties().platform);
			var errorContents = this.session.LoadFile(errorPath);
			this.errorTemplate = errorContents.data;	
		}

		if (!this.errorTemplate || this.errorTemplate.length <= 0)
		{
			throw "Unable to load error.html";
		}

		var systemInfo = this.session.systemInfo;
		var currentPlatform = systemInfo.Macintosh ? "Mac" : "Win";
		//correct path to css via code
		var cssURLArray;

		if(currentPlatform=="Win")
		{
		    cssURLArray =  new Array(this.session.GetResourcesPath(), "common", "info", "info_win");
		}
		else
		{
		    cssURLArray =  new Array(this.session.GetResourcesPath(), "common", "info", "info_mac");
		}
		var cssURL = "file://" + _concatPaths(cssURLArray, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_CSS",cssURL);
		
		//correct path to js via code
		var jsURLArray_1 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardButton1");
		var jsURL_1 = "file://" + _concatPaths(jsURLArray_1, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS1",jsURL_1);
		
		//correct path to js via code
		var jsURLArray_2 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardImage1");
		var jsURL_2 = "file://" + _concatPaths(jsURLArray_2, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS2",jsURL_2);

		//correct path to js via code
		var jsURLArray_3 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardWidget1");
		var jsURL_3 = "file://" + _concatPaths(jsURLArray_3, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS3",jsURL_3);

		//correct path to js via code
		var jsURLArray_4 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardReverseDisplay1");
		var jsURL_4 = "file://" + _concatPaths(jsURLArray_4, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS4",jsURL_4);

		//correct path to js via code
		var jsURLArray_5 =  new Array(this.session.GetResourcesPath(), "scripts", "WizardAccessibilityManager1");
		var jsURL_5 = "file://" + _concatPaths(jsURLArray_5, this.session.GetDefaultProperties().platform);

		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_JS5",jsURL_5);
		//END OF JS REPLACE AREA

		if(gSession.languagertl)
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_LANGUAGE_RTL","true");
		else
			this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_LANGUAGE_RTL","false");

		var imagefolderArray =  new Array(this.session.GetResourcesPath(), "media", "img");
		var imagefolderURL = "file://" + _concatPaths(imagefolderArray, this.session.GetDefaultProperties().platform)+"/";

		if(currentPlatform=="Win")
		{
			imagefolderURL = imagefolderURL.replace(/\\+/g, "/");
		}
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_IMAGE_FOLDER",imagefolderURL);

		var myregexp_gq = new RegExp("_REPLACE_AREA_OS_PLATFORM", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp_gq,currentPlatform);
		/*this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_OS_PLATFORM",currentPlatform);g*/
		
		var imageURLArray1 =  new Array(this.session.GetResourcesPath(), "media", "img", "panel_divider.png");
		var imageURL1 = "file://" + _concatPaths(imageURLArray1, this.session.GetDefaultProperties().platform);
		if(currentPlatform=="Win")
		{
			imageURL1 = imageURL1.replace(/\\+/g, "/");
		}
		var myregexp = new RegExp("_REPLACE_AREA_RULER", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp,imageURL1);
		myregexp = new RegExp("_REPLACE_JAWS_IS_RUNNING", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp, this.session.IsJawsRunning() ? "true" : "false");
		var myregexp1 = new RegExp("_REPLACE_AREA_TITLE", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp1,inTitle);
		var myregexp2 = new RegExp("_REPLACE_AREA_SUB_TITLE", "g");
		if ((subTitle == null) || (subTitle == ""))
			subTitle = inTitle;
		this.errorTemplate = this.errorTemplate.replace(myregexp2,subTitle);

		var buttonarea=null;
		var allbuttonz="";
		for(var i=0;i<buttonsArray.length;i++)
		{
			var eachWB = buttonsArray[i];
			allbuttonz+="{"
						+"label:'"
						//+inSession.localization.GetString("loc"+eachWB.label, eachWB.label)
						+eachWB.label
						+"',"
						+"left:'"+eachWB.left+"',"
						+"top:'"+eachWB.top+"',"
						+"returnCode:'"+eachWB.returnCode+"',"
						+"hotkey:'"+eachWB.hotkey+"',"
						+"defaultOption:'"+eachWB.defaultOption+"'"
							+"}";
			if(i<(buttonsArray.length-1))
			{
				allbuttonz+=",";
			}
		}
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_BUTTONZ",allbuttonz);
		this.errorTemplate = this.errorTemplate.replace("_REPLACE_AREA_BODY",inBody);

		var myregexp3 = new RegExp("_REPLACE_AREA_ERROR", "g");
		this.errorTemplate = this.errorTemplate.replace(myregexp3, errorBody);

		return this.session.UIShowModalAlert(this.errorTemplate);
	}
	catch(ex)
	{
		alert(inBody);
	}
}
