//
//	Script: wineLabelJS
//	Version: 1.1
//	Modified:
//	26/02/2009 v1.0 Added this change control documentation
//					Modified generateLabelWizardHTML to include Label Wizard 2 and
//					Label Wizard File Upload 3
//  22/04/2009 v1.1 Modified generateLabelWizardHTML to include Label Wizard 3 and
//					modified the height of Label Wizard File Upload 2 to 600 pixels

//This function displays a message on the Image/Logo Upload window when file uploading has started
function displayMsg()
{
	document.UploadForm.msg.value = "File Uploading.......Please Wait";
}

//This function refreshs the label wizard page and closes the Image/Logo Upload page
function refreshLabelWizardPage()
{
	//Refresh the Label Wizard page, ie the parent page 
	parent.opener.location.reload(true);
	
	//Close the Image/Logo Upload window
	window.close();
}

//This function opens the Image Upload window
function openUploadWindow()
{
	UploadWindow = window.open("ImageUpload.asp", "Upload", "width=700,height=150");
}

//This function opens the Logo Upload window
function openUploadLogoWindow()
{
	UploadLogoWindow = window.open("LogoUpload.asp", "UploadLogo", "width=700,height=150");
}

//This function is called by flash with a list of text field parameters
//to set the hidden fields xfield1, xfield2, xfield3 on the form "additem".	
//The first argument is assigned to xfield1, the second to xfield2
//and the third to xfield3
function receiveValues(/*varargs*/)
{
	for (var i = 0; i < arguments.length; i += 1)
	{
	   var text = arguments[i];
	   if (i == 0)
	   {
			document.additem.xfield1.value = text;
	   }
	   else if (i == 1)
	   		{
	   			document.additem.xfield2.value = text;
			}
			else
			{
				document.additem.xfield3.value = text;
			}
    }
}

//Label Wizard version 2.0 functions

//This function is called to generate the Label Wizard and label HTML code. The parameters
//passed to the function are the label name, height and width and the type of Label Wizard.
//The call to this javascript function is added to the product short description.
function generateLabelWizardHTML(labelName,labelWidth,labelHeight,typeLabelWizard)
{
	//Define variables
	var directoryName = "LabelWizard";	
	var labelWizardName = " ";
	var labelWizardWidth = 0;	
	var labelWizardHeight = 0;
	
	//Determine the Label Wizard to be generated based
	//on the type of Label Wizard parameter
	switch(typeLabelWizard)
	{
		case "LW1":
			labelWizardName = "LabelWizard1";
			labelWizardWidth = 365;			
			labelWizardHeight = 515;
  			break;
			
		case "LW2":
			labelWizardName = "LabelWizard2";
			labelWizardWidth = 350;			
			labelWizardHeight = 500;
  			break;

		case "LW3":
			labelWizardName = "LabelWizard3";
			labelWizardWidth = 350;			
			labelWizardHeight = 500;
  			break;

		case "LW-F1":
			labelWizardName = "LabelWizard_FileUpload1";
			labelWizardWidth = 350;				
			labelWizardHeight = 550;
  			break;
			
		case "LW-F2":
			labelWizardName = "LabelWizard_FileUpload2";
			labelWizardWidth = 350;				
			labelWizardHeight = 600;
  			break;
			
		case "LW-F3":
			labelWizardName = "LabelWizard_FileUpload3";
			labelWizardWidth = 350;				
			labelWizardHeight = 600;
  			break;
			
		default:
			labelWizardName = "Error";
			labelWizardWidth = 0;				
			labelWizardHeight = 0;		
	}

	//Generate Timestamp
	var timeStamp = generateTimeStamp();

	//Label definition

	document.write(
	'<table width="60%" border="0" cellspacing="0" cellpadding="0"><tr>\n' +
	'<td align="left" valign="top">\n' +				   
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n' +
	' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n' +
	' width="'+ labelWidth + '" height="' + labelHeight + '" id="' + labelName + '" align="middle">\n' +
	' <param name="allowScriptAccess" value="sameDomain" />\n' +
	' <param name="movie" value="' + directoryName + '/' + labelName + '.swf" />\n' +
	' <param name="quality" value="high" />\n' +
	' <param name="bgcolor" value="#ffffff" />\n' +
	' <PARAM NAME=FlashVars VALUE="sessionID=' + timeStamp + '" />\n' +
	' <embed src="' + directoryName + '/' + labelName + '.swf" FlashVars="sessionID=' + timeStamp + '" quality="high" bgcolor="#ffffff" width="' + labelWidth + '" height="' + labelHeight + '" name="' + labelName + '"\n' +
	' align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n' +
	' </object></td>\n');

	//Label Wizard definition
		
	document.write(
	'<td align="left" valign="top">\n' +
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n' +
	' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n' +
	' width="'+ labelWizardWidth + '" height="' + labelWizardHeight + '" id="' + labelWizardName + '" align="middle">\n' +
	' <param name="allowScriptAccess" value="sameDomain" />\n' +
	' <param name="movie" value="' + directoryName + '/' + labelWizardName + '.swf" />\n' +
	' <param name="quality" value="high" />\n' +
	' <param name="bgcolor" value="#ffffff" />\n' +
	' <PARAM NAME=FlashVars VALUE="sessionID=' + timeStamp + '" />\n' +
	' <embed src="' + directoryName + '/' + labelWizardName + '.swf" FlashVars="sessionID=' + timeStamp + '" quality="high" bgcolor="#ffffff" width="' + labelWizardWidth + '" height="' + labelWizardHeight + '" name="' + labelWizardName + '"\n' +
	' align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n' +
	' </object></td></tr></table>\n');
}

//This function is called to generate a unique time stamp. The time stamp is used to
//create the connection between the Label Wizard and the label.
function generateTimeStamp()
{
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();

	return hours + '' + minutes + '' + seconds;
}

//This function is called from the wine label flash movie to pass the text field
//data to the the hidden fields xfield1,xfield2,xfield3 on the form "additem".
//The first argument is assigned to xfield1, the second to xfield2 and the third to xfield3
//Note: This function was called 'receiveValues' for the Label Wizard v1.0
function receive_Data_From_Flash(/*varargs*/)
{
	for (var i = 0; i < arguments.length; i += 1)
	{
	   var text = arguments[i];
	   if (i == 0)
	   {
			document.additem.xfield1.value = text;
	   }
	   else if (i == 1)
	   		{
	   			document.additem.xfield2.value = text;
			}
			else
			{
				document.additem.xfield3.value = text;
			}
    }
}

//This function is called from the Label Wizard to refresh the HTML page.
//It will be called by pressing the 'Start Again' button.
function refreshPage()
{
	window.location.reload();
}