/*
 *	NGSoft Bt. Copyright(c) 
 *	All rights reserved.
 *	info@ngsoft.hu
 * 
 *	@author N�meth Gergely
 *	@version 1.0
 *	@created 10-february-2008 17:54:23
 */

/*
 * 
 */
function DrawBoxes()
{
	var alldiv = document.getElementsByTagName('div');
	for(i=0;i<alldiv.length;i++)
	{
		var tagid = alldiv[i].getAttribute('id');
		if((tagid == 'loc0') || (tagid == 'description') || (tagid == 'companyinfo'))
		{
			Nifty("div#"+tagid, "fixed-height medium");
		}
	}
}

/*
 * Change Nifty Corners Color
 */
function ChangeColor(DivId, divbg, divfg)
{
	if(document.getElementById(DivId).style.backgroundColor != divbg)
	{
		var actObject = document.getElementById(DivId);
		var x = actObject.getElementsByTagName("B");
		
		actObject.style.backgroundColor = divbg;
		actObject.style.Color = divfg;
		
		for(i=0;i<x.length;i++)
		{
			if(x[i].className == "niftyfill") continue;
			if(x[i].className == "niftycorners")
			{
				x[i].style.borderColor = divbg;
			}
			else
			{
				x[i].style.backgroundColor = divbg;
			}
		}
	}
}

/*
 * Make Nifty Corners div
 */
function MakeStyle(DivId, bgcolor, fgcolor)
{
 	var actDivObject = document.getElementById(DivId);
 	
 	if(actDivObject != null)
 	{
 		actDivObject.style.backgroundColor = bgcolor;
	 	actDivObject.style.color = fgcolor;
	 	Nifty('div#' + DivId, 'fixed-height medium');
 	}
}

/*
 * 
 */
function MakeGradientStyle(DivId)
{
	var actDivObject = document.getElementById(DivId);
 	
 	if(actDivObject != null)
 	{
	 	Nifty('div#' + DivId, 'fixed-height medium transparent');
 	}
}
 
/*
*	Niftyfize the result version 3 in gradient
*/
function NiftyQueryGradient(classname)
{
	var elements = YAHOO.util.Dom.getElementsByClassName(classname, 'div');
	
	for(i = 0; i < elements.length; i++)
	{
		var actTagId = elements[i].getAttribute('id');
		var actNode = document.getElementById(actTagId);
		
		if(actNode != null)
		{	
			Nifty('div#' + actTagId, 'transparent');
		}
	}
}
/*
 * 
 */
function CorrectBorder()
{
	var x = document.getElementById("page");
	var news_result = document.getElementById('needCorrection');
	if (x.clientHeight > 2048){
		var sbdivs = x.getElementsByTagName("DIV");
		for(i=0;i<sbdivs.length;i++){
			if(sbdivs[i].style.height == "2048px"){
				sbdivs[i].style.height = "100%";
			}
		}
	}
	if (news_result)
	{
		var sbdivs = x.getElementsByTagName("DIV");
		for(i=0;i<sbdivs.length;i++){
			if(sbdivs[i].style.height == "2048px"){
				sbdivs[i].style.height = "100%";
			}
		}
	}
}

/*
 * 
 */
function CorrectNodeOrder()
{
	var needCorrect = true; 
	
	var pager_01 = document.getElementById("slavepager_01");
	var pager_02 = document.getElementById("slavepager_02");
	var mpager_01 = document.getElementById("mainpager_01");
	var mpager_02 = document.getElementById("mainpager_02");
	
	var slavesorter = document.getElementById("slavesorter");
	
	if(slavesorter != null)
	{
		var mainsorter = document.getElementById("mainsorter");
		var mainsorterResult = document.getElementById("mainsorter_result");
		var slavesorterResult = document.getElementById("slavesorter_result");
		
		mainsorterResult.innerHTML = slavesorterResult.innerHTML;

		var resultArea = document.getElementById("resultArea");
		resultArea.removeChild(resultArea.firstChild);
	}
	
	if(pager_01 != null)
	{	
		var	content = document.getElementById("content");
		var ads_content = document.getElementById("ads_content");
		if(ads_content != null)
		{
			var resultArea = document.getElementById("resultArea");
			
			mpager_01.innerHTML = pager_01.innerHTML;
			mpager_02.innerHTML = pager_02.innerHTML;
			
			resultArea.removeChild(pager_01);
			resultArea.removeChild(pager_02);
			
			needCorrect=false;
		}
		
		var pager_01 = document.getElementById("slavepager_01");
		
		if((content != null) && (pager_01 != null))
		{
			content.replaceChild(pager_01, mpager_01);
			content.replaceChild(pager_02, mpager_02);
		}
		if(needCorrect)
		{
			pager_01.setAttribute('id', 'mainpager_01');
			pager_02.setAttribute('id', 'mainpager_02');
		}
		
	}
}
/**
 * CorrectContainer
 * @param {repair the container's height for M$IE}  
 */
 function CorrectContainer() {
 	
 	if(navigator.appName.indexOf('MSIE 7.0'))
 	{
 		document.getElementById('container').style.height = 'auto';
 	}
	else if(navigator.appName.indexOf('MSIE 6.0'))
	{
		var min_height = document.getElementById('menu').clientHeight;
	 	var act_cont_height = document.getElementById('container').clientHeight;
		if((min_height >= act_cont_height)||(act_cont_height==750))
		{
				document.getElementById('container').style.height = min_height;
		}
		else
		{
			document.getElementById('container').style.height = 'auto';
		}
	}
	
	/*document.getElementById('container').style.height = 'auto';
	alert(navigator.appName + navigator.appVersion);*/
}

/*
 * 
 */
function CorrectLinkBold(target, is_firefox)
{
		var search = /link-+[0-9]{1,3}/; 
		var elements = document.getElementsByTagName('a');
		for(i=(elements.length-1) ; i>0 ; i--)
		{
			var temp = elements[i].getAttribute('id');
			if(temp.match(search))
			{
				if(is_firefox == 1)
				{
					if(temp == target)
					{
						temp.style.setProperty('font-weigth','bold',null);
					}
					else
					{
						temp.style.setProperty('font-weigth','normal',null);
					}
				}
				else
				{
					if(temp == target)
					{
						temp.style.setAttribute('font-weigth','bold');
					}
					else
					{
						temp.style.setAttribute('font-weigth','normal');
					}
				}
			
			}
			if(temp == 'link-0')break;
		}
}

/*
 * 
 */
function CorrectNewsHeight()
{
	var elements = YAHOO.util.Dom.getElementsByClassName('news', 'div');
	for(i = 0; i < elements.length; i++)
	{
		var act_fame_img = elements[i].getElementsByTagName('img');
		if(act_fame_img[1] != null)
		{
			var act_fame = elements[i];
			var act_fame_text = elements[i].getElementsByTagName('p');
			if(act_fame_text[0].clientHeight < 130)
				var new_height = 190;
			else
				var new_height = act_fame_text[0].clientHeight+60;
			act_fame.style.height = new_height;
		}				
	}
}
/*
*	Niftyfize the result version 2
*/
function NiftyQuery_v_2(classname)
{
	var elements = YAHOO.util.Dom.getElementsByClassName(classname, 'div');
	
	for(i = 0; i < elements.length; i++)
	{
		var actTagId = elements[i].getAttribute('id');
		var actNode = document.getElementById(actTagId);
		Nifty('div#' + actTagId, 'height medium transparent');
	}
}

/*
 * 
 */
function hideall(handleDiv)
{
 	var x = YAHOO.util.Dom.getElementsByClassName(handleDiv, 'div');
 	for(i = 0; i < x.length; i++)
	{
		var actualTag = x[i].getAttribute('id');
		document.getElementById(actualTag).style.display = 'none';
	} 	
}

/*
 * 
 */
function giveDate()
{
	var today = new Date();
	var year = today.getFullYear();
	var month = today.getMonth()+2;
	if(month<10)
		{
		    month = '0'+month;
		}
	var day = today.getDate();
	if(day<10)
		{
		    day = '0'+day;
		}
	if(month > 12)
	{
		year = '2009';
		month = '01';
	}
	var today_string = year+'-'+month+'-'+day;
	return today_string;
}

/*
 * 
 */
function checkCategory(input)
{
	var act_cat = input.selectedIndex;
	
	if(act_cat != 0)
		{
			if(window.frames['shadowbox_content'].document.options_form.cat_ok.style.display == 'none')
			{
				window.frames['shadowbox_content'].document.options_form.cat_ok.style.display = '';
				window.frames['shadowbox_content'].document.options_form.cat_error.style.display = 'none';
			}
		}
		else
		{
			if(FormCheck)
			{
				var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_category');
				var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
				if(text_dst.innerHTML == '')
					text_dst.innerHTML = text_src.innerHTML
				else
					text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
			}
			window.frames['shadowbox_content'].document.options_form.cat_ok.style.display = 'none';
			window.frames['shadowbox_content'].document.options_form.cat_error.style.display = '';
			return false;
		}
	return true;
		
}

/*
 * 
 */
function checkPhone(input)
{
	var act_phone = input.value;
	var stripped = act_phone.replace(/[\(\)\.\-\/\ ]/g, '');
	
	if(!(isNaN(parseInt(stripped)))&&((stripped.length == 11)||(stripped.length == 10)))
	{
			if(window.frames['shadowbox_content'].document.options_form.phone_ok.style.display == 'none')
			{
				window.frames['shadowbox_content'].document.options_form.phone_ok.style.display = '';
				window.frames['shadowbox_content'].document.options_form.phone_error.style.display = 'none';
			}				
		}
		else
		{
			if(FormCheck)
			{
				var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_phone');
				var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
				if(text_dst.innerHTML == '')
					text_dst.innerHTML = text_src.innerHTML
				else
					text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
			}
			window.frames['shadowbox_content'].document.options_form.phone_ok.style.display = 'none';
			window.frames['shadowbox_content'].document.options_form.phone_error.style.display = '';
			return false;
		}
	return true;
		
}
function checkName(input,name2test)
{
	var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/;
	var test_name = input.value;
	if((!(test_name.match(illegalChars))) && (test_name!=''))
		{
			if(window.frames['shadowbox_content'].document.getElementById(name2test+'_ok').style.display == 'none')
			{
				window.frames['shadowbox_content'].document.getElementById(name2test+'_ok').style.display = '';
				window.frames['shadowbox_content'].document.getElementById(name2test+'_error').style.display = 'none';
			}
		}
		else
		{
			if(FormCheck)
				{
					var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_'+name2test);
					var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
					if(text_dst.innerHTML == '')
						text_dst.innerHTML = text_src.innerHTML
					else
						text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
				}
			window.frames['shadowbox_content'].document.getElementById(name2test+'_ok').style.display = 'none';
			window.frames['shadowbox_content'].document.getElementById(name2test+'_error').style.display = '';
			return false;
		}
		return true;
		
}
/*
 * 
 */
function checkMail(input)
{
	var emailFilter = /([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})/;
	var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/;
	var act_mail = input.value;
	
	if((emailFilter.test(act_mail))&&(!(act_mail.match(illegalChars))))
		{
			if(window.frames['shadowbox_content'].document.getElementById('email_ok').style.display == 'none')
				{
				window.frames['shadowbox_content'].document.getElementById('email_ok').style.display = '';
				window.frames['shadowbox_content'].document.getElementById('email_error').style.display = 'none';
			}
		}
		else
		{
			if(FormCheck)
				{
					var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_email');
					var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
					if(text_dst.innerHTML == '')
						text_dst.innerHTML = text_src.innerHTML
					else
						text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
				}
			window.frames['shadowbox_content'].document.getElementById('email_ok').style.display = 'none';
			window.frames['shadowbox_content'].document.getElementById('email_error').style.display = '';
			return false;
		}
		return true;
		
}

/*
 * 
 */
function limitText(textarea, countdown) 
{
	
	if (textarea.value.length > 500) 
	{
		textarea.value = textarea.value.substring(0, 500);
	}
	else 
	{
		countdown.value = 500 - textarea.value.length;
	}
}

/*
 * 
 */
function checkText(input, countdown)
{
	if(countdown != 'formcheck')
		limitText(input, countdown);
	var act_text = input.value;
	
	if(act_text != '')
	{
		if(window.frames['shadowbox_content'].document.options_form.text_ok.style.display == 'none')
		{
			window.frames['shadowbox_content'].document.options_form.text_ok.style.display = '';
			window.frames['shadowbox_content'].document.options_form.text_error.style.display = 'none';
		}
	}
	else
	{
		if(FormCheck)
			{
				var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_text');
				var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
				if(text_dst.innerHTML == '')
					text_dst.innerHTML = text_src.innerHTML
				else
					text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
			}
		window.frames['shadowbox_content'].document.options_form.text_ok.style.display = 'none';
		window.frames['shadowbox_content'].document.options_form.text_error.style.display = '';
		return false;
	}
	
	return true;
}

/*
 * 
 */
function checkPrice(input)
{
	var act_price = input.value;
	
	if(!(isNaN(act_price)) && (act_price.length != 0))
		{
			if(window.frames['shadowbox_content'].document.options_form.price_ok.style.display == 'none')
			{
				window.frames['shadowbox_content'].document.options_form.price_ok.style.display = '';
				window.frames['shadowbox_content'].document.options_form.price_error.style.display = 'none';
			}
			return true;			
		}
		else
		{
			if(FormCheck)
			{
				var text_src = window.frames['shadowbox_content'].document.getElementById('error_help_price');
				var text_dst = window.frames['shadowbox_content'].document.getElementById('info_container');
				if(text_dst.innerHTML == '')
					text_dst.innerHTML = text_src.innerHTML
				else
					text_dst.innerHTML = text_dst.innerHTML + '<br>' + text_src.innerHTML
			}
			window.frames['shadowbox_content'].document.options_form.price_ok.style.display = 'none';
			window.frames['shadowbox_content'].document.options_form.price_error.style.display = '';
			return false;
		}
}

/*
 * 
 */
function HideIcons()
{
	var x = window.frames['shadowbox_content'].document.getElementsByTagName('img');

	for(i = 0; i < x.length; i++)
	{
		if((x[i].id == 'cat_ok')||(x[i].id == 'cat_error')||(x[i].id == 'phone_ok')||(x[i].id == 'phone_error')||(x[i].id == 'email_ok')||(x[i].id == 'email_error')||(x[i].id == 'price_ok')||(x[i].id == 'price_error')||(x[i].id == 'text_ok')||(x[i].id == 'text_error')
		||(x[i].id == 'surname_ok')||(x[i].id == 'surname_error')||(x[i].id == 'forename_ok')||(x[i].id == 'forename_error'))
		{
			x[i].style.display='none';
		}
	}
}

/*
 * 
 */
function handlef(id)
{
 	var e = document.getElementById(id);
 	e.style.display = e.style.display == "none" ? "block" : "none";
}
 
/*
 * 
 */
function handleDivView(id)
{
	var isAds_Content = document.getElementById('ads_content');
	var x = $(id);
	if(x.style.display == 'none')
	{
		if(isAds_Content != null)
		{
			var real_height = document.getElementById('container').clientHeight;
			alert(real_height);
			var real_height = real_height + document.getElementById('ads_options').clientHeight;
			alert(real_height);
		}
		x.show();
		
	}
	else
	{
		x.hide();
	}
}
/*
 * 
 */
function tooltip(dst)
{
	var dst_div		= window.frames['shadowbox_content'].document.getElementById('info_container');
	
	if(dst == 'none')
	{
		dst_div.innerHTML = '';
		dst_div.style.display = 'none';
		return false;		
	}
	var src_span	= window.frames['shadowbox_content'].document.getElementById(dst);
	
	if(dst_div.style.display = 'none')
		dst_div.style.display = '';
	
		dst_div.innerHTML = src_span.innerHTML
}

/*
 * 
 */
function checkFormAll(from)
{
	
	FormCheck = true;
	
	var subscribe_form = window.frames['shadowbox_content'].document.getElementById('subscribe_form');
	if(subscribe_form != null)
	{
		window.frames['shadowbox_content'].document.getElementById('info_container').innerHTML='';
		
		var input_mail		= window.frames['shadowbox_content'].document.getElementById('email');
		var input_forename	= window.frames['shadowbox_content'].document.getElementById('forename');
		var input_surname	= window.frames['shadowbox_content'].document.getElementById('surname');
		window.frames['shadowbox_content'].document.getElementById('info_container').style.display='';
		var chk_01 = checkName(input_surname, "surname");
		var chk_02 = checkName(input_forename, "forename");
		var chk_03 = checkMail(input_mail);
		if(!(chk_01 && chk_02 && chk_03))
		{
			FormCheck = false;
			return false;
			
		}
		
		window.frames['shadowbox_content'].document.getElementById('info_container').style.display='none';
		
	}
	else
	{
		window.frames['shadowbox_content'].document.getElementById('info_container').innerHTML='';
		tooltip('none');
	
		var input_mail 		= window.frames['shadowbox_content'].document.options_form.email;
		var input_cate		= window.frames['shadowbox_content'].document.options_form.select_category;
		var input_mail		= window.frames['shadowbox_content'].document.options_form.email;
		var input_phone		= window.frames['shadowbox_content'].document.options_form.phone;
		var input_price		= window.frames['shadowbox_content'].document.options_form.price;
		var input_text		= window.frames['shadowbox_content'].document.options_form.ads_text;
		
		window.frames['shadowbox_content'].document.getElementById('info_container').style.display='';
		
		var chk_02 = checkCategory(input_cate);
		var chk_03 = checkPhone(input_phone);
		var chk_01 = checkMail(input_mail);
		var chk_04 = checkPrice(input_price);
		var chk_05 = checkText(input_text, 'formcheck');
		if(!(chk_01 && chk_02 && chk_03 && chk_04 && chk_05))
		{
			FormCheck = false;
			return false;
			
		}
		window.frames['shadowbox_content'].document.getElementById('info_container').style.display='none';
	}
	return true;
}
function handleinfo(id)
{
	var x = $(id);
	x.innerHTML  = "";
}
//pretag what
//number as loop variable 
function handleAllInfo(pretag, number)
{
	for(i=0; i<number; i++)
	{
		id = pretag + i;
		var e = document.getElementById(id);
 		e.style.display = e.style.display == "none" ? "" : "none";
	}
}

function hideElement (element) 
{
	if (element.style) 
	{
		element.style.display = 'none';
	}
}

function showElement (element) 
{
	if (element.style) 
	{
		element.style.display = '';
	}
}
function sbTutiInit(){
	Shadowbox.init({
        skipSetup: true // skip the automatic setup
    });
	
    // set up all anchor elements with a 'movie' class to work with Shadowbox
    for(i=0;i<10;i++)
	{
		//var lookfor = 
		if($('sb_gall_'+i))
		{
			var classname = 'sb_gallery_'+i;
			Shadowbox.setup($$('a.'+classname),{
				gallery:i
			});
		}
		
	}
	
}
