function start() {
	//start
	
	if(jskomShow&&$('komunikat')) {
		jskomAppear();
		$('komunikat').observe('click',jskomFadeOut);
	}
	if($('subpage_form')) {
		var V = new Validate();
		V.formname = 'subpage_form';
		V.register('first_name','isEmpty',{});
		V.register('first_name','isProperName',{});
		V.register('last_name','isEmpty',{});
		V.register('last_name','isProperName',{});
		V.register('title','isEmpty',{});
		V.register('company','isEmpty',{});
		V.register('email','isEmpty',{});
		V.register('email','isEmail',{});
		if(lang=='dk') {
			V.register('phone_number','isProperPhone',{});
			V.register('phone_number','isEmpty',{});
		}
		else {
			V.register('phone_prefix','isEmptyPhoneEn',{});
			V.register('phone_number','isEmptyPhoneEn',{});
			V.register('phone_prefix','isProperPhoneEn',{});
			V.register('phone_number','isProperPhoneEn',{});
		}
		V.register('captcha','isEmpty',{});

		$(V.formname).onsubmit = null;
		V.observeAll();
	}
}
window.onload = start;

function goBack() {
  window.history.back()
  }

function checkCF(oForm) {
	if(oForm.first_name.value.length<=0) {
		if(lang=='en') alert('Please enter your first name');
		else alert('Venligst indtast dit fornavn');
		oForm.first_name.focus();
		return false;
	}
	if(oForm.last_name.value.length<=0) {
		if(lang=='en') alert('Please enter your last name');
		else alert('Venligst indtast dit efternavn');
		oForm.last_name.focus();
		return false;
	}
	if(oForm.title.value.length<=0) {
		if(lang=='en') alert('Please enter your title');
		else alert('Venligst indtast din titel');
		oForm.title.focus();
		return false;
	}
	if(oForm.email.value.length<=0) {
		if(lang=='en') alert('Please enter your email');
		else alert('Venligst indtast din e-mail');
		oForm.email.focus();
		return false;
	}
	if(!isEmail(oForm.email.value)) {
		if(lang=='en') alert('Please enter a proper email');
		else alert('Venligst indtast en korrekt e-mail');
		oForm.email.focus();
		return false;
	}
	if(oForm.company.value.length<=0) {
		if(lang=='en') alert('Please enter your company');
		else alert('Venligst indtast dit telefonnummer');
		oForm.company.focus();
		return false;
	}
	if(oForm.phone_number.value.length<=0) {
		if(lang=='en') alert('Please enter your phone number');
		else alert('Venligst indtast koden før du trykker Send');
		oForm.phone_number.focus();
		return false;
	}
	if(oForm.captcha.value.length<=0) {
		if(lang=='en') alert('Please enter the code before you click Submit');
		else alert('');
		oForm.captcha.focus();
		return false;
	}
	return true;
}

function setText(oTextInput) {
	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;
}
function clearText(oTextInput) {
	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';
}

function isEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return(reg.test(address));
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function selectedRadioValue(oForm, sRadioName) {
	var retval = '';
	for(var i=0;i<oForm.elements.length;i++) {
		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;
		if(oForm.elements[i].checked) retval = oForm.elements[i].value;
	}
	return retval;
}

function showKom(kom,kom_status) {
	if(kom_status=='error') {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_error.png';
	}
	else if(kom_status=='info') {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_info.png';
	}
	else {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_ok.png';
	}
	$('kom_text').update(kom);
	jskomAppear();
}
var jskomShow=false;
var jskomZostaw=true;
var peJskom;
function jskomAppear() {
	try{
		//Effect.Appear('jskom');
		$('komunikat').show();
	}
	catch (exc) {
		$('komunikat').show();
	}
	if(!jskomZostaw) peJskom = new PeriodicalExecuter(function(peJskom) {
			jskomFadeOut();
		}, 4);
}
function jskomFadeOut() {
	try{
		Effect.Fade('komunikat');
		}
	catch (exc) {
		$('komunikat').hide();
	}
	//$('komunikat').update('');
	if(peJskom) peJskom.stop();
}


//stara galeria
var img;
var galFotos = [];
var aktFoto = 0;
function setGal(fot,fotos) {
	if(typeof fotos=='object') galFotos = fotos;
	else galFotos = [];
	$('bigFotoContainer').show();
	aktFoto = 0;
	if(galFotos.length>0) {
		for(var i=0;i<galFotos.length;i++) {
			if(galFotos[i]==fot) aktFoto = i;
		}
	}
	pokazFotoGal(fot);
}
function pokazFotoGal(fot) {
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	fotoNav();
	//$('main').hide();	
}
function pokazFoto(fot) {
	galFotos = [];
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	$('bigFotoContainer').show();
	//$('main').hide();
	aktFoto = 0;
	fotoNav();
}
function showimg(evt) {
	$('bigFotoImg').hide();
	$('bigFotoImg').update(img);
	$('bigFotoImg').show();
	var dim = document.viewport.getDimensions();
	if(img.width>dim.width||img.height>dim.height-160) {
		var new_size = image_small_maker(img.width, img.height, dim.width, dim.height-160)
		img.setStyle({'width':new_size[0]+'px','height':new_size[1]+'px'});
	}
}
function wywalFoto() {
	$('bigFotoContainer').hide();
	$('bigFotoImg').hide();
	//$('main').show();
}
function fotoNav() {
	if(aktFoto>0) $('bigFotoPrev').show();
	else $('bigFotoPrev').hide();
	if(aktFoto<galFotos.length-1) $('bigFotoNext').show();
	else $('bigFotoNext').hide();
}
function prevFoto() {
	if(aktFoto<=0) return;
	aktFoto--;
	pokazFotoGal(galFotos[aktFoto]);
}
function nextFoto() {
	if(aktFoto>galFotos.length-1) return;
	aktFoto++;
	pokazFotoGal(galFotos[aktFoto]);
}
function image_small_maker(orig_width, orig_height, max_width, max_height) {
	var xRatio = max_width / orig_width; 
	var yRatio = max_height / orig_height; 
	var new_width = 0;
	var new_height = 0;
	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 
	 new_width = orig_width; 
	 new_height = orig_height; 
	} 
	else if ((xRatio * orig_height) < max_height) { 
	 new_height = Math.ceil(xRatio * orig_height); 
	 new_width = max_width; 
	} 
	else { 
		new_width = Math.ceil(yRatio * orig_width); 
		new_height = max_height; 
		}
	var output = [];
	output.push(Math.round(new_width));
	output.push(Math.round(new_height));
	return output;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function viewportDims() {
	var viewportwidth;
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
 	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return {width:viewportwidth,height:viewportheight};
}















var contentIds=Array();
function showContentBig(id) {
	for(i=0;i<contentIds.length;i++) if (contentIds[i]!=id) {
		$('content_'+contentIds[i]).hide();
		$('leftnav_'+contentIds[i]).removeClassName('leftnav_element_big_a');
		$('leftnav_'+contentIds[i]).addClassName('leftnav_element_big');
	}
	$('content_'+id).show();
	$('leftnav_'+id).removeClassName('leftnav_element_big');
	$('leftnav_'+id).addClassName('leftnav_element_big_a');
	toggleBIR(1);
	aktBIR=id;
}
function showContent(id) {
	for(i=0;i<contentIds.length;i++) if (contentIds[i]!=id) {
		$('content_'+contentIds[i]).hide();
		$('leftnav_'+contentIds[i]).removeClassName('leftnav_element_a');
		$('leftnav_'+contentIds[i]).addClassName('leftnav_element');
	}
	$('content_'+id).show();
	$('leftnav_'+id).removeClassName('leftnav_element');
	$('leftnav_'+id).addClassName('leftnav_element_a');
}
function declareContent(id) {
	contentIds.push(id);
}



var listArr=Array();
function declareList(listId) {
	listArr[listId]=0;
}
	
function toggleList(listId) {
	if (listArr[listId]==1) {
		$('kat_lista_'+listId).hide();
		$('arr_'+listId).src='images/_arr_down.png';
		listArr[listId]=0;		
	}
	else {
		$('kat_lista_'+listId).show();
		$('arr_'+listId).src='images/_arr_up.png';
		listArr[listId]=1;
	}
		
}




var peMenu;
var aktMenu;
//			var aktMenu;
//			var aktMenu;	
for (var k=1;k<=4;k++) newImage('images/dk_menu_images/menu_'+k+'.gif');
for (var k=1;k<=4;k++) newImage('images/dk_menu_images/menu_'+k+'_active.gif');
for (var k=1;k<=4;k++) newImage('images/en_menu_images/menu_'+k+'.gif');
for (var k=1;k<=4;k++) newImage('images/en_menu_images/menu_'+k+'_active.gif');
function showMenu(i,la) {
	aktMenu = i;
	for (var j=1;j<=4;j++) if (i!=j) $('menu_drop_'+j).hide();				
	$('menu_drop_'+i).show();
	$('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'_active.gif')
	//Effect.BlindDown('menu_drop_'+i, { duration: 0.5 });
	//peMenu = new PeriodicalExecuter(hideMenu,1);
}
function hideMenuOne(i,j,la) {			
	$('menu_drop_'+i).hide();	
	if (i!=j) $('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'.gif')
	//Effect.BlindUp('menu_drop_'+i, { duration: 0.5 });				
}
function highlightMenu(i,la) {
	aktMenu = i;
	for (var j=1;j<=4;j++) if (i!=j) $('menu_drop_'+j).hide();				
	
	$('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'_active.gif')
	//Effect.BlindDown('menu_drop_'+i, { duration: 0.5 });
	//peMenu = new PeriodicalExecuter(hideMenu,1);
}
function dishighlightMenu(i,j,la) {			
	$('menu_drop_'+i).hide();	
	if (i!=j) $('mainmenu_img_'+i).src=('images/'+la+'_menu_images/menu_'+i+'.gif')
	//Effect.BlindUp('menu_drop_'+i, { duration: 0.5 });				
}




function showProfile(id) {
	window.location='asseco_live,'+id;
}



function defPr(pid) {
	var kid = $('pr_'+pid).readAttribute('k1');
	if(kid>0) {
		if(listArr[kid]!=1) toggleList(kid);
	}
	$('pr_'+pid).scrollTo();
}

function defK2(k2id) {
	var kid = $('k2_'+k2id).readAttribute('k1');
	if(kid>0) {
		if(listArr[kid]!=1) toggleList(kid);
	}
	$('k2_'+k2id).scrollTo();
}

function defK1(k1id) {
	/*k1id2=0;
	if (k1id==111) k1id2=109;
	if (k1id==127) k1id2=111;
	if (k1id==118) k1id2=127;
	if (k1id==123) k1id2=118;
	if (k1id==125) k1id2=123;
	if (k1id==undefined) k1id2=125;	*/
	if(k1id>0) {
		if(listArr[k1id]!=1) toggleList(k1id);
	}
	$('k1_'+k1id).scrollTo();
}
