
function newWindow(a,b,c,d,e,h,L,design){

      url = '/all.php?type=tred&a='+a+'&b='+b+'&c='+c+'&d='+d+'&e='+e+'&h='+h+'&L='+L+'&design='+design; 
		show3D = window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=750, height=500");
		show3D.focus();
}

var menuCurrent = null;
function toggleMenu(obj) {
	if (menuCurrent != null && menuCurrent != obj) {
		document.getElementById('sm'+menuCurrent).style.display = 'none';	
	}
	if (document.getElementById('sm'+obj) != undefined) {
		document.getElementById('sm'+obj).style.display = 'block';
		menuCurrent = obj;
	}
}

function doSearch(path) {
	/*re = /\$|,|@|#|~|`|´|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$/g;
	var query = document.getElementById('query').value.replace(re, "");*/
	var query = document.getElementById('query').value;
	window.location.href = '/'+encodeURIComponent(path)+'/'+encodeURIComponent(query)+'/';
}



function doSearchEnter(e, path){
	e = e || event;
	if (e.keyCode == 13) {
		doSearch(path);
		return false;
	}
}

function customPrompt(q, d, params) {
	disable();
	document.getElementById('prompt_q').innerHTML = q;
	document.getElementById('prompt_value').value = d;
	$('#prompt').center();
	document.getElementById('prompt').style.display = 'block';
	
	document.getElementById('prompt_ok').onclick = function() {
		for (key in params) {
			document.getElementById(key).value = params[key];	
		}
		document.getElementById('value').value = document.getElementById('prompt_value').value;
		
		document.getElementById('form_action').submit();
	}
	
	document.getElementById('prompt_value').focus();
	document.getElementById('prompt_value').select();
}

function closePrompt() {
	document.getElementById('prompt').style.display = 'none';
	document.getElementById('disable').style.display = 'none';
}

function customConfirm(q, params) {
	disable();
	document.getElementById('confirm_q').innerHTML = q;
	$('#confirm').center();
	document.getElementById('confirm').style.display = 'block';
	
	document.getElementById('confirm_ok').onclick = function() {
		for (key in params) {
			document.getElementById(key).value = params[key];	
		}

		document.getElementById('form_action').submit();
	}
}

function closeConfirm() {
	document.getElementById('confirm').style.display = 'none';	
	document.getElementById('disable').style.display = 'none';
}

function customAlert(t) {
	disable();
	document.getElementById('alert_t').innerHTML = t;
	$('#alert').center();
	document.getElementById('alert').style.display = 'block';
}

function closeAlert() {
	document.getElementById('alert').style.display = 'none';
	document.getElementById('disable').style.display = 'none';
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

function disable() {
	var d = document.getElementById('disable').style;
	d.height = getDocHeight()+'px';
	d.width = getDocWidth()+'px';
	d.display = 'block';
}

function enable() {
	document.getElementById('disable').style.display = 'none';
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}

requiredFields = new Array();

function checkValues(obj, form_id) {
	var error = false;

	for (field_id in requiredFields[obj]) {
		if (requiredFields[obj][field_id]['type'] == 'textfield') {
			if (!requiredFields[obj][field_id]['param'].test(document.getElementById(field_id).value) && ((requiredFields[obj][field_id]['only_check_if_value'] == true && document.getElementById(field_id).value != '') || (requiredFields[obj][field_id]['check_if_value'] && document.getElementById(requiredFields[obj][field_id]['check_if_value']).value != '' && document.getElementById(requiredFields[obj][field_id]['check_if_value']).value > 0) || (requiredFields[obj][field_id]['check_if_checked'] && document.getElementById(requiredFields[obj][field_id]['check_if_checked']) != undefined && document.getElementById(requiredFields[obj][field_id]['check_if_checked']).checked == true) || (requiredFields[obj][field_id]['only_check_if_value'] != true && !requiredFields[obj][field_id]['check_if_value'] && !requiredFields[obj][field_id]['check_if_checked']))) {
				error = true;
				
				if (requiredFields[obj][field_id]['tab'] != undefined) {
					selectTab(document.getElementById('tab'+requiredFields[obj][field_id]['tab']));
				}
	
				document.getElementById(field_id).parentNode.getElementsByTagName('span')[1].innerHTML = requiredFields[obj][field_id]['error'];
				document.getElementById(field_id).parentNode.getElementsByTagName('span')[1].style.display = 'inline';
					
				document.getElementById(field_id).className += ' error_input';
				document.getElementById(field_id).onkeyup = function () {
					if (requiredFields[obj][field_id]['param'].test(document.getElementById(field_id).value) || (requiredFields[obj][field_id]['only_check_if_value'] == true && document.getElementById(field_id).value == '') || (requiredFields[obj][field_id]['check_if_value'] && !document.getElementById(requiredFields[obj][field_id]['check_if_value']).value) || (requiredFields[obj][field_id]['check_if_checked'] && document.getElementById(requiredFields[obj][field_id]['check_if_checked']).checked == false)) {
						this.className = this.className.replace(' error_input', '');
						document.getElementById(field_id).parentNode.getElementsByTagName('span')[1].style.display = 'none';
						this.onkeyup = null;
					}
				}
				
				document.getElementById(field_id).onchange = function () {
					if (requiredFields[obj][field_id]['param'].test(document.getElementById(field_id).value) || (requiredFields[obj][field_id]['only_check_if_value'] == true && document.getElementById(field_id).value == '') || (requiredFields[obj][field_id]['check_if_value'] && !document.getElementById(requiredFields[obj][field_id]['check_if_value']).value) || (requiredFields[obj][field_id]['check_if_checked'] && document.getElementById(requiredFields[obj][field_id]['check_if_checked']).checked == false)) {
						this.className = this.className.replace(' error_input', '');
						document.getElementById(field_id).parentNode.getElementsByTagName('span')[1].style.display = 'none';
						this.onchange = null;
					}
				}
				
				document.getElementById(field_id).onfocus = function () {
					if (requiredFields[obj][field_id]['param'].test(document.getElementById(field_id).value) || (requiredFields[obj][field_id]['only_check_if_value'] == true && document.getElementById(field_id).value == '') || (requiredFields[obj][field_id]['check_if_value'] && !document.getElementById(requiredFields[obj][field_id]['check_if_value']).value) || (requiredFields[obj][field_id]['check_if_checked'] && document.getElementById(requiredFields[obj][field_id]['check_if_checked']).checked == false)) {
						this.className = this.className.replace(' error_input', '');
						document.getElementById(field_id).parentNode.getElementsByTagName('span')[1].style.display = 'none';
						this.onfocus = null;
					}
				}
										
				document.getElementById(field_id).focus();
				break;
			}
		} else if (requiredFields[obj][field_id]['type'] == 'option') {
			if (!document.getElementById(field_id).length || !requiredFields[obj][field_id]['param'].test(document.getElementById(field_id).options[document.getElementById(field_id).selectedIndex].value)) {
				error = true;
				
				if (requiredFields[obj][field_id]['tab'] != undefined) {
					selectTab(document.getElementById('tab'+requiredFields[obj][field_id]['tab']));	
				}
				
				alert(requiredFields[obj][field_id]['error']);
				
				document.getElementById(field_id).focus();
				break;
			}
		}
	}	

	if (!error) {
		document.getElementById(form_id).submit();
	}
}

function onlyNumbers(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	// Backspace, Tab, Delete, Piletaster, Tal
	if (charCode == 8 || charCode == 9 || charCode == 127 || (charCode >= 17 && charCode <= 20) || (charCode >= 48 && charCode <= 57)) {
		return true;	
	}
	return false;
}

function toggleInputs(obj, number, settings) {
	/*
	settings['active_parameter_id'] = x;
	settings['values'][x] = true;
	*/
	//if (obj.type.indexOf('text') != -1) {
	//	current_value = obj.value;
	//} else {
		current_value = obj.options[obj.selectedIndex].value;
	//}
	if (settings['values'][current_value] == true) {
		document.getElementById('parameter_'+number+'_'+settings['active_parameter_id']).disabled = false;
	} else {
		document.getElementById('parameter_'+number+'_'+settings['active_parameter_id']).value = '';
		document.getElementById('parameter_'+number+'_'+settings['active_parameter_id']).disabled = true;
	}
}

$(document).ready(function() {
	
// antifreeze code - sidewalk	
	 window.isActive = true;
    $(window).focus(function() { this.isActive = true; });
    $(window).blur(function() { this.isActive = false; });
	
	$("#query").autocomplete({
 		select: function(event, ui) {
			window.location.href = ui.item.path;
		},
		source: function(request, response) {
			jQuery.ajax({
				url: "/functions/search_item.php",
				dataType: "json",
				data: {
					term : request.term
				},
				success: function(data) {
					response(data);
				}
			});
		}
	});

	
	slideShow(5000);
	quotes(5000);
	
	
	$('#ql_pw').keyup(function(event) {
		if (event.keyCode == "13") $('#ql_form').submit(); 
	});
	$('#ql_un').keyup(function(event) {
		if (event.keyCode == "13") $('#ql_form').submit(); 
	});
	
	// For at undgå ActiveX-problem i IE9. ActiveX bruges hermed kun i IE6 og derunder	
	jQuery.ajaxSetup({
        xhr: function() {
			if (window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject)) {
				return new window.XMLHttpRequest();
			} else {
				try {
					return new window.ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {}
			}
        }
    });
});


   
function showPrint() {
	day = new Date();
	id = day.getTime();
	w = Math.round(screen.width*0.85);
	h = Math.round(screen.height*0.7);
	l = (screen.width/2)-(w/2);
	t = (screen.height/2)-(h/2);

	eval("page" + id + " = window.open('/udskriv/', '" + id + "', 'toolbar=no, location=no, directories=no, status=no, statusbar=no, menubar=0, scrollbars=auto, resizable=yes, copyhistory=no, width="+w+", height="+h+", top="+t+", left="+l+"');");
}

function slideShow(speed) {
    //append a LI item to the UL list for displaying caption
    $('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div id="slideshow-caption-bg"></div><div class="slideshow-caption-container"><h3></h3><span></span></div></li>');
 
    //Set the opacity of all images to 0
    $('ul.slideshow li').css({opacity: 0.0});
	
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('ul.slideshow li:first'));
     
    //Get the first image and display it (set it to full opacity)
    current.css({opacity: 1.0});
     
    //Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html(current.find('img').attr('title'));
	$('#slideshow-caption span').html(current.find('img').attr('alt'));
		 
	//Display the caption
	$('#slideshow-caption').css({opacity: 1, bottom:5, left: 5, right: 300});
	$('#slideshow-caption-bg').css({opacity: 0.5});
	
	var first_title = current.find('img').attr('title');

	if (!first_title) {
		$('#slideshow-caption').slideToggle(1);
	}
     
    //Call the gallery function to run the slideshow 
	if ($('ul.slideshow li').length > 2) {   
    	var timer = setInterval('gallery()',speed);
	
		//pause the slideshow on mouse over
		$('ul.slideshow').hover(
			function () {
				clearInterval(timer);   
			},  
			function () {
				
    
	timer = setInterval('gallery()',speed);

				         
			}
		);
	}
     
}
 
function gallery() {
 
  if (window.isActive) { 
    //if no IMGs have the show class, grab the first image
    var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('ul.slideshow li:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
         
    //Get next image caption
    var n_title = next.find('img').attr('title'); 
    var n_desc = next.find('img').attr('alt');
	
	var c_title = current.find('img').attr('title'); 
    var c_desc = current.find('img').attr('alt');    
         
    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
   
    //Hide the caption first, and then set and display the caption
	if (c_title && n_title) {
		$('#slideshow-caption').slideToggle(300, function() {
			$('#slideshow-caption h3').html(n_title); 
			$('#slideshow-caption span').html(n_desc); 
			$('#slideshow-caption').slideToggle(500);
		});
	} else if (c_title) {
		$('#slideshow-caption').slideToggle(300);
	} else if (n_title) { // n_title
		$('#slideshow-caption h3').html(n_title); 
		$('#slideshow-caption span').html(n_desc); 
		$('#slideshow-caption').slideToggle(500);
	}

    //Hide the current image
    current.animate({opacity: 0.0}, 1000).removeClass('show');
  	}//END IF ISACTIVE
}


function quotes(speed) {
    //append a LI item to the UL list for displaying caption
    //$('ul.quotes').append('<li id="slideshow-caption" class="caption"><div id="slideshow-caption-bg"></div><div class="slideshow-caption-container"><h3></h3><span></span></div></li>');
 
    //Set the opacity of all images to 0
    $('ul.quotes li').css({opacity: 0.0});
	
	var current = ($('ul.quotes li.show')?  $('ul.quotes li.show') : $('ul.quotes li:first'));
     
    //Get the first image and display it (set it to full opacity)
    current.css({opacity: 1.0});
	
	//Call the gallery function to run the slideshow 
	if ($('ul.quotes li').length > 2) {   
    	var timer = setInterval('quotesGallery()',speed);
	
		//pause the slideshow on mouse over
		$('ul.quotes').hover(
			function () {
				clearInterval(qtimer);   
			},  
			function () {
				
				
					qtimer = setInterval('quotesGallery()',speed);
   		 
		
				         
			}
		);
	}
     
}
 
function quotesGallery() {
 
 if (window.isActive) {
    //if no IMGs have the show class, grab the first image
    var current = ($('ul.quotes li.show')?  $('ul.quotes li.show') : $('ul.quotes li:first'));
 
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().attr('class') == 'stop')? $('ul.quotes li:first') : current.next()) : $('ul.quotes li:first'));
          
	 	  
	//Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

    //Hide the current image
    current.animate({opacity: 0.0}, 1000).removeClass('show');
 	}// END IF ISACTIVE
}


