function ChangeButton(oButton) {
	var aButton = document.getElementsByName(oButton.id);
	if(aButton != null) {
		for(i=0;i<aButton.length;i++) {		
			if(aButton[i].getAttribute('srcOri') != null)
				aButton[i].setAttribute("src", aButton[i].getAttribute('srcOri'));
			else
				aButton[i].setAttribute("srcOri", aButton[i].getAttribute('src'));
		}
		oButton.setAttribute("src", oButton.getAttribute('overSrc'));
		oButton.setAttribute("srcBackup", oButton.getAttribute('src'));
	}
}

function ChangeTab(p_intTabPaneIndex, p_intImageIndex, p_strMessage) {
	var oTp = eval('tp' + p_intTabPaneIndex);
	if(oTp) {
		oTp.setSelectedIndex(p_intImageIndex);
		var oImages = document.getElementsByName('tabimg');
		ChangeButton(oImages[p_intImageIndex]);
		alert(p_strMessage);
	}
}


function ChangeAreaFromCountry(p_strArea, p_strCountry, p_aArea, p_strLabel)
{
	var l_oArea = document.getElementById(p_strArea);
	var l_oCountry = document.getElementById(p_strCountry);

	if(l_oArea != null && l_oCountry != null)
	{
		l_oArea.length = 1;
		l_oArea.options[l_oArea.length-1].text = p_strLabel;

		for(i = 0; i < p_aArea.length; i++)
		{
			var aTemp = p_aArea[i].split(",");
			
			if(aTemp[0] * 1 == l_oCountry.options[l_oCountry.selectedIndex].value)
			{
				l_oArea.length++;
  			l_oArea.options[l_oArea.length-1].value = aTemp[1];
  			l_oArea.options[l_oArea.length-1].text = aTemp[2];
			}
		}
		if(l_oArea.length == 1)
			l_oArea.disabled = true;
		else
			l_oArea.disabled = false;
	}
}

function checkSearch(p_oDocument, p_strText1, p_strText2, p_strText3, p_strText4, p_strText5, p_strText6, p_strText7) {
	if(p_oDocument != null)
	{
		if(p_oDocument.Code != null)
		{
			if(p_oDocument.Code.value == '' || p_oDocument.Code.value==p_strText1) {
				alert(p_strText2);
				p_oDocument.Code.focus();
				return false;
			}
			if(AmpersandInString(p_oDocument.Code.value)||QuoteInString(p_oDocument.Code.value)) {
				alert(p_strText3);
				p_oDocument.Code.focus();
				return false;
			}
		}
		else
		{
			if(p_oDocument.From.value == '' || p_oDocument.From.value==p_strText4) {
				alert(p_strText5);
				p_oDocument.From.focus();
				return false;
			}
			if(p_oDocument.Persons.value == '') {
				alert(p_strText6);
				p_oDocument.Persons.focus();
				return false;
			}
			if(p_oDocument.Country[p_oDocument.Country.selectedIndex].value == '') {
				alert(p_strText7);
				p_oDocument.Country.focus();
				return false;
			}
		}
	}
	SaveComboBoxCriteria(p_oDocument);
	
	return true;
}

// Save
function SaveComboBoxCriteria(p_oDocument)
{
	if(p_oDocument != null)
	{
		SaveCriterium('From',p_oDocument.From[p_oDocument.From.selectedIndex].value);	
		SaveCriterium('Persons',p_oDocument.Persons[p_oDocument.Persons.selectedIndex].value);
		SaveCriterium('Country',p_oDocument.Country[p_oDocument.Country.selectedIndex].value);
		SaveCriterium('Area',p_oDocument.Area[p_oDocument.Area.selectedIndex].value);
		SaveCriterium('Accommodation',p_oDocument.Accommodation[p_oDocument.Accommodation.selectedIndex].value);
		SaveCriterium('Selection',p_oDocument.Selection[p_oDocument.Selection.selectedIndex].value);
	}
}

function SaveCriterium(cName,cValue)
{
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime()+1000*60*60*24*365);
	SetCookieItem(cName,cValue);
	return true;
}

// Load
function LoadComboBoxCriteria(p_oDocument)
{
	if(p_oDocument != null)
	{
		SetCriterium('From', p_oDocument.From, 'select');
		SetCriterium('Persons', p_oDocument.Persons, 'select');
		SetCriterium('Country', p_oDocument.Country, 'select');
		ChangeAreaFromCountry('Area', 'Country', aArea, cNoPreference);
		SetCriterium('Area', p_oDocument.Area, 'select');
		SetCriterium('Accommodation', p_oDocument.Accommodation, 'select');
		SetCriterium('Selection', p_oDocument.Selection, 'select');
	}
}

function SetCriterium(tcCookie,tcName,tcType) {
	var lcValue = GetCookieItemValue(tcCookie);
	if(lcValue != null && lcValue != 'undefined') {
		switch(tcType.toLowerCase()) {
			case "text":
				tcName.value = lcValue;
				break;
			case "checkbox":
				tcName.checked = lcValue;
				break;
			case "radio":
				tcName[lcValue].checked = true;
				break;
			case "select":
				if(tcName.type == 'select-one' || tcName.type == 'select')
				{
   				for(var i=0; i < tcName.length; i++) {
						if(tcName.options[i].text == lcValue || tcName.options[i].value == lcValue) {
							tcName.selectedIndex = i;
						}
   				}
   			}
   			else
   			{
   				tcName.value = lcValue;
   			}   
				break;
			default: 
				alert("unknown type");
				break;
		}
  }
}

function ChangeProduct(oSelect) {
	if(oSelect != null)
	{
		if(!IsArray(oSelect))
		{
			document.getElementById('pa' + oSelect.value).style.display = '';
			document.getElementById('text' + oSelect.value).style.display = '';
		}
		else
		{
			for(i = 0; i < oSelect.length; i++)
			{
				var aTblPrice = document.getElementsByName('pa' + oSelect[i].value);
				for(t = 0; t<aTblPrice.length; t++)
				{
					aTblPrice[t].style.display = 'none';
				}
				var aText = document.getElementsByName('text' + oSelect[i].value);
				for(t=0; t < aText.length; t++)
				{
					aText[t].style.display = 'none';
				}
			}
			
			if(document.getElementById('pa' + oSelect[oSelect.selectedIndex].value) != null)
				document.getElementById('pa' + oSelect[oSelect.selectedIndex].value).style.display = '';
			if(document.getElementById('text' + oSelect[oSelect.selectedIndex].value) != null)
				document.getElementById('text' + oSelect[oSelect.selectedIndex].value).style.display = '';
		}
	}
}

function AddToFavorites(cCode, dFrom, dTo, iDuration)
{
	var cCookie = GetCookieItemValue("favorites");
	var lFound = false;
	var cLine = '';

	if(cCookie != null)
	{
		var aCookie = cCookie.split(",");
		
		for(i=0; i < aCookie.length; i++)
		{
			var aValue = aCookie[i].split("#");
			
			if(cCode == aValue[0])
				lFound = true;
		}
		if(!lFound)
			cLine = ',' + cCode + '#' + dFrom + '#' + dTo + '#' + iDuration;
	}
	else
	{
		cCookie = '';
		cLine = cCode + '#' + dFrom + '#' + dTo + '#' + iDuration;
	}
	if(!lFound)
	{
		cCookie += cLine;
		SetCookieItem("favorites", cCookie);
	}
}

function RemoveFromFavorites(cCode, dFrom, dTo, iDuration) {
	var cCookie = GetCookieItemValue("favorites");
	var cLine = '';

	if(cCookie != null) {
		var aCookie = cCookie.split(",");
		for(i=0; i < aCookie.length; i++) {
			var aValue = aCookie[i].split("#");
			if(cCode != aValue[0]) {
				cLine += cCode + '#' + dFrom + '#' + dTo + '#' + iDuration + ','
			}
		}
		if(cLine.length!=0) cCookie = cLine.substr(0,cLine.length-1);
		else cCookie = '';
	}
	SetCookieItem("favorites", cCookie);
	return true;
}

function ChangeSource(p_oElement, p_intIndex)
{
	var l_oSource = document.getElementsByName("Source")[p_intIndex];
	var l_oSourceValue = document.getElementsByName("SourceValue")[0];

	switch(true)
	{
		case p_oElement.name.substring(0, 6) == "select":
			l_oSource.value = p_oElement[p_oElement.selectedIndex].value;
			l_oSource.checked = true;
			l_oSourceValue.value = "";
			break;
		case p_oElement.name.substring(0, 5) == "input":
			l_oSource.checked = true;
			l_oSourceValue.value = p_oElement.value;
			break;
	}
}

function CheckSubscribeForm()
{
	var lcError = "";
	
	with(document.forms["subscription"])
	{
		if(Initials.value.length < 1)
			lcError = lcError + oAlerts[0] + "\n";
		if(LastName.value.length < 2)
			lcError = lcError + oAlerts[1] + "\n";
		if(!CheckEmail(EmailAddress.value))
			lcError = lcError + oAlerts[2] + "\n";
		if(lcError == "")
			submit();
		else
			alert(lcError);
	}
}

function CheckUnsubscribeForm()
{
	var lcError = "";
	
	with(document.forms["unsubscription"])
	{
		if(!CheckEmail(EmailAddress.value))
			lcError = lcError + oAlerts[2] + "\n";
		if(lcError == "")
			submit();
		else
			alert(lcError);
	}
}