function hideValue(what, def)
{
	if(trim(what.value) == def)
	{
		what.value = "";
	}
	return;
}

function showValue(what, def)
{
	if(trim(what.value) == '')
	{
		what.value = def;
	}
	return;
}

// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value )
{
	return LTrim(RTrim(value));
	
}

function loadImages(path, pics)
{
	pics_arr = pics.split(',');
	for(i=0; i < pics_arr.length; i++)
	{
		eval('c' + i + ' = new Image();');
		eval('c' + i + '.src = path + "' + pics_arr[i] + '";');
	}
}

function changeBgck(what, img)
{
	document.getElementById(what).style.backgroundImage = "url('"+img+"')";
	//document.getElementById(what).style.backgroundPosition = 'middle';
}

function showHideCart()
{
	var link_target = document.getElementById('shopping_link');
	var items_target = document.getElementById('shopping_items');
	var cart_target = document.getElementById('shopping_cart_holder');
	
	//if(document.styleSheets[0].rules) var myStyle = document.styleSheets[0].rules;
	//else if(document.styleSheets[0].cssRules) var myStyle = document.styleSheets[0].cssRules;
	
	if(cart_target && cart_target.style.display == 'none')
	{
		//link_target.innerHTML = 'Hide Shopping Cart';
		//cart_target.style.opacity = 0; 
		//cart_target.style.MozOpacity = 0; 
		//cart_target.style.KhtmlOpacity = 0; 
		//cart_target.style.filter = "alpha(opacity=0)";
		cart_target.style.display = '';
	}
	else if(cart_target && cart_target.style.display == '')
	{
		//link_target.innerHTML = 'Show Shopping Cart';
		cart_target.style.display = 'none';
	}
	
	//shiftOpacity(cart_target.id, 400);
}

function expandCart()
{
	var cart_holder = document.getElementById('shopping_cart_holder');
	var cart_body = document.getElementById('shopping_cart_body');
	var cart_total = document.getElementById('shopping_cart_total');
	var cart = document.getElementById('shopping_cart');
	var cart_top = document.getElementById('shopping_cart_top');
	var cart_left = document.getElementById('shopping_cart_mid_left');
	var cart_right = document.getElementById('shopping_cart_mid_right');
	var cart_bottom = document.getElementById('shopping_cart_bottom');
	var link_target = document.getElementById('shopping_link');
	var link_target_bottom = document.getElementById('shopping_link_bottom');
	var arrow_target = document.getElementById('expand_arrow');
	var arrow_target_bottom = document.getElementById('bottom_arrow');
	
	if(cart_body.style.display == '')
	{
		cart_holder.style.width = '120px';
		cart.style.width = '90px';
		cart_top.style.width = '90px';
		cart_bottom.style.width = '90px';
		cart_body.style.display = 'none';
		cart_total.style.display = 'none';
		cart.style.height = '24px';
		cart_left.style.height = '24px';
		cart_right.style.height = '24px';
		link_target.innerHTML = 'maximize';
		link_target_bottom.style.display = 'none';
		cart_holder.style.height = '50px';
		cart_holder.style.marginTop = '-58px';
		arrow_target.src = 'http://www.nvisiontravel.com/images/default/nv_arrow_down.gif';
		arrow_target_bottom.style.display = 'none';
	}
	else
	{
		cart_body.style.display = '';
		cart_total.style.display = '';
		cart_holder.style.width = '300px';
		cart.style.width = '270px';
		cart_top.style.width = '270px';
		cart_bottom.style.width = '270px';
		cart_holder.style.height = '708px';
		cart.style.height = '678px';
		cart_left.style.height = '678px';
		cart_right.style.height = '678px';
		link_target.innerHTML = 'minimize';
		link_target_bottom.style.display = '';
		cart_holder.style.marginTop = '-25px';
		arrow_target.src = 'http://www.nvisiontravel.com/images/default/nv_arrow_up.gif';
		arrow_target_bottom.style.display = '';
	}
}

function opacity(id, opacStart, opacEnd, millisec)
{ 
	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0;
	
	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
	    for(i = opacStart; i >= opacEnd; i--) { 
	        setTimeout("changeOpac(" + i + ",'" + id + "'," + opacEnd + ")",(timer * speed)); 
	        timer++;
	    }
	} else if(opacStart < opacEnd) { 
	    for(i = opacStart; i <= opacEnd; i++) 
	        { 
	        setTimeout("changeOpac(" + i + ",'" + id + "'," + opacEnd + ")",(timer * speed)); 
	        timer++; 
	    } 
	}
} 

//change the opacity for different browsers 
function changeOpac(opacity, id, opacEnd)
{
	var cart_target = document.getElementById('shopping_cart_holder');
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if(opacity == 0 && opacEnd == 0) cart_target.style.display = 'none';
}

function shiftOpacity(id, millisec)
{ 
	//if an element is invisible, make it visible, else make it ivisible 
	if(document.getElementById(id).style.opacity == 0)
	{ 
		opacity(id, 0, 100, millisec); 
	}
	else
	{ 
		opacity(id, 100, 0, millisec); 
	} 
} 

function preloadImages(img_array)
{
	pics_array = img_array.split(',');
	for(i = 0; i < pics_array.length; i++)
	{
		eval("c"+i+" = new Image; c"+i+".src = pics_array[i];");
	}
}

var timer_id;
var direction=0;
var curr = 0;
function scroll_iframe(frm,inc,dir)
{
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm])
  {
    if (direction == 0)
    {
    	curr += inc;
    	window.frames[frm].scrollBy(0, inc);
    	if(curr >= window.frames[frm].document.body.offsetHeight)
    	{
    		direction = 1;
    		curr = window.frames[frm].document.body.offsetHeight;
    	}
    }
    else if (direction == 1)
    {
    	curr -= inc;
    	window.frames[frm].scrollBy(0, -inc);
    	if(curr <= 0)
    	{
    		direction = 0;
    		curr = 0;
    	}
    }
    //else window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 5);
  }
}

function stopScroll()
{
	if (timer_id) clearTimeout(timer_id);
}

function change_class(tid, cfg)
{
	if(cfg == 1) newclass = 'admin_button';
	else if(cfg == 2) newclass = 'admin_button_over';
	
	//var dtarget = document.getElementById(tid);
	
	tid.className = newclass;
}

Array.prototype.in_array = function ( obj )
{
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ )
	{
		if ( this[x] == obj ) return true;
	}
	return false;
}

var traveller_cnt = 2;
var total_count = 0;
var room_type_selection = 0;
var last_flash_service_id = 0;
var room_types = Array();
var room_prices = Array();
var add_array = Array();

function checkCartForm()
{
	var cform = document.shopping_cart_form;
	
	if(cform.bb || cform.tour_id || cform.bb.value != '' || cform.tour_id.value != '' || traveller_cnt == 0)
	{
		var stat_fields = Array('from_date','room_type_selection');
		var stat_error = Array('Choose Check-In date!','Choose Rooms Type!');
		
		for(var i = 0; i < stat_fields.length; i++)
		{
			eval("var sf = cform." + stat_fields[i] + ";");
			if(trim(sf.value) == '')
			{
				alert(stat_error[i]);
				sf.focus();
				return false;
			}
		}
		
		if(add_array && add_array.length > 0)
		{
			for(var c = 0; c < add_array.length; c++)
			{
				var what_chk = document.getElementById('add_' + add_array[c]);
				var what_chk_part = document.getElementById('add_' + add_array[c] + '_participants');
				
				if(what_chk && what_chk_part && what_chk.checked)
				{
					if(what_chk_part.value == 0)
					{
						alert('Choose Participants for the selected option!');
						what_chk_part.focus();
						return false;
					}
				}
			}
		}
	}
	else
	{
		alert('Wrong Initialization!');
		return false;
	}
	
	var pars = 'doit=1&tour_id='+cform.tour_id.value+'&bb='+cform.bb.value+'&total='+document.getElementById('total_count_price').innerHTML;
	
	new Ajax.Updater('shopping_remote', 'http://www.nvisiontravel.com/modules/shopping_cart/gather_private_info.php', {postBody: pars, evalScripts: true, onComplete: function(){showCart();}});
}

function checkPrivateInfoForm()
{
	var cform = document.shopping_cart_private_info;
	
	if(cform.bb || cform.tour_id || cform.bb.value != '' || cform.tour_id.value != '' || traveller_cnt == 0)
	{
		var stat_fields = Array('title','firstname','lastname','email','phone','city','postal_code','address');
		var stat_error = Array('Choose title!','Enter Your first name!','Enter Your last name!','Enter Your e-mail!','Enter Your phone number!','Enter Your city!','Enter Your postal code!','Enter Your address!');
		
		for(var i = 0; i < stat_fields.length; i++)
		{
			eval("var sf = cform." + stat_fields[i] + ";");
			if(trim(sf.value) == '')
			{
				alert(stat_error[i]);
				sf.focus();
				return false;
			}
			else if(stat_fields[i] == 'email')
			{
				var regex = new RegExp(/^(.+){3,}\@(.+){3,}\.([a-z]+){2,}$/);
				var match = regex.exec(sf.value);
				if (match == null)
				{
					alert('Enter valid e-mail!');
					sf.focus();
					return false;
				}
			}
		}
	}
	else
	{
		alert('Wrong Initialization!');
		return false;
	}
	
	cform.submit();
}

function uncheckFields()
{
	if(add_array && add_array.length > 0)
	{
		for(var c = 0; c < add_array.length; c++)
		{
			var what_chk = document.getElementById('add_' + add_array[c]);
			
			if(what_chk && what_chk.checked)
			{
				what_chk.checked = false;
				setAddParticipantsOptions(add_array[c], 1);
			}
		}
		
		totalCount();
		
		saveCartOptions();
		
		getMarkedItems(document.getElementById('tour_id').value);
	}
}

//[2] = 0 - variable
//[2] = 1 - innerHTML
//[2] = 2 - value
//[2] = 3 - checked
//[2] = 4 - selected
function initCart()
{
	var ginfo = Get_Cookie( 'cart_tour_' + document.getElementById('tour_id').value );
	
	if(ginfo)
	{
		var garray = ginfo.split('|');
		
		for(var i = 0; i < garray.length; i++)
		{
			var gsubarray = garray[i].split('=');
			
			switch(parseInt(gsubarray[2]))
			{
				//variable
				case 0:
				eval(gsubarray[0] + " = " + gsubarray[1] + ";");
				break;
				
				//innerHTML
				case 1:
				var tinit = document.getElementById(gsubarray[0]);
				if(tinit) tinit.innerHTML = gsubarray[1];
				break;
				
				//value
				case 2:
				var tinit = document.getElementById(gsubarray[0]);
				if(tinit) tinit.value = gsubarray[1];
				break;
				
				//checked
				case 3:
				var tinit = document.getElementById(gsubarray[0]);
				if(tinit) tinit.checked = (gsubarray[1] == 1 ? true : false);
				break;
				
				//selected
				case 4:
				eval(gsubarray[0] + " = '" + gsubarray[1] + "';");
				break;
			}
		}
	}
	
	addRemoveTravellers(0);
	
	if(add_array && add_array.length > 0)
	{
		var curr_bb = parseInt(document.shopping_cart_form.bb.value);
		
		for(var c = 0; c < add_array.length; c++)
		{
			var what_bb = document.getElementById('add_' + add_array[c]).className;
			var what_chk = document.getElementById('add_' + add_array[c]);
			
			if(what_chk && what_chk.checked)
			{
				 curr_bb += parseInt(what_bb);
			}
		}
		
		document.shopping_cart_form.bb.value = curr_bb;
	}
	
	calculateEndDate();
	
	getMarkedItems(document.getElementById('tour_id').value);
}

function saveCartOptions()
{
	var cookie_value = 'tour_id=' + document.getElementById('tour_id').value + '=2' +
	'|from_date=' + document.getElementById('from_date').value + '=2' +
	'|traveller_cnt=' + traveller_cnt + '=0|room_type_selection=' + document.getElementById('room_type_selection').value + '=4';
	
	var php_cookie_value = traveller_cnt + '|' + document.getElementById('from_date').value +
	'|' + document.getElementById('room_type_selection').value;
	
	if(add_array && add_array.length > 0)
	{
		for(var c = 0; c < add_array.length; c++)
		{
			var what_chk = document.getElementById('add_' + add_array[c]);
			cookie_value += '|add_' + add_array[c] + '=' + (what_chk.checked ? 1 : 0) + '=3';
			
			var what = document.getElementById('add_' + add_array[c] + '_participants');
			if(what)
			{
				cookie_value += '|add_' + add_array[c] + '_participants=' + what.options[what.selectedIndex].value + '=4';
				
				if(what_chk.checked)
				{
					php_cookie_value += '|' + add_array[c] + ',' + what.options[what.selectedIndex].value;
				}
			}
			else
			{
				what = document.getElementById('add_' + add_array[c] + '_participants_in');
				if(what)
				{
					cookie_value += '|add_' + add_array[c] + '_participants=' + what.value + '=2';
					
					if(what_chk.checked)
					{
						php_cookie_value += '|' + add_array[c];
					}
				}
			}
		}
	}
	
	Set_Cookie( 'cart_tour_' + document.getElementById('tour_id').value, cookie_value, 30, '/', '', '' );
	Set_Cookie( 'selected_tour', document.getElementById('tour_id').value, 30, '/', '', '' );
	Set_Cookie( 'php_cookie_' + document.getElementById('tour_id').value, php_cookie_value, 30, '/', '', '' );
}

function addRemoveTravellers(act)
{
	if(document.getElementById('travellers'))
	{
		var cont = document.getElementById('travellers');
		
		//remove
		if(act == 1) traveller_cnt = traveller_cnt - 1;
		//add
		if(act == 2) traveller_cnt = traveller_cnt + 1;
		
		if(traveller_cnt < 1) traveller_cnt = 1;
		if(traveller_cnt > 6) traveller_cnt = 6;
		
		if(traveller_cnt >= 1 && traveller_cnt <= 6)
		{
			cont.style.width = parseInt(traveller_cnt * 10) + 'px';
		}
		
		var pars = 'doit=1&tour_id='+document.getElementById('tour_id').value+'&persons_count='+traveller_cnt;
		
		new Ajax.Request('http://www.nvisiontravel.com/modules/tours/get_room_types.php', {method: 'post', postBody:pars, onSuccess: function(transport)
			{
				var result = transport.responseText.split('|');
				
				//room types
				room_types = result[0].split(',');
				
				//room prices
				room_prices = result[1].split(',');
				
				//update price
				if(document.getElementById('room_type_selection') && document.getElementById('total_count_price'))
				{
					var snew_res = 0;
					var sel = document.getElementById('room_type_selection');
					sel.options.length = 0;
					sel.options[0] = new Option('-- selection room type --', '');
					
					for(var i = 0; i < room_types.length; i++)
					{
						var new_res = room_types[i];
						sel.options[(i+1)] = new Option(new_res.replace('_', ' + '), new_res);
						if(new_res == room_type_selection)
						{
							sel.options[(i+1)].selected = true;
							
							document.getElementById('tour_count_price_total').innerHTML = room_prices[i];
							document.getElementById('tour_count_price_per_traveler').innerHTML = (room_prices[i] / traveller_cnt).toFixed(2);
						}
					}
					
					if(snew_res == 0)
					{
						document.getElementById('tour_count_price_total').innerHTML = room_prices[0];
						document.getElementById('tour_count_price_per_traveler').innerHTML = (room_prices[0] / traveller_cnt).toFixed(2);
					}
					
					if(add_array && add_array.length > 0)
					{
						for(var i = 0; i < add_array.length; i++)
						{
							setAddParticipantsOptions(add_array[i], 0);
						}
					}
					
					totalCount();
					
					saveCartOptions();
				}
			}
		});
	}
}

function calculateRoomTypes()
{
	var srt = document.getElementById('room_type_selection').selectedIndex - 1;
	
	if(srt >= 0)
	{
		document.getElementById('tour_count_price_total').innerHTML = room_prices[srt];
		document.getElementById('tour_count_price_per_traveler').innerHTML = (room_prices[srt] / traveller_cnt).toFixed(2);
	}
	
	totalCount();
	
	saveCartOptions();
}

function setAddParticipantsOptions(what_id, cfg)
{
	what_id = parseInt(what_id);
	
	var what = document.getElementById('add_' + what_id + '_participants');
	var what_bb = document.getElementById('add_' + what_id).className;
	
	var pars = 'doit=1&tour_id='+document.getElementById('tour_id').value+'&additional_id='+what_id;
	
	new Ajax.Request('http://www.nvisiontravel.com/modules/tours/get_additional_prices.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			if(what)
			{
				if((traveller_cnt + 1) > what.options.length)
				{
					for(var a = what.options.length; a < (traveller_cnt + 1); a++)
					{
						if(a == 1) var padd = ' participant';
						else var padd = ' participants';
						
						what.options[a] = new Option(a + padd, a);
						
						what.options[a].className = result[(a-1)];
						
						eval("if(a == add_" + what_id + "_participants) what.options[a].selected = true;");
					}
				}
				else if((traveller_cnt + 1) < what.options.length)
				{
					for(var a = what.options.length; a > (traveller_cnt + 1); a--)
					{
						what.options[(a-1)] = null;
					}
				}
			}
			
			if(cfg == 1)
			{
				if(document.getElementById('add_' + what_id).checked)
				{
					document.shopping_cart_form.bb.value = parseInt(document.shopping_cart_form.bb.value) + parseInt(what_bb);
				}
				else
				{
					document.shopping_cart_form.bb.value -= parseInt(what_bb);
				}
				
				calculateEndDate();
				
				if(document.getElementById('add_' + what_id).checked) setOpenedService(what_id, 0);
				else getMarkedItems(document.getElementById('tour_id').value);
			}
			
			//flash call
			if(parseInt(cfg) == 3)
			{
				document.getElementById('add_' + what_id).scrollIntoView(true);
				document.getElementById('shopping_cart_body').scrollTop = parseInt(document.getElementById('shopping_cart_body').scrollTop) - 200;
				
				if(!document.getElementById('add_' + what_id).checked)
				{
					document.shopping_cart_form.bb.value = parseInt(document.shopping_cart_form.bb.value) + parseInt(what_bb);
					document.getElementById('add_' + what_id).checked = true;
					
					calculateEndDate();
				}
				
				if(document.getElementById('shopping_cart_body').style.display == 'none') expandCart();
			}
			
			totalCount();
			
			saveCartOptions();
			
			if(what_id == last_flash_service_id)
			{
				getServiceInfo(what_id);
				
				getMarkedItems(document.getElementById('tour_id').value);
			}
		}
	});
}

function totalCount()
{
	var ccount = 0;
	var tpcount = parseInt(document.getElementById('tour_count_price_total').innerHTML);
	
	if(add_array && add_array.length > 0)
	{
		for(var b = 0; b < add_array.length; b++)
		{
			var what_aid = document.getElementById('add_' + add_array[b]);
			var what_said = document.getElementById('add_' + add_array[b] + '_participants');
			var what_said_in = document.getElementById('add_' + add_array[b] + '_participants_in');
			var what_said_night = document.getElementById('add_' + add_array[b] + '_participants_night');
			var what_paid = document.getElementById('add_' + add_array[b] + '_price');
			var what_paid_total = document.getElementById('add_' + add_array[b] + '_price_total');
			var what_paid_night = document.getElementById('add_' + add_array[b] + '_price_night');
			var what_paid_total_night = document.getElementById('add_' + add_array[b] + '_price_total_night');
			
			if(what_aid.checked)
			{
				if(what_said)
				{
					//ccount = parseInt(ccount) + parseInt(what_said.options[what_said.selectedIndex].className) * parseInt(what_aid.className);
					ccount = parseInt(ccount) + parseInt(what_said.options[what_said.selectedIndex].className);
					
					var srts = document.getElementById('room_type_selection').value;
					if(srts == '') srts = document.getElementById('room_type_selection').options[1].value;
					
					if(what_said_night)
					{
						var win_price = what_said_night.value.split(',');
						//ccount = parseInt(ccount) + parseInt(win_price[(checkFixRoomTypes(srts))]) * parseInt(what_aid.className);
						ccount = parseInt(ccount) + parseInt(win_price[(checkFixRoomTypes(srts))]);
					}
				}
				else
				{
					if(what_said_in)
					{
						var srts = document.getElementById('room_type_selection').value;
						if(srts == '') srts = document.getElementById('room_type_selection').options[1].value;
						
						var win_price = what_said_in.value.split(',');
						//ccount = parseInt(ccount) + parseInt(win_price[(checkFixRoomTypes(srts))]) * parseInt(what_aid.className);
						ccount = parseInt(ccount) + parseInt(win_price[(checkFixRoomTypes(srts))]);
					}
				}
				
				if(what_said)
				{
					if(what_said.options[what_said.selectedIndex].value > 0)
					{
						//what_paid.innerHTML = ((parseInt(what_said.options[what_said.selectedIndex].className) * parseInt(what_aid.className)) / what_said.options[what_said.selectedIndex].value).toFixed(2);
						//what_paid_total.innerHTML = (what_said.options[what_said.selectedIndex].className * parseInt(what_aid.className)).toFixed(2);
						what_paid.innerHTML = (parseInt(what_said.options[what_said.selectedIndex].className) / what_said.options[what_said.selectedIndex].value).toFixed(2);
						what_paid_total.innerHTML = what_said.options[what_said.selectedIndex].className;
					}
					
					if(what_said_night)
					{
						var srts = document.getElementById('room_type_selection').value;
						if(srts == '') srts = document.getElementById('room_type_selection').options[1].value;
						
						var win_price = what_said_night.value.split(',');
						//what_paid_night.innerHTML = ((parseInt(win_price[(checkFixRoomTypes(srts))]) * parseInt(what_aid.className)) / traveller_cnt).toFixed(2);
						//what_paid_total_night.innerHTML = (parseInt(win_price[(checkFixRoomTypes(srts))]) * parseInt(what_aid.className)).toFixed(2);
						what_paid_night.innerHTML = (parseInt(win_price[(checkFixRoomTypes(srts))]) / traveller_cnt).toFixed(2);
						what_paid_total_night.innerHTML = parseInt(win_price[(checkFixRoomTypes(srts))]).toFixed(2);
					}
				}
				else
				{
					if(!what_said)
					{
						if(what_said_in)
						{
							var srts = document.getElementById('room_type_selection').value;
							if(srts == '') srts = document.getElementById('room_type_selection').options[1].value;
							
							var win_price = what_said_in.value.split(',');
							var wprice = win_price[checkFixRoomTypes(srts)];
							
							if(wprice != 'undefined')
							{
								//what_paid.innerHTML = ((parseInt(wprice) * parseInt(what_aid.className)) / traveller_cnt).toFixed(2);
								//what_paid_total.innerHTML = (parseInt(wprice) * parseInt(what_aid.className)).toFixed(2);
								what_paid.innerHTML = (parseInt(wprice) / traveller_cnt).toFixed(2);
								what_paid_total.innerHTML = parseInt(wprice).toFixed(2);
							}
							else
							{
								what_paid.innerHTML = 0.00;
								what_paid_total.innerHTML = 0.00;
							}
						}
					}
					else
					{
						what_paid.innerHTML = 0.00;
						what_paid_total.innerHTML = 0.00;
					}
				}
			}
		}
	}
	
	document.getElementById('total_count_price').innerHTML = (parseInt(ccount) + tpcount).toFixed(2);
	
	saveCartOptions();
}

function checkFixRoomTypes(what)
{
	var ret;
	
	if(what == '1xsgl')	ret = 0;
	if(what == '2xsgl')	ret = 1;
	if(what == '1xdbl')	ret = 2;
	if(what == '3xsgl')	ret = 3;
	if(what == '1xsgl_1xdbl')	ret = 4;
	if(what == '4xsgl')	ret = 5;
	if(what == '2xsgl_1xdbl')	ret = 6;
	if(what == '2xdbl')	ret = 7;
	if(what == '5xsgl')	ret = 8;
	if(what == '3xsgl_1xdbl')	ret = 9;
	if(what == '1xsgl_2xdbl')	ret = 10;
	if(what == '6xsgl')	ret = 11;
	if(what == '4xsgl_1xdbl')	ret = 12;
	if(what == '2xsgl_2xdbl')	ret = 13;
	if(what == '3xdbl')	ret = 14;
	
	return ret;
}

function calculateEndDate()
{
	var reg = document.shopping_cart_form;
	
	if(document.getElementById('end_date'))
	{
		var pars = 'doit=1&check_in_date=' + reg.from_date.value + '&bb=' + reg.bb.value;
		
		new Ajax.Request('http://www.nvisiontravel.com/modules/tours/calculate_check_out_date.php', {method: 'post', postBody:pars, onSuccess: function(transport)
			{
				document.getElementById('end_date').innerHTML = transport.responseText;
				
				saveCartOptions();
			}
		});
	}
}

function shFaq(what)
{
	if(document.getElementById('faq' + what))
	{
		var tfaq = document.getElementById('faq' + what);
		
		if(tfaq.style.display == '') tfaq.style.display = 'none';
		else if(tfaq.style.display == 'none') tfaq.style.display = '';
	}
}

function backToTour(tour_id)
{
	var pars = 'remote=1';
		
	new Ajax.Updater('shopping_remote', 'http://www.nvisiontravel.com/modules/shopping_cart/shopping_cart.php', {postBody: pars, evalScripts: true, onComplete: function(){showCart();}});
	
	showCart();
}

//flash communication
var flashID;
function getID( swfID )
{
	if(document.all)
	{
		flashID = document.all[swfID];
	}
	else
	{
		flashID = document.getElementById(swfID);
	}
}

function js_to_as( str )
{     
	flashID.onChange(str);
}

function getServiceInfo( add_id )
{
	var tadd_id = document.getElementById('add_' + add_id + '_price');
	var tadd_id_bb = document.getElementById('add_' + add_id).className;
	var tadd_id_in = document.getElementById('add_' + add_id + '_participants_in');
	//var tadd_id_night = document.getElementById('add_' + add_id + '_price_night');
	var tadd_id_night = document.getElementById('add_' + add_id + '_price_total_night');
	
	if(tadd_id && tadd_id_bb && !tadd_id_in)
	{
		if(tadd_id_night)	flashID.onChange( tadd_id.innerHTML + "EUR," + tadd_id_night.innerHTML + "EUR" );
		else	flashID.onChange( tadd_id.innerHTML + "EUR,0" );
	}
	else if(tadd_id_in)
	{
		
		flashID.onChange( tadd_id.innerHTML + "EUR,0" );
	}
	
	//document.getElementById('add_' + add_id + '_main').style.backgroundColor = '#e3e3e3';
	
	last_flash_service_id = add_id;
}

function wait(msecs)
{
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs)
	{
		cur = new Date().getTime();
	}
}

function changeTour(tour_id)
{
	Set_Cookie( 'selected_flash_tour', tour_id, 0, '/', '', '' );
	
	if(document.getElementById('tour_id') && document.getElementById('tour_id').value != tour_id)
	{
		Set_Cookie( 'selected_tour', tour_id, 30, '/', '', '' );
		
		var pars = 'remote=1';
		
		new Ajax.Updater('shopping_remote', 'http://www.nvisiontravel.com/modules/shopping_cart/shopping_cart.php', {postBody: pars, evalScripts: true, onComplete: function(){showCart();}});
	}
	
	showCart();
}

function hideCart()
{
	Set_Cookie( 'selected_flash_tour', '', 3600, '/', '', '' );
	
	if(document.getElementById('shopping_cart_holder'))
	{
		var tcart = document.getElementById('shopping_cart_holder');
		
		if(tcart.style.display == '')
		{
			showHideCart();
		}
	}
}

function showCart()
{
	if(document.getElementById('shopping_cart_holder'))
	{
		var tcart = document.getElementById('shopping_cart_holder');
		
		if(tcart.style.display == 'none')
		{
			showHideCart();
		}
	}
}

function getMarkedItems(tour_id)
{
	var marked_items = tour_id;
	
	if(add_array && add_array.length > 0)
	{
		for(var b = 0; b < add_array.length; b++)
		{
			var what_aid = document.getElementById('add_' + add_array[b]);
			if(what_aid && what_aid.checked) marked_items += ',' + add_array[b];
		}
	}
	
	flashID.onMark( marked_items );
}

function setOpenedService(add_id, cfg)
{
	if(document.getElementById('tour_id') && document.getElementById('tour_id').value != '')
	{
		flashID.onCheck(document.getElementById('tour_id').value + ',' + add_id + ',' + cfg);
	}
}
//end of flash communication

function LightboxDelegate(url , caption , id) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   objLink.setAttribute('rel','lightbox');
   objLink.setAttribute('title',caption);
   if(typeof width != 'undefined') {
      objLink.setAttribute('width',width);
   }
   if(typeof Height != 'undefined') {
      objLink.setAttribute('height',height);
   }
   Lightbox.prototype.start(objLink);
}

function closePic()
{
	if(document.getElementById('showPreview')) 
	{
		document.body.removeChild(document.getElementById('showPreview'));
		document.body.removeChild(document.getElementById('showPreviewPic'));
		
		var elementBody = document.getElementsByTagName('html');
		elementBody[0].style.overflow = '';
		elementBody[0].onselectstart = function() {return true;};
	}
}

function showBigGallery(img, txt)
{
	//opera fix
	var agt = navigator.userAgent.toLowerCase();
  var is_opera = (agt.indexOf("opera") != -1);
	if(is_opera) txt = Url.decode(txt);
	
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showPreview';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	//dl.style.height = parseInt(document.getElementById('allover').offsetHeight) + 40 + 'px';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	//dl.style.top = scrollHeight+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//pic div
	pl = document.createElement('div');
	pl.id = 'showPreviewPic';
	pl.style.cssText = 'float:left;';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-200+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-251px';
	pl.style.padding = '10px 5px 10px 14px';
	pl.style.width = '503px';
	pl.style.height = '415px';
	pl.style.textAlign = 'center';
	pl.style.zIndex = 1001;
	pl.style.backgroundImage = 'url(\'http://www.nvisiontravel.com/images/default/spinner.gif\')';
	pl.style.backgroundPosition = 'center';
	pl.style.backgroundRepeat = 'no-repeat';
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showPreviewPicClose';
	cl.style.cssText = 'float:left;';
	cl.style.width = '500px';
	//cl.style.border = 'red 1px solid';
	cl.style.backgroundColor = '#FFFFFF';
	cl.style.textAlign = 'left';
	cl.style.padding = '10px 0px 10px 0px';
	cl_in = '<div style="float:left;width:400px;color:#2f5b77;font-size:12px;">' + txt + '</div>';
	cl_in += '<div style="float:right;width:90px;text-align:left;"><a href="javascript:closePic();" style="text-decoration:none;color:#666666;white-spacing:nowrap;">Close <img src="http://www.nvisiontravel.com/images/default/close.gif" alt="Close" style="vertical-align:middle;border:0px;"/></a></div>';
	cl.innerHTML = cl_in;
	
	//pic
	pic_div = document.createElement('div');
	pic_div.style.cssText = 'float:left;';
	pic_div.style.width = '493px';
	pic_div.style.height = '370px';
	
	pic = document.createElement('img');
	pic.id = 'imagePreview';
	pic.src = img;
	pic.setAttribute('alt', '');
	pic.setAttribute('border', '0');
	
	pic_div.appendChild(pic);
	pl.appendChild(pic_div);
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	var elementBody = document.getElementsByTagName('html');
	elementBody[0].style.overflow = 'hidden';
	elementBody[0].onselectstart = function() {return false;};
	
	scroll(0, scrollHeight);
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowW, windowH;
	if (self.innerHeight) {	// all except Explorer
		windowW = self.innerWidth;
		windowH = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowW = document.documentElement.clientWidth;
		windowH = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowW = document.body.clientWidth;
		windowH = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowH){
		pageHeight = windowH;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowW){	
		pageWidth = windowW;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowW,windowH) 
	return arrayPageSize;
}

function winWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if( document.documentElement && document.documentElement.clientWidth )
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function winHeight()
{
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' )
  {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && document.documentElement.clientHeight )
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight )
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollX()
{
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfX = window.pageXOffset;
  }
  else if( document.body && document.body.scrollLeft )
  {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && document.documentElement.scrollLeft )
  {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
}
