function ChangeSearchResult(index)
{
	document.forms[0].action = 'default.asp?show=searchresult&index=' + index;
	document.forms[0].submit();
	return;
}

function isInt (str)
{
	var i = parseInt (str);

	if (isNaN (i)) return false;

	i = i.toString ();
	if (i != str) return false;

	return true;
}

function validateForm(which) {	
	
	errorText = "";
	

	if (which.FirstName.value == "") errorText += "Fornavn\n";
	if (which.LastName.value == "") errorText += "Efternavn\n";
	if (which.Street.value == "") errorText += "Vej\n";
	if (which.StreetNo.value == "") errorText += "Vej nr.\n";
	if (which.PostalCode.value == "" || which.PostalCode.value.length < 4) errorText += "Postnr. (min. 4 cifre)\n"
	if (which.City.value == "") errorText += "By\n";
	if(which.ID.value.length == 0)
	{
	    var validEmail = which.Email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	    if (which.UserID.value == "") errorText += "Brugernavn (min. 4 tegn)\n";
	    if (which.UserID.value != "" && which.UserID.value.length < 4) errorText += "Brugernavn (min. 4 tegn)\n";
	    if (which.Password.value == "" || which.Password.value.length < 4) errorText += "Password (min. 4 tegn)\n";
	    if (which.Password.value != which.PasswordRepeat.value) errorText += "Felterne Password og Gentag password er ikke ens.\n";
	    if (which.UserID.value == which.Password.value && which.UserID.value != "" && which.Password.value != "") errorText += "Brugernavnet og passwordet må ikke være ens.\n";
	    if (which.Email.value == "") errorText += "Email\n"
	    if (which.Email.value != "" && !validEmail) errorText += "En gyldig email-adresse\n"	
	}
	if (which.BirthDay.value == "" || which.BirthMonth.value == "" || which.BirthYear.value == "") errorText += "Fødselsdag\n"
	if (which.Region.value == "notchosen") errorText += "Region\n"
  if (which.Children.value == "") errorText += "Antal børn\n"
	else if (!isInt(which.Children.value)) errorText += "Antal børn skal angives med cifre\n"	
	if (which.PersonalInfo.value.length < 100) errorText += "Personlig præsentation (min. 100 tegn)\n"
	if (which.Newspaper.value == "") errorText += "Avishold\n";
	if (which.captchaBox.value == "") errorText += "Sikkerhedskode\n";
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.SubmitButton.disabled = true;
		
		return true; 
	}
}	


function validateChangePwdForm(which) {	
	
	errorText = "";

    if (which.Password.value == "" || which.Password.value.length < 4) errorText += "Adgangskode (min. 4 tegn)\n";
    if (which.NewPassword.value == "" || which.NewPassword.value.length < 4) errorText += "Ny adgangskode (min. 4 tegn)\n";
    if (which.NewPassword.value != which.RepeatNewPassword.value) errorText += "Felterne \"Ny adgangskode\" og \"Gentag ny adgangskode\" er ikke ens.\n";    
	
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.SubmitButton.disabled = true;
		
		return true; 
	}
}	

function validateContactForm(which) {
	errorText = "";
	
	var validEmail = which.Email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

	if(which.Name.value == "") errorText += "Navn\n";
	if(which.Email.value == "") errorText += "Email\n"
	if(which.Email.value != "" && !validEmail) errorText += "En gyldig email-adresse\n"
	if(which.Subject.value == "") errorText += "Emne\n";
	if(which.Content.value == "") errorText += "Besked\n";
	
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.SubmitButton.disabled = true;
		
		return true; 
	}	
}


function validateMailForm(which) {
	errorText = "";

	if(which.Subject.value == "") errorText += "Emne\n";
	if(which.Message.value == "") errorText += "Besked\n";
	if(which.captchaBox.value == "") errorText += "Sikkerhedskode\n";
	
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.SubmitButton.disabled = true;
		
		return true; 
	}	
}

function validateUserReportForm(which) {
	errorText = "";

	if(which.Comment.value == "") errorText += "Kommentar\n";
	
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.ReportUser.disabled = true;
		
		return true; 
	}	
}

function validateForgotPwdForm(which) {
	errorText = "";

	var validEmail = which.Email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);	
	
	if(which.Email.value == "") errorText += "Email-adresse\n";
	if(which.Email.value != "" && !validEmail) errorText += "En gyldig email-adresse\n";
	
	if (errorText != "") { alert("Du mangler at indtaste følgende:\n\n" + errorText);return false; } 
	else { 
		which.SubmitButton.disabled = true;
		
		return true; 
	}		
}

function validateUserSearchForm(which) {
	errorText = "";
	
	if (which.MinAge.value != "" && !isInt(which.MinAge.value)) errorText += "Min. alder skal angives med cifre\n"
	if (which.MaxAge.value != "" && !isInt(which.MaxAge.value)) errorText += "Max. alder skal angives med cifre\n"
	if (which.MinHeight.value != "" && !isInt(which.MinHeight.value)) errorText += "Min. højde skal angives med cifre\n"
	if (which.MaxHeight.value != "" && !isInt(which.MaxHeight.value)) errorText += "Max. højde skal angives med cifre\n"
	if (which.MinWeight.value != "" && !isInt(which.MinWeight.value)) errorText += "Min vægt skal angives med cifre\n"
	if (which.MaxWeight.value != "" && !isInt(which.MaxWeight.value)) errorText += "Max. vægt skal angives med cifre\n"
	
	if (errorText != "") { alert("Ret venligst følgende indtastninger:\n\n" + errorText);return false; } 
	else { 
		return true; 
	}	
}

function toggleLayer(whichLayer)
{
if (document.getElementById)
{
	var style2 = document.getElementById(whichLayer).style;
	style2.display = style2.display? "":"block";
}
else if (document.all)
{
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
}
else if (document.layers)
{
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block";
}
}

function insertcode(tag, desc, txtarea)
{
    // our textfield
    var textarea = document.getElementById(txtarea);

    // our open tag
    var open = "[" + tag + "]";

    // our close tag
    var close = "[/" + tag + "]";

    if(!textarea.setSelectionRange)
    {
        var selected = document.selection.createRange().text; 
        if(selected.length <= 0)
        { 
            textarea.value += open + prompt("Indtast venligst den tekst du vil gøre " + desc, "") + close;
        }
        else
        {
       	    alert('here2');
            document.selection.createRange().text = open + selected + close; 
        }

    }
    else
    {
    	var b = textarea;
	if( document.selection ){
	var range = document.selection.createRange();
	var stored_range = range.duplicate();
	stored_range.moveToElementText( element );
	stored_range.setEndPoint( 'EndToEnd', range );    	
	b.selectionStart = stored_range.text.length - range.text.length;
	b.selectionEnd = element.selectionStart + range.text.length;
	}
	
        // the text before the selection
        var pretext = textarea.value.substring(0, b.selectionStart);
        
        // the selected text with tags before and after
        var codetext = textarea.value.substring(b.selectionStart, b.selectionEnd);

        // the text after the selection
        var posttext = textarea.value.substring(b.selectionEnd, textarea.value.length)
        
        // check if there was a selection
        if(codetext == "")
        {
            //prompt the user
            codetext = prompt("Indtast venligst den tekst du vil gøre " + desc, "");
        }

	if(codetext != "") 
	{	        
	        codetext = open + codetext + close;
		textarea.value = pretext + codetext + posttext;
	}
    }

    // set the focus on the text field
    textarea.focus();
}

function selOn(c) {c.style.borderColor = '#393F57';c.style.backgroundColor = '#EEEEEE';c.style.cursor = 'pointer';	}
function selOff(c) {c.style.borderColor = '#D6D3CE';c.style.backgroundColor = '';}

function insertAtCursor(myField, myValue) 
{
	var field = document.getElementById(myField);

	if (document.selection) {
		field.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	else if (field.selectionStart || field.selectionStart == '0') 
	{
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		field.value = field.value.substring(0, startPos) + myValue + field.value.substring(endPos, field.value.length);
	}
	else 
	{
	myField.value += myValue;
	}
}