/*!
**********************************************************************
@file Welcome.js

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

***********************************************************************
*/

function Welcome_wp(inController)
{
	this.SetController(inController);
	
	this.doubleDown = false;
	this.doubleUp = false;
	
	this.modeBox = null;	
	
	this.mustProvideSerial = false;
	
	this.serialNumberValid = "0";
	this.serialNumberOutput = "";
	this.serialNumber = "";	
	
	this.UpgradeSerialNumber = "";
	this.UpgradeSerialNumber2 = "";
	
	this.ProductSelected1 = "";
	this.ProductSelected2 = "";
	
	this.serialIcon = null;
	this.upgradeSN2Icon = null;
	this.upgradeSN1Icon = null;
	
	this.isUpgradeValid = "";
	this.completedUpgradePass = "";
	this.continueUpgradePass = "";
	
	this.arrSNElements = new Array("personalization_SN1", "personalization_SN2", "personalization_SN3", "personalization_SN4", "personalization_SN5", "personalization_SN6");
	this.bSetFocusOnSNElement = true;
	
	this.wizardControl.session.properties["UPGRADEQUALSN"] = "";
}

Welcome_wp.prototype = new WizardPage("Welcome");

Welcome_wp.prototype.GetPageTitleDisplayName = function()
{
	return this.localization.GetString("locTitle", "Welcome");
}

Welcome_wp.prototype.GetNavDisplayName = function()
{
	return this.localization.GetString("locNavTitle", "Welcome");
}

Welcome_wp.prototype.onSwitchTo = function()
{
	if(this.wizardControl.session.needsValidSerialization)
	{
		this.PayloadsToCheck = new Array();
		var driverPayload = this.wizardControl.session.GetDriverPayload();
		if(driverPayload)
		    this.PayloadsToCheck.push(driverPayload.AdobeCode);
	}
	// Participate if the session requires serialization
	return (true == this.wizardControl.session.needsValidSerialization); 
}

Welcome_wp.prototype.handleSerialRadio = function()
{
	var doClearWhenDone = false;
	if (this.wizTrialRadio.GetRadioState() == kRadioStateOn)
	{
		doClearWhenDone = true;
	}
	
	this.wizSerialRadio.SetRadioState(kRadioStateOn);

	// Check number and set serial output
	this.updateSerialCheckStatus();
	// Set focus on edit control if they dont have
	this.getElementById(this.arrSNElements[0]).focus(); // Set focus on 1st edit control
	this.getElementById(this.arrSNElements[0]).select();

	if (doClearWhenDone)
	{
		this.errorbox.Clear();
		this.errorbox.ShowHide();
	}
}


Welcome_wp.prototype.handleTrialRadio = function()
{
    this.wizTrialRadio.SetRadioState(kRadioStateOn);

	this.serialNumberOutput = "";
	this.serialNumber = "";	
	this.serialNumberValid = "0";
	
	this.serialIcon.Hide();
	
	this.getElementById("pers_EPIC_SERIAL").value = "";
	
	if (this.wizardControl.session.properties["pers_EPIC_SERIAL"])
		delete this.wizardControl.session.properties["pers_EPIC_SERIAL"];
	
	this.errorbox.Clear();
	this.errorbox.ShowHide();
	this.wizardControl.session.aflLanguage = kMultiLingualIsoCode;
}

Welcome_wp.prototype.FillButtonArea = function()
{
	var buttonarea = document.getElementById("navButtons");
	var thisPage = this;
	
	var cancelWB = new WizardButton1(8, "c", this.wizardControl.session.localization.GetString("locBtnQuit", "Quit"), 
		"128px", "32px", "258px", "16px","bigbutton_normalsize", buttonarea, function(){thisPage.wizardControl.NavCancel();});
	
	var nextWB = new WizardButton1(9, "n", this.wizardControl.session.localization.GetString("locBtnNext", "Next"), 
		"128px", "32px", "400px", "16px","bigbutton_normalsize", buttonarea, function(){thisPage.wizardControl.NavNext();});
	
	var backWB = new WizardButton1(10, "b", this.wizardControl.session.localization.GetString("locBtnBack", "Back"), 
		"128px", "32px", "258px", "16px","bigbutton_normalsize", buttonarea, function(){thisPage.onBack();});
	
	this.cancelWB = cancelWB;
	this.nextWB = nextWB;
	this.backWB = backWB;
	
	this.backWB.Hide();
}

Welcome_wp.prototype.RenderInitialWizardImagesOfPage = function()
{
	this.serialIcon = new WizardImage1(kImgIconCheckMedium, "serialIcon", "serialIcon", this.getElementById("locPerSerial"));
	this.serialIcon.GetRawImageStyle().verticalAlign = "middle";
	this.upgradeSN1Icon = new WizardImage1(kImgIconCheckMedium, "upgradeSN1Icon", "upgradeSN1Icon", this.getElementById("locUpgradeSerialEntry11"));
	this.upgradeSN2Icon = new WizardImage1(kImgIconCheckMedium, "upgradeSN2Icon", "upgradeSN2Icon", this.getElementById("locUpgradeSerialEntry22"));
	this.upgradeSN1Icon.GetRawImageStyle().verticalAlign = "middle";
	this.upgradeSN1Icon.GetRawImageStyle().verticalAlign = "middle";
}

Welcome_wp.prototype.CreateWAMPage = function()
{
	if (this.wizardControl.WAM)
	{
		this.wizardControl.WAM.AddElementSet	([
							//{element:_,hotkey:_,focal:_,nofocal:_,type:_},
							{element:this.getElementById("welcomeHeader"),virtualtype:'ReadableText',jawslabel:'Press Alt Plus S For Serial Mode. Press Alt Plus T For Trial Mode. Press Alt Plus N For Next Button. Press Alt Plus Q For Quit Button.'},
							{element:this.wizSerialRadio.GetDisplayElement(),hotkey:'S',virtualtype:'WizardRadioButton1',jawslabel:this.getElementById("labelSerialRadio").innerText+', Serial Mode Radio Button.'},
							{element:this.getElementById("labelSerialRadio"),virtualtype:'ReadableText'},
							{element:this.getElementById("personalization_SN1"),hotkey:'1',virtualtype:'InputField'},
							{element:this.getElementById("personalization_SN2"),hotkey:'2',virtualtype:'InputField'},
							{element:this.getElementById("personalization_SN3"),hotkey:'3',virtualtype:'InputField'},
							{element:this.getElementById("personalization_SN4"),hotkey:'4',virtualtype:'InputField'},
							{element:this.getElementById("personalization_SN5"),hotkey:'5',virtualtype:'InputField'},
							{element:this.getElementById("personalization_SN6"),hotkey:'6',virtualtype:'InputField'},
							{element:this.getElementById("serialInstuctionText"),virtualtype:'ReadableText'},
							{element:this.wizTrialRadio.GetDisplayElement(),hotkey:'T',virtualtype:'WizardRadioButton1',jawslabel:this.getElementById("localLabelTrialRadio").innerText+', Trial Mode Radio Button.'},
							{element:this.getElementById("localLabelTrialRadio"),virtualtype:'ReadableText'},
							{element:this.getElementById("trialInstructionText1"),virtualtype:'ReadableText'},
							{element:this.getElementById("trialInstructionText2"),virtualtype:'ReadableText'},
							{element:this.getElementById("upgradeSNHeader"),virtualtype:'ReadableText',jawslabel:'Press Alt Plus B For Back Button. Press Alt Plus N For Next Button.'},
							{element:this.getElementById("upgradeSNContent"),virtualtype:'ReadableText'},
							{element:this.getElementById("locUpgradeSNProductname1"),virtualtype:'ReadableText'},
							{element:this.getElementById("upgradeProductList1Select"),hotkey:'U',virtualtype:'ListBox'},
							{element:this.getElementById("locUpgradeSNSerial1"),virtualtype:'ReadableText'},
							{element:this.getElementById("upgrade1_SN1"),hotkey:'V',virtualtype:'InputField'},
							{element:this.getElementById("locUpgradeSNProductname2"),virtualtype:'ReadableText'},
							{element:this.getElementById("upgradeProductList2Select"),hotkey:'W',virtualtype:'ListBox'},
							{element:this.getElementById("locUpgradeSNSerial2"),virtualtype:'ReadableText'},
							{element:this.getElementById("upgrade1_SN2"),hotkey:'X',virtualtype:'InputField'},
							{element:this.cancelWB.GetDisplayElement(),hotkey:'Q',virtualtype:'WizardButton1'},
							{element:this.backWB.GetDisplayElement(),hotkey:'B',virtualtype:'WizardButton1'},
							{element:this.nextWB.GetDisplayElement(),hotkey:'N',virtualtype:'WizardButton1'}
						]);
		this.wizardControl.WAM.SetPageDefaultEnterElement(this.nextWB.GetDisplayElement());
		this.wizardControl.WAM.SetPageDefaultFocusElement(this.nextWB.GetDisplayElement());
		this.wizardControl.WAM.SetPageDefaultEscapeElement(this.cancelWB.GetDisplayElement());
		this.wizardControl.WAM.SetFocusOnDefaultElement();
	}
}

Welcome_wp.prototype.onShow = function()
{
	this.ClearButtonArea();
	this.FillButtonArea();
	
	this.setWindowTitle();	
	this.wizardControl.session.UISetCloseBoxEnabled(1);	
	
	var leftWelcomeContent = this.getElementById("left_Welcome");
	var rightWelcomeContent = this.getElementById("right_Welcome");
	
	var leftUpgradeContent = this.getElementById("left_UpgradeSN");
	var rightUpgradeContent = this.getElementById("right_UpgradeSN");
	
	leftWelcomeContent.style.display = "block";
	rightWelcomeContent.style.display = "block";
				
	leftUpgradeContent.style.display = "none";
	rightUpgradeContent.style.display = "none";
	
	this.backWB.Hide();
	
	this.upgradeSN2Icon.SetWidth("20");
	this.upgradeSN2Icon.SetSrc(kImgIconCriticalMedium);
	this.upgradeSN2Icon.Hide();
	
	this.upgradeSN1Icon.SetWidth("20");
	this.upgradeSN1Icon.SetSrc(kImgIconCriticalMedium);
	this.upgradeSN1Icon.Hide();
	
	this.getElementById("upgrade1_SN1").value = "";
	this.getElementById("upgrade1_SN2").value= "";
	this.getElementById("upgradeProductList1Select").disabled = false;
	this.getElementById("upgrade1_SN1").disabled = false;
	

	// For Greek Mac we reduce the width of right frame
        var systemInfo = gSession.systemInfo;
        var currentPlatform = systemInfo.Macintosh ? "Mac" : "Win";
	if(currentPlatform=="Mac" && gSession.Rlanguage=="el_GR")
	{
           rightWelcomeContent.style.width="290px";
        }


	if(gSession.languagertl)
	{
                  this.getElementById("locPerSerial").ignore=true;
		  this.getElementById("locUpgradeSerialEntry11").ignore=true;
		  var toChange = true;
	 	  if(gSession.reversedpage[this.pageName])
                  {	
			toChange = false;
                  }			
	}
	
	this.AutoReverseRTLOnce();
	this.ConfigureAutoReverseRTL();
	this.AutoReverseRTL();
	this.CreateWAMPage();
	if(gSession.languagertl)
	{
		rightWelcomeContent.style.left="-40px";
		leftUpgradeContent.style.left="0px";
		rightUpgradeContent.style.left="0px";
		if (toChange)
		{
			this.backWB.mainelement.style.left="400px";
			this.backWB.label.style.left="50px";
		}
		this.getElementById("upgradeProduct1SelectSpan").dir="ltr";
		this.getElementById("upgradeProduct2SelectSpan").dir="ltr";
	}

	if (this.wizSerialRadio.GetRadioState() == kRadioStateOn)
	{
		if (this.wizardControl.WAM) // If WAM is running, call WAM APIs to set/get focus element
			this.wizardControl.WAM.SetFocusElement(this.getElementById(this.arrSNElements[0]));
		else
			this.getElementById(this.arrSNElements[0]).focus();
		this.getElementById(this.arrSNElements[0]).select();
	}
	// Place correct icon next to the SN fields
	if (this.serialNumberValid == "1" && this.wizSerialRadio.GetRadioState() == kRadioStateOn)
	{
		this.ShowHideSerialNumberIcon(this.serialIcon, true, true);
	}
	else if (this.serialNumberValid != "1" && this.wizSerialRadio.GetRadioState() == kRadioStateOn && this.serialNumber.length == 24)
	{
		this.ShowHideSerialNumberIcon(this.serialIcon, true, false);
	}
	else
	{
		this.serialIcon.Hide();
	}
	
	return true;
}

Welcome_wp.prototype.onBack = function()
{
	// Assuming we are already on the upgrade SN entry page
	// Go back to Welcome screen
	var leftWelcomeContent = this.getElementById("left_Welcome");
	var rightWelcomeContent = this.getElementById("right_Welcome");
	
	var leftUpgradeContent = this.getElementById("left_UpgradeSN");
	var rightUpgradeContent = this.getElementById("right_UpgradeSN");
		
	leftWelcomeContent.style.display = "block";
	rightWelcomeContent.style.display = "block";
	
	leftUpgradeContent.style.display = "none";
	rightUpgradeContent.style.display = "none";
	var upgradeProductList1Select = this.getElementById("upgradeProductList1Select");
	if (upgradeProductList1Select)
	{
		if (upgradeProductList1Select.hasChildNodes() == true)
		{
			var optionlist = upgradeProductList1Select.childNodes;
			var count=optionlist.length;
			for( var x =0 ; x < count; x++)        	    			
			{
			  var childobj=optionlist.item(0);
			  upgradeProductList1Select.removeChild(childobj);
			}
		}
	}

	var upgradeProductList2Select = this.getElementById("upgradeProductList2Select");
	if ( upgradeProductList2Select) 
	{
		if (upgradeProductList2Select.hasChildNodes() == true)
		{
			var optionlist2 = upgradeProductList2Select.childNodes;
			var count=optionlist2.length;
			for( var x =0 ; x < count; x++)        	    			
			{
			  var childobj2=optionlist2.item(0);
			  upgradeProductList2Select.removeChild(childobj2);
			}
		}
	}
	this.getElementById("upgrade1_SN1").value = "";
	this.getElementById("upgrade1_SN2").value = "";
	
	this.upgradeSN2Icon.SetWidth("24");
	this.upgradeSN2Icon.SetSrc(kImgIconCheckMedium);
	this.upgradeSN2Icon.Hide();
	
	this.upgradeSN1Icon.SetWidth("24");
	this.upgradeSN1Icon.SetSrc(kImgIconCheckMedium);
	this.upgradeSN1Icon.Hide();
	
	this.completedUpgradePass = "";
	this.continueUpgradePass = "";
	this.completedUpgradePass = "";
	this.continueUpgradePass = "";
	this.getElementById("upgradeProductList1Select").disabled=false;
	this.getElementById("upgrade1_SN1").disabled=false;
	
	this.backWB.Hide();
	this.cancelWB.Show();
	// We are showing same page with defferent layout, so announce JAWS page message.
	if (this.wizardControl.WAM)
		this.wizardControl.WAM.AnnouncePageMeesage();
}

Welcome_wp.prototype.updateSerialNumber = function()
{
	this.serialNumber = "";
	
	for (var i=0; i < this.arrSNElements.length; i++)
		this.serialNumber += this.getElementById(this.arrSNElements[i]).value;
}

Welcome_wp.prototype.updateSerialCheckStatus = function()
{
	this.updateSerialNumber();
	this.serialNumberValid = "0";
	this.serialNumberUpgrade = "0";
	this.serialNumberUpsell="0";
	this.serialNumberUpdate="0";

	if (this.serialNumber.length == 24)
	{	
		var serialResults = null;
		
		// Try to validate the serial number entered against the driver SIF
		if (this.PayloadsToCheck && this.PayloadsToCheck[0])
		{
			serialResults = this.wizardControl.session.IsValidSerialNumberForAdobeCode(this.PayloadsToCheck[0], this.serialNumber);
		}
		
		if (serialResults) 
		{
			var bSupported = false;       
			if(serialResults.locale)
			{
				this.wizardControl.session.aflLanguage = serialResults.locale;
				if(serialResults.locale != kMultiLingualIsoCode)
				{			       
					var langList = this.wizardControl.session.GetSupportedLanguagesArray();				       
					//Check if this language is in supported langugages
					if(langList)
					{
						for(var indx = 0; indx < langList.length; ++indx)
						{
							if(langList[indx] == serialResults.locale)
							{
								bSupported = true;			                    
								break;
							}
						}
					}
				}
				else
				{
					 bSupported = true;
				}			    
			}
	   
			if ( bSupported)
			{
				if (null == serialResults["_error"] || "0" == serialResults["_error"]) {
					this.serialNumberOutput = serialResults["serialOutput"];
					this.serialNumberValid = serialResults["isValid"];
					this.serialNumberUpgrade = serialResults["isUpgrade"];
					this.serialNumberUpsell = serialResults["isUpsell"];
					this.serialNumberUpdate = serialResults["isUpdate"];
					
					// If it is an upgrade serial number, populate the upgrade products list dropdown
					if( (this.serialNumberUpgrade && this.serialNumberUpgrade == "1") || (this.serialNumberUpdate && this.serialNumberUpdate == "1") || (this.serialNumberUpsell && this.serialNumberUpsell == "1") )
					{
						if(serialResults["UpgradeProducts"])
						{
							this.serialNumberUpgradeCount = parseInt(serialResults["UpgradeProducts"].count);
							this.serialNumberUpgradeProducts = new Array();
							for (var i = 1; i <= this.serialNumberUpgradeCount; i++)
							{
								this.serialNumberUpgradeProducts.push(serialResults["UpgradeProducts"][i]);
							}
						}
					}
				}
			}
		}
	}
	else
	{
		this.serialIcon.Hide();
	}
	
	var selected_pe = this.getElementById("pers_EPIC_SERIAL");
	
	// Valid serial number detected
	if (("1" == this.serialNumberValid) && (this.wizSerialRadio.GetRadioState() == kRadioStateOn))
	{
		selected_pe.value = this.serialNumberOutput;
		this.wizardControl.session.properties["pers_EPIC_SERIAL"] = this.serialNumberOutput;
		this.ShowHideSerialNumberIcon(this.serialIcon, true, true);
		this.errorbox.Clear();
		this.errorbox.ShowHide();
	}
	// Invalid serial number
	else if ((this.mustProvideSerial || (this.serialNumber.length > 0)) && (this.wizSerialRadio.GetRadioState() == kRadioStateOn))
	{
		if (this.serialNumber.length == 24)
		{
			this.ShowHideSerialNumberIcon(this.serialIcon, true, false);
		}
		else
		{
			this.serialIcon.Hide();
		}
		selected_pe.value = "";
		if (this.wizardControl.session.properties["pers_EPIC_SERIAL"])
			delete this.wizardControl.session.properties["pers_EPIC_SERIAL"];
		this.errorbox.Clear();
		this.errorbox.AddError("critical", this.localization.GetString("locPerError", "You have entered an invalid serial number.  Please re-enter a valid serial number and try again."));
	} 
	// Trial option chosen. Clear the serialization data
	else
	{
		selected_pe.value = "";
		if (this.wizardControl.session.properties["pers_EPIC_SERIAL"])
			delete this.wizardControl.session.properties["pers_EPIC_SERIAL"];
	}

	// Serialization is a dynamic intrinsic constraint so re-compute those now.
	this.wizardControl.session.PayloadPolicyRefresh();
}

Welcome_wp.prototype.ShowHideSerialNumberIcon = function(serialNumberIcon, bShow, bChecked)
{
	if (bShow) {
		if (bChecked) {
			serialNumberIcon.SetWidth("24");
			serialNumberIcon.SetSrc(kImgIconCheckMedium);
		}
		else {
			serialNumberIcon.SetWidth("20");
			serialNumberIcon.SetSrc(kImgIconCriticalMedium);
		}
		serialNumberIcon.Show("inline");
	}
	else {
		serialNumberIcon.Hide();
	}
}

Welcome_wp.prototype.UpgradeSerialCheckStatus = function(bNextButtonPressed)
{
	var upgradeResults = null;

	this.upgradeSN2Icon.Hide();
	this.upgradeSN1Icon.Hide();
	this.UpgradeSerialNumber = "";
	this.UpgradeSerialNumber2 = "";
	this.ProductSelected1 = "";
	this.ProductSelected2 = "";
	this.UpgradeSerialNumber = this.getElementById("upgrade1_SN1").value;
	this.UpgradeSerialNumber2= this.getElementById("upgrade1_SN2").value;
	this.ProductSelected1 = this.getElementById("upgradeProductList1Select").value;
	this.ProductSelected2 = this.getElementById("upgradeProductList2Select").value;
	if (this.PayloadsToCheck && this.PayloadsToCheck[0])
	{
		upgradeResults = this.wizardControl.session.IsUpgradeValidSerialNumberForAdobeCode(this.PayloadsToCheck[0],this.serialNumber,this.UpgradeSerialNumber,this.UpgradeSerialNumber2,this.ProductSelected1, this.ProductSelected2);				
	}
	this.isUpgradeValid = upgradeResults["isUpgradeValid"];
	this.completedUpgradePass = upgradeResults["completedUpgradePass"];
	this.continueUpgradePass = upgradeResults["continueUpgradePass"];

	if (("1" == this.continueUpgradePass ) && ("0" == this.completedUpgradePass) && ("0" ==  this.isUpgradeValid )) 
	{
		var upgrade2SelectDiv=this.getElementById("upgrade2SelectDiv");
		var upgrade2EditDiv=this.getElementById("upgrade2EditDiv");	

		upgrade2SelectDiv.style.display = "block";
		upgrade2EditDiv.style.display = "block";
		this.wizardControl.session.UIShowWindow(1); // On Safari 3.1.1 elements are not drawn, this will force frameview to be redrawn Bug#1782889
		this.ShowHideSerialNumberIcon(this.upgradeSN1Icon, true, true);
		var upgradeProductList2Select = this.getElementById("upgradeProductList2Select");

		if (upgradeProductList2Select.hasChildNodes() == true)
		{
			var optionlist2 = upgradeProductList2Select.childNodes;
			var count=optionlist2.length;
			for( var x =0 ; x < count; x++)
			{
				var childobj2=optionlist2.item(0);
				upgradeProductList2Select.removeChild(childobj2);
			}
		}
		if(this.serialNumberUpgradeProducts)
		{
			for (var i = 0; i < this.serialNumberUpgradeProducts.length; i++)
			{
				var option = document.createElement("option");
				option.appendChild(document.createTextNode(this.serialNumberUpgradeProducts[i]));
				option.value = this.serialNumberUpgradeProducts[i];
				if( option.value != this.getElementById("upgradeProductList1Select").value)
					upgradeProductList2Select.appendChild(option);
			}
			this.getElementById("upgradeProductList1Select").disabled=true;
			this.getElementById("upgrade1_SN1").disabled=true;
		}
	}
	else
	{
		var upgradeProductList2Select = this.getElementById("upgradeProductList2Select");
		if (upgradeProductList2Select.hasChildNodes() == true)
		{
			var optionlist2 = upgradeProductList2Select.childNodes;
			var count=optionlist2.length;
			var upgradeProductList1Select = this.getElementById("upgradeProductList1Select");
			var optionlist1 = upgradeProductList1Select.childNodes;
			var count1=optionlist1.length;
			var bValidUpgradeSerialEntered = ("1" == this.completedUpgradePass ) || ("1" ==  this.isUpgradeValid);
			if( count == count1 - 1 )
			{
				this.ShowHideSerialNumberIcon(this.upgradeSN2Icon, bValidUpgradeSerialEntered || bNextButtonPressed,
					bValidUpgradeSerialEntered)
				this.ShowHideSerialNumberIcon(this.upgradeSN1Icon, true, true);
			}
			else
			{
				this.ShowHideSerialNumberIcon(this.upgradeSN1Icon, bValidUpgradeSerialEntered || bNextButtonPressed,
					bValidUpgradeSerialEntered)
			}
		}
	}
}

Welcome_wp.prototype.onUpgradeSNFieldChange = function(input, minCharLenghtTest)
{
	var serialN = input.value;
	var serialStored = "";
	var snIconToHide = null;

	if (input == this.getElementById("upgrade1_SN1")) {
		serialStored = this.UpgradeSerialNumber;
		this.UpgradeSerialNumber = serialN;
		snIconToHide = this.upgradeSN1Icon;
	}
	else {
		serialStored = this.UpgradeSerialNumber2;
		this.UpgradeSerialNumber2 = serialN;
		snIconToHide = this.upgradeSN2Icon;
	}
	if (serialN != serialStored) {
		if (serialN.length > minCharLenghtTest) {
			this.UpgradeSerialCheckStatus(false);
		}
		else {
			snIconToHide.Hide();
		}
	}
}

Welcome_wp.prototype.onUpgradeSNFieldPaste = function(input)
{
	var pasteText = "";
	var pasteObject = this.wizardControl.session.UIGetPasteboardValue();
	
	if (null == pasteObject["_error"] || "0" == pasteObject["_error"]) {
		pasteText = pasteObject["value"];
	}
	if (pasteText.length > 0) {
		input.value = pasteText;
		this.onUpgradeSNFieldChange(input, 0);
		event.returnValue = false;
	}
}

Welcome_wp.prototype.onUpgradeSNFieldOnKeyDown = function(input)
{
	// Paste keys? - Handle them as we are not getting onpaste on Safari 2.x
	if ((event.metaKey || event.ctrlKey) && (event.keyCode == 86)) {
		this.onUpgradeSNFieldPaste(input);
	}
}

Welcome_wp.prototype.onNext = function()
{
	this.updateSerialCheckStatus();
	if((this.wizSerialRadio.GetRadioState() == kRadioStateOn) && ("1" == this.serialNumberValid))
	{
		// Update UI to allow the user to enter previous serial number
		var leftWelcomeContent = this.getElementById("left_Welcome");
		var rightWelcomeContent = this.getElementById("right_Welcome");
		
		var leftUpgradeContent = this.getElementById("left_UpgradeSN");
		var rightUpgradeContent = this.getElementById("right_UpgradeSN");
		
		// Upgrade serial number detected
		if(   ((this.serialNumberUpgrade) && (this.serialNumberUpgrade == "1")) || ((this.serialNumberUpdate) && (this.serialNumberUpdate == "1")) || ((this.serialNumberUpsell) && (this.serialNumberUpsell == "1")) )
		{
			// We are on Welcome screen
			if(leftWelcomeContent.style.display != "none" )
			{
				// Populate the first dropdown with the set of upgrade products
				if(this.serialNumberUpgradeProducts && this.serialNumberUpgradeProducts.length > 0)
				{
					var upgradeProductList1Select = this.getElementById("upgradeProductList1Select");
				
					// Remove the previous contents and then re-populate	
					var upgrade2SelectDiv=this.getElementById("upgrade2SelectDiv");
					var upgrade2EditDiv=this.getElementById("upgrade2EditDiv");	
					upgrade2SelectDiv.style.display = "none";
					upgrade2EditDiv.style.display = "none";		
					if ( "1"==this.continueUpgradePass)
					{
						upgrade2SelectDiv.style.display = "block";
						upgrade2EditDiv.style.display = "block";  
					}
					
					if (upgradeProductList1Select.hasChildNodes() == true)
					{
						var optionlist = upgradeProductList1Select.childNodes;
						var count=optionlist.length;
						for( var x =0 ; x < count; x++)        	    			
						{
						  var childobj=optionlist.item(0);
						  upgradeProductList1Select.removeChild(childobj);
						}
					}				

					for (var i = 0; i < this.serialNumberUpgradeProducts.length; i++)
					{
						var option = document.createElement("option");
						option.appendChild(document.createTextNode(this.serialNumberUpgradeProducts[i]));
						option.value = this.serialNumberUpgradeProducts[i];
						upgradeProductList1Select.appendChild(option);
					}
					
					var upgradeProductList2Select = this.getElementById("upgradeProductList2Select");
					if (upgradeProductList2Select.hasChildNodes() == true)
					{
						var optionlist2 = upgradeProductList2Select.childNodes;
						var count=optionlist2.length;
						for( var x =0 ; x < count; x++)        	    			
						{
						  var childobj2=optionlist2.item(0);
						  upgradeProductList2Select.removeChild(childobj2);
						}
					}
					for (var i = 0; i < this.serialNumberUpgradeProducts.length; i++)
					{
						var option = document.createElement("option");
						option.appendChild(document.createTextNode(this.serialNumberUpgradeProducts[i]));
						option.value = this.serialNumberUpgradeProducts[i];
						upgradeProductList2Select.appendChild(option);
					}
				}
				else
					return true;
				
				leftWelcomeContent.style.display = "none";
				rightWelcomeContent.style.display = "none";
				
				leftUpgradeContent.style.display = "block";
				rightUpgradeContent.style.display = "block";
				this.UpgradeSerialNumber = "";
				this.UpgradeSerialNumber2 = "";
				this.cancelWB.Hide();
				this.backWB.Show();
				// We are showing same page with defferent layout, so announce JAWS page message.
				if (this.wizardControl.WAM)
					this.wizardControl.WAM.AnnouncePageMeesage();
			}
			// We are on Upgrade screen. Detect whether the upgrade serial number entered is a valid one or not
			else
			{
			    
				this.UpgradeSerialCheckStatus(true);
				if ("1" == this.continueUpgradePass)
				    return false;
				
				if  (("1" == this.completedUpgradePass ) || ("1" ==  this.isUpgradeValid))
				{
					var dataToPass;
					if (this.UpgradeSerialNumber)
					{
						dataToPass = this.UpgradeSerialNumber;
						this.wizardControl.session.properties["UPGRADEQUALSN"] = dataToPass;
					}
					if (this.UpgradeSerialNumber2)
						this.wizardControl.session.properties["UPGRADEQUALSN"] = dataToPass + "|" + this.UpgradeSerialNumber2;   
						
					 return true;
				}
				else {
					var button1 = {label:this.wizardControl.session.localization.GetString("locOk", "OK"), left:"256px", top:"106px", returnCode:"1", hotkey:"O", defaultOption:"7"};
					var buttonsArray = new Array(button1);
					if (this.UpgradeSerialNumber == "")
					{
						var resultDialog = new WizardAlert1(this.wizardControl.session, this.localization.GetString("locInvalidSNRequiredTitle", "Serial Number required"), this.localization.GetString("locInvalidSNRequired", "Please enter a valid serial number, or select \"Install as trial\""), buttonsArray, "");
					}
					else
					{
					   var resultDialog = new WizardAlert1(this.wizardControl.session, this.localization.GetString("locInvalidSNRetryTitle", "Invalid Serial Number"), this.localization.GetString("locInvalidUpgradeSNRetry",
						    "The serial number you entered does not match the product you selected. Please reenter the serial number or select a different product to upgrade from."), buttonsArray, "");					
					}
					return false;
				}
			}
		}
		// Valid non-upgrade SN
		else
		{
			return true;
		}
	}
	else if((this.wizSerialRadio.GetRadioState() == kRadioStateOn) && ("1" != this.serialNumberValid))
	{
		var resultDialog = null;
		try
		{
			var button1 = {label:this.wizardControl.session.localization.GetString("locOk", "OK"), left:"256px", top:"106px", returnCode:"1", hotkey:"O", defaultOption:"7"};
			var buttonsArray = new Array(button1);

			if(this.serialNumber == "")
			{
				var resultDialog = new WizardAlert1(this.wizardControl.session, this.localization.GetString("locInvalidSNRequiredTitle", "Serial Number required"), this.localization.GetString("locInvalidSNRequired", "Please enter a valid serial number, or select \"Install as trial\""), buttonsArray, "");
			}
			else
			{
				var resultDialog = new WizardAlert1(this.wizardControl.session, this.localization.GetString("locInvalidSNRetryTitle", "Invalid Serial Number"), this.localization.GetString("locInvalidSNRetry", "The serial number you entered is not valid. Click OK to retry entering the serial number."), buttonsArray, "");
			}
			
			this.getElementById(this.arrSNElements[0]).focus();
			this.getElementById(this.arrSNElements[0]).select();
		}
		catch (ex)
		{
		}
		finally
		{
			resultDialog = null;
		}
		return false;
	}
	else if(this.wizTrialRadio.GetRadioState() == kRadioStateOn)
	{
		this.wizardControl.session.aflLanguage = kMultiLingualIsoCode;
		return true;
	}
	return false;
}


Welcome_wp.prototype.onFieldChange = function()
{
	var oldSerialNumber = this.serialNumber;
	this.updateSerialNumber();

	if (oldSerialNumber != this.serialNumber) {
		if (this.serialNumber.length >= 24)
		{
			this.updateSerialCheckStatus();
		}
		else
		{
			this.serialIcon.Hide();
			this.errorbox.Clear();
			this.errorbox.ShowHide();
		}
	}
}


/**
 Change the serial number field focus when a field is full
*/
Welcome_wp.prototype.autoTab = function (input, len, e) 
{
	if(this.invalidKeydown==true)
	{
		//if there was an invalid keydown, there is also an invalid keyup immediately following it, ignoring
		return false;
	}
	var keyCode = e.keyCode; 
	var strKey = String.fromCharCode(e.keyCode);
	
	var reKeyboardChars = /[\x00\x03\x08\x09\x10\x0D\x11\x16\x18\x1A\x2E\x25\x26\x27\x28]/;
	var reValidChars = /\d|[\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69]/;

	this.onFieldChange();
	if(input.value.length >= len && !reKeyboardChars.test(strKey)
		&& reValidChars.test(strKey)) // Should numbers only - Fixed bug#1659912
	{
		input.value = input.value.slice(0, len);

		if((this.getIndex(input) != this.getIndex(document.getElementById("personalization_SN6")))) 
		{
			// TODO: before GM Need to investigate with MS as to the cause of this problem.
			try 
			{
				input.form[(this.getIndex(input)+1) % input.form.length].focus();
				input.form[(this.getIndex(input)+1) % input.form.length].select();
			}
			catch(ex)
			{
				
			} 
		} 
	}

	return true;
} 

Welcome_wp.prototype.onResourcesLoaded = function()
{
	this.RenderInitialWizardImagesOfPage();
	var systemInfo = this.wizardControl.session.systemInfo;
	var thisCB = this;
	for (var i = 0; i < this.arrSNElements.length; i++) 
	{
		var snElement = this.getElementById(this.arrSNElements[i]);

		snElement.onkeyup = function() { thisCB.autoTab(this, 4, event); };
		snElement.onkeydown = function() { thisCB.numericWatch(this, 4, event); event.cancelBubble=true;};
//		snElement.onbeforepaste = function() { thisCB.serialBeforePaste(); };
		snElement.onpaste = function() { thisCB.distributePaste(this, 4); event.returnValue = false;};
		snElement.onblur = function()
		{
			if (thisCB.bSetFocusOnSNElement)
				this.focus();
			thisCB.bSetFocusOnSNElement = false;
		};
		snElement.onfocus = function()
		{
			if (thisCB.wizSerialRadio.GetRadioState() != kRadioStateOn)
				thisCB.wizSerialRadio.SetRadioState(kRadioStateOn); // Select serial radio button
		}
		if (systemInfo.Windows && !_global_ie7 || systemInfo.Macintosh && !window.devicePixelRatio)
			snElement.className = "inputPaddingNotIE7";
	}
	this.getElementById("upgrade1_SN1").onkeyup = function() { thisCB.onUpgradeSNFieldChange(this, 9); };
	this.getElementById("upgrade1_SN2").onkeyup = function() { thisCB.onUpgradeSNFieldChange(this, 9); };
	this.getElementById("upgrade1_SN1").onpaste = function() { thisCB.onUpgradeSNFieldPaste(this); };
	this.getElementById("upgrade1_SN2").onpaste = function() { thisCB.onUpgradeSNFieldPaste(this); };
	this.getElementById("upgrade1_SN1").onkeydown = function() { thisCB.onUpgradeSNFieldOnKeyDown(this); };
	this.getElementById("upgrade1_SN2").onkeydown = function() { thisCB.onUpgradeSNFieldOnKeyDown(this); };

	var serialRadioContainer = this.getElementById("serialRadioContainer");
	var trialRadioContainer = this.getElementById("trialRadioContainer");
	
	this.wizSerialRadio = new WizardRadioButton1("sRadio", "radio", serialRadioContainer, function(){thisCB.handleSerialRadio();}, true);
	this.wizTrialRadio = new WizardRadioButton1("tRadio", "radio", trialRadioContainer, function(){thisCB.handleTrialRadio();}, false);
	
	this.radioGroupSerialTrial = new WizardRadioButtonSet1();
	this.radioGroupSerialTrial.AddWizardRadioButton(this.wizSerialRadio);
	this.radioGroupSerialTrial.AddWizardRadioButton(this.wizTrialRadio);
}

/**
 Get the index of the current form item
*/
Welcome_wp.prototype.getIndex = function (input) {
	
	var index = -1, i = 0, found = false;

	while (i < input.form.length && index == -1)
	{
		if (input.form[i] == input)
			index = i;
		else 
			i++;
	}
	return index;
}


/**
 Block undesired serial number characters while allowing for keyboard-based paste
*/
Welcome_wp.prototype.numericWatch = function (input, len, e) 
{
	var blnValidChar = true;
	this.invalidKeydown = false;
	var reValidChars = /\d/;
	var reKeyboardChars = /[\x00\x03\x08\x09\x0D\x16\x18\x1A\x2E]/;
	var reClipBoardChars = /[\x56\x58\x43\x41]/;
	var reControlChars = /[\x63\x78\x76\x7A]/;
	var reArrowKeys = /[\x25\x26\x27\x28]/;
	var reNumericKeypad = /[\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69]/;
	var strKey, iKeyCode;
 
	iKeyCode = e.keyCode;
	strKey = String.fromCharCode(e.keyCode);

	// WORKAROUND for bug#1756764! On Mac the tabbing on edit feilds is wrong. When focus is on last edit control and user presses
	// tab the system removes partial focus but still keys can be typed onto it.
	// Similarly if the focus is on first feild and pressing shift tab causes focus to remove from document and then
	// never puts again while pressing tab keys
	// Supporting Accessibilty requires extra effort on mac to over come this problem, so for the time being
	// putting this explicit check to put focus on proper control.
	if (this.wizardControl.session.systemInfo.Macintosh) {
		var index = this.getIndex(input);
	
		if (e.shiftKey && (e.keyCode == 9) && index == this.getIndex(document.getElementById("personalization_SN1"))) {
			document.getElementById("personalization_SN6").focus();
			e.returnValue = false;	
			this.invalidKeydown=true;
			return false;
		}
		if (!e.shiftKey && e.keyCode == 9 && index == this.getIndex(document.getElementById("personalization_SN6"))) {
			document.getElementById("personalization_SN1").focus();
			e.returnValue = false;	
			this.invalidKeydown=true;
			return false;
		}
	}
	if(e.shiftKey && (e.keyCode == 9 || reArrowKeys.test(strKey)))//shift+tab
	{
		return true;
	}
	else if ((e.shiftKey && !e.keyCode == 0) ||
		(!reValidChars.test(strKey) && 
		!reKeyboardChars.test(strKey) &&
		!(e.ctrlKey && reClipBoardChars.test(strKey)) && 
		!(e.metaKey && reClipBoardChars.test(strKey)) && 
		!reControlChars.test(strKey) && 
		!reArrowKeys.test(strKey) && 
		!reNumericKeypad.test(strKey)   ))
	{
		blnValidChar = false;
	}

	if (blnValidChar) 
	{		
		if (e.metaKey && (e.keyCode == 86)) 
		{
			blnValidChar = this.distributePaste(input, len);
		} 
		else if (e.ctrlKey && (e.keyCode == 86)) 
		{
		    blnValidChar = this.distributePaste(input, len);
		}			
	} 
	if(!blnValidChar) 
	{
		e.returnValue = false;	
		this.invalidKeydown=true;
		return false;
	}
	return true; 
}

Welcome_wp.prototype.GetSerialNumber = function (inSerialNumber, maxLen)
{
	var retString = "";
	var reValidChars = /^\d+$/; // Only numbers are allowed

	for(var i=0; i<inSerialNumber.length; i++) {
		if (inSerialNumber.charAt(i) != ' ' && inSerialNumber.charAt(i) != '-') {
			retString += inSerialNumber.charAt(i);
		}
	}
	// Chop out extra characters
	if (retString.length > maxLen) {
		retString = retString.slice(0, maxLen);
	}
	// Valid chars
	if (!reValidChars.test(retString)) {
		retString = "";
	}
	return retString;
}

/**
 Paste the current text in the clipboard across the serial number fields, removing unwanted dashes
*/
Welcome_wp.prototype.distributePaste = function (input, len) 
{
	var storeChopped = "";
	var storeFull = "";
	var returnVal = false;
	// Search for SN input feild
	for (var loopCount = 0; loopCount < this.arrSNElements.length; loopCount++) {
		if (input == document.getElementById(this.arrSNElements[loopCount]))
		break;
	}
	// Are we pasting in any of the SN input feilds
	if (loopCount < this.arrSNElements.length) {

		var requiresResult = "0";
		var count = 0;
		var reValidChars = /^\d+$/; // Only numbers are allowed
		var position = 0;

		var pasteObject = this.wizardControl.session.UIGetPasteboardValue();
		
		if (null == pasteObject["_error"] || "0" == pasteObject["_error"]) {
			storeFull = pasteObject["value"];
		}		
		storeChopped = this.GetSerialNumber(storeFull, len*(this.arrSNElements.length - loopCount));
		if (storeChopped.length > 0) {
			for(position = 0; position < storeChopped.length; position = position + len) {
				if (position > storeFull.length) {
					position = storeFull.length - 1;
				}

				document.getElementById(this.arrSNElements[loopCount]).value = storeChopped.slice(position, position+len);	
				loopCount++;
			}
			returnVal = true;
		}
	} 
	
	this.onFieldChange();

	return returnVal;
} 


/**
 Callback to help Windows deal with distributed paste
*/
/*Welcome_wp.prototype.serialBeforePaste = function() 
{
	return true;
} */


// Return the name of the class.
"Welcome_wp";
