
var EZXObject = null;
var EZXObjectNails = null;
var strEZTempLookName = "EZTempLook";
var intChannelID = 0;
var bOnlyHandAX = false;
var EZfaceActiveXInstalled = null;


//*********************************************************************************************************
// Function name: SetHandControl
//
// This function is setting if the page contain only the hand ActiveX.
// If there is only one ActiveX then the name of the ActiveX will be "EZFaceControlX1".
// This was done to prevent duplicating the JavaScript library.
//*********************************************************************************************************
function SetHandControl()
{
	bOnlyHandAX = !bOnlyHandAX;
}

//*********************************************************************************************************
// Function name: LoadEZfaceActiveXtoPage
//
// This function initializes the activeX parameters and load model photos, hotlooks and products xml.
// If activeX version isnt install or version number less than 209 we send the user to the installation pages.
//*********************************************************************************************************
function LoadEZfaceActiveXtoPage()
{
	if (window.document.forms['frmEZfaceActiveX'].EZFaceControlX1)
	{
		try
		{
			EZXTempObject = new ActiveXObject("EZFaceW.EZFaceControlX210");
			Version = EZXTempObject.Registry.Version;
			EZXTempObject = null;
			if(Version > 209)
			{
				try
				{
					EZXObject = window.document.forms['frmEZfaceActiveX'].EZFaceControlX1;
					//var EZwin = window.document.forms['frmEZfaceActiveX'].EZFaceControlWLX;
					//(EZwin);
				}
				catch(e)
				{
					if (EZXObject == null)
						EZXObject = window.document.EZFaceControlX1;
				}
				//("bOnlyHandAX - " + bOnlyHandAX);
				if(!bOnlyHandAX)
				{
					EZXObjectNails = window.document.forms['frmEZfaceActiveX'].EZFaceControlX2;
					if(EZXObjectNails)
					{
						EZXObject.PhotoType = 0;
						EZXObjectNails.PhotoType = 1;
						EZXObject.AlphaFade = true;
						EZXObject.ProgressBar = true;
						EZXObjectNails.AlphaFade = false;
 						EZXObjectNails.ProgressBar = false;
						EZXObject.Stretch = true;
						EZXObjectNails.Stretch = false;
						EZXObject.Slave = EZXObjectNails.Self;
						EZXObjectNails.BackGroundColor = 16777215;
						//EZXObject.DrawBitmap.Halftone = true;
						EZXObject.SaveLookWithPhoto = true;
						EZXObject.LookThumbnailScale = 0.25;
					}
					else
					{
						EZXObject.PhotoType = 0;
						EZXObject.AlphaFade = true;
						EZXObject.ProgressBar = true;
						EZXObject.Stretch = true;
						//EZXObject.DrawBitmap.Halftone = true;
					}
				}
				else
				{
					EZXObject.PhotoType = 1;
					EZXObject.AlphaFade = true;
					EZXObject.ProgressBar = true;
					EZXObject.Stretch = true;
					EZXObject.BackGroundColor = 16777215;
					//EZXObject.DrawBitmap.Halftone = true;
				}

				LookWithPhoto = true;

				if(!EZXObject.SetSourceID(strSourceID))
				{
					EZXObject.CreateSource(strSourceID, "", "", strSourceName);
					EZXObject.SourceID = strSourceID;
				}
				EZXObject.SubSourceID = strSubSourceID;
				EZXObject.CheckPasswordLocaly = false;

				EZXObject.Source.LoadColorGroup = false;

				// Load models list from XML
				//LoadModelsPhotoXML();

				// Load Hot looks list XML
				//LoadHotlooksListXml();

				// Load product XML
				//LoadProductXML();

				// The location of the model gallery  URL
				EZXObject.Brand = strBrand;
				EZXObject.Source.ASPExt=".jsp";
				EZXObject.Source.ImagePath = strImagePath;
				EZXObject.Source.ASPPath = strASPPath;
				EZXObject.GetUserIdUrl = strGetUserIDPath
				//EZXObject.Source.ASPPath = "http://winpic2/ezface-prod/EZfaceActiveXFunctionalitySiteJSP_2/BackEnd/";
				EZXObject.Source.UserAlbumPath = strUserAlbumPath;

				EZXObject.Bitmap.MinPhotoLoadSize = MinPhotoLoadSize;
				EZXObject.Bitmap.MaxPhotoLoadSize = MaxPhotoLoadSize;
				EZXObject.Bitmap.MinPhotoSendSize = MinPhotoSendSize;
				EZXObject.Bitmap.MaxPhotoSendSize = MaxPhotoSendSize;
				EZXObject.Bitmap.MinUploadHeight = MinUploadHeight;
				EZXObject.Bitmap.MinUploadWidth = MinUploadWidth;
				// Create guest user for using the activex.
				/*bResult = false;
				// Check if the guest user register in the activeX, if not create the guest user.
				if(!EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword))
				{
					EZXObject.CreateUser(strGuestUserID, strGuestUserLogin, strGuestUserPassword, -1, -1);
					bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
					while(!bResult)
					{
						bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
					}

				}
				else
					bResult = true;

				if(bResult)
				{
					// Set first model

					EZXObject.User.PersonType = strPersontypeID;
					LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);

					EZXObject.Visible = true;
					if(EZXObjectNails)
						EZXObjectNails.Visible = true;

					//setTimeout("LoadModels();", 500);
					setTimeout("LoadProductShades();", 500);

				}
				else
				{
					setTimeout("LoadEZfaceActiveXtoPage();", 500);
				}*/
			}
			else
			{
				// Call EZface installation pages
				ActivateEZfaceInstallationSystem();
			}
		}
		catch(e)
		{
			("Error " + e.message);
		}
	}
	else
	{
		setTimeout("LoadEZfaceActiveXtoPage();", 500);
	}
}

//*********************************************************************************************************
// Function name: UpdateWindowlessObject
//
// This function update window less ActiveX with bitmap data from ActiveX.
// Window less ActiveX is object that allows you to put any object (image, photo, html) on the window less ActiveX.
// All the functionality of the ActiveX is done on the real ActiveX and every update raise event (OnUpdate)
// and in this event we are updating the window less with the current data.
// ActiveXType is parameter to set which ActiveX to update. 1 - face ActiveX, 2 - Nails
//*********************************************************************************************************
function UpdateWindowlessObject(ActiveXType)
{
	var EZXWindowlessObject = null;
	if (ActiveXType == 1)
	{
		try
		{
			EZXWindowlessObject = window.document.forms['frmEZfaceActiveX'].EZFaceControlWLX;
			EZXWindowlessObject.Update(EZXObject.DrawBitmapDC, 0, 0, EZXObject.DrawBitmap.Width, EZXObject.DrawBitmap.Height);
		}
		catch(e)
		{}
	}
	else
	{
		if (ActiveXType == 2)
		{
			try
			{
				EZXWindowlessObject = window.document.forms['frmEZfaceActiveX'].EZFaceControlWLX2;
				EZXWindowlessObject.Update(EZXObjectNails.DrawBitmapDC, 0, 0, EZXObjectNails.DrawBitmap.Width, EZXObjectNails.DrawBitmap.Height);
			}
			catch(e){}
		}
	}
}

//*********************************************************************************************************
// Function name: Load_ActiveX_LoginGuestUser_SetFirstModel
//
// This function initializes the activeX parameters and load model photos xml.
// After initializes the activeX the function will login with guest user (if the guest user does not exist the function will create the user)
// and then load the first model from the models gallery.
//*********************************************************************************************************
function Load_ActiveX_LoginGuestUser_SetFirstModel()
{
	LoadEZfaceActiveXtoPage();

	// Create guest user for using the activex.
	bResult = false;
	// Check if the guest user register in the activeX, if not create the guest user.
	if(!EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword))
	{
		EZXObject.CreateUser(strGuestUserID, strGuestUserLogin, strGuestUserPassword, -1, -1);
		bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
		while(!bResult)
		{
			bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
		}

	}
	else
		bResult = true;

	if(bResult)
	{
		// Set user person type
		EZXObject.User.PersonType = strPersontypeID;
		// Set first model
		LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);

		UpdateWindowlessObject(1);

		EZXObject.Visible = true;
		if(EZXObjectNails) {
			EZXObjectNails.Visible = true;
			UpdateWindowlessObject(2);
		}

	}
	else
	{
		setTimeout("Load_ActiveX_LoginGuestUser_SetFirstModel();", 500);
	}
}

//*********************************************************************************************************
// Function name: Load_ActiveX_LoginGuestUser_SetLastPhoto
//
// This function initializes the activeX parameters and load model photos xml.
// After initializes the activeX the function will login with guest user (if the guest user does not exist the function will create the user)
// and then we are checking what is the last photo model or user photo and according to that we load to the ActiveX the photo.
// If there is no photo loaded we will load the first model photo.
//*********************************************************************************************************
function Load_ActiveX_LoginGuestUser_SetLastPhoto()
{

	//LoadEZfaceActiveXtoPage();

	// Create guest user for using the activex.
	bResult = false;
	// Check if the guest user register in the activeX, if not create the guest user.
	if(!EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword))
	{
		EZXObject.CreateUser(strGuestUserID, strGuestUserLogin, strGuestUserPassword, -1, -1);
		bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
		while(!bResult)
		{
			bResult = EZXObject.UserLogin(strGuestUserLogin,strGuestUserPassword);
		}
	}
	else
		bResult = true;

	if(bResult)
	{
		// Get from local ActiveX the last user photo ID and the last Model photo ID
		var intModelID = EZXObject.User.ModelPhotoID;
		var intUserPhotoIndex = EZXObject.User.PhotoIndex;
		var intModelCount = EZXObject.DBModelPhotoList(0).Count;
		var intUsetPhotoCount = EZXObject.User.PhotoList(0).Count;

		// Set user person type
		EZXObject.User.PersonType = strPersontypeID;

		// --- Set photo by default instead model

		if((intUserPhotoIndex > -1) && (intUserPhotoIndex < intUsetPhotoCount))
		{
			EZXObject.User.PhotoIndex = intUserPhotoIndex;
			//ApplyUserPhoto(intUserPhotoIndex);
		}
		else
		{
			if(((intModelID < 0) && (intUsetPhotoCount < 1)) || ( intModelID > intModelCount))
			{
				// Set first model
				LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
			}
			else
			{
				LoadModelPhoto(intModelID);
			}
		}
		UpdateWindowlessObject(1);
		UpdateWindowlessObject(2);

		EZXObject.Visible = true;
		if(EZXObjectNails)
			EZXObjectNails.Visible = true;

	}
	else
	{
		setTimeout("Load_ActiveX_LoginGuestUser_SetLastPhoto(UserLogin,UserPassword);", 500);
	}
}

//*********************************************************************************************************
// Function name: LoadEZfaceActiveXtoPageByUser
//
// This function initializes the activeX parameters and load model photos, hotlooks and products xml.
// If activeX version isnt install or version number less than 209 we send the user to the installation pages.
// The function gets 2 parameter UserLogin and UserPassword for loadin the last [hoto that user used and for loading
// the last look.
//*********************************************************************************************************
function LoadEZfaceActiveXtoPageByUser_noams(UserLoginData)
{
	LoadEZfaceActiveXtoPage();
	// Create user for using the activex.
	bResult = false;
	// Check if the user register in the activeX, if not create the user.
	if(!EZXObject.UserLogin(UserLoginData,strUserPassword))
	{
		// Create the user in the ActiveX
		if(EZXObject.CreateUserEx(UserLoginData, strUserPassword))
		{
			// Login into the ActiveX
			bResult = EZXObject.UserLogin(UserLoginData,strUserPassword);
			while(!bResult)
			{
				bResult = EZXObject.UserLogin(UserLoginData,strUserPassword);						
			}
		}
		else
			alert('EZFace is currently experiencing technical difficulties. Please try again later.')
	}
	else
		bResult = true;					
	
	if(bResult)
	{
		strUserLogin = UserLoginData;
				
		// Get from local ActiveX the last user photo ID and the last Model photo ID
		var intModelID = EZXObject.User.ModelPhotoID;
		var intUserPhotoIndex = EZXObject.User.PhotoIndex;
		var intModelCount = EZXObject.DBModelPhotoList(0).Count;
		var intUsetPhotoCount = EZXObject.User.PhotoList(0).Count;
		
		// --- Set photo by default instead model  	
		if((intUserPhotoIndex > -1) && (intUserPhotoIndex < intUsetPhotoCount))
		{
			EZXObject.User.PhotoIndex = intUserPhotoIndex;
			ApplyUserPhoto(intUserPhotoIndex);
		}
		else
		{
			if(((intModelID < 0) && (intUsetPhotoCount < 1)) || ( intModelID > intModelCount)) 
			{
				// Set first model
				
				LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
			}
			else
			{
				LoadModelPhoto(intModelID);
			}
		}
		
		
		// Load temp look.
		LoadEZTempLook();
		// Delete temp look after apply on the user/model photo.
		DeleteEZTempLook();
		
		UpdateWindowlessObject(1);
		UpdateWindowlessObject(2);

		EZXObject.Visible = true;
		if(EZXObjectNails)
			EZXObjectNails.Visible = true;
		
		//setTimeout("LoadProductShades();", 500);
			
	}
	else
	{
		setTimeout("LoadEZfaceActiveXtoPageByUser(strUserLogin);", 500);
	}
}


function LoadEZfaceActiveXtoPageByUser(UserLoginData)
{
	LoadEZfaceActiveXtoPage();
	// Create user for using the activex.
	bResult = false;
	// Check if the user register in the activeX, if not create the user.
	if(!EZXObject.UserLogin(UserLoginData,strUserPassword))
	{
		// Create the user in the ActiveX
		if(EZXObject.CreateUserEx(UserLoginData, strUserPassword))
		{
			// Login into the ActiveX
			bResult = EZXObject.UserLogin(UserLoginData,strUserPassword);
			while(!bResult)
			{
				bResult = EZXObject.UserLogin(UserLoginData,strUserPassword);						
			}
		}
		else
			alert('EZFace is currently experiencing technical difficulties. Please try again later.')
	}
	else
		bResult = true;					
	
	if(bResult)
	{
		strUserLogin = UserLoginData;
		
		if (document.location.href.indexOf('/connect/makeupmirror')>=0) {
		
			try {
				$('vmoStageStart').style.display='none'
				//ApplyUserPhoto(0);
				
			var intModelID = EZXObject.User.ModelPhotoID;
				var intUserPhotoIndex = EZXObject.User.PhotoIndex;
				var intModelCount = EZXObject.DBModelPhotoList(0).Count;
				var intUsetPhotoCount = EZXObject.User.PhotoList(0).Count;
				
				// --- Set photo by default instead model  	
				if((intUserPhotoIndex > -1) && (intUserPhotoIndex < intUsetPhotoCount))
				{
					EZXObject.User.PhotoIndex = intUserPhotoIndex;
					ApplyUserPhoto(intUserPhotoIndex);
				}
				else
				{
					if (!miniVMO) {
						if(((intModelID < 0) && (intUsetPhotoCount < 1)) || ( intModelID > intModelCount)) 
						{
							// Set first model
							LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
						}
						else
						{
							LoadModelPhoto(intModelID);
						}
					} else {
						throw "err"	
					}
					
				}			
				
				
				
				startFlags = document.getElementsByClassName('vmoStart');
				for(x=0;x<startFlags.length;x++) {
					startFlags[x].style.display='block';
				}	
				$('leftCol').style.background = 'transparent url(/connect/makeupmirror/images/leftColBG.gif) no-repeat'
				$('vmoStageStart').style.display='none'
				vmoStart = 1;
			} catch(err) {
				$('vmoStageStart').style.display='block'
				startFlags = document.getElementsByClassName('vmoStart');
				for(x=0;x<startFlags.length;x++) {
					startFlags[x].style.display='none';
				}	
				$('leftCol').style.background = 'none'
			}
		
		}
		
		/*
		// Get from local ActiveX the last user photo ID and the last Model photo ID
		var intModelID = EZXObject.User.ModelPhotoID;
		var intUserPhotoIndex = EZXObject.User.PhotoIndex;
		var intModelCount = EZXObject.DBModelPhotoList(0).Count;
		var intUsetPhotoCount = EZXObject.User.PhotoList(0).Count;
		
		// --- Set photo by default instead model  	
		if((intUserPhotoIndex > -1) && (intUserPhotoIndex < intUsetPhotoCount))
		{
			EZXObject.User.PhotoIndex = intUserPhotoIndex;
			ApplyUserPhoto(intUserPhotoIndex);
		}
		else
		{
			if(((intModelID < 0) && (intUsetPhotoCount < 1)) || ( intModelID > intModelCount)) 
			{
				// Set first model
				LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
			}
			else
			{
				LoadModelPhoto(intModelID);
			}
		}
		*/
		
		// Load temp look.
		LoadEZTempLook();
		// Delete temp look after apply on the user/model photo.
		DeleteEZTempLook();
		
		UpdateWindowlessObject(1);
		UpdateWindowlessObject(2);
		
		EZXObject.Visible = true;
		if(EZXObjectNails)
			EZXObjectNails.Visible = true;
		
		//setTimeout("LoadProductShades();", 500);
			
	}
	else
	{
		setTimeout("LoadEZfaceActiveXtoPageByUser(strUserLogin);", 500);
	}
}

//*********************************************************************************************************
// Function name: LoadModelsPhotoXML
//
// Load model gallery from XML  the name of the DOM object is xDomModels
//*********************************************************************************************************
function LoadModelsPhotoXML()
{
	EZXObject.Source.ModelPhotosXml = xDomModels.xml;
}

//*********************************************************************************************************
// Function name: LoadHotlooksListXml
//
// Load hotlooks list from XML  the name of the DOM object is xDomHotlooks
//*********************************************************************************************************
function LoadHotlooksListXml()
{
	//(xDomHotlooks.xml);
	//(xDomHotlooks.selectSingleNode("//hotlook [id = 'PR_F0_05_24']/channel/subProductName").xml);
	//(xDomHotlooks.selectSingleNode("//hotlook [id = 'PR_F0_05_24']/channel/subProductName").text);
	EZXObject.Source.HotlooksListXml = xDomHotlooks.xml;
}

//*********************************************************************************************************
// Function name: LoadProductXML
//
// Load product from XML  the name of the DOM object is xDomProducts
//*********************************************************************************************************
function LoadProductXML()
{
	EZXObject.Source.DBSuperProductXml = xDomProducts.xml;
	strSuperProdID = xDomProducts.selectSingleNode("//load/superProduct/id").text;
}

//*********************************************************************************************************
// Function name: DeleteProduct
//
// Delete product from the activeX cache.
//*********************************************************************************************************
function DeleteProduct()
{
	EZFaceControlX1.Source.DBSuperProductXml = "";
}

//*********************************************************************************************************
// Function name: LoadBasketByXML
//
// Load basket from XML  the function gets XML parameter.
//*********************************************************************************************************
function LoadBasketByXML(strBasketXML)
{
	EZXObject.User.Basket = strBasketXML;
}

//*********************************************************************************************************
// Function name: GetBasketXML
//
// Get basket XML  the function return string value with basket XML.
//*********************************************************************************************************
function GetBasketXML()
{
	strBasketXML = EZXObject.User.Basket;
	return strBasketXML;
}

//*********************************************************************************************************
// Function name: ClearBasket
//
// Delete basket from all products.
//*********************************************************************************************************
function ClearBasket()
{
	EZXObject.User.ClearBasket();
}

//*********************************************************************************************************
// Function name: AddToBasket
//
// Add product to the basket by product code.
//*********************************************************************************************************
function AddToBasket(strProdID){
	EZXObject.User.AddToBasket(strProdID);
}

//*********************************************************************************************************
// Function name: RemoveFromBasket
//
// Remove product from the basket by product code.
//*********************************************************************************************************
function RemoveFromBasket(strProdID){
	EZXObject.User.DeleteFromBasket(strProdID);
}

//*********************************************************************************************************
// Function name: ApplyColor
//
// Apply product color on the model photo.
// intChannelID is global parameter that set the channel of the product that you work now, the default value is 0.
// There are some product the can be apply on 2 more channels in the same product
// like Eye Shadow so you don't need to send it all the time only to change the global parameter.
//*********************************************************************************************************
function ApplyColor(strProdID)
{
	if (vmoTransient) {
		docLocation = document.location.href;
		docLocation = docLocation.substring(7,docLocation.length).substring(docLocation.substring(7,docLocation.length).indexOf('/'), docLocation.substring(7,docLocation.length).length)
		document.location = "/registration/?redirect_page="+docLocation.replace('?', '%3F').replace('=', '%3D')+'&hd=hd_product';
		return;	
	}
	try {

	EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID).DBSubProdID = strProdID;
	EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID).Visible = true;
	} catch(err){}
	if ($('prodUsedColumn')) generateUsedProds();

	//DeleteEZTempLook();
	//SaveEZTempLook();
}

//*********************************************************************************************************
// Function name: ApplyHotLook
//
// Apply hotlook on the model photo by hotlook index.
// Index parameter is the order of the nodes in the HotLooks XML
//*********************************************************************************************************
function ApplyHotLook(index)
{
	EZXObject.User.HotLookList.LoadFromDBProxy();

   	EZXObject.User.HotLookID = EZXObject.User.HotLookList.Items(index).ID;

   	//DeleteEZTempLook();
	//SaveEZTempLook();
}

//*********************************************************************************************************
// Function name: ApplyHotLookByID
//
// Apply hotlook on the model photo by hotlook ID/Code.
//*********************************************************************************************************
function ApplyHotLookByID(HotLookID,HotLookImg)
{
	EZXObject.User.HotLookList.LoadFromDBProxy();

   	EZXObject.User.HotLookID = HotLookID;
	AjaxVMO.vmoStartFlag(1);
   	//DeleteEZTempLook();
	//SaveEZTempLook();
	hotLooks=document.getElementsByClassName('dvHotlook');

	for(x=0;x<hotLooks.length;x++) {
			hotLooks[x].style.border='none';
	}
	$(HotLookImg).style.border='2px solid #3399FF';
	if ($('rightCol').style.display!='block') $('rightCol').style.display='block'
	generateUsedProds();
}

//*********************************************************************************************************
// Function name: GetHotlookXML
//
// Get XML with all the products on the model photo.
//*********************************************************************************************************
function GetHotlookXML(){
	strHotlookXML = EZXObject.User.HotlookXML;
	return strHotlookXML;
}

//*********************************************************************************************************
// Function name: LoadEZTempLook
//
// Load temp hotlook by name.
// strEZTempLookName will contain the name of the temp look
//*********************************************************************************************************
function LoadEZTempLook()
{
	//Load EZface temp look
	tempLookIndex = -1;
	EZLookList = EZXObject.User.LookList;
	var maxLookList = EZLookList.Count;
	for (var i=0;i<maxLookList;i++)
	{
		if (EZLookList.Items(i).Name == strEZTempLookName)
		{
			tempLookIndex=i;
		}
	}

	if(tempLookIndex>-1)
	{
		EZXObject.User.LookIndex = tempLookIndex;
	}
}

//*********************************************************************************************************
// Function name: SaveEZTempLook
//
// Save temp hotlook for moving from page to page.
// strEZTempLookName will contain the name of the temp look
//*********************************************************************************************************
function SaveEZTempLook()
{
	EZXObject.User.LookList.Add(strEZTempLookName).SaveToStream();
	//EZXObject.User.LookList.Items(0).SaveToStream();
}

//*********************************************************************************************************
// Function name: DeleteEZTempLook
//
// Delete temp hotlook  must be done at the beginning on the session.
// strEZTempLookName will contain the name of the temp look
//*********************************************************************************************************
function DeleteEZTempLook()
{
	tempLookIndex = -1;
	EZLookList = EZXObject.User.LookList;
	var maxLookList = EZLookList.Count;
	for (var i=0;i<maxLookList;i++)
	{
		if (EZLookList.Items(i).Name == strEZTempLookName)
		{
			tempLookIndex=i;
		}
	}

	if(tempLookIndex>-1){
		EZLookList.Delete(tempLookIndex);
	}
}

//*********************************************************************************************************
// Function name: SetNameForEZTempLook
//
// Set the name of the temp look
// strEZTempLookName will contain the name of the temp look
//*********************************************************************************************************
function SetNameForEZTempLook(TempLookName)
{
	if(TempLookName != "")
		strEZTempLookName = TempLookName;
	else
		strEZTempLookName = "EZTempLook";
}

//*********************************************************************************************************
// Function name: DisposeEZfaceActiveX
//
// Dispose active x when exit / close the page  must be done.
//*********************************************************************************************************
function DisposeEZfaceActiveX()
{
	try {
		EZXObject.Release_();
		if(EZXObjectNails)
			EZXObjectNails.Release_();
	} catch(err) {}
}

//*********************************************************************************************************
// Function name: Before
//
// Show the model photo without any product on the model face.
//
// Before just show you the photo without all the product but not delete them from the ActiveX
// after apply new product on the photo the ActiveX will show again the products.
// ClearAll function delete all the products from the ActiveX
//*********************************************************************************************************
function Before()
{
	
	EZXObject.Bitmap.Before();
}

//*********************************************************************************************************
// Function name: After
//
// Show the model photo with all the products.
//*********************************************************************************************************
function After()
{
	EZXObject.Bitmap.After();
}

//*********************************************************************************************************
// Function name: ClearAll
//
// Delete the entire product from the model photo.
//*********************************************************************************************************
function ClearAll()
{
	EZXObject.Bitmap.ClearAll();
	DeleteEZTempLook();
	clearProductsUsed();
}

//*********************************************************************************************************
// Function name: SetIntensity
//
// Set the intensity of the product color
// The type of num is integer and the values are 1 or -1.
// The ActiveX has the intensity of the product on the model photo and when the user move the slider less intensity the value is 1 and
// when  more intensity the value is -1.
//*********************************************************************************************************
function SetIntensity(num)
{
	EZChannel = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID);

	AlphaMin = EZChannel.AlphaMin;
	AlphaMax = EZChannel.AlphaMax;
	AlphaStep = EZChannel.AlphaStep;

	CurAlpha = EZChannel.Alpha + (EZChannel.AlphaStep * num);
	if(CurAlpha < AlphaMin)
		CurAlpha = AlphaMin;
	if(CurAlpha > AlphaMax)
		CurAlpha = AlphaMax;

	EZChannel.Alpha = CurAlpha;
}

//*********************************************************************************************************
// Function name: SetIntensityByPercentage
//
// Set the intensity of the product color
// The type of num is integer and the values is the percentage between the min and max alpha.
//*********************************************************************************************************
function SetIntensityByPercentage(num)
{
	EZChannel = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID);
	AlphaMin = EZChannel.AlphaMin;
	AlphaMax = EZChannel.AlphaMax;

	CurAlpha = Math.round(((num / 100) * (AlphaMax-AlphaMin)) + AlphaMin );
	EZChannel.Alpha = 255 - CurAlpha;
}

//*********************************************************************************************************
// Function name: LoadModelPhoto
//
// Load model photo to the ActiveX by model ID
//*********************************************************************************************************
function LoadModelPhoto(ModelID) {
	intModelCount = EZXObject.DBModelPhotoList(0).Count;
	if(intModelCount > 0 && ModelID != "")
	{
		
		/*if(EZXObjectNails)
			EZXObjectNails.User.ModelPhotoID = ModelID;
		*/
		EZXObject.User.ModelPhotoID = ModelID;
		
	}
}

function LoadFirstModelPhoto(fl)
{
	FirstModelID = EZXObject.DBModelPhotoList(0).Items(0).ID;
	LastModelID = EZXObject.DBModelPhotoList(0).Count-1;
	PrevModelID = EZXObject.User.ModelPhotoID;
	if(PrevModelID==FirstModelID){
		LoadModelPhoto(LastModelID);
	}else{
		LoadModelPhoto(FirstModelID);
	}

	if(fl)
	{
		setTimeout("LoadUserPhotos(0);", 500);
	}
}

//*********************************************************************************************************
// Function name: RemoveLastProduct
//
// Remove the last product from model photo
//*********************************************************************************************************
function RemoveLastProduct()
{
	intCurrentChannel = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID).ID;
	if(intCurrentChannel > -1)
	{
		intChannelIndex = EZXObject.Bitmap.VisibleChannelIndexByID(intCurrentChannel);
		if(intChannelIndex > -1)
		{
			if(EZXObject.Bitmap.ChannelVisible(intChannelIndex))
			{
				EZXObject.Bitmap.Clear(intChannelIndex);
				//DeleteEZTempLook();
				//SaveEZTempLook();
			}
		}
	}
	generateUsedProds();
}

//*********************************************************************************************************
// Function name: RemoveProductByID
//
// Remove product from model photo by product ID
//*********************************************************************************************************
function RemoveProductByID(ProductID)
{
	for(i = 0; i < EZXObject.Bitmap.ChannelCount; i++)
	{
		if(EZXObject.Bitmap.ChannelSubProductID(i) == ProductID)
		{
			EZXObject.Bitmap.Clear(i);
			//DeleteEZTempLook();
			//SaveEZTempLook();
		}
	}
}

//*********************************************************************************************************
// Function name: IsEZfaceActiveXInstalled
//
// Check if EZface ActiveX installed on the computer
//*********************************************************************************************************
function IsEZfaceActiveXInstalled()
{
	if (EZfaceActiveXInstalled) {
		//fixes memory leak
		return EZfaceActiveXInstalled;
	}
	try{
		EZFaceControlX = new ActiveXObject("EZFaceW.EZFaceControlX210");
	}catch(ex){
		EZfaceActiveXInstalled = false
		return false;
	}

	Ver = EZFaceControlX.Registry.Version;
	if(Ver < 209) { EZfaceActiveXInstalled = false;return false; }

	rr = EZFaceControlX.SetSourceID(strSourceID);
	if(!rr) rr = EZFaceControlX.CreateSource(strSourceID, "", "", strSourceName);
	if(rr){
		EZFaceControlX.SourceID = strSourceID;
		EZFaceControlX.Brand = strBrand;
		EZFaceControlX.Source.ASPExt=".jsp";
		if(!EZFaceControlX.UserLogin(strGuestUserLogin,strGuestUserPassword))
			EZFaceControlX.CreateUser(strGuestUserID, strGuestUserLogin, strGuestUserPassword, -1, -1);
	}
	EZfaceActiveXInstalled = true;
	return true;

}

//*********************************************************************************************************
// Function name: ChangeChannelID
//
// Change channel ID
//*********************************************************************************************************
function ChangeChannelID(ChannelID)
{
	intChannelID = ChannelID;
}

//*********************************************************************************************************
// Function name: ActivateEZfaceInstallationSystem
//
// Install or upgrade EZface ActiveX
// This function must have the user login (email or GUID) and password.
//*********************************************************************************************************
function ActivateEZfaceInstallationSystem()
{
	window.location.href = "/connect/makeupmirror/installer.jsp";
}


function SendPhoto(){
	rc = EZXObject.Bitmap.LoadPhoto("C:\\");
	if(rc == 0)	{
		EZXObject.Bitmap.TransReset();
		scaleVal = Math.min ((240/EZXObject.Bitmap.Width), (238/EZXObject.Bitmap.Height));
		EZXObject.Bitmap.TransScale = scaleVal;
		EZXObject.Bitmap.TransRequired = true;
		Upload();
	}else if(rc == -2) {
		document.getElementById("txtSendPhoto").value = "";
	}else{
		if(rc == -1) ("Failed to load\nUnknown error");
		else if(rc == -3) ("Failed to load\nThe photo format you tried to upload is not supported.");
		else if(rc == -4) ("Failed to load\nThe photo size you have defined is too small.");
		else if(rc == -5) ("Failed to load\nThe photo size you have defined is too big.");
		else if(rc == -6) ("Failed to load\nFile corrupted");
		else if(rc == -7) ("Failed to load\nNumber of colors must be at least 256.");
		else if(rc == -8) ("Failed to load\nGrayscale picture");
		else if(rc == -9) ("Failed to load\nThe photo size you have defined is too big.");
		else ("Failed to load\nUnknown error");
		document.getElementById("txtSendPhoto").value = "";
		//setTimeout("LoadFirstModelPhoto(0);", 500);
	}
}

function Upload()
{
	var objSendPhoto = document.getElementById("txtSendPhoto");
	SendPhotoName = objSendPhoto.value;
	objSendPhoto.value = "";
	rc = EZXObject.Bitmap.UploadPhoto(strUploadPhotoPath, 2, SendPhotoName);
	if 	(rc==0) {
		("You photo has been sent.\nWe will do our outmost to process it within 24 hrs");
		//EZXObject.Bitmap.TransScale = 1;
		EZXObject.Bitmap.TransRequired = false;
		setTimeout("LoadFirstModelPhoto(1);", 500);
	}else{
		if(rc==-50) ("Your photo is being processed,\nplease wait until it is available\nbefore uploading another one.");
		else if(rc==-1) ("Failed to upload\nConnection to server failed.");
		else if(rc==-2) ("Failed to upload\nOperation cancelled by User.");
		else if(rc==-3) ("Failed to upload\nThe uploaded photo size is too small.");
		else if(rc==-4) ("Failed to upload\nThe uploaded photo size is too big.");
		else if(rc==-51) ("Failed to upload\nOther DB error.");
		else ("Failed to upload\nUnknown error");
		//EZXObject.Bitmap.TransScale = 1;
		EZXObject.Bitmap.TransRequired = false;
		setTimeout("LoadFirstModelPhoto(0);", 500);
	}
}


intModelID = 1;
function ChangeModel(num)
{
	intModelID += num;
	if(intModelID<1) intModelID=15;
	if(intModelID>15) intModelID=1;
	LoadModelPhoto(intModelID);
}

function ApplyProductColor(ezFaceProdParams) {
	try {
		ezFaceProdId = ezFaceProdParams.split(":");
	
		strSuperProdID = ezFaceProdId[0];
		strSubProdID = ezFaceProdId[1];

		try {
			openMiniVMO()
		}catch(err) {
			closeVMOTab();
		}
	
		LoadProductShades();	

	
		if ($('intbar')) {
			SubColor = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBSubProductList.ItemsByID(strSubProdID).ColorHex;
		
			R = SubColor.substring(1,3);
			G = SubColor.substring(3,5)
			B = SubColor.substring(5,7)
			mycolor = "0x" + B + G + R;
			document.intbar.SetVariable("_level0.sColor", mycolor);
		
			SliderAplha = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID).Alpha;
			document.intbar.SetVariable("_level0.sAlpha", SliderAplha);
		}
		if (strSuperProdID && strSubProdID) {
			ApplyColor(strSubProdID);
		}
	} catch(err) {}
}

function SetChannelID()
{
	intSelectedChannelID = frmEZfaceActiveX.cmbChannels.options[frmEZfaceActiveX.cmbChannels.selectedIndex].value;
	ChangeChannelID(intSelectedChannelID);
	frmEZfaceActiveX.cmbSubProducts.selectedIndex = -1;
}

function SetProductIntensity(num)
{
	SetIntensity(num);
	window.document.forms['frmEZfaceActiveX'].txtAlpha.value = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID).DBChannelList.Items(intChannelID).Alpha;
}

function LoadProductShades()
{

	if (!strSuperProdID) {
		alert('No SuperProdId')
		return;
	}
	//try{
	EZSuper = EZXObject.DBSuperProductList.ItemsByID(strSuperProdID);
		if ($('dvModels')) {
			$('vmoPreloaderStatus').innerHTML = 'Loading Models...'
			setTimeout("LoadModels();", 500);
		}
	//} catch(err) {}

}

function ApplyModel(strModelID, el) {
	if (el) {
		dvModel = $('dvModels').getElementsByClassName('tabModelContainer')
		dvModel = $('dvModels').getElementsByClassName('tabModelContainer')
		for(x=0;x<dvModel.length;x++) {
			dvModel[x].style.border='none';
		}
		el.style.border='2px solid #3399FF'
	}
	AjaxVMO.vmoStartFlag(1);
	LoadModelPhoto(strModelID);
}

function LoadModels()
{
	if ($('dvModels')) {
		$('dvModels').innerHTML = "";
		strImagePath = EZXObject.Source.ImagePath;
		EZModel = EZXObject.DBModelPhotoList(0);
		EZCount = EZModel.Count;
		strModels = '';
		//(EZCount);
		x=1;
		for(i=0;i<EZCount;i++){
			EZModelItem = EZModel.Items(i);

			EZModelID = EZModelItem.ID;
			EZModelName = EZModelItem.Name;
			EZModelFileName = strImagePath + EZModelItem.JPGFileName;
			if (x%2==0 || x==0) strModels+='<div>'
			strModels+='<div id="dvModel'+EZModelID+'" class="tabModelContainer" onclick="ApplyModel(\'' + EZModelID + '\', this);return false;"><img src="'+ EZModelFileName +'" border="0" width="75" height="83" /></div>'
			if (x%2==0 || x==0) strModels+='<div class="clear">&nbsp;</div></div>'
			x++;
		}
		$('dvModels').innerHTML = strModels;
		$('vmoPreloaderStatus').innerHTML = 'Loading CG Looks...'
		setTimeout("LoadHotlooks();", 500);
	}
}

function LoadHotlooks()
{

	EZXObject.User.HotLookList.LoadFromDBProxy();
	dvHotlooks.innerHTML = "";
	strImagePath = EZXObject.Source.ImagePath+'modelphotos/';
	EZHotlook = EZXObject.User.HotLookList;
	EZCount = EZHotlook.Count;
	strHotlooks = "";
	//(EZCount);
	for(i=0;i<EZCount;i++){
		EZHotlookItem = EZHotlook.Items(i);

		EZHotlookID = EZHotlookItem.ID;
		EZHotlookName = EZHotlookItem.Name;
		EZHotlookFileName = strImagePath + EZHotlookItem.JPGFileName;

		strHotlooks+= '<div>'
		strHotlooks+= '<div class="dvHotlook" id="dvHotlook' + EZHotlookID + '" onclick="ApplyHotLookByID(\''+EZHotlookID+'\', this.id);return false;" style="background:transparent url('+EZHotlookFileName+') no-repeat;width:75px;height:76px;margin-bottom:10px;cursor:pointer;float:left;"></div>';
		strHotlooks+= '<div style="float:left;margin-left:5px">'
		strHotlooks+= '<div>'+EZHotlookName+'</div><div onclick="ApplyHotLookByID(\''+EZHotlookID+'\', \'dvHotlook' + EZHotlookID + '\');return false;" style="color:#FF6600;font-weight:bold;cursor:pointer;padding:1px">Apply</div>'
		strHotlooks+= '</div><div class="clear"></div>'
		strHotlooks+= '</div>'					

		//strHotlooks+= '<a href="#" onclick="ApplyHotLookByID('+ EZHotlookID +', "dvHotlook"'+ EZHotlookID + '\" );return false;">';
		//strHotlooks+= "<img src='"+ EZHotlookFileName +"' border=0 title='"+EZHotlookName+"'></A></div>";

	}
	dvHotlooks.innerHTML = strHotlooks;
	setTimeout("LoadUserLooks(1);", 500);
}

function SaveUserLook(){
		try {
			if (document.getElementById("txtSaveLook").value) {
				var objSaveUserLook = document.getElementById("txtSaveLook");
				UserLookName = objSaveUserLook.value;
				EZXObject.User.LookList.Add(UserLookName).SaveToStream();
				objSaveUserLook.value = "";
				$('saveLookBody').innerHTML = "Your Look has been saved.";
				setTimeout("LoadUserLooks(0);", 500);
				setTimeout("$('saveLookContainer').style.display='none'", 3000);
			} else {
				$('saveLookBody').innerHTML = "Please enter a look title.";
				x = 'Look Title: <input type="text" id="txtSaveLook" name="txtSaveLook"  lang="10" maxlength="10" width="10"> <br /><input type="button" value="Save" onclick="SaveUserLook();" />';
				setTimeout("$('saveLookBody').innerHTML="+x, 5000);
			}
		} catch (err) {
			$('saveLookBody').innerHTML = "Sorry, an error occurred while saving your look."
		}

}

function DeleteUserLook(strUserLook){
	if(confirm("Delete this look?")){
		EZXObject.User.LookList.Delete(strUserLook);
		setTimeout("LoadUserLooks(0);", 500);
	}
}

function DeleteUserPhoto(strUserPhoto){
	if(confirm("Delete Photo?")){
		UpdateFlag = EZXObject.User.PhotoList(0).Delete(strUserPhoto);
		if(UpdateFlag==-2) LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
		setTimeout("LoadUserPhotos(0);", 500);
	}
}

function ApplyUserLook(strUserLook)
{
	AjaxVMO.vmoStartFlag(1);
	EZXObject.User.LookIndex = strUserLook;
	
	if ($('rightCol').style.display!='block') $('rightCol').style.display='block'
	generateUsedProds();
}

function LoadUserLooks(fl)
{

	dvUserLooks.innerHTML = "";
	strImagePath = EZXObject.Source.ImagePath;
	EZUserLook = EZXObject.User.LookList;
	EZCount = EZUserLook.Count;
	strUserLooks = '';
	//(EZCount);
	for(i=0;i<EZCount;i++){
		EZUserLookItem = EZUserLook.Items(i);

		EZUserLookName = EZUserLookItem.Name;
		EZUserLookFileName = EZUserLookItem.ThumbnailFileName;

		strUserLooks+='<div>'
		+'<div id="dvUserLook"'+ i +'" style="float:left;margin:0 10px 10px 0;width:73px;height:80px;background:transparent url('+EZUserLookFileName+') no-repeat;" onclick="ApplyUserLook(\''+ i +'\');return false;">'
		+'</div>'
		+'<div style="float:left;">'
			+'<div>'+EZUserLookName+'</div>'
			+'<div style="font-weight:bold;color:#FF6600;"><span onclick="ApplyUserLook(\''+ i +'\');return false;" style="text-decoration:underline;cursor:pointer;">TRY</span> OR <span onclick="DeleteUserLook(\''+ i +'\');return false;" style="text-decoration:underline;cursor:pointer">DELETE</span></div>'
		+'</div>'
		+'<div class="clear"></div>'
		+'</div>'
/*
		strUserLooks+= "<td><table><tr><td><div id='dvUserLook" + i + "'>";
		strUserLooks+= "<a href='#' onclick='ApplyUserLook(\"" + i + "\");return false;'>";
		strUserLooks+= "<img src='"+ EZUserLookFileName +"' border=0 title='"+EZUserLookName+"'></A></div></td></tr>";
		strUserLooks+= "<tr><td align=center><a href='#' onclick='DeleteUserLook(\"" + i + "\");return false;'>Delete</a></td></tr></table></td>";
		*/
	}
	dvUserLooks.innerHTML = strUserLooks;
	dvUserLooks.style.borderBottom ="";
	dvUserLooks.style.borderLeft = "";
	dvUserLooks.style.borderRight = "";
	dvUserLooks.style.borderTop = "";
	$('vmoPreloaderStatus').innerHTML = 'Loading User Photos...'
	if(fl) setTimeout("LoadUserPhotos(1);", 500);
}

function ApplyUserPhoto(strUserPhoto, el) {
	if (el) {
		userDv = $('dvUserPhotos').getElementsByClassName('userPhotoContainer');
		for(x=0;x<userDv.length;x++) {
			userDv[x].style.border = 'none';
		}
		el.style.border = '2px solid #3399FF';
	}
	//(strUserPhoto+","+strPhotoStatus);
	try {
	AjaxVMO.vmoStartFlag(1);
	} catch(err){}
	EZXObject.User.PhotoIndex = strUserPhoto;
}

function LoadUserPhotos(fl)
{
	try {
		dvUserPhotos.innerHTML = "";
		strImagePath = EZXObject.Source.ImagePath;
		UpdateFlag = EZXObject.User.PhotoListUpdate();
		if(UpdateFlag==-2) LoadModelPhoto(EZXObject.DBModelPhotoList(0).Items(0).ID);
		EZUserPhoto = EZXObject.User.PhotoList(0);
		EZCount = EZUserPhoto.Count;
		strUserPhotos = "";
		//(EZCount);
		for(i=0;i<EZCount;i++){
			EZUserPhotoItem = EZUserPhoto.Items(i);
			PhotoStatus = EZUserPhotoItem.Status;
			RejectCauses = EZUserPhotoItem.RejectCauses;
			EZUserPhotoName = EZUserPhotoItem.Name;
			if (PhotoStatus==4){
				//good photo
				EZUserPhotoFileName = EZUserPhotoItem.ThumbnailFileName;
				strUserPhotos+='<div class="userPhoto">'
				strUserPhotos+='<div id="dvUserPhoto"' + i + ' onclick="ApplyUserPhoto(\'' + i + '\', this);return false;" class="userPhotoContainer" style="cursor:pointer;width:75px;height:83px;"><img src="/global/images/spacer.gif" style="height:100%; width:100%;background:transparent url('+EZUserPhotoFileName+') no-repeat 0% 0%" /></div>'
				strUserPhotos+='<div align="center" style="font-size:1em;cursor:pointer;" onclick="DeleteUserPhoto('+ i +');return false;">[ <span style="text-decoration:underline;">DELETE</span> ]</div>'
				strUserPhotos+='</div>'
				//strUserPhotos+= "<td><table><tr><div id='dvUserPhoto" + i + "'><td>";
				//strUserPhotos+= "<a href='#' onclick='ApplyUserPhoto(\"" + i + "\");return false;'>";
				//strUserPhotos+= "<img width=133 height=178 src='"+ EZUserPhotoFileName +"' border=0 title='"+EZUserPhotoName+"'></A></td></div></tr>";
				//strUserPhotos+= "<tr><td align=center><a href='#' onclick='DeleteUserPhoto(\"" + i + "\");return false;'>Delete</a></td></tr></table></td>";
			}else if (PhotoStatus==3){
				//rejected photo
				strUserPhotos+='<div class="userPhoto">'
				strUserPhotos+='<div id="dvUserPhoto"' + i + ' style="height:82px;border:1px solid #CCCCCC;">Your photo was rejected with causes: '+RejectCauses+'</div>'
				strUserPhotos+='<div align="center" style="font-size:1em;cursor:pointer;" onclick="DeleteUserPhoto('+ i +');return false;">[ <span style="text-decoration:underline;">DELETE</span> ]</div>'
				strUserPhotos+='</div>'

				//strUserPhotos+= "<td><table><tr><div id='dvUserPhoto" + i + "'><td>";
				//strUserPhotos+="<table width=133 height=178 width=100% height=100% border=1 cellpadding=3 cellspacing=3>";
				//strUserPhotos+="<tr><td align=center>Your photo was rejected with causes: "+RejectCauses+"</td></tr></table>";
				//strUserPhotos+= "</td></div></tr>";
				//strUserPhotos+= "<tr><td align=center><a href='#' onclick='DeleteUserPhoto(\"" + i + "\");return false;'>Delete</a></td></tr></table></td>";
			}else if (PhotoStatus==2){
				//being process
				strUserPhotos+='<div class="userPhoto">'
				strUserPhotos+='<div id="dvUserPhoto"' + i + ' style="height:82px;border:1px solid #CCCCCC;">Your photo is being processed</div>'
				strUserPhotos+='<div align="center" style="font-size:1em;cursor:pointer;" onclick="DeleteUserPhoto('+ i +');return false;">[ <span style="text-decoration:underline;">DELETE</span> ]</div>'
				strUserPhotos+='</div>'

				//strUserPhotos+= "<td><table><tr><div id='dvUserPhoto" + i + "'><td>";
				//strUserPhotos+="<table width=133 height=178 width=100% height=100% border=1 cellpadding=3 cellspacing=3>";
				//strUserPhotos+="<tr><td align=center>Your photo is being processed</td></tr></table>";
				//strUserPhotos+= "</td></div></tr>";
				//strUserPhotos+= "<tr><td align=center>&nbsp;</td></tr></table></td>";
			}
		}
		if (strUserPhotos) {
			$('uploadUserPhotos').style.display='none';
			$('tabHdrCopy').innerHTML = '<div class="tabLink" style="cursor:pointer;position:relative;" onclick="showUploadInstructions()">[ <span style="text-decoration:underline;">UPLOAD NEW PHOTO</span> ]</div>'
			dvUserPhotos.innerHTML = strUserPhotos+'<div style="clear:both;"></div>';
		}
		
	} catch(err){}
}

//*********************************************************************************************************
// Function name: DeleteDiskCache
//
// This function deleting the cache folder in C:\Program Files\EZFace\ActiveX\Cache.
// Very important using this function on live site will delete all the time all model/user photo from ActiveX cache
// and you will not use the caching mechanism of the ActiveX that allow the user to use again the user/model photos
// without downloading photos all the time.
//*********************************************************************************************************
function DeleteDiskCache()
{
	EZXObject.DeleteDiskCache();
}

//*********************************************************************************************************
// Send to a friend section
//*********************************************************************************************************

function SendMail()
{
	var mailErr = 0;
	var strLocalActiveXPath = EZXObject.Registry.LocalPath;
	
	var emailFormat = document.getElementById('emailFormat').value;
	
	strNameTo = "&txtNameTo1="+document.getElementById('txtNameTo1').value;
	strNameTo += "&txtNameTo2="+document.getElementById('txtNameTo2').value;	
	strNameTo += "&txtNameTo3="+document.getElementById('txtNameTo3').value;
			
	var strMailTo = document.getElementById("txtMailTo1").value;
	if (strMailTo == "") 
	{
		alert("Please include your friend's e-mail address, so we know where to send the message.");
		mailErr = 1;	   
	}
	else if (!EmailAddressValidation(strMailTo))
	{
		alert("Your friend's e-mail address does not seem to be valid. Please retype your friend's e-mail address and try again.");
		mailErr = 1;
	}
	
	if (mailErr ==0) { closeTAF() } else { return }
	
	strMailTo = "&mailTo=" + strMailTo;
	var strMailTo2 = document.getElementById("txtMailTo2").value;
	if (EmailAddressValidation(strMailTo2))
		strMailTo += "&mailTo2=" + strMailTo2;
	var strMailTo3 = document.getElementById("txtMailTo3").value;
	if (EmailAddressValidation(strMailTo3))
		strMailTo += "&mailTo3=" + strMailTo3;
			
	var strBody = document.getElementById("msgBody").value.stripTags();
	var strProductList = GetProductList(emailFormat);
	var strNailImageName = "";
	var strFaceImageName = "";
	if (strUserLogin.length > 0)
	{
		strNailImageName = strUserLogin + "_Nail.jpg";
		strFaceImageName = strUserLogin + "_Face.jpg";
	}
	else
	{
		strNailImageName = strGuestUserLogin + "_Nail.jpg";
		strFaceImageName = strGuestUserLogin + "_Face.jpg";
	}
	
	var strURL_Dll = "http://stage03.ezface.com/upload/upload.dll";
	var bSendImageResult = EZXObjectNails.Bitmap.SaveToServer(strURL_Dll,strNailImageName,1,0.80,0);
	if(bSendImageResult)
	{
		bSendImageResult = EZXObject.Bitmap.SaveToServer(strURL_Dll,strFaceImageName,1,1,0);
		if(bSendImageResult)
		{
			winobj = window.open('about:blank','new', 'width=650,height=488, top=15, left=15');
			var frm = document.getElementById("frmEZfaceActiveX");
	
			if (emailFormat == "text") {
			frm.action =  "http://stage03.ezface.com/ezmail/CG/sendmail_text.asp?" + "pname1=" + strFaceImageName  + "&pname2=" + strNailImageName + "&msgBody=" + strBody + strMailTo + strNameTo +"&productList=" + strProductList;
			}
			else {
			frm.action =  "http://stage03.ezface.com/ezmail/CG/sendmail_html.asp?" + "pname1=" + strFaceImageName  + "&pname2=" + strNailImageName + "&msgBody=" + strBody + strMailTo + strNameTo +"&productList=" + strProductList;
			}
			frm.target = "new";
			frm.submit();
		}
	}
}

function getEmailFormat(val) {
	document.getElementById('emailFormat').value = val;
}

function EmailAddressValidation(EmailAddress) {
	var EmailRegx = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(EmailRegx);
	return regex.test(EmailAddress);
}

function merge(r, g, b){ return (r << 16 | g << 8 | b); }

function GetProductList(emailFormat){
	EZXObject.DBSuperProductList.PreFetch();
	var EZBitmap = EZXObject.Bitmap;
	var strProductListData = "";
	var intChannelCount = EZBitmap.ChannelCount;
	for(i=0; i < intChannelCount; i++)
	{
		bIsChannelVisible = EZBitmap.ChannelUnVisible(i);
		
		if (bIsChannelVisible == 0) 
		{  
			SubProdID = EZBitmap.ChannelSubProductID(i);
			//alert("SubProdID = "+SubProdID);
			SuperProdID = EZBitmap.ChannelSuperProductID(i);
			if (SuperProdID != "" && SubProdID != "")
			{ 
				bIsChannelSuperProduct = EZBitmap.ChannelSuperProduct(i);
				
				strSubCategory = "undefined";
				if (bIsChannelSuperProduct) 
				{
					bIsChannelSubProduct = EZBitmap.ChannelSubProduct(i);
					//alert("bIsChannelSubProduct = "+bIsChannelSubProduct);
					strSuperProdName = EZBitmap.ChannelSuperProduct(i).Name;
					strColor = EZBitmap.ChannelColor(i);
					//alert("strColor = "+strColor);
					strSubCategory = EZBitmap.ChannelSubCategoryName(i);
					if (bIsChannelSubProduct) 
					{
						strSubProdName = EZBitmap.ChannelSubProduct(i).Name;
					}
					else 
					{
						strSuperProdName="";
						strSubProdName = "This product is not currently available";
					}
				}
				else 
				{
					strSuperProdName="";
					strSubProdName = "This product is not currently available";
				}
				if (emailFormat == "text") {
						strProductListData += strSuperProdName;
						strProductListData += " - ";
						strProductListData += strSubProdName;
						strProductListData += " ; ";
				}
				else{
		
					start_red = strColor >> 16;
					start_green = (strColor & 0x00FF00) >> 8;
					start_blue = strColor & 0x0000FF;
					mycolor = (merge(start_blue, start_green, start_red)).toString(16);
					Fullrgb = "000000";
					mycolor = Fullrgb.substring(0, 5 - mycolor.length + 1) + mycolor;
			
					strProductListData += strSuperProdName;
					strProductListData += " - ";
					strProductListData += strSubProdName;
					strProductListData += "<input style='WIDTH: 20px; CURSOR: default; HEIGHT: 20px; BACKGROUND-COLOR:"+ mycolor +"'  type=image src='dot.gif'>";
					strProductListData += "<br>";
				}
			}
		}
	}
	return strProductListData;
}