﻿function GetUrlBase() {
	var result = window.location.toString().replace("http://","");
	result = result.substr(0,result.indexOf("/"));
	return result;
}

var generalCategoryId = "-1";
var generalLanguageId = "";
var generalFlowerCode = "";

// povoleni nacitani a pouzivani groote
var loadSizes = false;

function NullImagesCounters()
{
	kleursDescriptionCounter = 0;
	lipsDescriptionCounter = 0;
	patroonsDescriptionCounter = 0;
}

// **************************************************************************************************************************
// GROOTE - selection management
// **************************************************************************************************************************

var selectedGrooteId = -1;
var selectedGrooteName = "";
var selectedGrooteIndex = -1;

function ShowGroote(grooteId, grooteName)
{
	if ((grooteId == null) && (grooteName == null))
	{
		document.getElementById("kleurBox").style.display = "none";
		document.getElementById("lipBox").style.display = "none";
		document.getElementById("patroonBox").style.display = "none";
		document.getElementById("resultsBox").style.display = "none";
		return;
	}
	
	selectedGrooteId = grooteId;
	selectedGrooteName = grooteName;
	
	MyCookie.Write("selectedGrooteId",selectedGrooteId,1);
	MyCookie.Write("grooteName",grooteName,1);
		
	for (var i = 0; i < sizesId.length; i++)
	{
		if (sizesId[i] == grooteId)
		{
			selectedGrooteIndex = i;
			break;
		}
	}
		
	NullImagesCounters();
	
	document.getElementById("selectedGrootte1").innerHTML = grooteName; 
	document.getElementById("selectedGrootte2").innerHTML = grooteName +":";
	document.getElementById("selectedGrootte3").innerHTML = grooteName +":";
	document.getElementById("selectedGrootte4").innerHTML = grooteName +":";
	
	document.getElementById("kleurBox").style.display = "block";
	document.getElementById("kleurItems").innerHTML = "<img src=\"/images/loader.gif\" alt=\" \" />";
	document.getElementById("kleurItems").style.display = "block";
	
	document.getElementById("lipBox").style.display = "none";
	document.getElementById("patroonBox").style.display = "none";
	document.getElementById("resultsBox").style.display = "none";
	
	LoadKleurs();
}

// **************************************************************************************************************************
// KLEUR - selection management
// **************************************************************************************************************************

var selectedKleurId = -1;
var selectedKleurName = "";
var selectedKleurIndex = -1;

function ShowKleur(kleurId, kleurName)
{
	if ((kleurId == null) && (kleurName == null))
	{
		document.getElementById("lipBox").style.display = "none";
		document.getElementById("patroonBox").style.display = "none";
		document.getElementById("resultsBox").style.display = "none";
		return;
	}
	
	selectedKleurId = kleurId;
	selectedKleurName = kleurName;
	
	MyCookie.Write("selectedKleurId",selectedKleurId,1);
	MyCookie.Write("selectedKleurName",selectedKleurName,1);
	
	for (var i = 0; i < kleursId.length; i++)
	{
		if (kleursId[i] == kleurId)
		{
			selectedKleurIndex = i;
			break;
		}
	}
	
	NullImagesCounters();
	
	document.getElementById("selectedKleur1").innerHTML = kleurName;
	document.getElementById("selectedKleur2").innerHTML = kleurName +":";
	document.getElementById("selectedKleur3").innerHTML = kleurName +":";
	
	document.getElementById("lipBox").style.display = "block";
	document.getElementById("lipItems").innerHTML = "<img src=\"/images/loader.gif\" alt=\" \" />";
	document.getElementById("lipItems").style.display = "block";
	
	document.getElementById("patroonBox").style.display = "none";
	document.getElementById("resultsBox").style.display = "none";
	
	LoadLips();
}

// **************************************************************************************************************************
// LIP - selection management
// **************************************************************************************************************************

var selectedLipId = -1;
var selectedLipName = "";
var selectedLipIndex = -1;

function ShowLip(lipId, lipName)
{
	if ((lipId == null) && (lipName == null))
	{
		document.getElementById("patroonBox").style.display = "none";
		document.getElementById("resultsBox").style.display = "none";
		return;
	}
	
	selectedLipId = lipId;
	selectedLipName = lipName;
	
	MyCookie.Write("selectedLipId",selectedLipId,1);
	MyCookie.Write("selectedLipName",selectedLipName,1);
	
	for (var i = 0; i < lipsId.length; i++)
	{
		if (lipsId[i] == lipId)
		{
			selectedLipIndex = i;
			break;
		}
	}
	
	NullImagesCounters();
	
	document.getElementById("selectedLip1").innerHTML = lipName;
	document.getElementById("selectedLip2").innerHTML = lipName +":";
	
	document.getElementById("patroonBox").style.display = "block";
	document.getElementById("patroonItems").innerHTML = "<img src=\"/images/loader.gif\" alt=\" \" />";
	document.getElementById("patroonItems").style.display = "block";
	
	document.getElementById("resultsBox").style.display = "none";
	
	LoadPatroons();
}

// **************************************************************************************************************************
// PATROON - selection management
// **************************************************************************************************************************

var selectedPatroonId = -1;
var selectedPatroonName = "";
var selectedPatroonIndex = -1;

function ShowPatroon(patroonId, patroonName)
{
	if ((patroonId == null) && (patroonName == null))
	{
		document.getElementById("resultsBox").style.display = "none";
		return;
	}
	
	selectedPatroonId = patroonId;
	selectedPatroonName = patroonName;
	
	MyCookie.Write("selectedPatroonId",selectedPatroonId,1);
	MyCookie.Write("selectedPatroonName",selectedPatroonName,1);
	
	for (var i = 0; i < patroonsId.length; i++)
	{
		if (patroonsId[i] == patroonId)
		{
			selectedPatroonIndex = i;
			break;
		}
	}
	
	NullImagesCounters();
	
	document.getElementById("selectedPatroon1").innerHTML = patroonName;
	
	document.getElementById("resultsBox").style.display = "block";
	document.getElementById("resultItems").innerHTML = "<img src=\"/images/loader.gif\" alt=\" \" />";
	document.getElementById("resultItems").style.display = "block";
	
	LoadResults();
}

// **************************************************************************************************************************
// Getting info texts for extended searching
// **************************************************************************************************************************

function LoadTexts(languageId, categoryCode)
{
	generalFlowerCode = categoryCode;
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=00-search-texts&languageid="+ languageId +"&categorycode='"+ categoryCode +"'");
        LoadTextsProcess();
    }
    else
    {
        window.setTimeout("LoadTexts('"+languageId+"','"+categoryCode+"');", 10);
    }
}

function LoadTextsProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadTextsProcess();", 10);
    }
    else
    {
		var items = ajaxResultsXML.getElementsByTagName("item");
		if (items.length > 0)
		{
			var vals = items[0].attributes.getNamedItem("content").nodeValue;
			
			while (vals.indexOf("<hr />") > -1) { vals = vals.replace("<hr />", "<hr/>"); }
			while (vals.indexOf("&lt;hr/&gt;") > -1) { vals = vals.replace("&lt;hr/&gt;", "<hr/>"); }
			while (vals.indexOf("&lt;hr/ &gt;") > -1) { vals = vals.replace("&lt;hr/ &gt;", "<hr/>"); }
			while (vals.indexOf("<hr>") > -1) { vals = vals.replace("<hr>", "<hr/>"); }
			while (vals.indexOf("<HR />") > -1) { vals = vals.replace("<HR />", "<hr/>"); }
			
			vals = vals.split("<hr/>");
			
			var globalText  = RemoveHeader((vals.length >= 1 ? vals[0] : "")) +"<br />";
			var grootteText = RemoveHeader((vals.length >= 2 ? vals[1] : "")) +"<br />";
			var kleurText   = RemoveHeader((vals.length >= 3 ? vals[2] : "")) +"<br />";
			var lipText     = RemoveHeader((vals.length >= 4 ? vals[3] : "")) +"<br />";
			var patroonText = RemoveHeader((vals.length >= 5 ? vals[4] : "")) +"<br />";
			var resultText  = RemoveHeader((vals.length >= 6 ? vals[5] : "")) +"<br />";
		
			if (document.getElementById("shortCatContent") != null) document.getElementById("shortCatContent").innerHTML = globalText;
			if (document.getElementById("grootteText") != null) document.getElementById("grootteText").innerHTML = grootteText;
			if (document.getElementById("kleurText") != null) document.getElementById("kleurText").innerHTML = kleurText;
			if (document.getElementById("lipText") != null) document.getElementById("lipText").innerHTML = lipText;
			if (document.getElementById("patroonText") != null) document.getElementById("patroonText").innerHTML = patroonText;
			//if ( != null) document.getElementById("resultsText").innerHTML = resultText;
			if (document.getElementById("resultsText") != null) document.getElementById("resultsText").innerHTML = "";
		}
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
    }
}

function RemoveHeader(text)
{
	var result = text;
	if (result.indexOf("</h2>") > -1)
	{
		result = result.substring(result.indexOf("</h2>") + 5);
	}
	return result;
}

// **************************************************************************************************************************
// GETTING FILE NAMES OF PHOTOS FOR EXTENDED SEARCH
// **************************************************************************************************************************

var kleurFiles = new Array();
var lipFiles = new Array();
var patroonFiles = new Array();

function LoadKleurFiles()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/filelist.aspx?directory=/images/photosearch/03_kleur/");
        LoadKleurFilesProcess();
    }
    else
    {
        window.setTimeout("LoadKleurFiles();", 10);
    }
}

function LoadKleurFilesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadKleurFilesProcess();", 10);
    }
    else
    {
		kleurFiles = ajaxResultsText.split("|");
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
    }
}

function LoadLipFiles()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/filelist.aspx?directory=/images/photosearch/04_lip/");
        LoadLipFilesProcess();
    }
    else
    {
        window.setTimeout("LoadLipFiles();", 10);
    }
}

function LoadLipFilesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadLipFilesProcess();", 10);
    }
    else
    {
		lipFiles = ajaxResultsText.split("|");
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
    }
}

function LoadPatroonFiles()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/filelist.aspx?directory=/images/photosearch/05_patroon/");
        LoadPatroonFilesProcess();
    }
    else
    {
        window.setTimeout("LoadPatroonFiles();", 10);
    }
}

function LoadPatroonFilesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadPatroonFilesProcess();", 10);
    }
    else
    {
		patroonFiles = ajaxResultsText.split("|");
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
    }
}


// **************************************************************************************************************************
// GROOTE
// **************************************************************************************************************************

var sizesId = new Array();
var sizesName = new Array();
var sizesDescription = new Array();
var sizesCount = 0;

function LoadSizes(languageId, categoryId)
{
    if (!ajaxLoadingData && (kleurFiles.length > 0) && (lipFiles.length > 0) && (patroonFiles.length > 0))
    {
		if (!loadSizes)
		{
			document.getElementById("grooteBox").style.display = "none";
			document.getElementById("selectedGrootte1").style.display = "none";
			document.getElementById("selectedGrootte2").style.display = "none";
			document.getElementById("selectedGrootte3").style.display = "none";
			document.getElementById("selectedGrootte4").style.display = "none";
			document.getElementById("kleurBoxSelectionPath").style.display = "none";
			
			generalCategoryId = categoryId;
			generalLanguageId = languageId;
			ShowGroote(-1, '');
			return;
		}
		
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=01-search-grootte&languageid="+ languageId +"&categoryid="+ categoryId);
        LoadSizesProcess();
    }
    else
    {
        window.setTimeout("LoadSizes('"+languageId+"','"+categoryId+"');", 10);
    }
}

function LoadSizesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadSizesProcess();", 10);
    }
    else
    {
		sizesId = new Array();
		sizesName = new Array();
		sizesDescription = new Array();
	
		var obj = document.getElementById("grootteItems");
		obj.innerHTML = ""
		var items = ajaxResultsXML.getElementsByTagName("item");
		sizesCount = items.length;
		if (items.length > 0)
		{
			var content = "";
			for (var i = 0; i < items.length; i++)
			{
				sizesId[i] = items[i].attributes.getNamedItem("id").nodeValue;
				sizesName[i] = items[i].attributes.getNamedItem("name").nodeValue;
				sizesDescription[i] = items[i].attributes.getNamedItem("description").nodeValue;
				
				content += "<div class=\"item\" id=\"grooteBlockItem"+ sizesId[i] +"\" style=\"display:none;\">"+
								"<a href=\"javascript:ShowGroote('"+ sizesId[i] +"','"+ sizesName[i] +"');\" id=\"imageSizes"+ sizesId[i] +"\" style=\"display:none;\" class=\"imageLink\">"+
									"<img src=\"\" alt=\""+ sizesName[i] +"\" id=\"imageSizes"+ sizesId[i] +"image\" />"+
								"</a><a href=\"javascript:ShowGroote('"+ sizesId[i] +"','"+ sizesName[i] +"');\" class=\"textLink\">"+ sizesName[i] +"</a></div>";
			}
			obj.innerHTML = content;
		}
		
        //ajaxResultReady = false;
        //ajaxLoadingData = false;
    }
}

// **************************************************************************************************************************
// KLEUR
// **************************************************************************************************************************

var kleursId = new Array();
var kleursName = new Array();
var kleursDescription = new Array();
var kleursCount = 0;
var kleursCategoryId = "-1";
var kleursDescriptionCounter = 0;

function LoadKleurs()
{
    if (!ajaxLoadingData && (kleurFiles.length > 0) && (lipFiles.length > 0) && (patroonFiles.length > 0))
    {
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=02-search-kleur&languageid="+ generalLanguageId +"&categoryid="+ generalCategoryId +"&Attribute11IndexValue="+ selectedGrooteId);
        LoadKleursProcess();
    }
    else
    {
        window.setTimeout("LoadKleurs();", 10);
    }
}

function LoadKleursProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadKleursProcess();", 10);
    }
    else
    {
		kleursId = new Array();
		kleursName = new Array();
		kleursDescription = new Array();
	
		var obj = document.getElementById("kleurItems");
		obj.innerHTML = ""
		var items = ajaxResultsXML.getElementsByTagName("item");
		kleursCount = items.length;
		if (items.length > 0)
		{
			var content = "";
			for (var i = 0; i < items.length; i++)
			{
				kleursId[i] = items[i].attributes.getNamedItem("id").nodeValue;
				kleursName[i] = items[i].attributes.getNamedItem("name").nodeValue;
				kleursDescription[i] = items[i].attributes.getNamedItem("description").nodeValue;
				
				content += "<div class=\"item\" id=\"kleurBlockItem"+ kleursId[i] +"\" style=\"display:none;\">"+
								"<a href=\"javascript:ShowKleur('"+ kleursId[i] +"','"+ kleursName[i] +"');\" id=\"imageKleurs"+ kleursId[i] +"\" class=\"imageLink\" style=\"display:none;\">"+
									"<img src=\"\" alt=\""+ kleursName[i] +"\" id=\"imageKleurs"+ kleursId[i] +"image\" />"+
								"</a><a href=\"javascript:ShowKleur('"+ kleursId[i] +"','"+ kleursName[i] +"');\" class=\"textLink\">"+ kleursName[i] +"</a></div>";
			}
			obj.innerHTML = content;
		}
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
		
		kleursDescriptionCounter = 0;
		LoadKleursImages();
		
		if (mustShowAll)
		{
			var selKleurId = MyCookie.Read("selectedKleurId");
			var selKleurName = MyCookie.Read("selectedKleurName");
			ShowKleur(selKleurId, selKleurName);
		}
    }
}

function LoadKleursImages()
{
	for (var i = 0; i < kleursDescription.length; i++)
	{
		var existsInKleur = false;
		var existsInLip = false;
		var existsInPatroon = false;
		
		for (var y = 0; y < kleurFiles.length; y++)
		{
			if (kleurFiles[y] == generalFlowerCode.toLowerCase() + "x" + kleursDescription[i].toLowerCase() + "mm.jpg")
			{
				existsInKleur = true;
			}
		}

		for (var y = 0; y < lipFiles.length; y++)
		{
			if ((lipFiles[y].substring(5,lipFiles[y].length-1).indexOf(kleursDescription[i].toLowerCase()) == 0)
				&& (lipFiles[y].indexOf(generalFlowerCode.toLowerCase()) > -1))
			{
				existsInLip = true;
			}
		}
		
		for (var y = 0; y < patroonFiles.length; y++)
		{
			if ((patroonFiles[y].substring(5,patroonFiles[y].length-1).indexOf(kleursDescription[i].toLowerCase()) == 0)
				&& (patroonFiles[y].indexOf(generalFlowerCode.toLowerCase()) > -1))
				existsInPatroon = true;
		}
		
		if (existsInKleur && existsInLip && existsInPatroon)
		{
			document.getElementById("imageKleurs"+ kleursId[i] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/03_kleur/"+ generalFlowerCode.toLowerCase() + "x" + kleursDescription[i].toLowerCase() + "mm.jpg";
			document.getElementById("imageKleurs"+ kleursId[i]).style.display = "block";
			document.getElementById("kleurBlockItem"+ kleursId[i]).style.display = "block";
		}
	}
	
	window.location = "#kleurSkip4Href";
	
	return;
	// old controll if the files exist
	if (!ajaxLoadingData)
    {
		if (kleursDescriptionCounter < kleursDescription.length)
		{
			AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/fileexist.aspx?file=/images/photosearch/03_kleur/"+ generalFlowerCode + "x" + kleursDescription[kleursDescriptionCounter] + "mm.jpg");
			LoadKleursImagesProcess();
		}
	}
	else
	{
		window.setTimeout("LoadKleursImages();", 10);
	}
}

function LoadKleursImagesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadKleursImagesProcess();", 10);
    }
    else
    {
		if (ajaxResultsText == "1")
		{
			try
			{
				document.getElementById("imageKleurs"+ kleursId[kleursDescriptionCounter] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/03_kleur/"+ generalFlowerCode.toLowerCase() + "x" + kleursDescription[kleursDescriptionCounter].toLowerCase() + "mm.jpg";
				document.getElementById("imageKleurs"+ kleursId[kleursDescriptionCounter]).style.display = "block";
				document.getElementById("kleurBlockItem"+ kleursId[kleursDescriptionCounter]).style.display = "block";
			} catch (exception) {}
		}
			
		kleursDescriptionCounter++;
		ajaxResultReady = false;
		ajaxLoadingData = false;
			
		LoadKleursImages();
    }
}

// **************************************************************************************************************************
// LIP
// **************************************************************************************************************************

var lipsId = new Array();
var lipsName = new Array();
var lipsDescription = new Array();
var lipsCount = 0;
var lipsCategoryId = "-1";
var lipsDescriptionCounter = 0;

function LoadLips()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=03-search-lip&languageid="+ generalLanguageId +"&categoryid="+ generalCategoryId +"&Attribute11IndexValue="+ selectedGrooteId +"&Attribute14IndexValue="+ selectedKleurId);
        LoadLipsProcess();
    }
    else
    {
        window.setTimeout("LoadLips();", 10);
    }
}

function LoadLipsProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadLipsProcess();", 10);
    }
    else
    {
		lipsId = new Array();
		lipsName = new Array();
		lipsDescription = new Array();
	
		var obj = document.getElementById("lipItems");
		obj.innerHTML = ""
		var items = ajaxResultsXML.getElementsByTagName("item");
		lipsCount = items.length;
		if (items.length > 0)
		{
			var content = "";
			for (var i = 0; i < items.length; i++)
			{
				lipsId[i] = items[i].attributes.getNamedItem("id").nodeValue;
				lipsName[i] = items[i].attributes.getNamedItem("name").nodeValue;
				lipsDescription[i] = items[i].attributes.getNamedItem("description").nodeValue;
				
				content += "<div class=\"item\" id=\"lipBlockItem"+ lipsId[i] +"\" style=\"display:none;\">"+
					"<a href=\"javascript:ShowLip('"+ lipsId[i] +"','"+ lipsName[i] +"');\" id=\"imageLips"+ lipsId[i] +"\" class=\"imageLink\" style=\"display:none;\">"+
						"<img src=\"\" alt=\""+ lipsName[i] +"\" id=\"imageLips"+ lipsId[i] +"image\" />"+
					"</a><a href=\"javascript:ShowLip('"+ lipsId[i] +"','"+ lipsName[i] +"');\" class=\"textLink\">"+ lipsName[i] +"</a></div>";
			}
			obj.innerHTML = content;
		}
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
		
		lipsDescriptionCounter = 0;
		LoadLipsImages();
		
		if (mustShowAll)
		{
			var selLipId = MyCookie.Read("selectedLipId");
			var selLipName = MyCookie.Read("selectedLipName");
			ShowLip(selLipId, selLipName);
		}
    }
}

function LoadLipsImages()
{
	for (var i = 0; i < lipsDescription.length; i++)
	{
		var existsInLip = false;
		var existsInPatroon = false;

		for (var y = 0; y < lipFiles.length; y++)
		{		
			if (lipFiles[y] == generalFlowerCode.toLowerCase() + "x" + kleursDescription[selectedKleurIndex].toLowerCase() + lipsDescription[i].toLowerCase() + "m.jpg")
			{
				existsInLip = true;
			}
		}
		
		for (var y = 0; y < patroonFiles.length; y++)
		{
			if ((patroonFiles[y].substring(8,patroonFiles[y].length-1).indexOf(lipsDescription[i].toLowerCase()) == 0)
				&& (patroonFiles[y].indexOf(generalFlowerCode.toLowerCase()) > -1))
				existsInPatroon = true;
		}
		
		if (existsInLip && existsInPatroon)
		{
			document.getElementById("imageLips"+ lipsId[i] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/04_lip/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex].toLowerCase() + lipsDescription[i].toLowerCase() + "m.jpg";
			document.getElementById("imageLips"+ lipsId[i]).style.display = "block";
			document.getElementById("lipBlockItem"+ lipsId[i]).style.display = "block";
		}
	}
	
	window.location = "#lipSkip4Href";
	
	return;
	// old loading by checking files
	if (!ajaxLoadingData)
    {
		if (lipsDescriptionCounter < lipsDescription.length)
		{
			AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/fileexist.aspx?file=/images/photosearch/04_lip/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex] + lipsDescription[lipsDescriptionCounter] + "m.jpg");
			LoadLipsImagesProcess();
		}
	}
	else
	{
		window.setTimeout("LoadLipsImages();", 10);
	}
}

function LoadLipsImagesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadLipsImagesProcess();", 10);
    }
    else
    {
		if (ajaxResultsText == "1")
		{
			try
			{
				document.getElementById("imageLips"+ lipsId[lipsDescriptionCounter] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/04_lip/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex].toLowerCase() + lipsDescription[lipsDescriptionCounter].toLowerCase() + "m.jpg";
				document.getElementById("imageLips"+ lipsId[lipsDescriptionCounter]).style.display = "block";
				document.getElementById("lipBlockItem"+ lipsId[lipsDescriptionCounter]).style.display = "block";
			} catch (exception) {}
		}
		
		lipsDescriptionCounter++;
		
		ajaxResultReady = false;
		ajaxLoadingData = false;
			
		LoadLipsImages();
    }
}

// **************************************************************************************************************************
// PATROON
// **************************************************************************************************************************

var patroonsId = new Array();
var patroonsName = new Array();
var patroonsDescription = new Array();
var patroonsCount = 0;
var patroonsCategoryId = "-1";
var patroonsDescriptionCounter = 0;

function LoadPatroons()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=04-search-patroon&languageid="+ generalLanguageId +"&categoryid="+ generalCategoryId +"&Attribute11IndexValue="+ selectedGrooteId +"&Attribute14IndexValue="+ selectedKleurId +"&Attribute15IndexValue="+ selectedLipId);
        LoadPatroonsProcess();
    }
    else
    {
        window.setTimeout("LoadPatroons();", 10);
    }
}

function LoadPatroonsProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadPatroonsProcess();", 10);
    }
    else
    {
		patroonsId = new Array();
		patroonsName = new Array();
		patroonsDescription = new Array();
	
		var obj = document.getElementById("patroonItems");
		obj.innerHTML = ""
		var items = ajaxResultsXML.getElementsByTagName("item");
		patroonsCount = items.length;
		if (items.length > 0)
		{
			var content = "";
			for (var i = 0; i < items.length; i++)
			{
				patroonsId[i] = items[i].attributes.getNamedItem("id").nodeValue;
				patroonsName[i] = items[i].attributes.getNamedItem("name").nodeValue;
				patroonsDescription[i] = items[i].attributes.getNamedItem("description").nodeValue;
				
				content += "<div class=\"item\" id=\"patroonBlockItem"+ patroonsId[i] +"\" style=\"display:none;\">"+
								"<a href=\"javascript:ShowPatroon('"+ patroonsId[i] +"','"+ patroonsName[i] +"');\" id=\"imagePatroons"+ patroonsId[i] +"\" class=\"imageLink\" style=\"display:none;\">"+
									"<img src=\"\" alt=\""+ patroonsName[i] +"\" id=\"imagePatroons"+ patroonsId[i] +"image\" />"+
								"</a><a href=\"javascript:ShowPatroon('"+ patroonsId[i] +"','"+ patroonsName[i] +"');\" class=\"textLink\">"+ patroonsName[i] +"</a></div>";
			}
			obj.innerHTML = content;
		}
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
		
		patroonsDescriptionCounter = 0;
		LoadPatroonsImages();
		
		if (mustShowAll)
		{
			var selPatroonId = MyCookie.Read("selectedPatroonId");
			var selPatroonName = MyCookie.Read("selectedPatroonName");
			ShowPatroon(selPatroonId, selPatroonName);
		}
    }
}

function LoadPatroonsImages()
{
	for (var i = 0; i < patroonsDescription.length; i++)
	{
		var existsInPatroon = false;
		
		for (var y = 0; y < patroonFiles.length; y++)
		{		
			if (patroonFiles[y] == generalFlowerCode.toLowerCase() + "x" + kleursDescription[selectedKleurIndex].toLowerCase() + lipsDescription[selectedLipIndex].toLowerCase() + patroonsDescription[i].toLowerCase() +".jpg")
			{
				existsInPatroon = true;
			}
		}
		
		if (existsInPatroon)
		{
			document.getElementById("imagePatroons"+ patroonsId[i] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/05_patroon/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex] + lipsDescription[selectedLipIndex] + patroonsDescription[i] + ".jpg";
			document.getElementById("imagePatroons"+ patroonsId[i]).style.display = "block";
			document.getElementById("patroonBlockItem"+ patroonsId[i]).style.display = "block";
		}
	}
	
	window.location = "#patroonSkip4Href";
	
	return;
	// old loading by checking files
	if (!ajaxLoadingData)
    {
		if (patroonsDescriptionCounter < patroonsDescription.length)
		{
			AjaxTransfer("http://"+GetUrlBase()+"/controls/connectors/orchids/fileexist.aspx?file=/images/photosearch/05_patroon/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex] + lipsDescription[selectedLipIndex]+ patroonsDescription[patroonsDescriptionCounter] + ".jpg");
			LoadPatroonsImagesProcess();
		}
	}
	else
	{
		window.setTimeout("LoadPatroonsImages();", 10);
	}
}

function LoadPatroonsImagesProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadPatroonsImagesProcess();", 10);
    }
    else
    {
		if (ajaxResultsText == "1")
		{
			try
			{
				document.getElementById("imagePatroons"+ patroonsId[patroonsDescriptionCounter] +"image").src = "http://"+GetUrlBase()+"/images/photosearch/05_patroon/"+ generalFlowerCode + "x" + kleursDescription[selectedKleurIndex] + lipsDescription[selectedLipIndex] + patroonsDescription[patroonsDescriptionCounter] + ".jpg";
				document.getElementById("imagePatroons"+ patroonsId[patroonsDescriptionCounter]).style.display = "block";
				document.getElementById("patroonBlockItem"+ patroonsId[patroonsDescriptionCounter]).style.display = "block";
			} catch (exception) {}
		}
		
		patroonsDescriptionCounter++;
		
		ajaxResultReady = false;
		ajaxLoadingData = false;
			
		LoadPatroonsImages();
    }
}

// **************************************************************************************************************************
// RESULTS
// **************************************************************************************************************************

function LoadResults()
{
    if (!ajaxLoadingData)
    {
        AjaxTransfer("http://"+GetUrlBase()+"/connector/connectorOrchids.aspx?file=05-search-results&languageid="+ generalLanguageId +"&categoryid="+ generalCategoryId +"&Attribute11IndexValue="+ selectedGrooteId +"&Attribute14IndexValue="+ selectedKleurId +"&Attribute15IndexValue="+ selectedLipId +"&Attribute16IndexValue="+ selectedPatroonId);
        LoadResultsProcess();
    }
    else
    {
        window.setTimeout("LoadResults();", 10);
    }
}

function LoadResultsProcess()
{
    if (!ajaxResultReady)
    {
        window.setTimeout("LoadResultsProcess();", 10);
    }
    else
    {
		var obj = document.getElementById("resultItems");
		obj.innerHTML = "";
		var items = ajaxResultsXML.getElementsByTagName("item");
		resultsCount = items.length;
		var lastItemUrl = -1;
		var showedItemsCount = 0;
		if (items.length > 0)
		{
			var content = "";
			for (var i = 0; i < items.length; i++)
			{
				var id = items[i].attributes.getNamedItem("id").nodeValue;
				var catid = items[i].attributes.getNamedItem("categoryid").nodeValue;
				var name = (items[i].attributes.getNamedItem("name").nodeValue.toString() != "" ? items[i].attributes.getNamedItem("name").nodeValue.toString() : items[i].attributes.getNamedItem("centralname").nodeValue.toString());
				var code = items[i].attributes.getNamedItem("code").nodeValue;
				var src = items[i].attributes.getNamedItem("src").nodeValue;
				
				var url = "/"+ generalLanguageShortcut +"/s346/c"+ catid + "/p"+ id;
				
				if (src != "")
				{
					showedItemsCount++;
					lastItemUrl = url;
					content += "<div class=\"item\" id=\"resultBlockItem\"><a href=\"javascript:MyCookie.Write('backToPhotoSearch','1',1);window.location='"+ url +"';\" id=\"imageResults"+ id +"\" class=\"imageLink\"><img src=\""+ src.replace(".jpg","_small.jpg") +"\" alt=\""+ name +"\" id=\"imageResults"+ id +"image\" /></a><a href=\""+ url +"\" class=\"textLink\">"+ code +"</a></div>";
				}
			}
			obj.innerHTML = content;
		}
		
		// showing all data for going back function
		if (mustShowAll)
		{
			GetObj("generalLoader").style.display = "none";
			GetObj("photosearchBlock").style.display = "block";
			mustShowAll = false;
		}
		else
		{
			// if there is only one item, right redirection
			if (showedItemsCount == 1)
			{
				MyCookie.Write('backToPhotoSearch','1',1);
				window.location = lastItemUrl;
			}
		}
		
        ajaxResultReady = false;
        ajaxLoadingData = false;
	
		window.location = "#resultSkip4Href";
    }
}