// JavaScript Document
  function pop_window(url) { 
   var popit = window.open(url,'console','status,width=720,height=590');
  } 
  function pop_window2(url) { 
   var popit = window.open(url,'console','status,width=525,height=305');
  } 

function validatename()
{
	fname=document.getElementById('name')
	if (fname.value.length>2 && !fname.value.match(/[@£$]/))
	{
		document.getElementById('imgname').src="ok.gif"
		fname.style.borderColor='#20e500';
	}
	else
	{
		document.getElementById('imgname').src="req.gif"
		fname.style.borderColor='red';
	}
}

function validateemail()
{
	femail=document.getElementById('email')
	//var goodEmail = femail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	var goodEmail = femail.value.match(/\b(?:\w[-.\w]*\@[-a-z0-9]+(?:\.[-a-z0-9]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|arpa|pro|local|[a-z]{2}))\b/gi);

	if (goodEmail){
		document.getElementById('imgemail').src="ok.gif"
		femail.style.borderColor='#20e500';
	} else {
		document.getElementById('imgemail').src="req.gif"
		femail.style.borderColor='red';
	}
}

function validatemsg()
{
	fmsg=document.getElementById('msg')
	if (fmsg.value.length>5)
	{
		document.getElementById('imgmsg').src="ok.gif"
		fmsg.style.borderColor='#20e500';
	}
	else
	{
		document.getElementById('imgmsg').src="req.gif"
		fmsg.style.borderColor='red';
	}
}

function validate_form()
{
	fname=document.getElementById('name')
	if (!(fname.value.length>2 && !fname.value.match(/[@£$]/)))
	{
		alert("Sjekk navn, for kort eller ugyldig tegn.\nCheck name, too short or invalid character.");
		dfname.focus();
		fname.select();
		return false;
	}

	femail=document.getElementById('email')
	// var goodEmail = femail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	var goodEmail = femail.value.match(/\b(?:\w[-.\w]*\@[-a-z0-9]+(?:\.[-a-z0-9]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|arpa|pro|local|[a-z]{2}))\b/gi);
	if (!goodEmail){
		alert("Sjekk email, ikke gyldig format.\nCheck email, not valid format.");
		femail.focus();
		femail.select();
		return false;
	}

	fmsg=document.getElementById('msg')
	if (fmsg.value.length<=5)
	{
		alert("Sjekk melding, minimum 5 bokstaver.\nCheck message, minimum 5 letters.");
		fmsg.focus();
		fmsg.select();
		return false;
	}
	return true;
}

function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}
function setCaretToEnd (input) {
  setSelectionRange(input, input.value.length, input.value.length);
}
function setCaretToBegin (input) {
  setSelectionRange(input, 0, 0);
}
function setCaretToPos (input, pos) {
  setSelectionRange(input, pos, pos);
}
function selectString (input, string) {
  var match = new RegExp(string, "i").exec(input.value);
  if (match) {
    setSelectionRange (input, match.index, match.index + match
[0].length);
  }
}
function replaceSelection (input, replaceString) {
  if (input.setSelectionRange) {
    var selectionStart = input.selectionStart;
    var selectionEnd = input.selectionEnd;
    input.value = input.value.substring(0, selectionStart)
                  + replaceString
                  + input.value.substring(selectionEnd);
    if (selectionStart != selectionEnd) // has there been a selection
      setSelectionRange(input, selectionStart, selectionStart + 
replaceString.length);
    else // set caret
      setCaretToPos(input, selectionStart + replaceString.length);
  }
  else if (document.selection) {
    var range = document.selection.createRange();
    if (range.parentElement() == input) {
      var isCollapsed = range.text == '';
      range.text = replaceString;
      if (!isCollapsed)  { // there has been a selection
        //it appears range.select() should select the newly 
        //inserted text but that fails with IE
        range.moveStart('character', -replaceString.length);
        range.select();
      }
    }
  }
}


// jQuery stuff
$(document).ready(function() {
	$('#gb_input').hide();
	$('#gb_input_show').show();
	
	$('#gb_input_show').click(function() {
		$(this).animate( {
		  opacity: 0,
		  height: 0 }, 'slow', function() {
			$('#gb_input').animate( {
				opacity: 'show',
				height: 'show' }, 2000 );
		});
	});
	return false;
});
