// JavaScript Document


function changeState(conatainer, mode)
{
	var div = conatainer.getElementsByClassName('opinion_anotation')[0];
	
	if(conatainer.timeOut) clearTimeout(conatainer.timeOut);
		
	conatainer.timeOut = setTimeout(
	function()
	{
		if(mode == "over")
		{
			new Effect.BlindDown(div, 
									{ 
										duration: 0.3 ,
										queue: 'end'
									});
		}
		else
		{
			conatainer.notClose = 1;
			new Effect.BlindUp(div, 
									{ 
										duration: 0.3 ,
										queue: 'end'
									});	
		}
	}, 90);
}

function loadSubcategory(num, lnk)
{
	var ul        = (lnk.parentNode).parentNode;
	var div 	  = ul.parentNode;
	var divs 	  = div.getElementsByClassName('category_bottom_listing_div');
	var lnks      = ul.getElementsByTagName('a');
	
	
	for(var i=0; i<divs.length; i++)
	{
		divs[i].hide();
		lnks[i].className = "";
	}
	
	//$('subArticles_' + num).show();
	new Effect.BlindDown('subArticles_' + num);
	
	lnk.className = "active_vacation";
}

function initComments()
{
	var imageList = document.getElementsByClassName('comment_container');
	for (var i = 0; i < imageList.length; i++) 
	{
		imageList[i].onmouseover = function () 
		{
			changeState(this, 'over');
		};
		imageList[i].onmouseout =  function () {
			changeState(this, 'off');
		};
	}
}


function showHideShareButtons()
{
	$('shareButtonsUl').toggle();	
}

function loadWeather()
{
	new Ajax.Request("/server/LoadWeather.php",
    {
        method: "post"
    }
    );	
}

function showPic()
{
	$('link_pic').className   = 'actve';
	$('link_video').className = '';
	
	$('div_pic').show();
	$('div_video').hide();
}

function showVideo()
{	
	$('link_pic').className   = '';
	$('link_video').className = 'actve';
	
	$('div_pic').hide();
	$('div_video').show();
}

function showWeather()
{
	$('li_weather').className = 'border_left';
	$('li_fixing').className  = '';
	
	$('link_weather').className = 'actve';
	$('link_fixing').className  = '';
	
	$('div_weather').show();
	$('div_fixing').hide();
}

function showFixing()
{
	$('li_weather').className = '';
	$('li_fixing').className  = 'border_right';
	
	$('link_weather').className = '';
	$('link_fixing').className  = 'actve';
	
	$('div_weather').hide();
	$('div_fixing').show();
}




function enlargePic(imgSrc, lnk)
{
	var src   = imgSrc;
	var img = $('bigImg');	
	
	var imgPreloader = new Image();
	
	new Effect.Opacity(img, Object.extend(
						{
					   		duration: 0.25, 
							from:1.0, 
							to:0.0,
							afterFinishInternal: function(effect) 
							{
								imgPreloader.src = src;
							}
						})
			);	
	
	// once image is preloaded, appear the image
	imgPreloader.onload = function()
	{
		img.src 	= src;
		new Effect.Appear(img, {duration: 0.25});
	}
	
	// remove active class from old link
	lnkA = $('galleryContainer').getElementsByClassName('active_im');
	if(lnkA[0]) lnkA[0].className = "";
	
	lnk.className = "active_im";
}

function slide(div, px)
{
	var tbl = $(div);
	
	
	if(tbl.hiddenHeight == null)
	{
		tbl.hiddenHeight = (tbl.getHeight() - (tbl.parentNode).getHeight());
		//alert(tbl.hiddenHeight);
	}
	
	if(tbl.posProperty == null)
	{
		tbl.posProperty = tbl.hiddenHeight;
		//alert(tbl.posProperty);
	}
	
	
	if(tbl.posProperty>=0 && tbl.posProperty<=tbl.hiddenHeight)
	{
		var toMove = null;
		var newPos = null;
		
		if((tbl.posProperty + px) < 0)
		{
			toMove = -tbl.posProperty;
			newPos = 0;
		}
		else if((tbl.posProperty + px) > tbl.hiddenHeight)
		{
			toMove = tbl.hiddenHeight - tbl.posProperty;
			newPos = tbl.hiddenHeight;	
		}
		else
		{
			toMove = px;
			newPos = tbl.posProperty + px;		
		}
		
		new Effect.Move (div, 
					 { 
					 	x     : 0, 
						y     : toMove, 
						mode  : 'relative',
						queue : {position:'front', scope:'one', limit:1},
						afterFinish : function () { tbl.posProperty = newPos; }
					 }
					 );
	}
}

function defaultArticleFont()
{
	var div  = $('articleDescription');
	var div2 = $('commentsDiv');
	
	if(div) div.style.fontSize   = "12px";
	if(div2) div2.style.fontSize = "12px";
}

function increaseArticleFont()
{
	var divs = document.getElementsByClassName('rsz');
	
	for(var i=0; i<divs.length; i++)
	{
		if(divs[i].style.fontSize == "")
			divs[i].style.fontSize = "12px";
		var size = parseInt(divs[i].style.fontSize.replace("px",""));
		divs[i].style.fontSize = (size + 1) + "px";
	}
	
}

function decreaseArticleFont()
{
	var divs = document.getElementsByClassName('rsz');
	
	for(var i=0; i<divs.length; i++)
	{
		if(divs[i].style.fontSize == "")
			divs[i].style.fontSize = "12px";
		var size = parseInt(divs[i].style.fontSize.replace("px",""));
		divs[i].style.fontSize = (size - 1) + "px";
	}
}

function showComments()
{
	$('commentsDiv').show();
	$('articleDiv').hide();
	$('article_lnk').className = "";
	$('comment_lnk').className = "active_in";
}

function showArticleDetails()
{
	$('commentsDiv').hide();
	$('articleDiv').show();
	$('article_lnk').className = "active_in";
	$('comment_lnk').className = "";
}

function openDetailedSearch()
{
	$('det_search').show();
	//$('link_det_search').hide();
	//$('link_srt_search').show();
}

function openShortSearch()
{
	$('det_search').hide();
	//$('link_det_search').show();
	//$('link_srt_search').hide();
}

function openCalendar(inp)
{
	displayCalendar(inp, "dd.mm.yyyy", inp);
}

function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function calculateDate()
{
	var fromDate = new Date();
	var curDate  = $F('from_date').split('.');
	
	var months   = (getCheckedValue($('abonament').plan1));
	if (!months) months   = (getCheckedValue($('abonament').plan2));
	if (!months) months   = (getCheckedValue($('abonament').plan3));

	//var months   = (getCheckedValue($('abonament').plan));
	fromDate.setFullYear(parseInt(curDate[2]), (parseInt(curDate[1]) - 1), curDate[0]);
	
	fromDate.setMonth(fromDate.getMonth() + parseInt(months));
	$('to_date').value = fromDate.getDate() + '.' + (fromDate.getMonth() + 1) + '.' + fromDate.getFullYear();
}

function deleteComment(id)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'deleteComment',
							id: id
						}, 
						onComplete: function (result) { if(result.responseText == "done") $('comment_' + id).remove();}
					 }
					);
}

function deleteCommentAirline(id)
{
	new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'deleteCommentAirline',
							id: id
						}, 
						onComplete: function (result) { if(result.responseText == "done") $('comment_' + id).remove();}
					 }
					);
}

function makeEditable(id, lang)
{
	new Ajax.InPlaceEditor('c_text_' + id, file + '?el=text' + lang + '&func=editComment&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай',
									rows:10
								}
						   );	
}

function makeEditableAirline(id)
{
	new Ajax.InPlaceEditor('text_comment_' + id, file + '?el=comment&func=editCommentAirline&id=' + id, 
						   		{
									formClassName:'formEdit',
									highlightcolor: '#eeeeee',
									hoverClassName: 'overEdit',
									clickToEditText: 'Редактирай',
									rows:10
								}
						   );	
}


function initAjaxIndicator()
{
	Ajax.Responders.register(
	{
  		onCreate: function() 
  		{
    		$('indicator').show();
  		},
  		onComplete: function() 
  		{
    		$('indicator').hide();
  		}
	});
}

function validateAddComment()
{
	if($F('name') == "")	
	{
		alert('Не сте въвели Име');
		$('name').focus();
		return false;
	}
	
	
	if($F('text') == "")	
	{
		alert('Не сте въвели Съдържание на коментара');
		$('text').focus();
		return false;
	}
	
	return true;
}

function validateSendFriend()
{
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;
	
	if($F('name2') == "")	
	{
		alert('Не сте въвели `Вашето име`');
		$('name').focus();
		return false;
	}
	
	if($F('from_mail') == "")	
	{
		alert('Не сте въвели `От (e-mail)`');
		$('from_mail').focus();
		return false;
	}
	
	
	if(!(Exp1.exec($F('from_mail'))))
	{
		alert('Моля въведете валиден `От (e-mail)`!');
        $('from_mail').focus();
		return false;
	}
	
	if($F('to_mail') == "")	
	{
		alert('Не сте въвели `До кого (e-mail)`');
		$('to_mail').focus();
		return false;
	}
	
	if(!(Exp1.exec($F('to_mail'))))
	{
		alert('Моля въведете валиден `До кого (e-mail)`!');
        $('to_mail').focus();
		return false;
	}
	
	return true;
}

function validateSubscribe()
{
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;
	
	if($F('name') == "")	
	{
		toolTip($('name'), 4);
		return false;
	}
	
	if($F('mail') == "")	
	{
		toolTip($('mail'), 5);
		return false;
	}
	
	
	if(!(Exp1.exec($F('mail'))))
	{
		toolTip($('mail'), 6);
		return false;
	}
	
	if($F('re_mail') == "")	
	{
		toolTip($('re_mail'), 7);
		return false;
	}
	
	if($F('re_mail') != $F('mail'))	
	{
		toolTip($('re_mail'), 8);
		return false;
	}
	
	if($('code').disabled)	
	{
		toolTip($('code'), 12);
		return false;
	}
	
	if($F('code') == "")	
	{
		toolTip($('code'), 9);
		return false;
	}
	
	return true;
}

function validateAbonament()
{
	
	m=0;m2=0;m3=0;
			
	if (document.forms['abonament'].plan1.length)
	{
		for(k=0;k<document.forms['abonament'].plan1.length;k++)
		{
			if (document.forms['abonament'].plan1[k].checked==true) 
			{
				 m=1;
			}
		}
	}
	else 
	{
		if (document.forms['abonament'].plan1.checked==true) 
			{
				 m=1;
			}
	}
	
	
	if (document.forms['abonament'].plan2.length)
	{
		for(k=0;k<document.forms['abonament'].plan2.length;k++)
		{
			if (document.forms['abonament'].plan2[k].checked==true) 
			{
				 m2=1;
			}
		}
	}
	else 
	{
		if (document.forms['abonament'].plan2.checked==true) 
			{
				 m2=1;
			}
	}
	
	if (document.forms['abonament'].plan3.length)
	{
		for(k=0;k<document.forms['abonament'].plan3.length;k++)
		{
			if (document.forms['abonament'].plan3[k].checked==true) 
			{
				 m3=1;
			}
		}
	}
	else 
	{
		if (document.forms['abonament'].plan3.checked==true) 
			{
				 m3=1;
			}
	}
	
	
	if ( (m==0) && (m2==0) && (m3==0) )
	{
		 alert('Не сте избрали `Тарифи`');
		 return false;	
	}
	
	
	/*
	m=0
			
	if (document.forms['abonament'].plan.length)
	{
		for(k=0;k<document.forms['abonament'].plan.length;k++)
		{
			if (document.forms['abonament'].plan[k].checked==true) 
			{
				 m=1;
			}
		}
	}
	else 
	{
		if (document.forms['abonament'].plan.checked==true) 
			{
				 m=1;
			}
	}
	
	if (m==0) 
	{
		 alert('Не сте избрали `Тарифи`');
		 return false;	
	}
	*/
	if($F('name') == "")	
	{
		alert('Не сте въвели `Име`');
		$('name').focus();
		return false;
	}
	
	if($F('last_name') == "")	
	{
		alert('Не сте въвели `Фамилия`');
		$('last_name').focus();
		return false;
	}
	
	if($F('country') == "")	
	{
		alert('Не сте въвели `Държава`');
		$('country').focus();
		return false;
	}
	
	if($F('city') == "")	
	{
		alert('Не сте въвели `Град`');
		$('city').focus();
		return false;
	}
	
	if($F('address') == "")	
	{
		alert('Не сте въвели `Адрес`');
		$('address').focus();
		return false;
	}
	
	if($F('post_code') == "")	
	{
		alert('Не сте въвели `Пощенски код`');
		$('post_code').focus();
		return false;
	}
	
	if($F('phone') == "")	
	{
		alert('Не сте въвели `Телефонен номер`');
		$('phone').focus();
		return false;
	}
	
	
	if($F('mail') == "")	
	{
		alert('Не сте въвели `E-mail`');
		$('mail').focus();
		return false;
	}
	
	var Exp1=/^[a-zA-Z0-9\._-]+@+[a-zA-Z0-9\._-]+\.+[a-zA-Z]{2,4}$/;
	if(!(Exp1.exec($F('mail'))))
	{
		alert('Моля въведете валиден `E-mail`!');
        $('mail').focus();
		return false;
	}
	
	if($('present').checked)	
	{
		if($F('name3') == "")	
		{
			alert('Не сте въвели `Име`');
			$('name3').focus();
			return false;
		}
	
		if($F('last_name2') == "")	
		{
			alert('Не сте въвели `Фамилия`');
			$('last_name2').focus();
			return false;
		}
		if($F('address2') == "")	
		{
			alert('Не сте въвели `Адрес`');
			$('address2').focus();
			return false;
		}
	
		if($F('post_code2') == "")	
		{
			alert('Не сте въвели `Пощенски код`');
			$('post_code2').focus();
			return false;
		}
	
		if($F('phone2') == "")	
		{
			alert('Не сте въвели `Телефонен номер`');
			$('phone2').focus();
			return false;
		}
	
		if($F('mail2') == "")	
		{
			alert('Не сте въвели `E-mail`');
			$('mail2').focus();
			return false;
		}
	
		if(!(Exp1.exec($F('mail2'))))
		{
			alert('Моля въведете валиден `E-mail`!');
        	$('mail2').focus();
			return false;
		}
	}
	
	return true;
}

function mailCheck()
{
	if($F('mail') != '')
	{
	  $('mail').disabled = true;
	  new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'mailCheck',
							mail: $F('mail')
						}, 
						onComplete: function (result) { if(result.responseText != "done") {$('mail').value = ''; toolTip($('mail'), 10);} $('mail').disabled = false;}
					 }
					);
	}
}

function codeCheck()
{
	if($F('code') != '')
	{
	  $('code').disabled = true;
	  new Ajax.Request(file, 
					 { parameters: 
					 	{ 
							func: 'codeCheck',
							code: $F('code')
						}, 
						onComplete: function (result) 
						{ 
							if(result.responseText != "done") 
							{
								$('code').value = ''; toolTip($('code'), 11);
							}
							else
							{
								closeToolTip();
							}
							$('code').disabled = false;
						}
					 }
					);
	}
}





function hideMessages()
{
	var msgA = document.getElementsByClassName('okmsg');
	for (var i=0; i<msgA.length; i++){
		var div = msgA[i];
		
		new Effect.DropOut(div);	
	}
	
	var msgA = document.getElementsByClassName('errormsg');
	for (var i=0; i<msgA.length; i++){
		var div = msgA[i];
		
		new Effect.DropOut(div);
	}
}

function showHideSendFriend()
{
	if($('sendFriend').style.display == 'none')
	{
		showSendFriend();
	}
	else
	{
		hideSendFriend();
	}	
}

function subscribeFriend(chk)
{
	if(chk.checked)
	{
		$('subscribe_friend').show();
	}
	else
	{
		$('subscribe_friend').hide();
	}		
}

function paymentForm(chk)
{
	if(chk.checked)
	{
		$('payment_form').show();
	}
	else
	{
		$('payment_form').hide();
	}		
}

function tarifni(type)
{
	if(type == 2)
	{
		$('tTable1').hide();
		$('tTable2').show();
		$('tTable3').hide();
		
		
	}
	else if(type == 3)
	{
		$('tTable1').hide();
		$('tTable2').hide();
		$('tTable3').show();
		
	}
	else
	{
		$('tTable1').show();
		$('tTable2').hide();
		$('tTable3').hide();
		
		
	}
	
	
}	

function subscribePaymentMethod(sel)
{
	if(sel.value == 3)
	{
		$('agentsTbl').show();
	}
	else
	{
		$('agentsTbl').hide();
	}
	if(sel.value == 1)
	{
		$('banksTbl').show();
	}
	else
	{
		$('banksTbl').hide();
	}	
	
	if(sel.value == 2)
	{
		$('ckechsTbl').show();
	}
	else
	{
		$('ckechsTbl').hide();
	}	
}

function showSendFriend()
{
	new Effect.Grow('sendFriend');
}

function hideSendFriend()
{
	new Effect.Shrink('sendFriend');
}

function loadAlt(imgAltContainer)
{
	var galTitle    = "";
	var imgTitle    = "";
	var titleToShow = "";
	
	if($(imgAltContainer)) imgTitle = $(imgAltContainer).innerHTML;
	if($('gallery_title')) galTitle = $('gallery_title').innerHTML;
	
	if(imgTitle != "") 		titleToShow = imgTitle;
	else if(galTitle != "") titleToShow = galTitle;
	
	if(titleToShow != "" && $('big_image_title')) $('big_image_title').innerHTML = titleToShow;
}


Event.observe(window, 'load', function (){setTimeout("hideMessages()", 4000);}, false);



/////////////////// NEW /////////////////////////////////////

function loadIndexArticles(active, container, type)
{
	new Ajax.Updater(container, file, 
					 { parameters: 
					 	{ 
							func: 'aGetIndexArticlesHtml',
							active: active,
							type: type,
							container: container
						}
					 }
					);
}

function loadIndexVideoNews(active)
{
	new Ajax.Updater('video_news', file, 
					 { parameters: 
					 	{ 
							func: 'aGetIndexVideoNewsHtml',
							active: active
						}
					 }
					);	
}

function rSetStyle(x, cls)
{
	x.className = cls;
}

function noteField(el)
{
	el = $(el);
	var txt = el.value;
	new Event.observe(el, 'focus', function() 
	{
		if(el.value == txt)
		{
			el.value = "";
		}
	});
	
	new Event.observe(el, 'blur', function() 
	{
  		if(el.value == "")
		{
			el.value = txt;
		}	
	});
}

function selectAll(el)
{
	new Event.observe(el, 'click', function() 
	{
		$(el).focus();
		$(el).select();
	});
	
}

function showUrl(url)
{
	var u = url + '&mode=articles&' + $('category_id').serialize();
	$('url').value = u;
}

function showPlane(airlineID, planeID)
{
	new Ajax.Updater('planesHolder', file, 
					 { parameters: 
					 	{ 
							func      : 'htmlPlane',
							airlineID : airlineID,
							planeID   : planeID
						}
					 }
					);	
}

function rate(rate)
{
	$('rating').value = rate;
	$('new_rate').style.width = (rate * 21) + "px";
}

function saveAirlineComment()
{
	var data = $('newComment').serialize(true);
	data.func = 'addCommentAirline';
	new Ajax.Request(file, 
					 { parameters: data,
						onComplete: function (result) 
						{ 
							$('saveResult').innerHTML = result.responseText;
						}
					 }
					);	
}

function sendFreeCalendarRequest()
{
	var data = $('order_form').serialize(true);
	data.func = 'sendFreeCalendarRequest';
	data.json = 1;
	new Ajax.Request(file, 
					 { parameters: data,
						onComplete: function (result) 
						{ 
							var res = eval('(' + result.responseText + ')');
							
							if(!res.error)
							{
								$('order_form').reset();
								window.location.href = '/thankyou.php?mode=calendars';
							}
							else
							{
								var container = document.getElementById("saveResult");
								
								while(container.childNodes.length) container.removeChild(container.firstChild);
								
								var newdiv = document.createElement("div");
								newdiv.innerHTML = res.msg;
								
								container.appendChild(newdiv);
							}
						}
					 }
					);	
}

function sendFreeBrochuresRequest()
{
	var data = $('order_form').serialize(true);
	data.func = 'sendFreeBrochuresRequest';
	data.json = 1;
	new Ajax.Request(file, 
					 { parameters: data,
						onComplete: function (result) 
						{ 
							var res = eval('(' + result.responseText + ')');
							
							if(!res.error)
							{
								$('order_form').reset();
								window.location.href = '/thankyou.php?mode=brochures';
							}
							else
							{
								$('saveResult').innerHTML = res.msg;	
							}
						}
					 }
					);	
}

function sendRequestInfo()
{
	var data = $('requestForm').serialize(true);
	data.func = 'sendRequestInfo';
	data.json = 1;
	new Ajax.Request(file, 
					 { parameters: data,
						onComplete: function (result) 
						{ 
							var res = eval('(' + result.responseText + ')');
							
							if(!res.error)
							{
								$('requestForm').reset();
								window.location.href = '/thankyou.php?mode=request';
							}
							else
							{
								$('saveResult').innerHTML = res.msg;
							}
						}
					 }
					);	
}

function loadSubSubMenu(subMenuParent, current)
{
	new Ajax.Updater('subSubMenuDiv', file, 
					 { parameters: 
					 	{ 
							func   : 'loadSubSubMenu',
							parent : subMenuParent,
							current: current
						}
					 }
					);	
}

function loadTab(num)
{
	$('tab_1').hide();	
	$('tab_2').hide();	
	$('tab_3').hide();	
	$('tab_4').hide();	
	
	$('tab_' + num).show();
	
	$('lnk_1').className = "";
	$('lnk_2').className = "";
	$('lnk_3').className = "";
	$('lnk_4').className = "";
	
	$('lnk_' + num).className = "active_tabbb";
}

function enlargeText(section)
{
	$("short_" + section).hide();
	$("long_" + section).show();
}

function smallText(section)
{
	$("short_" + section).show();
	$("long_" + section).hide();
}

////////////////////////////////////////////////////////////
